blob: 669662a2b416abf8ebc4932d571658455b069bd4 [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
Michal Kazior500ff9f2015-03-31 10:26:21 +0000521int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
522 struct cfg80211_chan_def *def)
523{
524 struct ieee80211_chanctx_conf *conf;
525
526 rcu_read_lock();
527 conf = rcu_dereference(vif->chanctx_conf);
528 if (!conf) {
529 rcu_read_unlock();
530 return -ENOENT;
531 }
532
533 *def = conf->def;
534 rcu_read_unlock();
535
536 return 0;
537}
538
539static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
540 struct ieee80211_chanctx_conf *conf,
541 void *data)
542{
543 int *num = data;
544
545 (*num)++;
546}
547
548static int ath10k_mac_num_chanctxs(struct ath10k *ar)
549{
550 int num = 0;
551
552 ieee80211_iter_chan_contexts_atomic(ar->hw,
553 ath10k_mac_num_chanctxs_iter,
554 &num);
555
556 return num;
557}
558
559static void
560ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
561 struct ieee80211_chanctx_conf *conf,
562 void *data)
563{
564 struct cfg80211_chan_def **def = data;
565
566 *def = &conf->def;
567}
568
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300569static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
570 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571{
572 int ret;
573
574 lockdep_assert_held(&ar->conf_mutex);
575
Michal Kaziorcfd10612014-11-25 15:16:05 +0100576 if (ar->num_peers >= ar->max_num_peers)
577 return -ENOBUFS;
578
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300579 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800580 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200581 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200582 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800584 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585
586 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800587 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200588 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200589 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300590 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800591 }
Michal Kazior292a7532014-11-25 15:16:04 +0100592
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100593 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
595 return 0;
596}
597
Kalle Valo5a13e762014-01-20 11:01:46 +0200598static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
599{
600 struct ath10k *ar = arvif->ar;
601 u32 param;
602 int ret;
603
604 param = ar->wmi.pdev_param->sta_kickout_th;
605 ret = ath10k_wmi_pdev_set_param(ar, param,
606 ATH10K_KICKOUT_THRESHOLD);
607 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200608 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200609 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200610 return ret;
611 }
612
613 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
614 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
615 ATH10K_KEEPALIVE_MIN_IDLE);
616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200617 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200618 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200619 return ret;
620 }
621
622 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
623 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
624 ATH10K_KEEPALIVE_MAX_IDLE);
625 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200626 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200627 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200628 return ret;
629 }
630
631 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
632 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
633 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
634 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200635 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200636 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200637 return ret;
638 }
639
640 return 0;
641}
642
Vivek Natarajanacab6402014-11-26 09:06:12 +0200643static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200644{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200645 struct ath10k *ar = arvif->ar;
646 u32 vdev_param;
647
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200648 vdev_param = ar->wmi.vdev_param->rts_threshold;
649 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200650}
651
652static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
653{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200654 struct ath10k *ar = arvif->ar;
655 u32 vdev_param;
656
Michal Kazior424121c2013-07-22 14:13:31 +0200657 if (value != 0xFFFFFFFF)
658 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
659 ATH10K_FRAGMT_THRESHOLD_MIN,
660 ATH10K_FRAGMT_THRESHOLD_MAX);
661
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200662 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
663 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200664}
665
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
667{
668 int ret;
669
670 lockdep_assert_held(&ar->conf_mutex);
671
672 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
673 if (ret)
674 return ret;
675
676 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
677 if (ret)
678 return ret;
679
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100680 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100681
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682 return 0;
683}
684
685static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
686{
687 struct ath10k_peer *peer, *tmp;
688
689 lockdep_assert_held(&ar->conf_mutex);
690
691 spin_lock_bh(&ar->data_lock);
692 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
693 if (peer->vdev_id != vdev_id)
694 continue;
695
Michal Kazior7aa7a722014-08-25 12:09:38 +0200696 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697 peer->addr, vdev_id);
698
699 list_del(&peer->list);
700 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100701 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300702 }
703 spin_unlock_bh(&ar->data_lock);
704}
705
Michal Kaziora96d7742013-07-16 09:38:56 +0200706static void ath10k_peer_cleanup_all(struct ath10k *ar)
707{
708 struct ath10k_peer *peer, *tmp;
709
710 lockdep_assert_held(&ar->conf_mutex);
711
712 spin_lock_bh(&ar->data_lock);
713 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
714 list_del(&peer->list);
715 kfree(peer);
716 }
717 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100718
719 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100720 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200721}
722
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300723static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
724 struct ieee80211_sta *sta,
725 enum wmi_tdls_peer_state state)
726{
727 int ret;
728 struct wmi_tdls_peer_update_cmd_arg arg = {};
729 struct wmi_tdls_peer_capab_arg cap = {};
730 struct wmi_channel_arg chan_arg = {};
731
732 lockdep_assert_held(&ar->conf_mutex);
733
734 arg.vdev_id = vdev_id;
735 arg.peer_state = state;
736 ether_addr_copy(arg.addr, sta->addr);
737
738 cap.peer_max_sp = sta->max_sp;
739 cap.peer_uapsd_queues = sta->uapsd_queues;
740
741 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
742 !sta->tdls_initiator)
743 cap.is_peer_responder = 1;
744
745 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
746 if (ret) {
747 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
748 arg.addr, vdev_id, ret);
749 return ret;
750 }
751
752 return 0;
753}
754
Kalle Valo5e3dd152013-06-12 20:52:10 +0300755/************************/
756/* Interface management */
757/************************/
758
Michal Kazior64badcb2014-09-18 11:18:02 +0300759void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
760{
761 struct ath10k *ar = arvif->ar;
762
763 lockdep_assert_held(&ar->data_lock);
764
765 if (!arvif->beacon)
766 return;
767
768 if (!arvif->beacon_buf)
769 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
770 arvif->beacon->len, DMA_TO_DEVICE);
771
Michal Kazioraf213192015-01-29 14:29:52 +0200772 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
773 arvif->beacon_state != ATH10K_BEACON_SENT))
774 return;
775
Michal Kazior64badcb2014-09-18 11:18:02 +0300776 dev_kfree_skb_any(arvif->beacon);
777
778 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200779 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300780}
781
782static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
783{
784 struct ath10k *ar = arvif->ar;
785
786 lockdep_assert_held(&ar->data_lock);
787
788 ath10k_mac_vif_beacon_free(arvif);
789
790 if (arvif->beacon_buf) {
791 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
792 arvif->beacon_buf, arvif->beacon_paddr);
793 arvif->beacon_buf = NULL;
794 }
795}
796
Kalle Valo5e3dd152013-06-12 20:52:10 +0300797static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
798{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300799 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300800
Michal Kazior548db542013-07-05 16:15:15 +0300801 lockdep_assert_held(&ar->conf_mutex);
802
Michal Kazior7962b0d2014-10-28 10:34:38 +0100803 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
804 return -ESHUTDOWN;
805
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300806 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
807 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
808 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300809 return -ETIMEDOUT;
810
811 return 0;
812}
813
Michal Kazior1bbc0972014-04-08 09:45:47 +0300814static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300815{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000816 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100817 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300818 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300819 int ret = 0;
820
821 lockdep_assert_held(&ar->conf_mutex);
822
Michal Kazior500ff9f2015-03-31 10:26:21 +0000823 ieee80211_iter_chan_contexts_atomic(ar->hw,
824 ath10k_mac_get_any_chandef_iter,
825 &chandef);
826 if (WARN_ON_ONCE(!chandef))
827 return -ENOENT;
828
829 channel = chandef->chan;
830
Kalle Valo5e3dd152013-06-12 20:52:10 +0300831 arg.vdev_id = vdev_id;
832 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100833 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300834
835 /* TODO setup this dynamically, what in case we
836 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100837 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 arg.channel.chan_radar =
839 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840
Michal Kazior89c5c842013-10-23 04:02:13 -0700841 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700842 arg.channel.max_power = channel->max_power * 2;
843 arg.channel.max_reg_power = channel->max_reg_power * 2;
844 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300845
Michal Kazior7962b0d2014-10-28 10:34:38 +0100846 reinit_completion(&ar->vdev_setup_done);
847
Kalle Valo5e3dd152013-06-12 20:52:10 +0300848 ret = ath10k_wmi_vdev_start(ar, &arg);
849 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200850 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200851 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300852 return ret;
853 }
854
855 ret = ath10k_vdev_setup_sync(ar);
856 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200857 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200858 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300859 return ret;
860 }
861
862 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
863 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200864 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200865 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300866 goto vdev_stop;
867 }
868
869 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870
Michal Kazior7aa7a722014-08-25 12:09:38 +0200871 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300872 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300873 return 0;
874
875vdev_stop:
876 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
877 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200878 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200879 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300880
881 return ret;
882}
883
Michal Kazior1bbc0972014-04-08 09:45:47 +0300884static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300885{
886 int ret = 0;
887
888 lockdep_assert_held(&ar->conf_mutex);
889
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200890 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
891 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200892 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200893 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300894
Michal Kazior7962b0d2014-10-28 10:34:38 +0100895 reinit_completion(&ar->vdev_setup_done);
896
Kalle Valo5e3dd152013-06-12 20:52:10 +0300897 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
898 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200899 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200900 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901
902 ret = ath10k_vdev_setup_sync(ar);
903 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200904 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200905 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300906
Michal Kazior7aa7a722014-08-25 12:09:38 +0200907 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300908 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300909 return ret;
910}
911
Michal Kazior1bbc0972014-04-08 09:45:47 +0300912static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913{
914 int bit, ret = 0;
915
916 lockdep_assert_held(&ar->conf_mutex);
917
Ben Greeara9aefb32014-08-12 11:02:19 +0300918 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200919 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 return -ENOMEM;
921 }
922
Ben Greear16c11172014-09-23 14:17:16 -0700923 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300924
Ben Greear16c11172014-09-23 14:17:16 -0700925 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926
927 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
928 WMI_VDEV_TYPE_MONITOR,
929 0, ar->mac_addr);
930 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200931 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200932 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300933 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300934 }
935
Ben Greear16c11172014-09-23 14:17:16 -0700936 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200937 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938 ar->monitor_vdev_id);
939
Kalle Valo5e3dd152013-06-12 20:52:10 +0300940 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941}
942
Michal Kazior1bbc0972014-04-08 09:45:47 +0300943static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944{
945 int ret = 0;
946
947 lockdep_assert_held(&ar->conf_mutex);
948
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200951 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200952 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300953 return ret;
954 }
955
Ben Greear16c11172014-09-23 14:17:16 -0700956 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300957
Michal Kazior7aa7a722014-08-25 12:09:38 +0200958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300959 ar->monitor_vdev_id);
960 return ret;
961}
962
Michal Kazior1bbc0972014-04-08 09:45:47 +0300963static int ath10k_monitor_start(struct ath10k *ar)
964{
965 int ret;
966
967 lockdep_assert_held(&ar->conf_mutex);
968
Michal Kazior1bbc0972014-04-08 09:45:47 +0300969 ret = ath10k_monitor_vdev_create(ar);
970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200971 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300972 return ret;
973 }
974
975 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
976 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200977 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300978 ath10k_monitor_vdev_delete(ar);
979 return ret;
980 }
981
982 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200983 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300984
985 return 0;
986}
987
Michal Kazior19337472014-08-28 12:58:16 +0200988static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300989{
990 int ret;
991
992 lockdep_assert_held(&ar->conf_mutex);
993
Michal Kazior1bbc0972014-04-08 09:45:47 +0300994 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200995 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200996 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200997 return ret;
998 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300999
1000 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001001 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001002 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001003 return ret;
1004 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001005
1006 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001007 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001008
1009 return 0;
1010}
1011
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301012static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1013{
1014 struct ath10k_vif *arvif;
1015
1016 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1017 return true;
1018
1019 if (!ar->num_started_vdevs)
1020 return false;
1021
1022 list_for_each_entry(arvif, &ar->arvifs, list)
1023 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1024 return false;
1025
1026 ath10k_dbg(ar, ATH10K_DBG_MAC,
1027 "mac disabling promiscuous mode because vdev is started\n");
1028 return true;
1029}
1030
Michal Kazior500ff9f2015-03-31 10:26:21 +00001031static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1032{
1033 int num_ctx;
1034
1035 /* At least one chanctx is required to derive a channel to start
1036 * monitor vdev on.
1037 */
1038 num_ctx = ath10k_mac_num_chanctxs(ar);
1039 if (num_ctx == 0)
1040 return false;
1041
1042 /* If there's already an existing special monitor interface then don't
1043 * bother creating another monitor vdev.
1044 */
1045 if (ar->monitor_arvif)
1046 return false;
1047
1048 return ar->monitor ||
1049 !ath10k_mac_should_disable_promisc(ar) ||
1050 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1051}
1052
1053static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1054{
1055 int num_ctx;
1056
1057 num_ctx = ath10k_mac_num_chanctxs(ar);
1058
1059 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1060 * shouldn't allow this but make sure to prevent handling the following
1061 * case anyway since multi-channel DFS hasn't been tested at all.
1062 */
1063 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1064 return false;
1065
1066 return true;
1067}
1068
Michal Kazior19337472014-08-28 12:58:16 +02001069static int ath10k_monitor_recalc(struct ath10k *ar)
1070{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001071 bool needed;
1072 bool allowed;
1073 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001074
1075 lockdep_assert_held(&ar->conf_mutex);
1076
Michal Kazior500ff9f2015-03-31 10:26:21 +00001077 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1078 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001079
1080 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001081 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1082 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001083
Michal Kazior500ff9f2015-03-31 10:26:21 +00001084 if (WARN_ON(needed && !allowed)) {
1085 if (ar->monitor_started) {
1086 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1087
1088 ret = ath10k_monitor_stop(ar);
1089 if (ret)
1090 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1091 /* not serious */
1092 }
1093
1094 return -EPERM;
1095 }
1096
1097 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001098 return 0;
1099
Michal Kazior500ff9f2015-03-31 10:26:21 +00001100 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001101 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001102 else
1103 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001104}
1105
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001106static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1107{
1108 struct ath10k *ar = arvif->ar;
1109 u32 vdev_param, rts_cts = 0;
1110
1111 lockdep_assert_held(&ar->conf_mutex);
1112
1113 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1114
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001115 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001116
1117 if (arvif->num_legacy_stations > 0)
1118 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1119 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001120 else
1121 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1122 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001123
1124 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1125 rts_cts);
1126}
1127
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001128static int ath10k_start_cac(struct ath10k *ar)
1129{
1130 int ret;
1131
1132 lockdep_assert_held(&ar->conf_mutex);
1133
1134 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1135
Michal Kazior19337472014-08-28 12:58:16 +02001136 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001137 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001138 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001139 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1140 return ret;
1141 }
1142
Michal Kazior7aa7a722014-08-25 12:09:38 +02001143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001144 ar->monitor_vdev_id);
1145
1146 return 0;
1147}
1148
1149static int ath10k_stop_cac(struct ath10k *ar)
1150{
1151 lockdep_assert_held(&ar->conf_mutex);
1152
1153 /* CAC is not running - do nothing */
1154 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1155 return 0;
1156
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001157 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001158 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001159
Michal Kazior7aa7a722014-08-25 12:09:38 +02001160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001161
1162 return 0;
1163}
1164
Michal Kazior500ff9f2015-03-31 10:26:21 +00001165static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1166 struct ieee80211_chanctx_conf *conf,
1167 void *data)
1168{
1169 bool *ret = data;
1170
1171 if (!*ret && conf->radar_enabled)
1172 *ret = true;
1173}
1174
1175static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1176{
1177 bool has_radar = false;
1178
1179 ieee80211_iter_chan_contexts_atomic(ar->hw,
1180 ath10k_mac_has_radar_iter,
1181 &has_radar);
1182
1183 return has_radar;
1184}
1185
Michal Kaziord6500972014-04-08 09:56:09 +03001186static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001187{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001188 int ret;
1189
1190 lockdep_assert_held(&ar->conf_mutex);
1191
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001192 ath10k_stop_cac(ar);
1193
Michal Kazior500ff9f2015-03-31 10:26:21 +00001194 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001195 return;
1196
Michal Kaziord6500972014-04-08 09:56:09 +03001197 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001198 return;
1199
1200 ret = ath10k_start_cac(ar);
1201 if (ret) {
1202 /*
1203 * Not possible to start CAC on current channel so starting
1204 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1205 * by indicating that radar was detected.
1206 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001207 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001208 ieee80211_radar_detected(ar->hw);
1209 }
1210}
1211
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301212static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1213{
1214 struct ath10k *ar = arvif->ar;
1215 int ret;
1216
1217 lockdep_assert_held(&ar->conf_mutex);
1218
1219 reinit_completion(&ar->vdev_setup_done);
1220
1221 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1222 if (ret) {
1223 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1224 arvif->vdev_id, ret);
1225 return ret;
1226 }
1227
1228 ret = ath10k_vdev_setup_sync(ar);
1229 if (ret) {
1230 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1231 arvif->vdev_id, ret);
1232 return ret;
1233 }
1234
1235 WARN_ON(ar->num_started_vdevs == 0);
1236
1237 if (ar->num_started_vdevs != 0) {
1238 ar->num_started_vdevs--;
1239 ath10k_recalc_radar_detection(ar);
1240 }
1241
1242 return ret;
1243}
1244
Michal Kazior500ff9f2015-03-31 10:26:21 +00001245static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1246 const struct cfg80211_chan_def *chandef,
1247 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001248{
1249 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001250 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301251 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001252
1253 lockdep_assert_held(&ar->conf_mutex);
1254
1255 reinit_completion(&ar->vdev_setup_done);
1256
1257 arg.vdev_id = arvif->vdev_id;
1258 arg.dtim_period = arvif->dtim_period;
1259 arg.bcn_intval = arvif->beacon_interval;
1260
1261 arg.channel.freq = chandef->chan->center_freq;
1262 arg.channel.band_center_freq1 = chandef->center_freq1;
1263 arg.channel.mode = chan_to_phymode(chandef);
1264
1265 arg.channel.min_power = 0;
1266 arg.channel.max_power = chandef->chan->max_power * 2;
1267 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1268 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1269
1270 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1271 arg.ssid = arvif->u.ap.ssid;
1272 arg.ssid_len = arvif->u.ap.ssid_len;
1273 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1274
1275 /* For now allow DFS for AP mode */
1276 arg.channel.chan_radar =
1277 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1278 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1279 arg.ssid = arvif->vif->bss_conf.ssid;
1280 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1281 }
1282
Michal Kazior7aa7a722014-08-25 12:09:38 +02001283 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001284 "mac vdev %d start center_freq %d phymode %s\n",
1285 arg.vdev_id, arg.channel.freq,
1286 ath10k_wmi_phymode_str(arg.channel.mode));
1287
Michal Kaziordc55e302014-07-29 12:53:36 +03001288 if (restart)
1289 ret = ath10k_wmi_vdev_restart(ar, &arg);
1290 else
1291 ret = ath10k_wmi_vdev_start(ar, &arg);
1292
Michal Kazior72654fa2014-04-08 09:56:09 +03001293 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001294 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001295 arg.vdev_id, ret);
1296 return ret;
1297 }
1298
1299 ret = ath10k_vdev_setup_sync(ar);
1300 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001301 ath10k_warn(ar,
1302 "failed to synchronize setup for vdev %i restart %d: %d\n",
1303 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001304 return ret;
1305 }
1306
Michal Kaziord6500972014-04-08 09:56:09 +03001307 ar->num_started_vdevs++;
1308 ath10k_recalc_radar_detection(ar);
1309
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301310 ret = ath10k_monitor_recalc(ar);
1311 if (ret) {
1312 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1313 arg.vdev_id, restart, ret);
1314 ret2 = ath10k_vdev_stop(arvif);
1315 if (ret2)
1316 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1317 arg.vdev_id, restart, ret2);
1318 }
1319
Michal Kazior72654fa2014-04-08 09:56:09 +03001320 return ret;
1321}
1322
Michal Kazior500ff9f2015-03-31 10:26:21 +00001323static int ath10k_vdev_start(struct ath10k_vif *arvif,
1324 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001325{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001326 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001327}
1328
Michal Kazior500ff9f2015-03-31 10:26:21 +00001329static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1330 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001331{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001332 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001333}
1334
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001335static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1336 struct sk_buff *bcn)
1337{
1338 struct ath10k *ar = arvif->ar;
1339 struct ieee80211_mgmt *mgmt;
1340 const u8 *p2p_ie;
1341 int ret;
1342
1343 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1344 return 0;
1345
1346 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1347 return 0;
1348
1349 mgmt = (void *)bcn->data;
1350 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1351 mgmt->u.beacon.variable,
1352 bcn->len - (mgmt->u.beacon.variable -
1353 bcn->data));
1354 if (!p2p_ie)
1355 return -ENOENT;
1356
1357 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1358 if (ret) {
1359 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1360 arvif->vdev_id, ret);
1361 return ret;
1362 }
1363
1364 return 0;
1365}
1366
1367static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1368 u8 oui_type, size_t ie_offset)
1369{
1370 size_t len;
1371 const u8 *next;
1372 const u8 *end;
1373 u8 *ie;
1374
1375 if (WARN_ON(skb->len < ie_offset))
1376 return -EINVAL;
1377
1378 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1379 skb->data + ie_offset,
1380 skb->len - ie_offset);
1381 if (!ie)
1382 return -ENOENT;
1383
1384 len = ie[1] + 2;
1385 end = skb->data + skb->len;
1386 next = ie + len;
1387
1388 if (WARN_ON(next > end))
1389 return -EINVAL;
1390
1391 memmove(ie, next, end - next);
1392 skb_trim(skb, skb->len - len);
1393
1394 return 0;
1395}
1396
1397static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1398{
1399 struct ath10k *ar = arvif->ar;
1400 struct ieee80211_hw *hw = ar->hw;
1401 struct ieee80211_vif *vif = arvif->vif;
1402 struct ieee80211_mutable_offsets offs = {};
1403 struct sk_buff *bcn;
1404 int ret;
1405
1406 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1407 return 0;
1408
Michal Kazior81a9a172015-03-05 16:02:17 +02001409 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1410 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1411 return 0;
1412
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001413 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1414 if (!bcn) {
1415 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1416 return -EPERM;
1417 }
1418
1419 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1420 if (ret) {
1421 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1422 kfree_skb(bcn);
1423 return ret;
1424 }
1425
1426 /* P2P IE is inserted by firmware automatically (as configured above)
1427 * so remove it from the base beacon template to avoid duplicate P2P
1428 * IEs in beacon frames.
1429 */
1430 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1431 offsetof(struct ieee80211_mgmt,
1432 u.beacon.variable));
1433
1434 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1435 0, NULL, 0);
1436 kfree_skb(bcn);
1437
1438 if (ret) {
1439 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1440 ret);
1441 return ret;
1442 }
1443
1444 return 0;
1445}
1446
1447static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1448{
1449 struct ath10k *ar = arvif->ar;
1450 struct ieee80211_hw *hw = ar->hw;
1451 struct ieee80211_vif *vif = arvif->vif;
1452 struct sk_buff *prb;
1453 int ret;
1454
1455 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1456 return 0;
1457
Michal Kazior81a9a172015-03-05 16:02:17 +02001458 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1459 return 0;
1460
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001461 prb = ieee80211_proberesp_get(hw, vif);
1462 if (!prb) {
1463 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1464 return -EPERM;
1465 }
1466
1467 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1468 kfree_skb(prb);
1469
1470 if (ret) {
1471 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1472 ret);
1473 return ret;
1474 }
1475
1476 return 0;
1477}
1478
Michal Kazior500ff9f2015-03-31 10:26:21 +00001479static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1480{
1481 struct ath10k *ar = arvif->ar;
1482 struct cfg80211_chan_def def;
1483 int ret;
1484
1485 /* When originally vdev is started during assign_vif_chanctx() some
1486 * information is missing, notably SSID. Firmware revisions with beacon
1487 * offloading require the SSID to be provided during vdev (re)start to
1488 * handle hidden SSID properly.
1489 *
1490 * Vdev restart must be done after vdev has been both started and
1491 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1492 * deliver vdev restart response event causing timeouts during vdev
1493 * syncing in ath10k.
1494 *
1495 * Note: The vdev down/up and template reinstallation could be skipped
1496 * since only wmi-tlv firmware are known to have beacon offload and
1497 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1498 * response delivery. It's probably more robust to keep it as is.
1499 */
1500 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1501 return 0;
1502
1503 if (WARN_ON(!arvif->is_started))
1504 return -EINVAL;
1505
1506 if (WARN_ON(!arvif->is_up))
1507 return -EINVAL;
1508
1509 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1510 return -EINVAL;
1511
1512 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1513 if (ret) {
1514 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1515 arvif->vdev_id, ret);
1516 return ret;
1517 }
1518
1519 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1520 * firmware will crash upon vdev up.
1521 */
1522
1523 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1524 if (ret) {
1525 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1526 return ret;
1527 }
1528
1529 ret = ath10k_mac_setup_prb_tmpl(arvif);
1530 if (ret) {
1531 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1532 return ret;
1533 }
1534
1535 ret = ath10k_vdev_restart(arvif, &def);
1536 if (ret) {
1537 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1538 arvif->vdev_id, ret);
1539 return ret;
1540 }
1541
1542 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1543 arvif->bssid);
1544 if (ret) {
1545 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1546 arvif->vdev_id, ret);
1547 return ret;
1548 }
1549
1550 return 0;
1551}
1552
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001554 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001557 int ret = 0;
1558
Michal Kazior548db542013-07-05 16:15:15 +03001559 lockdep_assert_held(&arvif->ar->conf_mutex);
1560
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001562 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1563 if (ret)
1564 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1565 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001566
Michal Kaziorc930f742014-01-23 11:38:25 +01001567 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001568
1569 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001570 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001571 spin_unlock_bh(&arvif->ar->data_lock);
1572
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 return;
1574 }
1575
1576 arvif->tx_seq_no = 0x1000;
1577
Michal Kaziorc930f742014-01-23 11:38:25 +01001578 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001579 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001580
1581 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1582 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001584 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001585 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 return;
1587 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001588
Michal Kaziorc930f742014-01-23 11:38:25 +01001589 arvif->is_up = true;
1590
Michal Kazior500ff9f2015-03-31 10:26:21 +00001591 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1592 if (ret) {
1593 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1594 arvif->vdev_id, ret);
1595 return;
1596 }
1597
Michal Kazior7aa7a722014-08-25 12:09:38 +02001598 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599}
1600
1601static void ath10k_control_ibss(struct ath10k_vif *arvif,
1602 struct ieee80211_bss_conf *info,
1603 const u8 self_peer[ETH_ALEN])
1604{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001605 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001606 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 int ret = 0;
1608
Michal Kazior548db542013-07-05 16:15:15 +03001609 lockdep_assert_held(&arvif->ar->conf_mutex);
1610
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611 if (!info->ibss_joined) {
1612 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1613 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001614 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 self_peer, arvif->vdev_id, ret);
1616
Michal Kaziorc930f742014-01-23 11:38:25 +01001617 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 return;
1619
Michal Kaziorc930f742014-01-23 11:38:25 +01001620 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621
1622 return;
1623 }
1624
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001625 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1626 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001628 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 self_peer, arvif->vdev_id, ret);
1630 return;
1631 }
1632
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001633 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1634 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 ATH10K_DEFAULT_ATIM);
1636 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001637 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001638 arvif->vdev_id, ret);
1639}
1640
Michal Kazior9f9b5742014-12-12 12:41:36 +01001641static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1642{
1643 struct ath10k *ar = arvif->ar;
1644 u32 param;
1645 u32 value;
1646 int ret;
1647
1648 lockdep_assert_held(&arvif->ar->conf_mutex);
1649
1650 if (arvif->u.sta.uapsd)
1651 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1652 else
1653 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1654
1655 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1656 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1657 if (ret) {
1658 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1659 value, arvif->vdev_id, ret);
1660 return ret;
1661 }
1662
1663 return 0;
1664}
1665
1666static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1667{
1668 struct ath10k *ar = arvif->ar;
1669 u32 param;
1670 u32 value;
1671 int ret;
1672
1673 lockdep_assert_held(&arvif->ar->conf_mutex);
1674
1675 if (arvif->u.sta.uapsd)
1676 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1677 else
1678 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1679
1680 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1681 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1682 param, value);
1683 if (ret) {
1684 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1685 value, arvif->vdev_id, ret);
1686 return ret;
1687 }
1688
1689 return 0;
1690}
1691
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001692static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1693{
1694 struct ath10k_vif *arvif;
1695 int num = 0;
1696
1697 lockdep_assert_held(&ar->conf_mutex);
1698
1699 list_for_each_entry(arvif, &ar->arvifs, list)
1700 if (arvif->ps)
1701 num++;
1702
1703 return num;
1704}
1705
Michal Kaziorad088bf2013-10-16 15:44:46 +03001706static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001708 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001709 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001710 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001711 enum wmi_sta_powersave_param param;
1712 enum wmi_sta_ps_mode psmode;
1713 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001714 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001715 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716
Michal Kazior548db542013-07-05 16:15:15 +03001717 lockdep_assert_held(&arvif->ar->conf_mutex);
1718
Michal Kaziorad088bf2013-10-16 15:44:46 +03001719 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1720 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001721
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001722 enable_ps = arvif->ps;
1723
1724 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1725 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1726 ar->fw_features)) {
1727 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1728 arvif->vdev_id);
1729 enable_ps = false;
1730 }
1731
1732 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733 psmode = WMI_STA_PS_MODE_ENABLED;
1734 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1735
Michal Kazior526549a2014-12-12 12:41:37 +01001736 ps_timeout = conf->dynamic_ps_timeout;
1737 if (ps_timeout == 0) {
1738 /* Firmware doesn't like 0 */
1739 ps_timeout = ieee80211_tu_to_usec(
1740 vif->bss_conf.beacon_int) / 1000;
1741 }
1742
Michal Kaziorad088bf2013-10-16 15:44:46 +03001743 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001744 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001746 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001747 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001748 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001749 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750 } else {
1751 psmode = WMI_STA_PS_MODE_DISABLED;
1752 }
1753
Michal Kazior7aa7a722014-08-25 12:09:38 +02001754 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001755 arvif->vdev_id, psmode ? "enable" : "disable");
1756
Michal Kaziorad088bf2013-10-16 15:44:46 +03001757 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1758 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001759 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001760 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001761 return ret;
1762 }
1763
1764 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001765}
1766
Michal Kazior46725b152015-01-28 09:57:49 +02001767static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1768{
1769 struct ath10k *ar = arvif->ar;
1770 struct wmi_sta_keepalive_arg arg = {};
1771 int ret;
1772
1773 lockdep_assert_held(&arvif->ar->conf_mutex);
1774
1775 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1776 return 0;
1777
1778 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1779 return 0;
1780
1781 /* Some firmware revisions have a bug and ignore the `enabled` field.
1782 * Instead use the interval to disable the keepalive.
1783 */
1784 arg.vdev_id = arvif->vdev_id;
1785 arg.enabled = 1;
1786 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1787 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1788
1789 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1790 if (ret) {
1791 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1792 arvif->vdev_id, ret);
1793 return ret;
1794 }
1795
1796 return 0;
1797}
1798
Michal Kazior81a9a172015-03-05 16:02:17 +02001799static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1800{
1801 struct ath10k *ar = arvif->ar;
1802 struct ieee80211_vif *vif = arvif->vif;
1803 int ret;
1804
Michal Kazior8513d952015-03-09 14:19:24 +01001805 lockdep_assert_held(&arvif->ar->conf_mutex);
1806
1807 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1808 return;
1809
Michal Kazior81a9a172015-03-05 16:02:17 +02001810 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1811 return;
1812
1813 if (!vif->csa_active)
1814 return;
1815
1816 if (!arvif->is_up)
1817 return;
1818
1819 if (!ieee80211_csa_is_complete(vif)) {
1820 ieee80211_csa_update_counter(vif);
1821
1822 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1823 if (ret)
1824 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1825 ret);
1826
1827 ret = ath10k_mac_setup_prb_tmpl(arvif);
1828 if (ret)
1829 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1830 ret);
1831 } else {
1832 ieee80211_csa_finish(vif);
1833 }
1834}
1835
1836static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1837{
1838 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1839 ap_csa_work);
1840 struct ath10k *ar = arvif->ar;
1841
1842 mutex_lock(&ar->conf_mutex);
1843 ath10k_mac_vif_ap_csa_count_down(arvif);
1844 mutex_unlock(&ar->conf_mutex);
1845}
1846
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001847static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1848 struct ieee80211_vif *vif)
1849{
1850 struct sk_buff *skb = data;
1851 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1852 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1853
1854 if (vif->type != NL80211_IFTYPE_STATION)
1855 return;
1856
1857 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1858 return;
1859
1860 cancel_delayed_work(&arvif->connection_loss_work);
1861}
1862
1863void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1864{
1865 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1866 IEEE80211_IFACE_ITER_NORMAL,
1867 ath10k_mac_handle_beacon_iter,
1868 skb);
1869}
1870
1871static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1872 struct ieee80211_vif *vif)
1873{
1874 u32 *vdev_id = data;
1875 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1876 struct ath10k *ar = arvif->ar;
1877 struct ieee80211_hw *hw = ar->hw;
1878
1879 if (arvif->vdev_id != *vdev_id)
1880 return;
1881
1882 if (!arvif->is_up)
1883 return;
1884
1885 ieee80211_beacon_loss(vif);
1886
1887 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1888 * (done by mac80211) succeeds but beacons do not resume then it
1889 * doesn't make sense to continue operation. Queue connection loss work
1890 * which can be cancelled when beacon is received.
1891 */
1892 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1893 ATH10K_CONNECTION_LOSS_HZ);
1894}
1895
1896void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1897{
1898 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1899 IEEE80211_IFACE_ITER_NORMAL,
1900 ath10k_mac_handle_beacon_miss_iter,
1901 &vdev_id);
1902}
1903
1904static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1905{
1906 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1907 connection_loss_work.work);
1908 struct ieee80211_vif *vif = arvif->vif;
1909
1910 if (!arvif->is_up)
1911 return;
1912
1913 ieee80211_connection_loss(vif);
1914}
1915
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916/**********************/
1917/* Station management */
1918/**********************/
1919
Michal Kazior590922a2014-10-21 10:10:29 +03001920static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1921 struct ieee80211_vif *vif)
1922{
1923 /* Some firmware revisions have unstable STA powersave when listen
1924 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1925 * generate NullFunc frames properly even if buffered frames have been
1926 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1927 * buffered frames. Often pinging the device from AP would simply fail.
1928 *
1929 * As a workaround set it to 1.
1930 */
1931 if (vif->type == NL80211_IFTYPE_STATION)
1932 return 1;
1933
1934 return ar->hw->conf.listen_interval;
1935}
1936
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001938 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 struct wmi_peer_assoc_complete_arg *arg)
1941{
Michal Kazior590922a2014-10-21 10:10:29 +03001942 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001943 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001944
Michal Kazior548db542013-07-05 16:15:15 +03001945 lockdep_assert_held(&ar->conf_mutex);
1946
Michal Kaziorc51880e2015-03-30 09:51:57 +03001947 if (vif->type == NL80211_IFTYPE_STATION)
1948 aid = vif->bss_conf.aid;
1949 else
1950 aid = sta->aid;
1951
Kalle Valob25f32c2014-09-14 12:50:49 +03001952 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001954 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001956 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001957 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001958 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001959}
1960
1961static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001962 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001963 struct wmi_peer_assoc_complete_arg *arg)
1964{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001966 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 struct cfg80211_bss *bss;
1968 const u8 *rsnie = NULL;
1969 const u8 *wpaie = NULL;
1970
Michal Kazior548db542013-07-05 16:15:15 +03001971 lockdep_assert_held(&ar->conf_mutex);
1972
Michal Kazior500ff9f2015-03-31 10:26:21 +00001973 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1974 return;
1975
1976 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1977 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001978 if (bss) {
1979 const struct cfg80211_bss_ies *ies;
1980
1981 rcu_read_lock();
1982 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1983
1984 ies = rcu_dereference(bss->ies);
1985
1986 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001987 WLAN_OUI_TYPE_MICROSOFT_WPA,
1988 ies->data,
1989 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 rcu_read_unlock();
1991 cfg80211_put_bss(ar->hw->wiphy, bss);
1992 }
1993
1994 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1995 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001996 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001997 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1998 }
1999
2000 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002001 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2003 }
2004}
2005
2006static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002007 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008 struct ieee80211_sta *sta,
2009 struct wmi_peer_assoc_complete_arg *arg)
2010{
2011 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002012 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013 const struct ieee80211_supported_band *sband;
2014 const struct ieee80211_rate *rates;
2015 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002016 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 int i;
2018
Michal Kazior548db542013-07-05 16:15:15 +03002019 lockdep_assert_held(&ar->conf_mutex);
2020
Michal Kazior500ff9f2015-03-31 10:26:21 +00002021 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2022 return;
2023
2024 sband = ar->hw->wiphy->bands[def.chan->band];
2025 ratemask = sta->supp_rates[def.chan->band];
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 rates = sband->bitrates;
2027
2028 rateset->num_rates = 0;
2029
2030 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2031 if (!(ratemask & 1))
2032 continue;
2033
Michal Kazior486017c2015-03-30 09:51:54 +03002034 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2035 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 rateset->num_rates++;
2037 }
2038}
2039
2040static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2041 struct ieee80211_sta *sta,
2042 struct wmi_peer_assoc_complete_arg *arg)
2043{
2044 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03002046 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047
Michal Kazior548db542013-07-05 16:15:15 +03002048 lockdep_assert_held(&ar->conf_mutex);
2049
Kalle Valo5e3dd152013-06-12 20:52:10 +03002050 if (!ht_cap->ht_supported)
2051 return;
2052
2053 arg->peer_flags |= WMI_PEER_HT;
2054 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2055 ht_cap->ampdu_factor)) - 1;
2056
2057 arg->peer_mpdu_density =
2058 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2059
2060 arg->peer_ht_caps = ht_cap->cap;
2061 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2062
2063 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2064 arg->peer_flags |= WMI_PEER_LDPC;
2065
2066 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2067 arg->peer_flags |= WMI_PEER_40MHZ;
2068 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2069 }
2070
2071 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2072 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2073
2074 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2075 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2076
2077 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2078 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2079 arg->peer_flags |= WMI_PEER_STBC;
2080 }
2081
2082 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2084 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2085 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2086 arg->peer_rate_caps |= stbc;
2087 arg->peer_flags |= WMI_PEER_STBC;
2088 }
2089
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2091 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2092 else if (ht_cap->mcs.rx_mask[1])
2093 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2094
2095 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
2096 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
2097 arg->peer_ht_rates.rates[n++] = i;
2098
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002099 /*
2100 * This is a workaround for HT-enabled STAs which break the spec
2101 * and have no HT capabilities RX mask (no HT RX MCS map).
2102 *
2103 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2104 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2105 *
2106 * Firmware asserts if such situation occurs.
2107 */
2108 if (n == 0) {
2109 arg->peer_ht_rates.num_rates = 8;
2110 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2111 arg->peer_ht_rates.rates[i] = i;
2112 } else {
2113 arg->peer_ht_rates.num_rates = n;
2114 arg->peer_num_spatial_streams = sta->rx_nss;
2115 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116
Michal Kazior7aa7a722014-08-25 12:09:38 +02002117 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002118 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119 arg->peer_ht_rates.num_rates,
2120 arg->peer_num_spatial_streams);
2121}
2122
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002123static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2124 struct ath10k_vif *arvif,
2125 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126{
2127 u32 uapsd = 0;
2128 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002129 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130
Michal Kazior548db542013-07-05 16:15:15 +03002131 lockdep_assert_held(&ar->conf_mutex);
2132
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002134 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135 sta->uapsd_queues, sta->max_sp);
2136
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2138 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2139 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2140 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2141 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2142 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2143 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2144 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2145 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2146 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2147 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2148 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2149
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2151 max_sp = sta->max_sp;
2152
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002153 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2154 sta->addr,
2155 WMI_AP_PS_PEER_PARAM_UAPSD,
2156 uapsd);
2157 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002158 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002159 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002160 return ret;
2161 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002163 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2164 sta->addr,
2165 WMI_AP_PS_PEER_PARAM_MAX_SP,
2166 max_sp);
2167 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002168 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002169 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002170 return ret;
2171 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172
2173 /* TODO setup this based on STA listen interval and
2174 beacon interval. Currently we don't know
2175 sta->listen_interval - mac80211 patch required.
2176 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002177 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002178 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2179 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002180 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002181 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002182 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002183 return ret;
2184 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002187 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188}
2189
2190static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002191 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 struct ieee80211_sta *sta,
2193 struct wmi_peer_assoc_complete_arg *arg)
2194{
2195 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002196 struct cfg80211_chan_def def;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002197 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198
Michal Kazior500ff9f2015-03-31 10:26:21 +00002199 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2200 return;
2201
Kalle Valo5e3dd152013-06-12 20:52:10 +03002202 if (!vht_cap->vht_supported)
2203 return;
2204
2205 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002206
Michal Kazior500ff9f2015-03-31 10:26:21 +00002207 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002208 arg->peer_flags |= WMI_PEER_VHT_2G;
2209
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210 arg->peer_vht_caps = vht_cap->cap;
2211
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002212 ampdu_factor = (vht_cap->cap &
2213 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2214 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2215
2216 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2217 * zero in VHT IE. Using it would result in degraded throughput.
2218 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2219 * it if VHT max_mpdu is smaller. */
2220 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2221 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2222 ampdu_factor)) - 1);
2223
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2225 arg->peer_flags |= WMI_PEER_80MHZ;
2226
2227 arg->peer_vht_rates.rx_max_rate =
2228 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2229 arg->peer_vht_rates.rx_mcs_set =
2230 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2231 arg->peer_vht_rates.tx_max_rate =
2232 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2233 arg->peer_vht_rates.tx_mcs_set =
2234 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2235
Michal Kazior7aa7a722014-08-25 12:09:38 +02002236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002237 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238}
2239
2240static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002241 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 struct wmi_peer_assoc_complete_arg *arg)
2244{
Michal Kazior590922a2014-10-21 10:10:29 +03002245 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2246
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247 switch (arvif->vdev_type) {
2248 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002249 if (sta->wme)
2250 arg->peer_flags |= WMI_PEER_QOS;
2251
2252 if (sta->wme && sta->uapsd_queues) {
2253 arg->peer_flags |= WMI_PEER_APSD;
2254 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2255 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002256 break;
2257 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002258 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002259 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002260 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002261 case WMI_VDEV_TYPE_IBSS:
2262 if (sta->wme)
2263 arg->peer_flags |= WMI_PEER_QOS;
2264 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002265 default:
2266 break;
2267 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002268
2269 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2270 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002271}
2272
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002273static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002274{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002275 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2276 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002277}
2278
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002280 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 struct ieee80211_sta *sta,
2282 struct wmi_peer_assoc_complete_arg *arg)
2283{
Michal Kazior500ff9f2015-03-31 10:26:21 +00002284 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2286
Michal Kazior500ff9f2015-03-31 10:26:21 +00002287 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2288 return;
2289
2290 switch (def.chan->band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002292 if (sta->vht_cap.vht_supported) {
2293 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2294 phymode = MODE_11AC_VHT40;
2295 else
2296 phymode = MODE_11AC_VHT20;
2297 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002298 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2299 phymode = MODE_11NG_HT40;
2300 else
2301 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002302 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002304 } else {
2305 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 }
2307
2308 break;
2309 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002310 /*
2311 * Check VHT first.
2312 */
2313 if (sta->vht_cap.vht_supported) {
2314 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2315 phymode = MODE_11AC_VHT80;
2316 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2317 phymode = MODE_11AC_VHT40;
2318 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2319 phymode = MODE_11AC_VHT20;
2320 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2322 phymode = MODE_11NA_HT40;
2323 else
2324 phymode = MODE_11NA_HT20;
2325 } else {
2326 phymode = MODE_11A;
2327 }
2328
2329 break;
2330 default:
2331 break;
2332 }
2333
Michal Kazior7aa7a722014-08-25 12:09:38 +02002334 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002335 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002336
Kalle Valo5e3dd152013-06-12 20:52:10 +03002337 arg->peer_phymode = phymode;
2338 WARN_ON(phymode == MODE_UNKNOWN);
2339}
2340
Kalle Valob9ada652013-10-16 15:44:46 +03002341static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002342 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002343 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002344 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002345{
Michal Kazior548db542013-07-05 16:15:15 +03002346 lockdep_assert_held(&ar->conf_mutex);
2347
Kalle Valob9ada652013-10-16 15:44:46 +03002348 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002349
Michal Kazior590922a2014-10-21 10:10:29 +03002350 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2351 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002352 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002353 ath10k_peer_assoc_h_ht(ar, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002354 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002355 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2356 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357
Kalle Valob9ada652013-10-16 15:44:46 +03002358 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002359}
2360
Michal Kazior90046f52014-02-14 14:45:51 +01002361static const u32 ath10k_smps_map[] = {
2362 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2363 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2364 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2365 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2366};
2367
2368static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2369 const u8 *addr,
2370 const struct ieee80211_sta_ht_cap *ht_cap)
2371{
2372 int smps;
2373
2374 if (!ht_cap->ht_supported)
2375 return 0;
2376
2377 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2378 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2379
2380 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2381 return -EINVAL;
2382
2383 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2384 WMI_PEER_SMPS_STATE,
2385 ath10k_smps_map[smps]);
2386}
2387
Michal Kazior139e1702015-02-15 16:50:42 +02002388static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2389 struct ieee80211_vif *vif,
2390 struct ieee80211_sta_vht_cap vht_cap)
2391{
2392 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2393 int ret;
2394 u32 param;
2395 u32 value;
2396
2397 if (!(ar->vht_cap_info &
2398 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2399 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2400 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2401 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2402 return 0;
2403
2404 param = ar->wmi.vdev_param->txbf;
2405 value = 0;
2406
2407 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2408 return 0;
2409
2410 /* The following logic is correct. If a remote STA advertises support
2411 * for being a beamformer then we should enable us being a beamformee.
2412 */
2413
2414 if (ar->vht_cap_info &
2415 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2416 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2417 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2418 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2419
2420 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2421 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2422 }
2423
2424 if (ar->vht_cap_info &
2425 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2426 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2427 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2428 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2429
2430 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2431 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2432 }
2433
2434 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2435 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2436
2437 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2438 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2439
2440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2441 if (ret) {
2442 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2443 value, ret);
2444 return ret;
2445 }
2446
2447 return 0;
2448}
2449
Kalle Valo5e3dd152013-06-12 20:52:10 +03002450/* can be called only in mac80211 callbacks due to `key_count` usage */
2451static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2452 struct ieee80211_vif *vif,
2453 struct ieee80211_bss_conf *bss_conf)
2454{
2455 struct ath10k *ar = hw->priv;
2456 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002457 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002458 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002459 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460 struct ieee80211_sta *ap_sta;
2461 int ret;
2462
Michal Kazior548db542013-07-05 16:15:15 +03002463 lockdep_assert_held(&ar->conf_mutex);
2464
Michal Kazior077efc82014-10-21 10:10:29 +03002465 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2466 arvif->vdev_id, arvif->bssid, arvif->aid);
2467
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 rcu_read_lock();
2469
2470 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2471 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002472 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002473 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002474 rcu_read_unlock();
2475 return;
2476 }
2477
Michal Kazior90046f52014-02-14 14:45:51 +01002478 /* ap_sta must be accessed only within rcu section which must be left
2479 * before calling ath10k_setup_peer_smps() which might sleep. */
2480 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002481 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002482
Michal Kazior590922a2014-10-21 10:10:29 +03002483 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002485 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002486 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002487 rcu_read_unlock();
2488 return;
2489 }
2490
2491 rcu_read_unlock();
2492
Kalle Valob9ada652013-10-16 15:44:46 +03002493 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002496 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002497 return;
2498 }
2499
Michal Kazior90046f52014-02-14 14:45:51 +01002500 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2501 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002502 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002503 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002504 return;
2505 }
2506
Michal Kazior139e1702015-02-15 16:50:42 +02002507 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2508 if (ret) {
2509 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2510 arvif->vdev_id, bss_conf->bssid, ret);
2511 return;
2512 }
2513
Michal Kazior7aa7a722014-08-25 12:09:38 +02002514 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002515 "mac vdev %d up (associated) bssid %pM aid %d\n",
2516 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2517
Michal Kazior077efc82014-10-21 10:10:29 +03002518 WARN_ON(arvif->is_up);
2519
Michal Kaziorc930f742014-01-23 11:38:25 +01002520 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002521 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002522
2523 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2524 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002525 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002526 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002527 return;
2528 }
2529
2530 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002531
2532 /* Workaround: Some firmware revisions (tested with qca6174
2533 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2534 * poked with peer param command.
2535 */
2536 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2537 WMI_PEER_DUMMY_VAR, 1);
2538 if (ret) {
2539 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2540 arvif->bssid, arvif->vdev_id, ret);
2541 return;
2542 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002543}
2544
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2546 struct ieee80211_vif *vif)
2547{
2548 struct ath10k *ar = hw->priv;
2549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002550 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551 int ret;
2552
Michal Kazior548db542013-07-05 16:15:15 +03002553 lockdep_assert_held(&ar->conf_mutex);
2554
Michal Kazior077efc82014-10-21 10:10:29 +03002555 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2556 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002557
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002559 if (ret)
2560 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2561 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002563 arvif->def_wep_key_idx = -1;
2564
Michal Kazior139e1702015-02-15 16:50:42 +02002565 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2566 if (ret) {
2567 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2568 arvif->vdev_id, ret);
2569 return;
2570 }
2571
Michal Kaziorc930f742014-01-23 11:38:25 +01002572 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002573
2574 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575}
2576
Michal Kazior590922a2014-10-21 10:10:29 +03002577static int ath10k_station_assoc(struct ath10k *ar,
2578 struct ieee80211_vif *vif,
2579 struct ieee80211_sta *sta,
2580 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002581{
Michal Kazior590922a2014-10-21 10:10:29 +03002582 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002583 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 int ret = 0;
2585
Michal Kazior548db542013-07-05 16:15:15 +03002586 lockdep_assert_held(&ar->conf_mutex);
2587
Michal Kazior590922a2014-10-21 10:10:29 +03002588 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002589 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002590 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002591 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002592 return ret;
2593 }
2594
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002595 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002596 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2597 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002598 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002599 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002600 return ret;
2601 }
2602
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002603 /* Re-assoc is run only to update supported rates for given station. It
2604 * doesn't make much sense to reconfigure the peer completely.
2605 */
2606 if (!reassoc) {
2607 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2608 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002609 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002610 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002611 arvif->vdev_id, ret);
2612 return ret;
2613 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002614
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002615 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2616 if (ret) {
2617 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2618 sta->addr, arvif->vdev_id, ret);
2619 return ret;
2620 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002621
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002622 if (!sta->wme) {
2623 arvif->num_legacy_stations++;
2624 ret = ath10k_recalc_rtscts_prot(arvif);
2625 if (ret) {
2626 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2627 arvif->vdev_id, ret);
2628 return ret;
2629 }
2630 }
2631
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002632 /* Plumb cached keys only for static WEP */
2633 if (arvif->def_wep_key_idx != -1) {
2634 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2635 if (ret) {
2636 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2637 arvif->vdev_id, ret);
2638 return ret;
2639 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002640 }
2641 }
2642
Kalle Valo5e3dd152013-06-12 20:52:10 +03002643 return ret;
2644}
2645
Michal Kazior590922a2014-10-21 10:10:29 +03002646static int ath10k_station_disassoc(struct ath10k *ar,
2647 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002648 struct ieee80211_sta *sta)
2649{
Michal Kazior590922a2014-10-21 10:10:29 +03002650 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002651 int ret = 0;
2652
2653 lockdep_assert_held(&ar->conf_mutex);
2654
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002655 if (!sta->wme) {
2656 arvif->num_legacy_stations--;
2657 ret = ath10k_recalc_rtscts_prot(arvif);
2658 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002659 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002660 arvif->vdev_id, ret);
2661 return ret;
2662 }
2663 }
2664
Kalle Valo5e3dd152013-06-12 20:52:10 +03002665 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2666 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002667 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002668 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669 return ret;
2670 }
2671
2672 return ret;
2673}
2674
2675/**************/
2676/* Regulatory */
2677/**************/
2678
2679static int ath10k_update_channel_list(struct ath10k *ar)
2680{
2681 struct ieee80211_hw *hw = ar->hw;
2682 struct ieee80211_supported_band **bands;
2683 enum ieee80211_band band;
2684 struct ieee80211_channel *channel;
2685 struct wmi_scan_chan_list_arg arg = {0};
2686 struct wmi_channel_arg *ch;
2687 bool passive;
2688 int len;
2689 int ret;
2690 int i;
2691
Michal Kazior548db542013-07-05 16:15:15 +03002692 lockdep_assert_held(&ar->conf_mutex);
2693
Kalle Valo5e3dd152013-06-12 20:52:10 +03002694 bands = hw->wiphy->bands;
2695 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2696 if (!bands[band])
2697 continue;
2698
2699 for (i = 0; i < bands[band]->n_channels; i++) {
2700 if (bands[band]->channels[i].flags &
2701 IEEE80211_CHAN_DISABLED)
2702 continue;
2703
2704 arg.n_channels++;
2705 }
2706 }
2707
2708 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2709 arg.channels = kzalloc(len, GFP_KERNEL);
2710 if (!arg.channels)
2711 return -ENOMEM;
2712
2713 ch = arg.channels;
2714 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2715 if (!bands[band])
2716 continue;
2717
2718 for (i = 0; i < bands[band]->n_channels; i++) {
2719 channel = &bands[band]->channels[i];
2720
2721 if (channel->flags & IEEE80211_CHAN_DISABLED)
2722 continue;
2723
2724 ch->allow_ht = true;
2725
2726 /* FIXME: when should we really allow VHT? */
2727 ch->allow_vht = true;
2728
2729 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002730 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731
2732 ch->ht40plus =
2733 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2734
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002735 ch->chan_radar =
2736 !!(channel->flags & IEEE80211_CHAN_RADAR);
2737
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002738 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002739 ch->passive = passive;
2740
2741 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002742 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002743 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002744 ch->max_power = channel->max_power * 2;
2745 ch->max_reg_power = channel->max_reg_power * 2;
2746 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002747 ch->reg_class_id = 0; /* FIXME */
2748
2749 /* FIXME: why use only legacy modes, why not any
2750 * HT/VHT modes? Would that even make any
2751 * difference? */
2752 if (channel->band == IEEE80211_BAND_2GHZ)
2753 ch->mode = MODE_11G;
2754 else
2755 ch->mode = MODE_11A;
2756
2757 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2758 continue;
2759
Michal Kazior7aa7a722014-08-25 12:09:38 +02002760 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002761 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2762 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763 ch->freq, ch->max_power, ch->max_reg_power,
2764 ch->max_antenna_gain, ch->mode);
2765
2766 ch++;
2767 }
2768 }
2769
2770 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2771 kfree(arg.channels);
2772
2773 return ret;
2774}
2775
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002776static enum wmi_dfs_region
2777ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2778{
2779 switch (dfs_region) {
2780 case NL80211_DFS_UNSET:
2781 return WMI_UNINIT_DFS_DOMAIN;
2782 case NL80211_DFS_FCC:
2783 return WMI_FCC_DFS_DOMAIN;
2784 case NL80211_DFS_ETSI:
2785 return WMI_ETSI_DFS_DOMAIN;
2786 case NL80211_DFS_JP:
2787 return WMI_MKK4_DFS_DOMAIN;
2788 }
2789 return WMI_UNINIT_DFS_DOMAIN;
2790}
2791
Michal Kaziorf7843d72013-07-16 09:38:52 +02002792static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002793{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002796 enum wmi_dfs_region wmi_dfs_reg;
2797 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002798
Michal Kaziorf7843d72013-07-16 09:38:52 +02002799 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800
2801 ret = ath10k_update_channel_list(ar);
2802 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002803 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002804
2805 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002806
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002807 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2808 nl_dfs_reg = ar->dfs_detector->region;
2809 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2810 } else {
2811 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2812 }
2813
Kalle Valo5e3dd152013-06-12 20:52:10 +03002814 /* Target allows setting up per-band regdomain but ath_common provides
2815 * a combined one only */
2816 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002817 regpair->reg_domain,
2818 regpair->reg_domain, /* 2ghz */
2819 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002821 regpair->reg_5ghz_ctl,
2822 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002823 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002824 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002825}
Michal Kazior548db542013-07-05 16:15:15 +03002826
Michal Kaziorf7843d72013-07-16 09:38:52 +02002827static void ath10k_reg_notifier(struct wiphy *wiphy,
2828 struct regulatory_request *request)
2829{
2830 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2831 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002832 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002833
2834 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2835
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002836 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002837 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002838 request->dfs_region);
2839 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2840 request->dfs_region);
2841 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002842 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002843 request->dfs_region);
2844 }
2845
Michal Kaziorf7843d72013-07-16 09:38:52 +02002846 mutex_lock(&ar->conf_mutex);
2847 if (ar->state == ATH10K_STATE_ON)
2848 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002849 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850}
2851
2852/***************/
2853/* TX handlers */
2854/***************/
2855
Michal Kazior96d828d2015-03-31 10:26:23 +00002856void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2857{
2858 lockdep_assert_held(&ar->htt.tx_lock);
2859
2860 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2861 ar->tx_paused |= BIT(reason);
2862 ieee80211_stop_queues(ar->hw);
2863}
2864
2865static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2866 struct ieee80211_vif *vif)
2867{
2868 struct ath10k *ar = data;
2869 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2870
2871 if (arvif->tx_paused)
2872 return;
2873
2874 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2875}
2876
2877void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2878{
2879 lockdep_assert_held(&ar->htt.tx_lock);
2880
2881 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2882 ar->tx_paused &= ~BIT(reason);
2883
2884 if (ar->tx_paused)
2885 return;
2886
2887 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2888 IEEE80211_IFACE_ITER_RESUME_ALL,
2889 ath10k_mac_tx_unlock_iter,
2890 ar);
2891}
2892
2893void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
2894{
2895 struct ath10k *ar = arvif->ar;
2896
2897 lockdep_assert_held(&ar->htt.tx_lock);
2898
2899 WARN_ON(reason >= BITS_PER_LONG);
2900 arvif->tx_paused |= BIT(reason);
2901 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
2902}
2903
2904void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
2905{
2906 struct ath10k *ar = arvif->ar;
2907
2908 lockdep_assert_held(&ar->htt.tx_lock);
2909
2910 WARN_ON(reason >= BITS_PER_LONG);
2911 arvif->tx_paused &= ~BIT(reason);
2912
2913 if (ar->tx_paused)
2914 return;
2915
2916 if (arvif->tx_paused)
2917 return;
2918
2919 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2920}
2921
Michal Kazior42c3aa62013-10-02 11:03:38 +02002922static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2923{
2924 if (ieee80211_is_mgmt(hdr->frame_control))
2925 return HTT_DATA_TX_EXT_TID_MGMT;
2926
2927 if (!ieee80211_is_data_qos(hdr->frame_control))
2928 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2929
2930 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2931 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2932
2933 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2934}
2935
Michal Kazior2b37c292014-09-02 11:00:22 +03002936static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002937{
Michal Kazior2b37c292014-09-02 11:00:22 +03002938 if (vif)
2939 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002940
Michal Kazior1bbc0972014-04-08 09:45:47 +03002941 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002942 return ar->monitor_vdev_id;
2943
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002945 return 0;
2946}
2947
Michal Kaziord740d8f2015-03-30 09:51:51 +03002948static enum ath10k_hw_txrx_mode
2949ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002950 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002951{
2952 const struct ieee80211_hdr *hdr = (void *)skb->data;
2953 __le16 fc = hdr->frame_control;
2954
2955 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2956 return ATH10K_HW_TXRX_RAW;
2957
2958 if (ieee80211_is_mgmt(fc))
2959 return ATH10K_HW_TXRX_MGMT;
2960
2961 /* Workaround:
2962 *
2963 * NullFunc frames are mostly used to ping if a client or AP are still
2964 * reachable and responsive. This implies tx status reports must be
2965 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2966 * come to a conclusion that the other end disappeared and tear down
2967 * BSS connection or it can never disconnect from BSS/client (which is
2968 * the case).
2969 *
2970 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2971 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2972 * which seems to deliver correct tx reports for NullFunc frames. The
2973 * downside of using it is it ignores client powersave state so it can
2974 * end up disconnecting sleeping clients in AP mode. It should fix STA
2975 * mode though because AP don't sleep.
2976 */
2977 if (ar->htt.target_version_major < 3 &&
2978 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2979 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2980 return ATH10K_HW_TXRX_MGMT;
2981
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002982 /* Workaround:
2983 *
2984 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2985 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2986 * to work with Ethernet txmode so use it.
2987 */
2988 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2989 return ATH10K_HW_TXRX_ETHERNET;
2990
Michal Kaziord740d8f2015-03-30 09:51:51 +03002991 return ATH10K_HW_TXRX_NATIVE_WIFI;
2992}
2993
Michal Kazior4b604552014-07-21 21:03:09 +03002994/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2995 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002996 */
Michal Kazior4b604552014-07-21 21:03:09 +03002997static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002998{
2999 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003000 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001 u8 *qos_ctl;
3002
3003 if (!ieee80211_is_data_qos(hdr->frame_control))
3004 return;
3005
3006 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003007 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3008 skb->data, (void *)qos_ctl - (void *)skb->data);
3009 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003010
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003011 /* Some firmware revisions don't handle sending QoS NullFunc well.
3012 * These frames are mainly used for CQM purposes so it doesn't really
3013 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003014 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003015 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003016 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003017 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003018
3019 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003020}
3021
Michal Kaziord740d8f2015-03-30 09:51:51 +03003022static void ath10k_tx_h_8023(struct sk_buff *skb)
3023{
3024 struct ieee80211_hdr *hdr;
3025 struct rfc1042_hdr *rfc1042;
3026 struct ethhdr *eth;
3027 size_t hdrlen;
3028 u8 da[ETH_ALEN];
3029 u8 sa[ETH_ALEN];
3030 __be16 type;
3031
3032 hdr = (void *)skb->data;
3033 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3034 rfc1042 = (void *)skb->data + hdrlen;
3035
3036 ether_addr_copy(da, ieee80211_get_DA(hdr));
3037 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3038 type = rfc1042->snap_type;
3039
3040 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3041 skb_push(skb, sizeof(*eth));
3042
3043 eth = (void *)skb->data;
3044 ether_addr_copy(eth->h_dest, da);
3045 ether_addr_copy(eth->h_source, sa);
3046 eth->h_proto = type;
3047}
3048
Michal Kazior4b604552014-07-21 21:03:09 +03003049static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3050 struct ieee80211_vif *vif,
3051 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003052{
3053 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003054 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3055
3056 /* This is case only for P2P_GO */
3057 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3058 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3059 return;
3060
3061 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3062 spin_lock_bh(&ar->data_lock);
3063 if (arvif->u.ap.noa_data)
3064 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3065 GFP_ATOMIC))
3066 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3067 arvif->u.ap.noa_data,
3068 arvif->u.ap.noa_len);
3069 spin_unlock_bh(&ar->data_lock);
3070 }
3071}
3072
Michal Kazior8d6d3622014-11-24 14:58:31 +01003073static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3074{
3075 /* FIXME: Not really sure since when the behaviour changed. At some
3076 * point new firmware stopped requiring creation of peer entries for
3077 * offchannel tx (and actually creating them causes issues with wmi-htc
3078 * tx credit replenishment and reliability). Assuming it's at least 3.4
3079 * because that's when the `freq` was introduced to TX_FRM HTT command.
3080 */
3081 return !(ar->htt.target_version_major >= 3 &&
3082 ar->htt.target_version_minor >= 4);
3083}
3084
Michal Kaziord740d8f2015-03-30 09:51:51 +03003085static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003086{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003087 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003088 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089
Michal Kaziord740d8f2015-03-30 09:51:51 +03003090 spin_lock_bh(&ar->data_lock);
3091
3092 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3093 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3094 ret = -ENOSPC;
3095 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003096 }
3097
Michal Kaziord740d8f2015-03-30 09:51:51 +03003098 __skb_queue_tail(q, skb);
3099 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3100
3101unlock:
3102 spin_unlock_bh(&ar->data_lock);
3103
3104 return ret;
3105}
3106
3107static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3108{
3109 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3110 struct ath10k_htt *htt = &ar->htt;
3111 int ret = 0;
3112
3113 switch (cb->txmode) {
3114 case ATH10K_HW_TXRX_RAW:
3115 case ATH10K_HW_TXRX_NATIVE_WIFI:
3116 case ATH10K_HW_TXRX_ETHERNET:
3117 ret = ath10k_htt_tx(htt, skb);
3118 break;
3119 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003120 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003121 ar->fw_features))
3122 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3123 else if (ar->htt.target_version_major >= 3)
3124 ret = ath10k_htt_tx(htt, skb);
3125 else
3126 ret = ath10k_htt_mgmt_tx(htt, skb);
3127 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003128 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129
3130 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003131 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3132 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003133 ieee80211_free_txskb(ar->hw, skb);
3134 }
3135}
3136
3137void ath10k_offchan_tx_purge(struct ath10k *ar)
3138{
3139 struct sk_buff *skb;
3140
3141 for (;;) {
3142 skb = skb_dequeue(&ar->offchan_tx_queue);
3143 if (!skb)
3144 break;
3145
3146 ieee80211_free_txskb(ar->hw, skb);
3147 }
3148}
3149
3150void ath10k_offchan_tx_work(struct work_struct *work)
3151{
3152 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3153 struct ath10k_peer *peer;
3154 struct ieee80211_hdr *hdr;
3155 struct sk_buff *skb;
3156 const u8 *peer_addr;
3157 int vdev_id;
3158 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003159 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003160
3161 /* FW requirement: We must create a peer before FW will send out
3162 * an offchannel frame. Otherwise the frame will be stuck and
3163 * never transmitted. We delete the peer upon tx completion.
3164 * It is unlikely that a peer for offchannel tx will already be
3165 * present. However it may be in some rare cases so account for that.
3166 * Otherwise we might remove a legitimate peer and break stuff. */
3167
3168 for (;;) {
3169 skb = skb_dequeue(&ar->offchan_tx_queue);
3170 if (!skb)
3171 break;
3172
3173 mutex_lock(&ar->conf_mutex);
3174
Michal Kazior7aa7a722014-08-25 12:09:38 +02003175 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003176 skb);
3177
3178 hdr = (struct ieee80211_hdr *)skb->data;
3179 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003180 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181
3182 spin_lock_bh(&ar->data_lock);
3183 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3184 spin_unlock_bh(&ar->data_lock);
3185
3186 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003187 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003188 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003189 peer_addr, vdev_id);
3190
3191 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003192 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3193 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003194 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003195 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003196 peer_addr, vdev_id, ret);
3197 }
3198
3199 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003200 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003201 ar->offchan_tx_skb = skb;
3202 spin_unlock_bh(&ar->data_lock);
3203
Michal Kaziord740d8f2015-03-30 09:51:51 +03003204 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003205
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003206 time_left =
3207 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3208 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003209 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210 skb);
3211
3212 if (!peer) {
3213 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3214 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003215 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 peer_addr, vdev_id, ret);
3217 }
3218
3219 mutex_unlock(&ar->conf_mutex);
3220 }
3221}
3222
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003223void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3224{
3225 struct sk_buff *skb;
3226
3227 for (;;) {
3228 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3229 if (!skb)
3230 break;
3231
3232 ieee80211_free_txskb(ar->hw, skb);
3233 }
3234}
3235
3236void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3237{
3238 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3239 struct sk_buff *skb;
3240 int ret;
3241
3242 for (;;) {
3243 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3244 if (!skb)
3245 break;
3246
3247 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003248 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003249 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003250 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003251 ieee80211_free_txskb(ar->hw, skb);
3252 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003253 }
3254}
3255
Kalle Valo5e3dd152013-06-12 20:52:10 +03003256/************/
3257/* Scanning */
3258/************/
3259
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003260void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003261{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003262 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003264 switch (ar->scan.state) {
3265 case ATH10K_SCAN_IDLE:
3266 break;
3267 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003268 if (ar->scan.is_roc)
3269 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003270 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003271 case ATH10K_SCAN_ABORTING:
3272 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003273 ieee80211_scan_completed(ar->hw,
3274 (ar->scan.state ==
3275 ATH10K_SCAN_ABORTING));
3276 /* fall through */
3277 case ATH10K_SCAN_STARTING:
3278 ar->scan.state = ATH10K_SCAN_IDLE;
3279 ar->scan_channel = NULL;
3280 ath10k_offchan_tx_purge(ar);
3281 cancel_delayed_work(&ar->scan.timeout);
3282 complete_all(&ar->scan.completed);
3283 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003284 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003285}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003286
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003287void ath10k_scan_finish(struct ath10k *ar)
3288{
3289 spin_lock_bh(&ar->data_lock);
3290 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003291 spin_unlock_bh(&ar->data_lock);
3292}
3293
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003294static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003295{
3296 struct wmi_stop_scan_arg arg = {
3297 .req_id = 1, /* FIXME */
3298 .req_type = WMI_SCAN_STOP_ONE,
3299 .u.scan_id = ATH10K_SCAN_ID,
3300 };
3301 int ret;
3302
3303 lockdep_assert_held(&ar->conf_mutex);
3304
Kalle Valo5e3dd152013-06-12 20:52:10 +03003305 ret = ath10k_wmi_stop_scan(ar, &arg);
3306 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003307 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003308 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309 }
3310
Kalle Valo5e3dd152013-06-12 20:52:10 +03003311 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003312 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003313 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003314 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003315 } else if (ret > 0) {
3316 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003318
3319out:
3320 /* Scan state should be updated upon scan completion but in case
3321 * firmware fails to deliver the event (for whatever reason) it is
3322 * desired to clean up scan state anyway. Firmware may have just
3323 * dropped the scan completion event delivery due to transport pipe
3324 * being overflown with data and/or it can recover on its own before
3325 * next scan request is submitted.
3326 */
3327 spin_lock_bh(&ar->data_lock);
3328 if (ar->scan.state != ATH10K_SCAN_IDLE)
3329 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003330 spin_unlock_bh(&ar->data_lock);
3331
3332 return ret;
3333}
3334
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003335static void ath10k_scan_abort(struct ath10k *ar)
3336{
3337 int ret;
3338
3339 lockdep_assert_held(&ar->conf_mutex);
3340
3341 spin_lock_bh(&ar->data_lock);
3342
3343 switch (ar->scan.state) {
3344 case ATH10K_SCAN_IDLE:
3345 /* This can happen if timeout worker kicked in and called
3346 * abortion while scan completion was being processed.
3347 */
3348 break;
3349 case ATH10K_SCAN_STARTING:
3350 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003351 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003352 ath10k_scan_state_str(ar->scan.state),
3353 ar->scan.state);
3354 break;
3355 case ATH10K_SCAN_RUNNING:
3356 ar->scan.state = ATH10K_SCAN_ABORTING;
3357 spin_unlock_bh(&ar->data_lock);
3358
3359 ret = ath10k_scan_stop(ar);
3360 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003361 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003362
3363 spin_lock_bh(&ar->data_lock);
3364 break;
3365 }
3366
3367 spin_unlock_bh(&ar->data_lock);
3368}
3369
3370void ath10k_scan_timeout_work(struct work_struct *work)
3371{
3372 struct ath10k *ar = container_of(work, struct ath10k,
3373 scan.timeout.work);
3374
3375 mutex_lock(&ar->conf_mutex);
3376 ath10k_scan_abort(ar);
3377 mutex_unlock(&ar->conf_mutex);
3378}
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380static int ath10k_start_scan(struct ath10k *ar,
3381 const struct wmi_start_scan_arg *arg)
3382{
3383 int ret;
3384
3385 lockdep_assert_held(&ar->conf_mutex);
3386
3387 ret = ath10k_wmi_start_scan(ar, arg);
3388 if (ret)
3389 return ret;
3390
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3392 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003393 ret = ath10k_scan_stop(ar);
3394 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003395 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003396
3397 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398 }
3399
Ben Greear2f9eec02015-02-15 16:50:38 +02003400 /* If we failed to start the scan, return error code at
3401 * this point. This is probably due to some issue in the
3402 * firmware, but no need to wedge the driver due to that...
3403 */
3404 spin_lock_bh(&ar->data_lock);
3405 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3406 spin_unlock_bh(&ar->data_lock);
3407 return -EINVAL;
3408 }
3409 spin_unlock_bh(&ar->data_lock);
3410
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003411 /* Add a 200ms margin to account for event/command processing */
3412 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3413 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003414 return 0;
3415}
3416
3417/**********************/
3418/* mac80211 callbacks */
3419/**********************/
3420
3421static void ath10k_tx(struct ieee80211_hw *hw,
3422 struct ieee80211_tx_control *control,
3423 struct sk_buff *skb)
3424{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003426 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3427 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003428 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003429 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003430 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003431
3432 /* We should disable CCK RATE due to P2P */
3433 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003434 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003435
Michal Kazior4b604552014-07-21 21:03:09 +03003436 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003437 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003438 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003439 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003440 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003441 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003442
Michal Kaziord740d8f2015-03-30 09:51:51 +03003443 switch (ATH10K_SKB_CB(skb)->txmode) {
3444 case ATH10K_HW_TXRX_MGMT:
3445 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003446 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003447 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3448 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003449 break;
3450 case ATH10K_HW_TXRX_ETHERNET:
3451 ath10k_tx_h_8023(skb);
3452 break;
3453 case ATH10K_HW_TXRX_RAW:
3454 /* FIXME: Packet injection isn't implemented. It should be
3455 * doable with firmware 10.2 on qca988x.
3456 */
3457 WARN_ON_ONCE(1);
3458 ieee80211_free_txskb(hw, skb);
3459 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003460 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003461
Kalle Valo5e3dd152013-06-12 20:52:10 +03003462 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3463 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003464 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003465 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466 spin_unlock_bh(&ar->data_lock);
3467
Michal Kazior8d6d3622014-11-24 14:58:31 +01003468 if (ath10k_mac_need_offchan_tx_work(ar)) {
3469 ATH10K_SKB_CB(skb)->htt.freq = 0;
3470 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003471
Michal Kazior8d6d3622014-11-24 14:58:31 +01003472 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3473 skb);
3474
3475 skb_queue_tail(&ar->offchan_tx_queue, skb);
3476 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3477 return;
3478 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479 }
3480
Michal Kaziord740d8f2015-03-30 09:51:51 +03003481 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482}
3483
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003484/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003485void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003486{
3487 /* make sure rcu-protected mac80211 tx path itself is drained */
3488 synchronize_net();
3489
3490 ath10k_offchan_tx_purge(ar);
3491 ath10k_mgmt_over_wmi_tx_purge(ar);
3492
3493 cancel_work_sync(&ar->offchan_tx_work);
3494 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3495}
3496
Michal Kazioraffd3212013-07-16 09:54:35 +02003497void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003498{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003499 struct ath10k_vif *arvif;
3500
Michal Kazior818bdd12013-07-16 09:38:57 +02003501 lockdep_assert_held(&ar->conf_mutex);
3502
Michal Kazior19337472014-08-28 12:58:16 +02003503 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3504 ar->filter_flags = 0;
3505 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003506 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003507
3508 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003509 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003510
3511 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003512 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003513
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003514 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003515 ath10k_peer_cleanup_all(ar);
3516 ath10k_core_stop(ar);
3517 ath10k_hif_power_down(ar);
3518
3519 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003520 list_for_each_entry(arvif, &ar->arvifs, list)
3521 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003522 spin_unlock_bh(&ar->data_lock);
3523}
3524
Ben Greear46acf7b2014-05-16 17:15:38 +03003525static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3526{
3527 struct ath10k *ar = hw->priv;
3528
3529 mutex_lock(&ar->conf_mutex);
3530
3531 if (ar->cfg_tx_chainmask) {
3532 *tx_ant = ar->cfg_tx_chainmask;
3533 *rx_ant = ar->cfg_rx_chainmask;
3534 } else {
3535 *tx_ant = ar->supp_tx_chainmask;
3536 *rx_ant = ar->supp_rx_chainmask;
3537 }
3538
3539 mutex_unlock(&ar->conf_mutex);
3540
3541 return 0;
3542}
3543
Ben Greear5572a952014-11-24 16:22:10 +02003544static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3545{
3546 /* It is not clear that allowing gaps in chainmask
3547 * is helpful. Probably it will not do what user
3548 * is hoping for, so warn in that case.
3549 */
3550 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3551 return;
3552
3553 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3554 dbg, cm);
3555}
3556
Ben Greear46acf7b2014-05-16 17:15:38 +03003557static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3558{
3559 int ret;
3560
3561 lockdep_assert_held(&ar->conf_mutex);
3562
Ben Greear5572a952014-11-24 16:22:10 +02003563 ath10k_check_chain_mask(ar, tx_ant, "tx");
3564 ath10k_check_chain_mask(ar, rx_ant, "rx");
3565
Ben Greear46acf7b2014-05-16 17:15:38 +03003566 ar->cfg_tx_chainmask = tx_ant;
3567 ar->cfg_rx_chainmask = rx_ant;
3568
3569 if ((ar->state != ATH10K_STATE_ON) &&
3570 (ar->state != ATH10K_STATE_RESTARTED))
3571 return 0;
3572
3573 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3574 tx_ant);
3575 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003576 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003577 ret, tx_ant);
3578 return ret;
3579 }
3580
3581 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3582 rx_ant);
3583 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003584 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003585 ret, rx_ant);
3586 return ret;
3587 }
3588
3589 return 0;
3590}
3591
3592static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3593{
3594 struct ath10k *ar = hw->priv;
3595 int ret;
3596
3597 mutex_lock(&ar->conf_mutex);
3598 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3599 mutex_unlock(&ar->conf_mutex);
3600 return ret;
3601}
3602
Kalle Valo5e3dd152013-06-12 20:52:10 +03003603static int ath10k_start(struct ieee80211_hw *hw)
3604{
3605 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003606 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003607
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003608 /*
3609 * This makes sense only when restarting hw. It is harmless to call
3610 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3611 * commands will be submitted while restarting.
3612 */
3613 ath10k_drain_tx(ar);
3614
Michal Kazior548db542013-07-05 16:15:15 +03003615 mutex_lock(&ar->conf_mutex);
3616
Michal Kaziorc5058f52014-05-26 12:46:03 +03003617 switch (ar->state) {
3618 case ATH10K_STATE_OFF:
3619 ar->state = ATH10K_STATE_ON;
3620 break;
3621 case ATH10K_STATE_RESTARTING:
3622 ath10k_halt(ar);
3623 ar->state = ATH10K_STATE_RESTARTED;
3624 break;
3625 case ATH10K_STATE_ON:
3626 case ATH10K_STATE_RESTARTED:
3627 case ATH10K_STATE_WEDGED:
3628 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003629 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003630 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003631 case ATH10K_STATE_UTF:
3632 ret = -EBUSY;
3633 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003634 }
3635
3636 ret = ath10k_hif_power_up(ar);
3637 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003638 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003639 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003640 }
3641
Kalle Valo43d2a302014-09-10 18:23:30 +03003642 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003643 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003644 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003645 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003646 }
3647
Bartosz Markowski226a3392013-09-26 17:47:16 +02003648 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003649 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003650 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003651 goto err_core_stop;
3652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003653
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003654 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003655 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003656 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003657 goto err_core_stop;
3658 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659
Ben Greear46acf7b2014-05-16 17:15:38 +03003660 if (ar->cfg_tx_chainmask)
3661 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3662 ar->cfg_rx_chainmask);
3663
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003664 /*
3665 * By default FW set ARP frames ac to voice (6). In that case ARP
3666 * exchange is not working properly for UAPSD enabled AP. ARP requests
3667 * which arrives with access category 0 are processed by network stack
3668 * and send back with access category 0, but FW changes access category
3669 * to 6. Set ARP frames access category to best effort (0) solves
3670 * this problem.
3671 */
3672
3673 ret = ath10k_wmi_pdev_set_param(ar,
3674 ar->wmi.pdev_param->arp_ac_override, 0);
3675 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003676 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003677 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003678 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003679 }
3680
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303681 ret = ath10k_wmi_pdev_set_param(ar,
3682 ar->wmi.pdev_param->ani_enable, 1);
3683 if (ret) {
3684 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3685 ret);
3686 goto err_core_stop;
3687 }
3688
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303689 ar->ani_enabled = true;
3690
Michal Kaziord6500972014-04-08 09:56:09 +03003691 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003692 ath10k_regd_update(ar);
3693
Simon Wunderlich855aed12014-08-02 09:12:54 +03003694 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303695 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003696
Michal Kaziorae254432014-05-26 12:46:02 +03003697 mutex_unlock(&ar->conf_mutex);
3698 return 0;
3699
3700err_core_stop:
3701 ath10k_core_stop(ar);
3702
3703err_power_down:
3704 ath10k_hif_power_down(ar);
3705
3706err_off:
3707 ar->state = ATH10K_STATE_OFF;
3708
3709err:
Michal Kazior548db542013-07-05 16:15:15 +03003710 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003711 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003712}
3713
3714static void ath10k_stop(struct ieee80211_hw *hw)
3715{
3716 struct ath10k *ar = hw->priv;
3717
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003718 ath10k_drain_tx(ar);
3719
Michal Kazior548db542013-07-05 16:15:15 +03003720 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003721 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003722 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003723 ar->state = ATH10K_STATE_OFF;
3724 }
Michal Kazior548db542013-07-05 16:15:15 +03003725 mutex_unlock(&ar->conf_mutex);
3726
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003727 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003728 cancel_work_sync(&ar->restart_work);
3729}
3730
Michal Kaziorad088bf2013-10-16 15:44:46 +03003731static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003732{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003733 struct ath10k_vif *arvif;
3734 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003735
3736 lockdep_assert_held(&ar->conf_mutex);
3737
Michal Kaziorad088bf2013-10-16 15:44:46 +03003738 list_for_each_entry(arvif, &ar->arvifs, list) {
3739 ret = ath10k_mac_vif_setup_ps(arvif);
3740 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003741 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003742 break;
3743 }
3744 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003745
Michal Kaziorad088bf2013-10-16 15:44:46 +03003746 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003747}
3748
Michal Kazior500ff9f2015-03-31 10:26:21 +00003749static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003750{
3751 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003752 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003753 int ret;
3754
3755 lockdep_assert_held(&ar->conf_mutex);
3756
Michal Kazior500ff9f2015-03-31 10:26:21 +00003757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003758
3759 /* First stop monitor interface. Some FW versions crash if there's a
3760 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003761 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003762 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003763
3764 list_for_each_entry(arvif, &ar->arvifs, list) {
3765 if (!arvif->is_started)
3766 continue;
3767
Michal Kaziordc55e302014-07-29 12:53:36 +03003768 if (!arvif->is_up)
3769 continue;
3770
Michal Kaziorc930f742014-01-23 11:38:25 +01003771 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3772 continue;
3773
Michal Kaziordc55e302014-07-29 12:53:36 +03003774 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003775 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003776 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003777 arvif->vdev_id, ret);
3778 continue;
3779 }
3780 }
3781
Michal Kaziordc55e302014-07-29 12:53:36 +03003782 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003783
3784 list_for_each_entry(arvif, &ar->arvifs, list) {
3785 if (!arvif->is_started)
3786 continue;
3787
3788 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3789 continue;
3790
Michal Kazior81a9a172015-03-05 16:02:17 +02003791 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3792 if (ret)
3793 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3794 ret);
3795
3796 ret = ath10k_mac_setup_prb_tmpl(arvif);
3797 if (ret)
3798 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3799 ret);
3800
Michal Kazior500ff9f2015-03-31 10:26:21 +00003801 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3802 continue;
3803
3804 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003805 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003806 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003807 arvif->vdev_id, ret);
3808 continue;
3809 }
3810
3811 if (!arvif->is_up)
3812 continue;
3813
3814 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3815 arvif->bssid);
3816 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003817 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003818 arvif->vdev_id, ret);
3819 continue;
3820 }
3821 }
3822
Michal Kazior19337472014-08-28 12:58:16 +02003823 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003824}
3825
Michal Kazior7d9d5582014-10-21 10:40:15 +03003826static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3827{
3828 int ret;
3829 u32 param;
3830
3831 lockdep_assert_held(&ar->conf_mutex);
3832
3833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3834
3835 param = ar->wmi.pdev_param->txpower_limit2g;
3836 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3837 if (ret) {
3838 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3839 txpower, ret);
3840 return ret;
3841 }
3842
3843 param = ar->wmi.pdev_param->txpower_limit5g;
3844 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3845 if (ret) {
3846 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3847 txpower, ret);
3848 return ret;
3849 }
3850
3851 return 0;
3852}
3853
3854static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3855{
3856 struct ath10k_vif *arvif;
3857 int ret, txpower = -1;
3858
3859 lockdep_assert_held(&ar->conf_mutex);
3860
3861 list_for_each_entry(arvif, &ar->arvifs, list) {
3862 WARN_ON(arvif->txpower < 0);
3863
3864 if (txpower == -1)
3865 txpower = arvif->txpower;
3866 else
3867 txpower = min(txpower, arvif->txpower);
3868 }
3869
3870 if (WARN_ON(txpower == -1))
3871 return -EINVAL;
3872
3873 ret = ath10k_mac_txpower_setup(ar, txpower);
3874 if (ret) {
3875 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3876 txpower, ret);
3877 return ret;
3878 }
3879
3880 return 0;
3881}
3882
Kalle Valo5e3dd152013-06-12 20:52:10 +03003883static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3884{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003885 struct ath10k *ar = hw->priv;
3886 struct ieee80211_conf *conf = &hw->conf;
3887 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888
3889 mutex_lock(&ar->conf_mutex);
3890
Michal Kazioraffd3212013-07-16 09:54:35 +02003891 if (changed & IEEE80211_CONF_CHANGE_PS)
3892 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893
3894 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003895 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3896 ret = ath10k_monitor_recalc(ar);
3897 if (ret)
3898 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003899 }
3900
3901 mutex_unlock(&ar->conf_mutex);
3902 return ret;
3903}
3904
Ben Greear5572a952014-11-24 16:22:10 +02003905static u32 get_nss_from_chainmask(u16 chain_mask)
3906{
3907 if ((chain_mask & 0x15) == 0x15)
3908 return 4;
3909 else if ((chain_mask & 0x7) == 0x7)
3910 return 3;
3911 else if ((chain_mask & 0x3) == 0x3)
3912 return 2;
3913 return 1;
3914}
3915
Kalle Valo5e3dd152013-06-12 20:52:10 +03003916/*
3917 * TODO:
3918 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3919 * because we will send mgmt frames without CCK. This requirement
3920 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3921 * in the TX packet.
3922 */
3923static int ath10k_add_interface(struct ieee80211_hw *hw,
3924 struct ieee80211_vif *vif)
3925{
3926 struct ath10k *ar = hw->priv;
3927 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3928 enum wmi_sta_powersave_param param;
3929 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003930 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003931 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00003932 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003933 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003934
Johannes Berg848955c2014-11-11 12:48:42 +01003935 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3936
Kalle Valo5e3dd152013-06-12 20:52:10 +03003937 mutex_lock(&ar->conf_mutex);
3938
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003939 memset(arvif, 0, sizeof(*arvif));
3940
Kalle Valo5e3dd152013-06-12 20:52:10 +03003941 arvif->ar = ar;
3942 arvif->vif = vif;
3943
Ben Greeare63b33f2013-10-22 14:54:14 -07003944 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003945 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003946 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3947 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003948
Ben Greeara9aefb32014-08-12 11:02:19 +03003949 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003950 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003951 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003952 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003953 }
Ben Greear16c11172014-09-23 14:17:16 -07003954 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955
Ben Greear16c11172014-09-23 14:17:16 -07003956 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3957 bit, ar->free_vdev_map);
3958
3959 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003960 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003961
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003963 case NL80211_IFTYPE_P2P_DEVICE:
3964 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3965 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3966 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003967 case NL80211_IFTYPE_UNSPECIFIED:
3968 case NL80211_IFTYPE_STATION:
3969 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3970 if (vif->p2p)
3971 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3972 break;
3973 case NL80211_IFTYPE_ADHOC:
3974 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3975 break;
3976 case NL80211_IFTYPE_AP:
3977 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3978
3979 if (vif->p2p)
3980 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3981 break;
3982 case NL80211_IFTYPE_MONITOR:
3983 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3984 break;
3985 default:
3986 WARN_ON(1);
3987 break;
3988 }
3989
Michal Kazior96d828d2015-03-31 10:26:23 +00003990 /* Using vdev_id as queue number will make it very easy to do per-vif
3991 * tx queue locking. This shouldn't wrap due to interface combinations
3992 * but do a modulo for correctness sake and prevent using offchannel tx
3993 * queues for regular vif tx.
3994 */
3995 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
3996 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
3997 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
3998
Michal Kazior64badcb2014-09-18 11:18:02 +03003999 /* Some firmware revisions don't wait for beacon tx completion before
4000 * sending another SWBA event. This could lead to hardware using old
4001 * (freed) beacon data in some cases, e.g. tx credit starvation
4002 * combined with missed TBTT. This is very very rare.
4003 *
4004 * On non-IOMMU-enabled hosts this could be a possible security issue
4005 * because hw could beacon some random data on the air. On
4006 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4007 * device would crash.
4008 *
4009 * Since there are no beacon tx completions (implicit nor explicit)
4010 * propagated to host the only workaround for this is to allocate a
4011 * DMA-coherent buffer for a lifetime of a vif and use it for all
4012 * beacon tx commands. Worst case for this approach is some beacons may
4013 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4014 */
4015 if (vif->type == NL80211_IFTYPE_ADHOC ||
4016 vif->type == NL80211_IFTYPE_AP) {
4017 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4018 IEEE80211_MAX_FRAME_LEN,
4019 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304020 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004021 if (!arvif->beacon_buf) {
4022 ret = -ENOMEM;
4023 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4024 ret);
4025 goto err;
4026 }
4027 }
4028
4029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4030 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4031 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004032
4033 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4034 arvif->vdev_subtype, vif->addr);
4035 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004036 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004037 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004038 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004039 }
4040
Ben Greear16c11172014-09-23 14:17:16 -07004041 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004042 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004043
Michal Kazior46725b152015-01-28 09:57:49 +02004044 /* It makes no sense to have firmware do keepalives. mac80211 already
4045 * takes care of this with idle connection polling.
4046 */
4047 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004048 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004049 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004050 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004051 goto err_vdev_delete;
4052 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004053
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004054 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004055
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004056 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4057 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004058 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004059 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004060 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004061 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004062 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004063 goto err_vdev_delete;
4064 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004065
Ben Greear5572a952014-11-24 16:22:10 +02004066 if (ar->cfg_tx_chainmask) {
4067 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4068
4069 vdev_param = ar->wmi.vdev_param->nss;
4070 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4071 nss);
4072 if (ret) {
4073 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4074 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4075 ret);
4076 goto err_vdev_delete;
4077 }
4078 }
4079
Kalle Valo5e3dd152013-06-12 20:52:10 +03004080 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004081 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4082 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004084 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004085 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004086 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004087 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004088
Kalle Valo5a13e762014-01-20 11:01:46 +02004089 ret = ath10k_mac_set_kickout(arvif);
4090 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004091 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004092 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004093 goto err_peer_delete;
4094 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004095 }
4096
4097 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4098 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4099 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4100 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4101 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004102 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004103 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004104 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004105 goto err_peer_delete;
4106 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004107
Michal Kazior9f9b5742014-12-12 12:41:36 +01004108 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004109 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004110 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004111 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004112 goto err_peer_delete;
4113 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004114
Michal Kazior9f9b5742014-12-12 12:41:36 +01004115 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004116 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004117 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004118 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004119 goto err_peer_delete;
4120 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004121 }
4122
Michal Kazior424121c2013-07-22 14:13:31 +02004123 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004124 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004125 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004126 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004127 goto err_peer_delete;
4128 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004129
Michal Kazior424121c2013-07-22 14:13:31 +02004130 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004131 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004132 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004133 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004134 goto err_peer_delete;
4135 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004136
Michal Kazior7d9d5582014-10-21 10:40:15 +03004137 arvif->txpower = vif->bss_conf.txpower;
4138 ret = ath10k_mac_txpower_recalc(ar);
4139 if (ret) {
4140 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4141 goto err_peer_delete;
4142 }
4143
Michal Kazior500ff9f2015-03-31 10:26:21 +00004144 if (vif->type == NL80211_IFTYPE_MONITOR) {
4145 ar->monitor_arvif = arvif;
4146 ret = ath10k_monitor_recalc(ar);
4147 if (ret) {
4148 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4149 goto err_peer_delete;
4150 }
4151 }
4152
Kalle Valo5e3dd152013-06-12 20:52:10 +03004153 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004154 return 0;
4155
4156err_peer_delete:
4157 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
4158 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4159
4160err_vdev_delete:
4161 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004162 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004163 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004164
4165err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004166 if (arvif->beacon_buf) {
4167 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4168 arvif->beacon_buf, arvif->beacon_paddr);
4169 arvif->beacon_buf = NULL;
4170 }
4171
Michal Kazior9dad14a2013-10-16 15:44:45 +03004172 mutex_unlock(&ar->conf_mutex);
4173
Kalle Valo5e3dd152013-06-12 20:52:10 +03004174 return ret;
4175}
4176
4177static void ath10k_remove_interface(struct ieee80211_hw *hw,
4178 struct ieee80211_vif *vif)
4179{
4180 struct ath10k *ar = hw->priv;
4181 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4182 int ret;
4183
Michal Kazior81a9a172015-03-05 16:02:17 +02004184 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004185 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004186
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304187 mutex_lock(&ar->conf_mutex);
4188
Michal Kaziored543882013-09-13 14:16:56 +02004189 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004190 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004191 spin_unlock_bh(&ar->data_lock);
4192
Simon Wunderlich855aed12014-08-02 09:12:54 +03004193 ret = ath10k_spectral_vif_stop(arvif);
4194 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004195 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004196 arvif->vdev_id, ret);
4197
Ben Greear16c11172014-09-23 14:17:16 -07004198 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004199 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004200
4201 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02004202 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4203 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02004205 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004206 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004207
4208 kfree(arvif->u.ap.noa_data);
4209 }
4210
Michal Kazior7aa7a722014-08-25 12:09:38 +02004211 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004212 arvif->vdev_id);
4213
Kalle Valo5e3dd152013-06-12 20:52:10 +03004214 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4215 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004216 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004217 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004218
Michal Kazior2c512052015-02-15 16:50:40 +02004219 /* Some firmware revisions don't notify host about self-peer removal
4220 * until after associated vdev is deleted.
4221 */
4222 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4223 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4224 vif->addr);
4225 if (ret)
4226 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4227 arvif->vdev_id, ret);
4228
4229 spin_lock_bh(&ar->data_lock);
4230 ar->num_peers--;
4231 spin_unlock_bh(&ar->data_lock);
4232 }
4233
Kalle Valo5e3dd152013-06-12 20:52:10 +03004234 ath10k_peer_cleanup(ar, arvif->vdev_id);
4235
Michal Kazior500ff9f2015-03-31 10:26:21 +00004236 if (vif->type == NL80211_IFTYPE_MONITOR) {
4237 ar->monitor_arvif = NULL;
4238 ret = ath10k_monitor_recalc(ar);
4239 if (ret)
4240 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4241 }
4242
Kalle Valo5e3dd152013-06-12 20:52:10 +03004243 mutex_unlock(&ar->conf_mutex);
4244}
4245
4246/*
4247 * FIXME: Has to be verified.
4248 */
4249#define SUPPORTED_FILTERS \
4250 (FIF_PROMISC_IN_BSS | \
4251 FIF_ALLMULTI | \
4252 FIF_CONTROL | \
4253 FIF_PSPOLL | \
4254 FIF_OTHER_BSS | \
4255 FIF_BCN_PRBRESP_PROMISC | \
4256 FIF_PROBE_REQ | \
4257 FIF_FCSFAIL)
4258
4259static void ath10k_configure_filter(struct ieee80211_hw *hw,
4260 unsigned int changed_flags,
4261 unsigned int *total_flags,
4262 u64 multicast)
4263{
4264 struct ath10k *ar = hw->priv;
4265 int ret;
4266
4267 mutex_lock(&ar->conf_mutex);
4268
4269 changed_flags &= SUPPORTED_FILTERS;
4270 *total_flags &= SUPPORTED_FILTERS;
4271 ar->filter_flags = *total_flags;
4272
Michal Kazior19337472014-08-28 12:58:16 +02004273 ret = ath10k_monitor_recalc(ar);
4274 if (ret)
4275 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004276
4277 mutex_unlock(&ar->conf_mutex);
4278}
4279
4280static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4281 struct ieee80211_vif *vif,
4282 struct ieee80211_bss_conf *info,
4283 u32 changed)
4284{
4285 struct ath10k *ar = hw->priv;
4286 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4287 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004288 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004289
4290 mutex_lock(&ar->conf_mutex);
4291
4292 if (changed & BSS_CHANGED_IBSS)
4293 ath10k_control_ibss(arvif, info, vif->addr);
4294
4295 if (changed & BSS_CHANGED_BEACON_INT) {
4296 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004297 vdev_param = ar->wmi.vdev_param->beacon_interval;
4298 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004300 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004301 "mac vdev %d beacon_interval %d\n",
4302 arvif->vdev_id, arvif->beacon_interval);
4303
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004305 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004306 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307 }
4308
4309 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004310 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004311 "vdev %d set beacon tx mode to staggered\n",
4312 arvif->vdev_id);
4313
Bartosz Markowski226a3392013-09-26 17:47:16 +02004314 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4315 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004316 WMI_BEACON_STAGGERED_MODE);
4317 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004318 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004319 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004320
4321 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4322 if (ret)
4323 ath10k_warn(ar, "failed to update beacon template: %d\n",
4324 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004325 }
4326
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004327 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4328 ret = ath10k_mac_setup_prb_tmpl(arvif);
4329 if (ret)
4330 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4331 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004332 }
4333
Michal Kaziorba2479f2015-01-24 12:14:51 +02004334 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004335 arvif->dtim_period = info->dtim_period;
4336
Michal Kazior7aa7a722014-08-25 12:09:38 +02004337 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004338 "mac vdev %d dtim_period %d\n",
4339 arvif->vdev_id, arvif->dtim_period);
4340
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004341 vdev_param = ar->wmi.vdev_param->dtim_period;
4342 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004343 arvif->dtim_period);
4344 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004345 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004346 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004347 }
4348
4349 if (changed & BSS_CHANGED_SSID &&
4350 vif->type == NL80211_IFTYPE_AP) {
4351 arvif->u.ap.ssid_len = info->ssid_len;
4352 if (info->ssid_len)
4353 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4354 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4355 }
4356
Michal Kazior077efc82014-10-21 10:10:29 +03004357 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4358 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004359
4360 if (changed & BSS_CHANGED_BEACON_ENABLED)
4361 ath10k_control_beaconing(arvif, info);
4362
4363 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004364 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004365 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004366 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004367
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004368 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004369 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004370 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004371 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004372
4373 vdev_param = ar->wmi.vdev_param->protection_mode;
4374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4375 info->use_cts_prot ? 1 : 0);
4376 if (ret)
4377 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4378 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004379 }
4380
4381 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004382 if (info->use_short_slot)
4383 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4384
4385 else
4386 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4387
Michal Kazior7aa7a722014-08-25 12:09:38 +02004388 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004389 arvif->vdev_id, slottime);
4390
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004391 vdev_param = ar->wmi.vdev_param->slot_time;
4392 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004393 slottime);
4394 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004395 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004396 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004397 }
4398
4399 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004400 if (info->use_short_preamble)
4401 preamble = WMI_VDEV_PREAMBLE_SHORT;
4402 else
4403 preamble = WMI_VDEV_PREAMBLE_LONG;
4404
Michal Kazior7aa7a722014-08-25 12:09:38 +02004405 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004406 "mac vdev %d preamble %dn",
4407 arvif->vdev_id, preamble);
4408
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004409 vdev_param = ar->wmi.vdev_param->preamble;
4410 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004411 preamble);
4412 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004413 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004414 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004415 }
4416
4417 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004418 if (info->assoc) {
4419 /* Workaround: Make sure monitor vdev is not running
4420 * when associating to prevent some firmware revisions
4421 * (e.g. 10.1 and 10.2) from crashing.
4422 */
4423 if (ar->monitor_started)
4424 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004425 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004426 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004427 } else {
4428 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004429 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004430 }
4431
Michal Kazior7d9d5582014-10-21 10:40:15 +03004432 if (changed & BSS_CHANGED_TXPOWER) {
4433 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4434 arvif->vdev_id, info->txpower);
4435
4436 arvif->txpower = info->txpower;
4437 ret = ath10k_mac_txpower_recalc(ar);
4438 if (ret)
4439 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4440 }
4441
Michal Kaziorbf14e652014-12-12 12:41:38 +01004442 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004443 arvif->ps = vif->bss_conf.ps;
4444
4445 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004446 if (ret)
4447 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4448 arvif->vdev_id, ret);
4449 }
4450
Kalle Valo5e3dd152013-06-12 20:52:10 +03004451 mutex_unlock(&ar->conf_mutex);
4452}
4453
4454static int ath10k_hw_scan(struct ieee80211_hw *hw,
4455 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004456 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004457{
4458 struct ath10k *ar = hw->priv;
4459 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004460 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004461 struct wmi_start_scan_arg arg;
4462 int ret = 0;
4463 int i;
4464
4465 mutex_lock(&ar->conf_mutex);
4466
4467 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004468 switch (ar->scan.state) {
4469 case ATH10K_SCAN_IDLE:
4470 reinit_completion(&ar->scan.started);
4471 reinit_completion(&ar->scan.completed);
4472 ar->scan.state = ATH10K_SCAN_STARTING;
4473 ar->scan.is_roc = false;
4474 ar->scan.vdev_id = arvif->vdev_id;
4475 ret = 0;
4476 break;
4477 case ATH10K_SCAN_STARTING:
4478 case ATH10K_SCAN_RUNNING:
4479 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004480 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004481 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004482 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004483 spin_unlock_bh(&ar->data_lock);
4484
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004485 if (ret)
4486 goto exit;
4487
Kalle Valo5e3dd152013-06-12 20:52:10 +03004488 memset(&arg, 0, sizeof(arg));
4489 ath10k_wmi_start_scan_init(ar, &arg);
4490 arg.vdev_id = arvif->vdev_id;
4491 arg.scan_id = ATH10K_SCAN_ID;
4492
4493 if (!req->no_cck)
4494 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4495
4496 if (req->ie_len) {
4497 arg.ie_len = req->ie_len;
4498 memcpy(arg.ie, req->ie, arg.ie_len);
4499 }
4500
4501 if (req->n_ssids) {
4502 arg.n_ssids = req->n_ssids;
4503 for (i = 0; i < arg.n_ssids; i++) {
4504 arg.ssids[i].len = req->ssids[i].ssid_len;
4505 arg.ssids[i].ssid = req->ssids[i].ssid;
4506 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004507 } else {
4508 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004509 }
4510
4511 if (req->n_channels) {
4512 arg.n_channels = req->n_channels;
4513 for (i = 0; i < arg.n_channels; i++)
4514 arg.channels[i] = req->channels[i]->center_freq;
4515 }
4516
4517 ret = ath10k_start_scan(ar, &arg);
4518 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004519 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004520 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004521 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004522 spin_unlock_bh(&ar->data_lock);
4523 }
4524
4525exit:
4526 mutex_unlock(&ar->conf_mutex);
4527 return ret;
4528}
4529
4530static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4531 struct ieee80211_vif *vif)
4532{
4533 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004534
4535 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004536 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004537 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004538
4539 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004540}
4541
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004542static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4543 struct ath10k_vif *arvif,
4544 enum set_key_cmd cmd,
4545 struct ieee80211_key_conf *key)
4546{
4547 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4548 int ret;
4549
4550 /* 10.1 firmware branch requires default key index to be set to group
4551 * key index after installing it. Otherwise FW/HW Txes corrupted
4552 * frames with multi-vif APs. This is not required for main firmware
4553 * branch (e.g. 636).
4554 *
4555 * FIXME: This has been tested only in AP. It remains unknown if this
4556 * is required for multi-vif STA interfaces on 10.1 */
4557
4558 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4559 return;
4560
4561 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4562 return;
4563
4564 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4565 return;
4566
4567 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4568 return;
4569
4570 if (cmd != SET_KEY)
4571 return;
4572
4573 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4574 key->keyidx);
4575 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004576 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004577 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004578}
4579
Kalle Valo5e3dd152013-06-12 20:52:10 +03004580static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4581 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4582 struct ieee80211_key_conf *key)
4583{
4584 struct ath10k *ar = hw->priv;
4585 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4586 struct ath10k_peer *peer;
4587 const u8 *peer_addr;
4588 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4589 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4590 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004591 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004593 /* this one needs to be done in software */
4594 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4595 return 1;
4596
Kalle Valo5e3dd152013-06-12 20:52:10 +03004597 if (key->keyidx > WMI_MAX_KEY_INDEX)
4598 return -ENOSPC;
4599
4600 mutex_lock(&ar->conf_mutex);
4601
4602 if (sta)
4603 peer_addr = sta->addr;
4604 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4605 peer_addr = vif->bss_conf.bssid;
4606 else
4607 peer_addr = vif->addr;
4608
4609 key->hw_key_idx = key->keyidx;
4610
4611 /* the peer should not disappear in mid-way (unless FW goes awry) since
4612 * we already hold conf_mutex. we just make sure its there now. */
4613 spin_lock_bh(&ar->data_lock);
4614 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4615 spin_unlock_bh(&ar->data_lock);
4616
4617 if (!peer) {
4618 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004619 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004620 peer_addr);
4621 ret = -EOPNOTSUPP;
4622 goto exit;
4623 } else {
4624 /* if the peer doesn't exist there is no key to disable
4625 * anymore */
4626 goto exit;
4627 }
4628 }
4629
Michal Kazior7cc45732015-03-09 14:24:17 +01004630 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4631 flags |= WMI_KEY_PAIRWISE;
4632 else
4633 flags |= WMI_KEY_GROUP;
4634
Kalle Valo5e3dd152013-06-12 20:52:10 +03004635 if (is_wep) {
4636 if (cmd == SET_KEY)
4637 arvif->wep_keys[key->keyidx] = key;
4638 else
4639 arvif->wep_keys[key->keyidx] = NULL;
4640
4641 if (cmd == DISABLE_KEY)
4642 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004643
Michal Kaziorad325cb2015-02-18 14:02:27 +01004644 /* When WEP keys are uploaded it's possible that there are
4645 * stations associated already (e.g. when merging) without any
4646 * keys. Static WEP needs an explicit per-peer key upload.
4647 */
4648 if (vif->type == NL80211_IFTYPE_ADHOC &&
4649 cmd == SET_KEY)
4650 ath10k_mac_vif_update_wep_key(arvif, key);
4651
Michal Kazior370e5672015-02-18 14:02:26 +01004652 /* 802.1x never sets the def_wep_key_idx so each set_key()
4653 * call changes default tx key.
4654 *
4655 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4656 * after first set_key().
4657 */
4658 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4659 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004660
Michal Kazior7cc45732015-03-09 14:24:17 +01004661 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4662 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4663 * mode and associated stations in AP/IBSS.
4664 *
4665 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4666 * work fine when mapped directly from mac80211.
4667 *
4668 * Note: When installing first static WEP groupwise key (which
4669 * should be pairwise) def_wep_key_idx isn't known yet (it's
4670 * equal to -1). Since .set_default_unicast_key is called only
4671 * for static WEP it's used to re-upload the key as pairwise.
4672 */
4673 if (arvif->def_wep_key_idx >= 0 &&
4674 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4675 flags &= ~WMI_KEY_GROUP;
4676 flags |= WMI_KEY_PAIRWISE;
4677 }
Michal Kazior370e5672015-02-18 14:02:26 +01004678 }
4679
4680 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004681 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004682 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004683 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004684 goto exit;
4685 }
4686
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004687 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4688
Kalle Valo5e3dd152013-06-12 20:52:10 +03004689 spin_lock_bh(&ar->data_lock);
4690 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4691 if (peer && cmd == SET_KEY)
4692 peer->keys[key->keyidx] = key;
4693 else if (peer && cmd == DISABLE_KEY)
4694 peer->keys[key->keyidx] = NULL;
4695 else if (peer == NULL)
4696 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004697 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004698 spin_unlock_bh(&ar->data_lock);
4699
4700exit:
4701 mutex_unlock(&ar->conf_mutex);
4702 return ret;
4703}
4704
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004705static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4706 struct ieee80211_vif *vif,
4707 int keyidx)
4708{
4709 struct ath10k *ar = hw->priv;
4710 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4711 int ret;
4712
4713 mutex_lock(&arvif->ar->conf_mutex);
4714
4715 if (arvif->ar->state != ATH10K_STATE_ON)
4716 goto unlock;
4717
4718 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4719 arvif->vdev_id, keyidx);
4720
4721 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4722 arvif->vdev_id,
4723 arvif->ar->wmi.vdev_param->def_keyid,
4724 keyidx);
4725
4726 if (ret) {
4727 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4728 arvif->vdev_id,
4729 ret);
4730 goto unlock;
4731 }
4732
4733 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004734
4735 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4736 if (ret) {
4737 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4738 arvif->vdev_id, ret);
4739 goto unlock;
4740 }
4741
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004742unlock:
4743 mutex_unlock(&arvif->ar->conf_mutex);
4744}
4745
Michal Kazior9797feb2014-02-14 14:49:48 +01004746static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4747{
4748 struct ath10k *ar;
4749 struct ath10k_vif *arvif;
4750 struct ath10k_sta *arsta;
4751 struct ieee80211_sta *sta;
4752 u32 changed, bw, nss, smps;
4753 int err;
4754
4755 arsta = container_of(wk, struct ath10k_sta, update_wk);
4756 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4757 arvif = arsta->arvif;
4758 ar = arvif->ar;
4759
4760 spin_lock_bh(&ar->data_lock);
4761
4762 changed = arsta->changed;
4763 arsta->changed = 0;
4764
4765 bw = arsta->bw;
4766 nss = arsta->nss;
4767 smps = arsta->smps;
4768
4769 spin_unlock_bh(&ar->data_lock);
4770
4771 mutex_lock(&ar->conf_mutex);
4772
4773 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004774 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004775 sta->addr, bw);
4776
4777 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4778 WMI_PEER_CHAN_WIDTH, bw);
4779 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004780 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004781 sta->addr, bw, err);
4782 }
4783
4784 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004785 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004786 sta->addr, nss);
4787
4788 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4789 WMI_PEER_NSS, nss);
4790 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004791 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004792 sta->addr, nss, err);
4793 }
4794
4795 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004796 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004797 sta->addr, smps);
4798
4799 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4800 WMI_PEER_SMPS_STATE, smps);
4801 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004802 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004803 sta->addr, smps, err);
4804 }
4805
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004806 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4807 changed & IEEE80211_RC_NSS_CHANGED) {
4808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004809 sta->addr);
4810
Michal Kazior590922a2014-10-21 10:10:29 +03004811 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004812 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004813 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004814 sta->addr);
4815 }
4816
Michal Kazior9797feb2014-02-14 14:49:48 +01004817 mutex_unlock(&ar->conf_mutex);
4818}
4819
Marek Puzyniak7c354242015-03-30 09:51:52 +03004820static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4821 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004822{
4823 struct ath10k *ar = arvif->ar;
4824
4825 lockdep_assert_held(&ar->conf_mutex);
4826
Marek Puzyniak7c354242015-03-30 09:51:52 +03004827 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004828 return 0;
4829
4830 if (ar->num_stations >= ar->max_num_stations)
4831 return -ENOBUFS;
4832
4833 ar->num_stations++;
4834
4835 return 0;
4836}
4837
Marek Puzyniak7c354242015-03-30 09:51:52 +03004838static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4839 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004840{
4841 struct ath10k *ar = arvif->ar;
4842
4843 lockdep_assert_held(&ar->conf_mutex);
4844
Marek Puzyniak7c354242015-03-30 09:51:52 +03004845 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004846 return;
4847
4848 ar->num_stations--;
4849}
4850
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004851struct ath10k_mac_tdls_iter_data {
4852 u32 num_tdls_stations;
4853 struct ieee80211_vif *curr_vif;
4854};
4855
4856static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4857 struct ieee80211_sta *sta)
4858{
4859 struct ath10k_mac_tdls_iter_data *iter_data = data;
4860 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4861 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4862
4863 if (sta->tdls && sta_vif == iter_data->curr_vif)
4864 iter_data->num_tdls_stations++;
4865}
4866
4867static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4868 struct ieee80211_vif *vif)
4869{
4870 struct ath10k_mac_tdls_iter_data data = {};
4871
4872 data.curr_vif = vif;
4873
4874 ieee80211_iterate_stations_atomic(hw,
4875 ath10k_mac_tdls_vif_stations_count_iter,
4876 &data);
4877 return data.num_tdls_stations;
4878}
4879
4880static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4881 struct ieee80211_vif *vif)
4882{
4883 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4884 int *num_tdls_vifs = data;
4885
4886 if (vif->type != NL80211_IFTYPE_STATION)
4887 return;
4888
4889 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4890 (*num_tdls_vifs)++;
4891}
4892
4893static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4894{
4895 int num_tdls_vifs = 0;
4896
4897 ieee80211_iterate_active_interfaces_atomic(hw,
4898 IEEE80211_IFACE_ITER_NORMAL,
4899 ath10k_mac_tdls_vifs_count_iter,
4900 &num_tdls_vifs);
4901 return num_tdls_vifs;
4902}
4903
Kalle Valo5e3dd152013-06-12 20:52:10 +03004904static int ath10k_sta_state(struct ieee80211_hw *hw,
4905 struct ieee80211_vif *vif,
4906 struct ieee80211_sta *sta,
4907 enum ieee80211_sta_state old_state,
4908 enum ieee80211_sta_state new_state)
4909{
4910 struct ath10k *ar = hw->priv;
4911 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004912 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004913 int ret = 0;
4914
Michal Kazior76f90022014-02-25 09:29:57 +02004915 if (old_state == IEEE80211_STA_NOTEXIST &&
4916 new_state == IEEE80211_STA_NONE) {
4917 memset(arsta, 0, sizeof(*arsta));
4918 arsta->arvif = arvif;
4919 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4920 }
4921
Michal Kazior9797feb2014-02-14 14:49:48 +01004922 /* cancel must be done outside the mutex to avoid deadlock */
4923 if ((old_state == IEEE80211_STA_NONE &&
4924 new_state == IEEE80211_STA_NOTEXIST))
4925 cancel_work_sync(&arsta->update_wk);
4926
Kalle Valo5e3dd152013-06-12 20:52:10 +03004927 mutex_lock(&ar->conf_mutex);
4928
4929 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004930 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004931 /*
4932 * New station addition.
4933 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004934 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4935 u32 num_tdls_stations;
4936 u32 num_tdls_vifs;
4937
Michal Kaziorcfd10612014-11-25 15:16:05 +01004938 ath10k_dbg(ar, ATH10K_DBG_MAC,
4939 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4940 arvif->vdev_id, sta->addr,
4941 ar->num_stations + 1, ar->max_num_stations,
4942 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004943
Marek Puzyniak7c354242015-03-30 09:51:52 +03004944 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004945 if (ret) {
4946 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4947 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004948 goto exit;
4949 }
4950
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004951 if (sta->tdls)
4952 peer_type = WMI_PEER_TYPE_TDLS;
4953
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004954 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004955 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004956 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004957 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 -08004958 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004959 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004960 goto exit;
4961 }
Michal Kazior077efc82014-10-21 10:10:29 +03004962
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004963 if (!sta->tdls)
4964 goto exit;
4965
4966 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4967 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4968
4969 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4970 num_tdls_stations == 0) {
4971 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4972 arvif->vdev_id, ar->max_num_tdls_vdevs);
4973 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4974 ath10k_mac_dec_num_stations(arvif, sta);
4975 ret = -ENOBUFS;
4976 goto exit;
4977 }
4978
4979 if (num_tdls_stations == 0) {
4980 /* This is the first tdls peer in current vif */
4981 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4982
4983 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4984 state);
4985 if (ret) {
4986 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4987 arvif->vdev_id, ret);
4988 ath10k_peer_delete(ar, arvif->vdev_id,
4989 sta->addr);
4990 ath10k_mac_dec_num_stations(arvif, sta);
4991 goto exit;
4992 }
4993 }
4994
4995 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4996 WMI_TDLS_PEER_STATE_PEERING);
4997 if (ret) {
4998 ath10k_warn(ar,
4999 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5000 sta->addr, arvif->vdev_id, ret);
5001 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5002 ath10k_mac_dec_num_stations(arvif, sta);
5003
5004 if (num_tdls_stations != 0)
5005 goto exit;
5006 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5007 WMI_TDLS_DISABLE);
5008 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005009 } else if ((old_state == IEEE80211_STA_NONE &&
5010 new_state == IEEE80211_STA_NOTEXIST)) {
5011 /*
5012 * Existing station deletion.
5013 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005014 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005015 "mac vdev %d peer delete %pM (sta gone)\n",
5016 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005017
Kalle Valo5e3dd152013-06-12 20:52:10 +03005018 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5019 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005020 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005021 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005022
Marek Puzyniak7c354242015-03-30 09:51:52 +03005023 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005024
5025 if (!sta->tdls)
5026 goto exit;
5027
5028 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5029 goto exit;
5030
5031 /* This was the last tdls peer in current vif */
5032 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5033 WMI_TDLS_DISABLE);
5034 if (ret) {
5035 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5036 arvif->vdev_id, ret);
5037 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005038 } else if (old_state == IEEE80211_STA_AUTH &&
5039 new_state == IEEE80211_STA_ASSOC &&
5040 (vif->type == NL80211_IFTYPE_AP ||
5041 vif->type == NL80211_IFTYPE_ADHOC)) {
5042 /*
5043 * New association.
5044 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005045 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005046 sta->addr);
5047
Michal Kazior590922a2014-10-21 10:10:29 +03005048 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005049 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005050 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005051 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005052 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005053 new_state == IEEE80211_STA_AUTHORIZED &&
5054 sta->tdls) {
5055 /*
5056 * Tdls station authorized.
5057 */
5058 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5059 sta->addr);
5060
5061 ret = ath10k_station_assoc(ar, vif, sta, false);
5062 if (ret) {
5063 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5064 sta->addr, arvif->vdev_id, ret);
5065 goto exit;
5066 }
5067
5068 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5069 WMI_TDLS_PEER_STATE_CONNECTED);
5070 if (ret)
5071 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5072 sta->addr, arvif->vdev_id, ret);
5073 } else if (old_state == IEEE80211_STA_ASSOC &&
5074 new_state == IEEE80211_STA_AUTH &&
5075 (vif->type == NL80211_IFTYPE_AP ||
5076 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005077 /*
5078 * Disassociation.
5079 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005080 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005081 sta->addr);
5082
Michal Kazior590922a2014-10-21 10:10:29 +03005083 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005084 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005085 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005086 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005087 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005088exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005089 mutex_unlock(&ar->conf_mutex);
5090 return ret;
5091}
5092
5093static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005094 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005095{
5096 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005097 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5098 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005099 u32 value = 0;
5100 int ret = 0;
5101
Michal Kazior548db542013-07-05 16:15:15 +03005102 lockdep_assert_held(&ar->conf_mutex);
5103
Kalle Valo5e3dd152013-06-12 20:52:10 +03005104 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5105 return 0;
5106
5107 switch (ac) {
5108 case IEEE80211_AC_VO:
5109 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5110 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005111 prio = 7;
5112 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005113 break;
5114 case IEEE80211_AC_VI:
5115 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5116 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005117 prio = 5;
5118 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005119 break;
5120 case IEEE80211_AC_BE:
5121 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5122 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005123 prio = 2;
5124 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005125 break;
5126 case IEEE80211_AC_BK:
5127 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5128 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005129 prio = 0;
5130 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005131 break;
5132 }
5133
5134 if (enable)
5135 arvif->u.sta.uapsd |= value;
5136 else
5137 arvif->u.sta.uapsd &= ~value;
5138
5139 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5140 WMI_STA_PS_PARAM_UAPSD,
5141 arvif->u.sta.uapsd);
5142 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005143 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005144 goto exit;
5145 }
5146
5147 if (arvif->u.sta.uapsd)
5148 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5149 else
5150 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5151
5152 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5153 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5154 value);
5155 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005156 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005157
Michal Kazior9f9b5742014-12-12 12:41:36 +01005158 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5159 if (ret) {
5160 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5161 arvif->vdev_id, ret);
5162 return ret;
5163 }
5164
5165 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5166 if (ret) {
5167 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5168 arvif->vdev_id, ret);
5169 return ret;
5170 }
5171
Michal Kaziorb0e56152015-01-24 12:14:52 +02005172 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5173 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5174 /* Only userspace can make an educated decision when to send
5175 * trigger frame. The following effectively disables u-UAPSD
5176 * autotrigger in firmware (which is enabled by default
5177 * provided the autotrigger service is available).
5178 */
5179
5180 arg.wmm_ac = acc;
5181 arg.user_priority = prio;
5182 arg.service_interval = 0;
5183 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5184 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5185
5186 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5187 arvif->bssid, &arg, 1);
5188 if (ret) {
5189 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5190 ret);
5191 return ret;
5192 }
5193 }
5194
Kalle Valo5e3dd152013-06-12 20:52:10 +03005195exit:
5196 return ret;
5197}
5198
5199static int ath10k_conf_tx(struct ieee80211_hw *hw,
5200 struct ieee80211_vif *vif, u16 ac,
5201 const struct ieee80211_tx_queue_params *params)
5202{
5203 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005204 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005205 struct wmi_wmm_params_arg *p = NULL;
5206 int ret;
5207
5208 mutex_lock(&ar->conf_mutex);
5209
5210 switch (ac) {
5211 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005212 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005213 break;
5214 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005215 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005216 break;
5217 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005218 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005219 break;
5220 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005221 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005222 break;
5223 }
5224
5225 if (WARN_ON(!p)) {
5226 ret = -EINVAL;
5227 goto exit;
5228 }
5229
5230 p->cwmin = params->cw_min;
5231 p->cwmax = params->cw_max;
5232 p->aifs = params->aifs;
5233
5234 /*
5235 * The channel time duration programmed in the HW is in absolute
5236 * microseconds, while mac80211 gives the txop in units of
5237 * 32 microseconds.
5238 */
5239 p->txop = params->txop * 32;
5240
Michal Kazior7fc979a2015-01-28 09:57:28 +02005241 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5242 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5243 &arvif->wmm_params);
5244 if (ret) {
5245 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5246 arvif->vdev_id, ret);
5247 goto exit;
5248 }
5249 } else {
5250 /* This won't work well with multi-interface cases but it's
5251 * better than nothing.
5252 */
5253 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5254 if (ret) {
5255 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5256 goto exit;
5257 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005258 }
5259
5260 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5261 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005262 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005263
5264exit:
5265 mutex_unlock(&ar->conf_mutex);
5266 return ret;
5267}
5268
5269#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5270
5271static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5272 struct ieee80211_vif *vif,
5273 struct ieee80211_channel *chan,
5274 int duration,
5275 enum ieee80211_roc_type type)
5276{
5277 struct ath10k *ar = hw->priv;
5278 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5279 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005280 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005281
5282 mutex_lock(&ar->conf_mutex);
5283
5284 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005285 switch (ar->scan.state) {
5286 case ATH10K_SCAN_IDLE:
5287 reinit_completion(&ar->scan.started);
5288 reinit_completion(&ar->scan.completed);
5289 reinit_completion(&ar->scan.on_channel);
5290 ar->scan.state = ATH10K_SCAN_STARTING;
5291 ar->scan.is_roc = true;
5292 ar->scan.vdev_id = arvif->vdev_id;
5293 ar->scan.roc_freq = chan->center_freq;
5294 ret = 0;
5295 break;
5296 case ATH10K_SCAN_STARTING:
5297 case ATH10K_SCAN_RUNNING:
5298 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005299 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005300 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005301 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005302 spin_unlock_bh(&ar->data_lock);
5303
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005304 if (ret)
5305 goto exit;
5306
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005307 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5308
Kalle Valo5e3dd152013-06-12 20:52:10 +03005309 memset(&arg, 0, sizeof(arg));
5310 ath10k_wmi_start_scan_init(ar, &arg);
5311 arg.vdev_id = arvif->vdev_id;
5312 arg.scan_id = ATH10K_SCAN_ID;
5313 arg.n_channels = 1;
5314 arg.channels[0] = chan->center_freq;
5315 arg.dwell_time_active = duration;
5316 arg.dwell_time_passive = duration;
5317 arg.max_scan_time = 2 * duration;
5318 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5319 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5320
5321 ret = ath10k_start_scan(ar, &arg);
5322 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005323 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005324 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005325 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005326 spin_unlock_bh(&ar->data_lock);
5327 goto exit;
5328 }
5329
5330 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5331 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005332 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005333
5334 ret = ath10k_scan_stop(ar);
5335 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005336 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005337
Kalle Valo5e3dd152013-06-12 20:52:10 +03005338 ret = -ETIMEDOUT;
5339 goto exit;
5340 }
5341
5342 ret = 0;
5343exit:
5344 mutex_unlock(&ar->conf_mutex);
5345 return ret;
5346}
5347
5348static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5349{
5350 struct ath10k *ar = hw->priv;
5351
5352 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005353 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005354 mutex_unlock(&ar->conf_mutex);
5355
Michal Kazior4eb2e162014-10-28 10:23:09 +01005356 cancel_delayed_work_sync(&ar->scan.timeout);
5357
Kalle Valo5e3dd152013-06-12 20:52:10 +03005358 return 0;
5359}
5360
5361/*
5362 * Both RTS and Fragmentation threshold are interface-specific
5363 * in ath10k, but device-specific in mac80211.
5364 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005365
5366static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5367{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005368 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005369 struct ath10k_vif *arvif;
5370 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005371
Michal Kaziorad088bf2013-10-16 15:44:46 +03005372 mutex_lock(&ar->conf_mutex);
5373 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005374 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005375 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005376
Michal Kaziorad088bf2013-10-16 15:44:46 +03005377 ret = ath10k_mac_set_rts(arvif, value);
5378 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005379 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005380 arvif->vdev_id, ret);
5381 break;
5382 }
5383 }
5384 mutex_unlock(&ar->conf_mutex);
5385
5386 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005387}
5388
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005389static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5390 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391{
5392 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005393 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005394 int ret;
5395
5396 /* mac80211 doesn't care if we really xmit queued frames or not
5397 * we'll collect those frames either way if we stop/delete vdevs */
5398 if (drop)
5399 return;
5400
Michal Kazior548db542013-07-05 16:15:15 +03005401 mutex_lock(&ar->conf_mutex);
5402
Michal Kazioraffd3212013-07-16 09:54:35 +02005403 if (ar->state == ATH10K_STATE_WEDGED)
5404 goto skip;
5405
Michal Kazioredb82362013-07-05 16:15:14 +03005406 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005407 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005408
Michal Kazioredb82362013-07-05 16:15:14 +03005409 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005410 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005411 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005412
Michal Kazior7962b0d2014-10-28 10:34:38 +01005413 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5414 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5415 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005416
5417 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005418 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005419
5420 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005421 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005422 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005423
Michal Kazioraffd3212013-07-16 09:54:35 +02005424skip:
Michal Kazior548db542013-07-05 16:15:15 +03005425 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005426}
5427
5428/* TODO: Implement this function properly
5429 * For now it is needed to reply to Probe Requests in IBSS mode.
5430 * Propably we need this information from FW.
5431 */
5432static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5433{
5434 return 1;
5435}
5436
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005437static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5438 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005439{
5440 struct ath10k *ar = hw->priv;
5441
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005442 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5443 return;
5444
Michal Kazioraffd3212013-07-16 09:54:35 +02005445 mutex_lock(&ar->conf_mutex);
5446
5447 /* If device failed to restart it will be in a different state, e.g.
5448 * ATH10K_STATE_WEDGED */
5449 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005450 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005451 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005452 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005453 }
5454
5455 mutex_unlock(&ar->conf_mutex);
5456}
5457
Michal Kazior2e1dea42013-07-31 10:32:40 +02005458static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5459 struct survey_info *survey)
5460{
5461 struct ath10k *ar = hw->priv;
5462 struct ieee80211_supported_band *sband;
5463 struct survey_info *ar_survey = &ar->survey[idx];
5464 int ret = 0;
5465
5466 mutex_lock(&ar->conf_mutex);
5467
5468 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5469 if (sband && idx >= sband->n_channels) {
5470 idx -= sband->n_channels;
5471 sband = NULL;
5472 }
5473
5474 if (!sband)
5475 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5476
5477 if (!sband || idx >= sband->n_channels) {
5478 ret = -ENOENT;
5479 goto exit;
5480 }
5481
5482 spin_lock_bh(&ar->data_lock);
5483 memcpy(survey, ar_survey, sizeof(*survey));
5484 spin_unlock_bh(&ar->data_lock);
5485
5486 survey->channel = &sband->channels[idx];
5487
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005488 if (ar->rx_channel == survey->channel)
5489 survey->filled |= SURVEY_INFO_IN_USE;
5490
Michal Kazior2e1dea42013-07-31 10:32:40 +02005491exit:
5492 mutex_unlock(&ar->conf_mutex);
5493 return ret;
5494}
5495
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005496/* Check if only one bit set */
5497static int ath10k_check_single_mask(u32 mask)
5498{
5499 int bit;
5500
5501 bit = ffs(mask);
5502 if (!bit)
5503 return 0;
5504
5505 mask &= ~BIT(bit - 1);
5506 if (mask)
5507 return 2;
5508
5509 return 1;
5510}
5511
5512static bool
5513ath10k_default_bitrate_mask(struct ath10k *ar,
5514 enum ieee80211_band band,
5515 const struct cfg80211_bitrate_mask *mask)
5516{
5517 u32 legacy = 0x00ff;
5518 u8 ht = 0xff, i;
5519 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005520 u16 nrf = ar->num_rf_chains;
5521
5522 if (ar->cfg_tx_chainmask)
5523 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005524
5525 switch (band) {
5526 case IEEE80211_BAND_2GHZ:
5527 legacy = 0x00fff;
5528 vht = 0;
5529 break;
5530 case IEEE80211_BAND_5GHZ:
5531 break;
5532 default:
5533 return false;
5534 }
5535
5536 if (mask->control[band].legacy != legacy)
5537 return false;
5538
Ben Greearb116ea12014-11-24 16:22:10 +02005539 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005540 if (mask->control[band].ht_mcs[i] != ht)
5541 return false;
5542
Ben Greearb116ea12014-11-24 16:22:10 +02005543 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005544 if (mask->control[band].vht_mcs[i] != vht)
5545 return false;
5546
5547 return true;
5548}
5549
5550static bool
5551ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5552 enum ieee80211_band band,
5553 u8 *fixed_nss)
5554{
5555 int ht_nss = 0, vht_nss = 0, i;
5556
5557 /* check legacy */
5558 if (ath10k_check_single_mask(mask->control[band].legacy))
5559 return false;
5560
5561 /* check HT */
5562 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5563 if (mask->control[band].ht_mcs[i] == 0xff)
5564 continue;
5565 else if (mask->control[band].ht_mcs[i] == 0x00)
5566 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005567
5568 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005569 }
5570
5571 ht_nss = i;
5572
5573 /* check VHT */
5574 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5575 if (mask->control[band].vht_mcs[i] == 0x03ff)
5576 continue;
5577 else if (mask->control[band].vht_mcs[i] == 0x0000)
5578 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005579
5580 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005581 }
5582
5583 vht_nss = i;
5584
5585 if (ht_nss > 0 && vht_nss > 0)
5586 return false;
5587
5588 if (ht_nss)
5589 *fixed_nss = ht_nss;
5590 else if (vht_nss)
5591 *fixed_nss = vht_nss;
5592 else
5593 return false;
5594
5595 return true;
5596}
5597
5598static bool
5599ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5600 enum ieee80211_band band,
5601 enum wmi_rate_preamble *preamble)
5602{
5603 int legacy = 0, ht = 0, vht = 0, i;
5604
5605 *preamble = WMI_RATE_PREAMBLE_OFDM;
5606
5607 /* check legacy */
5608 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5609 if (legacy > 1)
5610 return false;
5611
5612 /* check HT */
5613 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5614 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5615 if (ht > 1)
5616 return false;
5617
5618 /* check VHT */
5619 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5620 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5621 if (vht > 1)
5622 return false;
5623
5624 /* Currently we support only one fixed_rate */
5625 if ((legacy + ht + vht) != 1)
5626 return false;
5627
5628 if (ht)
5629 *preamble = WMI_RATE_PREAMBLE_HT;
5630 else if (vht)
5631 *preamble = WMI_RATE_PREAMBLE_VHT;
5632
5633 return true;
5634}
5635
5636static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005637ath10k_bitrate_mask_rate(struct ath10k *ar,
5638 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005639 enum ieee80211_band band,
5640 u8 *fixed_rate,
5641 u8 *fixed_nss)
5642{
Michal Kazioraf001482015-03-30 09:51:56 +03005643 struct ieee80211_supported_band *sband;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005644 u8 rate = 0, pream = 0, nss = 0, i;
5645 enum wmi_rate_preamble preamble;
5646
5647 /* Check if single rate correct */
5648 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5649 return false;
5650
5651 pream = preamble;
5652
5653 switch (preamble) {
5654 case WMI_RATE_PREAMBLE_CCK:
5655 case WMI_RATE_PREAMBLE_OFDM:
5656 i = ffs(mask->control[band].legacy) - 1;
Michal Kazioraf001482015-03-30 09:51:56 +03005657 sband = &ar->mac.sbands[band];
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005658
Michal Kazioraf001482015-03-30 09:51:56 +03005659 if (WARN_ON(i >= sband->n_bitrates))
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005660 return false;
5661
Michal Kazioraf001482015-03-30 09:51:56 +03005662 rate = sband->bitrates[i].hw_value;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005663 break;
5664 case WMI_RATE_PREAMBLE_HT:
5665 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5666 if (mask->control[band].ht_mcs[i])
5667 break;
5668
5669 if (i == IEEE80211_HT_MCS_MASK_LEN)
5670 return false;
5671
5672 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5673 nss = i;
5674 break;
5675 case WMI_RATE_PREAMBLE_VHT:
5676 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5677 if (mask->control[band].vht_mcs[i])
5678 break;
5679
5680 if (i == NL80211_VHT_NSS_MAX)
5681 return false;
5682
5683 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5684 nss = i;
5685 break;
5686 }
5687
5688 *fixed_nss = nss + 1;
5689 nss <<= 4;
5690 pream <<= 6;
5691
Michal Kazior7aa7a722014-08-25 12:09:38 +02005692 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 +01005693 pream, nss, rate);
5694
5695 *fixed_rate = pream | nss | rate;
5696
5697 return true;
5698}
5699
Michal Kazior7aa7a722014-08-25 12:09:38 +02005700static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5701 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005702 enum ieee80211_band band,
5703 u8 *fixed_rate,
5704 u8 *fixed_nss)
5705{
5706 /* First check full NSS mask, if we can simply limit NSS */
5707 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5708 return true;
5709
5710 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005711 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005712}
5713
5714static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5715 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005716 u8 fixed_nss,
5717 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005718{
5719 struct ath10k *ar = arvif->ar;
5720 u32 vdev_param;
5721 int ret = 0;
5722
5723 mutex_lock(&ar->conf_mutex);
5724
5725 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005726 arvif->fixed_nss == fixed_nss &&
5727 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005728 goto exit;
5729
5730 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005731 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005732
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005733 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005734 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005735
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005736 vdev_param = ar->wmi.vdev_param->fixed_rate;
5737 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5738 vdev_param, fixed_rate);
5739 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005740 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005741 fixed_rate, ret);
5742 ret = -EINVAL;
5743 goto exit;
5744 }
5745
5746 arvif->fixed_rate = fixed_rate;
5747
5748 vdev_param = ar->wmi.vdev_param->nss;
5749 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5750 vdev_param, fixed_nss);
5751
5752 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005753 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005754 fixed_nss, ret);
5755 ret = -EINVAL;
5756 goto exit;
5757 }
5758
5759 arvif->fixed_nss = fixed_nss;
5760
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005761 vdev_param = ar->wmi.vdev_param->sgi;
5762 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5763 force_sgi);
5764
5765 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005766 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005767 force_sgi, ret);
5768 ret = -EINVAL;
5769 goto exit;
5770 }
5771
5772 arvif->force_sgi = force_sgi;
5773
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005774exit:
5775 mutex_unlock(&ar->conf_mutex);
5776 return ret;
5777}
5778
5779static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5780 struct ieee80211_vif *vif,
5781 const struct cfg80211_bitrate_mask *mask)
5782{
5783 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005784 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005785 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005786 enum ieee80211_band band;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005787 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5788 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005789 u8 force_sgi;
5790
Michal Kazior500ff9f2015-03-31 10:26:21 +00005791 if (ath10k_mac_vif_chan(vif, &def))
5792 return -EPERM;
5793
Ben Greearb116ea12014-11-24 16:22:10 +02005794 if (ar->cfg_tx_chainmask)
5795 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5796
Michal Kazior500ff9f2015-03-31 10:26:21 +00005797 band = def.chan->band;
5798
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005799 force_sgi = mask->control[band].gi;
5800 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5801 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005802
5803 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005804 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005805 &fixed_rate,
5806 &fixed_nss))
5807 return -EINVAL;
5808 }
5809
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005810 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005811 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005812 return -EINVAL;
5813 }
5814
5815 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5816 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005817}
5818
Michal Kazior9797feb2014-02-14 14:49:48 +01005819static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5820 struct ieee80211_vif *vif,
5821 struct ieee80211_sta *sta,
5822 u32 changed)
5823{
5824 struct ath10k *ar = hw->priv;
5825 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5826 u32 bw, smps;
5827
5828 spin_lock_bh(&ar->data_lock);
5829
Michal Kazior7aa7a722014-08-25 12:09:38 +02005830 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005831 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5832 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5833 sta->smps_mode);
5834
5835 if (changed & IEEE80211_RC_BW_CHANGED) {
5836 bw = WMI_PEER_CHWIDTH_20MHZ;
5837
5838 switch (sta->bandwidth) {
5839 case IEEE80211_STA_RX_BW_20:
5840 bw = WMI_PEER_CHWIDTH_20MHZ;
5841 break;
5842 case IEEE80211_STA_RX_BW_40:
5843 bw = WMI_PEER_CHWIDTH_40MHZ;
5844 break;
5845 case IEEE80211_STA_RX_BW_80:
5846 bw = WMI_PEER_CHWIDTH_80MHZ;
5847 break;
5848 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005849 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005850 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005851 bw = WMI_PEER_CHWIDTH_20MHZ;
5852 break;
5853 }
5854
5855 arsta->bw = bw;
5856 }
5857
5858 if (changed & IEEE80211_RC_NSS_CHANGED)
5859 arsta->nss = sta->rx_nss;
5860
5861 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5862 smps = WMI_PEER_SMPS_PS_NONE;
5863
5864 switch (sta->smps_mode) {
5865 case IEEE80211_SMPS_AUTOMATIC:
5866 case IEEE80211_SMPS_OFF:
5867 smps = WMI_PEER_SMPS_PS_NONE;
5868 break;
5869 case IEEE80211_SMPS_STATIC:
5870 smps = WMI_PEER_SMPS_STATIC;
5871 break;
5872 case IEEE80211_SMPS_DYNAMIC:
5873 smps = WMI_PEER_SMPS_DYNAMIC;
5874 break;
5875 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005876 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005877 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005878 smps = WMI_PEER_SMPS_PS_NONE;
5879 break;
5880 }
5881
5882 arsta->smps = smps;
5883 }
5884
Michal Kazior9797feb2014-02-14 14:49:48 +01005885 arsta->changed |= changed;
5886
5887 spin_unlock_bh(&ar->data_lock);
5888
5889 ieee80211_queue_work(hw, &arsta->update_wk);
5890}
5891
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005892static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5893{
5894 /*
5895 * FIXME: Return 0 for time being. Need to figure out whether FW
5896 * has the API to fetch 64-bit local TSF
5897 */
5898
5899 return 0;
5900}
5901
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005902static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5903 struct ieee80211_vif *vif,
5904 enum ieee80211_ampdu_mlme_action action,
5905 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5906 u8 buf_size)
5907{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005908 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005909 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5910
Michal Kazior7aa7a722014-08-25 12:09:38 +02005911 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 +02005912 arvif->vdev_id, sta->addr, tid, action);
5913
5914 switch (action) {
5915 case IEEE80211_AMPDU_RX_START:
5916 case IEEE80211_AMPDU_RX_STOP:
5917 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5918 * creation/removal. Do we need to verify this?
5919 */
5920 return 0;
5921 case IEEE80211_AMPDU_TX_START:
5922 case IEEE80211_AMPDU_TX_STOP_CONT:
5923 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5924 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5925 case IEEE80211_AMPDU_TX_OPERATIONAL:
5926 /* Firmware offloads Tx aggregation entirely so deny mac80211
5927 * Tx aggregation requests.
5928 */
5929 return -EOPNOTSUPP;
5930 }
5931
5932 return -EINVAL;
5933}
5934
Michal Kazior500ff9f2015-03-31 10:26:21 +00005935static void
5936ath10k_mac_update_rx_channel(struct ath10k *ar)
5937{
5938 struct cfg80211_chan_def *def = NULL;
5939
5940 /* Both locks are required because ar->rx_channel is modified. This
5941 * allows readers to hold either lock.
5942 */
5943 lockdep_assert_held(&ar->conf_mutex);
5944 lockdep_assert_held(&ar->data_lock);
5945
5946 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5947 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5948 * ppdu on Rx may reduce performance on low-end systems. It should be
5949 * possible to make tables/hashmaps to speed the lookup up (be vary of
5950 * cpu data cache lines though regarding sizes) but to keep the initial
5951 * implementation simple and less intrusive fallback to the slow lookup
5952 * only for multi-channel cases. Single-channel cases will remain to
5953 * use the old channel derival and thus performance should not be
5954 * affected much.
5955 */
5956 rcu_read_lock();
5957 if (ath10k_mac_num_chanctxs(ar) == 1) {
5958 ieee80211_iter_chan_contexts_atomic(ar->hw,
5959 ath10k_mac_get_any_chandef_iter,
5960 &def);
5961 ar->rx_channel = def->chan;
5962 } else {
5963 ar->rx_channel = NULL;
5964 }
5965 rcu_read_unlock();
5966}
5967
5968static void
5969ath10k_mac_chan_ctx_init(struct ath10k *ar,
5970 struct ath10k_chanctx *arctx,
5971 struct ieee80211_chanctx_conf *conf)
5972{
5973 lockdep_assert_held(&ar->conf_mutex);
5974 lockdep_assert_held(&ar->data_lock);
5975
5976 memset(arctx, 0, sizeof(*arctx));
5977
5978 arctx->conf = *conf;
5979}
5980
5981static int
5982ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5983 struct ieee80211_chanctx_conf *ctx)
5984{
5985 struct ath10k *ar = hw->priv;
5986 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5987
5988 ath10k_dbg(ar, ATH10K_DBG_MAC,
5989 "mac chanctx add freq %hu width %d ptr %p\n",
5990 ctx->def.chan->center_freq, ctx->def.width, ctx);
5991
5992 mutex_lock(&ar->conf_mutex);
5993
5994 spin_lock_bh(&ar->data_lock);
5995 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
5996 ath10k_mac_update_rx_channel(ar);
5997 spin_unlock_bh(&ar->data_lock);
5998
5999 ath10k_recalc_radar_detection(ar);
6000 ath10k_monitor_recalc(ar);
6001
6002 mutex_unlock(&ar->conf_mutex);
6003
6004 return 0;
6005}
6006
6007static void
6008ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6009 struct ieee80211_chanctx_conf *ctx)
6010{
6011 struct ath10k *ar = hw->priv;
6012
6013 ath10k_dbg(ar, ATH10K_DBG_MAC,
6014 "mac chanctx remove freq %hu width %d ptr %p\n",
6015 ctx->def.chan->center_freq, ctx->def.width, ctx);
6016
6017 mutex_lock(&ar->conf_mutex);
6018
6019 spin_lock_bh(&ar->data_lock);
6020 ath10k_mac_update_rx_channel(ar);
6021 spin_unlock_bh(&ar->data_lock);
6022
6023 ath10k_recalc_radar_detection(ar);
6024 ath10k_monitor_recalc(ar);
6025
6026 mutex_unlock(&ar->conf_mutex);
6027}
6028
6029static void
6030ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6031 struct ieee80211_chanctx_conf *ctx,
6032 u32 changed)
6033{
6034 struct ath10k *ar = hw->priv;
6035 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6036
6037 mutex_lock(&ar->conf_mutex);
6038
6039 ath10k_dbg(ar, ATH10K_DBG_MAC,
6040 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6041 arctx->conf.def.chan->center_freq,
6042 ctx->def.chan->center_freq,
6043 arctx->conf.def.width, ctx->def.width,
6044 ctx, changed);
6045
6046 /* This shouldn't really happen because channel switching should use
6047 * switch_vif_chanctx().
6048 */
6049 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6050 goto unlock;
6051
6052 spin_lock_bh(&ar->data_lock);
6053 arctx->conf = *ctx;
6054 spin_unlock_bh(&ar->data_lock);
6055
6056 ath10k_recalc_radar_detection(ar);
6057
6058 /* FIXME: How to configure Rx chains properly? */
6059
6060 /* No other actions are actually necessary. Firmware maintains channel
6061 * definitions per vdev internally and there's no host-side channel
6062 * context abstraction to configure, e.g. channel width.
6063 */
6064
6065unlock:
6066 mutex_unlock(&ar->conf_mutex);
6067}
6068
6069static int
6070ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6071 struct ieee80211_vif *vif,
6072 struct ieee80211_chanctx_conf *ctx)
6073{
6074 struct ath10k *ar = hw->priv;
6075 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6076 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6077 int ret;
6078
6079 mutex_lock(&ar->conf_mutex);
6080
6081 ath10k_dbg(ar, ATH10K_DBG_MAC,
6082 "mac chanctx assign ptr %p vdev_id %i\n",
6083 ctx, arvif->vdev_id);
6084
6085 if (WARN_ON(arvif->is_started)) {
6086 mutex_unlock(&ar->conf_mutex);
6087 return -EBUSY;
6088 }
6089
6090 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6091 if (ret) {
6092 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6093 arvif->vdev_id, vif->addr,
6094 arctx->conf.def.chan->center_freq, ret);
6095 goto err;
6096 }
6097
6098 arvif->is_started = true;
6099
6100 if (vif->type == NL80211_IFTYPE_MONITOR) {
6101 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6102 if (ret) {
6103 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6104 arvif->vdev_id, ret);
6105 goto err_stop;
6106 }
6107
6108 arvif->is_up = true;
6109 }
6110
6111 mutex_unlock(&ar->conf_mutex);
6112 return 0;
6113
6114err_stop:
6115 ath10k_vdev_stop(arvif);
6116 arvif->is_started = false;
6117
6118err:
6119 mutex_unlock(&ar->conf_mutex);
6120 return ret;
6121}
6122
6123static void
6124ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6125 struct ieee80211_vif *vif,
6126 struct ieee80211_chanctx_conf *ctx)
6127{
6128 struct ath10k *ar = hw->priv;
6129 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6130 int ret;
6131
6132 mutex_lock(&ar->conf_mutex);
6133
6134 ath10k_dbg(ar, ATH10K_DBG_MAC,
6135 "mac chanctx unassign ptr %p vdev_id %i\n",
6136 ctx, arvif->vdev_id);
6137
6138 WARN_ON(!arvif->is_started);
6139
6140 if (vif->type == NL80211_IFTYPE_MONITOR) {
6141 WARN_ON(!arvif->is_up);
6142
6143 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6144 if (ret)
6145 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6146 arvif->vdev_id, ret);
6147
6148 arvif->is_up = false;
6149 }
6150
6151 ret = ath10k_vdev_stop(arvif);
6152 if (ret)
6153 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6154 arvif->vdev_id, ret);
6155
6156 arvif->is_started = false;
6157
6158 mutex_unlock(&ar->conf_mutex);
6159}
6160
6161static int
6162ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6163 struct ieee80211_vif_chanctx_switch *vifs,
6164 int n_vifs,
6165 enum ieee80211_chanctx_switch_mode mode)
6166{
6167 struct ath10k *ar = hw->priv;
6168 struct ath10k_vif *arvif;
6169 struct ath10k_chanctx *arctx_new, *arctx_old;
6170 int i;
6171
6172 mutex_lock(&ar->conf_mutex);
6173
6174 ath10k_dbg(ar, ATH10K_DBG_MAC,
6175 "mac chanctx switch n_vifs %d mode %d\n",
6176 n_vifs, mode);
6177
6178 spin_lock_bh(&ar->data_lock);
6179 for (i = 0; i < n_vifs; i++) {
6180 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6181 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6182 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6183
6184 ath10k_dbg(ar, ATH10K_DBG_MAC,
6185 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6186 arvif->vdev_id,
6187 vifs[i].old_ctx->def.chan->center_freq,
6188 vifs[i].new_ctx->def.chan->center_freq,
6189 vifs[i].old_ctx->def.width,
6190 vifs[i].new_ctx->def.width,
6191 arctx_old, arctx_new);
6192
6193 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6194 ath10k_mac_chan_ctx_init(ar, arctx_new,
6195 vifs[i].new_ctx);
6196 }
6197
6198 arctx_new->conf = *vifs[i].new_ctx;
6199
6200 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6201 * yet updated chanctx_conf pointer.
6202 */
6203 arctx_old->conf = *vifs[i].new_ctx;
6204 }
6205 ath10k_mac_update_rx_channel(ar);
6206 spin_unlock_bh(&ar->data_lock);
6207
6208 /* FIXME: Reconfigure only affected vifs */
6209 ath10k_mac_chan_reconfigure(ar);
6210
6211 mutex_unlock(&ar->conf_mutex);
6212 return 0;
6213}
6214
Kalle Valo5e3dd152013-06-12 20:52:10 +03006215static const struct ieee80211_ops ath10k_ops = {
6216 .tx = ath10k_tx,
6217 .start = ath10k_start,
6218 .stop = ath10k_stop,
6219 .config = ath10k_config,
6220 .add_interface = ath10k_add_interface,
6221 .remove_interface = ath10k_remove_interface,
6222 .configure_filter = ath10k_configure_filter,
6223 .bss_info_changed = ath10k_bss_info_changed,
6224 .hw_scan = ath10k_hw_scan,
6225 .cancel_hw_scan = ath10k_cancel_hw_scan,
6226 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006227 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006228 .sta_state = ath10k_sta_state,
6229 .conf_tx = ath10k_conf_tx,
6230 .remain_on_channel = ath10k_remain_on_channel,
6231 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6232 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006233 .flush = ath10k_flush,
6234 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006235 .set_antenna = ath10k_set_antenna,
6236 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006237 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006238 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006239 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006240 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006241 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006242 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006243 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6244 .get_et_stats = ath10k_debug_get_et_stats,
6245 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006246 .add_chanctx = ath10k_mac_op_add_chanctx,
6247 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6248 .change_chanctx = ath10k_mac_op_change_chanctx,
6249 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6250 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6251 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006252
6253 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6254
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006255#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006256 .suspend = ath10k_wow_op_suspend,
6257 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006258#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006259#ifdef CONFIG_MAC80211_DEBUGFS
6260 .sta_add_debugfs = ath10k_sta_add_debugfs,
6261#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006262};
6263
Kalle Valo5e3dd152013-06-12 20:52:10 +03006264#define CHAN2G(_channel, _freq, _flags) { \
6265 .band = IEEE80211_BAND_2GHZ, \
6266 .hw_value = (_channel), \
6267 .center_freq = (_freq), \
6268 .flags = (_flags), \
6269 .max_antenna_gain = 0, \
6270 .max_power = 30, \
6271}
6272
6273#define CHAN5G(_channel, _freq, _flags) { \
6274 .band = IEEE80211_BAND_5GHZ, \
6275 .hw_value = (_channel), \
6276 .center_freq = (_freq), \
6277 .flags = (_flags), \
6278 .max_antenna_gain = 0, \
6279 .max_power = 30, \
6280}
6281
6282static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6283 CHAN2G(1, 2412, 0),
6284 CHAN2G(2, 2417, 0),
6285 CHAN2G(3, 2422, 0),
6286 CHAN2G(4, 2427, 0),
6287 CHAN2G(5, 2432, 0),
6288 CHAN2G(6, 2437, 0),
6289 CHAN2G(7, 2442, 0),
6290 CHAN2G(8, 2447, 0),
6291 CHAN2G(9, 2452, 0),
6292 CHAN2G(10, 2457, 0),
6293 CHAN2G(11, 2462, 0),
6294 CHAN2G(12, 2467, 0),
6295 CHAN2G(13, 2472, 0),
6296 CHAN2G(14, 2484, 0),
6297};
6298
6299static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006300 CHAN5G(36, 5180, 0),
6301 CHAN5G(40, 5200, 0),
6302 CHAN5G(44, 5220, 0),
6303 CHAN5G(48, 5240, 0),
6304 CHAN5G(52, 5260, 0),
6305 CHAN5G(56, 5280, 0),
6306 CHAN5G(60, 5300, 0),
6307 CHAN5G(64, 5320, 0),
6308 CHAN5G(100, 5500, 0),
6309 CHAN5G(104, 5520, 0),
6310 CHAN5G(108, 5540, 0),
6311 CHAN5G(112, 5560, 0),
6312 CHAN5G(116, 5580, 0),
6313 CHAN5G(120, 5600, 0),
6314 CHAN5G(124, 5620, 0),
6315 CHAN5G(128, 5640, 0),
6316 CHAN5G(132, 5660, 0),
6317 CHAN5G(136, 5680, 0),
6318 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006319 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006320 CHAN5G(149, 5745, 0),
6321 CHAN5G(153, 5765, 0),
6322 CHAN5G(157, 5785, 0),
6323 CHAN5G(161, 5805, 0),
6324 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006325};
6326
Michal Kaziore7b54192014-08-07 11:03:27 +02006327struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006328{
6329 struct ieee80211_hw *hw;
6330 struct ath10k *ar;
6331
Michal Kaziore7b54192014-08-07 11:03:27 +02006332 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006333 if (!hw)
6334 return NULL;
6335
6336 ar = hw->priv;
6337 ar->hw = hw;
6338
6339 return ar;
6340}
6341
6342void ath10k_mac_destroy(struct ath10k *ar)
6343{
6344 ieee80211_free_hw(ar->hw);
6345}
6346
6347static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6348 {
6349 .max = 8,
6350 .types = BIT(NL80211_IFTYPE_STATION)
6351 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006352 },
6353 {
6354 .max = 3,
6355 .types = BIT(NL80211_IFTYPE_P2P_GO)
6356 },
6357 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006358 .max = 1,
6359 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6360 },
6361 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006362 .max = 7,
6363 .types = BIT(NL80211_IFTYPE_AP)
6364 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006365};
6366
Bartosz Markowskif2595092013-12-10 16:20:39 +01006367static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006368 {
6369 .max = 8,
6370 .types = BIT(NL80211_IFTYPE_AP)
6371 },
6372};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006373
6374static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6375 {
6376 .limits = ath10k_if_limits,
6377 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6378 .max_interfaces = 8,
6379 .num_different_channels = 1,
6380 .beacon_int_infra_match = true,
6381 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006382};
6383
6384static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006385 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006386 .limits = ath10k_10x_if_limits,
6387 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006388 .max_interfaces = 8,
6389 .num_different_channels = 1,
6390 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006391#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006392 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6393 BIT(NL80211_CHAN_WIDTH_20) |
6394 BIT(NL80211_CHAN_WIDTH_40) |
6395 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006396#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006397 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006398};
6399
6400static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6401{
6402 struct ieee80211_sta_vht_cap vht_cap = {0};
6403 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006404 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006405 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006406
6407 vht_cap.vht_supported = 1;
6408 vht_cap.cap = ar->vht_cap_info;
6409
Michal Kaziorbc657a362015-02-26 11:11:22 +01006410 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6411 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6412 val = ar->num_rf_chains - 1;
6413 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6414 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6415
6416 vht_cap.cap |= val;
6417 }
6418
6419 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6420 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6421 val = ar->num_rf_chains - 1;
6422 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6423 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6424
6425 vht_cap.cap |= val;
6426 }
6427
Michal Kazior8865bee42013-07-24 12:36:46 +02006428 mcs_map = 0;
6429 for (i = 0; i < 8; i++) {
6430 if (i < ar->num_rf_chains)
6431 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6432 else
6433 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6434 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006435
6436 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6437 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6438
6439 return vht_cap;
6440}
6441
6442static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6443{
6444 int i;
6445 struct ieee80211_sta_ht_cap ht_cap = {0};
6446
6447 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6448 return ht_cap;
6449
6450 ht_cap.ht_supported = 1;
6451 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6452 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6453 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6454 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6455 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6456
6457 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6458 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6459
6460 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6461 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6462
6463 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6464 u32 smps;
6465
6466 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6467 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6468
6469 ht_cap.cap |= smps;
6470 }
6471
6472 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6473 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6474
6475 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6476 u32 stbc;
6477
6478 stbc = ar->ht_cap_info;
6479 stbc &= WMI_HT_CAP_RX_STBC;
6480 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6481 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6482 stbc &= IEEE80211_HT_CAP_RX_STBC;
6483
6484 ht_cap.cap |= stbc;
6485 }
6486
6487 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6488 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6489
6490 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6491 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6492
6493 /* max AMSDU is implicitly taken from vht_cap_info */
6494 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6495 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6496
Michal Kazior8865bee42013-07-24 12:36:46 +02006497 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006498 ht_cap.mcs.rx_mask[i] = 0xFF;
6499
6500 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6501
6502 return ht_cap;
6503}
6504
Kalle Valo5e3dd152013-06-12 20:52:10 +03006505static void ath10k_get_arvif_iter(void *data, u8 *mac,
6506 struct ieee80211_vif *vif)
6507{
6508 struct ath10k_vif_iter *arvif_iter = data;
6509 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6510
6511 if (arvif->vdev_id == arvif_iter->vdev_id)
6512 arvif_iter->arvif = arvif;
6513}
6514
6515struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6516{
6517 struct ath10k_vif_iter arvif_iter;
6518 u32 flags;
6519
6520 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6521 arvif_iter.vdev_id = vdev_id;
6522
6523 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6524 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6525 flags,
6526 ath10k_get_arvif_iter,
6527 &arvif_iter);
6528 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006529 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006530 return NULL;
6531 }
6532
6533 return arvif_iter.arvif;
6534}
6535
6536int ath10k_mac_register(struct ath10k *ar)
6537{
Johannes Berg3cb10942015-01-22 21:38:45 +01006538 static const u32 cipher_suites[] = {
6539 WLAN_CIPHER_SUITE_WEP40,
6540 WLAN_CIPHER_SUITE_WEP104,
6541 WLAN_CIPHER_SUITE_TKIP,
6542 WLAN_CIPHER_SUITE_CCMP,
6543 WLAN_CIPHER_SUITE_AES_CMAC,
6544 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006545 struct ieee80211_supported_band *band;
6546 struct ieee80211_sta_vht_cap vht_cap;
6547 struct ieee80211_sta_ht_cap ht_cap;
6548 void *channels;
6549 int ret;
6550
6551 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6552
6553 SET_IEEE80211_DEV(ar->hw, ar->dev);
6554
6555 ht_cap = ath10k_get_ht_cap(ar);
6556 vht_cap = ath10k_create_vht_cap(ar);
6557
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006558 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6559 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6560 ATH10K_NUM_CHANS);
6561
Kalle Valo5e3dd152013-06-12 20:52:10 +03006562 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6563 channels = kmemdup(ath10k_2ghz_channels,
6564 sizeof(ath10k_2ghz_channels),
6565 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006566 if (!channels) {
6567 ret = -ENOMEM;
6568 goto err_free;
6569 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006570
6571 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6572 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6573 band->channels = channels;
6574 band->n_bitrates = ath10k_g_rates_size;
6575 band->bitrates = ath10k_g_rates;
6576 band->ht_cap = ht_cap;
6577
Yanbo Lid68bb122015-01-23 08:18:20 +08006578 /* Enable the VHT support at 2.4 GHz */
6579 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006580
6581 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6582 }
6583
6584 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6585 channels = kmemdup(ath10k_5ghz_channels,
6586 sizeof(ath10k_5ghz_channels),
6587 GFP_KERNEL);
6588 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006589 ret = -ENOMEM;
6590 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006591 }
6592
6593 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6594 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6595 band->channels = channels;
6596 band->n_bitrates = ath10k_a_rates_size;
6597 band->bitrates = ath10k_a_rates;
6598 band->ht_cap = ht_cap;
6599 band->vht_cap = vht_cap;
6600 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6601 }
6602
6603 ar->hw->wiphy->interface_modes =
6604 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006605 BIT(NL80211_IFTYPE_AP);
6606
Ben Greear46acf7b2014-05-16 17:15:38 +03006607 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6608 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6609
Bartosz Markowskid3541812013-12-10 16:20:40 +01006610 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6611 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006612 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006613 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6614 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006615
6616 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6617 IEEE80211_HW_SUPPORTS_PS |
6618 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006619 IEEE80211_HW_MFP_CAPABLE |
6620 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6621 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006622 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006623 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006624 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006625 IEEE80211_HW_CONNECTION_MONITOR |
6626 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006627 IEEE80211_HW_CHANCTX_STA_CSA |
6628 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006629
Eliad Peller0d8614b2014-09-10 14:07:36 +03006630 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6631
Kalle Valo5e3dd152013-06-12 20:52:10 +03006632 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006633 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006634
6635 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6636 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6637 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6638 }
6639
6640 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6641 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6642
6643 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006644 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006645 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006646
Kalle Valo5e3dd152013-06-12 20:52:10 +03006647 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6648
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006649 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6650 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6651
6652 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6653 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6654 * correct Probe Responses. This is more of a hack advert..
6655 */
6656 ar->hw->wiphy->probe_resp_offload |=
6657 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6658 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6659 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6660 }
6661
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006662 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6663 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6664
Kalle Valo5e3dd152013-06-12 20:52:10 +03006665 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006666 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006667 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6668
6669 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006670 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6671
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006672 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6673
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006674 ret = ath10k_wow_init(ar);
6675 if (ret) {
6676 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6677 goto err_free;
6678 }
6679
Kalle Valo5e3dd152013-06-12 20:52:10 +03006680 /*
6681 * on LL hardware queues are managed entirely by the FW
6682 * so we only advertise to mac we can do the queues thing
6683 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006684 ar->hw->queues = IEEE80211_MAX_QUEUES;
6685
6686 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6687 * something that vdev_ids can't reach so that we don't stop the queue
6688 * accidentally.
6689 */
6690 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006691
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006692 switch (ar->wmi.op_version) {
6693 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6694 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006695 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6696 ar->hw->wiphy->n_iface_combinations =
6697 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006698 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006699 break;
6700 case ATH10K_FW_WMI_OP_VERSION_10_1:
6701 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006702 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006703 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6704 ar->hw->wiphy->n_iface_combinations =
6705 ARRAY_SIZE(ath10k_10x_if_comb);
6706 break;
6707 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6708 case ATH10K_FW_WMI_OP_VERSION_MAX:
6709 WARN_ON(1);
6710 ret = -EINVAL;
6711 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006712 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006713
Michal Kazior7c199992013-07-31 10:47:57 +02006714 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6715
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006716 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6717 /* Init ath dfs pattern detector */
6718 ar->ath_common.debug_mask = ATH_DBG_DFS;
6719 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6720 NL80211_DFS_UNSET);
6721
6722 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006723 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006724 }
6725
Kalle Valo5e3dd152013-06-12 20:52:10 +03006726 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6727 ath10k_reg_notifier);
6728 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006729 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006730 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006731 }
6732
Johannes Berg3cb10942015-01-22 21:38:45 +01006733 ar->hw->wiphy->cipher_suites = cipher_suites;
6734 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6735
Kalle Valo5e3dd152013-06-12 20:52:10 +03006736 ret = ieee80211_register_hw(ar->hw);
6737 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006738 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006739 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006740 }
6741
6742 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6743 ret = regulatory_hint(ar->hw->wiphy,
6744 ar->ath_common.regulatory.alpha2);
6745 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006746 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006747 }
6748
6749 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006750
6751err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006752 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006753err_free:
6754 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6755 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6756
Kalle Valo5e3dd152013-06-12 20:52:10 +03006757 return ret;
6758}
6759
6760void ath10k_mac_unregister(struct ath10k *ar)
6761{
6762 ieee80211_unregister_hw(ar->hw);
6763
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006764 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6765 ar->dfs_detector->exit(ar->dfs_detector);
6766
Kalle Valo5e3dd152013-06-12 20:52:10 +03006767 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6768 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6769
6770 SET_IEEE80211_DEV(ar->hw, NULL);
6771}