blob: 2eead654fc3f332b7052d79dad519844d4ef96a5 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
Michal Kaziorb4aa5392015-03-31 10:26:24 +000031#include "wmi-tlv.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020032#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020033#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030034
Michal Kaziordcc33092015-03-30 09:51:54 +030035/*********/
36/* Rates */
37/*********/
38
Michal Kaziordcc33092015-03-30 09:51:54 +030039static struct ieee80211_rate ath10k_rates[] = {
Michal Kazior5528e032015-03-30 09:51:56 +030040 { .bitrate = 10,
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
42 { .bitrate = 20,
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
46 { .bitrate = 55,
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
50 { .bitrate = 110,
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
Michal Kazior5653b392015-03-30 09:51:54 +030054
Michal Kazioraf001482015-03-30 09:51:56 +030055 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
Michal Kaziordcc33092015-03-30 09:51:54 +030063};
64
Michal Kazior8d7aa6b2015-03-30 09:51:57 +030065#define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
66
67#define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
Michal Kaziordcc33092015-03-30 09:51:54 +030070#define ath10k_g_rates (ath10k_rates + 0)
71#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
72
Michal Kazior486017c2015-03-30 09:51:54 +030073static bool ath10k_mac_bitrate_is_cck(int bitrate)
74{
75 switch (bitrate) {
76 case 10:
77 case 20:
78 case 55:
79 case 110:
80 return true;
81 }
82
83 return false;
84}
85
86static u8 ath10k_mac_bitrate_to_rate(int bitrate)
87{
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
90}
91
Michal Kazior5528e032015-03-30 09:51:56 +030092u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
93 u8 hw_rate)
94{
95 const struct ieee80211_rate *rate;
96 int i;
97
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
100
101 if (rate->hw_value == hw_rate)
102 return i;
103 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
104 rate->hw_value_short == hw_rate)
105 return i;
106 }
107
108 return 0;
109}
110
Michal Kazior01cebe12015-03-30 09:51:56 +0300111u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
112 u32 bitrate)
113{
114 int i;
115
116 for (i = 0; i < sband->n_bitrates; i++)
117 if (sband->bitrates[i].bitrate == bitrate)
118 return i;
119
120 return 0;
121}
122
Michal Kazior3ae54222015-03-31 10:49:20 +0000123static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
124{
125 switch ((mcs_map >> (2 * nss)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
129 }
130 return 0;
131}
132
Kalle Valo5e3dd152013-06-12 20:52:10 +0300133/**********/
134/* Crypto */
135/**********/
136
137static int ath10k_send_key(struct ath10k_vif *arvif,
138 struct ieee80211_key_conf *key,
139 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100140 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300141{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200142 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300143 struct wmi_vdev_install_key_arg arg = {
144 .vdev_id = arvif->vdev_id,
145 .key_idx = key->keyidx,
146 .key_len = key->keylen,
147 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100148 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300149 .macaddr = macaddr,
150 };
151
Michal Kazior548db542013-07-05 16:15:15 +0300152 lockdep_assert_held(&arvif->ar->conf_mutex);
153
Kalle Valo5e3dd152013-06-12 20:52:10 +0300154 switch (key->cipher) {
155 case WLAN_CIPHER_SUITE_CCMP:
156 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200157 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300158 break;
159 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160 arg.key_cipher = WMI_CIPHER_TKIP;
161 arg.key_txmic_len = 8;
162 arg.key_rxmic_len = 8;
163 break;
164 case WLAN_CIPHER_SUITE_WEP40:
165 case WLAN_CIPHER_SUITE_WEP104:
166 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300167 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100168 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100169 WARN_ON(1);
170 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300171 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200172 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 return -EOPNOTSUPP;
174 }
175
176 if (cmd == DISABLE_KEY) {
177 arg.key_cipher = WMI_CIPHER_NONE;
178 arg.key_data = NULL;
179 }
180
181 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
182}
183
184static int ath10k_install_key(struct ath10k_vif *arvif,
185 struct ieee80211_key_conf *key,
186 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100187 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188{
189 struct ath10k *ar = arvif->ar;
190 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300191 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300192
Michal Kazior548db542013-07-05 16:15:15 +0300193 lockdep_assert_held(&ar->conf_mutex);
194
Wolfram Sang16735d02013-11-14 14:32:02 -0800195 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300196
Michal Kazior370e5672015-02-18 14:02:26 +0100197 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300198 if (ret)
199 return ret;
200
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300201 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
202 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300203 return -ETIMEDOUT;
204
205 return 0;
206}
207
208static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
209 const u8 *addr)
210{
211 struct ath10k *ar = arvif->ar;
212 struct ath10k_peer *peer;
213 int ret;
214 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100215 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216
217 lockdep_assert_held(&ar->conf_mutex);
218
219 spin_lock_bh(&ar->data_lock);
220 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
221 spin_unlock_bh(&ar->data_lock);
222
223 if (!peer)
224 return -ENOENT;
225
226 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
227 if (arvif->wep_keys[i] == NULL)
228 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100229
230 flags = 0;
231 flags |= WMI_KEY_PAIRWISE;
232
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200233 /* set TX_USAGE flag for default key id */
234 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100235 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300236
237 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100238 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300239 if (ret)
240 return ret;
241
Sujith Manoharanae167132014-11-25 11:46:59 +0530242 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300243 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530244 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300245 }
246
247 return 0;
248}
249
250static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
251 const u8 *addr)
252{
253 struct ath10k *ar = arvif->ar;
254 struct ath10k_peer *peer;
255 int first_errno = 0;
256 int ret;
257 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100258 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300259
260 lockdep_assert_held(&ar->conf_mutex);
261
262 spin_lock_bh(&ar->data_lock);
263 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
264 spin_unlock_bh(&ar->data_lock);
265
266 if (!peer)
267 return -ENOENT;
268
269 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
270 if (peer->keys[i] == NULL)
271 continue;
272
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200273 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100275 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300276 if (ret && first_errno == 0)
277 first_errno = ret;
278
279 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200280 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300281 i, ret);
282
Sujith Manoharanae167132014-11-25 11:46:59 +0530283 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530285 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300286 }
287
288 return first_errno;
289}
290
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530291bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
292 u8 keyidx)
293{
294 struct ath10k_peer *peer;
295 int i;
296
297 lockdep_assert_held(&ar->data_lock);
298
299 /* We don't know which vdev this peer belongs to,
300 * since WMI doesn't give us that information.
301 *
302 * FIXME: multi-bss needs to be handled.
303 */
304 peer = ath10k_peer_find(ar, 0, addr);
305 if (!peer)
306 return false;
307
308 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
309 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
310 return true;
311 }
312
313 return false;
314}
315
Kalle Valo5e3dd152013-06-12 20:52:10 +0300316static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
317 struct ieee80211_key_conf *key)
318{
319 struct ath10k *ar = arvif->ar;
320 struct ath10k_peer *peer;
321 u8 addr[ETH_ALEN];
322 int first_errno = 0;
323 int ret;
324 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100325 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 for (;;) {
330 /* since ath10k_install_key we can't hold data_lock all the
331 * time, so we try to remove the keys incrementally */
332 spin_lock_bh(&ar->data_lock);
333 i = 0;
334 list_for_each_entry(peer, &ar->peers, list) {
335 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
336 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300337 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300338 peer->keys[i] = NULL;
339 break;
340 }
341 }
342
343 if (i < ARRAY_SIZE(peer->keys))
344 break;
345 }
346 spin_unlock_bh(&ar->data_lock);
347
348 if (i == ARRAY_SIZE(peer->keys))
349 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200350 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100351 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300352 if (ret && first_errno == 0)
353 first_errno = ret;
354
355 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200356 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200357 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300358 }
359
360 return first_errno;
361}
362
Michal Kazior370e5672015-02-18 14:02:26 +0100363static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
364{
365 struct ath10k *ar = arvif->ar;
366 enum nl80211_iftype iftype = arvif->vif->type;
367 struct ieee80211_key_conf *key;
368 u32 flags = 0;
369 int num = 0;
370 int i;
371 int ret;
372
373 lockdep_assert_held(&ar->conf_mutex);
374
375 if (iftype != NL80211_IFTYPE_STATION)
376 return 0;
377
378 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
379 if (arvif->wep_keys[i]) {
380 key = arvif->wep_keys[i];
381 ++num;
382 }
383 }
384
385 if (num != 1)
386 return 0;
387
388 flags |= WMI_KEY_PAIRWISE;
389 flags |= WMI_KEY_TX_USAGE;
390
391 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
392 if (ret) {
393 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
394 key->keyidx, arvif->vdev_id, ret);
395 return ret;
396 }
397
398 return 0;
399}
400
Michal Kaziorad325cb2015-02-18 14:02:27 +0100401static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
402 struct ieee80211_key_conf *key)
403{
404 struct ath10k *ar = arvif->ar;
405 struct ath10k_peer *peer;
406 int ret;
407
408 lockdep_assert_held(&ar->conf_mutex);
409
410 list_for_each_entry(peer, &ar->peers, list) {
411 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
412 continue;
413
414 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
415 continue;
416
417 if (peer->keys[key->keyidx] == key)
418 continue;
419
420 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
421 arvif->vdev_id, key->keyidx);
422
423 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
424 if (ret) {
425 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
426 arvif->vdev_id, peer->addr, ret);
427 return ret;
428 }
429 }
430
431 return 0;
432}
433
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434/*********************/
435/* General utilities */
436/*********************/
437
438static inline enum wmi_phy_mode
439chan_to_phymode(const struct cfg80211_chan_def *chandef)
440{
441 enum wmi_phy_mode phymode = MODE_UNKNOWN;
442
443 switch (chandef->chan->band) {
444 case IEEE80211_BAND_2GHZ:
445 switch (chandef->width) {
446 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800447 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
448 phymode = MODE_11B;
449 else
450 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300451 break;
452 case NL80211_CHAN_WIDTH_20:
453 phymode = MODE_11NG_HT20;
454 break;
455 case NL80211_CHAN_WIDTH_40:
456 phymode = MODE_11NG_HT40;
457 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400458 case NL80211_CHAN_WIDTH_5:
459 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300460 case NL80211_CHAN_WIDTH_80:
461 case NL80211_CHAN_WIDTH_80P80:
462 case NL80211_CHAN_WIDTH_160:
463 phymode = MODE_UNKNOWN;
464 break;
465 }
466 break;
467 case IEEE80211_BAND_5GHZ:
468 switch (chandef->width) {
469 case NL80211_CHAN_WIDTH_20_NOHT:
470 phymode = MODE_11A;
471 break;
472 case NL80211_CHAN_WIDTH_20:
473 phymode = MODE_11NA_HT20;
474 break;
475 case NL80211_CHAN_WIDTH_40:
476 phymode = MODE_11NA_HT40;
477 break;
478 case NL80211_CHAN_WIDTH_80:
479 phymode = MODE_11AC_VHT80;
480 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400481 case NL80211_CHAN_WIDTH_5:
482 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300483 case NL80211_CHAN_WIDTH_80P80:
484 case NL80211_CHAN_WIDTH_160:
485 phymode = MODE_UNKNOWN;
486 break;
487 }
488 break;
489 default:
490 break;
491 }
492
493 WARN_ON(phymode == MODE_UNKNOWN);
494 return phymode;
495}
496
497static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
498{
499/*
500 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
501 * 0 for no restriction
502 * 1 for 1/4 us
503 * 2 for 1/2 us
504 * 3 for 1 us
505 * 4 for 2 us
506 * 5 for 4 us
507 * 6 for 8 us
508 * 7 for 16 us
509 */
510 switch (mpdudensity) {
511 case 0:
512 return 0;
513 case 1:
514 case 2:
515 case 3:
516 /* Our lower layer calculations limit our precision to
517 1 microsecond */
518 return 1;
519 case 4:
520 return 2;
521 case 5:
522 return 4;
523 case 6:
524 return 8;
525 case 7:
526 return 16;
527 default:
528 return 0;
529 }
530}
531
Michal Kazior500ff9f2015-03-31 10:26:21 +0000532int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
533 struct cfg80211_chan_def *def)
534{
535 struct ieee80211_chanctx_conf *conf;
536
537 rcu_read_lock();
538 conf = rcu_dereference(vif->chanctx_conf);
539 if (!conf) {
540 rcu_read_unlock();
541 return -ENOENT;
542 }
543
544 *def = conf->def;
545 rcu_read_unlock();
546
547 return 0;
548}
549
550static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
551 struct ieee80211_chanctx_conf *conf,
552 void *data)
553{
554 int *num = data;
555
556 (*num)++;
557}
558
559static int ath10k_mac_num_chanctxs(struct ath10k *ar)
560{
561 int num = 0;
562
563 ieee80211_iter_chan_contexts_atomic(ar->hw,
564 ath10k_mac_num_chanctxs_iter,
565 &num);
566
567 return num;
568}
569
570static void
571ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
572 struct ieee80211_chanctx_conf *conf,
573 void *data)
574{
575 struct cfg80211_chan_def **def = data;
576
577 *def = &conf->def;
578}
579
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300580static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
581 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300582{
583 int ret;
584
585 lockdep_assert_held(&ar->conf_mutex);
586
Michal Kaziorcfd10612014-11-25 15:16:05 +0100587 if (ar->num_peers >= ar->max_num_peers)
588 return -ENOBUFS;
589
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300590 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800591 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200592 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200593 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800595 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300596
597 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800598 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200599 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200600 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300601 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800602 }
Michal Kazior292a7532014-11-25 15:16:04 +0100603
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100604 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300605
606 return 0;
607}
608
Kalle Valo5a13e762014-01-20 11:01:46 +0200609static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
610{
611 struct ath10k *ar = arvif->ar;
612 u32 param;
613 int ret;
614
615 param = ar->wmi.pdev_param->sta_kickout_th;
616 ret = ath10k_wmi_pdev_set_param(ar, param,
617 ATH10K_KICKOUT_THRESHOLD);
618 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200619 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200620 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200621 return ret;
622 }
623
624 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
625 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
626 ATH10K_KEEPALIVE_MIN_IDLE);
627 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200628 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200629 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200630 return ret;
631 }
632
633 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
634 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
635 ATH10K_KEEPALIVE_MAX_IDLE);
636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200637 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200638 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200639 return ret;
640 }
641
642 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
643 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
644 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
645 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200646 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200647 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200648 return ret;
649 }
650
651 return 0;
652}
653
Vivek Natarajanacab6402014-11-26 09:06:12 +0200654static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200655{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200656 struct ath10k *ar = arvif->ar;
657 u32 vdev_param;
658
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200659 vdev_param = ar->wmi.vdev_param->rts_threshold;
660 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200661}
662
663static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
664{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200665 struct ath10k *ar = arvif->ar;
666 u32 vdev_param;
667
Michal Kazior424121c2013-07-22 14:13:31 +0200668 if (value != 0xFFFFFFFF)
669 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
670 ATH10K_FRAGMT_THRESHOLD_MIN,
671 ATH10K_FRAGMT_THRESHOLD_MAX);
672
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200673 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
674 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200675}
676
Kalle Valo5e3dd152013-06-12 20:52:10 +0300677static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
678{
679 int ret;
680
681 lockdep_assert_held(&ar->conf_mutex);
682
683 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
684 if (ret)
685 return ret;
686
687 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
688 if (ret)
689 return ret;
690
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100691 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100692
Kalle Valo5e3dd152013-06-12 20:52:10 +0300693 return 0;
694}
695
696static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
697{
698 struct ath10k_peer *peer, *tmp;
699
700 lockdep_assert_held(&ar->conf_mutex);
701
702 spin_lock_bh(&ar->data_lock);
703 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
704 if (peer->vdev_id != vdev_id)
705 continue;
706
Michal Kazior7aa7a722014-08-25 12:09:38 +0200707 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300708 peer->addr, vdev_id);
709
710 list_del(&peer->list);
711 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100712 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300713 }
714 spin_unlock_bh(&ar->data_lock);
715}
716
Michal Kaziora96d7742013-07-16 09:38:56 +0200717static void ath10k_peer_cleanup_all(struct ath10k *ar)
718{
719 struct ath10k_peer *peer, *tmp;
720
721 lockdep_assert_held(&ar->conf_mutex);
722
723 spin_lock_bh(&ar->data_lock);
724 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
725 list_del(&peer->list);
726 kfree(peer);
727 }
728 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100729
730 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100731 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200732}
733
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300734static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
735 struct ieee80211_sta *sta,
736 enum wmi_tdls_peer_state state)
737{
738 int ret;
739 struct wmi_tdls_peer_update_cmd_arg arg = {};
740 struct wmi_tdls_peer_capab_arg cap = {};
741 struct wmi_channel_arg chan_arg = {};
742
743 lockdep_assert_held(&ar->conf_mutex);
744
745 arg.vdev_id = vdev_id;
746 arg.peer_state = state;
747 ether_addr_copy(arg.addr, sta->addr);
748
749 cap.peer_max_sp = sta->max_sp;
750 cap.peer_uapsd_queues = sta->uapsd_queues;
751
752 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
753 !sta->tdls_initiator)
754 cap.is_peer_responder = 1;
755
756 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
757 if (ret) {
758 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
759 arg.addr, vdev_id, ret);
760 return ret;
761 }
762
763 return 0;
764}
765
Kalle Valo5e3dd152013-06-12 20:52:10 +0300766/************************/
767/* Interface management */
768/************************/
769
Michal Kazior64badcb2014-09-18 11:18:02 +0300770void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
771{
772 struct ath10k *ar = arvif->ar;
773
774 lockdep_assert_held(&ar->data_lock);
775
776 if (!arvif->beacon)
777 return;
778
779 if (!arvif->beacon_buf)
780 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
781 arvif->beacon->len, DMA_TO_DEVICE);
782
Michal Kazioraf213192015-01-29 14:29:52 +0200783 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
784 arvif->beacon_state != ATH10K_BEACON_SENT))
785 return;
786
Michal Kazior64badcb2014-09-18 11:18:02 +0300787 dev_kfree_skb_any(arvif->beacon);
788
789 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200790 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300791}
792
793static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
794{
795 struct ath10k *ar = arvif->ar;
796
797 lockdep_assert_held(&ar->data_lock);
798
799 ath10k_mac_vif_beacon_free(arvif);
800
801 if (arvif->beacon_buf) {
802 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
803 arvif->beacon_buf, arvif->beacon_paddr);
804 arvif->beacon_buf = NULL;
805 }
806}
807
Kalle Valo5e3dd152013-06-12 20:52:10 +0300808static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
809{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300810 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300811
Michal Kazior548db542013-07-05 16:15:15 +0300812 lockdep_assert_held(&ar->conf_mutex);
813
Michal Kazior7962b0d2014-10-28 10:34:38 +0100814 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
815 return -ESHUTDOWN;
816
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300817 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
818 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
819 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300820 return -ETIMEDOUT;
821
822 return 0;
823}
824
Michal Kazior1bbc0972014-04-08 09:45:47 +0300825static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300826{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000827 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100828 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300829 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300830 int ret = 0;
831
832 lockdep_assert_held(&ar->conf_mutex);
833
Michal Kazior500ff9f2015-03-31 10:26:21 +0000834 ieee80211_iter_chan_contexts_atomic(ar->hw,
835 ath10k_mac_get_any_chandef_iter,
836 &chandef);
837 if (WARN_ON_ONCE(!chandef))
838 return -ENOENT;
839
840 channel = chandef->chan;
841
Kalle Valo5e3dd152013-06-12 20:52:10 +0300842 arg.vdev_id = vdev_id;
843 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100844 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300845
846 /* TODO setup this dynamically, what in case we
847 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100848 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200849 arg.channel.chan_radar =
850 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300851
Michal Kazior89c5c842013-10-23 04:02:13 -0700852 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700853 arg.channel.max_power = channel->max_power * 2;
854 arg.channel.max_reg_power = channel->max_reg_power * 2;
855 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300856
Michal Kazior7962b0d2014-10-28 10:34:38 +0100857 reinit_completion(&ar->vdev_setup_done);
858
Kalle Valo5e3dd152013-06-12 20:52:10 +0300859 ret = ath10k_wmi_vdev_start(ar, &arg);
860 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200861 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200862 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863 return ret;
864 }
865
866 ret = ath10k_vdev_setup_sync(ar);
867 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200868 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200869 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870 return ret;
871 }
872
873 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
874 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200875 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200876 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300877 goto vdev_stop;
878 }
879
880 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300881
Michal Kazior7aa7a722014-08-25 12:09:38 +0200882 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300883 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300884 return 0;
885
886vdev_stop:
887 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
888 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200889 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200890 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300891
892 return ret;
893}
894
Michal Kazior1bbc0972014-04-08 09:45:47 +0300895static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300896{
897 int ret = 0;
898
899 lockdep_assert_held(&ar->conf_mutex);
900
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200901 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
902 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200903 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200904 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300905
Michal Kazior7962b0d2014-10-28 10:34:38 +0100906 reinit_completion(&ar->vdev_setup_done);
907
Kalle Valo5e3dd152013-06-12 20:52:10 +0300908 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
909 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200910 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200911 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300912
913 ret = ath10k_vdev_setup_sync(ar);
914 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200915 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200916 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917
Michal Kazior7aa7a722014-08-25 12:09:38 +0200918 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300919 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 return ret;
921}
922
Michal Kazior1bbc0972014-04-08 09:45:47 +0300923static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300924{
925 int bit, ret = 0;
926
927 lockdep_assert_held(&ar->conf_mutex);
928
Ben Greeara9aefb32014-08-12 11:02:19 +0300929 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200930 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300931 return -ENOMEM;
932 }
933
Ben Greear16c11172014-09-23 14:17:16 -0700934 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300935
Ben Greear16c11172014-09-23 14:17:16 -0700936 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300937
938 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
939 WMI_VDEV_TYPE_MONITOR,
940 0, ar->mac_addr);
941 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200942 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200943 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300944 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300945 }
946
Ben Greear16c11172014-09-23 14:17:16 -0700947 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200948 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 ar->monitor_vdev_id);
950
Kalle Valo5e3dd152013-06-12 20:52:10 +0300951 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300952}
953
Michal Kazior1bbc0972014-04-08 09:45:47 +0300954static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955{
956 int ret = 0;
957
958 lockdep_assert_held(&ar->conf_mutex);
959
Kalle Valo5e3dd152013-06-12 20:52:10 +0300960 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
961 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200962 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200963 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300964 return ret;
965 }
966
Ben Greear16c11172014-09-23 14:17:16 -0700967 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300968
Michal Kazior7aa7a722014-08-25 12:09:38 +0200969 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300970 ar->monitor_vdev_id);
971 return ret;
972}
973
Michal Kazior1bbc0972014-04-08 09:45:47 +0300974static int ath10k_monitor_start(struct ath10k *ar)
975{
976 int ret;
977
978 lockdep_assert_held(&ar->conf_mutex);
979
Michal Kazior1bbc0972014-04-08 09:45:47 +0300980 ret = ath10k_monitor_vdev_create(ar);
981 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200982 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300983 return ret;
984 }
985
986 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
987 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200988 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300989 ath10k_monitor_vdev_delete(ar);
990 return ret;
991 }
992
993 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200994 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300995
996 return 0;
997}
998
Michal Kazior19337472014-08-28 12:58:16 +0200999static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +03001000{
1001 int ret;
1002
1003 lockdep_assert_held(&ar->conf_mutex);
1004
Michal Kazior1bbc0972014-04-08 09:45:47 +03001005 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001006 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001007 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001008 return ret;
1009 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001010
1011 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001012 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001013 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001014 return ret;
1015 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001016
1017 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001018 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001019
1020 return 0;
1021}
1022
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301023static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1024{
1025 struct ath10k_vif *arvif;
1026
1027 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1028 return true;
1029
1030 if (!ar->num_started_vdevs)
1031 return false;
1032
1033 list_for_each_entry(arvif, &ar->arvifs, list)
1034 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1035 return false;
1036
1037 ath10k_dbg(ar, ATH10K_DBG_MAC,
1038 "mac disabling promiscuous mode because vdev is started\n");
1039 return true;
1040}
1041
Michal Kazior500ff9f2015-03-31 10:26:21 +00001042static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1043{
1044 int num_ctx;
1045
1046 /* At least one chanctx is required to derive a channel to start
1047 * monitor vdev on.
1048 */
1049 num_ctx = ath10k_mac_num_chanctxs(ar);
1050 if (num_ctx == 0)
1051 return false;
1052
1053 /* If there's already an existing special monitor interface then don't
1054 * bother creating another monitor vdev.
1055 */
1056 if (ar->monitor_arvif)
1057 return false;
1058
1059 return ar->monitor ||
1060 !ath10k_mac_should_disable_promisc(ar) ||
1061 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1062}
1063
1064static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1065{
1066 int num_ctx;
1067
1068 num_ctx = ath10k_mac_num_chanctxs(ar);
1069
1070 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1071 * shouldn't allow this but make sure to prevent handling the following
1072 * case anyway since multi-channel DFS hasn't been tested at all.
1073 */
1074 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1075 return false;
1076
1077 return true;
1078}
1079
Michal Kazior19337472014-08-28 12:58:16 +02001080static int ath10k_monitor_recalc(struct ath10k *ar)
1081{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001082 bool needed;
1083 bool allowed;
1084 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001085
1086 lockdep_assert_held(&ar->conf_mutex);
1087
Michal Kazior500ff9f2015-03-31 10:26:21 +00001088 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1089 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001090
1091 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001092 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1093 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001094
Michal Kazior500ff9f2015-03-31 10:26:21 +00001095 if (WARN_ON(needed && !allowed)) {
1096 if (ar->monitor_started) {
1097 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1098
1099 ret = ath10k_monitor_stop(ar);
1100 if (ret)
1101 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1102 /* not serious */
1103 }
1104
1105 return -EPERM;
1106 }
1107
1108 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001109 return 0;
1110
Michal Kazior500ff9f2015-03-31 10:26:21 +00001111 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001112 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001113 else
1114 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001115}
1116
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001117static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1118{
1119 struct ath10k *ar = arvif->ar;
1120 u32 vdev_param, rts_cts = 0;
1121
1122 lockdep_assert_held(&ar->conf_mutex);
1123
1124 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1125
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001126 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001127
1128 if (arvif->num_legacy_stations > 0)
1129 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1130 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001131 else
1132 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1133 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001134
1135 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1136 rts_cts);
1137}
1138
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001139static int ath10k_start_cac(struct ath10k *ar)
1140{
1141 int ret;
1142
1143 lockdep_assert_held(&ar->conf_mutex);
1144
1145 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1146
Michal Kazior19337472014-08-28 12:58:16 +02001147 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001148 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001149 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001150 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1151 return ret;
1152 }
1153
Michal Kazior7aa7a722014-08-25 12:09:38 +02001154 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001155 ar->monitor_vdev_id);
1156
1157 return 0;
1158}
1159
1160static int ath10k_stop_cac(struct ath10k *ar)
1161{
1162 lockdep_assert_held(&ar->conf_mutex);
1163
1164 /* CAC is not running - do nothing */
1165 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1166 return 0;
1167
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001168 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001169 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001170
Michal Kazior7aa7a722014-08-25 12:09:38 +02001171 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001172
1173 return 0;
1174}
1175
Michal Kazior500ff9f2015-03-31 10:26:21 +00001176static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1177 struct ieee80211_chanctx_conf *conf,
1178 void *data)
1179{
1180 bool *ret = data;
1181
1182 if (!*ret && conf->radar_enabled)
1183 *ret = true;
1184}
1185
1186static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1187{
1188 bool has_radar = false;
1189
1190 ieee80211_iter_chan_contexts_atomic(ar->hw,
1191 ath10k_mac_has_radar_iter,
1192 &has_radar);
1193
1194 return has_radar;
1195}
1196
Michal Kaziord6500972014-04-08 09:56:09 +03001197static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001198{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001199 int ret;
1200
1201 lockdep_assert_held(&ar->conf_mutex);
1202
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001203 ath10k_stop_cac(ar);
1204
Michal Kazior500ff9f2015-03-31 10:26:21 +00001205 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001206 return;
1207
Michal Kaziord6500972014-04-08 09:56:09 +03001208 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001209 return;
1210
1211 ret = ath10k_start_cac(ar);
1212 if (ret) {
1213 /*
1214 * Not possible to start CAC on current channel so starting
1215 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1216 * by indicating that radar was detected.
1217 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001218 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001219 ieee80211_radar_detected(ar->hw);
1220 }
1221}
1222
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301223static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1224{
1225 struct ath10k *ar = arvif->ar;
1226 int ret;
1227
1228 lockdep_assert_held(&ar->conf_mutex);
1229
1230 reinit_completion(&ar->vdev_setup_done);
1231
1232 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1233 if (ret) {
1234 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1235 arvif->vdev_id, ret);
1236 return ret;
1237 }
1238
1239 ret = ath10k_vdev_setup_sync(ar);
1240 if (ret) {
1241 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1242 arvif->vdev_id, ret);
1243 return ret;
1244 }
1245
1246 WARN_ON(ar->num_started_vdevs == 0);
1247
1248 if (ar->num_started_vdevs != 0) {
1249 ar->num_started_vdevs--;
1250 ath10k_recalc_radar_detection(ar);
1251 }
1252
1253 return ret;
1254}
1255
Michal Kazior500ff9f2015-03-31 10:26:21 +00001256static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1257 const struct cfg80211_chan_def *chandef,
1258 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001259{
1260 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001261 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301262 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001263
1264 lockdep_assert_held(&ar->conf_mutex);
1265
1266 reinit_completion(&ar->vdev_setup_done);
1267
1268 arg.vdev_id = arvif->vdev_id;
1269 arg.dtim_period = arvif->dtim_period;
1270 arg.bcn_intval = arvif->beacon_interval;
1271
1272 arg.channel.freq = chandef->chan->center_freq;
1273 arg.channel.band_center_freq1 = chandef->center_freq1;
1274 arg.channel.mode = chan_to_phymode(chandef);
1275
1276 arg.channel.min_power = 0;
1277 arg.channel.max_power = chandef->chan->max_power * 2;
1278 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1279 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1280
1281 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1282 arg.ssid = arvif->u.ap.ssid;
1283 arg.ssid_len = arvif->u.ap.ssid_len;
1284 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1285
1286 /* For now allow DFS for AP mode */
1287 arg.channel.chan_radar =
1288 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1289 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1290 arg.ssid = arvif->vif->bss_conf.ssid;
1291 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1292 }
1293
Michal Kazior7aa7a722014-08-25 12:09:38 +02001294 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001295 "mac vdev %d start center_freq %d phymode %s\n",
1296 arg.vdev_id, arg.channel.freq,
1297 ath10k_wmi_phymode_str(arg.channel.mode));
1298
Michal Kaziordc55e302014-07-29 12:53:36 +03001299 if (restart)
1300 ret = ath10k_wmi_vdev_restart(ar, &arg);
1301 else
1302 ret = ath10k_wmi_vdev_start(ar, &arg);
1303
Michal Kazior72654fa2014-04-08 09:56:09 +03001304 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001305 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001306 arg.vdev_id, ret);
1307 return ret;
1308 }
1309
1310 ret = ath10k_vdev_setup_sync(ar);
1311 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001312 ath10k_warn(ar,
1313 "failed to synchronize setup for vdev %i restart %d: %d\n",
1314 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001315 return ret;
1316 }
1317
Michal Kaziord6500972014-04-08 09:56:09 +03001318 ar->num_started_vdevs++;
1319 ath10k_recalc_radar_detection(ar);
1320
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301321 ret = ath10k_monitor_recalc(ar);
1322 if (ret) {
1323 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1324 arg.vdev_id, restart, ret);
1325 ret2 = ath10k_vdev_stop(arvif);
1326 if (ret2)
1327 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1328 arg.vdev_id, restart, ret2);
1329 }
1330
Michal Kazior72654fa2014-04-08 09:56:09 +03001331 return ret;
1332}
1333
Michal Kazior500ff9f2015-03-31 10:26:21 +00001334static int ath10k_vdev_start(struct ath10k_vif *arvif,
1335 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001336{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001337 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001338}
1339
Michal Kazior500ff9f2015-03-31 10:26:21 +00001340static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1341 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001342{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001343 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001344}
1345
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001346static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1347 struct sk_buff *bcn)
1348{
1349 struct ath10k *ar = arvif->ar;
1350 struct ieee80211_mgmt *mgmt;
1351 const u8 *p2p_ie;
1352 int ret;
1353
1354 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1355 return 0;
1356
1357 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1358 return 0;
1359
1360 mgmt = (void *)bcn->data;
1361 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1362 mgmt->u.beacon.variable,
1363 bcn->len - (mgmt->u.beacon.variable -
1364 bcn->data));
1365 if (!p2p_ie)
1366 return -ENOENT;
1367
1368 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1369 if (ret) {
1370 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1371 arvif->vdev_id, ret);
1372 return ret;
1373 }
1374
1375 return 0;
1376}
1377
1378static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1379 u8 oui_type, size_t ie_offset)
1380{
1381 size_t len;
1382 const u8 *next;
1383 const u8 *end;
1384 u8 *ie;
1385
1386 if (WARN_ON(skb->len < ie_offset))
1387 return -EINVAL;
1388
1389 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1390 skb->data + ie_offset,
1391 skb->len - ie_offset);
1392 if (!ie)
1393 return -ENOENT;
1394
1395 len = ie[1] + 2;
1396 end = skb->data + skb->len;
1397 next = ie + len;
1398
1399 if (WARN_ON(next > end))
1400 return -EINVAL;
1401
1402 memmove(ie, next, end - next);
1403 skb_trim(skb, skb->len - len);
1404
1405 return 0;
1406}
1407
1408static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1409{
1410 struct ath10k *ar = arvif->ar;
1411 struct ieee80211_hw *hw = ar->hw;
1412 struct ieee80211_vif *vif = arvif->vif;
1413 struct ieee80211_mutable_offsets offs = {};
1414 struct sk_buff *bcn;
1415 int ret;
1416
1417 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1418 return 0;
1419
Michal Kazior81a9a172015-03-05 16:02:17 +02001420 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1421 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1422 return 0;
1423
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001424 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1425 if (!bcn) {
1426 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1427 return -EPERM;
1428 }
1429
1430 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1431 if (ret) {
1432 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1433 kfree_skb(bcn);
1434 return ret;
1435 }
1436
1437 /* P2P IE is inserted by firmware automatically (as configured above)
1438 * so remove it from the base beacon template to avoid duplicate P2P
1439 * IEs in beacon frames.
1440 */
1441 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1442 offsetof(struct ieee80211_mgmt,
1443 u.beacon.variable));
1444
1445 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1446 0, NULL, 0);
1447 kfree_skb(bcn);
1448
1449 if (ret) {
1450 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1451 ret);
1452 return ret;
1453 }
1454
1455 return 0;
1456}
1457
1458static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1459{
1460 struct ath10k *ar = arvif->ar;
1461 struct ieee80211_hw *hw = ar->hw;
1462 struct ieee80211_vif *vif = arvif->vif;
1463 struct sk_buff *prb;
1464 int ret;
1465
1466 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1467 return 0;
1468
Michal Kazior81a9a172015-03-05 16:02:17 +02001469 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1470 return 0;
1471
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001472 prb = ieee80211_proberesp_get(hw, vif);
1473 if (!prb) {
1474 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1475 return -EPERM;
1476 }
1477
1478 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1479 kfree_skb(prb);
1480
1481 if (ret) {
1482 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1483 ret);
1484 return ret;
1485 }
1486
1487 return 0;
1488}
1489
Michal Kazior500ff9f2015-03-31 10:26:21 +00001490static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1491{
1492 struct ath10k *ar = arvif->ar;
1493 struct cfg80211_chan_def def;
1494 int ret;
1495
1496 /* When originally vdev is started during assign_vif_chanctx() some
1497 * information is missing, notably SSID. Firmware revisions with beacon
1498 * offloading require the SSID to be provided during vdev (re)start to
1499 * handle hidden SSID properly.
1500 *
1501 * Vdev restart must be done after vdev has been both started and
1502 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1503 * deliver vdev restart response event causing timeouts during vdev
1504 * syncing in ath10k.
1505 *
1506 * Note: The vdev down/up and template reinstallation could be skipped
1507 * since only wmi-tlv firmware are known to have beacon offload and
1508 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1509 * response delivery. It's probably more robust to keep it as is.
1510 */
1511 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1512 return 0;
1513
1514 if (WARN_ON(!arvif->is_started))
1515 return -EINVAL;
1516
1517 if (WARN_ON(!arvif->is_up))
1518 return -EINVAL;
1519
1520 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1521 return -EINVAL;
1522
1523 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1524 if (ret) {
1525 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1526 arvif->vdev_id, ret);
1527 return ret;
1528 }
1529
1530 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1531 * firmware will crash upon vdev up.
1532 */
1533
1534 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1535 if (ret) {
1536 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1537 return ret;
1538 }
1539
1540 ret = ath10k_mac_setup_prb_tmpl(arvif);
1541 if (ret) {
1542 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1543 return ret;
1544 }
1545
1546 ret = ath10k_vdev_restart(arvif, &def);
1547 if (ret) {
1548 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1549 arvif->vdev_id, ret);
1550 return ret;
1551 }
1552
1553 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1554 arvif->bssid);
1555 if (ret) {
1556 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1557 arvif->vdev_id, ret);
1558 return ret;
1559 }
1560
1561 return 0;
1562}
1563
Kalle Valo5e3dd152013-06-12 20:52:10 +03001564static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001565 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001566{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001567 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001568 int ret = 0;
1569
Michal Kazior548db542013-07-05 16:15:15 +03001570 lockdep_assert_held(&arvif->ar->conf_mutex);
1571
Kalle Valo5e3dd152013-06-12 20:52:10 +03001572 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001573 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1574 if (ret)
1575 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1576 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001577
Michal Kaziorc930f742014-01-23 11:38:25 +01001578 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001579
1580 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001581 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001582 spin_unlock_bh(&arvif->ar->data_lock);
1583
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584 return;
1585 }
1586
1587 arvif->tx_seq_no = 0x1000;
1588
Michal Kaziorc930f742014-01-23 11:38:25 +01001589 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001590 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001591
1592 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1593 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001594 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001595 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001596 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597 return;
1598 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001599
Michal Kaziorc930f742014-01-23 11:38:25 +01001600 arvif->is_up = true;
1601
Michal Kazior500ff9f2015-03-31 10:26:21 +00001602 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1603 if (ret) {
1604 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1605 arvif->vdev_id, ret);
1606 return;
1607 }
1608
Michal Kazior7aa7a722014-08-25 12:09:38 +02001609 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001610}
1611
1612static void ath10k_control_ibss(struct ath10k_vif *arvif,
1613 struct ieee80211_bss_conf *info,
1614 const u8 self_peer[ETH_ALEN])
1615{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001616 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001617 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 int ret = 0;
1619
Michal Kazior548db542013-07-05 16:15:15 +03001620 lockdep_assert_held(&arvif->ar->conf_mutex);
1621
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001623 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 return;
1625
Michal Kaziorc930f742014-01-23 11:38:25 +01001626 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627
1628 return;
1629 }
1630
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001631 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1632 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 ATH10K_DEFAULT_ATIM);
1634 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001635 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 arvif->vdev_id, ret);
1637}
1638
Michal Kazior9f9b5742014-12-12 12:41:36 +01001639static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1640{
1641 struct ath10k *ar = arvif->ar;
1642 u32 param;
1643 u32 value;
1644 int ret;
1645
1646 lockdep_assert_held(&arvif->ar->conf_mutex);
1647
1648 if (arvif->u.sta.uapsd)
1649 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1650 else
1651 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1652
1653 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1654 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1655 if (ret) {
1656 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1657 value, arvif->vdev_id, ret);
1658 return ret;
1659 }
1660
1661 return 0;
1662}
1663
1664static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1665{
1666 struct ath10k *ar = arvif->ar;
1667 u32 param;
1668 u32 value;
1669 int ret;
1670
1671 lockdep_assert_held(&arvif->ar->conf_mutex);
1672
1673 if (arvif->u.sta.uapsd)
1674 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1675 else
1676 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1677
1678 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1679 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1680 param, value);
1681 if (ret) {
1682 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1683 value, arvif->vdev_id, ret);
1684 return ret;
1685 }
1686
1687 return 0;
1688}
1689
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001690static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1691{
1692 struct ath10k_vif *arvif;
1693 int num = 0;
1694
1695 lockdep_assert_held(&ar->conf_mutex);
1696
1697 list_for_each_entry(arvif, &ar->arvifs, list)
1698 if (arvif->ps)
1699 num++;
1700
1701 return num;
1702}
1703
Michal Kaziorad088bf2013-10-16 15:44:46 +03001704static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001705{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001706 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001707 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001708 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001709 enum wmi_sta_powersave_param param;
1710 enum wmi_sta_ps_mode psmode;
1711 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001712 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001713 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001714
Michal Kazior548db542013-07-05 16:15:15 +03001715 lockdep_assert_held(&arvif->ar->conf_mutex);
1716
Michal Kaziorad088bf2013-10-16 15:44:46 +03001717 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1718 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001719
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001720 enable_ps = arvif->ps;
1721
1722 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1723 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1724 ar->fw_features)) {
1725 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1726 arvif->vdev_id);
1727 enable_ps = false;
1728 }
1729
1730 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 psmode = WMI_STA_PS_MODE_ENABLED;
1732 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1733
Michal Kazior526549a2014-12-12 12:41:37 +01001734 ps_timeout = conf->dynamic_ps_timeout;
1735 if (ps_timeout == 0) {
1736 /* Firmware doesn't like 0 */
1737 ps_timeout = ieee80211_tu_to_usec(
1738 vif->bss_conf.beacon_int) / 1000;
1739 }
1740
Michal Kaziorad088bf2013-10-16 15:44:46 +03001741 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001742 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001744 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001745 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001746 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001747 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001748 } else {
1749 psmode = WMI_STA_PS_MODE_DISABLED;
1750 }
1751
Michal Kazior7aa7a722014-08-25 12:09:38 +02001752 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001753 arvif->vdev_id, psmode ? "enable" : "disable");
1754
Michal Kaziorad088bf2013-10-16 15:44:46 +03001755 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1756 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001757 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001758 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001759 return ret;
1760 }
1761
1762 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763}
1764
Michal Kazior46725b152015-01-28 09:57:49 +02001765static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1766{
1767 struct ath10k *ar = arvif->ar;
1768 struct wmi_sta_keepalive_arg arg = {};
1769 int ret;
1770
1771 lockdep_assert_held(&arvif->ar->conf_mutex);
1772
1773 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1774 return 0;
1775
1776 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1777 return 0;
1778
1779 /* Some firmware revisions have a bug and ignore the `enabled` field.
1780 * Instead use the interval to disable the keepalive.
1781 */
1782 arg.vdev_id = arvif->vdev_id;
1783 arg.enabled = 1;
1784 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1785 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1786
1787 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1788 if (ret) {
1789 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1790 arvif->vdev_id, ret);
1791 return ret;
1792 }
1793
1794 return 0;
1795}
1796
Michal Kazior81a9a172015-03-05 16:02:17 +02001797static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1798{
1799 struct ath10k *ar = arvif->ar;
1800 struct ieee80211_vif *vif = arvif->vif;
1801 int ret;
1802
Michal Kazior8513d952015-03-09 14:19:24 +01001803 lockdep_assert_held(&arvif->ar->conf_mutex);
1804
1805 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1806 return;
1807
Michal Kazior81a9a172015-03-05 16:02:17 +02001808 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1809 return;
1810
1811 if (!vif->csa_active)
1812 return;
1813
1814 if (!arvif->is_up)
1815 return;
1816
1817 if (!ieee80211_csa_is_complete(vif)) {
1818 ieee80211_csa_update_counter(vif);
1819
1820 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1821 if (ret)
1822 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1823 ret);
1824
1825 ret = ath10k_mac_setup_prb_tmpl(arvif);
1826 if (ret)
1827 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1828 ret);
1829 } else {
1830 ieee80211_csa_finish(vif);
1831 }
1832}
1833
1834static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1835{
1836 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1837 ap_csa_work);
1838 struct ath10k *ar = arvif->ar;
1839
1840 mutex_lock(&ar->conf_mutex);
1841 ath10k_mac_vif_ap_csa_count_down(arvif);
1842 mutex_unlock(&ar->conf_mutex);
1843}
1844
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001845static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1846 struct ieee80211_vif *vif)
1847{
1848 struct sk_buff *skb = data;
1849 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1850 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1851
1852 if (vif->type != NL80211_IFTYPE_STATION)
1853 return;
1854
1855 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1856 return;
1857
1858 cancel_delayed_work(&arvif->connection_loss_work);
1859}
1860
1861void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1862{
1863 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1864 IEEE80211_IFACE_ITER_NORMAL,
1865 ath10k_mac_handle_beacon_iter,
1866 skb);
1867}
1868
1869static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1870 struct ieee80211_vif *vif)
1871{
1872 u32 *vdev_id = data;
1873 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1874 struct ath10k *ar = arvif->ar;
1875 struct ieee80211_hw *hw = ar->hw;
1876
1877 if (arvif->vdev_id != *vdev_id)
1878 return;
1879
1880 if (!arvif->is_up)
1881 return;
1882
1883 ieee80211_beacon_loss(vif);
1884
1885 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1886 * (done by mac80211) succeeds but beacons do not resume then it
1887 * doesn't make sense to continue operation. Queue connection loss work
1888 * which can be cancelled when beacon is received.
1889 */
1890 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1891 ATH10K_CONNECTION_LOSS_HZ);
1892}
1893
1894void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1895{
1896 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1897 IEEE80211_IFACE_ITER_NORMAL,
1898 ath10k_mac_handle_beacon_miss_iter,
1899 &vdev_id);
1900}
1901
1902static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1903{
1904 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1905 connection_loss_work.work);
1906 struct ieee80211_vif *vif = arvif->vif;
1907
1908 if (!arvif->is_up)
1909 return;
1910
1911 ieee80211_connection_loss(vif);
1912}
1913
Kalle Valo5e3dd152013-06-12 20:52:10 +03001914/**********************/
1915/* Station management */
1916/**********************/
1917
Michal Kazior590922a2014-10-21 10:10:29 +03001918static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1919 struct ieee80211_vif *vif)
1920{
1921 /* Some firmware revisions have unstable STA powersave when listen
1922 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1923 * generate NullFunc frames properly even if buffered frames have been
1924 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1925 * buffered frames. Often pinging the device from AP would simply fail.
1926 *
1927 * As a workaround set it to 1.
1928 */
1929 if (vif->type == NL80211_IFTYPE_STATION)
1930 return 1;
1931
1932 return ar->hw->conf.listen_interval;
1933}
1934
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001936 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 struct wmi_peer_assoc_complete_arg *arg)
1939{
Michal Kazior590922a2014-10-21 10:10:29 +03001940 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001941 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001942
Michal Kazior548db542013-07-05 16:15:15 +03001943 lockdep_assert_held(&ar->conf_mutex);
1944
Michal Kaziorc51880e2015-03-30 09:51:57 +03001945 if (vif->type == NL80211_IFTYPE_STATION)
1946 aid = vif->bss_conf.aid;
1947 else
1948 aid = sta->aid;
1949
Kalle Valob25f32c2014-09-14 12:50:49 +03001950 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001952 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001954 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001956 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001957}
1958
1959static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001960 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001961 struct wmi_peer_assoc_complete_arg *arg)
1962{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001963 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001964 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 struct cfg80211_bss *bss;
1966 const u8 *rsnie = NULL;
1967 const u8 *wpaie = NULL;
1968
Michal Kazior548db542013-07-05 16:15:15 +03001969 lockdep_assert_held(&ar->conf_mutex);
1970
Michal Kazior500ff9f2015-03-31 10:26:21 +00001971 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1972 return;
1973
1974 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1975 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 if (bss) {
1977 const struct cfg80211_bss_ies *ies;
1978
1979 rcu_read_lock();
1980 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1981
1982 ies = rcu_dereference(bss->ies);
1983
1984 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001985 WLAN_OUI_TYPE_MICROSOFT_WPA,
1986 ies->data,
1987 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988 rcu_read_unlock();
1989 cfg80211_put_bss(ar->hw->wiphy, bss);
1990 }
1991
1992 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1993 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001994 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1996 }
1997
1998 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001999 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002000 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2001 }
2002}
2003
2004static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002005 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 struct ieee80211_sta *sta,
2007 struct wmi_peer_assoc_complete_arg *arg)
2008{
2009 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002010 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011 const struct ieee80211_supported_band *sband;
2012 const struct ieee80211_rate *rates;
2013 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002014 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 int i;
2016
Michal Kazior548db542013-07-05 16:15:15 +03002017 lockdep_assert_held(&ar->conf_mutex);
2018
Michal Kazior500ff9f2015-03-31 10:26:21 +00002019 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2020 return;
2021
2022 sband = ar->hw->wiphy->bands[def.chan->band];
2023 ratemask = sta->supp_rates[def.chan->band];
Kalle Valo5e3dd152013-06-12 20:52:10 +03002024 rates = sband->bitrates;
2025
2026 rateset->num_rates = 0;
2027
2028 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2029 if (!(ratemask & 1))
2030 continue;
2031
Michal Kazior486017c2015-03-30 09:51:54 +03002032 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2033 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002034 rateset->num_rates++;
2035 }
2036}
2037
2038static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2039 struct ieee80211_sta *sta,
2040 struct wmi_peer_assoc_complete_arg *arg)
2041{
2042 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03002044 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045
Michal Kazior548db542013-07-05 16:15:15 +03002046 lockdep_assert_held(&ar->conf_mutex);
2047
Kalle Valo5e3dd152013-06-12 20:52:10 +03002048 if (!ht_cap->ht_supported)
2049 return;
2050
2051 arg->peer_flags |= WMI_PEER_HT;
2052 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2053 ht_cap->ampdu_factor)) - 1;
2054
2055 arg->peer_mpdu_density =
2056 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2057
2058 arg->peer_ht_caps = ht_cap->cap;
2059 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2060
2061 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2062 arg->peer_flags |= WMI_PEER_LDPC;
2063
2064 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2065 arg->peer_flags |= WMI_PEER_40MHZ;
2066 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2067 }
2068
2069 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2070 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2071
2072 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2073 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2074
2075 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2076 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2077 arg->peer_flags |= WMI_PEER_STBC;
2078 }
2079
2080 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002081 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2082 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2083 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2084 arg->peer_rate_caps |= stbc;
2085 arg->peer_flags |= WMI_PEER_STBC;
2086 }
2087
Kalle Valo5e3dd152013-06-12 20:52:10 +03002088 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2089 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2090 else if (ht_cap->mcs.rx_mask[1])
2091 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2092
2093 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
2094 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
2095 arg->peer_ht_rates.rates[n++] = i;
2096
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002097 /*
2098 * This is a workaround for HT-enabled STAs which break the spec
2099 * and have no HT capabilities RX mask (no HT RX MCS map).
2100 *
2101 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2102 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2103 *
2104 * Firmware asserts if such situation occurs.
2105 */
2106 if (n == 0) {
2107 arg->peer_ht_rates.num_rates = 8;
2108 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2109 arg->peer_ht_rates.rates[i] = i;
2110 } else {
2111 arg->peer_ht_rates.num_rates = n;
2112 arg->peer_num_spatial_streams = sta->rx_nss;
2113 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002114
Michal Kazior7aa7a722014-08-25 12:09:38 +02002115 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002116 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 arg->peer_ht_rates.num_rates,
2118 arg->peer_num_spatial_streams);
2119}
2120
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002121static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2122 struct ath10k_vif *arvif,
2123 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002124{
2125 u32 uapsd = 0;
2126 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002127 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128
Michal Kazior548db542013-07-05 16:15:15 +03002129 lockdep_assert_held(&ar->conf_mutex);
2130
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002132 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 sta->uapsd_queues, sta->max_sp);
2134
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2136 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2137 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2138 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2139 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2140 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2141 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2142 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2143 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2144 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2145 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2146 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2147
Kalle Valo5e3dd152013-06-12 20:52:10 +03002148 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2149 max_sp = sta->max_sp;
2150
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002151 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2152 sta->addr,
2153 WMI_AP_PS_PEER_PARAM_UAPSD,
2154 uapsd);
2155 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002156 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002157 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002158 return ret;
2159 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002160
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002161 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2162 sta->addr,
2163 WMI_AP_PS_PEER_PARAM_MAX_SP,
2164 max_sp);
2165 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002166 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002167 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002168 return ret;
2169 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170
2171 /* TODO setup this based on STA listen interval and
2172 beacon interval. Currently we don't know
2173 sta->listen_interval - mac80211 patch required.
2174 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002175 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002176 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2177 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002178 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002179 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002180 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002181 return ret;
2182 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002185 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186}
2187
2188static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002189 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190 struct ieee80211_sta *sta,
2191 struct wmi_peer_assoc_complete_arg *arg)
2192{
2193 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002194 struct cfg80211_chan_def def;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002195 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002196
Michal Kazior500ff9f2015-03-31 10:26:21 +00002197 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2198 return;
2199
Kalle Valo5e3dd152013-06-12 20:52:10 +03002200 if (!vht_cap->vht_supported)
2201 return;
2202
2203 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002204
Michal Kazior500ff9f2015-03-31 10:26:21 +00002205 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002206 arg->peer_flags |= WMI_PEER_VHT_2G;
2207
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208 arg->peer_vht_caps = vht_cap->cap;
2209
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002210 ampdu_factor = (vht_cap->cap &
2211 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2212 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2213
2214 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2215 * zero in VHT IE. Using it would result in degraded throughput.
2216 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2217 * it if VHT max_mpdu is smaller. */
2218 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2219 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2220 ampdu_factor)) - 1);
2221
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2223 arg->peer_flags |= WMI_PEER_80MHZ;
2224
2225 arg->peer_vht_rates.rx_max_rate =
2226 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2227 arg->peer_vht_rates.rx_mcs_set =
2228 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2229 arg->peer_vht_rates.tx_max_rate =
2230 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2231 arg->peer_vht_rates.tx_mcs_set =
2232 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2233
Michal Kazior7aa7a722014-08-25 12:09:38 +02002234 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002235 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002236}
2237
2238static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002239 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002240 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002241 struct wmi_peer_assoc_complete_arg *arg)
2242{
Michal Kazior590922a2014-10-21 10:10:29 +03002243 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2244
Kalle Valo5e3dd152013-06-12 20:52:10 +03002245 switch (arvif->vdev_type) {
2246 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002247 if (sta->wme)
2248 arg->peer_flags |= WMI_PEER_QOS;
2249
2250 if (sta->wme && sta->uapsd_queues) {
2251 arg->peer_flags |= WMI_PEER_APSD;
2252 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2253 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002254 break;
2255 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002256 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002257 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002258 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002259 case WMI_VDEV_TYPE_IBSS:
2260 if (sta->wme)
2261 arg->peer_flags |= WMI_PEER_QOS;
2262 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002263 default:
2264 break;
2265 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002266
2267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2268 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002269}
2270
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002271static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002272{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002273 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2274 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002275}
2276
Kalle Valo5e3dd152013-06-12 20:52:10 +03002277static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002278 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279 struct ieee80211_sta *sta,
2280 struct wmi_peer_assoc_complete_arg *arg)
2281{
Michal Kazior500ff9f2015-03-31 10:26:21 +00002282 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2284
Michal Kazior500ff9f2015-03-31 10:26:21 +00002285 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2286 return;
2287
2288 switch (def.chan->band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002290 if (sta->vht_cap.vht_supported) {
2291 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2292 phymode = MODE_11AC_VHT40;
2293 else
2294 phymode = MODE_11AC_VHT20;
2295 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002296 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2297 phymode = MODE_11NG_HT40;
2298 else
2299 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002300 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002302 } else {
2303 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304 }
2305
2306 break;
2307 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002308 /*
2309 * Check VHT first.
2310 */
2311 if (sta->vht_cap.vht_supported) {
2312 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2313 phymode = MODE_11AC_VHT80;
2314 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2315 phymode = MODE_11AC_VHT40;
2316 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2317 phymode = MODE_11AC_VHT20;
2318 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2320 phymode = MODE_11NA_HT40;
2321 else
2322 phymode = MODE_11NA_HT20;
2323 } else {
2324 phymode = MODE_11A;
2325 }
2326
2327 break;
2328 default:
2329 break;
2330 }
2331
Michal Kazior7aa7a722014-08-25 12:09:38 +02002332 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002333 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002334
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335 arg->peer_phymode = phymode;
2336 WARN_ON(phymode == MODE_UNKNOWN);
2337}
2338
Kalle Valob9ada652013-10-16 15:44:46 +03002339static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002340 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002341 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002342 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343{
Michal Kazior548db542013-07-05 16:15:15 +03002344 lockdep_assert_held(&ar->conf_mutex);
2345
Kalle Valob9ada652013-10-16 15:44:46 +03002346 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002347
Michal Kazior590922a2014-10-21 10:10:29 +03002348 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2349 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002350 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002351 ath10k_peer_assoc_h_ht(ar, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002352 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002353 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2354 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355
Kalle Valob9ada652013-10-16 15:44:46 +03002356 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357}
2358
Michal Kazior90046f52014-02-14 14:45:51 +01002359static const u32 ath10k_smps_map[] = {
2360 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2361 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2362 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2363 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2364};
2365
2366static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2367 const u8 *addr,
2368 const struct ieee80211_sta_ht_cap *ht_cap)
2369{
2370 int smps;
2371
2372 if (!ht_cap->ht_supported)
2373 return 0;
2374
2375 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2376 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2377
2378 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2379 return -EINVAL;
2380
2381 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2382 WMI_PEER_SMPS_STATE,
2383 ath10k_smps_map[smps]);
2384}
2385
Michal Kazior139e1702015-02-15 16:50:42 +02002386static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2387 struct ieee80211_vif *vif,
2388 struct ieee80211_sta_vht_cap vht_cap)
2389{
2390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2391 int ret;
2392 u32 param;
2393 u32 value;
2394
2395 if (!(ar->vht_cap_info &
2396 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2397 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2398 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2399 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2400 return 0;
2401
2402 param = ar->wmi.vdev_param->txbf;
2403 value = 0;
2404
2405 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2406 return 0;
2407
2408 /* The following logic is correct. If a remote STA advertises support
2409 * for being a beamformer then we should enable us being a beamformee.
2410 */
2411
2412 if (ar->vht_cap_info &
2413 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2414 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2415 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2416 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2417
2418 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2419 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2420 }
2421
2422 if (ar->vht_cap_info &
2423 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2424 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2425 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2426 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2427
2428 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2429 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2430 }
2431
2432 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2433 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2434
2435 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2436 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2437
2438 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2439 if (ret) {
2440 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2441 value, ret);
2442 return ret;
2443 }
2444
2445 return 0;
2446}
2447
Kalle Valo5e3dd152013-06-12 20:52:10 +03002448/* can be called only in mac80211 callbacks due to `key_count` usage */
2449static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2450 struct ieee80211_vif *vif,
2451 struct ieee80211_bss_conf *bss_conf)
2452{
2453 struct ath10k *ar = hw->priv;
2454 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002455 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002456 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002457 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458 struct ieee80211_sta *ap_sta;
2459 int ret;
2460
Michal Kazior548db542013-07-05 16:15:15 +03002461 lockdep_assert_held(&ar->conf_mutex);
2462
Michal Kazior077efc82014-10-21 10:10:29 +03002463 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2464 arvif->vdev_id, arvif->bssid, arvif->aid);
2465
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466 rcu_read_lock();
2467
2468 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2469 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002470 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002471 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 rcu_read_unlock();
2473 return;
2474 }
2475
Michal Kazior90046f52014-02-14 14:45:51 +01002476 /* ap_sta must be accessed only within rcu section which must be left
2477 * before calling ath10k_setup_peer_smps() which might sleep. */
2478 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002479 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002480
Michal Kazior590922a2014-10-21 10:10:29 +03002481 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002482 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002483 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002484 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485 rcu_read_unlock();
2486 return;
2487 }
2488
2489 rcu_read_unlock();
2490
Kalle Valob9ada652013-10-16 15:44:46 +03002491 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2492 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002493 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002494 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002495 return;
2496 }
2497
Michal Kazior90046f52014-02-14 14:45:51 +01002498 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2499 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002500 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002501 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002502 return;
2503 }
2504
Michal Kazior139e1702015-02-15 16:50:42 +02002505 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2506 if (ret) {
2507 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2508 arvif->vdev_id, bss_conf->bssid, ret);
2509 return;
2510 }
2511
Michal Kazior7aa7a722014-08-25 12:09:38 +02002512 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002513 "mac vdev %d up (associated) bssid %pM aid %d\n",
2514 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2515
Michal Kazior077efc82014-10-21 10:10:29 +03002516 WARN_ON(arvif->is_up);
2517
Michal Kaziorc930f742014-01-23 11:38:25 +01002518 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002519 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002520
2521 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2522 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002523 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002524 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002525 return;
2526 }
2527
2528 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002529
2530 /* Workaround: Some firmware revisions (tested with qca6174
2531 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2532 * poked with peer param command.
2533 */
2534 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2535 WMI_PEER_DUMMY_VAR, 1);
2536 if (ret) {
2537 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2538 arvif->bssid, arvif->vdev_id, ret);
2539 return;
2540 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002541}
2542
Kalle Valo5e3dd152013-06-12 20:52:10 +03002543static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2544 struct ieee80211_vif *vif)
2545{
2546 struct ath10k *ar = hw->priv;
2547 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002548 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002549 int ret;
2550
Michal Kazior548db542013-07-05 16:15:15 +03002551 lockdep_assert_held(&ar->conf_mutex);
2552
Michal Kazior077efc82014-10-21 10:10:29 +03002553 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2554 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002555
Kalle Valo5e3dd152013-06-12 20:52:10 +03002556 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002557 if (ret)
2558 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2559 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002560
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002561 arvif->def_wep_key_idx = -1;
2562
Michal Kazior139e1702015-02-15 16:50:42 +02002563 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2564 if (ret) {
2565 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2566 arvif->vdev_id, ret);
2567 return;
2568 }
2569
Michal Kaziorc930f742014-01-23 11:38:25 +01002570 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002571
2572 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002573}
2574
Michal Kazior590922a2014-10-21 10:10:29 +03002575static int ath10k_station_assoc(struct ath10k *ar,
2576 struct ieee80211_vif *vif,
2577 struct ieee80211_sta *sta,
2578 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002579{
Michal Kazior590922a2014-10-21 10:10:29 +03002580 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002581 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582 int ret = 0;
2583
Michal Kazior548db542013-07-05 16:15:15 +03002584 lockdep_assert_held(&ar->conf_mutex);
2585
Michal Kazior590922a2014-10-21 10:10:29 +03002586 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002588 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002589 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002590 return ret;
2591 }
2592
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002593 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002594 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2595 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002596 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002597 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002598 return ret;
2599 }
2600
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002601 /* Re-assoc is run only to update supported rates for given station. It
2602 * doesn't make much sense to reconfigure the peer completely.
2603 */
2604 if (!reassoc) {
2605 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2606 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002607 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002608 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002609 arvif->vdev_id, ret);
2610 return ret;
2611 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002612
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002613 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2614 if (ret) {
2615 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2616 sta->addr, arvif->vdev_id, ret);
2617 return ret;
2618 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002619
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002620 if (!sta->wme) {
2621 arvif->num_legacy_stations++;
2622 ret = ath10k_recalc_rtscts_prot(arvif);
2623 if (ret) {
2624 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2625 arvif->vdev_id, ret);
2626 return ret;
2627 }
2628 }
2629
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002630 /* Plumb cached keys only for static WEP */
2631 if (arvif->def_wep_key_idx != -1) {
2632 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2633 if (ret) {
2634 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2635 arvif->vdev_id, ret);
2636 return ret;
2637 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002638 }
2639 }
2640
Kalle Valo5e3dd152013-06-12 20:52:10 +03002641 return ret;
2642}
2643
Michal Kazior590922a2014-10-21 10:10:29 +03002644static int ath10k_station_disassoc(struct ath10k *ar,
2645 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002646 struct ieee80211_sta *sta)
2647{
Michal Kazior590922a2014-10-21 10:10:29 +03002648 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002649 int ret = 0;
2650
2651 lockdep_assert_held(&ar->conf_mutex);
2652
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002653 if (!sta->wme) {
2654 arvif->num_legacy_stations--;
2655 ret = ath10k_recalc_rtscts_prot(arvif);
2656 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002657 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002658 arvif->vdev_id, ret);
2659 return ret;
2660 }
2661 }
2662
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2664 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002665 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002666 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002667 return ret;
2668 }
2669
2670 return ret;
2671}
2672
2673/**************/
2674/* Regulatory */
2675/**************/
2676
2677static int ath10k_update_channel_list(struct ath10k *ar)
2678{
2679 struct ieee80211_hw *hw = ar->hw;
2680 struct ieee80211_supported_band **bands;
2681 enum ieee80211_band band;
2682 struct ieee80211_channel *channel;
2683 struct wmi_scan_chan_list_arg arg = {0};
2684 struct wmi_channel_arg *ch;
2685 bool passive;
2686 int len;
2687 int ret;
2688 int i;
2689
Michal Kazior548db542013-07-05 16:15:15 +03002690 lockdep_assert_held(&ar->conf_mutex);
2691
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692 bands = hw->wiphy->bands;
2693 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2694 if (!bands[band])
2695 continue;
2696
2697 for (i = 0; i < bands[band]->n_channels; i++) {
2698 if (bands[band]->channels[i].flags &
2699 IEEE80211_CHAN_DISABLED)
2700 continue;
2701
2702 arg.n_channels++;
2703 }
2704 }
2705
2706 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2707 arg.channels = kzalloc(len, GFP_KERNEL);
2708 if (!arg.channels)
2709 return -ENOMEM;
2710
2711 ch = arg.channels;
2712 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2713 if (!bands[band])
2714 continue;
2715
2716 for (i = 0; i < bands[band]->n_channels; i++) {
2717 channel = &bands[band]->channels[i];
2718
2719 if (channel->flags & IEEE80211_CHAN_DISABLED)
2720 continue;
2721
2722 ch->allow_ht = true;
2723
2724 /* FIXME: when should we really allow VHT? */
2725 ch->allow_vht = true;
2726
2727 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002728 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002729
2730 ch->ht40plus =
2731 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2732
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002733 ch->chan_radar =
2734 !!(channel->flags & IEEE80211_CHAN_RADAR);
2735
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002736 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002737 ch->passive = passive;
2738
2739 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002740 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002741 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002742 ch->max_power = channel->max_power * 2;
2743 ch->max_reg_power = channel->max_reg_power * 2;
2744 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745 ch->reg_class_id = 0; /* FIXME */
2746
2747 /* FIXME: why use only legacy modes, why not any
2748 * HT/VHT modes? Would that even make any
2749 * difference? */
2750 if (channel->band == IEEE80211_BAND_2GHZ)
2751 ch->mode = MODE_11G;
2752 else
2753 ch->mode = MODE_11A;
2754
2755 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2756 continue;
2757
Michal Kazior7aa7a722014-08-25 12:09:38 +02002758 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002759 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2760 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002761 ch->freq, ch->max_power, ch->max_reg_power,
2762 ch->max_antenna_gain, ch->mode);
2763
2764 ch++;
2765 }
2766 }
2767
2768 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2769 kfree(arg.channels);
2770
2771 return ret;
2772}
2773
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002774static enum wmi_dfs_region
2775ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2776{
2777 switch (dfs_region) {
2778 case NL80211_DFS_UNSET:
2779 return WMI_UNINIT_DFS_DOMAIN;
2780 case NL80211_DFS_FCC:
2781 return WMI_FCC_DFS_DOMAIN;
2782 case NL80211_DFS_ETSI:
2783 return WMI_ETSI_DFS_DOMAIN;
2784 case NL80211_DFS_JP:
2785 return WMI_MKK4_DFS_DOMAIN;
2786 }
2787 return WMI_UNINIT_DFS_DOMAIN;
2788}
2789
Michal Kaziorf7843d72013-07-16 09:38:52 +02002790static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002793 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002794 enum wmi_dfs_region wmi_dfs_reg;
2795 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002796
Michal Kaziorf7843d72013-07-16 09:38:52 +02002797 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002798
2799 ret = ath10k_update_channel_list(ar);
2800 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002801 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802
2803 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002804
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002805 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2806 nl_dfs_reg = ar->dfs_detector->region;
2807 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2808 } else {
2809 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2810 }
2811
Kalle Valo5e3dd152013-06-12 20:52:10 +03002812 /* Target allows setting up per-band regdomain but ath_common provides
2813 * a combined one only */
2814 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002815 regpair->reg_domain,
2816 regpair->reg_domain, /* 2ghz */
2817 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002818 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002819 regpair->reg_5ghz_ctl,
2820 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002821 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002822 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002823}
Michal Kazior548db542013-07-05 16:15:15 +03002824
Michal Kaziorf7843d72013-07-16 09:38:52 +02002825static void ath10k_reg_notifier(struct wiphy *wiphy,
2826 struct regulatory_request *request)
2827{
2828 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2829 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002830 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002831
2832 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2833
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002834 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002835 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002836 request->dfs_region);
2837 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2838 request->dfs_region);
2839 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002840 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002841 request->dfs_region);
2842 }
2843
Michal Kaziorf7843d72013-07-16 09:38:52 +02002844 mutex_lock(&ar->conf_mutex);
2845 if (ar->state == ATH10K_STATE_ON)
2846 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002847 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002848}
2849
2850/***************/
2851/* TX handlers */
2852/***************/
2853
Michal Kazior96d828d2015-03-31 10:26:23 +00002854void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2855{
2856 lockdep_assert_held(&ar->htt.tx_lock);
2857
2858 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2859 ar->tx_paused |= BIT(reason);
2860 ieee80211_stop_queues(ar->hw);
2861}
2862
2863static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2864 struct ieee80211_vif *vif)
2865{
2866 struct ath10k *ar = data;
2867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2868
2869 if (arvif->tx_paused)
2870 return;
2871
2872 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2873}
2874
2875void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2876{
2877 lockdep_assert_held(&ar->htt.tx_lock);
2878
2879 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2880 ar->tx_paused &= ~BIT(reason);
2881
2882 if (ar->tx_paused)
2883 return;
2884
2885 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2886 IEEE80211_IFACE_ITER_RESUME_ALL,
2887 ath10k_mac_tx_unlock_iter,
2888 ar);
2889}
2890
2891void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
2892{
2893 struct ath10k *ar = arvif->ar;
2894
2895 lockdep_assert_held(&ar->htt.tx_lock);
2896
2897 WARN_ON(reason >= BITS_PER_LONG);
2898 arvif->tx_paused |= BIT(reason);
2899 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
2900}
2901
2902void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
2903{
2904 struct ath10k *ar = arvif->ar;
2905
2906 lockdep_assert_held(&ar->htt.tx_lock);
2907
2908 WARN_ON(reason >= BITS_PER_LONG);
2909 arvif->tx_paused &= ~BIT(reason);
2910
2911 if (ar->tx_paused)
2912 return;
2913
2914 if (arvif->tx_paused)
2915 return;
2916
2917 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2918}
2919
Michal Kaziorb4aa5392015-03-31 10:26:24 +00002920static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
2921 enum wmi_tlv_tx_pause_id pause_id,
2922 enum wmi_tlv_tx_pause_action action)
2923{
2924 struct ath10k *ar = arvif->ar;
2925
2926 lockdep_assert_held(&ar->htt.tx_lock);
2927
2928 switch (pause_id) {
2929 case WMI_TLV_TX_PAUSE_ID_MCC:
2930 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
2931 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
2932 case WMI_TLV_TX_PAUSE_ID_AP_PS:
2933 case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
2934 switch (action) {
2935 case WMI_TLV_TX_PAUSE_ACTION_STOP:
2936 ath10k_mac_vif_tx_lock(arvif, pause_id);
2937 break;
2938 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
2939 ath10k_mac_vif_tx_unlock(arvif, pause_id);
2940 break;
2941 default:
2942 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
2943 action, arvif->vdev_id);
2944 break;
2945 }
2946 break;
2947 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
2948 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
2949 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
2950 case WMI_TLV_TX_PAUSE_ID_HOST:
2951 default:
2952 /* FIXME: Some pause_ids aren't vdev specific. Instead they
2953 * target peer_id and tid. Implementing these could improve
2954 * traffic scheduling fairness across multiple connected
2955 * stations in AP/IBSS modes.
2956 */
2957 ath10k_dbg(ar, ATH10K_DBG_MAC,
2958 "mac ignoring unsupported tx pause vdev %i id %d\n",
2959 arvif->vdev_id, pause_id);
2960 break;
2961 }
2962}
2963
2964struct ath10k_mac_tx_pause {
2965 u32 vdev_id;
2966 enum wmi_tlv_tx_pause_id pause_id;
2967 enum wmi_tlv_tx_pause_action action;
2968};
2969
2970static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
2971 struct ieee80211_vif *vif)
2972{
2973 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2974 struct ath10k_mac_tx_pause *arg = data;
2975
2976 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
2977}
2978
2979void ath10k_mac_handle_tx_pause(struct ath10k *ar, u32 vdev_id,
2980 enum wmi_tlv_tx_pause_id pause_id,
2981 enum wmi_tlv_tx_pause_action action)
2982{
2983 struct ath10k_mac_tx_pause arg = {
2984 .vdev_id = vdev_id,
2985 .pause_id = pause_id,
2986 .action = action,
2987 };
2988
2989 spin_lock_bh(&ar->htt.tx_lock);
2990 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2991 IEEE80211_IFACE_ITER_RESUME_ALL,
2992 ath10k_mac_handle_tx_pause_iter,
2993 &arg);
2994 spin_unlock_bh(&ar->htt.tx_lock);
2995}
2996
Michal Kazior42c3aa62013-10-02 11:03:38 +02002997static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2998{
2999 if (ieee80211_is_mgmt(hdr->frame_control))
3000 return HTT_DATA_TX_EXT_TID_MGMT;
3001
3002 if (!ieee80211_is_data_qos(hdr->frame_control))
3003 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3004
3005 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3006 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3007
3008 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3009}
3010
Michal Kazior2b37c292014-09-02 11:00:22 +03003011static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003012{
Michal Kazior2b37c292014-09-02 11:00:22 +03003013 if (vif)
3014 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003015
Michal Kazior1bbc0972014-04-08 09:45:47 +03003016 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003017 return ar->monitor_vdev_id;
3018
Michal Kazior7aa7a722014-08-25 12:09:38 +02003019 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003020 return 0;
3021}
3022
Michal Kaziord740d8f2015-03-30 09:51:51 +03003023static enum ath10k_hw_txrx_mode
3024ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003025 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003026{
3027 const struct ieee80211_hdr *hdr = (void *)skb->data;
3028 __le16 fc = hdr->frame_control;
3029
3030 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3031 return ATH10K_HW_TXRX_RAW;
3032
3033 if (ieee80211_is_mgmt(fc))
3034 return ATH10K_HW_TXRX_MGMT;
3035
3036 /* Workaround:
3037 *
3038 * NullFunc frames are mostly used to ping if a client or AP are still
3039 * reachable and responsive. This implies tx status reports must be
3040 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3041 * come to a conclusion that the other end disappeared and tear down
3042 * BSS connection or it can never disconnect from BSS/client (which is
3043 * the case).
3044 *
3045 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3046 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3047 * which seems to deliver correct tx reports for NullFunc frames. The
3048 * downside of using it is it ignores client powersave state so it can
3049 * end up disconnecting sleeping clients in AP mode. It should fix STA
3050 * mode though because AP don't sleep.
3051 */
3052 if (ar->htt.target_version_major < 3 &&
3053 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3054 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3055 return ATH10K_HW_TXRX_MGMT;
3056
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003057 /* Workaround:
3058 *
3059 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3060 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3061 * to work with Ethernet txmode so use it.
3062 */
3063 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3064 return ATH10K_HW_TXRX_ETHERNET;
3065
Michal Kaziord740d8f2015-03-30 09:51:51 +03003066 return ATH10K_HW_TXRX_NATIVE_WIFI;
3067}
3068
Michal Kazior4b604552014-07-21 21:03:09 +03003069/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3070 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003071 */
Michal Kazior4b604552014-07-21 21:03:09 +03003072static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003073{
3074 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003075 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076 u8 *qos_ctl;
3077
3078 if (!ieee80211_is_data_qos(hdr->frame_control))
3079 return;
3080
3081 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003082 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3083 skb->data, (void *)qos_ctl - (void *)skb->data);
3084 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003085
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003086 /* Some firmware revisions don't handle sending QoS NullFunc well.
3087 * These frames are mainly used for CQM purposes so it doesn't really
3088 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003089 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003090 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003091 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003092 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003093
3094 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003095}
3096
Michal Kaziord740d8f2015-03-30 09:51:51 +03003097static void ath10k_tx_h_8023(struct sk_buff *skb)
3098{
3099 struct ieee80211_hdr *hdr;
3100 struct rfc1042_hdr *rfc1042;
3101 struct ethhdr *eth;
3102 size_t hdrlen;
3103 u8 da[ETH_ALEN];
3104 u8 sa[ETH_ALEN];
3105 __be16 type;
3106
3107 hdr = (void *)skb->data;
3108 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3109 rfc1042 = (void *)skb->data + hdrlen;
3110
3111 ether_addr_copy(da, ieee80211_get_DA(hdr));
3112 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3113 type = rfc1042->snap_type;
3114
3115 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3116 skb_push(skb, sizeof(*eth));
3117
3118 eth = (void *)skb->data;
3119 ether_addr_copy(eth->h_dest, da);
3120 ether_addr_copy(eth->h_source, sa);
3121 eth->h_proto = type;
3122}
3123
Michal Kazior4b604552014-07-21 21:03:09 +03003124static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3125 struct ieee80211_vif *vif,
3126 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003127{
3128 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3130
3131 /* This is case only for P2P_GO */
3132 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3133 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3134 return;
3135
3136 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3137 spin_lock_bh(&ar->data_lock);
3138 if (arvif->u.ap.noa_data)
3139 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3140 GFP_ATOMIC))
3141 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3142 arvif->u.ap.noa_data,
3143 arvif->u.ap.noa_len);
3144 spin_unlock_bh(&ar->data_lock);
3145 }
3146}
3147
Michal Kazior8d6d3622014-11-24 14:58:31 +01003148static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3149{
3150 /* FIXME: Not really sure since when the behaviour changed. At some
3151 * point new firmware stopped requiring creation of peer entries for
3152 * offchannel tx (and actually creating them causes issues with wmi-htc
3153 * tx credit replenishment and reliability). Assuming it's at least 3.4
3154 * because that's when the `freq` was introduced to TX_FRM HTT command.
3155 */
3156 return !(ar->htt.target_version_major >= 3 &&
3157 ar->htt.target_version_minor >= 4);
3158}
3159
Michal Kaziord740d8f2015-03-30 09:51:51 +03003160static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003161{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003162 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003163 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164
Michal Kaziord740d8f2015-03-30 09:51:51 +03003165 spin_lock_bh(&ar->data_lock);
3166
3167 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3168 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3169 ret = -ENOSPC;
3170 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003171 }
3172
Michal Kaziord740d8f2015-03-30 09:51:51 +03003173 __skb_queue_tail(q, skb);
3174 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3175
3176unlock:
3177 spin_unlock_bh(&ar->data_lock);
3178
3179 return ret;
3180}
3181
3182static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3183{
3184 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3185 struct ath10k_htt *htt = &ar->htt;
3186 int ret = 0;
3187
3188 switch (cb->txmode) {
3189 case ATH10K_HW_TXRX_RAW:
3190 case ATH10K_HW_TXRX_NATIVE_WIFI:
3191 case ATH10K_HW_TXRX_ETHERNET:
3192 ret = ath10k_htt_tx(htt, skb);
3193 break;
3194 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003195 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003196 ar->fw_features))
3197 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3198 else if (ar->htt.target_version_major >= 3)
3199 ret = ath10k_htt_tx(htt, skb);
3200 else
3201 ret = ath10k_htt_mgmt_tx(htt, skb);
3202 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003203 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003204
3205 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003206 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3207 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 ieee80211_free_txskb(ar->hw, skb);
3209 }
3210}
3211
3212void ath10k_offchan_tx_purge(struct ath10k *ar)
3213{
3214 struct sk_buff *skb;
3215
3216 for (;;) {
3217 skb = skb_dequeue(&ar->offchan_tx_queue);
3218 if (!skb)
3219 break;
3220
3221 ieee80211_free_txskb(ar->hw, skb);
3222 }
3223}
3224
3225void ath10k_offchan_tx_work(struct work_struct *work)
3226{
3227 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3228 struct ath10k_peer *peer;
3229 struct ieee80211_hdr *hdr;
3230 struct sk_buff *skb;
3231 const u8 *peer_addr;
3232 int vdev_id;
3233 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003234 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003235
3236 /* FW requirement: We must create a peer before FW will send out
3237 * an offchannel frame. Otherwise the frame will be stuck and
3238 * never transmitted. We delete the peer upon tx completion.
3239 * It is unlikely that a peer for offchannel tx will already be
3240 * present. However it may be in some rare cases so account for that.
3241 * Otherwise we might remove a legitimate peer and break stuff. */
3242
3243 for (;;) {
3244 skb = skb_dequeue(&ar->offchan_tx_queue);
3245 if (!skb)
3246 break;
3247
3248 mutex_lock(&ar->conf_mutex);
3249
Michal Kazior7aa7a722014-08-25 12:09:38 +02003250 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003251 skb);
3252
3253 hdr = (struct ieee80211_hdr *)skb->data;
3254 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003255 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003256
3257 spin_lock_bh(&ar->data_lock);
3258 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3259 spin_unlock_bh(&ar->data_lock);
3260
3261 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003262 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003263 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264 peer_addr, vdev_id);
3265
3266 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003267 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3268 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003270 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 peer_addr, vdev_id, ret);
3272 }
3273
3274 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003275 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003276 ar->offchan_tx_skb = skb;
3277 spin_unlock_bh(&ar->data_lock);
3278
Michal Kaziord740d8f2015-03-30 09:51:51 +03003279 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003280
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003281 time_left =
3282 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3283 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003284 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003285 skb);
3286
3287 if (!peer) {
3288 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3289 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003290 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003291 peer_addr, vdev_id, ret);
3292 }
3293
3294 mutex_unlock(&ar->conf_mutex);
3295 }
3296}
3297
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003298void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3299{
3300 struct sk_buff *skb;
3301
3302 for (;;) {
3303 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3304 if (!skb)
3305 break;
3306
3307 ieee80211_free_txskb(ar->hw, skb);
3308 }
3309}
3310
3311void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3312{
3313 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3314 struct sk_buff *skb;
3315 int ret;
3316
3317 for (;;) {
3318 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3319 if (!skb)
3320 break;
3321
3322 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003323 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003324 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003325 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003326 ieee80211_free_txskb(ar->hw, skb);
3327 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003328 }
3329}
3330
Kalle Valo5e3dd152013-06-12 20:52:10 +03003331/************/
3332/* Scanning */
3333/************/
3334
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003335void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003336{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003337 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003338
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003339 switch (ar->scan.state) {
3340 case ATH10K_SCAN_IDLE:
3341 break;
3342 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003343 if (ar->scan.is_roc)
3344 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003345 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003346 case ATH10K_SCAN_ABORTING:
3347 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003348 ieee80211_scan_completed(ar->hw,
3349 (ar->scan.state ==
3350 ATH10K_SCAN_ABORTING));
3351 /* fall through */
3352 case ATH10K_SCAN_STARTING:
3353 ar->scan.state = ATH10K_SCAN_IDLE;
3354 ar->scan_channel = NULL;
3355 ath10k_offchan_tx_purge(ar);
3356 cancel_delayed_work(&ar->scan.timeout);
3357 complete_all(&ar->scan.completed);
3358 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003359 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003360}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003361
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003362void ath10k_scan_finish(struct ath10k *ar)
3363{
3364 spin_lock_bh(&ar->data_lock);
3365 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003366 spin_unlock_bh(&ar->data_lock);
3367}
3368
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003369static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003370{
3371 struct wmi_stop_scan_arg arg = {
3372 .req_id = 1, /* FIXME */
3373 .req_type = WMI_SCAN_STOP_ONE,
3374 .u.scan_id = ATH10K_SCAN_ID,
3375 };
3376 int ret;
3377
3378 lockdep_assert_held(&ar->conf_mutex);
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380 ret = ath10k_wmi_stop_scan(ar, &arg);
3381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003382 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003383 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003384 }
3385
Kalle Valo5e3dd152013-06-12 20:52:10 +03003386 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003387 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003388 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003389 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003390 } else if (ret > 0) {
3391 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003392 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003393
3394out:
3395 /* Scan state should be updated upon scan completion but in case
3396 * firmware fails to deliver the event (for whatever reason) it is
3397 * desired to clean up scan state anyway. Firmware may have just
3398 * dropped the scan completion event delivery due to transport pipe
3399 * being overflown with data and/or it can recover on its own before
3400 * next scan request is submitted.
3401 */
3402 spin_lock_bh(&ar->data_lock);
3403 if (ar->scan.state != ATH10K_SCAN_IDLE)
3404 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405 spin_unlock_bh(&ar->data_lock);
3406
3407 return ret;
3408}
3409
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003410static void ath10k_scan_abort(struct ath10k *ar)
3411{
3412 int ret;
3413
3414 lockdep_assert_held(&ar->conf_mutex);
3415
3416 spin_lock_bh(&ar->data_lock);
3417
3418 switch (ar->scan.state) {
3419 case ATH10K_SCAN_IDLE:
3420 /* This can happen if timeout worker kicked in and called
3421 * abortion while scan completion was being processed.
3422 */
3423 break;
3424 case ATH10K_SCAN_STARTING:
3425 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003426 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003427 ath10k_scan_state_str(ar->scan.state),
3428 ar->scan.state);
3429 break;
3430 case ATH10K_SCAN_RUNNING:
3431 ar->scan.state = ATH10K_SCAN_ABORTING;
3432 spin_unlock_bh(&ar->data_lock);
3433
3434 ret = ath10k_scan_stop(ar);
3435 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003436 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003437
3438 spin_lock_bh(&ar->data_lock);
3439 break;
3440 }
3441
3442 spin_unlock_bh(&ar->data_lock);
3443}
3444
3445void ath10k_scan_timeout_work(struct work_struct *work)
3446{
3447 struct ath10k *ar = container_of(work, struct ath10k,
3448 scan.timeout.work);
3449
3450 mutex_lock(&ar->conf_mutex);
3451 ath10k_scan_abort(ar);
3452 mutex_unlock(&ar->conf_mutex);
3453}
3454
Kalle Valo5e3dd152013-06-12 20:52:10 +03003455static int ath10k_start_scan(struct ath10k *ar,
3456 const struct wmi_start_scan_arg *arg)
3457{
3458 int ret;
3459
3460 lockdep_assert_held(&ar->conf_mutex);
3461
3462 ret = ath10k_wmi_start_scan(ar, arg);
3463 if (ret)
3464 return ret;
3465
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3467 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003468 ret = ath10k_scan_stop(ar);
3469 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003470 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003471
3472 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473 }
3474
Ben Greear2f9eec02015-02-15 16:50:38 +02003475 /* If we failed to start the scan, return error code at
3476 * this point. This is probably due to some issue in the
3477 * firmware, but no need to wedge the driver due to that...
3478 */
3479 spin_lock_bh(&ar->data_lock);
3480 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3481 spin_unlock_bh(&ar->data_lock);
3482 return -EINVAL;
3483 }
3484 spin_unlock_bh(&ar->data_lock);
3485
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003486 /* Add a 200ms margin to account for event/command processing */
3487 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3488 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003489 return 0;
3490}
3491
3492/**********************/
3493/* mac80211 callbacks */
3494/**********************/
3495
3496static void ath10k_tx(struct ieee80211_hw *hw,
3497 struct ieee80211_tx_control *control,
3498 struct sk_buff *skb)
3499{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003501 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3502 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003503 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003504 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003505 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003506
3507 /* We should disable CCK RATE due to P2P */
3508 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003509 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510
Michal Kazior4b604552014-07-21 21:03:09 +03003511 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003512 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003513 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003514 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003515 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003516 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517
Michal Kaziord740d8f2015-03-30 09:51:51 +03003518 switch (ATH10K_SKB_CB(skb)->txmode) {
3519 case ATH10K_HW_TXRX_MGMT:
3520 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003521 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003522 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3523 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003524 break;
3525 case ATH10K_HW_TXRX_ETHERNET:
3526 ath10k_tx_h_8023(skb);
3527 break;
3528 case ATH10K_HW_TXRX_RAW:
3529 /* FIXME: Packet injection isn't implemented. It should be
3530 * doable with firmware 10.2 on qca988x.
3531 */
3532 WARN_ON_ONCE(1);
3533 ieee80211_free_txskb(hw, skb);
3534 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003535 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536
Kalle Valo5e3dd152013-06-12 20:52:10 +03003537 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3538 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003539 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003540 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 spin_unlock_bh(&ar->data_lock);
3542
Michal Kazior8d6d3622014-11-24 14:58:31 +01003543 if (ath10k_mac_need_offchan_tx_work(ar)) {
3544 ATH10K_SKB_CB(skb)->htt.freq = 0;
3545 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546
Michal Kazior8d6d3622014-11-24 14:58:31 +01003547 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3548 skb);
3549
3550 skb_queue_tail(&ar->offchan_tx_queue, skb);
3551 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3552 return;
3553 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003554 }
3555
Michal Kaziord740d8f2015-03-30 09:51:51 +03003556 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557}
3558
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003559/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003560void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003561{
3562 /* make sure rcu-protected mac80211 tx path itself is drained */
3563 synchronize_net();
3564
3565 ath10k_offchan_tx_purge(ar);
3566 ath10k_mgmt_over_wmi_tx_purge(ar);
3567
3568 cancel_work_sync(&ar->offchan_tx_work);
3569 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3570}
3571
Michal Kazioraffd3212013-07-16 09:54:35 +02003572void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003573{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003574 struct ath10k_vif *arvif;
3575
Michal Kazior818bdd12013-07-16 09:38:57 +02003576 lockdep_assert_held(&ar->conf_mutex);
3577
Michal Kazior19337472014-08-28 12:58:16 +02003578 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3579 ar->filter_flags = 0;
3580 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003581 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003582
3583 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003584 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003585
3586 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003587 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003588
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003589 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003590 ath10k_peer_cleanup_all(ar);
3591 ath10k_core_stop(ar);
3592 ath10k_hif_power_down(ar);
3593
3594 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003595 list_for_each_entry(arvif, &ar->arvifs, list)
3596 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003597 spin_unlock_bh(&ar->data_lock);
3598}
3599
Ben Greear46acf7b2014-05-16 17:15:38 +03003600static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3601{
3602 struct ath10k *ar = hw->priv;
3603
3604 mutex_lock(&ar->conf_mutex);
3605
3606 if (ar->cfg_tx_chainmask) {
3607 *tx_ant = ar->cfg_tx_chainmask;
3608 *rx_ant = ar->cfg_rx_chainmask;
3609 } else {
3610 *tx_ant = ar->supp_tx_chainmask;
3611 *rx_ant = ar->supp_rx_chainmask;
3612 }
3613
3614 mutex_unlock(&ar->conf_mutex);
3615
3616 return 0;
3617}
3618
Ben Greear5572a952014-11-24 16:22:10 +02003619static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3620{
3621 /* It is not clear that allowing gaps in chainmask
3622 * is helpful. Probably it will not do what user
3623 * is hoping for, so warn in that case.
3624 */
3625 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3626 return;
3627
3628 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3629 dbg, cm);
3630}
3631
Ben Greear46acf7b2014-05-16 17:15:38 +03003632static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3633{
3634 int ret;
3635
3636 lockdep_assert_held(&ar->conf_mutex);
3637
Ben Greear5572a952014-11-24 16:22:10 +02003638 ath10k_check_chain_mask(ar, tx_ant, "tx");
3639 ath10k_check_chain_mask(ar, rx_ant, "rx");
3640
Ben Greear46acf7b2014-05-16 17:15:38 +03003641 ar->cfg_tx_chainmask = tx_ant;
3642 ar->cfg_rx_chainmask = rx_ant;
3643
3644 if ((ar->state != ATH10K_STATE_ON) &&
3645 (ar->state != ATH10K_STATE_RESTARTED))
3646 return 0;
3647
3648 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3649 tx_ant);
3650 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003651 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003652 ret, tx_ant);
3653 return ret;
3654 }
3655
3656 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3657 rx_ant);
3658 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003659 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003660 ret, rx_ant);
3661 return ret;
3662 }
3663
3664 return 0;
3665}
3666
3667static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3668{
3669 struct ath10k *ar = hw->priv;
3670 int ret;
3671
3672 mutex_lock(&ar->conf_mutex);
3673 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3674 mutex_unlock(&ar->conf_mutex);
3675 return ret;
3676}
3677
Kalle Valo5e3dd152013-06-12 20:52:10 +03003678static int ath10k_start(struct ieee80211_hw *hw)
3679{
3680 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003681 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003682 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003683
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003684 /*
3685 * This makes sense only when restarting hw. It is harmless to call
3686 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3687 * commands will be submitted while restarting.
3688 */
3689 ath10k_drain_tx(ar);
3690
Michal Kazior548db542013-07-05 16:15:15 +03003691 mutex_lock(&ar->conf_mutex);
3692
Michal Kaziorc5058f52014-05-26 12:46:03 +03003693 switch (ar->state) {
3694 case ATH10K_STATE_OFF:
3695 ar->state = ATH10K_STATE_ON;
3696 break;
3697 case ATH10K_STATE_RESTARTING:
3698 ath10k_halt(ar);
3699 ar->state = ATH10K_STATE_RESTARTED;
3700 break;
3701 case ATH10K_STATE_ON:
3702 case ATH10K_STATE_RESTARTED:
3703 case ATH10K_STATE_WEDGED:
3704 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003705 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003706 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003707 case ATH10K_STATE_UTF:
3708 ret = -EBUSY;
3709 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003710 }
3711
3712 ret = ath10k_hif_power_up(ar);
3713 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003714 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003715 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003716 }
3717
Kalle Valo43d2a302014-09-10 18:23:30 +03003718 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003719 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003720 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003721 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003722 }
3723
Bartosz Markowski226a3392013-09-26 17:47:16 +02003724 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003725 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003726 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003727 goto err_core_stop;
3728 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003729
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003730 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003731 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003732 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003733 goto err_core_stop;
3734 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735
Michal Kaziorcf327842015-03-31 10:26:25 +00003736 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3737 ret = ath10k_wmi_adaptive_qcs(ar, true);
3738 if (ret) {
3739 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3740 ret);
3741 goto err_core_stop;
3742 }
3743 }
3744
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003745 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3746 burst_enable = ar->wmi.pdev_param->burst_enable;
3747 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3748 if (ret) {
3749 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3750 goto err_core_stop;
3751 }
3752 }
3753
Ben Greear46acf7b2014-05-16 17:15:38 +03003754 if (ar->cfg_tx_chainmask)
3755 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3756 ar->cfg_rx_chainmask);
3757
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003758 /*
3759 * By default FW set ARP frames ac to voice (6). In that case ARP
3760 * exchange is not working properly for UAPSD enabled AP. ARP requests
3761 * which arrives with access category 0 are processed by network stack
3762 * and send back with access category 0, but FW changes access category
3763 * to 6. Set ARP frames access category to best effort (0) solves
3764 * this problem.
3765 */
3766
3767 ret = ath10k_wmi_pdev_set_param(ar,
3768 ar->wmi.pdev_param->arp_ac_override, 0);
3769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003770 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003771 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003772 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003773 }
3774
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303775 ret = ath10k_wmi_pdev_set_param(ar,
3776 ar->wmi.pdev_param->ani_enable, 1);
3777 if (ret) {
3778 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3779 ret);
3780 goto err_core_stop;
3781 }
3782
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303783 ar->ani_enabled = true;
3784
Michal Kaziord6500972014-04-08 09:56:09 +03003785 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003786 ath10k_regd_update(ar);
3787
Simon Wunderlich855aed12014-08-02 09:12:54 +03003788 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303789 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003790
Michal Kaziorae254432014-05-26 12:46:02 +03003791 mutex_unlock(&ar->conf_mutex);
3792 return 0;
3793
3794err_core_stop:
3795 ath10k_core_stop(ar);
3796
3797err_power_down:
3798 ath10k_hif_power_down(ar);
3799
3800err_off:
3801 ar->state = ATH10K_STATE_OFF;
3802
3803err:
Michal Kazior548db542013-07-05 16:15:15 +03003804 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003805 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003806}
3807
3808static void ath10k_stop(struct ieee80211_hw *hw)
3809{
3810 struct ath10k *ar = hw->priv;
3811
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003812 ath10k_drain_tx(ar);
3813
Michal Kazior548db542013-07-05 16:15:15 +03003814 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003815 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003816 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003817 ar->state = ATH10K_STATE_OFF;
3818 }
Michal Kazior548db542013-07-05 16:15:15 +03003819 mutex_unlock(&ar->conf_mutex);
3820
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003821 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003822 cancel_work_sync(&ar->restart_work);
3823}
3824
Michal Kaziorad088bf2013-10-16 15:44:46 +03003825static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003826{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003827 struct ath10k_vif *arvif;
3828 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003829
3830 lockdep_assert_held(&ar->conf_mutex);
3831
Michal Kaziorad088bf2013-10-16 15:44:46 +03003832 list_for_each_entry(arvif, &ar->arvifs, list) {
3833 ret = ath10k_mac_vif_setup_ps(arvif);
3834 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003835 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003836 break;
3837 }
3838 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003839
Michal Kaziorad088bf2013-10-16 15:44:46 +03003840 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003841}
3842
Michal Kazior500ff9f2015-03-31 10:26:21 +00003843static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003844{
3845 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003846 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003847 int ret;
3848
3849 lockdep_assert_held(&ar->conf_mutex);
3850
Michal Kazior500ff9f2015-03-31 10:26:21 +00003851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003852
3853 /* First stop monitor interface. Some FW versions crash if there's a
3854 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003855 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003856 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003857
3858 list_for_each_entry(arvif, &ar->arvifs, list) {
3859 if (!arvif->is_started)
3860 continue;
3861
Michal Kaziordc55e302014-07-29 12:53:36 +03003862 if (!arvif->is_up)
3863 continue;
3864
Michal Kaziorc930f742014-01-23 11:38:25 +01003865 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3866 continue;
3867
Michal Kaziordc55e302014-07-29 12:53:36 +03003868 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003869 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003870 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003871 arvif->vdev_id, ret);
3872 continue;
3873 }
3874 }
3875
Michal Kaziordc55e302014-07-29 12:53:36 +03003876 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003877
3878 list_for_each_entry(arvif, &ar->arvifs, list) {
3879 if (!arvif->is_started)
3880 continue;
3881
3882 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3883 continue;
3884
Michal Kazior81a9a172015-03-05 16:02:17 +02003885 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3886 if (ret)
3887 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3888 ret);
3889
3890 ret = ath10k_mac_setup_prb_tmpl(arvif);
3891 if (ret)
3892 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3893 ret);
3894
Michal Kazior500ff9f2015-03-31 10:26:21 +00003895 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3896 continue;
3897
3898 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003899 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003900 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003901 arvif->vdev_id, ret);
3902 continue;
3903 }
3904
3905 if (!arvif->is_up)
3906 continue;
3907
3908 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3909 arvif->bssid);
3910 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003911 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003912 arvif->vdev_id, ret);
3913 continue;
3914 }
3915 }
3916
Michal Kazior19337472014-08-28 12:58:16 +02003917 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003918}
3919
Michal Kazior7d9d5582014-10-21 10:40:15 +03003920static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3921{
3922 int ret;
3923 u32 param;
3924
3925 lockdep_assert_held(&ar->conf_mutex);
3926
3927 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3928
3929 param = ar->wmi.pdev_param->txpower_limit2g;
3930 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3931 if (ret) {
3932 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3933 txpower, ret);
3934 return ret;
3935 }
3936
3937 param = ar->wmi.pdev_param->txpower_limit5g;
3938 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3939 if (ret) {
3940 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3941 txpower, ret);
3942 return ret;
3943 }
3944
3945 return 0;
3946}
3947
3948static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3949{
3950 struct ath10k_vif *arvif;
3951 int ret, txpower = -1;
3952
3953 lockdep_assert_held(&ar->conf_mutex);
3954
3955 list_for_each_entry(arvif, &ar->arvifs, list) {
3956 WARN_ON(arvif->txpower < 0);
3957
3958 if (txpower == -1)
3959 txpower = arvif->txpower;
3960 else
3961 txpower = min(txpower, arvif->txpower);
3962 }
3963
3964 if (WARN_ON(txpower == -1))
3965 return -EINVAL;
3966
3967 ret = ath10k_mac_txpower_setup(ar, txpower);
3968 if (ret) {
3969 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3970 txpower, ret);
3971 return ret;
3972 }
3973
3974 return 0;
3975}
3976
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3978{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003979 struct ath10k *ar = hw->priv;
3980 struct ieee80211_conf *conf = &hw->conf;
3981 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003982
3983 mutex_lock(&ar->conf_mutex);
3984
Michal Kazioraffd3212013-07-16 09:54:35 +02003985 if (changed & IEEE80211_CONF_CHANGE_PS)
3986 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003987
3988 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003989 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3990 ret = ath10k_monitor_recalc(ar);
3991 if (ret)
3992 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003993 }
3994
3995 mutex_unlock(&ar->conf_mutex);
3996 return ret;
3997}
3998
Ben Greear5572a952014-11-24 16:22:10 +02003999static u32 get_nss_from_chainmask(u16 chain_mask)
4000{
4001 if ((chain_mask & 0x15) == 0x15)
4002 return 4;
4003 else if ((chain_mask & 0x7) == 0x7)
4004 return 3;
4005 else if ((chain_mask & 0x3) == 0x3)
4006 return 2;
4007 return 1;
4008}
4009
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010/*
4011 * TODO:
4012 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4013 * because we will send mgmt frames without CCK. This requirement
4014 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4015 * in the TX packet.
4016 */
4017static int ath10k_add_interface(struct ieee80211_hw *hw,
4018 struct ieee80211_vif *vif)
4019{
4020 struct ath10k *ar = hw->priv;
4021 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4022 enum wmi_sta_powersave_param param;
4023 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004024 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004025 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004026 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004027 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028
Johannes Berg848955c2014-11-11 12:48:42 +01004029 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4030
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 mutex_lock(&ar->conf_mutex);
4032
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004033 memset(arvif, 0, sizeof(*arvif));
4034
Kalle Valo5e3dd152013-06-12 20:52:10 +03004035 arvif->ar = ar;
4036 arvif->vif = vif;
4037
Ben Greeare63b33f2013-10-22 14:54:14 -07004038 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004039 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004040 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4041 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004042
Ben Greeara9aefb32014-08-12 11:02:19 +03004043 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004044 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004045 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004046 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004047 }
Ben Greear16c11172014-09-23 14:17:16 -07004048 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004049
Ben Greear16c11172014-09-23 14:17:16 -07004050 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4051 bit, ar->free_vdev_map);
4052
4053 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004054 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004055
Kalle Valo5e3dd152013-06-12 20:52:10 +03004056 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004057 case NL80211_IFTYPE_P2P_DEVICE:
4058 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4059 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4060 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004061 case NL80211_IFTYPE_UNSPECIFIED:
4062 case NL80211_IFTYPE_STATION:
4063 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4064 if (vif->p2p)
4065 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4066 break;
4067 case NL80211_IFTYPE_ADHOC:
4068 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4069 break;
4070 case NL80211_IFTYPE_AP:
4071 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4072
4073 if (vif->p2p)
4074 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4075 break;
4076 case NL80211_IFTYPE_MONITOR:
4077 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4078 break;
4079 default:
4080 WARN_ON(1);
4081 break;
4082 }
4083
Michal Kazior96d828d2015-03-31 10:26:23 +00004084 /* Using vdev_id as queue number will make it very easy to do per-vif
4085 * tx queue locking. This shouldn't wrap due to interface combinations
4086 * but do a modulo for correctness sake and prevent using offchannel tx
4087 * queues for regular vif tx.
4088 */
4089 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4090 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4091 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4092
Michal Kazior64badcb2014-09-18 11:18:02 +03004093 /* Some firmware revisions don't wait for beacon tx completion before
4094 * sending another SWBA event. This could lead to hardware using old
4095 * (freed) beacon data in some cases, e.g. tx credit starvation
4096 * combined with missed TBTT. This is very very rare.
4097 *
4098 * On non-IOMMU-enabled hosts this could be a possible security issue
4099 * because hw could beacon some random data on the air. On
4100 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4101 * device would crash.
4102 *
4103 * Since there are no beacon tx completions (implicit nor explicit)
4104 * propagated to host the only workaround for this is to allocate a
4105 * DMA-coherent buffer for a lifetime of a vif and use it for all
4106 * beacon tx commands. Worst case for this approach is some beacons may
4107 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4108 */
4109 if (vif->type == NL80211_IFTYPE_ADHOC ||
4110 vif->type == NL80211_IFTYPE_AP) {
4111 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4112 IEEE80211_MAX_FRAME_LEN,
4113 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304114 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004115 if (!arvif->beacon_buf) {
4116 ret = -ENOMEM;
4117 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4118 ret);
4119 goto err;
4120 }
4121 }
4122
4123 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4124 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4125 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004126
4127 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4128 arvif->vdev_subtype, vif->addr);
4129 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004130 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004131 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004132 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004133 }
4134
Ben Greear16c11172014-09-23 14:17:16 -07004135 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004136 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004137
Michal Kazior46725b152015-01-28 09:57:49 +02004138 /* It makes no sense to have firmware do keepalives. mac80211 already
4139 * takes care of this with idle connection polling.
4140 */
4141 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004142 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004143 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004144 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004145 goto err_vdev_delete;
4146 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004147
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004148 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004149
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004150 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4151 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004152 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004153 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004154 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004155 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004156 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004157 goto err_vdev_delete;
4158 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004159
Ben Greear5572a952014-11-24 16:22:10 +02004160 if (ar->cfg_tx_chainmask) {
4161 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4162
4163 vdev_param = ar->wmi.vdev_param->nss;
4164 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4165 nss);
4166 if (ret) {
4167 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4168 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4169 ret);
4170 goto err_vdev_delete;
4171 }
4172 }
4173
Michal Kaziore57e0572015-03-24 13:14:03 +00004174 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4175 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004176 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4177 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004179 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004180 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004181 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004182 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004183 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004184
Michal Kaziore57e0572015-03-24 13:14:03 +00004185 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004186 ret = ath10k_mac_set_kickout(arvif);
4187 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004188 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004189 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004190 goto err_peer_delete;
4191 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004192 }
4193
4194 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4195 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4196 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4197 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4198 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004199 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004200 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004201 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004202 goto err_peer_delete;
4203 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204
Michal Kazior9f9b5742014-12-12 12:41:36 +01004205 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004206 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004207 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004208 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004209 goto err_peer_delete;
4210 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004211
Michal Kazior9f9b5742014-12-12 12:41:36 +01004212 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004213 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004214 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004215 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004216 goto err_peer_delete;
4217 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004218 }
4219
Michal Kazior424121c2013-07-22 14:13:31 +02004220 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004221 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004222 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004223 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004224 goto err_peer_delete;
4225 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004226
Michal Kazior424121c2013-07-22 14:13:31 +02004227 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004228 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004229 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004230 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004231 goto err_peer_delete;
4232 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004233
Michal Kazior7d9d5582014-10-21 10:40:15 +03004234 arvif->txpower = vif->bss_conf.txpower;
4235 ret = ath10k_mac_txpower_recalc(ar);
4236 if (ret) {
4237 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4238 goto err_peer_delete;
4239 }
4240
Michal Kazior500ff9f2015-03-31 10:26:21 +00004241 if (vif->type == NL80211_IFTYPE_MONITOR) {
4242 ar->monitor_arvif = arvif;
4243 ret = ath10k_monitor_recalc(ar);
4244 if (ret) {
4245 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4246 goto err_peer_delete;
4247 }
4248 }
4249
Kalle Valo5e3dd152013-06-12 20:52:10 +03004250 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004251 return 0;
4252
4253err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004254 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4255 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004256 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4257
4258err_vdev_delete:
4259 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004260 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004261 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004262
4263err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004264 if (arvif->beacon_buf) {
4265 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4266 arvif->beacon_buf, arvif->beacon_paddr);
4267 arvif->beacon_buf = NULL;
4268 }
4269
Michal Kazior9dad14a2013-10-16 15:44:45 +03004270 mutex_unlock(&ar->conf_mutex);
4271
Kalle Valo5e3dd152013-06-12 20:52:10 +03004272 return ret;
4273}
4274
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004275static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4276{
4277 int i;
4278
4279 for (i = 0; i < BITS_PER_LONG; i++)
4280 ath10k_mac_vif_tx_unlock(arvif, i);
4281}
4282
Kalle Valo5e3dd152013-06-12 20:52:10 +03004283static void ath10k_remove_interface(struct ieee80211_hw *hw,
4284 struct ieee80211_vif *vif)
4285{
4286 struct ath10k *ar = hw->priv;
4287 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4288 int ret;
4289
Michal Kazior81a9a172015-03-05 16:02:17 +02004290 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004291 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004292
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304293 mutex_lock(&ar->conf_mutex);
4294
Michal Kaziored543882013-09-13 14:16:56 +02004295 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004296 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004297 spin_unlock_bh(&ar->data_lock);
4298
Simon Wunderlich855aed12014-08-02 09:12:54 +03004299 ret = ath10k_spectral_vif_stop(arvif);
4300 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004301 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004302 arvif->vdev_id, ret);
4303
Ben Greear16c11172014-09-23 14:17:16 -07004304 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004305 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004306
Michal Kaziore57e0572015-03-24 13:14:03 +00004307 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4308 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004309 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4310 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004311 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004312 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004313 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004314
4315 kfree(arvif->u.ap.noa_data);
4316 }
4317
Michal Kazior7aa7a722014-08-25 12:09:38 +02004318 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004319 arvif->vdev_id);
4320
Kalle Valo5e3dd152013-06-12 20:52:10 +03004321 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4322 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004323 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004324 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004325
Michal Kazior2c512052015-02-15 16:50:40 +02004326 /* Some firmware revisions don't notify host about self-peer removal
4327 * until after associated vdev is deleted.
4328 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004329 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4330 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004331 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4332 vif->addr);
4333 if (ret)
4334 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4335 arvif->vdev_id, ret);
4336
4337 spin_lock_bh(&ar->data_lock);
4338 ar->num_peers--;
4339 spin_unlock_bh(&ar->data_lock);
4340 }
4341
Kalle Valo5e3dd152013-06-12 20:52:10 +03004342 ath10k_peer_cleanup(ar, arvif->vdev_id);
4343
Michal Kazior500ff9f2015-03-31 10:26:21 +00004344 if (vif->type == NL80211_IFTYPE_MONITOR) {
4345 ar->monitor_arvif = NULL;
4346 ret = ath10k_monitor_recalc(ar);
4347 if (ret)
4348 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4349 }
4350
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004351 spin_lock_bh(&ar->htt.tx_lock);
4352 ath10k_mac_vif_tx_unlock_all(arvif);
4353 spin_unlock_bh(&ar->htt.tx_lock);
4354
Kalle Valo5e3dd152013-06-12 20:52:10 +03004355 mutex_unlock(&ar->conf_mutex);
4356}
4357
4358/*
4359 * FIXME: Has to be verified.
4360 */
4361#define SUPPORTED_FILTERS \
4362 (FIF_PROMISC_IN_BSS | \
4363 FIF_ALLMULTI | \
4364 FIF_CONTROL | \
4365 FIF_PSPOLL | \
4366 FIF_OTHER_BSS | \
4367 FIF_BCN_PRBRESP_PROMISC | \
4368 FIF_PROBE_REQ | \
4369 FIF_FCSFAIL)
4370
4371static void ath10k_configure_filter(struct ieee80211_hw *hw,
4372 unsigned int changed_flags,
4373 unsigned int *total_flags,
4374 u64 multicast)
4375{
4376 struct ath10k *ar = hw->priv;
4377 int ret;
4378
4379 mutex_lock(&ar->conf_mutex);
4380
4381 changed_flags &= SUPPORTED_FILTERS;
4382 *total_flags &= SUPPORTED_FILTERS;
4383 ar->filter_flags = *total_flags;
4384
Michal Kazior19337472014-08-28 12:58:16 +02004385 ret = ath10k_monitor_recalc(ar);
4386 if (ret)
4387 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004388
4389 mutex_unlock(&ar->conf_mutex);
4390}
4391
4392static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4393 struct ieee80211_vif *vif,
4394 struct ieee80211_bss_conf *info,
4395 u32 changed)
4396{
4397 struct ath10k *ar = hw->priv;
4398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4399 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004400 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004401
4402 mutex_lock(&ar->conf_mutex);
4403
4404 if (changed & BSS_CHANGED_IBSS)
4405 ath10k_control_ibss(arvif, info, vif->addr);
4406
4407 if (changed & BSS_CHANGED_BEACON_INT) {
4408 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004409 vdev_param = ar->wmi.vdev_param->beacon_interval;
4410 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004411 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004412 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004413 "mac vdev %d beacon_interval %d\n",
4414 arvif->vdev_id, arvif->beacon_interval);
4415
Kalle Valo5e3dd152013-06-12 20:52:10 +03004416 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004417 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004418 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004419 }
4420
4421 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004422 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004423 "vdev %d set beacon tx mode to staggered\n",
4424 arvif->vdev_id);
4425
Bartosz Markowski226a3392013-09-26 17:47:16 +02004426 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4427 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004428 WMI_BEACON_STAGGERED_MODE);
4429 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004430 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004431 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004432
4433 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4434 if (ret)
4435 ath10k_warn(ar, "failed to update beacon template: %d\n",
4436 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004437 }
4438
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004439 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4440 ret = ath10k_mac_setup_prb_tmpl(arvif);
4441 if (ret)
4442 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4443 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004444 }
4445
Michal Kaziorba2479f2015-01-24 12:14:51 +02004446 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004447 arvif->dtim_period = info->dtim_period;
4448
Michal Kazior7aa7a722014-08-25 12:09:38 +02004449 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004450 "mac vdev %d dtim_period %d\n",
4451 arvif->vdev_id, arvif->dtim_period);
4452
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004453 vdev_param = ar->wmi.vdev_param->dtim_period;
4454 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004455 arvif->dtim_period);
4456 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004457 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004458 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004459 }
4460
4461 if (changed & BSS_CHANGED_SSID &&
4462 vif->type == NL80211_IFTYPE_AP) {
4463 arvif->u.ap.ssid_len = info->ssid_len;
4464 if (info->ssid_len)
4465 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4466 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4467 }
4468
Michal Kazior077efc82014-10-21 10:10:29 +03004469 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4470 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004471
4472 if (changed & BSS_CHANGED_BEACON_ENABLED)
4473 ath10k_control_beaconing(arvif, info);
4474
4475 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004476 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004477 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004478 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004479
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004480 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004481 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004482 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004483 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004484
4485 vdev_param = ar->wmi.vdev_param->protection_mode;
4486 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4487 info->use_cts_prot ? 1 : 0);
4488 if (ret)
4489 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4490 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004491 }
4492
4493 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004494 if (info->use_short_slot)
4495 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4496
4497 else
4498 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4499
Michal Kazior7aa7a722014-08-25 12:09:38 +02004500 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004501 arvif->vdev_id, slottime);
4502
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004503 vdev_param = ar->wmi.vdev_param->slot_time;
4504 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004505 slottime);
4506 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004507 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004508 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004509 }
4510
4511 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004512 if (info->use_short_preamble)
4513 preamble = WMI_VDEV_PREAMBLE_SHORT;
4514 else
4515 preamble = WMI_VDEV_PREAMBLE_LONG;
4516
Michal Kazior7aa7a722014-08-25 12:09:38 +02004517 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004518 "mac vdev %d preamble %dn",
4519 arvif->vdev_id, preamble);
4520
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004521 vdev_param = ar->wmi.vdev_param->preamble;
4522 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004523 preamble);
4524 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004525 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004526 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004527 }
4528
4529 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004530 if (info->assoc) {
4531 /* Workaround: Make sure monitor vdev is not running
4532 * when associating to prevent some firmware revisions
4533 * (e.g. 10.1 and 10.2) from crashing.
4534 */
4535 if (ar->monitor_started)
4536 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004537 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004538 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004539 } else {
4540 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004541 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004542 }
4543
Michal Kazior7d9d5582014-10-21 10:40:15 +03004544 if (changed & BSS_CHANGED_TXPOWER) {
4545 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4546 arvif->vdev_id, info->txpower);
4547
4548 arvif->txpower = info->txpower;
4549 ret = ath10k_mac_txpower_recalc(ar);
4550 if (ret)
4551 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4552 }
4553
Michal Kaziorbf14e652014-12-12 12:41:38 +01004554 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004555 arvif->ps = vif->bss_conf.ps;
4556
4557 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004558 if (ret)
4559 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4560 arvif->vdev_id, ret);
4561 }
4562
Kalle Valo5e3dd152013-06-12 20:52:10 +03004563 mutex_unlock(&ar->conf_mutex);
4564}
4565
4566static int ath10k_hw_scan(struct ieee80211_hw *hw,
4567 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004568 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004569{
4570 struct ath10k *ar = hw->priv;
4571 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004572 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004573 struct wmi_start_scan_arg arg;
4574 int ret = 0;
4575 int i;
4576
4577 mutex_lock(&ar->conf_mutex);
4578
4579 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004580 switch (ar->scan.state) {
4581 case ATH10K_SCAN_IDLE:
4582 reinit_completion(&ar->scan.started);
4583 reinit_completion(&ar->scan.completed);
4584 ar->scan.state = ATH10K_SCAN_STARTING;
4585 ar->scan.is_roc = false;
4586 ar->scan.vdev_id = arvif->vdev_id;
4587 ret = 0;
4588 break;
4589 case ATH10K_SCAN_STARTING:
4590 case ATH10K_SCAN_RUNNING:
4591 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004593 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004594 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004595 spin_unlock_bh(&ar->data_lock);
4596
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004597 if (ret)
4598 goto exit;
4599
Kalle Valo5e3dd152013-06-12 20:52:10 +03004600 memset(&arg, 0, sizeof(arg));
4601 ath10k_wmi_start_scan_init(ar, &arg);
4602 arg.vdev_id = arvif->vdev_id;
4603 arg.scan_id = ATH10K_SCAN_ID;
4604
4605 if (!req->no_cck)
4606 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4607
4608 if (req->ie_len) {
4609 arg.ie_len = req->ie_len;
4610 memcpy(arg.ie, req->ie, arg.ie_len);
4611 }
4612
4613 if (req->n_ssids) {
4614 arg.n_ssids = req->n_ssids;
4615 for (i = 0; i < arg.n_ssids; i++) {
4616 arg.ssids[i].len = req->ssids[i].ssid_len;
4617 arg.ssids[i].ssid = req->ssids[i].ssid;
4618 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004619 } else {
4620 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621 }
4622
4623 if (req->n_channels) {
4624 arg.n_channels = req->n_channels;
4625 for (i = 0; i < arg.n_channels; i++)
4626 arg.channels[i] = req->channels[i]->center_freq;
4627 }
4628
4629 ret = ath10k_start_scan(ar, &arg);
4630 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004631 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004632 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004633 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004634 spin_unlock_bh(&ar->data_lock);
4635 }
4636
4637exit:
4638 mutex_unlock(&ar->conf_mutex);
4639 return ret;
4640}
4641
4642static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4643 struct ieee80211_vif *vif)
4644{
4645 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004646
4647 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004648 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004649 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004650
4651 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004652}
4653
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004654static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4655 struct ath10k_vif *arvif,
4656 enum set_key_cmd cmd,
4657 struct ieee80211_key_conf *key)
4658{
4659 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4660 int ret;
4661
4662 /* 10.1 firmware branch requires default key index to be set to group
4663 * key index after installing it. Otherwise FW/HW Txes corrupted
4664 * frames with multi-vif APs. This is not required for main firmware
4665 * branch (e.g. 636).
4666 *
4667 * FIXME: This has been tested only in AP. It remains unknown if this
4668 * is required for multi-vif STA interfaces on 10.1 */
4669
4670 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4671 return;
4672
4673 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4674 return;
4675
4676 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4677 return;
4678
4679 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4680 return;
4681
4682 if (cmd != SET_KEY)
4683 return;
4684
4685 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4686 key->keyidx);
4687 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004688 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004689 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004690}
4691
Kalle Valo5e3dd152013-06-12 20:52:10 +03004692static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4693 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4694 struct ieee80211_key_conf *key)
4695{
4696 struct ath10k *ar = hw->priv;
4697 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4698 struct ath10k_peer *peer;
4699 const u8 *peer_addr;
4700 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4701 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4702 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004703 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004705 /* this one needs to be done in software */
4706 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4707 return 1;
4708
Kalle Valo5e3dd152013-06-12 20:52:10 +03004709 if (key->keyidx > WMI_MAX_KEY_INDEX)
4710 return -ENOSPC;
4711
4712 mutex_lock(&ar->conf_mutex);
4713
4714 if (sta)
4715 peer_addr = sta->addr;
4716 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4717 peer_addr = vif->bss_conf.bssid;
4718 else
4719 peer_addr = vif->addr;
4720
4721 key->hw_key_idx = key->keyidx;
4722
4723 /* the peer should not disappear in mid-way (unless FW goes awry) since
4724 * we already hold conf_mutex. we just make sure its there now. */
4725 spin_lock_bh(&ar->data_lock);
4726 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4727 spin_unlock_bh(&ar->data_lock);
4728
4729 if (!peer) {
4730 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004731 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732 peer_addr);
4733 ret = -EOPNOTSUPP;
4734 goto exit;
4735 } else {
4736 /* if the peer doesn't exist there is no key to disable
4737 * anymore */
4738 goto exit;
4739 }
4740 }
4741
Michal Kazior7cc45732015-03-09 14:24:17 +01004742 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4743 flags |= WMI_KEY_PAIRWISE;
4744 else
4745 flags |= WMI_KEY_GROUP;
4746
Kalle Valo5e3dd152013-06-12 20:52:10 +03004747 if (is_wep) {
4748 if (cmd == SET_KEY)
4749 arvif->wep_keys[key->keyidx] = key;
4750 else
4751 arvif->wep_keys[key->keyidx] = NULL;
4752
4753 if (cmd == DISABLE_KEY)
4754 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004755
Michal Kaziorad325cb2015-02-18 14:02:27 +01004756 /* When WEP keys are uploaded it's possible that there are
4757 * stations associated already (e.g. when merging) without any
4758 * keys. Static WEP needs an explicit per-peer key upload.
4759 */
4760 if (vif->type == NL80211_IFTYPE_ADHOC &&
4761 cmd == SET_KEY)
4762 ath10k_mac_vif_update_wep_key(arvif, key);
4763
Michal Kazior370e5672015-02-18 14:02:26 +01004764 /* 802.1x never sets the def_wep_key_idx so each set_key()
4765 * call changes default tx key.
4766 *
4767 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4768 * after first set_key().
4769 */
4770 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4771 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004772
Michal Kazior7cc45732015-03-09 14:24:17 +01004773 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4774 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4775 * mode and associated stations in AP/IBSS.
4776 *
4777 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4778 * work fine when mapped directly from mac80211.
4779 *
4780 * Note: When installing first static WEP groupwise key (which
4781 * should be pairwise) def_wep_key_idx isn't known yet (it's
4782 * equal to -1). Since .set_default_unicast_key is called only
4783 * for static WEP it's used to re-upload the key as pairwise.
4784 */
4785 if (arvif->def_wep_key_idx >= 0 &&
4786 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4787 flags &= ~WMI_KEY_GROUP;
4788 flags |= WMI_KEY_PAIRWISE;
4789 }
Michal Kazior370e5672015-02-18 14:02:26 +01004790 }
4791
4792 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004793 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004794 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004795 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004796 goto exit;
4797 }
4798
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004799 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4800
Kalle Valo5e3dd152013-06-12 20:52:10 +03004801 spin_lock_bh(&ar->data_lock);
4802 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4803 if (peer && cmd == SET_KEY)
4804 peer->keys[key->keyidx] = key;
4805 else if (peer && cmd == DISABLE_KEY)
4806 peer->keys[key->keyidx] = NULL;
4807 else if (peer == NULL)
4808 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004809 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004810 spin_unlock_bh(&ar->data_lock);
4811
4812exit:
4813 mutex_unlock(&ar->conf_mutex);
4814 return ret;
4815}
4816
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004817static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4818 struct ieee80211_vif *vif,
4819 int keyidx)
4820{
4821 struct ath10k *ar = hw->priv;
4822 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4823 int ret;
4824
4825 mutex_lock(&arvif->ar->conf_mutex);
4826
4827 if (arvif->ar->state != ATH10K_STATE_ON)
4828 goto unlock;
4829
4830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4831 arvif->vdev_id, keyidx);
4832
4833 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4834 arvif->vdev_id,
4835 arvif->ar->wmi.vdev_param->def_keyid,
4836 keyidx);
4837
4838 if (ret) {
4839 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4840 arvif->vdev_id,
4841 ret);
4842 goto unlock;
4843 }
4844
4845 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004846
4847 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4848 if (ret) {
4849 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4850 arvif->vdev_id, ret);
4851 goto unlock;
4852 }
4853
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004854unlock:
4855 mutex_unlock(&arvif->ar->conf_mutex);
4856}
4857
Michal Kazior9797feb2014-02-14 14:49:48 +01004858static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4859{
4860 struct ath10k *ar;
4861 struct ath10k_vif *arvif;
4862 struct ath10k_sta *arsta;
4863 struct ieee80211_sta *sta;
4864 u32 changed, bw, nss, smps;
4865 int err;
4866
4867 arsta = container_of(wk, struct ath10k_sta, update_wk);
4868 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4869 arvif = arsta->arvif;
4870 ar = arvif->ar;
4871
4872 spin_lock_bh(&ar->data_lock);
4873
4874 changed = arsta->changed;
4875 arsta->changed = 0;
4876
4877 bw = arsta->bw;
4878 nss = arsta->nss;
4879 smps = arsta->smps;
4880
4881 spin_unlock_bh(&ar->data_lock);
4882
4883 mutex_lock(&ar->conf_mutex);
4884
4885 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004886 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004887 sta->addr, bw);
4888
4889 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4890 WMI_PEER_CHAN_WIDTH, bw);
4891 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004892 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004893 sta->addr, bw, err);
4894 }
4895
4896 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004897 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004898 sta->addr, nss);
4899
4900 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4901 WMI_PEER_NSS, nss);
4902 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004903 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004904 sta->addr, nss, err);
4905 }
4906
4907 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004908 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004909 sta->addr, smps);
4910
4911 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4912 WMI_PEER_SMPS_STATE, smps);
4913 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004914 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004915 sta->addr, smps, err);
4916 }
4917
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004918 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4919 changed & IEEE80211_RC_NSS_CHANGED) {
4920 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004921 sta->addr);
4922
Michal Kazior590922a2014-10-21 10:10:29 +03004923 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004924 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004925 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004926 sta->addr);
4927 }
4928
Michal Kazior9797feb2014-02-14 14:49:48 +01004929 mutex_unlock(&ar->conf_mutex);
4930}
4931
Marek Puzyniak7c354242015-03-30 09:51:52 +03004932static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4933 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004934{
4935 struct ath10k *ar = arvif->ar;
4936
4937 lockdep_assert_held(&ar->conf_mutex);
4938
Marek Puzyniak7c354242015-03-30 09:51:52 +03004939 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004940 return 0;
4941
4942 if (ar->num_stations >= ar->max_num_stations)
4943 return -ENOBUFS;
4944
4945 ar->num_stations++;
4946
4947 return 0;
4948}
4949
Marek Puzyniak7c354242015-03-30 09:51:52 +03004950static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4951 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004952{
4953 struct ath10k *ar = arvif->ar;
4954
4955 lockdep_assert_held(&ar->conf_mutex);
4956
Marek Puzyniak7c354242015-03-30 09:51:52 +03004957 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004958 return;
4959
4960 ar->num_stations--;
4961}
4962
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004963struct ath10k_mac_tdls_iter_data {
4964 u32 num_tdls_stations;
4965 struct ieee80211_vif *curr_vif;
4966};
4967
4968static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4969 struct ieee80211_sta *sta)
4970{
4971 struct ath10k_mac_tdls_iter_data *iter_data = data;
4972 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4973 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4974
4975 if (sta->tdls && sta_vif == iter_data->curr_vif)
4976 iter_data->num_tdls_stations++;
4977}
4978
4979static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4980 struct ieee80211_vif *vif)
4981{
4982 struct ath10k_mac_tdls_iter_data data = {};
4983
4984 data.curr_vif = vif;
4985
4986 ieee80211_iterate_stations_atomic(hw,
4987 ath10k_mac_tdls_vif_stations_count_iter,
4988 &data);
4989 return data.num_tdls_stations;
4990}
4991
4992static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4993 struct ieee80211_vif *vif)
4994{
4995 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4996 int *num_tdls_vifs = data;
4997
4998 if (vif->type != NL80211_IFTYPE_STATION)
4999 return;
5000
5001 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5002 (*num_tdls_vifs)++;
5003}
5004
5005static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5006{
5007 int num_tdls_vifs = 0;
5008
5009 ieee80211_iterate_active_interfaces_atomic(hw,
5010 IEEE80211_IFACE_ITER_NORMAL,
5011 ath10k_mac_tdls_vifs_count_iter,
5012 &num_tdls_vifs);
5013 return num_tdls_vifs;
5014}
5015
Kalle Valo5e3dd152013-06-12 20:52:10 +03005016static int ath10k_sta_state(struct ieee80211_hw *hw,
5017 struct ieee80211_vif *vif,
5018 struct ieee80211_sta *sta,
5019 enum ieee80211_sta_state old_state,
5020 enum ieee80211_sta_state new_state)
5021{
5022 struct ath10k *ar = hw->priv;
5023 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005024 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005025 int ret = 0;
5026
Michal Kazior76f90022014-02-25 09:29:57 +02005027 if (old_state == IEEE80211_STA_NOTEXIST &&
5028 new_state == IEEE80211_STA_NONE) {
5029 memset(arsta, 0, sizeof(*arsta));
5030 arsta->arvif = arvif;
5031 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5032 }
5033
Michal Kazior9797feb2014-02-14 14:49:48 +01005034 /* cancel must be done outside the mutex to avoid deadlock */
5035 if ((old_state == IEEE80211_STA_NONE &&
5036 new_state == IEEE80211_STA_NOTEXIST))
5037 cancel_work_sync(&arsta->update_wk);
5038
Kalle Valo5e3dd152013-06-12 20:52:10 +03005039 mutex_lock(&ar->conf_mutex);
5040
5041 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005042 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005043 /*
5044 * New station addition.
5045 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005046 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5047 u32 num_tdls_stations;
5048 u32 num_tdls_vifs;
5049
Michal Kaziorcfd10612014-11-25 15:16:05 +01005050 ath10k_dbg(ar, ATH10K_DBG_MAC,
5051 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5052 arvif->vdev_id, sta->addr,
5053 ar->num_stations + 1, ar->max_num_stations,
5054 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005055
Marek Puzyniak7c354242015-03-30 09:51:52 +03005056 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005057 if (ret) {
5058 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5059 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005060 goto exit;
5061 }
5062
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005063 if (sta->tdls)
5064 peer_type = WMI_PEER_TYPE_TDLS;
5065
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005066 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005067 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005068 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005069 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 -08005070 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005071 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005072 goto exit;
5073 }
Michal Kazior077efc82014-10-21 10:10:29 +03005074
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005075 if (!sta->tdls)
5076 goto exit;
5077
5078 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5079 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5080
5081 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5082 num_tdls_stations == 0) {
5083 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5084 arvif->vdev_id, ar->max_num_tdls_vdevs);
5085 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5086 ath10k_mac_dec_num_stations(arvif, sta);
5087 ret = -ENOBUFS;
5088 goto exit;
5089 }
5090
5091 if (num_tdls_stations == 0) {
5092 /* This is the first tdls peer in current vif */
5093 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5094
5095 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5096 state);
5097 if (ret) {
5098 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5099 arvif->vdev_id, ret);
5100 ath10k_peer_delete(ar, arvif->vdev_id,
5101 sta->addr);
5102 ath10k_mac_dec_num_stations(arvif, sta);
5103 goto exit;
5104 }
5105 }
5106
5107 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5108 WMI_TDLS_PEER_STATE_PEERING);
5109 if (ret) {
5110 ath10k_warn(ar,
5111 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5112 sta->addr, arvif->vdev_id, ret);
5113 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5114 ath10k_mac_dec_num_stations(arvif, sta);
5115
5116 if (num_tdls_stations != 0)
5117 goto exit;
5118 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5119 WMI_TDLS_DISABLE);
5120 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005121 } else if ((old_state == IEEE80211_STA_NONE &&
5122 new_state == IEEE80211_STA_NOTEXIST)) {
5123 /*
5124 * Existing station deletion.
5125 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005126 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005127 "mac vdev %d peer delete %pM (sta gone)\n",
5128 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005129
Kalle Valo5e3dd152013-06-12 20:52:10 +03005130 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5131 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005132 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005133 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005134
Marek Puzyniak7c354242015-03-30 09:51:52 +03005135 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005136
5137 if (!sta->tdls)
5138 goto exit;
5139
5140 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5141 goto exit;
5142
5143 /* This was the last tdls peer in current vif */
5144 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5145 WMI_TDLS_DISABLE);
5146 if (ret) {
5147 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5148 arvif->vdev_id, ret);
5149 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005150 } else if (old_state == IEEE80211_STA_AUTH &&
5151 new_state == IEEE80211_STA_ASSOC &&
5152 (vif->type == NL80211_IFTYPE_AP ||
5153 vif->type == NL80211_IFTYPE_ADHOC)) {
5154 /*
5155 * New association.
5156 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005157 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005158 sta->addr);
5159
Michal Kazior590922a2014-10-21 10:10:29 +03005160 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005161 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005162 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005163 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005164 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005165 new_state == IEEE80211_STA_AUTHORIZED &&
5166 sta->tdls) {
5167 /*
5168 * Tdls station authorized.
5169 */
5170 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5171 sta->addr);
5172
5173 ret = ath10k_station_assoc(ar, vif, sta, false);
5174 if (ret) {
5175 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5176 sta->addr, arvif->vdev_id, ret);
5177 goto exit;
5178 }
5179
5180 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5181 WMI_TDLS_PEER_STATE_CONNECTED);
5182 if (ret)
5183 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5184 sta->addr, arvif->vdev_id, ret);
5185 } else if (old_state == IEEE80211_STA_ASSOC &&
5186 new_state == IEEE80211_STA_AUTH &&
5187 (vif->type == NL80211_IFTYPE_AP ||
5188 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005189 /*
5190 * Disassociation.
5191 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005192 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005193 sta->addr);
5194
Michal Kazior590922a2014-10-21 10:10:29 +03005195 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005196 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005197 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005198 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005199 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005200exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005201 mutex_unlock(&ar->conf_mutex);
5202 return ret;
5203}
5204
5205static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005206 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005207{
5208 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005209 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5210 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005211 u32 value = 0;
5212 int ret = 0;
5213
Michal Kazior548db542013-07-05 16:15:15 +03005214 lockdep_assert_held(&ar->conf_mutex);
5215
Kalle Valo5e3dd152013-06-12 20:52:10 +03005216 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5217 return 0;
5218
5219 switch (ac) {
5220 case IEEE80211_AC_VO:
5221 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5222 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005223 prio = 7;
5224 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005225 break;
5226 case IEEE80211_AC_VI:
5227 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5228 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005229 prio = 5;
5230 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005231 break;
5232 case IEEE80211_AC_BE:
5233 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5234 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005235 prio = 2;
5236 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005237 break;
5238 case IEEE80211_AC_BK:
5239 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5240 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005241 prio = 0;
5242 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005243 break;
5244 }
5245
5246 if (enable)
5247 arvif->u.sta.uapsd |= value;
5248 else
5249 arvif->u.sta.uapsd &= ~value;
5250
5251 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5252 WMI_STA_PS_PARAM_UAPSD,
5253 arvif->u.sta.uapsd);
5254 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005255 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005256 goto exit;
5257 }
5258
5259 if (arvif->u.sta.uapsd)
5260 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5261 else
5262 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5263
5264 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5265 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5266 value);
5267 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005268 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005269
Michal Kazior9f9b5742014-12-12 12:41:36 +01005270 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5271 if (ret) {
5272 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5273 arvif->vdev_id, ret);
5274 return ret;
5275 }
5276
5277 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5278 if (ret) {
5279 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5280 arvif->vdev_id, ret);
5281 return ret;
5282 }
5283
Michal Kaziorb0e56152015-01-24 12:14:52 +02005284 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5285 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5286 /* Only userspace can make an educated decision when to send
5287 * trigger frame. The following effectively disables u-UAPSD
5288 * autotrigger in firmware (which is enabled by default
5289 * provided the autotrigger service is available).
5290 */
5291
5292 arg.wmm_ac = acc;
5293 arg.user_priority = prio;
5294 arg.service_interval = 0;
5295 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5296 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5297
5298 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5299 arvif->bssid, &arg, 1);
5300 if (ret) {
5301 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5302 ret);
5303 return ret;
5304 }
5305 }
5306
Kalle Valo5e3dd152013-06-12 20:52:10 +03005307exit:
5308 return ret;
5309}
5310
5311static int ath10k_conf_tx(struct ieee80211_hw *hw,
5312 struct ieee80211_vif *vif, u16 ac,
5313 const struct ieee80211_tx_queue_params *params)
5314{
5315 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005316 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005317 struct wmi_wmm_params_arg *p = NULL;
5318 int ret;
5319
5320 mutex_lock(&ar->conf_mutex);
5321
5322 switch (ac) {
5323 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005324 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005325 break;
5326 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005327 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005328 break;
5329 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005330 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005331 break;
5332 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005333 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005334 break;
5335 }
5336
5337 if (WARN_ON(!p)) {
5338 ret = -EINVAL;
5339 goto exit;
5340 }
5341
5342 p->cwmin = params->cw_min;
5343 p->cwmax = params->cw_max;
5344 p->aifs = params->aifs;
5345
5346 /*
5347 * The channel time duration programmed in the HW is in absolute
5348 * microseconds, while mac80211 gives the txop in units of
5349 * 32 microseconds.
5350 */
5351 p->txop = params->txop * 32;
5352
Michal Kazior7fc979a2015-01-28 09:57:28 +02005353 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5354 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5355 &arvif->wmm_params);
5356 if (ret) {
5357 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5358 arvif->vdev_id, ret);
5359 goto exit;
5360 }
5361 } else {
5362 /* This won't work well with multi-interface cases but it's
5363 * better than nothing.
5364 */
5365 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5366 if (ret) {
5367 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5368 goto exit;
5369 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005370 }
5371
5372 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5373 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005374 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005375
5376exit:
5377 mutex_unlock(&ar->conf_mutex);
5378 return ret;
5379}
5380
5381#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5382
5383static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5384 struct ieee80211_vif *vif,
5385 struct ieee80211_channel *chan,
5386 int duration,
5387 enum ieee80211_roc_type type)
5388{
5389 struct ath10k *ar = hw->priv;
5390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5391 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005392 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005393
5394 mutex_lock(&ar->conf_mutex);
5395
5396 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005397 switch (ar->scan.state) {
5398 case ATH10K_SCAN_IDLE:
5399 reinit_completion(&ar->scan.started);
5400 reinit_completion(&ar->scan.completed);
5401 reinit_completion(&ar->scan.on_channel);
5402 ar->scan.state = ATH10K_SCAN_STARTING;
5403 ar->scan.is_roc = true;
5404 ar->scan.vdev_id = arvif->vdev_id;
5405 ar->scan.roc_freq = chan->center_freq;
5406 ret = 0;
5407 break;
5408 case ATH10K_SCAN_STARTING:
5409 case ATH10K_SCAN_RUNNING:
5410 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005411 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005412 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005413 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005414 spin_unlock_bh(&ar->data_lock);
5415
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005416 if (ret)
5417 goto exit;
5418
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005419 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5420
Kalle Valo5e3dd152013-06-12 20:52:10 +03005421 memset(&arg, 0, sizeof(arg));
5422 ath10k_wmi_start_scan_init(ar, &arg);
5423 arg.vdev_id = arvif->vdev_id;
5424 arg.scan_id = ATH10K_SCAN_ID;
5425 arg.n_channels = 1;
5426 arg.channels[0] = chan->center_freq;
5427 arg.dwell_time_active = duration;
5428 arg.dwell_time_passive = duration;
5429 arg.max_scan_time = 2 * duration;
5430 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5431 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5432
5433 ret = ath10k_start_scan(ar, &arg);
5434 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005435 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005436 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005437 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438 spin_unlock_bh(&ar->data_lock);
5439 goto exit;
5440 }
5441
5442 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5443 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005444 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005445
5446 ret = ath10k_scan_stop(ar);
5447 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005448 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005449
Kalle Valo5e3dd152013-06-12 20:52:10 +03005450 ret = -ETIMEDOUT;
5451 goto exit;
5452 }
5453
5454 ret = 0;
5455exit:
5456 mutex_unlock(&ar->conf_mutex);
5457 return ret;
5458}
5459
5460static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5461{
5462 struct ath10k *ar = hw->priv;
5463
5464 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005465 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005466 mutex_unlock(&ar->conf_mutex);
5467
Michal Kazior4eb2e162014-10-28 10:23:09 +01005468 cancel_delayed_work_sync(&ar->scan.timeout);
5469
Kalle Valo5e3dd152013-06-12 20:52:10 +03005470 return 0;
5471}
5472
5473/*
5474 * Both RTS and Fragmentation threshold are interface-specific
5475 * in ath10k, but device-specific in mac80211.
5476 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005477
5478static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5479{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005480 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005481 struct ath10k_vif *arvif;
5482 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005483
Michal Kaziorad088bf2013-10-16 15:44:46 +03005484 mutex_lock(&ar->conf_mutex);
5485 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005486 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005487 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005488
Michal Kaziorad088bf2013-10-16 15:44:46 +03005489 ret = ath10k_mac_set_rts(arvif, value);
5490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005491 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005492 arvif->vdev_id, ret);
5493 break;
5494 }
5495 }
5496 mutex_unlock(&ar->conf_mutex);
5497
5498 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005499}
5500
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005501static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5502 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005503{
5504 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005505 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005506 int ret;
5507
5508 /* mac80211 doesn't care if we really xmit queued frames or not
5509 * we'll collect those frames either way if we stop/delete vdevs */
5510 if (drop)
5511 return;
5512
Michal Kazior548db542013-07-05 16:15:15 +03005513 mutex_lock(&ar->conf_mutex);
5514
Michal Kazioraffd3212013-07-16 09:54:35 +02005515 if (ar->state == ATH10K_STATE_WEDGED)
5516 goto skip;
5517
Michal Kazioredb82362013-07-05 16:15:14 +03005518 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005519 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005520
Michal Kazioredb82362013-07-05 16:15:14 +03005521 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005522 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005523 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005524
Michal Kazior7962b0d2014-10-28 10:34:38 +01005525 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5526 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5527 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005528
5529 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005530 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005531
5532 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005533 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005534 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005535
Michal Kazioraffd3212013-07-16 09:54:35 +02005536skip:
Michal Kazior548db542013-07-05 16:15:15 +03005537 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005538}
5539
5540/* TODO: Implement this function properly
5541 * For now it is needed to reply to Probe Requests in IBSS mode.
5542 * Propably we need this information from FW.
5543 */
5544static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5545{
5546 return 1;
5547}
5548
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005549static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5550 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005551{
5552 struct ath10k *ar = hw->priv;
5553
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005554 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5555 return;
5556
Michal Kazioraffd3212013-07-16 09:54:35 +02005557 mutex_lock(&ar->conf_mutex);
5558
5559 /* If device failed to restart it will be in a different state, e.g.
5560 * ATH10K_STATE_WEDGED */
5561 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005562 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005563 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005564 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005565 }
5566
5567 mutex_unlock(&ar->conf_mutex);
5568}
5569
Michal Kazior2e1dea42013-07-31 10:32:40 +02005570static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5571 struct survey_info *survey)
5572{
5573 struct ath10k *ar = hw->priv;
5574 struct ieee80211_supported_band *sband;
5575 struct survey_info *ar_survey = &ar->survey[idx];
5576 int ret = 0;
5577
5578 mutex_lock(&ar->conf_mutex);
5579
5580 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5581 if (sband && idx >= sband->n_channels) {
5582 idx -= sband->n_channels;
5583 sband = NULL;
5584 }
5585
5586 if (!sband)
5587 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5588
5589 if (!sband || idx >= sband->n_channels) {
5590 ret = -ENOENT;
5591 goto exit;
5592 }
5593
5594 spin_lock_bh(&ar->data_lock);
5595 memcpy(survey, ar_survey, sizeof(*survey));
5596 spin_unlock_bh(&ar->data_lock);
5597
5598 survey->channel = &sband->channels[idx];
5599
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005600 if (ar->rx_channel == survey->channel)
5601 survey->filled |= SURVEY_INFO_IN_USE;
5602
Michal Kazior2e1dea42013-07-31 10:32:40 +02005603exit:
5604 mutex_unlock(&ar->conf_mutex);
5605 return ret;
5606}
5607
Michal Kazior3ae54222015-03-31 10:49:20 +00005608static bool
5609ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5610 enum ieee80211_band band,
5611 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005612{
Michal Kazior3ae54222015-03-31 10:49:20 +00005613 int num_rates = 0;
5614 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005615
Michal Kazior3ae54222015-03-31 10:49:20 +00005616 num_rates += hweight32(mask->control[band].legacy);
5617
5618 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5619 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5620
5621 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5622 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5623
5624 return num_rates == 1;
5625}
5626
5627static bool
5628ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5629 enum ieee80211_band band,
5630 const struct cfg80211_bitrate_mask *mask,
5631 int *nss)
5632{
5633 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5634 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5635 u8 ht_nss_mask = 0;
5636 u8 vht_nss_mask = 0;
5637 int i;
5638
5639 if (mask->control[band].legacy)
5640 return false;
5641
5642 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5643 if (mask->control[band].ht_mcs[i] == 0)
5644 continue;
5645 else if (mask->control[band].ht_mcs[i] ==
5646 sband->ht_cap.mcs.rx_mask[i])
5647 ht_nss_mask |= BIT(i);
5648 else
5649 return false;
5650 }
5651
5652 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5653 if (mask->control[band].vht_mcs[i] == 0)
5654 continue;
5655 else if (mask->control[band].vht_mcs[i] ==
5656 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5657 vht_nss_mask |= BIT(i);
5658 else
5659 return false;
5660 }
5661
5662 if (ht_nss_mask != vht_nss_mask)
5663 return false;
5664
5665 if (ht_nss_mask == 0)
5666 return false;
5667
5668 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5669 return false;
5670
5671 *nss = fls(ht_nss_mask);
5672
5673 return true;
5674}
5675
5676static int
5677ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5678 enum ieee80211_band band,
5679 const struct cfg80211_bitrate_mask *mask,
5680 u8 *rate, u8 *nss)
5681{
5682 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5683 int rate_idx;
5684 int i;
5685 u16 bitrate;
5686 u8 preamble;
5687 u8 hw_rate;
5688
5689 if (hweight32(mask->control[band].legacy) == 1) {
5690 rate_idx = ffs(mask->control[band].legacy) - 1;
5691
5692 hw_rate = sband->bitrates[rate_idx].hw_value;
5693 bitrate = sband->bitrates[rate_idx].bitrate;
5694
5695 if (ath10k_mac_bitrate_is_cck(bitrate))
5696 preamble = WMI_RATE_PREAMBLE_CCK;
5697 else
5698 preamble = WMI_RATE_PREAMBLE_OFDM;
5699
5700 *nss = 1;
5701 *rate = preamble << 6 |
5702 (*nss - 1) << 4 |
5703 hw_rate << 0;
5704
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005705 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005706 }
5707
Michal Kazior3ae54222015-03-31 10:49:20 +00005708 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5709 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5710 *nss = i + 1;
5711 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5712 (*nss - 1) << 4 |
5713 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005714
Michal Kazior3ae54222015-03-31 10:49:20 +00005715 return 0;
5716 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005717 }
5718
Michal Kazior3ae54222015-03-31 10:49:20 +00005719 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5720 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5721 *nss = i + 1;
5722 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5723 (*nss - 1) << 4 |
5724 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005725
Michal Kazior3ae54222015-03-31 10:49:20 +00005726 return 0;
5727 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005728 }
5729
Michal Kazior3ae54222015-03-31 10:49:20 +00005730 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005731}
5732
Michal Kazior3ae54222015-03-31 10:49:20 +00005733static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5734 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005735{
5736 struct ath10k *ar = arvif->ar;
5737 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005738 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005739
Michal Kazior3ae54222015-03-31 10:49:20 +00005740 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005741
Michal Kazior3ae54222015-03-31 10:49:20 +00005742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5743 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005744
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005745 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005746 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005747 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005748 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005749 rate, ret);
5750 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005751 }
5752
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005753 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005754 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005755 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005756 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5757 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005758 }
5759
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005760 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005761 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005762 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005763 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5764 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005765 }
5766
Michal Kazior3ae54222015-03-31 10:49:20 +00005767 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005768}
5769
Michal Kazior3ae54222015-03-31 10:49:20 +00005770static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5771 struct ieee80211_vif *vif,
5772 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005773{
5774 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005775 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005776 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005777 enum ieee80211_band band;
Michal Kazior3ae54222015-03-31 10:49:20 +00005778 u8 rate;
5779 u8 nss;
5780 u8 sgi;
5781 int single_nss;
5782 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005783
Michal Kazior500ff9f2015-03-31 10:26:21 +00005784 if (ath10k_mac_vif_chan(vif, &def))
5785 return -EPERM;
5786
Michal Kazior500ff9f2015-03-31 10:26:21 +00005787 band = def.chan->band;
5788
Michal Kazior3ae54222015-03-31 10:49:20 +00005789 sgi = mask->control[band].gi;
5790 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005791 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005792
Michal Kazior3ae54222015-03-31 10:49:20 +00005793 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5794 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5795 &rate, &nss);
5796 if (ret) {
5797 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5798 arvif->vdev_id, ret);
5799 return ret;
5800 }
5801 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5802 &single_nss)) {
5803 rate = WMI_FIXED_RATE_NONE;
5804 nss = single_nss;
5805 } else {
5806 rate = WMI_FIXED_RATE_NONE;
5807 nss = ar->num_rf_chains;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005808 }
5809
Michal Kazior3ae54222015-03-31 10:49:20 +00005810 mutex_lock(&ar->conf_mutex);
5811
5812 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
5813 if (ret) {
5814 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5815 arvif->vdev_id, ret);
5816 goto exit;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005817 }
5818
Michal Kazior3ae54222015-03-31 10:49:20 +00005819exit:
5820 mutex_unlock(&ar->conf_mutex);
5821
5822 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005823}
5824
Michal Kazior9797feb2014-02-14 14:49:48 +01005825static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5826 struct ieee80211_vif *vif,
5827 struct ieee80211_sta *sta,
5828 u32 changed)
5829{
5830 struct ath10k *ar = hw->priv;
5831 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5832 u32 bw, smps;
5833
5834 spin_lock_bh(&ar->data_lock);
5835
Michal Kazior7aa7a722014-08-25 12:09:38 +02005836 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005837 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5838 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5839 sta->smps_mode);
5840
5841 if (changed & IEEE80211_RC_BW_CHANGED) {
5842 bw = WMI_PEER_CHWIDTH_20MHZ;
5843
5844 switch (sta->bandwidth) {
5845 case IEEE80211_STA_RX_BW_20:
5846 bw = WMI_PEER_CHWIDTH_20MHZ;
5847 break;
5848 case IEEE80211_STA_RX_BW_40:
5849 bw = WMI_PEER_CHWIDTH_40MHZ;
5850 break;
5851 case IEEE80211_STA_RX_BW_80:
5852 bw = WMI_PEER_CHWIDTH_80MHZ;
5853 break;
5854 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005855 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005856 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005857 bw = WMI_PEER_CHWIDTH_20MHZ;
5858 break;
5859 }
5860
5861 arsta->bw = bw;
5862 }
5863
5864 if (changed & IEEE80211_RC_NSS_CHANGED)
5865 arsta->nss = sta->rx_nss;
5866
5867 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5868 smps = WMI_PEER_SMPS_PS_NONE;
5869
5870 switch (sta->smps_mode) {
5871 case IEEE80211_SMPS_AUTOMATIC:
5872 case IEEE80211_SMPS_OFF:
5873 smps = WMI_PEER_SMPS_PS_NONE;
5874 break;
5875 case IEEE80211_SMPS_STATIC:
5876 smps = WMI_PEER_SMPS_STATIC;
5877 break;
5878 case IEEE80211_SMPS_DYNAMIC:
5879 smps = WMI_PEER_SMPS_DYNAMIC;
5880 break;
5881 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005882 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005883 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005884 smps = WMI_PEER_SMPS_PS_NONE;
5885 break;
5886 }
5887
5888 arsta->smps = smps;
5889 }
5890
Michal Kazior9797feb2014-02-14 14:49:48 +01005891 arsta->changed |= changed;
5892
5893 spin_unlock_bh(&ar->data_lock);
5894
5895 ieee80211_queue_work(hw, &arsta->update_wk);
5896}
5897
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005898static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5899{
5900 /*
5901 * FIXME: Return 0 for time being. Need to figure out whether FW
5902 * has the API to fetch 64-bit local TSF
5903 */
5904
5905 return 0;
5906}
5907
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005908static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5909 struct ieee80211_vif *vif,
5910 enum ieee80211_ampdu_mlme_action action,
5911 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5912 u8 buf_size)
5913{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005914 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005915 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5916
Michal Kazior7aa7a722014-08-25 12:09:38 +02005917 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 +02005918 arvif->vdev_id, sta->addr, tid, action);
5919
5920 switch (action) {
5921 case IEEE80211_AMPDU_RX_START:
5922 case IEEE80211_AMPDU_RX_STOP:
5923 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5924 * creation/removal. Do we need to verify this?
5925 */
5926 return 0;
5927 case IEEE80211_AMPDU_TX_START:
5928 case IEEE80211_AMPDU_TX_STOP_CONT:
5929 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5930 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5931 case IEEE80211_AMPDU_TX_OPERATIONAL:
5932 /* Firmware offloads Tx aggregation entirely so deny mac80211
5933 * Tx aggregation requests.
5934 */
5935 return -EOPNOTSUPP;
5936 }
5937
5938 return -EINVAL;
5939}
5940
Michal Kazior500ff9f2015-03-31 10:26:21 +00005941static void
5942ath10k_mac_update_rx_channel(struct ath10k *ar)
5943{
5944 struct cfg80211_chan_def *def = NULL;
5945
5946 /* Both locks are required because ar->rx_channel is modified. This
5947 * allows readers to hold either lock.
5948 */
5949 lockdep_assert_held(&ar->conf_mutex);
5950 lockdep_assert_held(&ar->data_lock);
5951
5952 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5953 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5954 * ppdu on Rx may reduce performance on low-end systems. It should be
5955 * possible to make tables/hashmaps to speed the lookup up (be vary of
5956 * cpu data cache lines though regarding sizes) but to keep the initial
5957 * implementation simple and less intrusive fallback to the slow lookup
5958 * only for multi-channel cases. Single-channel cases will remain to
5959 * use the old channel derival and thus performance should not be
5960 * affected much.
5961 */
5962 rcu_read_lock();
5963 if (ath10k_mac_num_chanctxs(ar) == 1) {
5964 ieee80211_iter_chan_contexts_atomic(ar->hw,
5965 ath10k_mac_get_any_chandef_iter,
5966 &def);
5967 ar->rx_channel = def->chan;
5968 } else {
5969 ar->rx_channel = NULL;
5970 }
5971 rcu_read_unlock();
5972}
5973
5974static void
5975ath10k_mac_chan_ctx_init(struct ath10k *ar,
5976 struct ath10k_chanctx *arctx,
5977 struct ieee80211_chanctx_conf *conf)
5978{
5979 lockdep_assert_held(&ar->conf_mutex);
5980 lockdep_assert_held(&ar->data_lock);
5981
5982 memset(arctx, 0, sizeof(*arctx));
5983
5984 arctx->conf = *conf;
5985}
5986
5987static int
5988ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5989 struct ieee80211_chanctx_conf *ctx)
5990{
5991 struct ath10k *ar = hw->priv;
5992 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5993
5994 ath10k_dbg(ar, ATH10K_DBG_MAC,
5995 "mac chanctx add freq %hu width %d ptr %p\n",
5996 ctx->def.chan->center_freq, ctx->def.width, ctx);
5997
5998 mutex_lock(&ar->conf_mutex);
5999
6000 spin_lock_bh(&ar->data_lock);
6001 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
6002 ath10k_mac_update_rx_channel(ar);
6003 spin_unlock_bh(&ar->data_lock);
6004
6005 ath10k_recalc_radar_detection(ar);
6006 ath10k_monitor_recalc(ar);
6007
6008 mutex_unlock(&ar->conf_mutex);
6009
6010 return 0;
6011}
6012
6013static void
6014ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6015 struct ieee80211_chanctx_conf *ctx)
6016{
6017 struct ath10k *ar = hw->priv;
6018
6019 ath10k_dbg(ar, ATH10K_DBG_MAC,
6020 "mac chanctx remove freq %hu width %d ptr %p\n",
6021 ctx->def.chan->center_freq, ctx->def.width, ctx);
6022
6023 mutex_lock(&ar->conf_mutex);
6024
6025 spin_lock_bh(&ar->data_lock);
6026 ath10k_mac_update_rx_channel(ar);
6027 spin_unlock_bh(&ar->data_lock);
6028
6029 ath10k_recalc_radar_detection(ar);
6030 ath10k_monitor_recalc(ar);
6031
6032 mutex_unlock(&ar->conf_mutex);
6033}
6034
6035static void
6036ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6037 struct ieee80211_chanctx_conf *ctx,
6038 u32 changed)
6039{
6040 struct ath10k *ar = hw->priv;
6041 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6042
6043 mutex_lock(&ar->conf_mutex);
6044
6045 ath10k_dbg(ar, ATH10K_DBG_MAC,
6046 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6047 arctx->conf.def.chan->center_freq,
6048 ctx->def.chan->center_freq,
6049 arctx->conf.def.width, ctx->def.width,
6050 ctx, changed);
6051
6052 /* This shouldn't really happen because channel switching should use
6053 * switch_vif_chanctx().
6054 */
6055 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6056 goto unlock;
6057
6058 spin_lock_bh(&ar->data_lock);
6059 arctx->conf = *ctx;
6060 spin_unlock_bh(&ar->data_lock);
6061
6062 ath10k_recalc_radar_detection(ar);
6063
6064 /* FIXME: How to configure Rx chains properly? */
6065
6066 /* No other actions are actually necessary. Firmware maintains channel
6067 * definitions per vdev internally and there's no host-side channel
6068 * context abstraction to configure, e.g. channel width.
6069 */
6070
6071unlock:
6072 mutex_unlock(&ar->conf_mutex);
6073}
6074
6075static int
6076ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6077 struct ieee80211_vif *vif,
6078 struct ieee80211_chanctx_conf *ctx)
6079{
6080 struct ath10k *ar = hw->priv;
6081 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6082 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6083 int ret;
6084
6085 mutex_lock(&ar->conf_mutex);
6086
6087 ath10k_dbg(ar, ATH10K_DBG_MAC,
6088 "mac chanctx assign ptr %p vdev_id %i\n",
6089 ctx, arvif->vdev_id);
6090
6091 if (WARN_ON(arvif->is_started)) {
6092 mutex_unlock(&ar->conf_mutex);
6093 return -EBUSY;
6094 }
6095
6096 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6097 if (ret) {
6098 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6099 arvif->vdev_id, vif->addr,
6100 arctx->conf.def.chan->center_freq, ret);
6101 goto err;
6102 }
6103
6104 arvif->is_started = true;
6105
6106 if (vif->type == NL80211_IFTYPE_MONITOR) {
6107 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6108 if (ret) {
6109 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6110 arvif->vdev_id, ret);
6111 goto err_stop;
6112 }
6113
6114 arvif->is_up = true;
6115 }
6116
6117 mutex_unlock(&ar->conf_mutex);
6118 return 0;
6119
6120err_stop:
6121 ath10k_vdev_stop(arvif);
6122 arvif->is_started = false;
6123
6124err:
6125 mutex_unlock(&ar->conf_mutex);
6126 return ret;
6127}
6128
6129static void
6130ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6131 struct ieee80211_vif *vif,
6132 struct ieee80211_chanctx_conf *ctx)
6133{
6134 struct ath10k *ar = hw->priv;
6135 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6136 int ret;
6137
6138 mutex_lock(&ar->conf_mutex);
6139
6140 ath10k_dbg(ar, ATH10K_DBG_MAC,
6141 "mac chanctx unassign ptr %p vdev_id %i\n",
6142 ctx, arvif->vdev_id);
6143
6144 WARN_ON(!arvif->is_started);
6145
6146 if (vif->type == NL80211_IFTYPE_MONITOR) {
6147 WARN_ON(!arvif->is_up);
6148
6149 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6150 if (ret)
6151 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6152 arvif->vdev_id, ret);
6153
6154 arvif->is_up = false;
6155 }
6156
6157 ret = ath10k_vdev_stop(arvif);
6158 if (ret)
6159 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6160 arvif->vdev_id, ret);
6161
6162 arvif->is_started = false;
6163
6164 mutex_unlock(&ar->conf_mutex);
6165}
6166
6167static int
6168ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6169 struct ieee80211_vif_chanctx_switch *vifs,
6170 int n_vifs,
6171 enum ieee80211_chanctx_switch_mode mode)
6172{
6173 struct ath10k *ar = hw->priv;
6174 struct ath10k_vif *arvif;
6175 struct ath10k_chanctx *arctx_new, *arctx_old;
6176 int i;
6177
6178 mutex_lock(&ar->conf_mutex);
6179
6180 ath10k_dbg(ar, ATH10K_DBG_MAC,
6181 "mac chanctx switch n_vifs %d mode %d\n",
6182 n_vifs, mode);
6183
6184 spin_lock_bh(&ar->data_lock);
6185 for (i = 0; i < n_vifs; i++) {
6186 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6187 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6188 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6189
6190 ath10k_dbg(ar, ATH10K_DBG_MAC,
6191 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6192 arvif->vdev_id,
6193 vifs[i].old_ctx->def.chan->center_freq,
6194 vifs[i].new_ctx->def.chan->center_freq,
6195 vifs[i].old_ctx->def.width,
6196 vifs[i].new_ctx->def.width,
6197 arctx_old, arctx_new);
6198
6199 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6200 ath10k_mac_chan_ctx_init(ar, arctx_new,
6201 vifs[i].new_ctx);
6202 }
6203
6204 arctx_new->conf = *vifs[i].new_ctx;
6205
6206 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6207 * yet updated chanctx_conf pointer.
6208 */
6209 arctx_old->conf = *vifs[i].new_ctx;
6210 }
6211 ath10k_mac_update_rx_channel(ar);
6212 spin_unlock_bh(&ar->data_lock);
6213
6214 /* FIXME: Reconfigure only affected vifs */
6215 ath10k_mac_chan_reconfigure(ar);
6216
6217 mutex_unlock(&ar->conf_mutex);
6218 return 0;
6219}
6220
Kalle Valo5e3dd152013-06-12 20:52:10 +03006221static const struct ieee80211_ops ath10k_ops = {
6222 .tx = ath10k_tx,
6223 .start = ath10k_start,
6224 .stop = ath10k_stop,
6225 .config = ath10k_config,
6226 .add_interface = ath10k_add_interface,
6227 .remove_interface = ath10k_remove_interface,
6228 .configure_filter = ath10k_configure_filter,
6229 .bss_info_changed = ath10k_bss_info_changed,
6230 .hw_scan = ath10k_hw_scan,
6231 .cancel_hw_scan = ath10k_cancel_hw_scan,
6232 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006233 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006234 .sta_state = ath10k_sta_state,
6235 .conf_tx = ath10k_conf_tx,
6236 .remain_on_channel = ath10k_remain_on_channel,
6237 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6238 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006239 .flush = ath10k_flush,
6240 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006241 .set_antenna = ath10k_set_antenna,
6242 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006243 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006244 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006245 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006246 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006247 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006248 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006249 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6250 .get_et_stats = ath10k_debug_get_et_stats,
6251 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006252 .add_chanctx = ath10k_mac_op_add_chanctx,
6253 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6254 .change_chanctx = ath10k_mac_op_change_chanctx,
6255 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6256 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6257 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006258
6259 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6260
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006261#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006262 .suspend = ath10k_wow_op_suspend,
6263 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006264#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006265#ifdef CONFIG_MAC80211_DEBUGFS
6266 .sta_add_debugfs = ath10k_sta_add_debugfs,
6267#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006268};
6269
Kalle Valo5e3dd152013-06-12 20:52:10 +03006270#define CHAN2G(_channel, _freq, _flags) { \
6271 .band = IEEE80211_BAND_2GHZ, \
6272 .hw_value = (_channel), \
6273 .center_freq = (_freq), \
6274 .flags = (_flags), \
6275 .max_antenna_gain = 0, \
6276 .max_power = 30, \
6277}
6278
6279#define CHAN5G(_channel, _freq, _flags) { \
6280 .band = IEEE80211_BAND_5GHZ, \
6281 .hw_value = (_channel), \
6282 .center_freq = (_freq), \
6283 .flags = (_flags), \
6284 .max_antenna_gain = 0, \
6285 .max_power = 30, \
6286}
6287
6288static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6289 CHAN2G(1, 2412, 0),
6290 CHAN2G(2, 2417, 0),
6291 CHAN2G(3, 2422, 0),
6292 CHAN2G(4, 2427, 0),
6293 CHAN2G(5, 2432, 0),
6294 CHAN2G(6, 2437, 0),
6295 CHAN2G(7, 2442, 0),
6296 CHAN2G(8, 2447, 0),
6297 CHAN2G(9, 2452, 0),
6298 CHAN2G(10, 2457, 0),
6299 CHAN2G(11, 2462, 0),
6300 CHAN2G(12, 2467, 0),
6301 CHAN2G(13, 2472, 0),
6302 CHAN2G(14, 2484, 0),
6303};
6304
6305static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006306 CHAN5G(36, 5180, 0),
6307 CHAN5G(40, 5200, 0),
6308 CHAN5G(44, 5220, 0),
6309 CHAN5G(48, 5240, 0),
6310 CHAN5G(52, 5260, 0),
6311 CHAN5G(56, 5280, 0),
6312 CHAN5G(60, 5300, 0),
6313 CHAN5G(64, 5320, 0),
6314 CHAN5G(100, 5500, 0),
6315 CHAN5G(104, 5520, 0),
6316 CHAN5G(108, 5540, 0),
6317 CHAN5G(112, 5560, 0),
6318 CHAN5G(116, 5580, 0),
6319 CHAN5G(120, 5600, 0),
6320 CHAN5G(124, 5620, 0),
6321 CHAN5G(128, 5640, 0),
6322 CHAN5G(132, 5660, 0),
6323 CHAN5G(136, 5680, 0),
6324 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006325 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006326 CHAN5G(149, 5745, 0),
6327 CHAN5G(153, 5765, 0),
6328 CHAN5G(157, 5785, 0),
6329 CHAN5G(161, 5805, 0),
6330 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006331};
6332
Michal Kaziore7b54192014-08-07 11:03:27 +02006333struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006334{
6335 struct ieee80211_hw *hw;
6336 struct ath10k *ar;
6337
Michal Kaziore7b54192014-08-07 11:03:27 +02006338 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006339 if (!hw)
6340 return NULL;
6341
6342 ar = hw->priv;
6343 ar->hw = hw;
6344
6345 return ar;
6346}
6347
6348void ath10k_mac_destroy(struct ath10k *ar)
6349{
6350 ieee80211_free_hw(ar->hw);
6351}
6352
6353static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6354 {
6355 .max = 8,
6356 .types = BIT(NL80211_IFTYPE_STATION)
6357 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006358 },
6359 {
6360 .max = 3,
6361 .types = BIT(NL80211_IFTYPE_P2P_GO)
6362 },
6363 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006364 .max = 1,
6365 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6366 },
6367 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006368 .max = 7,
6369 .types = BIT(NL80211_IFTYPE_AP)
6370 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006371};
6372
Bartosz Markowskif2595092013-12-10 16:20:39 +01006373static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006374 {
6375 .max = 8,
6376 .types = BIT(NL80211_IFTYPE_AP)
6377 },
6378};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006379
6380static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6381 {
6382 .limits = ath10k_if_limits,
6383 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6384 .max_interfaces = 8,
6385 .num_different_channels = 1,
6386 .beacon_int_infra_match = true,
6387 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006388};
6389
6390static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006391 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006392 .limits = ath10k_10x_if_limits,
6393 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006394 .max_interfaces = 8,
6395 .num_different_channels = 1,
6396 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006397#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006398 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6399 BIT(NL80211_CHAN_WIDTH_20) |
6400 BIT(NL80211_CHAN_WIDTH_40) |
6401 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006402#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006403 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006404};
6405
Michal Kaziorcf327842015-03-31 10:26:25 +00006406static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6407 {
6408 .max = 2,
6409 .types = BIT(NL80211_IFTYPE_STATION) |
6410 BIT(NL80211_IFTYPE_AP) |
6411 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6412 BIT(NL80211_IFTYPE_P2P_GO),
6413 },
6414 {
6415 .max = 1,
6416 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6417 },
6418};
6419
6420static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6421 {
6422 .max = 1,
6423 .types = BIT(NL80211_IFTYPE_STATION),
6424 },
6425 {
6426 .max = 1,
6427 .types = BIT(NL80211_IFTYPE_ADHOC),
6428 },
6429};
6430
6431/* FIXME: This is not thouroughly tested. These combinations may over- or
6432 * underestimate hw/fw capabilities.
6433 */
6434static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6435 {
6436 .limits = ath10k_tlv_if_limit,
6437 .num_different_channels = 1,
6438 .max_interfaces = 3,
6439 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6440 },
6441 {
6442 .limits = ath10k_tlv_if_limit_ibss,
6443 .num_different_channels = 1,
6444 .max_interfaces = 2,
6445 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6446 },
6447};
6448
6449static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6450 {
6451 .limits = ath10k_tlv_if_limit,
6452 .num_different_channels = 2,
6453 .max_interfaces = 3,
6454 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6455 },
6456 {
6457 .limits = ath10k_tlv_if_limit_ibss,
6458 .num_different_channels = 1,
6459 .max_interfaces = 2,
6460 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6461 },
6462};
6463
Kalle Valo5e3dd152013-06-12 20:52:10 +03006464static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6465{
6466 struct ieee80211_sta_vht_cap vht_cap = {0};
6467 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006468 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006469 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006470
6471 vht_cap.vht_supported = 1;
6472 vht_cap.cap = ar->vht_cap_info;
6473
Michal Kaziorbc657a362015-02-26 11:11:22 +01006474 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6475 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6476 val = ar->num_rf_chains - 1;
6477 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6478 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6479
6480 vht_cap.cap |= val;
6481 }
6482
6483 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6484 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6485 val = ar->num_rf_chains - 1;
6486 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6487 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6488
6489 vht_cap.cap |= val;
6490 }
6491
Michal Kazior8865bee42013-07-24 12:36:46 +02006492 mcs_map = 0;
6493 for (i = 0; i < 8; i++) {
6494 if (i < ar->num_rf_chains)
6495 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6496 else
6497 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6498 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006499
6500 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6501 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6502
6503 return vht_cap;
6504}
6505
6506static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6507{
6508 int i;
6509 struct ieee80211_sta_ht_cap ht_cap = {0};
6510
6511 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6512 return ht_cap;
6513
6514 ht_cap.ht_supported = 1;
6515 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6516 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6517 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6518 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6519 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6520
6521 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6522 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6523
6524 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6525 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6526
6527 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6528 u32 smps;
6529
6530 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6531 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6532
6533 ht_cap.cap |= smps;
6534 }
6535
6536 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6537 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6538
6539 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6540 u32 stbc;
6541
6542 stbc = ar->ht_cap_info;
6543 stbc &= WMI_HT_CAP_RX_STBC;
6544 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6545 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6546 stbc &= IEEE80211_HT_CAP_RX_STBC;
6547
6548 ht_cap.cap |= stbc;
6549 }
6550
6551 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6552 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6553
6554 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6555 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6556
6557 /* max AMSDU is implicitly taken from vht_cap_info */
6558 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6559 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6560
Michal Kazior8865bee42013-07-24 12:36:46 +02006561 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006562 ht_cap.mcs.rx_mask[i] = 0xFF;
6563
6564 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6565
6566 return ht_cap;
6567}
6568
Kalle Valo5e3dd152013-06-12 20:52:10 +03006569static void ath10k_get_arvif_iter(void *data, u8 *mac,
6570 struct ieee80211_vif *vif)
6571{
6572 struct ath10k_vif_iter *arvif_iter = data;
6573 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6574
6575 if (arvif->vdev_id == arvif_iter->vdev_id)
6576 arvif_iter->arvif = arvif;
6577}
6578
6579struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6580{
6581 struct ath10k_vif_iter arvif_iter;
6582 u32 flags;
6583
6584 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6585 arvif_iter.vdev_id = vdev_id;
6586
6587 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6588 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6589 flags,
6590 ath10k_get_arvif_iter,
6591 &arvif_iter);
6592 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006593 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006594 return NULL;
6595 }
6596
6597 return arvif_iter.arvif;
6598}
6599
6600int ath10k_mac_register(struct ath10k *ar)
6601{
Johannes Berg3cb10942015-01-22 21:38:45 +01006602 static const u32 cipher_suites[] = {
6603 WLAN_CIPHER_SUITE_WEP40,
6604 WLAN_CIPHER_SUITE_WEP104,
6605 WLAN_CIPHER_SUITE_TKIP,
6606 WLAN_CIPHER_SUITE_CCMP,
6607 WLAN_CIPHER_SUITE_AES_CMAC,
6608 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006609 struct ieee80211_supported_band *band;
6610 struct ieee80211_sta_vht_cap vht_cap;
6611 struct ieee80211_sta_ht_cap ht_cap;
6612 void *channels;
6613 int ret;
6614
6615 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6616
6617 SET_IEEE80211_DEV(ar->hw, ar->dev);
6618
6619 ht_cap = ath10k_get_ht_cap(ar);
6620 vht_cap = ath10k_create_vht_cap(ar);
6621
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006622 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6623 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6624 ATH10K_NUM_CHANS);
6625
Kalle Valo5e3dd152013-06-12 20:52:10 +03006626 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6627 channels = kmemdup(ath10k_2ghz_channels,
6628 sizeof(ath10k_2ghz_channels),
6629 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006630 if (!channels) {
6631 ret = -ENOMEM;
6632 goto err_free;
6633 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006634
6635 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6636 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6637 band->channels = channels;
6638 band->n_bitrates = ath10k_g_rates_size;
6639 band->bitrates = ath10k_g_rates;
6640 band->ht_cap = ht_cap;
6641
Yanbo Lid68bb122015-01-23 08:18:20 +08006642 /* Enable the VHT support at 2.4 GHz */
6643 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006644
6645 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6646 }
6647
6648 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6649 channels = kmemdup(ath10k_5ghz_channels,
6650 sizeof(ath10k_5ghz_channels),
6651 GFP_KERNEL);
6652 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006653 ret = -ENOMEM;
6654 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006655 }
6656
6657 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6658 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6659 band->channels = channels;
6660 band->n_bitrates = ath10k_a_rates_size;
6661 band->bitrates = ath10k_a_rates;
6662 band->ht_cap = ht_cap;
6663 band->vht_cap = vht_cap;
6664 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6665 }
6666
6667 ar->hw->wiphy->interface_modes =
6668 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006669 BIT(NL80211_IFTYPE_AP);
6670
Ben Greear46acf7b2014-05-16 17:15:38 +03006671 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6672 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6673
Bartosz Markowskid3541812013-12-10 16:20:40 +01006674 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6675 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006676 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006677 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6678 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006679
6680 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6681 IEEE80211_HW_SUPPORTS_PS |
6682 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006683 IEEE80211_HW_MFP_CAPABLE |
6684 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6685 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006686 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006687 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006688 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006689 IEEE80211_HW_CONNECTION_MONITOR |
6690 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006691 IEEE80211_HW_CHANCTX_STA_CSA |
6692 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006693
Eliad Peller0d8614b2014-09-10 14:07:36 +03006694 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6695
Kalle Valo5e3dd152013-06-12 20:52:10 +03006696 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006697 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006698
6699 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6700 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6701 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6702 }
6703
6704 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6705 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6706
6707 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006708 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006709 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006710
Kalle Valo5e3dd152013-06-12 20:52:10 +03006711 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6712
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006713 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6714 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6715
6716 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6717 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6718 * correct Probe Responses. This is more of a hack advert..
6719 */
6720 ar->hw->wiphy->probe_resp_offload |=
6721 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6722 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6723 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6724 }
6725
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006726 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6727 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6728
Kalle Valo5e3dd152013-06-12 20:52:10 +03006729 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006730 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006731 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6732
6733 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006734 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6735
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006736 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6737
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006738 ret = ath10k_wow_init(ar);
6739 if (ret) {
6740 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6741 goto err_free;
6742 }
6743
Kalle Valo5e3dd152013-06-12 20:52:10 +03006744 /*
6745 * on LL hardware queues are managed entirely by the FW
6746 * so we only advertise to mac we can do the queues thing
6747 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006748 ar->hw->queues = IEEE80211_MAX_QUEUES;
6749
6750 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6751 * something that vdev_ids can't reach so that we don't stop the queue
6752 * accidentally.
6753 */
6754 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006755
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006756 switch (ar->wmi.op_version) {
6757 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006758 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6759 ar->hw->wiphy->n_iface_combinations =
6760 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006761 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006762 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006763 case ATH10K_FW_WMI_OP_VERSION_TLV:
6764 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6765 ar->hw->wiphy->iface_combinations =
6766 ath10k_tlv_qcs_if_comb;
6767 ar->hw->wiphy->n_iface_combinations =
6768 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
6769 } else {
6770 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
6771 ar->hw->wiphy->n_iface_combinations =
6772 ARRAY_SIZE(ath10k_tlv_if_comb);
6773 }
6774 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6775 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006776 case ATH10K_FW_WMI_OP_VERSION_10_1:
6777 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006778 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006779 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6780 ar->hw->wiphy->n_iface_combinations =
6781 ARRAY_SIZE(ath10k_10x_if_comb);
6782 break;
6783 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6784 case ATH10K_FW_WMI_OP_VERSION_MAX:
6785 WARN_ON(1);
6786 ret = -EINVAL;
6787 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006788 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006789
Michal Kazior7c199992013-07-31 10:47:57 +02006790 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6791
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006792 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6793 /* Init ath dfs pattern detector */
6794 ar->ath_common.debug_mask = ATH_DBG_DFS;
6795 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6796 NL80211_DFS_UNSET);
6797
6798 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006799 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006800 }
6801
Kalle Valo5e3dd152013-06-12 20:52:10 +03006802 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6803 ath10k_reg_notifier);
6804 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006805 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006806 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006807 }
6808
Johannes Berg3cb10942015-01-22 21:38:45 +01006809 ar->hw->wiphy->cipher_suites = cipher_suites;
6810 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6811
Kalle Valo5e3dd152013-06-12 20:52:10 +03006812 ret = ieee80211_register_hw(ar->hw);
6813 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006814 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006815 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006816 }
6817
6818 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6819 ret = regulatory_hint(ar->hw->wiphy,
6820 ar->ath_common.regulatory.alpha2);
6821 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006822 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006823 }
6824
6825 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006826
6827err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006828 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006829err_free:
6830 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6831 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6832
Kalle Valo5e3dd152013-06-12 20:52:10 +03006833 return ret;
6834}
6835
6836void ath10k_mac_unregister(struct ath10k *ar)
6837{
6838 ieee80211_unregister_hw(ar->hw);
6839
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006840 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6841 ar->dfs_detector->exit(ar->dfs_detector);
6842
Kalle Valo5e3dd152013-06-12 20:52:10 +03006843 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6844 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6845
6846 SET_IEEE80211_DEV(ar->hw, NULL);
6847}