blob: 1907b9f4611abe14b4eb443447f7aa6786744f3e [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
Michal Kaziorce90b272015-04-10 13:23:21 +0000233 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
234 addr, flags);
235 if (ret)
236 return ret;
237
238 flags = 0;
239 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300240
241 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100242 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300243 if (ret)
244 return ret;
245
Sujith Manoharanae167132014-11-25 11:46:59 +0530246 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300247 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530248 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300249 }
250
Michal Kaziorce90b272015-04-10 13:23:21 +0000251 /* In some cases (notably with static WEP IBSS with multiple keys)
252 * multicast Tx becomes broken. Both pairwise and groupwise keys are
253 * installed already. Using WMI_KEY_TX_USAGE in different combinations
254 * didn't seem help. Using def_keyid vdev parameter seems to be
255 * effective so use that.
256 *
257 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
258 */
259 if (arvif->def_wep_key_idx == -1)
260 return 0;
261
262 ret = ath10k_wmi_vdev_set_param(arvif->ar,
263 arvif->vdev_id,
264 arvif->ar->wmi.vdev_param->def_keyid,
265 arvif->def_wep_key_idx);
266 if (ret) {
267 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
268 arvif->vdev_id, ret);
269 return ret;
270 }
271
Kalle Valo5e3dd152013-06-12 20:52:10 +0300272 return 0;
273}
274
275static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
276 const u8 *addr)
277{
278 struct ath10k *ar = arvif->ar;
279 struct ath10k_peer *peer;
280 int first_errno = 0;
281 int ret;
282 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100283 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284
285 lockdep_assert_held(&ar->conf_mutex);
286
287 spin_lock_bh(&ar->data_lock);
288 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
289 spin_unlock_bh(&ar->data_lock);
290
291 if (!peer)
292 return -ENOENT;
293
294 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
295 if (peer->keys[i] == NULL)
296 continue;
297
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200298 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300299 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100300 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300301 if (ret && first_errno == 0)
302 first_errno = ret;
303
304 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200305 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300306 i, ret);
307
Sujith Manoharanae167132014-11-25 11:46:59 +0530308 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300309 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530310 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300311 }
312
313 return first_errno;
314}
315
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530316bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
317 u8 keyidx)
318{
319 struct ath10k_peer *peer;
320 int i;
321
322 lockdep_assert_held(&ar->data_lock);
323
324 /* We don't know which vdev this peer belongs to,
325 * since WMI doesn't give us that information.
326 *
327 * FIXME: multi-bss needs to be handled.
328 */
329 peer = ath10k_peer_find(ar, 0, addr);
330 if (!peer)
331 return false;
332
333 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
334 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
335 return true;
336 }
337
338 return false;
339}
340
Kalle Valo5e3dd152013-06-12 20:52:10 +0300341static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
342 struct ieee80211_key_conf *key)
343{
344 struct ath10k *ar = arvif->ar;
345 struct ath10k_peer *peer;
346 u8 addr[ETH_ALEN];
347 int first_errno = 0;
348 int ret;
349 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100350 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300351
352 lockdep_assert_held(&ar->conf_mutex);
353
354 for (;;) {
355 /* since ath10k_install_key we can't hold data_lock all the
356 * time, so we try to remove the keys incrementally */
357 spin_lock_bh(&ar->data_lock);
358 i = 0;
359 list_for_each_entry(peer, &ar->peers, list) {
360 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
361 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300362 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300363 peer->keys[i] = NULL;
364 break;
365 }
366 }
367
368 if (i < ARRAY_SIZE(peer->keys))
369 break;
370 }
371 spin_unlock_bh(&ar->data_lock);
372
373 if (i == ARRAY_SIZE(peer->keys))
374 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200375 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100376 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300377 if (ret && first_errno == 0)
378 first_errno = ret;
379
380 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200381 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200382 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300383 }
384
385 return first_errno;
386}
387
Michal Kaziorad325cb2015-02-18 14:02:27 +0100388static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
389 struct ieee80211_key_conf *key)
390{
391 struct ath10k *ar = arvif->ar;
392 struct ath10k_peer *peer;
393 int ret;
394
395 lockdep_assert_held(&ar->conf_mutex);
396
397 list_for_each_entry(peer, &ar->peers, list) {
398 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
399 continue;
400
401 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
402 continue;
403
404 if (peer->keys[key->keyidx] == key)
405 continue;
406
407 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
408 arvif->vdev_id, key->keyidx);
409
410 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
411 if (ret) {
412 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
413 arvif->vdev_id, peer->addr, ret);
414 return ret;
415 }
416 }
417
418 return 0;
419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421/*********************/
422/* General utilities */
423/*********************/
424
425static inline enum wmi_phy_mode
426chan_to_phymode(const struct cfg80211_chan_def *chandef)
427{
428 enum wmi_phy_mode phymode = MODE_UNKNOWN;
429
430 switch (chandef->chan->band) {
431 case IEEE80211_BAND_2GHZ:
432 switch (chandef->width) {
433 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800434 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
435 phymode = MODE_11B;
436 else
437 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300438 break;
439 case NL80211_CHAN_WIDTH_20:
440 phymode = MODE_11NG_HT20;
441 break;
442 case NL80211_CHAN_WIDTH_40:
443 phymode = MODE_11NG_HT40;
444 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400445 case NL80211_CHAN_WIDTH_5:
446 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300447 case NL80211_CHAN_WIDTH_80:
448 case NL80211_CHAN_WIDTH_80P80:
449 case NL80211_CHAN_WIDTH_160:
450 phymode = MODE_UNKNOWN;
451 break;
452 }
453 break;
454 case IEEE80211_BAND_5GHZ:
455 switch (chandef->width) {
456 case NL80211_CHAN_WIDTH_20_NOHT:
457 phymode = MODE_11A;
458 break;
459 case NL80211_CHAN_WIDTH_20:
460 phymode = MODE_11NA_HT20;
461 break;
462 case NL80211_CHAN_WIDTH_40:
463 phymode = MODE_11NA_HT40;
464 break;
465 case NL80211_CHAN_WIDTH_80:
466 phymode = MODE_11AC_VHT80;
467 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400468 case NL80211_CHAN_WIDTH_5:
469 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300470 case NL80211_CHAN_WIDTH_80P80:
471 case NL80211_CHAN_WIDTH_160:
472 phymode = MODE_UNKNOWN;
473 break;
474 }
475 break;
476 default:
477 break;
478 }
479
480 WARN_ON(phymode == MODE_UNKNOWN);
481 return phymode;
482}
483
484static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
485{
486/*
487 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
488 * 0 for no restriction
489 * 1 for 1/4 us
490 * 2 for 1/2 us
491 * 3 for 1 us
492 * 4 for 2 us
493 * 5 for 4 us
494 * 6 for 8 us
495 * 7 for 16 us
496 */
497 switch (mpdudensity) {
498 case 0:
499 return 0;
500 case 1:
501 case 2:
502 case 3:
503 /* Our lower layer calculations limit our precision to
504 1 microsecond */
505 return 1;
506 case 4:
507 return 2;
508 case 5:
509 return 4;
510 case 6:
511 return 8;
512 case 7:
513 return 16;
514 default:
515 return 0;
516 }
517}
518
Michal Kazior500ff9f2015-03-31 10:26:21 +0000519int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
520 struct cfg80211_chan_def *def)
521{
522 struct ieee80211_chanctx_conf *conf;
523
524 rcu_read_lock();
525 conf = rcu_dereference(vif->chanctx_conf);
526 if (!conf) {
527 rcu_read_unlock();
528 return -ENOENT;
529 }
530
531 *def = conf->def;
532 rcu_read_unlock();
533
534 return 0;
535}
536
537static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
538 struct ieee80211_chanctx_conf *conf,
539 void *data)
540{
541 int *num = data;
542
543 (*num)++;
544}
545
546static int ath10k_mac_num_chanctxs(struct ath10k *ar)
547{
548 int num = 0;
549
550 ieee80211_iter_chan_contexts_atomic(ar->hw,
551 ath10k_mac_num_chanctxs_iter,
552 &num);
553
554 return num;
555}
556
557static void
558ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
559 struct ieee80211_chanctx_conf *conf,
560 void *data)
561{
562 struct cfg80211_chan_def **def = data;
563
564 *def = &conf->def;
565}
566
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300567static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
568 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300569{
570 int ret;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
Michal Kaziorcfd10612014-11-25 15:16:05 +0100574 if (ar->num_peers >= ar->max_num_peers)
575 return -ENOBUFS;
576
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300577 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800578 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200579 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200580 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800582 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583
584 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800585 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200586 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200587 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800589 }
Michal Kazior292a7532014-11-25 15:16:04 +0100590
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100591 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592
593 return 0;
594}
595
Kalle Valo5a13e762014-01-20 11:01:46 +0200596static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
597{
598 struct ath10k *ar = arvif->ar;
599 u32 param;
600 int ret;
601
602 param = ar->wmi.pdev_param->sta_kickout_th;
603 ret = ath10k_wmi_pdev_set_param(ar, param,
604 ATH10K_KICKOUT_THRESHOLD);
605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200606 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200607 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200608 return ret;
609 }
610
611 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
612 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
613 ATH10K_KEEPALIVE_MIN_IDLE);
614 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200615 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200616 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200617 return ret;
618 }
619
620 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
621 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
622 ATH10K_KEEPALIVE_MAX_IDLE);
623 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200624 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200625 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200626 return ret;
627 }
628
629 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
630 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
631 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
632 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200633 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200634 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200635 return ret;
636 }
637
638 return 0;
639}
640
Vivek Natarajanacab6402014-11-26 09:06:12 +0200641static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200642{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200643 struct ath10k *ar = arvif->ar;
644 u32 vdev_param;
645
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200646 vdev_param = ar->wmi.vdev_param->rts_threshold;
647 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200648}
649
650static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
651{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200652 struct ath10k *ar = arvif->ar;
653 u32 vdev_param;
654
Michal Kazior424121c2013-07-22 14:13:31 +0200655 if (value != 0xFFFFFFFF)
656 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
657 ATH10K_FRAGMT_THRESHOLD_MIN,
658 ATH10K_FRAGMT_THRESHOLD_MAX);
659
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200660 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
661 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200662}
663
Kalle Valo5e3dd152013-06-12 20:52:10 +0300664static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
665{
666 int ret;
667
668 lockdep_assert_held(&ar->conf_mutex);
669
670 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
671 if (ret)
672 return ret;
673
674 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
675 if (ret)
676 return ret;
677
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100678 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100679
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680 return 0;
681}
682
683static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
684{
685 struct ath10k_peer *peer, *tmp;
686
687 lockdep_assert_held(&ar->conf_mutex);
688
689 spin_lock_bh(&ar->data_lock);
690 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
691 if (peer->vdev_id != vdev_id)
692 continue;
693
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695 peer->addr, vdev_id);
696
697 list_del(&peer->list);
698 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100699 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300700 }
701 spin_unlock_bh(&ar->data_lock);
702}
703
Michal Kaziora96d7742013-07-16 09:38:56 +0200704static void ath10k_peer_cleanup_all(struct ath10k *ar)
705{
706 struct ath10k_peer *peer, *tmp;
707
708 lockdep_assert_held(&ar->conf_mutex);
709
710 spin_lock_bh(&ar->data_lock);
711 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
712 list_del(&peer->list);
713 kfree(peer);
714 }
715 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100716
717 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100718 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200719}
720
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300721static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
722 struct ieee80211_sta *sta,
723 enum wmi_tdls_peer_state state)
724{
725 int ret;
726 struct wmi_tdls_peer_update_cmd_arg arg = {};
727 struct wmi_tdls_peer_capab_arg cap = {};
728 struct wmi_channel_arg chan_arg = {};
729
730 lockdep_assert_held(&ar->conf_mutex);
731
732 arg.vdev_id = vdev_id;
733 arg.peer_state = state;
734 ether_addr_copy(arg.addr, sta->addr);
735
736 cap.peer_max_sp = sta->max_sp;
737 cap.peer_uapsd_queues = sta->uapsd_queues;
738
739 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
740 !sta->tdls_initiator)
741 cap.is_peer_responder = 1;
742
743 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
744 if (ret) {
745 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
746 arg.addr, vdev_id, ret);
747 return ret;
748 }
749
750 return 0;
751}
752
Kalle Valo5e3dd152013-06-12 20:52:10 +0300753/************************/
754/* Interface management */
755/************************/
756
Michal Kazior64badcb2014-09-18 11:18:02 +0300757void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
758{
759 struct ath10k *ar = arvif->ar;
760
761 lockdep_assert_held(&ar->data_lock);
762
763 if (!arvif->beacon)
764 return;
765
766 if (!arvif->beacon_buf)
767 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
768 arvif->beacon->len, DMA_TO_DEVICE);
769
Michal Kazioraf213192015-01-29 14:29:52 +0200770 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
771 arvif->beacon_state != ATH10K_BEACON_SENT))
772 return;
773
Michal Kazior64badcb2014-09-18 11:18:02 +0300774 dev_kfree_skb_any(arvif->beacon);
775
776 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200777 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300778}
779
780static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
781{
782 struct ath10k *ar = arvif->ar;
783
784 lockdep_assert_held(&ar->data_lock);
785
786 ath10k_mac_vif_beacon_free(arvif);
787
788 if (arvif->beacon_buf) {
789 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
790 arvif->beacon_buf, arvif->beacon_paddr);
791 arvif->beacon_buf = NULL;
792 }
793}
794
Kalle Valo5e3dd152013-06-12 20:52:10 +0300795static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
796{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300797 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300798
Michal Kazior548db542013-07-05 16:15:15 +0300799 lockdep_assert_held(&ar->conf_mutex);
800
Michal Kazior7962b0d2014-10-28 10:34:38 +0100801 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
802 return -ESHUTDOWN;
803
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300804 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
805 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
806 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300807 return -ETIMEDOUT;
808
809 return 0;
810}
811
Michal Kazior1bbc0972014-04-08 09:45:47 +0300812static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300813{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000814 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100815 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300816 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300817 int ret = 0;
818
819 lockdep_assert_held(&ar->conf_mutex);
820
Michal Kazior500ff9f2015-03-31 10:26:21 +0000821 ieee80211_iter_chan_contexts_atomic(ar->hw,
822 ath10k_mac_get_any_chandef_iter,
823 &chandef);
824 if (WARN_ON_ONCE(!chandef))
825 return -ENOENT;
826
827 channel = chandef->chan;
828
Kalle Valo5e3dd152013-06-12 20:52:10 +0300829 arg.vdev_id = vdev_id;
830 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100831 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300832
833 /* TODO setup this dynamically, what in case we
834 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100835 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200836 arg.channel.chan_radar =
837 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838
Michal Kazior89c5c842013-10-23 04:02:13 -0700839 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700840 arg.channel.max_power = channel->max_power * 2;
841 arg.channel.max_reg_power = channel->max_reg_power * 2;
842 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300843
Michal Kazior7962b0d2014-10-28 10:34:38 +0100844 reinit_completion(&ar->vdev_setup_done);
845
Kalle Valo5e3dd152013-06-12 20:52:10 +0300846 ret = ath10k_wmi_vdev_start(ar, &arg);
847 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200848 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200849 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850 return ret;
851 }
852
853 ret = ath10k_vdev_setup_sync(ar);
854 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200855 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200856 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857 return ret;
858 }
859
860 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
861 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200862 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200863 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300864 goto vdev_stop;
865 }
866
867 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868
Michal Kazior7aa7a722014-08-25 12:09:38 +0200869 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300870 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300871 return 0;
872
873vdev_stop:
874 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
875 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200876 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200877 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300878
879 return ret;
880}
881
Michal Kazior1bbc0972014-04-08 09:45:47 +0300882static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300883{
884 int ret = 0;
885
886 lockdep_assert_held(&ar->conf_mutex);
887
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200888 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
889 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200890 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200891 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300892
Michal Kazior7962b0d2014-10-28 10:34:38 +0100893 reinit_completion(&ar->vdev_setup_done);
894
Kalle Valo5e3dd152013-06-12 20:52:10 +0300895 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
896 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200897 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200898 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899
900 ret = ath10k_vdev_setup_sync(ar);
901 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200902 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200903 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300904
Michal Kazior7aa7a722014-08-25 12:09:38 +0200905 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300906 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907 return ret;
908}
909
Michal Kazior1bbc0972014-04-08 09:45:47 +0300910static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300911{
912 int bit, ret = 0;
913
914 lockdep_assert_held(&ar->conf_mutex);
915
Ben Greeara9aefb32014-08-12 11:02:19 +0300916 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200917 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300918 return -ENOMEM;
919 }
920
Ben Greear16c11172014-09-23 14:17:16 -0700921 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300922
Ben Greear16c11172014-09-23 14:17:16 -0700923 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300924
925 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
926 WMI_VDEV_TYPE_MONITOR,
927 0, ar->mac_addr);
928 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200929 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200930 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300931 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 }
933
Ben Greear16c11172014-09-23 14:17:16 -0700934 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200935 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300936 ar->monitor_vdev_id);
937
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300939}
940
Michal Kazior1bbc0972014-04-08 09:45:47 +0300941static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942{
943 int ret = 0;
944
945 lockdep_assert_held(&ar->conf_mutex);
946
Kalle Valo5e3dd152013-06-12 20:52:10 +0300947 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
948 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200949 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200950 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300951 return ret;
952 }
953
Ben Greear16c11172014-09-23 14:17:16 -0700954 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955
Michal Kazior7aa7a722014-08-25 12:09:38 +0200956 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300957 ar->monitor_vdev_id);
958 return ret;
959}
960
Michal Kazior1bbc0972014-04-08 09:45:47 +0300961static int ath10k_monitor_start(struct ath10k *ar)
962{
963 int ret;
964
965 lockdep_assert_held(&ar->conf_mutex);
966
Michal Kazior1bbc0972014-04-08 09:45:47 +0300967 ret = ath10k_monitor_vdev_create(ar);
968 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200969 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300970 return ret;
971 }
972
973 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
974 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200975 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300976 ath10k_monitor_vdev_delete(ar);
977 return ret;
978 }
979
980 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300982
983 return 0;
984}
985
Michal Kazior19337472014-08-28 12:58:16 +0200986static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300987{
988 int ret;
989
990 lockdep_assert_held(&ar->conf_mutex);
991
Michal Kazior1bbc0972014-04-08 09:45:47 +0300992 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200993 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200994 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200995 return ret;
996 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300997
998 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001000 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001001 return ret;
1002 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001003
1004 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001006
1007 return 0;
1008}
1009
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301010static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1011{
1012 struct ath10k_vif *arvif;
1013
1014 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1015 return true;
1016
1017 if (!ar->num_started_vdevs)
1018 return false;
1019
1020 list_for_each_entry(arvif, &ar->arvifs, list)
1021 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1022 return false;
1023
1024 ath10k_dbg(ar, ATH10K_DBG_MAC,
1025 "mac disabling promiscuous mode because vdev is started\n");
1026 return true;
1027}
1028
Michal Kazior500ff9f2015-03-31 10:26:21 +00001029static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1030{
1031 int num_ctx;
1032
1033 /* At least one chanctx is required to derive a channel to start
1034 * monitor vdev on.
1035 */
1036 num_ctx = ath10k_mac_num_chanctxs(ar);
1037 if (num_ctx == 0)
1038 return false;
1039
1040 /* If there's already an existing special monitor interface then don't
1041 * bother creating another monitor vdev.
1042 */
1043 if (ar->monitor_arvif)
1044 return false;
1045
1046 return ar->monitor ||
1047 !ath10k_mac_should_disable_promisc(ar) ||
1048 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1049}
1050
1051static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1052{
1053 int num_ctx;
1054
1055 num_ctx = ath10k_mac_num_chanctxs(ar);
1056
1057 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1058 * shouldn't allow this but make sure to prevent handling the following
1059 * case anyway since multi-channel DFS hasn't been tested at all.
1060 */
1061 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1062 return false;
1063
1064 return true;
1065}
1066
Michal Kazior19337472014-08-28 12:58:16 +02001067static int ath10k_monitor_recalc(struct ath10k *ar)
1068{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001069 bool needed;
1070 bool allowed;
1071 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001072
1073 lockdep_assert_held(&ar->conf_mutex);
1074
Michal Kazior500ff9f2015-03-31 10:26:21 +00001075 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1076 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001077
1078 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001079 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1080 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001081
Michal Kazior500ff9f2015-03-31 10:26:21 +00001082 if (WARN_ON(needed && !allowed)) {
1083 if (ar->monitor_started) {
1084 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1085
1086 ret = ath10k_monitor_stop(ar);
1087 if (ret)
1088 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1089 /* not serious */
1090 }
1091
1092 return -EPERM;
1093 }
1094
1095 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001096 return 0;
1097
Michal Kazior500ff9f2015-03-31 10:26:21 +00001098 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001099 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001100 else
1101 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001102}
1103
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001104static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1105{
1106 struct ath10k *ar = arvif->ar;
1107 u32 vdev_param, rts_cts = 0;
1108
1109 lockdep_assert_held(&ar->conf_mutex);
1110
1111 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1112
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001113 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001114
1115 if (arvif->num_legacy_stations > 0)
1116 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1117 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001118 else
1119 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1120 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001121
1122 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1123 rts_cts);
1124}
1125
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001126static int ath10k_start_cac(struct ath10k *ar)
1127{
1128 int ret;
1129
1130 lockdep_assert_held(&ar->conf_mutex);
1131
1132 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1133
Michal Kazior19337472014-08-28 12:58:16 +02001134 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001135 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001136 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001137 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1138 return ret;
1139 }
1140
Michal Kazior7aa7a722014-08-25 12:09:38 +02001141 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001142 ar->monitor_vdev_id);
1143
1144 return 0;
1145}
1146
1147static int ath10k_stop_cac(struct ath10k *ar)
1148{
1149 lockdep_assert_held(&ar->conf_mutex);
1150
1151 /* CAC is not running - do nothing */
1152 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1153 return 0;
1154
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001155 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001156 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001157
Michal Kazior7aa7a722014-08-25 12:09:38 +02001158 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001159
1160 return 0;
1161}
1162
Michal Kazior500ff9f2015-03-31 10:26:21 +00001163static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1164 struct ieee80211_chanctx_conf *conf,
1165 void *data)
1166{
1167 bool *ret = data;
1168
1169 if (!*ret && conf->radar_enabled)
1170 *ret = true;
1171}
1172
1173static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1174{
1175 bool has_radar = false;
1176
1177 ieee80211_iter_chan_contexts_atomic(ar->hw,
1178 ath10k_mac_has_radar_iter,
1179 &has_radar);
1180
1181 return has_radar;
1182}
1183
Michal Kaziord6500972014-04-08 09:56:09 +03001184static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001185{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001186 int ret;
1187
1188 lockdep_assert_held(&ar->conf_mutex);
1189
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001190 ath10k_stop_cac(ar);
1191
Michal Kazior500ff9f2015-03-31 10:26:21 +00001192 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001193 return;
1194
Michal Kaziord6500972014-04-08 09:56:09 +03001195 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001196 return;
1197
1198 ret = ath10k_start_cac(ar);
1199 if (ret) {
1200 /*
1201 * Not possible to start CAC on current channel so starting
1202 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1203 * by indicating that radar was detected.
1204 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001205 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001206 ieee80211_radar_detected(ar->hw);
1207 }
1208}
1209
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301210static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1211{
1212 struct ath10k *ar = arvif->ar;
1213 int ret;
1214
1215 lockdep_assert_held(&ar->conf_mutex);
1216
1217 reinit_completion(&ar->vdev_setup_done);
1218
1219 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1220 if (ret) {
1221 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1222 arvif->vdev_id, ret);
1223 return ret;
1224 }
1225
1226 ret = ath10k_vdev_setup_sync(ar);
1227 if (ret) {
1228 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1229 arvif->vdev_id, ret);
1230 return ret;
1231 }
1232
1233 WARN_ON(ar->num_started_vdevs == 0);
1234
1235 if (ar->num_started_vdevs != 0) {
1236 ar->num_started_vdevs--;
1237 ath10k_recalc_radar_detection(ar);
1238 }
1239
1240 return ret;
1241}
1242
Michal Kazior500ff9f2015-03-31 10:26:21 +00001243static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1244 const struct cfg80211_chan_def *chandef,
1245 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001246{
1247 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001248 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301249 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001250
1251 lockdep_assert_held(&ar->conf_mutex);
1252
1253 reinit_completion(&ar->vdev_setup_done);
1254
1255 arg.vdev_id = arvif->vdev_id;
1256 arg.dtim_period = arvif->dtim_period;
1257 arg.bcn_intval = arvif->beacon_interval;
1258
1259 arg.channel.freq = chandef->chan->center_freq;
1260 arg.channel.band_center_freq1 = chandef->center_freq1;
1261 arg.channel.mode = chan_to_phymode(chandef);
1262
1263 arg.channel.min_power = 0;
1264 arg.channel.max_power = chandef->chan->max_power * 2;
1265 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1266 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1267
1268 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1269 arg.ssid = arvif->u.ap.ssid;
1270 arg.ssid_len = arvif->u.ap.ssid_len;
1271 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1272
1273 /* For now allow DFS for AP mode */
1274 arg.channel.chan_radar =
1275 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1276 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1277 arg.ssid = arvif->vif->bss_conf.ssid;
1278 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1279 }
1280
Michal Kazior7aa7a722014-08-25 12:09:38 +02001281 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001282 "mac vdev %d start center_freq %d phymode %s\n",
1283 arg.vdev_id, arg.channel.freq,
1284 ath10k_wmi_phymode_str(arg.channel.mode));
1285
Michal Kaziordc55e302014-07-29 12:53:36 +03001286 if (restart)
1287 ret = ath10k_wmi_vdev_restart(ar, &arg);
1288 else
1289 ret = ath10k_wmi_vdev_start(ar, &arg);
1290
Michal Kazior72654fa2014-04-08 09:56:09 +03001291 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001292 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001293 arg.vdev_id, ret);
1294 return ret;
1295 }
1296
1297 ret = ath10k_vdev_setup_sync(ar);
1298 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001299 ath10k_warn(ar,
1300 "failed to synchronize setup for vdev %i restart %d: %d\n",
1301 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001302 return ret;
1303 }
1304
Michal Kaziord6500972014-04-08 09:56:09 +03001305 ar->num_started_vdevs++;
1306 ath10k_recalc_radar_detection(ar);
1307
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301308 ret = ath10k_monitor_recalc(ar);
1309 if (ret) {
1310 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1311 arg.vdev_id, restart, ret);
1312 ret2 = ath10k_vdev_stop(arvif);
1313 if (ret2)
1314 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1315 arg.vdev_id, restart, ret2);
1316 }
1317
Michal Kazior72654fa2014-04-08 09:56:09 +03001318 return ret;
1319}
1320
Michal Kazior500ff9f2015-03-31 10:26:21 +00001321static int ath10k_vdev_start(struct ath10k_vif *arvif,
1322 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001323{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001324 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001325}
1326
Michal Kazior500ff9f2015-03-31 10:26:21 +00001327static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1328 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001329{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001330 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001331}
1332
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001333static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1334 struct sk_buff *bcn)
1335{
1336 struct ath10k *ar = arvif->ar;
1337 struct ieee80211_mgmt *mgmt;
1338 const u8 *p2p_ie;
1339 int ret;
1340
1341 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1342 return 0;
1343
1344 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1345 return 0;
1346
1347 mgmt = (void *)bcn->data;
1348 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1349 mgmt->u.beacon.variable,
1350 bcn->len - (mgmt->u.beacon.variable -
1351 bcn->data));
1352 if (!p2p_ie)
1353 return -ENOENT;
1354
1355 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1356 if (ret) {
1357 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1358 arvif->vdev_id, ret);
1359 return ret;
1360 }
1361
1362 return 0;
1363}
1364
1365static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1366 u8 oui_type, size_t ie_offset)
1367{
1368 size_t len;
1369 const u8 *next;
1370 const u8 *end;
1371 u8 *ie;
1372
1373 if (WARN_ON(skb->len < ie_offset))
1374 return -EINVAL;
1375
1376 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1377 skb->data + ie_offset,
1378 skb->len - ie_offset);
1379 if (!ie)
1380 return -ENOENT;
1381
1382 len = ie[1] + 2;
1383 end = skb->data + skb->len;
1384 next = ie + len;
1385
1386 if (WARN_ON(next > end))
1387 return -EINVAL;
1388
1389 memmove(ie, next, end - next);
1390 skb_trim(skb, skb->len - len);
1391
1392 return 0;
1393}
1394
1395static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1396{
1397 struct ath10k *ar = arvif->ar;
1398 struct ieee80211_hw *hw = ar->hw;
1399 struct ieee80211_vif *vif = arvif->vif;
1400 struct ieee80211_mutable_offsets offs = {};
1401 struct sk_buff *bcn;
1402 int ret;
1403
1404 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1405 return 0;
1406
Michal Kazior81a9a172015-03-05 16:02:17 +02001407 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1408 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1409 return 0;
1410
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001411 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1412 if (!bcn) {
1413 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1414 return -EPERM;
1415 }
1416
1417 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1418 if (ret) {
1419 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1420 kfree_skb(bcn);
1421 return ret;
1422 }
1423
1424 /* P2P IE is inserted by firmware automatically (as configured above)
1425 * so remove it from the base beacon template to avoid duplicate P2P
1426 * IEs in beacon frames.
1427 */
1428 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1429 offsetof(struct ieee80211_mgmt,
1430 u.beacon.variable));
1431
1432 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1433 0, NULL, 0);
1434 kfree_skb(bcn);
1435
1436 if (ret) {
1437 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1438 ret);
1439 return ret;
1440 }
1441
1442 return 0;
1443}
1444
1445static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1446{
1447 struct ath10k *ar = arvif->ar;
1448 struct ieee80211_hw *hw = ar->hw;
1449 struct ieee80211_vif *vif = arvif->vif;
1450 struct sk_buff *prb;
1451 int ret;
1452
1453 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1454 return 0;
1455
Michal Kazior81a9a172015-03-05 16:02:17 +02001456 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1457 return 0;
1458
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001459 prb = ieee80211_proberesp_get(hw, vif);
1460 if (!prb) {
1461 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1462 return -EPERM;
1463 }
1464
1465 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1466 kfree_skb(prb);
1467
1468 if (ret) {
1469 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1470 ret);
1471 return ret;
1472 }
1473
1474 return 0;
1475}
1476
Michal Kazior500ff9f2015-03-31 10:26:21 +00001477static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1478{
1479 struct ath10k *ar = arvif->ar;
1480 struct cfg80211_chan_def def;
1481 int ret;
1482
1483 /* When originally vdev is started during assign_vif_chanctx() some
1484 * information is missing, notably SSID. Firmware revisions with beacon
1485 * offloading require the SSID to be provided during vdev (re)start to
1486 * handle hidden SSID properly.
1487 *
1488 * Vdev restart must be done after vdev has been both started and
1489 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1490 * deliver vdev restart response event causing timeouts during vdev
1491 * syncing in ath10k.
1492 *
1493 * Note: The vdev down/up and template reinstallation could be skipped
1494 * since only wmi-tlv firmware are known to have beacon offload and
1495 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1496 * response delivery. It's probably more robust to keep it as is.
1497 */
1498 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1499 return 0;
1500
1501 if (WARN_ON(!arvif->is_started))
1502 return -EINVAL;
1503
1504 if (WARN_ON(!arvif->is_up))
1505 return -EINVAL;
1506
1507 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1508 return -EINVAL;
1509
1510 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1511 if (ret) {
1512 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1513 arvif->vdev_id, ret);
1514 return ret;
1515 }
1516
1517 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1518 * firmware will crash upon vdev up.
1519 */
1520
1521 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1522 if (ret) {
1523 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1524 return ret;
1525 }
1526
1527 ret = ath10k_mac_setup_prb_tmpl(arvif);
1528 if (ret) {
1529 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1530 return ret;
1531 }
1532
1533 ret = ath10k_vdev_restart(arvif, &def);
1534 if (ret) {
1535 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1536 arvif->vdev_id, ret);
1537 return ret;
1538 }
1539
1540 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1541 arvif->bssid);
1542 if (ret) {
1543 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1544 arvif->vdev_id, ret);
1545 return ret;
1546 }
1547
1548 return 0;
1549}
1550
Kalle Valo5e3dd152013-06-12 20:52:10 +03001551static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001552 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001554 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555 int ret = 0;
1556
Michal Kazior548db542013-07-05 16:15:15 +03001557 lockdep_assert_held(&arvif->ar->conf_mutex);
1558
Kalle Valo5e3dd152013-06-12 20:52:10 +03001559 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001560 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1561 if (ret)
1562 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1563 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001564
Michal Kaziorc930f742014-01-23 11:38:25 +01001565 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001566
1567 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001568 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001569 spin_unlock_bh(&arvif->ar->data_lock);
1570
Kalle Valo5e3dd152013-06-12 20:52:10 +03001571 return;
1572 }
1573
1574 arvif->tx_seq_no = 0x1000;
1575
Michal Kaziorc930f742014-01-23 11:38:25 +01001576 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001577 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001578
1579 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1580 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001582 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001583 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584 return;
1585 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001586
Michal Kaziorc930f742014-01-23 11:38:25 +01001587 arvif->is_up = true;
1588
Michal Kazior500ff9f2015-03-31 10:26:21 +00001589 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1590 if (ret) {
1591 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1592 arvif->vdev_id, ret);
1593 return;
1594 }
1595
Michal Kazior7aa7a722014-08-25 12:09:38 +02001596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597}
1598
1599static void ath10k_control_ibss(struct ath10k_vif *arvif,
1600 struct ieee80211_bss_conf *info,
1601 const u8 self_peer[ETH_ALEN])
1602{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001603 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001604 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605 int ret = 0;
1606
Michal Kazior548db542013-07-05 16:15:15 +03001607 lockdep_assert_held(&arvif->ar->conf_mutex);
1608
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001610 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611 return;
1612
Michal Kaziorc930f742014-01-23 11:38:25 +01001613 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001614
1615 return;
1616 }
1617
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001618 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1619 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001620 ATH10K_DEFAULT_ATIM);
1621 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001622 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 arvif->vdev_id, ret);
1624}
1625
Michal Kazior9f9b5742014-12-12 12:41:36 +01001626static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1627{
1628 struct ath10k *ar = arvif->ar;
1629 u32 param;
1630 u32 value;
1631 int ret;
1632
1633 lockdep_assert_held(&arvif->ar->conf_mutex);
1634
1635 if (arvif->u.sta.uapsd)
1636 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1637 else
1638 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1639
1640 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1641 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1642 if (ret) {
1643 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1644 value, arvif->vdev_id, ret);
1645 return ret;
1646 }
1647
1648 return 0;
1649}
1650
1651static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1652{
1653 struct ath10k *ar = arvif->ar;
1654 u32 param;
1655 u32 value;
1656 int ret;
1657
1658 lockdep_assert_held(&arvif->ar->conf_mutex);
1659
1660 if (arvif->u.sta.uapsd)
1661 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1662 else
1663 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1664
1665 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1666 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1667 param, value);
1668 if (ret) {
1669 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1670 value, arvif->vdev_id, ret);
1671 return ret;
1672 }
1673
1674 return 0;
1675}
1676
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001677static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1678{
1679 struct ath10k_vif *arvif;
1680 int num = 0;
1681
1682 lockdep_assert_held(&ar->conf_mutex);
1683
1684 list_for_each_entry(arvif, &ar->arvifs, list)
1685 if (arvif->ps)
1686 num++;
1687
1688 return num;
1689}
1690
Michal Kaziorad088bf2013-10-16 15:44:46 +03001691static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001693 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001694 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001695 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696 enum wmi_sta_powersave_param param;
1697 enum wmi_sta_ps_mode psmode;
1698 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001699 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001700 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701
Michal Kazior548db542013-07-05 16:15:15 +03001702 lockdep_assert_held(&arvif->ar->conf_mutex);
1703
Michal Kaziorad088bf2013-10-16 15:44:46 +03001704 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1705 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001707 enable_ps = arvif->ps;
1708
1709 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1710 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1711 ar->fw_features)) {
1712 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1713 arvif->vdev_id);
1714 enable_ps = false;
1715 }
1716
1717 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001718 psmode = WMI_STA_PS_MODE_ENABLED;
1719 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1720
Michal Kazior526549a2014-12-12 12:41:37 +01001721 ps_timeout = conf->dynamic_ps_timeout;
1722 if (ps_timeout == 0) {
1723 /* Firmware doesn't like 0 */
1724 ps_timeout = ieee80211_tu_to_usec(
1725 vif->bss_conf.beacon_int) / 1000;
1726 }
1727
Michal Kaziorad088bf2013-10-16 15:44:46 +03001728 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001729 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001731 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001732 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001733 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001734 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735 } else {
1736 psmode = WMI_STA_PS_MODE_DISABLED;
1737 }
1738
Michal Kazior7aa7a722014-08-25 12:09:38 +02001739 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001740 arvif->vdev_id, psmode ? "enable" : "disable");
1741
Michal Kaziorad088bf2013-10-16 15:44:46 +03001742 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1743 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001744 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001745 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001746 return ret;
1747 }
1748
1749 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750}
1751
Michal Kazior46725b152015-01-28 09:57:49 +02001752static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1753{
1754 struct ath10k *ar = arvif->ar;
1755 struct wmi_sta_keepalive_arg arg = {};
1756 int ret;
1757
1758 lockdep_assert_held(&arvif->ar->conf_mutex);
1759
1760 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1761 return 0;
1762
1763 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1764 return 0;
1765
1766 /* Some firmware revisions have a bug and ignore the `enabled` field.
1767 * Instead use the interval to disable the keepalive.
1768 */
1769 arg.vdev_id = arvif->vdev_id;
1770 arg.enabled = 1;
1771 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1772 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1773
1774 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1775 if (ret) {
1776 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1777 arvif->vdev_id, ret);
1778 return ret;
1779 }
1780
1781 return 0;
1782}
1783
Michal Kazior81a9a172015-03-05 16:02:17 +02001784static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1785{
1786 struct ath10k *ar = arvif->ar;
1787 struct ieee80211_vif *vif = arvif->vif;
1788 int ret;
1789
Michal Kazior8513d952015-03-09 14:19:24 +01001790 lockdep_assert_held(&arvif->ar->conf_mutex);
1791
1792 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1793 return;
1794
Michal Kazior81a9a172015-03-05 16:02:17 +02001795 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1796 return;
1797
1798 if (!vif->csa_active)
1799 return;
1800
1801 if (!arvif->is_up)
1802 return;
1803
1804 if (!ieee80211_csa_is_complete(vif)) {
1805 ieee80211_csa_update_counter(vif);
1806
1807 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1808 if (ret)
1809 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1810 ret);
1811
1812 ret = ath10k_mac_setup_prb_tmpl(arvif);
1813 if (ret)
1814 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1815 ret);
1816 } else {
1817 ieee80211_csa_finish(vif);
1818 }
1819}
1820
1821static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1822{
1823 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1824 ap_csa_work);
1825 struct ath10k *ar = arvif->ar;
1826
1827 mutex_lock(&ar->conf_mutex);
1828 ath10k_mac_vif_ap_csa_count_down(arvif);
1829 mutex_unlock(&ar->conf_mutex);
1830}
1831
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001832static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1833 struct ieee80211_vif *vif)
1834{
1835 struct sk_buff *skb = data;
1836 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1837 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1838
1839 if (vif->type != NL80211_IFTYPE_STATION)
1840 return;
1841
1842 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1843 return;
1844
1845 cancel_delayed_work(&arvif->connection_loss_work);
1846}
1847
1848void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1849{
1850 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1851 IEEE80211_IFACE_ITER_NORMAL,
1852 ath10k_mac_handle_beacon_iter,
1853 skb);
1854}
1855
1856static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1857 struct ieee80211_vif *vif)
1858{
1859 u32 *vdev_id = data;
1860 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1861 struct ath10k *ar = arvif->ar;
1862 struct ieee80211_hw *hw = ar->hw;
1863
1864 if (arvif->vdev_id != *vdev_id)
1865 return;
1866
1867 if (!arvif->is_up)
1868 return;
1869
1870 ieee80211_beacon_loss(vif);
1871
1872 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1873 * (done by mac80211) succeeds but beacons do not resume then it
1874 * doesn't make sense to continue operation. Queue connection loss work
1875 * which can be cancelled when beacon is received.
1876 */
1877 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1878 ATH10K_CONNECTION_LOSS_HZ);
1879}
1880
1881void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1882{
1883 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1884 IEEE80211_IFACE_ITER_NORMAL,
1885 ath10k_mac_handle_beacon_miss_iter,
1886 &vdev_id);
1887}
1888
1889static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1890{
1891 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1892 connection_loss_work.work);
1893 struct ieee80211_vif *vif = arvif->vif;
1894
1895 if (!arvif->is_up)
1896 return;
1897
1898 ieee80211_connection_loss(vif);
1899}
1900
Kalle Valo5e3dd152013-06-12 20:52:10 +03001901/**********************/
1902/* Station management */
1903/**********************/
1904
Michal Kazior590922a2014-10-21 10:10:29 +03001905static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1906 struct ieee80211_vif *vif)
1907{
1908 /* Some firmware revisions have unstable STA powersave when listen
1909 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1910 * generate NullFunc frames properly even if buffered frames have been
1911 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1912 * buffered frames. Often pinging the device from AP would simply fail.
1913 *
1914 * As a workaround set it to 1.
1915 */
1916 if (vif->type == NL80211_IFTYPE_STATION)
1917 return 1;
1918
1919 return ar->hw->conf.listen_interval;
1920}
1921
Kalle Valo5e3dd152013-06-12 20:52:10 +03001922static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001923 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925 struct wmi_peer_assoc_complete_arg *arg)
1926{
Michal Kazior590922a2014-10-21 10:10:29 +03001927 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001928 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001929
Michal Kazior548db542013-07-05 16:15:15 +03001930 lockdep_assert_held(&ar->conf_mutex);
1931
Michal Kaziorc51880e2015-03-30 09:51:57 +03001932 if (vif->type == NL80211_IFTYPE_STATION)
1933 aid = vif->bss_conf.aid;
1934 else
1935 aid = sta->aid;
1936
Kalle Valob25f32c2014-09-14 12:50:49 +03001937 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001939 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001941 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001943 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944}
1945
1946static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001947 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 struct wmi_peer_assoc_complete_arg *arg)
1949{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001951 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952 struct cfg80211_bss *bss;
1953 const u8 *rsnie = NULL;
1954 const u8 *wpaie = NULL;
1955
Michal Kazior548db542013-07-05 16:15:15 +03001956 lockdep_assert_held(&ar->conf_mutex);
1957
Michal Kazior500ff9f2015-03-31 10:26:21 +00001958 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1959 return;
1960
1961 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1962 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001963 if (bss) {
1964 const struct cfg80211_bss_ies *ies;
1965
1966 rcu_read_lock();
1967 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1968
1969 ies = rcu_dereference(bss->ies);
1970
1971 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001972 WLAN_OUI_TYPE_MICROSOFT_WPA,
1973 ies->data,
1974 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001975 rcu_read_unlock();
1976 cfg80211_put_bss(ar->hw->wiphy, bss);
1977 }
1978
1979 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1980 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001981 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001982 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1983 }
1984
1985 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001986 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001987 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1988 }
1989}
1990
1991static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001992 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001993 struct ieee80211_sta *sta,
1994 struct wmi_peer_assoc_complete_arg *arg)
1995{
1996 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001997 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998 const struct ieee80211_supported_band *sband;
1999 const struct ieee80211_rate *rates;
2000 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002001 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002 int i;
2003
Michal Kazior548db542013-07-05 16:15:15 +03002004 lockdep_assert_held(&ar->conf_mutex);
2005
Michal Kazior500ff9f2015-03-31 10:26:21 +00002006 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2007 return;
2008
2009 sband = ar->hw->wiphy->bands[def.chan->band];
2010 ratemask = sta->supp_rates[def.chan->band];
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011 rates = sband->bitrates;
2012
2013 rateset->num_rates = 0;
2014
2015 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2016 if (!(ratemask & 1))
2017 continue;
2018
Michal Kazior486017c2015-03-30 09:51:54 +03002019 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2020 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002021 rateset->num_rates++;
2022 }
2023}
2024
2025static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2026 struct ieee80211_sta *sta,
2027 struct wmi_peer_assoc_complete_arg *arg)
2028{
2029 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002030 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03002031 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002032
Michal Kazior548db542013-07-05 16:15:15 +03002033 lockdep_assert_held(&ar->conf_mutex);
2034
Kalle Valo5e3dd152013-06-12 20:52:10 +03002035 if (!ht_cap->ht_supported)
2036 return;
2037
2038 arg->peer_flags |= WMI_PEER_HT;
2039 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2040 ht_cap->ampdu_factor)) - 1;
2041
2042 arg->peer_mpdu_density =
2043 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2044
2045 arg->peer_ht_caps = ht_cap->cap;
2046 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2047
2048 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2049 arg->peer_flags |= WMI_PEER_LDPC;
2050
2051 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2052 arg->peer_flags |= WMI_PEER_40MHZ;
2053 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2054 }
2055
2056 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2057 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2058
2059 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2060 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2061
2062 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2063 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2064 arg->peer_flags |= WMI_PEER_STBC;
2065 }
2066
2067 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2069 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2070 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2071 arg->peer_rate_caps |= stbc;
2072 arg->peer_flags |= WMI_PEER_STBC;
2073 }
2074
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2076 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2077 else if (ht_cap->mcs.rx_mask[1])
2078 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2079
2080 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
2081 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
2082 arg->peer_ht_rates.rates[n++] = i;
2083
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002084 /*
2085 * This is a workaround for HT-enabled STAs which break the spec
2086 * and have no HT capabilities RX mask (no HT RX MCS map).
2087 *
2088 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2089 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2090 *
2091 * Firmware asserts if such situation occurs.
2092 */
2093 if (n == 0) {
2094 arg->peer_ht_rates.num_rates = 8;
2095 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2096 arg->peer_ht_rates.rates[i] = i;
2097 } else {
2098 arg->peer_ht_rates.num_rates = n;
2099 arg->peer_num_spatial_streams = sta->rx_nss;
2100 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101
Michal Kazior7aa7a722014-08-25 12:09:38 +02002102 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002103 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104 arg->peer_ht_rates.num_rates,
2105 arg->peer_num_spatial_streams);
2106}
2107
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002108static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2109 struct ath10k_vif *arvif,
2110 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111{
2112 u32 uapsd = 0;
2113 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002114 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002115
Michal Kazior548db542013-07-05 16:15:15 +03002116 lockdep_assert_held(&ar->conf_mutex);
2117
Kalle Valo5e3dd152013-06-12 20:52:10 +03002118 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002119 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002120 sta->uapsd_queues, sta->max_sp);
2121
Kalle Valo5e3dd152013-06-12 20:52:10 +03002122 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2123 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2124 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2125 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2126 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2127 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2128 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2129 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2130 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2131 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2132 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2133 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2134
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2136 max_sp = sta->max_sp;
2137
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002138 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2139 sta->addr,
2140 WMI_AP_PS_PEER_PARAM_UAPSD,
2141 uapsd);
2142 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002143 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002144 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002145 return ret;
2146 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002147
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002148 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2149 sta->addr,
2150 WMI_AP_PS_PEER_PARAM_MAX_SP,
2151 max_sp);
2152 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002153 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002154 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002155 return ret;
2156 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157
2158 /* TODO setup this based on STA listen interval and
2159 beacon interval. Currently we don't know
2160 sta->listen_interval - mac80211 patch required.
2161 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002162 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002163 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2164 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002165 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002166 ath10k_warn(ar, "failed to set ap ps peer param ageout time 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 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002171
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002172 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173}
2174
2175static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002176 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002177 struct ieee80211_sta *sta,
2178 struct wmi_peer_assoc_complete_arg *arg)
2179{
2180 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002181 struct cfg80211_chan_def def;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002182 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183
Michal Kazior500ff9f2015-03-31 10:26:21 +00002184 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2185 return;
2186
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187 if (!vht_cap->vht_supported)
2188 return;
2189
2190 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002191
Michal Kazior500ff9f2015-03-31 10:26:21 +00002192 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002193 arg->peer_flags |= WMI_PEER_VHT_2G;
2194
Kalle Valo5e3dd152013-06-12 20:52:10 +03002195 arg->peer_vht_caps = vht_cap->cap;
2196
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002197 ampdu_factor = (vht_cap->cap &
2198 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2199 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2200
2201 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2202 * zero in VHT IE. Using it would result in degraded throughput.
2203 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2204 * it if VHT max_mpdu is smaller. */
2205 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2206 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2207 ampdu_factor)) - 1);
2208
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2210 arg->peer_flags |= WMI_PEER_80MHZ;
2211
2212 arg->peer_vht_rates.rx_max_rate =
2213 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2214 arg->peer_vht_rates.rx_mcs_set =
2215 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2216 arg->peer_vht_rates.tx_max_rate =
2217 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2218 arg->peer_vht_rates.tx_mcs_set =
2219 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2220
Michal Kazior7aa7a722014-08-25 12:09:38 +02002221 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002222 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223}
2224
2225static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002226 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002227 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002228 struct wmi_peer_assoc_complete_arg *arg)
2229{
Michal Kazior590922a2014-10-21 10:10:29 +03002230 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2231
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232 switch (arvif->vdev_type) {
2233 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002234 if (sta->wme)
2235 arg->peer_flags |= WMI_PEER_QOS;
2236
2237 if (sta->wme && sta->uapsd_queues) {
2238 arg->peer_flags |= WMI_PEER_APSD;
2239 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2240 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002241 break;
2242 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002243 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002244 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002245 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002246 case WMI_VDEV_TYPE_IBSS:
2247 if (sta->wme)
2248 arg->peer_flags |= WMI_PEER_QOS;
2249 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002250 default:
2251 break;
2252 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002253
2254 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2255 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002256}
2257
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002258static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002259{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002260 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2261 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002262}
2263
Kalle Valo5e3dd152013-06-12 20:52:10 +03002264static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002265 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002266 struct ieee80211_sta *sta,
2267 struct wmi_peer_assoc_complete_arg *arg)
2268{
Michal Kazior500ff9f2015-03-31 10:26:21 +00002269 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002270 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2271
Michal Kazior500ff9f2015-03-31 10:26:21 +00002272 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2273 return;
2274
2275 switch (def.chan->band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002277 if (sta->vht_cap.vht_supported) {
2278 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2279 phymode = MODE_11AC_VHT40;
2280 else
2281 phymode = MODE_11AC_VHT20;
2282 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2284 phymode = MODE_11NG_HT40;
2285 else
2286 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002287 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002288 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002289 } else {
2290 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 }
2292
2293 break;
2294 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002295 /*
2296 * Check VHT first.
2297 */
2298 if (sta->vht_cap.vht_supported) {
2299 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2300 phymode = MODE_11AC_VHT80;
2301 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2302 phymode = MODE_11AC_VHT40;
2303 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2304 phymode = MODE_11AC_VHT20;
2305 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2307 phymode = MODE_11NA_HT40;
2308 else
2309 phymode = MODE_11NA_HT20;
2310 } else {
2311 phymode = MODE_11A;
2312 }
2313
2314 break;
2315 default:
2316 break;
2317 }
2318
Michal Kazior7aa7a722014-08-25 12:09:38 +02002319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002320 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002321
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322 arg->peer_phymode = phymode;
2323 WARN_ON(phymode == MODE_UNKNOWN);
2324}
2325
Kalle Valob9ada652013-10-16 15:44:46 +03002326static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002327 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002328 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002329 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002330{
Michal Kazior548db542013-07-05 16:15:15 +03002331 lockdep_assert_held(&ar->conf_mutex);
2332
Kalle Valob9ada652013-10-16 15:44:46 +03002333 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334
Michal Kazior590922a2014-10-21 10:10:29 +03002335 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2336 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002337 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002338 ath10k_peer_assoc_h_ht(ar, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002339 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002340 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2341 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002342
Kalle Valob9ada652013-10-16 15:44:46 +03002343 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344}
2345
Michal Kazior90046f52014-02-14 14:45:51 +01002346static const u32 ath10k_smps_map[] = {
2347 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2348 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2349 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2350 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2351};
2352
2353static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2354 const u8 *addr,
2355 const struct ieee80211_sta_ht_cap *ht_cap)
2356{
2357 int smps;
2358
2359 if (!ht_cap->ht_supported)
2360 return 0;
2361
2362 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2363 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2364
2365 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2366 return -EINVAL;
2367
2368 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2369 WMI_PEER_SMPS_STATE,
2370 ath10k_smps_map[smps]);
2371}
2372
Michal Kazior139e1702015-02-15 16:50:42 +02002373static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2374 struct ieee80211_vif *vif,
2375 struct ieee80211_sta_vht_cap vht_cap)
2376{
2377 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2378 int ret;
2379 u32 param;
2380 u32 value;
2381
2382 if (!(ar->vht_cap_info &
2383 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2384 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2385 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2386 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2387 return 0;
2388
2389 param = ar->wmi.vdev_param->txbf;
2390 value = 0;
2391
2392 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2393 return 0;
2394
2395 /* The following logic is correct. If a remote STA advertises support
2396 * for being a beamformer then we should enable us being a beamformee.
2397 */
2398
2399 if (ar->vht_cap_info &
2400 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2401 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2402 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2403 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2404
2405 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2406 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2407 }
2408
2409 if (ar->vht_cap_info &
2410 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2411 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2412 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2413 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2414
2415 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2416 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2417 }
2418
2419 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2420 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2421
2422 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2423 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2424
2425 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2426 if (ret) {
2427 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2428 value, ret);
2429 return ret;
2430 }
2431
2432 return 0;
2433}
2434
Kalle Valo5e3dd152013-06-12 20:52:10 +03002435/* can be called only in mac80211 callbacks due to `key_count` usage */
2436static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2437 struct ieee80211_vif *vif,
2438 struct ieee80211_bss_conf *bss_conf)
2439{
2440 struct ath10k *ar = hw->priv;
2441 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002442 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002443 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002444 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445 struct ieee80211_sta *ap_sta;
2446 int ret;
2447
Michal Kazior548db542013-07-05 16:15:15 +03002448 lockdep_assert_held(&ar->conf_mutex);
2449
Michal Kazior077efc82014-10-21 10:10:29 +03002450 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2451 arvif->vdev_id, arvif->bssid, arvif->aid);
2452
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453 rcu_read_lock();
2454
2455 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2456 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002457 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002458 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 rcu_read_unlock();
2460 return;
2461 }
2462
Michal Kazior90046f52014-02-14 14:45:51 +01002463 /* ap_sta must be accessed only within rcu section which must be left
2464 * before calling ath10k_setup_peer_smps() which might sleep. */
2465 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002466 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002467
Michal Kazior590922a2014-10-21 10:10:29 +03002468 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002469 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002470 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002471 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 rcu_read_unlock();
2473 return;
2474 }
2475
2476 rcu_read_unlock();
2477
Kalle Valob9ada652013-10-16 15:44:46 +03002478 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2479 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002480 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002481 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002482 return;
2483 }
2484
Michal Kazior90046f52014-02-14 14:45:51 +01002485 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2486 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002487 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002488 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002489 return;
2490 }
2491
Michal Kazior139e1702015-02-15 16:50:42 +02002492 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2493 if (ret) {
2494 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2495 arvif->vdev_id, bss_conf->bssid, ret);
2496 return;
2497 }
2498
Michal Kazior7aa7a722014-08-25 12:09:38 +02002499 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002500 "mac vdev %d up (associated) bssid %pM aid %d\n",
2501 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2502
Michal Kazior077efc82014-10-21 10:10:29 +03002503 WARN_ON(arvif->is_up);
2504
Michal Kaziorc930f742014-01-23 11:38:25 +01002505 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002506 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002507
2508 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2509 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002510 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002511 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002512 return;
2513 }
2514
2515 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002516
2517 /* Workaround: Some firmware revisions (tested with qca6174
2518 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2519 * poked with peer param command.
2520 */
2521 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2522 WMI_PEER_DUMMY_VAR, 1);
2523 if (ret) {
2524 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2525 arvif->bssid, arvif->vdev_id, ret);
2526 return;
2527 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528}
2529
Kalle Valo5e3dd152013-06-12 20:52:10 +03002530static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2531 struct ieee80211_vif *vif)
2532{
2533 struct ath10k *ar = hw->priv;
2534 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002535 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002536 int ret;
2537
Michal Kazior548db542013-07-05 16:15:15 +03002538 lockdep_assert_held(&ar->conf_mutex);
2539
Michal Kazior077efc82014-10-21 10:10:29 +03002540 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2541 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002542
Kalle Valo5e3dd152013-06-12 20:52:10 +03002543 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002544 if (ret)
2545 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2546 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002547
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002548 arvif->def_wep_key_idx = -1;
2549
Michal Kazior139e1702015-02-15 16:50:42 +02002550 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2551 if (ret) {
2552 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2553 arvif->vdev_id, ret);
2554 return;
2555 }
2556
Michal Kaziorc930f742014-01-23 11:38:25 +01002557 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002558
2559 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002560}
2561
Michal Kazior590922a2014-10-21 10:10:29 +03002562static int ath10k_station_assoc(struct ath10k *ar,
2563 struct ieee80211_vif *vif,
2564 struct ieee80211_sta *sta,
2565 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002566{
Michal Kazior590922a2014-10-21 10:10:29 +03002567 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002568 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002569 int ret = 0;
2570
Michal Kazior548db542013-07-05 16:15:15 +03002571 lockdep_assert_held(&ar->conf_mutex);
2572
Michal Kazior590922a2014-10-21 10:10:29 +03002573 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002575 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002576 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002577 return ret;
2578 }
2579
2580 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2581 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002582 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002583 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 return ret;
2585 }
2586
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002587 /* Re-assoc is run only to update supported rates for given station. It
2588 * doesn't make much sense to reconfigure the peer completely.
2589 */
2590 if (!reassoc) {
2591 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2592 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002593 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002594 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002595 arvif->vdev_id, ret);
2596 return ret;
2597 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002598
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002599 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2600 if (ret) {
2601 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2602 sta->addr, arvif->vdev_id, ret);
2603 return ret;
2604 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002605
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002606 if (!sta->wme) {
2607 arvif->num_legacy_stations++;
2608 ret = ath10k_recalc_rtscts_prot(arvif);
2609 if (ret) {
2610 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2611 arvif->vdev_id, ret);
2612 return ret;
2613 }
2614 }
2615
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002616 /* Plumb cached keys only for static WEP */
2617 if (arvif->def_wep_key_idx != -1) {
2618 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2619 if (ret) {
2620 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2621 arvif->vdev_id, ret);
2622 return ret;
2623 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624 }
2625 }
2626
Kalle Valo5e3dd152013-06-12 20:52:10 +03002627 return ret;
2628}
2629
Michal Kazior590922a2014-10-21 10:10:29 +03002630static int ath10k_station_disassoc(struct ath10k *ar,
2631 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002632 struct ieee80211_sta *sta)
2633{
Michal Kazior590922a2014-10-21 10:10:29 +03002634 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002635 int ret = 0;
2636
2637 lockdep_assert_held(&ar->conf_mutex);
2638
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002639 if (!sta->wme) {
2640 arvif->num_legacy_stations--;
2641 ret = ath10k_recalc_rtscts_prot(arvif);
2642 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002643 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002644 arvif->vdev_id, ret);
2645 return ret;
2646 }
2647 }
2648
Kalle Valo5e3dd152013-06-12 20:52:10 +03002649 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2650 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002651 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002652 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002653 return ret;
2654 }
2655
2656 return ret;
2657}
2658
2659/**************/
2660/* Regulatory */
2661/**************/
2662
2663static int ath10k_update_channel_list(struct ath10k *ar)
2664{
2665 struct ieee80211_hw *hw = ar->hw;
2666 struct ieee80211_supported_band **bands;
2667 enum ieee80211_band band;
2668 struct ieee80211_channel *channel;
2669 struct wmi_scan_chan_list_arg arg = {0};
2670 struct wmi_channel_arg *ch;
2671 bool passive;
2672 int len;
2673 int ret;
2674 int i;
2675
Michal Kazior548db542013-07-05 16:15:15 +03002676 lockdep_assert_held(&ar->conf_mutex);
2677
Kalle Valo5e3dd152013-06-12 20:52:10 +03002678 bands = hw->wiphy->bands;
2679 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2680 if (!bands[band])
2681 continue;
2682
2683 for (i = 0; i < bands[band]->n_channels; i++) {
2684 if (bands[band]->channels[i].flags &
2685 IEEE80211_CHAN_DISABLED)
2686 continue;
2687
2688 arg.n_channels++;
2689 }
2690 }
2691
2692 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2693 arg.channels = kzalloc(len, GFP_KERNEL);
2694 if (!arg.channels)
2695 return -ENOMEM;
2696
2697 ch = arg.channels;
2698 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2699 if (!bands[band])
2700 continue;
2701
2702 for (i = 0; i < bands[band]->n_channels; i++) {
2703 channel = &bands[band]->channels[i];
2704
2705 if (channel->flags & IEEE80211_CHAN_DISABLED)
2706 continue;
2707
2708 ch->allow_ht = true;
2709
2710 /* FIXME: when should we really allow VHT? */
2711 ch->allow_vht = true;
2712
2713 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002714 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002715
2716 ch->ht40plus =
2717 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2718
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002719 ch->chan_radar =
2720 !!(channel->flags & IEEE80211_CHAN_RADAR);
2721
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002722 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002723 ch->passive = passive;
2724
2725 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002726 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002727 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002728 ch->max_power = channel->max_power * 2;
2729 ch->max_reg_power = channel->max_reg_power * 2;
2730 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731 ch->reg_class_id = 0; /* FIXME */
2732
2733 /* FIXME: why use only legacy modes, why not any
2734 * HT/VHT modes? Would that even make any
2735 * difference? */
2736 if (channel->band == IEEE80211_BAND_2GHZ)
2737 ch->mode = MODE_11G;
2738 else
2739 ch->mode = MODE_11A;
2740
2741 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2742 continue;
2743
Michal Kazior7aa7a722014-08-25 12:09:38 +02002744 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002745 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2746 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002747 ch->freq, ch->max_power, ch->max_reg_power,
2748 ch->max_antenna_gain, ch->mode);
2749
2750 ch++;
2751 }
2752 }
2753
2754 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2755 kfree(arg.channels);
2756
2757 return ret;
2758}
2759
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002760static enum wmi_dfs_region
2761ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2762{
2763 switch (dfs_region) {
2764 case NL80211_DFS_UNSET:
2765 return WMI_UNINIT_DFS_DOMAIN;
2766 case NL80211_DFS_FCC:
2767 return WMI_FCC_DFS_DOMAIN;
2768 case NL80211_DFS_ETSI:
2769 return WMI_ETSI_DFS_DOMAIN;
2770 case NL80211_DFS_JP:
2771 return WMI_MKK4_DFS_DOMAIN;
2772 }
2773 return WMI_UNINIT_DFS_DOMAIN;
2774}
2775
Michal Kaziorf7843d72013-07-16 09:38:52 +02002776static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002777{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002780 enum wmi_dfs_region wmi_dfs_reg;
2781 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002782
Michal Kaziorf7843d72013-07-16 09:38:52 +02002783 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002784
2785 ret = ath10k_update_channel_list(ar);
2786 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002787 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002788
2789 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002790
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002791 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2792 nl_dfs_reg = ar->dfs_detector->region;
2793 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2794 } else {
2795 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2796 }
2797
Kalle Valo5e3dd152013-06-12 20:52:10 +03002798 /* Target allows setting up per-band regdomain but ath_common provides
2799 * a combined one only */
2800 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002801 regpair->reg_domain,
2802 regpair->reg_domain, /* 2ghz */
2803 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002804 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002805 regpair->reg_5ghz_ctl,
2806 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002808 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002809}
Michal Kazior548db542013-07-05 16:15:15 +03002810
Michal Kaziorf7843d72013-07-16 09:38:52 +02002811static void ath10k_reg_notifier(struct wiphy *wiphy,
2812 struct regulatory_request *request)
2813{
2814 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2815 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002816 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002817
2818 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2819
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002820 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002821 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002822 request->dfs_region);
2823 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2824 request->dfs_region);
2825 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002826 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002827 request->dfs_region);
2828 }
2829
Michal Kaziorf7843d72013-07-16 09:38:52 +02002830 mutex_lock(&ar->conf_mutex);
2831 if (ar->state == ATH10K_STATE_ON)
2832 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002833 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002834}
2835
2836/***************/
2837/* TX handlers */
2838/***************/
2839
Michal Kazior96d828d2015-03-31 10:26:23 +00002840void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2841{
2842 lockdep_assert_held(&ar->htt.tx_lock);
2843
2844 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2845 ar->tx_paused |= BIT(reason);
2846 ieee80211_stop_queues(ar->hw);
2847}
2848
2849static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2850 struct ieee80211_vif *vif)
2851{
2852 struct ath10k *ar = data;
2853 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2854
2855 if (arvif->tx_paused)
2856 return;
2857
2858 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2859}
2860
2861void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2862{
2863 lockdep_assert_held(&ar->htt.tx_lock);
2864
2865 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2866 ar->tx_paused &= ~BIT(reason);
2867
2868 if (ar->tx_paused)
2869 return;
2870
2871 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2872 IEEE80211_IFACE_ITER_RESUME_ALL,
2873 ath10k_mac_tx_unlock_iter,
2874 ar);
2875}
2876
2877void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
2878{
2879 struct ath10k *ar = arvif->ar;
2880
2881 lockdep_assert_held(&ar->htt.tx_lock);
2882
2883 WARN_ON(reason >= BITS_PER_LONG);
2884 arvif->tx_paused |= BIT(reason);
2885 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
2886}
2887
2888void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
2889{
2890 struct ath10k *ar = arvif->ar;
2891
2892 lockdep_assert_held(&ar->htt.tx_lock);
2893
2894 WARN_ON(reason >= BITS_PER_LONG);
2895 arvif->tx_paused &= ~BIT(reason);
2896
2897 if (ar->tx_paused)
2898 return;
2899
2900 if (arvif->tx_paused)
2901 return;
2902
2903 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2904}
2905
Michal Kaziorb4aa5392015-03-31 10:26:24 +00002906static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
2907 enum wmi_tlv_tx_pause_id pause_id,
2908 enum wmi_tlv_tx_pause_action action)
2909{
2910 struct ath10k *ar = arvif->ar;
2911
2912 lockdep_assert_held(&ar->htt.tx_lock);
2913
2914 switch (pause_id) {
2915 case WMI_TLV_TX_PAUSE_ID_MCC:
2916 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
2917 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
2918 case WMI_TLV_TX_PAUSE_ID_AP_PS:
2919 case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
2920 switch (action) {
2921 case WMI_TLV_TX_PAUSE_ACTION_STOP:
2922 ath10k_mac_vif_tx_lock(arvif, pause_id);
2923 break;
2924 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
2925 ath10k_mac_vif_tx_unlock(arvif, pause_id);
2926 break;
2927 default:
2928 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
2929 action, arvif->vdev_id);
2930 break;
2931 }
2932 break;
2933 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
2934 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
2935 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
2936 case WMI_TLV_TX_PAUSE_ID_HOST:
2937 default:
2938 /* FIXME: Some pause_ids aren't vdev specific. Instead they
2939 * target peer_id and tid. Implementing these could improve
2940 * traffic scheduling fairness across multiple connected
2941 * stations in AP/IBSS modes.
2942 */
2943 ath10k_dbg(ar, ATH10K_DBG_MAC,
2944 "mac ignoring unsupported tx pause vdev %i id %d\n",
2945 arvif->vdev_id, pause_id);
2946 break;
2947 }
2948}
2949
2950struct ath10k_mac_tx_pause {
2951 u32 vdev_id;
2952 enum wmi_tlv_tx_pause_id pause_id;
2953 enum wmi_tlv_tx_pause_action action;
2954};
2955
2956static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
2957 struct ieee80211_vif *vif)
2958{
2959 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2960 struct ath10k_mac_tx_pause *arg = data;
2961
2962 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
2963}
2964
2965void ath10k_mac_handle_tx_pause(struct ath10k *ar, u32 vdev_id,
2966 enum wmi_tlv_tx_pause_id pause_id,
2967 enum wmi_tlv_tx_pause_action action)
2968{
2969 struct ath10k_mac_tx_pause arg = {
2970 .vdev_id = vdev_id,
2971 .pause_id = pause_id,
2972 .action = action,
2973 };
2974
2975 spin_lock_bh(&ar->htt.tx_lock);
2976 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2977 IEEE80211_IFACE_ITER_RESUME_ALL,
2978 ath10k_mac_handle_tx_pause_iter,
2979 &arg);
2980 spin_unlock_bh(&ar->htt.tx_lock);
2981}
2982
Michal Kazior42c3aa62013-10-02 11:03:38 +02002983static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2984{
2985 if (ieee80211_is_mgmt(hdr->frame_control))
2986 return HTT_DATA_TX_EXT_TID_MGMT;
2987
2988 if (!ieee80211_is_data_qos(hdr->frame_control))
2989 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2990
2991 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2992 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2993
2994 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2995}
2996
Michal Kazior2b37c292014-09-02 11:00:22 +03002997static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002998{
Michal Kazior2b37c292014-09-02 11:00:22 +03002999 if (vif)
3000 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003001
Michal Kazior1bbc0972014-04-08 09:45:47 +03003002 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003003 return ar->monitor_vdev_id;
3004
Michal Kazior7aa7a722014-08-25 12:09:38 +02003005 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003006 return 0;
3007}
3008
Michal Kaziord740d8f2015-03-30 09:51:51 +03003009static enum ath10k_hw_txrx_mode
3010ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003011 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003012{
3013 const struct ieee80211_hdr *hdr = (void *)skb->data;
3014 __le16 fc = hdr->frame_control;
3015
3016 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3017 return ATH10K_HW_TXRX_RAW;
3018
3019 if (ieee80211_is_mgmt(fc))
3020 return ATH10K_HW_TXRX_MGMT;
3021
3022 /* Workaround:
3023 *
3024 * NullFunc frames are mostly used to ping if a client or AP are still
3025 * reachable and responsive. This implies tx status reports must be
3026 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3027 * come to a conclusion that the other end disappeared and tear down
3028 * BSS connection or it can never disconnect from BSS/client (which is
3029 * the case).
3030 *
3031 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3032 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3033 * which seems to deliver correct tx reports for NullFunc frames. The
3034 * downside of using it is it ignores client powersave state so it can
3035 * end up disconnecting sleeping clients in AP mode. It should fix STA
3036 * mode though because AP don't sleep.
3037 */
3038 if (ar->htt.target_version_major < 3 &&
3039 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3040 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3041 return ATH10K_HW_TXRX_MGMT;
3042
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003043 /* Workaround:
3044 *
3045 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3046 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3047 * to work with Ethernet txmode so use it.
3048 */
3049 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3050 return ATH10K_HW_TXRX_ETHERNET;
3051
Michal Kaziord740d8f2015-03-30 09:51:51 +03003052 return ATH10K_HW_TXRX_NATIVE_WIFI;
3053}
3054
Michal Kazior4b604552014-07-21 21:03:09 +03003055/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3056 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003057 */
Michal Kazior4b604552014-07-21 21:03:09 +03003058static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003059{
3060 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003061 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003062 u8 *qos_ctl;
3063
3064 if (!ieee80211_is_data_qos(hdr->frame_control))
3065 return;
3066
3067 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003068 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3069 skb->data, (void *)qos_ctl - (void *)skb->data);
3070 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003071
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003072 /* Some firmware revisions don't handle sending QoS NullFunc well.
3073 * These frames are mainly used for CQM purposes so it doesn't really
3074 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003075 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003076 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003077 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003078 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003079
3080 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081}
3082
Michal Kaziord740d8f2015-03-30 09:51:51 +03003083static void ath10k_tx_h_8023(struct sk_buff *skb)
3084{
3085 struct ieee80211_hdr *hdr;
3086 struct rfc1042_hdr *rfc1042;
3087 struct ethhdr *eth;
3088 size_t hdrlen;
3089 u8 da[ETH_ALEN];
3090 u8 sa[ETH_ALEN];
3091 __be16 type;
3092
3093 hdr = (void *)skb->data;
3094 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3095 rfc1042 = (void *)skb->data + hdrlen;
3096
3097 ether_addr_copy(da, ieee80211_get_DA(hdr));
3098 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3099 type = rfc1042->snap_type;
3100
3101 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3102 skb_push(skb, sizeof(*eth));
3103
3104 eth = (void *)skb->data;
3105 ether_addr_copy(eth->h_dest, da);
3106 ether_addr_copy(eth->h_source, sa);
3107 eth->h_proto = type;
3108}
3109
Michal Kazior4b604552014-07-21 21:03:09 +03003110static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3111 struct ieee80211_vif *vif,
3112 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113{
3114 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3116
3117 /* This is case only for P2P_GO */
3118 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3119 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3120 return;
3121
3122 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3123 spin_lock_bh(&ar->data_lock);
3124 if (arvif->u.ap.noa_data)
3125 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3126 GFP_ATOMIC))
3127 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3128 arvif->u.ap.noa_data,
3129 arvif->u.ap.noa_len);
3130 spin_unlock_bh(&ar->data_lock);
3131 }
3132}
3133
Michal Kazior8d6d3622014-11-24 14:58:31 +01003134static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3135{
3136 /* FIXME: Not really sure since when the behaviour changed. At some
3137 * point new firmware stopped requiring creation of peer entries for
3138 * offchannel tx (and actually creating them causes issues with wmi-htc
3139 * tx credit replenishment and reliability). Assuming it's at least 3.4
3140 * because that's when the `freq` was introduced to TX_FRM HTT command.
3141 */
3142 return !(ar->htt.target_version_major >= 3 &&
3143 ar->htt.target_version_minor >= 4);
3144}
3145
Michal Kaziord740d8f2015-03-30 09:51:51 +03003146static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003147{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003148 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003149 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150
Michal Kaziord740d8f2015-03-30 09:51:51 +03003151 spin_lock_bh(&ar->data_lock);
3152
3153 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3154 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3155 ret = -ENOSPC;
3156 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003157 }
3158
Michal Kaziord740d8f2015-03-30 09:51:51 +03003159 __skb_queue_tail(q, skb);
3160 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3161
3162unlock:
3163 spin_unlock_bh(&ar->data_lock);
3164
3165 return ret;
3166}
3167
3168static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3169{
3170 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3171 struct ath10k_htt *htt = &ar->htt;
3172 int ret = 0;
3173
3174 switch (cb->txmode) {
3175 case ATH10K_HW_TXRX_RAW:
3176 case ATH10K_HW_TXRX_NATIVE_WIFI:
3177 case ATH10K_HW_TXRX_ETHERNET:
3178 ret = ath10k_htt_tx(htt, skb);
3179 break;
3180 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003181 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003182 ar->fw_features))
3183 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3184 else if (ar->htt.target_version_major >= 3)
3185 ret = ath10k_htt_tx(htt, skb);
3186 else
3187 ret = ath10k_htt_mgmt_tx(htt, skb);
3188 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003189 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190
3191 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003192 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3193 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003194 ieee80211_free_txskb(ar->hw, skb);
3195 }
3196}
3197
3198void ath10k_offchan_tx_purge(struct ath10k *ar)
3199{
3200 struct sk_buff *skb;
3201
3202 for (;;) {
3203 skb = skb_dequeue(&ar->offchan_tx_queue);
3204 if (!skb)
3205 break;
3206
3207 ieee80211_free_txskb(ar->hw, skb);
3208 }
3209}
3210
3211void ath10k_offchan_tx_work(struct work_struct *work)
3212{
3213 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3214 struct ath10k_peer *peer;
3215 struct ieee80211_hdr *hdr;
3216 struct sk_buff *skb;
3217 const u8 *peer_addr;
3218 int vdev_id;
3219 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003220 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003221
3222 /* FW requirement: We must create a peer before FW will send out
3223 * an offchannel frame. Otherwise the frame will be stuck and
3224 * never transmitted. We delete the peer upon tx completion.
3225 * It is unlikely that a peer for offchannel tx will already be
3226 * present. However it may be in some rare cases so account for that.
3227 * Otherwise we might remove a legitimate peer and break stuff. */
3228
3229 for (;;) {
3230 skb = skb_dequeue(&ar->offchan_tx_queue);
3231 if (!skb)
3232 break;
3233
3234 mutex_lock(&ar->conf_mutex);
3235
Michal Kazior7aa7a722014-08-25 12:09:38 +02003236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003237 skb);
3238
3239 hdr = (struct ieee80211_hdr *)skb->data;
3240 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003241 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242
3243 spin_lock_bh(&ar->data_lock);
3244 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3245 spin_unlock_bh(&ar->data_lock);
3246
3247 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003248 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003249 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003250 peer_addr, vdev_id);
3251
3252 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003253 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3254 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003255 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003256 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003257 peer_addr, vdev_id, ret);
3258 }
3259
3260 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003261 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003262 ar->offchan_tx_skb = skb;
3263 spin_unlock_bh(&ar->data_lock);
3264
Michal Kaziord740d8f2015-03-30 09:51:51 +03003265 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003266
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003267 time_left =
3268 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3269 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003270 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 skb);
3272
3273 if (!peer) {
3274 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3275 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003276 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003277 peer_addr, vdev_id, ret);
3278 }
3279
3280 mutex_unlock(&ar->conf_mutex);
3281 }
3282}
3283
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003284void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3285{
3286 struct sk_buff *skb;
3287
3288 for (;;) {
3289 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3290 if (!skb)
3291 break;
3292
3293 ieee80211_free_txskb(ar->hw, skb);
3294 }
3295}
3296
3297void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3298{
3299 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3300 struct sk_buff *skb;
3301 int ret;
3302
3303 for (;;) {
3304 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3305 if (!skb)
3306 break;
3307
3308 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003309 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003310 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003311 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003312 ieee80211_free_txskb(ar->hw, skb);
3313 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003314 }
3315}
3316
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317/************/
3318/* Scanning */
3319/************/
3320
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003321void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003322{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003323 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003324
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003325 switch (ar->scan.state) {
3326 case ATH10K_SCAN_IDLE:
3327 break;
3328 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003329 if (ar->scan.is_roc)
3330 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003331 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003332 case ATH10K_SCAN_ABORTING:
3333 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003334 ieee80211_scan_completed(ar->hw,
3335 (ar->scan.state ==
3336 ATH10K_SCAN_ABORTING));
3337 /* fall through */
3338 case ATH10K_SCAN_STARTING:
3339 ar->scan.state = ATH10K_SCAN_IDLE;
3340 ar->scan_channel = NULL;
3341 ath10k_offchan_tx_purge(ar);
3342 cancel_delayed_work(&ar->scan.timeout);
3343 complete_all(&ar->scan.completed);
3344 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003345 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003346}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003347
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003348void ath10k_scan_finish(struct ath10k *ar)
3349{
3350 spin_lock_bh(&ar->data_lock);
3351 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003352 spin_unlock_bh(&ar->data_lock);
3353}
3354
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003355static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003356{
3357 struct wmi_stop_scan_arg arg = {
3358 .req_id = 1, /* FIXME */
3359 .req_type = WMI_SCAN_STOP_ONE,
3360 .u.scan_id = ATH10K_SCAN_ID,
3361 };
3362 int ret;
3363
3364 lockdep_assert_held(&ar->conf_mutex);
3365
Kalle Valo5e3dd152013-06-12 20:52:10 +03003366 ret = ath10k_wmi_stop_scan(ar, &arg);
3367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003368 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003369 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003370 }
3371
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003373 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003374 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003375 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003376 } else if (ret > 0) {
3377 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003378 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003379
3380out:
3381 /* Scan state should be updated upon scan completion but in case
3382 * firmware fails to deliver the event (for whatever reason) it is
3383 * desired to clean up scan state anyway. Firmware may have just
3384 * dropped the scan completion event delivery due to transport pipe
3385 * being overflown with data and/or it can recover on its own before
3386 * next scan request is submitted.
3387 */
3388 spin_lock_bh(&ar->data_lock);
3389 if (ar->scan.state != ATH10K_SCAN_IDLE)
3390 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 spin_unlock_bh(&ar->data_lock);
3392
3393 return ret;
3394}
3395
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003396static void ath10k_scan_abort(struct ath10k *ar)
3397{
3398 int ret;
3399
3400 lockdep_assert_held(&ar->conf_mutex);
3401
3402 spin_lock_bh(&ar->data_lock);
3403
3404 switch (ar->scan.state) {
3405 case ATH10K_SCAN_IDLE:
3406 /* This can happen if timeout worker kicked in and called
3407 * abortion while scan completion was being processed.
3408 */
3409 break;
3410 case ATH10K_SCAN_STARTING:
3411 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003412 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003413 ath10k_scan_state_str(ar->scan.state),
3414 ar->scan.state);
3415 break;
3416 case ATH10K_SCAN_RUNNING:
3417 ar->scan.state = ATH10K_SCAN_ABORTING;
3418 spin_unlock_bh(&ar->data_lock);
3419
3420 ret = ath10k_scan_stop(ar);
3421 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003422 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003423
3424 spin_lock_bh(&ar->data_lock);
3425 break;
3426 }
3427
3428 spin_unlock_bh(&ar->data_lock);
3429}
3430
3431void ath10k_scan_timeout_work(struct work_struct *work)
3432{
3433 struct ath10k *ar = container_of(work, struct ath10k,
3434 scan.timeout.work);
3435
3436 mutex_lock(&ar->conf_mutex);
3437 ath10k_scan_abort(ar);
3438 mutex_unlock(&ar->conf_mutex);
3439}
3440
Kalle Valo5e3dd152013-06-12 20:52:10 +03003441static int ath10k_start_scan(struct ath10k *ar,
3442 const struct wmi_start_scan_arg *arg)
3443{
3444 int ret;
3445
3446 lockdep_assert_held(&ar->conf_mutex);
3447
3448 ret = ath10k_wmi_start_scan(ar, arg);
3449 if (ret)
3450 return ret;
3451
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3453 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003454 ret = ath10k_scan_stop(ar);
3455 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003456 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003457
3458 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003459 }
3460
Ben Greear2f9eec02015-02-15 16:50:38 +02003461 /* If we failed to start the scan, return error code at
3462 * this point. This is probably due to some issue in the
3463 * firmware, but no need to wedge the driver due to that...
3464 */
3465 spin_lock_bh(&ar->data_lock);
3466 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3467 spin_unlock_bh(&ar->data_lock);
3468 return -EINVAL;
3469 }
3470 spin_unlock_bh(&ar->data_lock);
3471
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003472 /* Add a 200ms margin to account for event/command processing */
3473 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3474 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475 return 0;
3476}
3477
3478/**********************/
3479/* mac80211 callbacks */
3480/**********************/
3481
3482static void ath10k_tx(struct ieee80211_hw *hw,
3483 struct ieee80211_tx_control *control,
3484 struct sk_buff *skb)
3485{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003486 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003487 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3488 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003489 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003490 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003491 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003492
3493 /* We should disable CCK RATE due to P2P */
3494 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003495 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003496
Michal Kazior4b604552014-07-21 21:03:09 +03003497 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003498 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003499 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003500 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003501 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003502 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503
Michal Kaziord740d8f2015-03-30 09:51:51 +03003504 switch (ATH10K_SKB_CB(skb)->txmode) {
3505 case ATH10K_HW_TXRX_MGMT:
3506 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003507 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003508 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3509 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003510 break;
3511 case ATH10K_HW_TXRX_ETHERNET:
3512 ath10k_tx_h_8023(skb);
3513 break;
3514 case ATH10K_HW_TXRX_RAW:
3515 /* FIXME: Packet injection isn't implemented. It should be
3516 * doable with firmware 10.2 on qca988x.
3517 */
3518 WARN_ON_ONCE(1);
3519 ieee80211_free_txskb(hw, skb);
3520 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003521 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003522
Kalle Valo5e3dd152013-06-12 20:52:10 +03003523 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3524 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003525 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003526 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003527 spin_unlock_bh(&ar->data_lock);
3528
Michal Kazior8d6d3622014-11-24 14:58:31 +01003529 if (ath10k_mac_need_offchan_tx_work(ar)) {
3530 ATH10K_SKB_CB(skb)->htt.freq = 0;
3531 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003532
Michal Kazior8d6d3622014-11-24 14:58:31 +01003533 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3534 skb);
3535
3536 skb_queue_tail(&ar->offchan_tx_queue, skb);
3537 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3538 return;
3539 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540 }
3541
Michal Kaziord740d8f2015-03-30 09:51:51 +03003542 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543}
3544
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003545/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003546void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003547{
3548 /* make sure rcu-protected mac80211 tx path itself is drained */
3549 synchronize_net();
3550
3551 ath10k_offchan_tx_purge(ar);
3552 ath10k_mgmt_over_wmi_tx_purge(ar);
3553
3554 cancel_work_sync(&ar->offchan_tx_work);
3555 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3556}
3557
Michal Kazioraffd3212013-07-16 09:54:35 +02003558void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003559{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003560 struct ath10k_vif *arvif;
3561
Michal Kazior818bdd12013-07-16 09:38:57 +02003562 lockdep_assert_held(&ar->conf_mutex);
3563
Michal Kazior19337472014-08-28 12:58:16 +02003564 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3565 ar->filter_flags = 0;
3566 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003567 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003568
3569 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003570 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003571
3572 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003573 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003574
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003575 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003576 ath10k_peer_cleanup_all(ar);
3577 ath10k_core_stop(ar);
3578 ath10k_hif_power_down(ar);
3579
3580 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003581 list_for_each_entry(arvif, &ar->arvifs, list)
3582 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003583 spin_unlock_bh(&ar->data_lock);
3584}
3585
Ben Greear46acf7b2014-05-16 17:15:38 +03003586static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3587{
3588 struct ath10k *ar = hw->priv;
3589
3590 mutex_lock(&ar->conf_mutex);
3591
3592 if (ar->cfg_tx_chainmask) {
3593 *tx_ant = ar->cfg_tx_chainmask;
3594 *rx_ant = ar->cfg_rx_chainmask;
3595 } else {
3596 *tx_ant = ar->supp_tx_chainmask;
3597 *rx_ant = ar->supp_rx_chainmask;
3598 }
3599
3600 mutex_unlock(&ar->conf_mutex);
3601
3602 return 0;
3603}
3604
Ben Greear5572a952014-11-24 16:22:10 +02003605static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3606{
3607 /* It is not clear that allowing gaps in chainmask
3608 * is helpful. Probably it will not do what user
3609 * is hoping for, so warn in that case.
3610 */
3611 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3612 return;
3613
3614 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3615 dbg, cm);
3616}
3617
Ben Greear46acf7b2014-05-16 17:15:38 +03003618static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3619{
3620 int ret;
3621
3622 lockdep_assert_held(&ar->conf_mutex);
3623
Ben Greear5572a952014-11-24 16:22:10 +02003624 ath10k_check_chain_mask(ar, tx_ant, "tx");
3625 ath10k_check_chain_mask(ar, rx_ant, "rx");
3626
Ben Greear46acf7b2014-05-16 17:15:38 +03003627 ar->cfg_tx_chainmask = tx_ant;
3628 ar->cfg_rx_chainmask = rx_ant;
3629
3630 if ((ar->state != ATH10K_STATE_ON) &&
3631 (ar->state != ATH10K_STATE_RESTARTED))
3632 return 0;
3633
3634 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3635 tx_ant);
3636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003637 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003638 ret, tx_ant);
3639 return ret;
3640 }
3641
3642 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3643 rx_ant);
3644 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003645 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003646 ret, rx_ant);
3647 return ret;
3648 }
3649
3650 return 0;
3651}
3652
3653static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3654{
3655 struct ath10k *ar = hw->priv;
3656 int ret;
3657
3658 mutex_lock(&ar->conf_mutex);
3659 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3660 mutex_unlock(&ar->conf_mutex);
3661 return ret;
3662}
3663
Kalle Valo5e3dd152013-06-12 20:52:10 +03003664static int ath10k_start(struct ieee80211_hw *hw)
3665{
3666 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003667 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003668 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003670 /*
3671 * This makes sense only when restarting hw. It is harmless to call
3672 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3673 * commands will be submitted while restarting.
3674 */
3675 ath10k_drain_tx(ar);
3676
Michal Kazior548db542013-07-05 16:15:15 +03003677 mutex_lock(&ar->conf_mutex);
3678
Michal Kaziorc5058f52014-05-26 12:46:03 +03003679 switch (ar->state) {
3680 case ATH10K_STATE_OFF:
3681 ar->state = ATH10K_STATE_ON;
3682 break;
3683 case ATH10K_STATE_RESTARTING:
3684 ath10k_halt(ar);
3685 ar->state = ATH10K_STATE_RESTARTED;
3686 break;
3687 case ATH10K_STATE_ON:
3688 case ATH10K_STATE_RESTARTED:
3689 case ATH10K_STATE_WEDGED:
3690 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003691 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003692 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003693 case ATH10K_STATE_UTF:
3694 ret = -EBUSY;
3695 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003696 }
3697
3698 ret = ath10k_hif_power_up(ar);
3699 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003700 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003701 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003702 }
3703
Kalle Valo43d2a302014-09-10 18:23:30 +03003704 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003705 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003706 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003707 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003708 }
3709
Bartosz Markowski226a3392013-09-26 17:47:16 +02003710 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003711 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003712 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003713 goto err_core_stop;
3714 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003716 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003717 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003718 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003719 goto err_core_stop;
3720 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003721
Michal Kaziorcf327842015-03-31 10:26:25 +00003722 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3723 ret = ath10k_wmi_adaptive_qcs(ar, true);
3724 if (ret) {
3725 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3726 ret);
3727 goto err_core_stop;
3728 }
3729 }
3730
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003731 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3732 burst_enable = ar->wmi.pdev_param->burst_enable;
3733 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3734 if (ret) {
3735 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3736 goto err_core_stop;
3737 }
3738 }
3739
Ben Greear46acf7b2014-05-16 17:15:38 +03003740 if (ar->cfg_tx_chainmask)
3741 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3742 ar->cfg_rx_chainmask);
3743
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003744 /*
3745 * By default FW set ARP frames ac to voice (6). In that case ARP
3746 * exchange is not working properly for UAPSD enabled AP. ARP requests
3747 * which arrives with access category 0 are processed by network stack
3748 * and send back with access category 0, but FW changes access category
3749 * to 6. Set ARP frames access category to best effort (0) solves
3750 * this problem.
3751 */
3752
3753 ret = ath10k_wmi_pdev_set_param(ar,
3754 ar->wmi.pdev_param->arp_ac_override, 0);
3755 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003756 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003757 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003758 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003759 }
3760
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303761 ret = ath10k_wmi_pdev_set_param(ar,
3762 ar->wmi.pdev_param->ani_enable, 1);
3763 if (ret) {
3764 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3765 ret);
3766 goto err_core_stop;
3767 }
3768
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303769 ar->ani_enabled = true;
3770
Michal Kaziord6500972014-04-08 09:56:09 +03003771 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003772 ath10k_regd_update(ar);
3773
Simon Wunderlich855aed12014-08-02 09:12:54 +03003774 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303775 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003776
Michal Kaziorae254432014-05-26 12:46:02 +03003777 mutex_unlock(&ar->conf_mutex);
3778 return 0;
3779
3780err_core_stop:
3781 ath10k_core_stop(ar);
3782
3783err_power_down:
3784 ath10k_hif_power_down(ar);
3785
3786err_off:
3787 ar->state = ATH10K_STATE_OFF;
3788
3789err:
Michal Kazior548db542013-07-05 16:15:15 +03003790 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003791 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003792}
3793
3794static void ath10k_stop(struct ieee80211_hw *hw)
3795{
3796 struct ath10k *ar = hw->priv;
3797
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003798 ath10k_drain_tx(ar);
3799
Michal Kazior548db542013-07-05 16:15:15 +03003800 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003801 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003802 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003803 ar->state = ATH10K_STATE_OFF;
3804 }
Michal Kazior548db542013-07-05 16:15:15 +03003805 mutex_unlock(&ar->conf_mutex);
3806
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003807 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003808 cancel_work_sync(&ar->restart_work);
3809}
3810
Michal Kaziorad088bf2013-10-16 15:44:46 +03003811static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003812{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003813 struct ath10k_vif *arvif;
3814 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003815
3816 lockdep_assert_held(&ar->conf_mutex);
3817
Michal Kaziorad088bf2013-10-16 15:44:46 +03003818 list_for_each_entry(arvif, &ar->arvifs, list) {
3819 ret = ath10k_mac_vif_setup_ps(arvif);
3820 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003821 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003822 break;
3823 }
3824 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003825
Michal Kaziorad088bf2013-10-16 15:44:46 +03003826 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827}
3828
Michal Kazior500ff9f2015-03-31 10:26:21 +00003829static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003830{
3831 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003832 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003833 int ret;
3834
3835 lockdep_assert_held(&ar->conf_mutex);
3836
Michal Kazior500ff9f2015-03-31 10:26:21 +00003837 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003838
3839 /* First stop monitor interface. Some FW versions crash if there's a
3840 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003841 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003842 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003843
3844 list_for_each_entry(arvif, &ar->arvifs, list) {
3845 if (!arvif->is_started)
3846 continue;
3847
Michal Kaziordc55e302014-07-29 12:53:36 +03003848 if (!arvif->is_up)
3849 continue;
3850
Michal Kaziorc930f742014-01-23 11:38:25 +01003851 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3852 continue;
3853
Michal Kaziordc55e302014-07-29 12:53:36 +03003854 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003855 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003856 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003857 arvif->vdev_id, ret);
3858 continue;
3859 }
3860 }
3861
Michal Kaziordc55e302014-07-29 12:53:36 +03003862 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003863
3864 list_for_each_entry(arvif, &ar->arvifs, list) {
3865 if (!arvif->is_started)
3866 continue;
3867
3868 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3869 continue;
3870
Michal Kazior81a9a172015-03-05 16:02:17 +02003871 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3872 if (ret)
3873 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3874 ret);
3875
3876 ret = ath10k_mac_setup_prb_tmpl(arvif);
3877 if (ret)
3878 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3879 ret);
3880
Michal Kazior500ff9f2015-03-31 10:26:21 +00003881 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3882 continue;
3883
3884 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003886 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003887 arvif->vdev_id, ret);
3888 continue;
3889 }
3890
3891 if (!arvif->is_up)
3892 continue;
3893
3894 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3895 arvif->bssid);
3896 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003897 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003898 arvif->vdev_id, ret);
3899 continue;
3900 }
3901 }
3902
Michal Kazior19337472014-08-28 12:58:16 +02003903 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003904}
3905
Michal Kazior7d9d5582014-10-21 10:40:15 +03003906static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3907{
3908 int ret;
3909 u32 param;
3910
3911 lockdep_assert_held(&ar->conf_mutex);
3912
3913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3914
3915 param = ar->wmi.pdev_param->txpower_limit2g;
3916 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3917 if (ret) {
3918 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3919 txpower, ret);
3920 return ret;
3921 }
3922
3923 param = ar->wmi.pdev_param->txpower_limit5g;
3924 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3925 if (ret) {
3926 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3927 txpower, ret);
3928 return ret;
3929 }
3930
3931 return 0;
3932}
3933
3934static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3935{
3936 struct ath10k_vif *arvif;
3937 int ret, txpower = -1;
3938
3939 lockdep_assert_held(&ar->conf_mutex);
3940
3941 list_for_each_entry(arvif, &ar->arvifs, list) {
3942 WARN_ON(arvif->txpower < 0);
3943
3944 if (txpower == -1)
3945 txpower = arvif->txpower;
3946 else
3947 txpower = min(txpower, arvif->txpower);
3948 }
3949
3950 if (WARN_ON(txpower == -1))
3951 return -EINVAL;
3952
3953 ret = ath10k_mac_txpower_setup(ar, txpower);
3954 if (ret) {
3955 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3956 txpower, ret);
3957 return ret;
3958 }
3959
3960 return 0;
3961}
3962
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3964{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003965 struct ath10k *ar = hw->priv;
3966 struct ieee80211_conf *conf = &hw->conf;
3967 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003968
3969 mutex_lock(&ar->conf_mutex);
3970
Michal Kazioraffd3212013-07-16 09:54:35 +02003971 if (changed & IEEE80211_CONF_CHANGE_PS)
3972 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973
3974 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003975 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3976 ret = ath10k_monitor_recalc(ar);
3977 if (ret)
3978 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003979 }
3980
3981 mutex_unlock(&ar->conf_mutex);
3982 return ret;
3983}
3984
Ben Greear5572a952014-11-24 16:22:10 +02003985static u32 get_nss_from_chainmask(u16 chain_mask)
3986{
3987 if ((chain_mask & 0x15) == 0x15)
3988 return 4;
3989 else if ((chain_mask & 0x7) == 0x7)
3990 return 3;
3991 else if ((chain_mask & 0x3) == 0x3)
3992 return 2;
3993 return 1;
3994}
3995
Kalle Valo5e3dd152013-06-12 20:52:10 +03003996/*
3997 * TODO:
3998 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3999 * because we will send mgmt frames without CCK. This requirement
4000 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4001 * in the TX packet.
4002 */
4003static int ath10k_add_interface(struct ieee80211_hw *hw,
4004 struct ieee80211_vif *vif)
4005{
4006 struct ath10k *ar = hw->priv;
4007 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4008 enum wmi_sta_powersave_param param;
4009 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004010 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004011 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004012 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004013 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014
Johannes Berg848955c2014-11-11 12:48:42 +01004015 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4016
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017 mutex_lock(&ar->conf_mutex);
4018
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004019 memset(arvif, 0, sizeof(*arvif));
4020
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021 arvif->ar = ar;
4022 arvif->vif = vif;
4023
Ben Greeare63b33f2013-10-22 14:54:14 -07004024 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004025 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004026 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4027 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004028
Ben Greeara9aefb32014-08-12 11:02:19 +03004029 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004030 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004032 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004033 }
Ben Greear16c11172014-09-23 14:17:16 -07004034 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004035
Ben Greear16c11172014-09-23 14:17:16 -07004036 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4037 bit, ar->free_vdev_map);
4038
4039 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004040 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041
Kalle Valo5e3dd152013-06-12 20:52:10 +03004042 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004043 case NL80211_IFTYPE_P2P_DEVICE:
4044 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4045 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4046 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004047 case NL80211_IFTYPE_UNSPECIFIED:
4048 case NL80211_IFTYPE_STATION:
4049 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4050 if (vif->p2p)
4051 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4052 break;
4053 case NL80211_IFTYPE_ADHOC:
4054 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4055 break;
4056 case NL80211_IFTYPE_AP:
4057 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4058
4059 if (vif->p2p)
4060 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4061 break;
4062 case NL80211_IFTYPE_MONITOR:
4063 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4064 break;
4065 default:
4066 WARN_ON(1);
4067 break;
4068 }
4069
Michal Kazior96d828d2015-03-31 10:26:23 +00004070 /* Using vdev_id as queue number will make it very easy to do per-vif
4071 * tx queue locking. This shouldn't wrap due to interface combinations
4072 * but do a modulo for correctness sake and prevent using offchannel tx
4073 * queues for regular vif tx.
4074 */
4075 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4076 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4077 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4078
Michal Kazior64badcb2014-09-18 11:18:02 +03004079 /* Some firmware revisions don't wait for beacon tx completion before
4080 * sending another SWBA event. This could lead to hardware using old
4081 * (freed) beacon data in some cases, e.g. tx credit starvation
4082 * combined with missed TBTT. This is very very rare.
4083 *
4084 * On non-IOMMU-enabled hosts this could be a possible security issue
4085 * because hw could beacon some random data on the air. On
4086 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4087 * device would crash.
4088 *
4089 * Since there are no beacon tx completions (implicit nor explicit)
4090 * propagated to host the only workaround for this is to allocate a
4091 * DMA-coherent buffer for a lifetime of a vif and use it for all
4092 * beacon tx commands. Worst case for this approach is some beacons may
4093 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4094 */
4095 if (vif->type == NL80211_IFTYPE_ADHOC ||
4096 vif->type == NL80211_IFTYPE_AP) {
4097 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4098 IEEE80211_MAX_FRAME_LEN,
4099 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304100 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004101 if (!arvif->beacon_buf) {
4102 ret = -ENOMEM;
4103 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4104 ret);
4105 goto err;
4106 }
4107 }
4108
4109 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4110 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4111 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004112
4113 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4114 arvif->vdev_subtype, vif->addr);
4115 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004116 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004117 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004118 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004119 }
4120
Ben Greear16c11172014-09-23 14:17:16 -07004121 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004122 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004123
Michal Kazior46725b152015-01-28 09:57:49 +02004124 /* It makes no sense to have firmware do keepalives. mac80211 already
4125 * takes care of this with idle connection polling.
4126 */
4127 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004128 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004129 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004130 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004131 goto err_vdev_delete;
4132 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004133
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004134 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004135
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004136 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4137 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004138 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004139 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004140 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004141 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004142 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004143 goto err_vdev_delete;
4144 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004145
Ben Greear5572a952014-11-24 16:22:10 +02004146 if (ar->cfg_tx_chainmask) {
4147 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4148
4149 vdev_param = ar->wmi.vdev_param->nss;
4150 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4151 nss);
4152 if (ret) {
4153 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4154 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4155 ret);
4156 goto err_vdev_delete;
4157 }
4158 }
4159
Michal Kaziore57e0572015-03-24 13:14:03 +00004160 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4161 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004162 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4163 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004164 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004165 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004166 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004167 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004168 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004169 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004170
Michal Kaziore57e0572015-03-24 13:14:03 +00004171 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004172 ret = ath10k_mac_set_kickout(arvif);
4173 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004174 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004175 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004176 goto err_peer_delete;
4177 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178 }
4179
4180 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4181 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4182 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4183 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4184 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004185 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004186 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004187 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004188 goto err_peer_delete;
4189 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004190
Michal Kazior9f9b5742014-12-12 12:41:36 +01004191 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004192 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004193 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004194 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004195 goto err_peer_delete;
4196 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004197
Michal Kazior9f9b5742014-12-12 12:41:36 +01004198 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004199 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004200 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %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 }
4205
Michal Kazior424121c2013-07-22 14:13:31 +02004206 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004207 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004208 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004209 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004210 goto err_peer_delete;
4211 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004212
Michal Kazior424121c2013-07-22 14:13:31 +02004213 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004214 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004215 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004216 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004217 goto err_peer_delete;
4218 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004219
Michal Kazior7d9d5582014-10-21 10:40:15 +03004220 arvif->txpower = vif->bss_conf.txpower;
4221 ret = ath10k_mac_txpower_recalc(ar);
4222 if (ret) {
4223 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4224 goto err_peer_delete;
4225 }
4226
Michal Kazior500ff9f2015-03-31 10:26:21 +00004227 if (vif->type == NL80211_IFTYPE_MONITOR) {
4228 ar->monitor_arvif = arvif;
4229 ret = ath10k_monitor_recalc(ar);
4230 if (ret) {
4231 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4232 goto err_peer_delete;
4233 }
4234 }
4235
Kalle Valo5e3dd152013-06-12 20:52:10 +03004236 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004237 return 0;
4238
4239err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004240 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4241 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004242 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4243
4244err_vdev_delete:
4245 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004246 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004247 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004248
4249err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004250 if (arvif->beacon_buf) {
4251 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4252 arvif->beacon_buf, arvif->beacon_paddr);
4253 arvif->beacon_buf = NULL;
4254 }
4255
Michal Kazior9dad14a2013-10-16 15:44:45 +03004256 mutex_unlock(&ar->conf_mutex);
4257
Kalle Valo5e3dd152013-06-12 20:52:10 +03004258 return ret;
4259}
4260
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004261static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4262{
4263 int i;
4264
4265 for (i = 0; i < BITS_PER_LONG; i++)
4266 ath10k_mac_vif_tx_unlock(arvif, i);
4267}
4268
Kalle Valo5e3dd152013-06-12 20:52:10 +03004269static void ath10k_remove_interface(struct ieee80211_hw *hw,
4270 struct ieee80211_vif *vif)
4271{
4272 struct ath10k *ar = hw->priv;
4273 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4274 int ret;
4275
Michal Kazior81a9a172015-03-05 16:02:17 +02004276 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004277 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004278
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304279 mutex_lock(&ar->conf_mutex);
4280
Michal Kaziored543882013-09-13 14:16:56 +02004281 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004282 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004283 spin_unlock_bh(&ar->data_lock);
4284
Simon Wunderlich855aed12014-08-02 09:12:54 +03004285 ret = ath10k_spectral_vif_stop(arvif);
4286 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004287 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004288 arvif->vdev_id, ret);
4289
Ben Greear16c11172014-09-23 14:17:16 -07004290 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004291 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292
Michal Kaziore57e0572015-03-24 13:14:03 +00004293 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4294 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004295 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4296 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004297 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004298 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004299 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004300
4301 kfree(arvif->u.ap.noa_data);
4302 }
4303
Michal Kazior7aa7a722014-08-25 12:09:38 +02004304 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004305 arvif->vdev_id);
4306
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4308 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004309 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004310 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004311
Michal Kazior2c512052015-02-15 16:50:40 +02004312 /* Some firmware revisions don't notify host about self-peer removal
4313 * until after associated vdev is deleted.
4314 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004315 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4316 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004317 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4318 vif->addr);
4319 if (ret)
4320 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4321 arvif->vdev_id, ret);
4322
4323 spin_lock_bh(&ar->data_lock);
4324 ar->num_peers--;
4325 spin_unlock_bh(&ar->data_lock);
4326 }
4327
Kalle Valo5e3dd152013-06-12 20:52:10 +03004328 ath10k_peer_cleanup(ar, arvif->vdev_id);
4329
Michal Kazior500ff9f2015-03-31 10:26:21 +00004330 if (vif->type == NL80211_IFTYPE_MONITOR) {
4331 ar->monitor_arvif = NULL;
4332 ret = ath10k_monitor_recalc(ar);
4333 if (ret)
4334 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4335 }
4336
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004337 spin_lock_bh(&ar->htt.tx_lock);
4338 ath10k_mac_vif_tx_unlock_all(arvif);
4339 spin_unlock_bh(&ar->htt.tx_lock);
4340
Kalle Valo5e3dd152013-06-12 20:52:10 +03004341 mutex_unlock(&ar->conf_mutex);
4342}
4343
4344/*
4345 * FIXME: Has to be verified.
4346 */
4347#define SUPPORTED_FILTERS \
4348 (FIF_PROMISC_IN_BSS | \
4349 FIF_ALLMULTI | \
4350 FIF_CONTROL | \
4351 FIF_PSPOLL | \
4352 FIF_OTHER_BSS | \
4353 FIF_BCN_PRBRESP_PROMISC | \
4354 FIF_PROBE_REQ | \
4355 FIF_FCSFAIL)
4356
4357static void ath10k_configure_filter(struct ieee80211_hw *hw,
4358 unsigned int changed_flags,
4359 unsigned int *total_flags,
4360 u64 multicast)
4361{
4362 struct ath10k *ar = hw->priv;
4363 int ret;
4364
4365 mutex_lock(&ar->conf_mutex);
4366
4367 changed_flags &= SUPPORTED_FILTERS;
4368 *total_flags &= SUPPORTED_FILTERS;
4369 ar->filter_flags = *total_flags;
4370
Michal Kazior19337472014-08-28 12:58:16 +02004371 ret = ath10k_monitor_recalc(ar);
4372 if (ret)
4373 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004374
4375 mutex_unlock(&ar->conf_mutex);
4376}
4377
4378static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4379 struct ieee80211_vif *vif,
4380 struct ieee80211_bss_conf *info,
4381 u32 changed)
4382{
4383 struct ath10k *ar = hw->priv;
4384 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4385 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004386 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004387
4388 mutex_lock(&ar->conf_mutex);
4389
4390 if (changed & BSS_CHANGED_IBSS)
4391 ath10k_control_ibss(arvif, info, vif->addr);
4392
4393 if (changed & BSS_CHANGED_BEACON_INT) {
4394 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004395 vdev_param = ar->wmi.vdev_param->beacon_interval;
4396 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004397 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004398 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004399 "mac vdev %d beacon_interval %d\n",
4400 arvif->vdev_id, arvif->beacon_interval);
4401
Kalle Valo5e3dd152013-06-12 20:52:10 +03004402 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004403 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004404 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004405 }
4406
4407 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004408 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004409 "vdev %d set beacon tx mode to staggered\n",
4410 arvif->vdev_id);
4411
Bartosz Markowski226a3392013-09-26 17:47:16 +02004412 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4413 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004414 WMI_BEACON_STAGGERED_MODE);
4415 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004416 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004417 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004418
4419 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4420 if (ret)
4421 ath10k_warn(ar, "failed to update beacon template: %d\n",
4422 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004423 }
4424
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004425 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4426 ret = ath10k_mac_setup_prb_tmpl(arvif);
4427 if (ret)
4428 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4429 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004430 }
4431
Michal Kaziorba2479f2015-01-24 12:14:51 +02004432 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004433 arvif->dtim_period = info->dtim_period;
4434
Michal Kazior7aa7a722014-08-25 12:09:38 +02004435 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004436 "mac vdev %d dtim_period %d\n",
4437 arvif->vdev_id, arvif->dtim_period);
4438
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004439 vdev_param = ar->wmi.vdev_param->dtim_period;
4440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004441 arvif->dtim_period);
4442 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004443 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004444 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004445 }
4446
4447 if (changed & BSS_CHANGED_SSID &&
4448 vif->type == NL80211_IFTYPE_AP) {
4449 arvif->u.ap.ssid_len = info->ssid_len;
4450 if (info->ssid_len)
4451 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4452 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4453 }
4454
Michal Kazior077efc82014-10-21 10:10:29 +03004455 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4456 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004457
4458 if (changed & BSS_CHANGED_BEACON_ENABLED)
4459 ath10k_control_beaconing(arvif, info);
4460
4461 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004462 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004463 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004464 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004465
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004466 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004467 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004468 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004469 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004470
4471 vdev_param = ar->wmi.vdev_param->protection_mode;
4472 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4473 info->use_cts_prot ? 1 : 0);
4474 if (ret)
4475 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4476 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004477 }
4478
4479 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004480 if (info->use_short_slot)
4481 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4482
4483 else
4484 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4485
Michal Kazior7aa7a722014-08-25 12:09:38 +02004486 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004487 arvif->vdev_id, slottime);
4488
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004489 vdev_param = ar->wmi.vdev_param->slot_time;
4490 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004491 slottime);
4492 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004493 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004494 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004495 }
4496
4497 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004498 if (info->use_short_preamble)
4499 preamble = WMI_VDEV_PREAMBLE_SHORT;
4500 else
4501 preamble = WMI_VDEV_PREAMBLE_LONG;
4502
Michal Kazior7aa7a722014-08-25 12:09:38 +02004503 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004504 "mac vdev %d preamble %dn",
4505 arvif->vdev_id, preamble);
4506
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004507 vdev_param = ar->wmi.vdev_param->preamble;
4508 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004509 preamble);
4510 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004511 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004512 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004513 }
4514
4515 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004516 if (info->assoc) {
4517 /* Workaround: Make sure monitor vdev is not running
4518 * when associating to prevent some firmware revisions
4519 * (e.g. 10.1 and 10.2) from crashing.
4520 */
4521 if (ar->monitor_started)
4522 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004523 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004524 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004525 } else {
4526 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004527 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004528 }
4529
Michal Kazior7d9d5582014-10-21 10:40:15 +03004530 if (changed & BSS_CHANGED_TXPOWER) {
4531 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4532 arvif->vdev_id, info->txpower);
4533
4534 arvif->txpower = info->txpower;
4535 ret = ath10k_mac_txpower_recalc(ar);
4536 if (ret)
4537 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4538 }
4539
Michal Kaziorbf14e652014-12-12 12:41:38 +01004540 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004541 arvif->ps = vif->bss_conf.ps;
4542
4543 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004544 if (ret)
4545 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4546 arvif->vdev_id, ret);
4547 }
4548
Kalle Valo5e3dd152013-06-12 20:52:10 +03004549 mutex_unlock(&ar->conf_mutex);
4550}
4551
4552static int ath10k_hw_scan(struct ieee80211_hw *hw,
4553 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004554 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004555{
4556 struct ath10k *ar = hw->priv;
4557 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004558 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004559 struct wmi_start_scan_arg arg;
4560 int ret = 0;
4561 int i;
4562
4563 mutex_lock(&ar->conf_mutex);
4564
4565 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004566 switch (ar->scan.state) {
4567 case ATH10K_SCAN_IDLE:
4568 reinit_completion(&ar->scan.started);
4569 reinit_completion(&ar->scan.completed);
4570 ar->scan.state = ATH10K_SCAN_STARTING;
4571 ar->scan.is_roc = false;
4572 ar->scan.vdev_id = arvif->vdev_id;
4573 ret = 0;
4574 break;
4575 case ATH10K_SCAN_STARTING:
4576 case ATH10K_SCAN_RUNNING:
4577 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004579 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004580 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004581 spin_unlock_bh(&ar->data_lock);
4582
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004583 if (ret)
4584 goto exit;
4585
Kalle Valo5e3dd152013-06-12 20:52:10 +03004586 memset(&arg, 0, sizeof(arg));
4587 ath10k_wmi_start_scan_init(ar, &arg);
4588 arg.vdev_id = arvif->vdev_id;
4589 arg.scan_id = ATH10K_SCAN_ID;
4590
4591 if (!req->no_cck)
4592 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4593
4594 if (req->ie_len) {
4595 arg.ie_len = req->ie_len;
4596 memcpy(arg.ie, req->ie, arg.ie_len);
4597 }
4598
4599 if (req->n_ssids) {
4600 arg.n_ssids = req->n_ssids;
4601 for (i = 0; i < arg.n_ssids; i++) {
4602 arg.ssids[i].len = req->ssids[i].ssid_len;
4603 arg.ssids[i].ssid = req->ssids[i].ssid;
4604 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004605 } else {
4606 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004607 }
4608
4609 if (req->n_channels) {
4610 arg.n_channels = req->n_channels;
4611 for (i = 0; i < arg.n_channels; i++)
4612 arg.channels[i] = req->channels[i]->center_freq;
4613 }
4614
4615 ret = ath10k_start_scan(ar, &arg);
4616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004617 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004618 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004619 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004620 spin_unlock_bh(&ar->data_lock);
4621 }
4622
4623exit:
4624 mutex_unlock(&ar->conf_mutex);
4625 return ret;
4626}
4627
4628static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4629 struct ieee80211_vif *vif)
4630{
4631 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004632
4633 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004634 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004635 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004636
4637 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004638}
4639
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004640static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4641 struct ath10k_vif *arvif,
4642 enum set_key_cmd cmd,
4643 struct ieee80211_key_conf *key)
4644{
4645 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4646 int ret;
4647
4648 /* 10.1 firmware branch requires default key index to be set to group
4649 * key index after installing it. Otherwise FW/HW Txes corrupted
4650 * frames with multi-vif APs. This is not required for main firmware
4651 * branch (e.g. 636).
4652 *
4653 * FIXME: This has been tested only in AP. It remains unknown if this
4654 * is required for multi-vif STA interfaces on 10.1 */
4655
4656 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4657 return;
4658
4659 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4660 return;
4661
4662 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4663 return;
4664
4665 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4666 return;
4667
4668 if (cmd != SET_KEY)
4669 return;
4670
4671 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4672 key->keyidx);
4673 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004674 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004675 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004676}
4677
Kalle Valo5e3dd152013-06-12 20:52:10 +03004678static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4679 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4680 struct ieee80211_key_conf *key)
4681{
4682 struct ath10k *ar = hw->priv;
4683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4684 struct ath10k_peer *peer;
4685 const u8 *peer_addr;
4686 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4687 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4688 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004689 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004690 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004691 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004692
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004693 /* this one needs to be done in software */
4694 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4695 return 1;
4696
Kalle Valo5e3dd152013-06-12 20:52:10 +03004697 if (key->keyidx > WMI_MAX_KEY_INDEX)
4698 return -ENOSPC;
4699
4700 mutex_lock(&ar->conf_mutex);
4701
4702 if (sta)
4703 peer_addr = sta->addr;
4704 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4705 peer_addr = vif->bss_conf.bssid;
4706 else
4707 peer_addr = vif->addr;
4708
4709 key->hw_key_idx = key->keyidx;
4710
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004711 if (is_wep) {
4712 if (cmd == SET_KEY)
4713 arvif->wep_keys[key->keyidx] = key;
4714 else
4715 arvif->wep_keys[key->keyidx] = NULL;
4716 }
4717
Kalle Valo5e3dd152013-06-12 20:52:10 +03004718 /* the peer should not disappear in mid-way (unless FW goes awry) since
4719 * we already hold conf_mutex. we just make sure its there now. */
4720 spin_lock_bh(&ar->data_lock);
4721 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4722 spin_unlock_bh(&ar->data_lock);
4723
4724 if (!peer) {
4725 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004726 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004727 peer_addr);
4728 ret = -EOPNOTSUPP;
4729 goto exit;
4730 } else {
4731 /* if the peer doesn't exist there is no key to disable
4732 * anymore */
4733 goto exit;
4734 }
4735 }
4736
Michal Kazior7cc45732015-03-09 14:24:17 +01004737 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4738 flags |= WMI_KEY_PAIRWISE;
4739 else
4740 flags |= WMI_KEY_GROUP;
4741
Kalle Valo5e3dd152013-06-12 20:52:10 +03004742 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004743 if (cmd == DISABLE_KEY)
4744 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004745
Michal Kaziorad325cb2015-02-18 14:02:27 +01004746 /* When WEP keys are uploaded it's possible that there are
4747 * stations associated already (e.g. when merging) without any
4748 * keys. Static WEP needs an explicit per-peer key upload.
4749 */
4750 if (vif->type == NL80211_IFTYPE_ADHOC &&
4751 cmd == SET_KEY)
4752 ath10k_mac_vif_update_wep_key(arvif, key);
4753
Michal Kazior370e5672015-02-18 14:02:26 +01004754 /* 802.1x never sets the def_wep_key_idx so each set_key()
4755 * call changes default tx key.
4756 *
4757 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4758 * after first set_key().
4759 */
4760 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4761 flags |= WMI_KEY_TX_USAGE;
Michal Kazior370e5672015-02-18 14:02:26 +01004762 }
4763
4764 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004765 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004766 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004767 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004768 goto exit;
4769 }
4770
Michal Kazior29a10002015-04-10 13:05:58 +00004771 /* mac80211 sets static WEP keys as groupwise while firmware requires
4772 * them to be installed twice as both pairwise and groupwise.
4773 */
4774 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4775 flags2 = flags;
4776 flags2 &= ~WMI_KEY_GROUP;
4777 flags2 |= WMI_KEY_PAIRWISE;
4778
4779 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4780 if (ret) {
4781 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4782 arvif->vdev_id, peer_addr, ret);
4783 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4784 peer_addr, flags);
4785 if (ret2)
4786 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4787 arvif->vdev_id, peer_addr, ret2);
4788 goto exit;
4789 }
4790 }
4791
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004792 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4793
Kalle Valo5e3dd152013-06-12 20:52:10 +03004794 spin_lock_bh(&ar->data_lock);
4795 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4796 if (peer && cmd == SET_KEY)
4797 peer->keys[key->keyidx] = key;
4798 else if (peer && cmd == DISABLE_KEY)
4799 peer->keys[key->keyidx] = NULL;
4800 else if (peer == NULL)
4801 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004802 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004803 spin_unlock_bh(&ar->data_lock);
4804
4805exit:
4806 mutex_unlock(&ar->conf_mutex);
4807 return ret;
4808}
4809
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004810static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4811 struct ieee80211_vif *vif,
4812 int keyidx)
4813{
4814 struct ath10k *ar = hw->priv;
4815 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4816 int ret;
4817
4818 mutex_lock(&arvif->ar->conf_mutex);
4819
4820 if (arvif->ar->state != ATH10K_STATE_ON)
4821 goto unlock;
4822
4823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4824 arvif->vdev_id, keyidx);
4825
4826 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4827 arvif->vdev_id,
4828 arvif->ar->wmi.vdev_param->def_keyid,
4829 keyidx);
4830
4831 if (ret) {
4832 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4833 arvif->vdev_id,
4834 ret);
4835 goto unlock;
4836 }
4837
4838 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004839
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004840unlock:
4841 mutex_unlock(&arvif->ar->conf_mutex);
4842}
4843
Michal Kazior9797feb2014-02-14 14:49:48 +01004844static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4845{
4846 struct ath10k *ar;
4847 struct ath10k_vif *arvif;
4848 struct ath10k_sta *arsta;
4849 struct ieee80211_sta *sta;
4850 u32 changed, bw, nss, smps;
4851 int err;
4852
4853 arsta = container_of(wk, struct ath10k_sta, update_wk);
4854 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4855 arvif = arsta->arvif;
4856 ar = arvif->ar;
4857
4858 spin_lock_bh(&ar->data_lock);
4859
4860 changed = arsta->changed;
4861 arsta->changed = 0;
4862
4863 bw = arsta->bw;
4864 nss = arsta->nss;
4865 smps = arsta->smps;
4866
4867 spin_unlock_bh(&ar->data_lock);
4868
4869 mutex_lock(&ar->conf_mutex);
4870
4871 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004872 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004873 sta->addr, bw);
4874
4875 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4876 WMI_PEER_CHAN_WIDTH, bw);
4877 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004878 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004879 sta->addr, bw, err);
4880 }
4881
4882 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004884 sta->addr, nss);
4885
4886 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4887 WMI_PEER_NSS, nss);
4888 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004889 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004890 sta->addr, nss, err);
4891 }
4892
4893 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004894 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004895 sta->addr, smps);
4896
4897 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4898 WMI_PEER_SMPS_STATE, smps);
4899 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004900 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004901 sta->addr, smps, err);
4902 }
4903
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004904 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4905 changed & IEEE80211_RC_NSS_CHANGED) {
4906 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004907 sta->addr);
4908
Michal Kazior590922a2014-10-21 10:10:29 +03004909 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004910 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004911 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004912 sta->addr);
4913 }
4914
Michal Kazior9797feb2014-02-14 14:49:48 +01004915 mutex_unlock(&ar->conf_mutex);
4916}
4917
Marek Puzyniak7c354242015-03-30 09:51:52 +03004918static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4919 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004920{
4921 struct ath10k *ar = arvif->ar;
4922
4923 lockdep_assert_held(&ar->conf_mutex);
4924
Marek Puzyniak7c354242015-03-30 09:51:52 +03004925 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004926 return 0;
4927
4928 if (ar->num_stations >= ar->max_num_stations)
4929 return -ENOBUFS;
4930
4931 ar->num_stations++;
4932
4933 return 0;
4934}
4935
Marek Puzyniak7c354242015-03-30 09:51:52 +03004936static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4937 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004938{
4939 struct ath10k *ar = arvif->ar;
4940
4941 lockdep_assert_held(&ar->conf_mutex);
4942
Marek Puzyniak7c354242015-03-30 09:51:52 +03004943 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004944 return;
4945
4946 ar->num_stations--;
4947}
4948
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004949struct ath10k_mac_tdls_iter_data {
4950 u32 num_tdls_stations;
4951 struct ieee80211_vif *curr_vif;
4952};
4953
4954static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4955 struct ieee80211_sta *sta)
4956{
4957 struct ath10k_mac_tdls_iter_data *iter_data = data;
4958 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4959 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4960
4961 if (sta->tdls && sta_vif == iter_data->curr_vif)
4962 iter_data->num_tdls_stations++;
4963}
4964
4965static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4966 struct ieee80211_vif *vif)
4967{
4968 struct ath10k_mac_tdls_iter_data data = {};
4969
4970 data.curr_vif = vif;
4971
4972 ieee80211_iterate_stations_atomic(hw,
4973 ath10k_mac_tdls_vif_stations_count_iter,
4974 &data);
4975 return data.num_tdls_stations;
4976}
4977
4978static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4979 struct ieee80211_vif *vif)
4980{
4981 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4982 int *num_tdls_vifs = data;
4983
4984 if (vif->type != NL80211_IFTYPE_STATION)
4985 return;
4986
4987 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4988 (*num_tdls_vifs)++;
4989}
4990
4991static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4992{
4993 int num_tdls_vifs = 0;
4994
4995 ieee80211_iterate_active_interfaces_atomic(hw,
4996 IEEE80211_IFACE_ITER_NORMAL,
4997 ath10k_mac_tdls_vifs_count_iter,
4998 &num_tdls_vifs);
4999 return num_tdls_vifs;
5000}
5001
Kalle Valo5e3dd152013-06-12 20:52:10 +03005002static int ath10k_sta_state(struct ieee80211_hw *hw,
5003 struct ieee80211_vif *vif,
5004 struct ieee80211_sta *sta,
5005 enum ieee80211_sta_state old_state,
5006 enum ieee80211_sta_state new_state)
5007{
5008 struct ath10k *ar = hw->priv;
5009 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005010 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005011 int ret = 0;
5012
Michal Kazior76f90022014-02-25 09:29:57 +02005013 if (old_state == IEEE80211_STA_NOTEXIST &&
5014 new_state == IEEE80211_STA_NONE) {
5015 memset(arsta, 0, sizeof(*arsta));
5016 arsta->arvif = arvif;
5017 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5018 }
5019
Michal Kazior9797feb2014-02-14 14:49:48 +01005020 /* cancel must be done outside the mutex to avoid deadlock */
5021 if ((old_state == IEEE80211_STA_NONE &&
5022 new_state == IEEE80211_STA_NOTEXIST))
5023 cancel_work_sync(&arsta->update_wk);
5024
Kalle Valo5e3dd152013-06-12 20:52:10 +03005025 mutex_lock(&ar->conf_mutex);
5026
5027 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005028 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005029 /*
5030 * New station addition.
5031 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005032 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5033 u32 num_tdls_stations;
5034 u32 num_tdls_vifs;
5035
Michal Kaziorcfd10612014-11-25 15:16:05 +01005036 ath10k_dbg(ar, ATH10K_DBG_MAC,
5037 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5038 arvif->vdev_id, sta->addr,
5039 ar->num_stations + 1, ar->max_num_stations,
5040 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005041
Marek Puzyniak7c354242015-03-30 09:51:52 +03005042 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005043 if (ret) {
5044 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5045 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005046 goto exit;
5047 }
5048
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005049 if (sta->tdls)
5050 peer_type = WMI_PEER_TYPE_TDLS;
5051
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005052 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005053 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005054 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005055 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 -08005056 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005057 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005058 goto exit;
5059 }
Michal Kazior077efc82014-10-21 10:10:29 +03005060
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005061 if (!sta->tdls)
5062 goto exit;
5063
5064 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5065 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5066
5067 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5068 num_tdls_stations == 0) {
5069 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5070 arvif->vdev_id, ar->max_num_tdls_vdevs);
5071 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5072 ath10k_mac_dec_num_stations(arvif, sta);
5073 ret = -ENOBUFS;
5074 goto exit;
5075 }
5076
5077 if (num_tdls_stations == 0) {
5078 /* This is the first tdls peer in current vif */
5079 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5080
5081 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5082 state);
5083 if (ret) {
5084 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5085 arvif->vdev_id, ret);
5086 ath10k_peer_delete(ar, arvif->vdev_id,
5087 sta->addr);
5088 ath10k_mac_dec_num_stations(arvif, sta);
5089 goto exit;
5090 }
5091 }
5092
5093 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5094 WMI_TDLS_PEER_STATE_PEERING);
5095 if (ret) {
5096 ath10k_warn(ar,
5097 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5098 sta->addr, arvif->vdev_id, ret);
5099 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5100 ath10k_mac_dec_num_stations(arvif, sta);
5101
5102 if (num_tdls_stations != 0)
5103 goto exit;
5104 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5105 WMI_TDLS_DISABLE);
5106 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005107 } else if ((old_state == IEEE80211_STA_NONE &&
5108 new_state == IEEE80211_STA_NOTEXIST)) {
5109 /*
5110 * Existing station deletion.
5111 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005112 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005113 "mac vdev %d peer delete %pM (sta gone)\n",
5114 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005115
Kalle Valo5e3dd152013-06-12 20:52:10 +03005116 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5117 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005118 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005119 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005120
Marek Puzyniak7c354242015-03-30 09:51:52 +03005121 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005122
5123 if (!sta->tdls)
5124 goto exit;
5125
5126 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5127 goto exit;
5128
5129 /* This was the last tdls peer in current vif */
5130 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5131 WMI_TDLS_DISABLE);
5132 if (ret) {
5133 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5134 arvif->vdev_id, ret);
5135 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005136 } else if (old_state == IEEE80211_STA_AUTH &&
5137 new_state == IEEE80211_STA_ASSOC &&
5138 (vif->type == NL80211_IFTYPE_AP ||
5139 vif->type == NL80211_IFTYPE_ADHOC)) {
5140 /*
5141 * New association.
5142 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005144 sta->addr);
5145
Michal Kazior590922a2014-10-21 10:10:29 +03005146 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005147 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005148 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005149 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005150 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005151 new_state == IEEE80211_STA_AUTHORIZED &&
5152 sta->tdls) {
5153 /*
5154 * Tdls station authorized.
5155 */
5156 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5157 sta->addr);
5158
5159 ret = ath10k_station_assoc(ar, vif, sta, false);
5160 if (ret) {
5161 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5162 sta->addr, arvif->vdev_id, ret);
5163 goto exit;
5164 }
5165
5166 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5167 WMI_TDLS_PEER_STATE_CONNECTED);
5168 if (ret)
5169 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5170 sta->addr, arvif->vdev_id, ret);
5171 } else if (old_state == IEEE80211_STA_ASSOC &&
5172 new_state == IEEE80211_STA_AUTH &&
5173 (vif->type == NL80211_IFTYPE_AP ||
5174 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005175 /*
5176 * Disassociation.
5177 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005178 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005179 sta->addr);
5180
Michal Kazior590922a2014-10-21 10:10:29 +03005181 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005182 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005183 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005184 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005185 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005186exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005187 mutex_unlock(&ar->conf_mutex);
5188 return ret;
5189}
5190
5191static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005192 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005193{
5194 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005195 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5196 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005197 u32 value = 0;
5198 int ret = 0;
5199
Michal Kazior548db542013-07-05 16:15:15 +03005200 lockdep_assert_held(&ar->conf_mutex);
5201
Kalle Valo5e3dd152013-06-12 20:52:10 +03005202 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5203 return 0;
5204
5205 switch (ac) {
5206 case IEEE80211_AC_VO:
5207 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5208 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005209 prio = 7;
5210 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005211 break;
5212 case IEEE80211_AC_VI:
5213 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5214 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005215 prio = 5;
5216 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005217 break;
5218 case IEEE80211_AC_BE:
5219 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5220 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005221 prio = 2;
5222 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005223 break;
5224 case IEEE80211_AC_BK:
5225 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5226 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005227 prio = 0;
5228 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005229 break;
5230 }
5231
5232 if (enable)
5233 arvif->u.sta.uapsd |= value;
5234 else
5235 arvif->u.sta.uapsd &= ~value;
5236
5237 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5238 WMI_STA_PS_PARAM_UAPSD,
5239 arvif->u.sta.uapsd);
5240 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005241 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005242 goto exit;
5243 }
5244
5245 if (arvif->u.sta.uapsd)
5246 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5247 else
5248 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5249
5250 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5251 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5252 value);
5253 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005254 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005255
Michal Kazior9f9b5742014-12-12 12:41:36 +01005256 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5257 if (ret) {
5258 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5259 arvif->vdev_id, ret);
5260 return ret;
5261 }
5262
5263 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5264 if (ret) {
5265 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5266 arvif->vdev_id, ret);
5267 return ret;
5268 }
5269
Michal Kaziorb0e56152015-01-24 12:14:52 +02005270 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5271 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5272 /* Only userspace can make an educated decision when to send
5273 * trigger frame. The following effectively disables u-UAPSD
5274 * autotrigger in firmware (which is enabled by default
5275 * provided the autotrigger service is available).
5276 */
5277
5278 arg.wmm_ac = acc;
5279 arg.user_priority = prio;
5280 arg.service_interval = 0;
5281 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5282 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5283
5284 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5285 arvif->bssid, &arg, 1);
5286 if (ret) {
5287 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5288 ret);
5289 return ret;
5290 }
5291 }
5292
Kalle Valo5e3dd152013-06-12 20:52:10 +03005293exit:
5294 return ret;
5295}
5296
5297static int ath10k_conf_tx(struct ieee80211_hw *hw,
5298 struct ieee80211_vif *vif, u16 ac,
5299 const struct ieee80211_tx_queue_params *params)
5300{
5301 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005302 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005303 struct wmi_wmm_params_arg *p = NULL;
5304 int ret;
5305
5306 mutex_lock(&ar->conf_mutex);
5307
5308 switch (ac) {
5309 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005310 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311 break;
5312 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005313 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314 break;
5315 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005316 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005317 break;
5318 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005319 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005320 break;
5321 }
5322
5323 if (WARN_ON(!p)) {
5324 ret = -EINVAL;
5325 goto exit;
5326 }
5327
5328 p->cwmin = params->cw_min;
5329 p->cwmax = params->cw_max;
5330 p->aifs = params->aifs;
5331
5332 /*
5333 * The channel time duration programmed in the HW is in absolute
5334 * microseconds, while mac80211 gives the txop in units of
5335 * 32 microseconds.
5336 */
5337 p->txop = params->txop * 32;
5338
Michal Kazior7fc979a2015-01-28 09:57:28 +02005339 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5340 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5341 &arvif->wmm_params);
5342 if (ret) {
5343 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5344 arvif->vdev_id, ret);
5345 goto exit;
5346 }
5347 } else {
5348 /* This won't work well with multi-interface cases but it's
5349 * better than nothing.
5350 */
5351 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5352 if (ret) {
5353 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5354 goto exit;
5355 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005356 }
5357
5358 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5359 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005360 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005361
5362exit:
5363 mutex_unlock(&ar->conf_mutex);
5364 return ret;
5365}
5366
5367#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5368
5369static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5370 struct ieee80211_vif *vif,
5371 struct ieee80211_channel *chan,
5372 int duration,
5373 enum ieee80211_roc_type type)
5374{
5375 struct ath10k *ar = hw->priv;
5376 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5377 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005378 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005379 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005380
5381 mutex_lock(&ar->conf_mutex);
5382
5383 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005384 switch (ar->scan.state) {
5385 case ATH10K_SCAN_IDLE:
5386 reinit_completion(&ar->scan.started);
5387 reinit_completion(&ar->scan.completed);
5388 reinit_completion(&ar->scan.on_channel);
5389 ar->scan.state = ATH10K_SCAN_STARTING;
5390 ar->scan.is_roc = true;
5391 ar->scan.vdev_id = arvif->vdev_id;
5392 ar->scan.roc_freq = chan->center_freq;
5393 ret = 0;
5394 break;
5395 case ATH10K_SCAN_STARTING:
5396 case ATH10K_SCAN_RUNNING:
5397 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005398 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005399 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005400 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005401 spin_unlock_bh(&ar->data_lock);
5402
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005403 if (ret)
5404 goto exit;
5405
Michal Kaziorfcf98442015-03-31 11:03:47 +00005406 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005407
Kalle Valo5e3dd152013-06-12 20:52:10 +03005408 memset(&arg, 0, sizeof(arg));
5409 ath10k_wmi_start_scan_init(ar, &arg);
5410 arg.vdev_id = arvif->vdev_id;
5411 arg.scan_id = ATH10K_SCAN_ID;
5412 arg.n_channels = 1;
5413 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005414 arg.dwell_time_active = scan_time_msec;
5415 arg.dwell_time_passive = scan_time_msec;
5416 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005417 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5418 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005419 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005420
5421 ret = ath10k_start_scan(ar, &arg);
5422 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005423 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005424 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005425 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005426 spin_unlock_bh(&ar->data_lock);
5427 goto exit;
5428 }
5429
5430 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5431 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005432 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005433
5434 ret = ath10k_scan_stop(ar);
5435 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005436 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005437
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438 ret = -ETIMEDOUT;
5439 goto exit;
5440 }
5441
Michal Kaziorfcf98442015-03-31 11:03:47 +00005442 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5443 msecs_to_jiffies(duration));
5444
Kalle Valo5e3dd152013-06-12 20:52:10 +03005445 ret = 0;
5446exit:
5447 mutex_unlock(&ar->conf_mutex);
5448 return ret;
5449}
5450
5451static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5452{
5453 struct ath10k *ar = hw->priv;
5454
5455 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005456 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005457 mutex_unlock(&ar->conf_mutex);
5458
Michal Kazior4eb2e162014-10-28 10:23:09 +01005459 cancel_delayed_work_sync(&ar->scan.timeout);
5460
Kalle Valo5e3dd152013-06-12 20:52:10 +03005461 return 0;
5462}
5463
5464/*
5465 * Both RTS and Fragmentation threshold are interface-specific
5466 * in ath10k, but device-specific in mac80211.
5467 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005468
5469static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5470{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005471 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005472 struct ath10k_vif *arvif;
5473 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005474
Michal Kaziorad088bf2013-10-16 15:44:46 +03005475 mutex_lock(&ar->conf_mutex);
5476 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005477 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005478 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005479
Michal Kaziorad088bf2013-10-16 15:44:46 +03005480 ret = ath10k_mac_set_rts(arvif, value);
5481 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005482 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005483 arvif->vdev_id, ret);
5484 break;
5485 }
5486 }
5487 mutex_unlock(&ar->conf_mutex);
5488
5489 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490}
5491
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005492static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5493 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005494{
5495 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005496 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497 int ret;
5498
5499 /* mac80211 doesn't care if we really xmit queued frames or not
5500 * we'll collect those frames either way if we stop/delete vdevs */
5501 if (drop)
5502 return;
5503
Michal Kazior548db542013-07-05 16:15:15 +03005504 mutex_lock(&ar->conf_mutex);
5505
Michal Kazioraffd3212013-07-16 09:54:35 +02005506 if (ar->state == ATH10K_STATE_WEDGED)
5507 goto skip;
5508
Michal Kazioredb82362013-07-05 16:15:14 +03005509 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005510 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005511
Michal Kazioredb82362013-07-05 16:15:14 +03005512 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005513 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005514 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005515
Michal Kazior7962b0d2014-10-28 10:34:38 +01005516 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5517 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5518 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005519
5520 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005521 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005522
5523 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005524 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005525 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005526
Michal Kazioraffd3212013-07-16 09:54:35 +02005527skip:
Michal Kazior548db542013-07-05 16:15:15 +03005528 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005529}
5530
5531/* TODO: Implement this function properly
5532 * For now it is needed to reply to Probe Requests in IBSS mode.
5533 * Propably we need this information from FW.
5534 */
5535static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5536{
5537 return 1;
5538}
5539
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005540static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5541 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005542{
5543 struct ath10k *ar = hw->priv;
5544
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005545 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5546 return;
5547
Michal Kazioraffd3212013-07-16 09:54:35 +02005548 mutex_lock(&ar->conf_mutex);
5549
5550 /* If device failed to restart it will be in a different state, e.g.
5551 * ATH10K_STATE_WEDGED */
5552 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005553 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005554 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005555 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005556 }
5557
5558 mutex_unlock(&ar->conf_mutex);
5559}
5560
Michal Kazior2e1dea42013-07-31 10:32:40 +02005561static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5562 struct survey_info *survey)
5563{
5564 struct ath10k *ar = hw->priv;
5565 struct ieee80211_supported_band *sband;
5566 struct survey_info *ar_survey = &ar->survey[idx];
5567 int ret = 0;
5568
5569 mutex_lock(&ar->conf_mutex);
5570
5571 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5572 if (sband && idx >= sband->n_channels) {
5573 idx -= sband->n_channels;
5574 sband = NULL;
5575 }
5576
5577 if (!sband)
5578 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5579
5580 if (!sband || idx >= sband->n_channels) {
5581 ret = -ENOENT;
5582 goto exit;
5583 }
5584
5585 spin_lock_bh(&ar->data_lock);
5586 memcpy(survey, ar_survey, sizeof(*survey));
5587 spin_unlock_bh(&ar->data_lock);
5588
5589 survey->channel = &sband->channels[idx];
5590
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005591 if (ar->rx_channel == survey->channel)
5592 survey->filled |= SURVEY_INFO_IN_USE;
5593
Michal Kazior2e1dea42013-07-31 10:32:40 +02005594exit:
5595 mutex_unlock(&ar->conf_mutex);
5596 return ret;
5597}
5598
Michal Kazior3ae54222015-03-31 10:49:20 +00005599static bool
5600ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5601 enum ieee80211_band band,
5602 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005603{
Michal Kazior3ae54222015-03-31 10:49:20 +00005604 int num_rates = 0;
5605 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005606
Michal Kazior3ae54222015-03-31 10:49:20 +00005607 num_rates += hweight32(mask->control[band].legacy);
5608
5609 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5610 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5611
5612 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5613 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5614
5615 return num_rates == 1;
5616}
5617
5618static bool
5619ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5620 enum ieee80211_band band,
5621 const struct cfg80211_bitrate_mask *mask,
5622 int *nss)
5623{
5624 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5625 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5626 u8 ht_nss_mask = 0;
5627 u8 vht_nss_mask = 0;
5628 int i;
5629
5630 if (mask->control[band].legacy)
5631 return false;
5632
5633 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5634 if (mask->control[band].ht_mcs[i] == 0)
5635 continue;
5636 else if (mask->control[band].ht_mcs[i] ==
5637 sband->ht_cap.mcs.rx_mask[i])
5638 ht_nss_mask |= BIT(i);
5639 else
5640 return false;
5641 }
5642
5643 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5644 if (mask->control[band].vht_mcs[i] == 0)
5645 continue;
5646 else if (mask->control[band].vht_mcs[i] ==
5647 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5648 vht_nss_mask |= BIT(i);
5649 else
5650 return false;
5651 }
5652
5653 if (ht_nss_mask != vht_nss_mask)
5654 return false;
5655
5656 if (ht_nss_mask == 0)
5657 return false;
5658
5659 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5660 return false;
5661
5662 *nss = fls(ht_nss_mask);
5663
5664 return true;
5665}
5666
5667static int
5668ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5669 enum ieee80211_band band,
5670 const struct cfg80211_bitrate_mask *mask,
5671 u8 *rate, u8 *nss)
5672{
5673 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5674 int rate_idx;
5675 int i;
5676 u16 bitrate;
5677 u8 preamble;
5678 u8 hw_rate;
5679
5680 if (hweight32(mask->control[band].legacy) == 1) {
5681 rate_idx = ffs(mask->control[band].legacy) - 1;
5682
5683 hw_rate = sband->bitrates[rate_idx].hw_value;
5684 bitrate = sband->bitrates[rate_idx].bitrate;
5685
5686 if (ath10k_mac_bitrate_is_cck(bitrate))
5687 preamble = WMI_RATE_PREAMBLE_CCK;
5688 else
5689 preamble = WMI_RATE_PREAMBLE_OFDM;
5690
5691 *nss = 1;
5692 *rate = preamble << 6 |
5693 (*nss - 1) << 4 |
5694 hw_rate << 0;
5695
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005696 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005697 }
5698
Michal Kazior3ae54222015-03-31 10:49:20 +00005699 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5700 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5701 *nss = i + 1;
5702 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5703 (*nss - 1) << 4 |
5704 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005705
Michal Kazior3ae54222015-03-31 10:49:20 +00005706 return 0;
5707 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005708 }
5709
Michal Kazior3ae54222015-03-31 10:49:20 +00005710 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5711 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5712 *nss = i + 1;
5713 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5714 (*nss - 1) << 4 |
5715 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005716
Michal Kazior3ae54222015-03-31 10:49:20 +00005717 return 0;
5718 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005719 }
5720
Michal Kazior3ae54222015-03-31 10:49:20 +00005721 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005722}
5723
Michal Kazior3ae54222015-03-31 10:49:20 +00005724static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5725 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005726{
5727 struct ath10k *ar = arvif->ar;
5728 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005729 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005730
Michal Kazior3ae54222015-03-31 10:49:20 +00005731 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005732
Michal Kazior3ae54222015-03-31 10:49:20 +00005733 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5734 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005735
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005736 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005737 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005739 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005740 rate, ret);
5741 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005742 }
5743
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005744 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005745 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005746 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005747 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5748 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005749 }
5750
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005751 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005752 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005753 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005754 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5755 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005756 }
5757
Michal Kazior3ae54222015-03-31 10:49:20 +00005758 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005759}
5760
Michal Kazior3ae54222015-03-31 10:49:20 +00005761static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5762 struct ieee80211_vif *vif,
5763 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005764{
5765 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005766 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005767 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005768 enum ieee80211_band band;
Michal Kazior3ae54222015-03-31 10:49:20 +00005769 u8 rate;
5770 u8 nss;
5771 u8 sgi;
5772 int single_nss;
5773 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005774
Michal Kazior500ff9f2015-03-31 10:26:21 +00005775 if (ath10k_mac_vif_chan(vif, &def))
5776 return -EPERM;
5777
Michal Kazior500ff9f2015-03-31 10:26:21 +00005778 band = def.chan->band;
5779
Michal Kazior3ae54222015-03-31 10:49:20 +00005780 sgi = mask->control[band].gi;
5781 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005782 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005783
Michal Kazior3ae54222015-03-31 10:49:20 +00005784 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5785 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5786 &rate, &nss);
5787 if (ret) {
5788 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5789 arvif->vdev_id, ret);
5790 return ret;
5791 }
5792 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5793 &single_nss)) {
5794 rate = WMI_FIXED_RATE_NONE;
5795 nss = single_nss;
5796 } else {
5797 rate = WMI_FIXED_RATE_NONE;
5798 nss = ar->num_rf_chains;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005799 }
5800
Michal Kazior3ae54222015-03-31 10:49:20 +00005801 mutex_lock(&ar->conf_mutex);
5802
5803 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
5804 if (ret) {
5805 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5806 arvif->vdev_id, ret);
5807 goto exit;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005808 }
5809
Michal Kazior3ae54222015-03-31 10:49:20 +00005810exit:
5811 mutex_unlock(&ar->conf_mutex);
5812
5813 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005814}
5815
Michal Kazior9797feb2014-02-14 14:49:48 +01005816static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5817 struct ieee80211_vif *vif,
5818 struct ieee80211_sta *sta,
5819 u32 changed)
5820{
5821 struct ath10k *ar = hw->priv;
5822 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5823 u32 bw, smps;
5824
5825 spin_lock_bh(&ar->data_lock);
5826
Michal Kazior7aa7a722014-08-25 12:09:38 +02005827 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005828 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5829 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5830 sta->smps_mode);
5831
5832 if (changed & IEEE80211_RC_BW_CHANGED) {
5833 bw = WMI_PEER_CHWIDTH_20MHZ;
5834
5835 switch (sta->bandwidth) {
5836 case IEEE80211_STA_RX_BW_20:
5837 bw = WMI_PEER_CHWIDTH_20MHZ;
5838 break;
5839 case IEEE80211_STA_RX_BW_40:
5840 bw = WMI_PEER_CHWIDTH_40MHZ;
5841 break;
5842 case IEEE80211_STA_RX_BW_80:
5843 bw = WMI_PEER_CHWIDTH_80MHZ;
5844 break;
5845 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005846 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005847 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005848 bw = WMI_PEER_CHWIDTH_20MHZ;
5849 break;
5850 }
5851
5852 arsta->bw = bw;
5853 }
5854
5855 if (changed & IEEE80211_RC_NSS_CHANGED)
5856 arsta->nss = sta->rx_nss;
5857
5858 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5859 smps = WMI_PEER_SMPS_PS_NONE;
5860
5861 switch (sta->smps_mode) {
5862 case IEEE80211_SMPS_AUTOMATIC:
5863 case IEEE80211_SMPS_OFF:
5864 smps = WMI_PEER_SMPS_PS_NONE;
5865 break;
5866 case IEEE80211_SMPS_STATIC:
5867 smps = WMI_PEER_SMPS_STATIC;
5868 break;
5869 case IEEE80211_SMPS_DYNAMIC:
5870 smps = WMI_PEER_SMPS_DYNAMIC;
5871 break;
5872 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005873 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005874 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005875 smps = WMI_PEER_SMPS_PS_NONE;
5876 break;
5877 }
5878
5879 arsta->smps = smps;
5880 }
5881
Michal Kazior9797feb2014-02-14 14:49:48 +01005882 arsta->changed |= changed;
5883
5884 spin_unlock_bh(&ar->data_lock);
5885
5886 ieee80211_queue_work(hw, &arsta->update_wk);
5887}
5888
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005889static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5890{
5891 /*
5892 * FIXME: Return 0 for time being. Need to figure out whether FW
5893 * has the API to fetch 64-bit local TSF
5894 */
5895
5896 return 0;
5897}
5898
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005899static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5900 struct ieee80211_vif *vif,
5901 enum ieee80211_ampdu_mlme_action action,
5902 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5903 u8 buf_size)
5904{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005905 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005906 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5907
Michal Kazior7aa7a722014-08-25 12:09:38 +02005908 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 +02005909 arvif->vdev_id, sta->addr, tid, action);
5910
5911 switch (action) {
5912 case IEEE80211_AMPDU_RX_START:
5913 case IEEE80211_AMPDU_RX_STOP:
5914 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5915 * creation/removal. Do we need to verify this?
5916 */
5917 return 0;
5918 case IEEE80211_AMPDU_TX_START:
5919 case IEEE80211_AMPDU_TX_STOP_CONT:
5920 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5921 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5922 case IEEE80211_AMPDU_TX_OPERATIONAL:
5923 /* Firmware offloads Tx aggregation entirely so deny mac80211
5924 * Tx aggregation requests.
5925 */
5926 return -EOPNOTSUPP;
5927 }
5928
5929 return -EINVAL;
5930}
5931
Michal Kazior500ff9f2015-03-31 10:26:21 +00005932static void
5933ath10k_mac_update_rx_channel(struct ath10k *ar)
5934{
5935 struct cfg80211_chan_def *def = NULL;
5936
5937 /* Both locks are required because ar->rx_channel is modified. This
5938 * allows readers to hold either lock.
5939 */
5940 lockdep_assert_held(&ar->conf_mutex);
5941 lockdep_assert_held(&ar->data_lock);
5942
5943 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5944 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5945 * ppdu on Rx may reduce performance on low-end systems. It should be
5946 * possible to make tables/hashmaps to speed the lookup up (be vary of
5947 * cpu data cache lines though regarding sizes) but to keep the initial
5948 * implementation simple and less intrusive fallback to the slow lookup
5949 * only for multi-channel cases. Single-channel cases will remain to
5950 * use the old channel derival and thus performance should not be
5951 * affected much.
5952 */
5953 rcu_read_lock();
5954 if (ath10k_mac_num_chanctxs(ar) == 1) {
5955 ieee80211_iter_chan_contexts_atomic(ar->hw,
5956 ath10k_mac_get_any_chandef_iter,
5957 &def);
5958 ar->rx_channel = def->chan;
5959 } else {
5960 ar->rx_channel = NULL;
5961 }
5962 rcu_read_unlock();
5963}
5964
5965static void
5966ath10k_mac_chan_ctx_init(struct ath10k *ar,
5967 struct ath10k_chanctx *arctx,
5968 struct ieee80211_chanctx_conf *conf)
5969{
5970 lockdep_assert_held(&ar->conf_mutex);
5971 lockdep_assert_held(&ar->data_lock);
5972
5973 memset(arctx, 0, sizeof(*arctx));
5974
5975 arctx->conf = *conf;
5976}
5977
5978static int
5979ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5980 struct ieee80211_chanctx_conf *ctx)
5981{
5982 struct ath10k *ar = hw->priv;
5983 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5984
5985 ath10k_dbg(ar, ATH10K_DBG_MAC,
5986 "mac chanctx add freq %hu width %d ptr %p\n",
5987 ctx->def.chan->center_freq, ctx->def.width, ctx);
5988
5989 mutex_lock(&ar->conf_mutex);
5990
5991 spin_lock_bh(&ar->data_lock);
5992 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
5993 ath10k_mac_update_rx_channel(ar);
5994 spin_unlock_bh(&ar->data_lock);
5995
5996 ath10k_recalc_radar_detection(ar);
5997 ath10k_monitor_recalc(ar);
5998
5999 mutex_unlock(&ar->conf_mutex);
6000
6001 return 0;
6002}
6003
6004static void
6005ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6006 struct ieee80211_chanctx_conf *ctx)
6007{
6008 struct ath10k *ar = hw->priv;
6009
6010 ath10k_dbg(ar, ATH10K_DBG_MAC,
6011 "mac chanctx remove freq %hu width %d ptr %p\n",
6012 ctx->def.chan->center_freq, ctx->def.width, ctx);
6013
6014 mutex_lock(&ar->conf_mutex);
6015
6016 spin_lock_bh(&ar->data_lock);
6017 ath10k_mac_update_rx_channel(ar);
6018 spin_unlock_bh(&ar->data_lock);
6019
6020 ath10k_recalc_radar_detection(ar);
6021 ath10k_monitor_recalc(ar);
6022
6023 mutex_unlock(&ar->conf_mutex);
6024}
6025
6026static void
6027ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6028 struct ieee80211_chanctx_conf *ctx,
6029 u32 changed)
6030{
6031 struct ath10k *ar = hw->priv;
6032 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6033
6034 mutex_lock(&ar->conf_mutex);
6035
6036 ath10k_dbg(ar, ATH10K_DBG_MAC,
6037 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6038 arctx->conf.def.chan->center_freq,
6039 ctx->def.chan->center_freq,
6040 arctx->conf.def.width, ctx->def.width,
6041 ctx, changed);
6042
6043 /* This shouldn't really happen because channel switching should use
6044 * switch_vif_chanctx().
6045 */
6046 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6047 goto unlock;
6048
6049 spin_lock_bh(&ar->data_lock);
6050 arctx->conf = *ctx;
6051 spin_unlock_bh(&ar->data_lock);
6052
6053 ath10k_recalc_radar_detection(ar);
6054
6055 /* FIXME: How to configure Rx chains properly? */
6056
6057 /* No other actions are actually necessary. Firmware maintains channel
6058 * definitions per vdev internally and there's no host-side channel
6059 * context abstraction to configure, e.g. channel width.
6060 */
6061
6062unlock:
6063 mutex_unlock(&ar->conf_mutex);
6064}
6065
6066static int
6067ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6068 struct ieee80211_vif *vif,
6069 struct ieee80211_chanctx_conf *ctx)
6070{
6071 struct ath10k *ar = hw->priv;
6072 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6073 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6074 int ret;
6075
6076 mutex_lock(&ar->conf_mutex);
6077
6078 ath10k_dbg(ar, ATH10K_DBG_MAC,
6079 "mac chanctx assign ptr %p vdev_id %i\n",
6080 ctx, arvif->vdev_id);
6081
6082 if (WARN_ON(arvif->is_started)) {
6083 mutex_unlock(&ar->conf_mutex);
6084 return -EBUSY;
6085 }
6086
6087 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6088 if (ret) {
6089 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6090 arvif->vdev_id, vif->addr,
6091 arctx->conf.def.chan->center_freq, ret);
6092 goto err;
6093 }
6094
6095 arvif->is_started = true;
6096
6097 if (vif->type == NL80211_IFTYPE_MONITOR) {
6098 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6099 if (ret) {
6100 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6101 arvif->vdev_id, ret);
6102 goto err_stop;
6103 }
6104
6105 arvif->is_up = true;
6106 }
6107
6108 mutex_unlock(&ar->conf_mutex);
6109 return 0;
6110
6111err_stop:
6112 ath10k_vdev_stop(arvif);
6113 arvif->is_started = false;
6114
6115err:
6116 mutex_unlock(&ar->conf_mutex);
6117 return ret;
6118}
6119
6120static void
6121ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6122 struct ieee80211_vif *vif,
6123 struct ieee80211_chanctx_conf *ctx)
6124{
6125 struct ath10k *ar = hw->priv;
6126 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6127 int ret;
6128
6129 mutex_lock(&ar->conf_mutex);
6130
6131 ath10k_dbg(ar, ATH10K_DBG_MAC,
6132 "mac chanctx unassign ptr %p vdev_id %i\n",
6133 ctx, arvif->vdev_id);
6134
6135 WARN_ON(!arvif->is_started);
6136
6137 if (vif->type == NL80211_IFTYPE_MONITOR) {
6138 WARN_ON(!arvif->is_up);
6139
6140 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6141 if (ret)
6142 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6143 arvif->vdev_id, ret);
6144
6145 arvif->is_up = false;
6146 }
6147
6148 ret = ath10k_vdev_stop(arvif);
6149 if (ret)
6150 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6151 arvif->vdev_id, ret);
6152
6153 arvif->is_started = false;
6154
6155 mutex_unlock(&ar->conf_mutex);
6156}
6157
6158static int
6159ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6160 struct ieee80211_vif_chanctx_switch *vifs,
6161 int n_vifs,
6162 enum ieee80211_chanctx_switch_mode mode)
6163{
6164 struct ath10k *ar = hw->priv;
6165 struct ath10k_vif *arvif;
6166 struct ath10k_chanctx *arctx_new, *arctx_old;
6167 int i;
6168
6169 mutex_lock(&ar->conf_mutex);
6170
6171 ath10k_dbg(ar, ATH10K_DBG_MAC,
6172 "mac chanctx switch n_vifs %d mode %d\n",
6173 n_vifs, mode);
6174
6175 spin_lock_bh(&ar->data_lock);
6176 for (i = 0; i < n_vifs; i++) {
6177 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6178 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6179 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6180
6181 ath10k_dbg(ar, ATH10K_DBG_MAC,
6182 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6183 arvif->vdev_id,
6184 vifs[i].old_ctx->def.chan->center_freq,
6185 vifs[i].new_ctx->def.chan->center_freq,
6186 vifs[i].old_ctx->def.width,
6187 vifs[i].new_ctx->def.width,
6188 arctx_old, arctx_new);
6189
6190 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6191 ath10k_mac_chan_ctx_init(ar, arctx_new,
6192 vifs[i].new_ctx);
6193 }
6194
6195 arctx_new->conf = *vifs[i].new_ctx;
6196
6197 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6198 * yet updated chanctx_conf pointer.
6199 */
6200 arctx_old->conf = *vifs[i].new_ctx;
6201 }
6202 ath10k_mac_update_rx_channel(ar);
6203 spin_unlock_bh(&ar->data_lock);
6204
6205 /* FIXME: Reconfigure only affected vifs */
6206 ath10k_mac_chan_reconfigure(ar);
6207
6208 mutex_unlock(&ar->conf_mutex);
6209 return 0;
6210}
6211
Kalle Valo5e3dd152013-06-12 20:52:10 +03006212static const struct ieee80211_ops ath10k_ops = {
6213 .tx = ath10k_tx,
6214 .start = ath10k_start,
6215 .stop = ath10k_stop,
6216 .config = ath10k_config,
6217 .add_interface = ath10k_add_interface,
6218 .remove_interface = ath10k_remove_interface,
6219 .configure_filter = ath10k_configure_filter,
6220 .bss_info_changed = ath10k_bss_info_changed,
6221 .hw_scan = ath10k_hw_scan,
6222 .cancel_hw_scan = ath10k_cancel_hw_scan,
6223 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006224 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006225 .sta_state = ath10k_sta_state,
6226 .conf_tx = ath10k_conf_tx,
6227 .remain_on_channel = ath10k_remain_on_channel,
6228 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6229 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006230 .flush = ath10k_flush,
6231 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006232 .set_antenna = ath10k_set_antenna,
6233 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006234 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006235 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006236 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006237 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006238 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006239 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006240 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6241 .get_et_stats = ath10k_debug_get_et_stats,
6242 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006243 .add_chanctx = ath10k_mac_op_add_chanctx,
6244 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6245 .change_chanctx = ath10k_mac_op_change_chanctx,
6246 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6247 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6248 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006249
6250 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6251
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006252#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006253 .suspend = ath10k_wow_op_suspend,
6254 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006255#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006256#ifdef CONFIG_MAC80211_DEBUGFS
6257 .sta_add_debugfs = ath10k_sta_add_debugfs,
6258#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006259};
6260
Kalle Valo5e3dd152013-06-12 20:52:10 +03006261#define CHAN2G(_channel, _freq, _flags) { \
6262 .band = IEEE80211_BAND_2GHZ, \
6263 .hw_value = (_channel), \
6264 .center_freq = (_freq), \
6265 .flags = (_flags), \
6266 .max_antenna_gain = 0, \
6267 .max_power = 30, \
6268}
6269
6270#define CHAN5G(_channel, _freq, _flags) { \
6271 .band = IEEE80211_BAND_5GHZ, \
6272 .hw_value = (_channel), \
6273 .center_freq = (_freq), \
6274 .flags = (_flags), \
6275 .max_antenna_gain = 0, \
6276 .max_power = 30, \
6277}
6278
6279static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6280 CHAN2G(1, 2412, 0),
6281 CHAN2G(2, 2417, 0),
6282 CHAN2G(3, 2422, 0),
6283 CHAN2G(4, 2427, 0),
6284 CHAN2G(5, 2432, 0),
6285 CHAN2G(6, 2437, 0),
6286 CHAN2G(7, 2442, 0),
6287 CHAN2G(8, 2447, 0),
6288 CHAN2G(9, 2452, 0),
6289 CHAN2G(10, 2457, 0),
6290 CHAN2G(11, 2462, 0),
6291 CHAN2G(12, 2467, 0),
6292 CHAN2G(13, 2472, 0),
6293 CHAN2G(14, 2484, 0),
6294};
6295
6296static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006297 CHAN5G(36, 5180, 0),
6298 CHAN5G(40, 5200, 0),
6299 CHAN5G(44, 5220, 0),
6300 CHAN5G(48, 5240, 0),
6301 CHAN5G(52, 5260, 0),
6302 CHAN5G(56, 5280, 0),
6303 CHAN5G(60, 5300, 0),
6304 CHAN5G(64, 5320, 0),
6305 CHAN5G(100, 5500, 0),
6306 CHAN5G(104, 5520, 0),
6307 CHAN5G(108, 5540, 0),
6308 CHAN5G(112, 5560, 0),
6309 CHAN5G(116, 5580, 0),
6310 CHAN5G(120, 5600, 0),
6311 CHAN5G(124, 5620, 0),
6312 CHAN5G(128, 5640, 0),
6313 CHAN5G(132, 5660, 0),
6314 CHAN5G(136, 5680, 0),
6315 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006316 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006317 CHAN5G(149, 5745, 0),
6318 CHAN5G(153, 5765, 0),
6319 CHAN5G(157, 5785, 0),
6320 CHAN5G(161, 5805, 0),
6321 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006322};
6323
Michal Kaziore7b54192014-08-07 11:03:27 +02006324struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006325{
6326 struct ieee80211_hw *hw;
6327 struct ath10k *ar;
6328
Michal Kaziore7b54192014-08-07 11:03:27 +02006329 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006330 if (!hw)
6331 return NULL;
6332
6333 ar = hw->priv;
6334 ar->hw = hw;
6335
6336 return ar;
6337}
6338
6339void ath10k_mac_destroy(struct ath10k *ar)
6340{
6341 ieee80211_free_hw(ar->hw);
6342}
6343
6344static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6345 {
6346 .max = 8,
6347 .types = BIT(NL80211_IFTYPE_STATION)
6348 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006349 },
6350 {
6351 .max = 3,
6352 .types = BIT(NL80211_IFTYPE_P2P_GO)
6353 },
6354 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006355 .max = 1,
6356 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6357 },
6358 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006359 .max = 7,
6360 .types = BIT(NL80211_IFTYPE_AP)
6361 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006362};
6363
Bartosz Markowskif2595092013-12-10 16:20:39 +01006364static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006365 {
6366 .max = 8,
6367 .types = BIT(NL80211_IFTYPE_AP)
6368 },
6369};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006370
6371static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6372 {
6373 .limits = ath10k_if_limits,
6374 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6375 .max_interfaces = 8,
6376 .num_different_channels = 1,
6377 .beacon_int_infra_match = true,
6378 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006379};
6380
6381static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006382 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006383 .limits = ath10k_10x_if_limits,
6384 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006385 .max_interfaces = 8,
6386 .num_different_channels = 1,
6387 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006388#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006389 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6390 BIT(NL80211_CHAN_WIDTH_20) |
6391 BIT(NL80211_CHAN_WIDTH_40) |
6392 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006393#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006394 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006395};
6396
Michal Kaziorcf327842015-03-31 10:26:25 +00006397static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6398 {
6399 .max = 2,
6400 .types = BIT(NL80211_IFTYPE_STATION) |
6401 BIT(NL80211_IFTYPE_AP) |
6402 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6403 BIT(NL80211_IFTYPE_P2P_GO),
6404 },
6405 {
6406 .max = 1,
6407 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6408 },
6409};
6410
6411static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6412 {
6413 .max = 1,
6414 .types = BIT(NL80211_IFTYPE_STATION),
6415 },
6416 {
6417 .max = 1,
6418 .types = BIT(NL80211_IFTYPE_ADHOC),
6419 },
6420};
6421
6422/* FIXME: This is not thouroughly tested. These combinations may over- or
6423 * underestimate hw/fw capabilities.
6424 */
6425static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6426 {
6427 .limits = ath10k_tlv_if_limit,
6428 .num_different_channels = 1,
6429 .max_interfaces = 3,
6430 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6431 },
6432 {
6433 .limits = ath10k_tlv_if_limit_ibss,
6434 .num_different_channels = 1,
6435 .max_interfaces = 2,
6436 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6437 },
6438};
6439
6440static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6441 {
6442 .limits = ath10k_tlv_if_limit,
6443 .num_different_channels = 2,
6444 .max_interfaces = 3,
6445 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6446 },
6447 {
6448 .limits = ath10k_tlv_if_limit_ibss,
6449 .num_different_channels = 1,
6450 .max_interfaces = 2,
6451 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6452 },
6453};
6454
Kalle Valo5e3dd152013-06-12 20:52:10 +03006455static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6456{
6457 struct ieee80211_sta_vht_cap vht_cap = {0};
6458 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006459 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006460 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006461
6462 vht_cap.vht_supported = 1;
6463 vht_cap.cap = ar->vht_cap_info;
6464
Michal Kaziorbc657a362015-02-26 11:11:22 +01006465 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6466 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6467 val = ar->num_rf_chains - 1;
6468 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6469 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6470
6471 vht_cap.cap |= val;
6472 }
6473
6474 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6475 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6476 val = ar->num_rf_chains - 1;
6477 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6478 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6479
6480 vht_cap.cap |= val;
6481 }
6482
Michal Kazior8865bee42013-07-24 12:36:46 +02006483 mcs_map = 0;
6484 for (i = 0; i < 8; i++) {
6485 if (i < ar->num_rf_chains)
6486 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6487 else
6488 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6489 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006490
6491 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6492 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6493
6494 return vht_cap;
6495}
6496
6497static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6498{
6499 int i;
6500 struct ieee80211_sta_ht_cap ht_cap = {0};
6501
6502 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6503 return ht_cap;
6504
6505 ht_cap.ht_supported = 1;
6506 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6507 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6508 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6509 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6510 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6511
6512 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6513 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6514
6515 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6516 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6517
6518 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6519 u32 smps;
6520
6521 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6522 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6523
6524 ht_cap.cap |= smps;
6525 }
6526
6527 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6528 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6529
6530 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6531 u32 stbc;
6532
6533 stbc = ar->ht_cap_info;
6534 stbc &= WMI_HT_CAP_RX_STBC;
6535 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6536 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6537 stbc &= IEEE80211_HT_CAP_RX_STBC;
6538
6539 ht_cap.cap |= stbc;
6540 }
6541
6542 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6543 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6544
6545 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6546 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6547
6548 /* max AMSDU is implicitly taken from vht_cap_info */
6549 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6550 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6551
Michal Kazior8865bee42013-07-24 12:36:46 +02006552 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006553 ht_cap.mcs.rx_mask[i] = 0xFF;
6554
6555 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6556
6557 return ht_cap;
6558}
6559
Kalle Valo5e3dd152013-06-12 20:52:10 +03006560static void ath10k_get_arvif_iter(void *data, u8 *mac,
6561 struct ieee80211_vif *vif)
6562{
6563 struct ath10k_vif_iter *arvif_iter = data;
6564 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6565
6566 if (arvif->vdev_id == arvif_iter->vdev_id)
6567 arvif_iter->arvif = arvif;
6568}
6569
6570struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6571{
6572 struct ath10k_vif_iter arvif_iter;
6573 u32 flags;
6574
6575 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6576 arvif_iter.vdev_id = vdev_id;
6577
6578 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6579 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6580 flags,
6581 ath10k_get_arvif_iter,
6582 &arvif_iter);
6583 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006584 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006585 return NULL;
6586 }
6587
6588 return arvif_iter.arvif;
6589}
6590
6591int ath10k_mac_register(struct ath10k *ar)
6592{
Johannes Berg3cb10942015-01-22 21:38:45 +01006593 static const u32 cipher_suites[] = {
6594 WLAN_CIPHER_SUITE_WEP40,
6595 WLAN_CIPHER_SUITE_WEP104,
6596 WLAN_CIPHER_SUITE_TKIP,
6597 WLAN_CIPHER_SUITE_CCMP,
6598 WLAN_CIPHER_SUITE_AES_CMAC,
6599 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006600 struct ieee80211_supported_band *band;
6601 struct ieee80211_sta_vht_cap vht_cap;
6602 struct ieee80211_sta_ht_cap ht_cap;
6603 void *channels;
6604 int ret;
6605
6606 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6607
6608 SET_IEEE80211_DEV(ar->hw, ar->dev);
6609
6610 ht_cap = ath10k_get_ht_cap(ar);
6611 vht_cap = ath10k_create_vht_cap(ar);
6612
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006613 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6614 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6615 ATH10K_NUM_CHANS);
6616
Kalle Valo5e3dd152013-06-12 20:52:10 +03006617 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6618 channels = kmemdup(ath10k_2ghz_channels,
6619 sizeof(ath10k_2ghz_channels),
6620 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006621 if (!channels) {
6622 ret = -ENOMEM;
6623 goto err_free;
6624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006625
6626 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6627 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6628 band->channels = channels;
6629 band->n_bitrates = ath10k_g_rates_size;
6630 band->bitrates = ath10k_g_rates;
6631 band->ht_cap = ht_cap;
6632
Yanbo Lid68bb122015-01-23 08:18:20 +08006633 /* Enable the VHT support at 2.4 GHz */
6634 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006635
6636 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6637 }
6638
6639 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6640 channels = kmemdup(ath10k_5ghz_channels,
6641 sizeof(ath10k_5ghz_channels),
6642 GFP_KERNEL);
6643 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006644 ret = -ENOMEM;
6645 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006646 }
6647
6648 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6649 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6650 band->channels = channels;
6651 band->n_bitrates = ath10k_a_rates_size;
6652 band->bitrates = ath10k_a_rates;
6653 band->ht_cap = ht_cap;
6654 band->vht_cap = vht_cap;
6655 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6656 }
6657
6658 ar->hw->wiphy->interface_modes =
6659 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006660 BIT(NL80211_IFTYPE_AP);
6661
Ben Greear46acf7b2014-05-16 17:15:38 +03006662 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6663 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6664
Bartosz Markowskid3541812013-12-10 16:20:40 +01006665 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6666 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006667 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006668 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6669 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006670
6671 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6672 IEEE80211_HW_SUPPORTS_PS |
6673 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006674 IEEE80211_HW_MFP_CAPABLE |
6675 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6676 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006677 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006678 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006679 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006680 IEEE80211_HW_CONNECTION_MONITOR |
6681 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006682 IEEE80211_HW_CHANCTX_STA_CSA |
6683 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006684
Eliad Peller0d8614b2014-09-10 14:07:36 +03006685 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6686
Kalle Valo5e3dd152013-06-12 20:52:10 +03006687 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006688 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006689
6690 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6691 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6692 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6693 }
6694
6695 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6696 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6697
6698 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006699 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006700 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006701
Kalle Valo5e3dd152013-06-12 20:52:10 +03006702 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6703
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006704 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6705 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6706
6707 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6708 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6709 * correct Probe Responses. This is more of a hack advert..
6710 */
6711 ar->hw->wiphy->probe_resp_offload |=
6712 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6713 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6714 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6715 }
6716
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006717 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6718 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6719
Kalle Valo5e3dd152013-06-12 20:52:10 +03006720 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006721 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006722 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6723
6724 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006725 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6726
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006727 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6728
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006729 ret = ath10k_wow_init(ar);
6730 if (ret) {
6731 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6732 goto err_free;
6733 }
6734
Kalle Valo5e3dd152013-06-12 20:52:10 +03006735 /*
6736 * on LL hardware queues are managed entirely by the FW
6737 * so we only advertise to mac we can do the queues thing
6738 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006739 ar->hw->queues = IEEE80211_MAX_QUEUES;
6740
6741 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6742 * something that vdev_ids can't reach so that we don't stop the queue
6743 * accidentally.
6744 */
6745 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006746
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006747 switch (ar->wmi.op_version) {
6748 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006749 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6750 ar->hw->wiphy->n_iface_combinations =
6751 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006752 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006753 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006754 case ATH10K_FW_WMI_OP_VERSION_TLV:
6755 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6756 ar->hw->wiphy->iface_combinations =
6757 ath10k_tlv_qcs_if_comb;
6758 ar->hw->wiphy->n_iface_combinations =
6759 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
6760 } else {
6761 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
6762 ar->hw->wiphy->n_iface_combinations =
6763 ARRAY_SIZE(ath10k_tlv_if_comb);
6764 }
6765 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6766 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006767 case ATH10K_FW_WMI_OP_VERSION_10_1:
6768 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006769 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006770 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6771 ar->hw->wiphy->n_iface_combinations =
6772 ARRAY_SIZE(ath10k_10x_if_comb);
6773 break;
6774 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6775 case ATH10K_FW_WMI_OP_VERSION_MAX:
6776 WARN_ON(1);
6777 ret = -EINVAL;
6778 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006779 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006780
Michal Kazior7c199992013-07-31 10:47:57 +02006781 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6782
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006783 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6784 /* Init ath dfs pattern detector */
6785 ar->ath_common.debug_mask = ATH_DBG_DFS;
6786 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6787 NL80211_DFS_UNSET);
6788
6789 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006790 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006791 }
6792
Kalle Valo5e3dd152013-06-12 20:52:10 +03006793 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6794 ath10k_reg_notifier);
6795 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006796 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006797 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006798 }
6799
Johannes Berg3cb10942015-01-22 21:38:45 +01006800 ar->hw->wiphy->cipher_suites = cipher_suites;
6801 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6802
Kalle Valo5e3dd152013-06-12 20:52:10 +03006803 ret = ieee80211_register_hw(ar->hw);
6804 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006805 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006806 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006807 }
6808
6809 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6810 ret = regulatory_hint(ar->hw->wiphy,
6811 ar->ath_common.regulatory.alpha2);
6812 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006813 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006814 }
6815
6816 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006817
6818err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006819 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006820err_free:
6821 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6822 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6823
Kalle Valo5e3dd152013-06-12 20:52:10 +03006824 return ret;
6825}
6826
6827void ath10k_mac_unregister(struct ath10k *ar)
6828{
6829 ieee80211_unregister_hw(ar->hw);
6830
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006831 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6832 ar->dfs_detector->exit(ar->dfs_detector);
6833
Kalle Valo5e3dd152013-06-12 20:52:10 +03006834 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6835 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6836
6837 SET_IEEE80211_DEV(ar->hw, NULL);
6838}