blob: 52cf3e18929116ad5fe39efe4454b2a306358dbf [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 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004653 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4654 *
4655 * FIXME: It remains unknown if this is required for multi-vif STA
4656 * interfaces on 10.1.
4657 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004658
Michal Kazior8461baf2015-04-10 13:23:22 +00004659 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4660 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004661 return;
4662
4663 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4664 return;
4665
4666 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4667 return;
4668
4669 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4670 return;
4671
4672 if (cmd != SET_KEY)
4673 return;
4674
4675 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4676 key->keyidx);
4677 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004678 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004679 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004680}
4681
Kalle Valo5e3dd152013-06-12 20:52:10 +03004682static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4683 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4684 struct ieee80211_key_conf *key)
4685{
4686 struct ath10k *ar = hw->priv;
4687 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4688 struct ath10k_peer *peer;
4689 const u8 *peer_addr;
4690 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4691 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4692 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004693 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004694 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004695 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004696
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004697 /* this one needs to be done in software */
4698 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4699 return 1;
4700
Kalle Valo5e3dd152013-06-12 20:52:10 +03004701 if (key->keyidx > WMI_MAX_KEY_INDEX)
4702 return -ENOSPC;
4703
4704 mutex_lock(&ar->conf_mutex);
4705
4706 if (sta)
4707 peer_addr = sta->addr;
4708 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4709 peer_addr = vif->bss_conf.bssid;
4710 else
4711 peer_addr = vif->addr;
4712
4713 key->hw_key_idx = key->keyidx;
4714
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004715 if (is_wep) {
4716 if (cmd == SET_KEY)
4717 arvif->wep_keys[key->keyidx] = key;
4718 else
4719 arvif->wep_keys[key->keyidx] = NULL;
4720 }
4721
Kalle Valo5e3dd152013-06-12 20:52:10 +03004722 /* the peer should not disappear in mid-way (unless FW goes awry) since
4723 * we already hold conf_mutex. we just make sure its there now. */
4724 spin_lock_bh(&ar->data_lock);
4725 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4726 spin_unlock_bh(&ar->data_lock);
4727
4728 if (!peer) {
4729 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004730 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004731 peer_addr);
4732 ret = -EOPNOTSUPP;
4733 goto exit;
4734 } else {
4735 /* if the peer doesn't exist there is no key to disable
4736 * anymore */
4737 goto exit;
4738 }
4739 }
4740
Michal Kazior7cc45732015-03-09 14:24:17 +01004741 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4742 flags |= WMI_KEY_PAIRWISE;
4743 else
4744 flags |= WMI_KEY_GROUP;
4745
Kalle Valo5e3dd152013-06-12 20:52:10 +03004746 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004747 if (cmd == DISABLE_KEY)
4748 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004749
Michal Kaziorad325cb2015-02-18 14:02:27 +01004750 /* When WEP keys are uploaded it's possible that there are
4751 * stations associated already (e.g. when merging) without any
4752 * keys. Static WEP needs an explicit per-peer key upload.
4753 */
4754 if (vif->type == NL80211_IFTYPE_ADHOC &&
4755 cmd == SET_KEY)
4756 ath10k_mac_vif_update_wep_key(arvif, key);
4757
Michal Kazior370e5672015-02-18 14:02:26 +01004758 /* 802.1x never sets the def_wep_key_idx so each set_key()
4759 * call changes default tx key.
4760 *
4761 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4762 * after first set_key().
4763 */
4764 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4765 flags |= WMI_KEY_TX_USAGE;
Michal Kazior370e5672015-02-18 14:02:26 +01004766 }
4767
4768 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004770 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004771 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004772 goto exit;
4773 }
4774
Michal Kazior29a10002015-04-10 13:05:58 +00004775 /* mac80211 sets static WEP keys as groupwise while firmware requires
4776 * them to be installed twice as both pairwise and groupwise.
4777 */
4778 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4779 flags2 = flags;
4780 flags2 &= ~WMI_KEY_GROUP;
4781 flags2 |= WMI_KEY_PAIRWISE;
4782
4783 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4784 if (ret) {
4785 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4786 arvif->vdev_id, peer_addr, ret);
4787 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4788 peer_addr, flags);
4789 if (ret2)
4790 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4791 arvif->vdev_id, peer_addr, ret2);
4792 goto exit;
4793 }
4794 }
4795
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004796 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4797
Kalle Valo5e3dd152013-06-12 20:52:10 +03004798 spin_lock_bh(&ar->data_lock);
4799 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4800 if (peer && cmd == SET_KEY)
4801 peer->keys[key->keyidx] = key;
4802 else if (peer && cmd == DISABLE_KEY)
4803 peer->keys[key->keyidx] = NULL;
4804 else if (peer == NULL)
4805 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004806 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004807 spin_unlock_bh(&ar->data_lock);
4808
4809exit:
4810 mutex_unlock(&ar->conf_mutex);
4811 return ret;
4812}
4813
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004814static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4815 struct ieee80211_vif *vif,
4816 int keyidx)
4817{
4818 struct ath10k *ar = hw->priv;
4819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4820 int ret;
4821
4822 mutex_lock(&arvif->ar->conf_mutex);
4823
4824 if (arvif->ar->state != ATH10K_STATE_ON)
4825 goto unlock;
4826
4827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4828 arvif->vdev_id, keyidx);
4829
4830 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4831 arvif->vdev_id,
4832 arvif->ar->wmi.vdev_param->def_keyid,
4833 keyidx);
4834
4835 if (ret) {
4836 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4837 arvif->vdev_id,
4838 ret);
4839 goto unlock;
4840 }
4841
4842 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004843
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004844unlock:
4845 mutex_unlock(&arvif->ar->conf_mutex);
4846}
4847
Michal Kazior9797feb2014-02-14 14:49:48 +01004848static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4849{
4850 struct ath10k *ar;
4851 struct ath10k_vif *arvif;
4852 struct ath10k_sta *arsta;
4853 struct ieee80211_sta *sta;
4854 u32 changed, bw, nss, smps;
4855 int err;
4856
4857 arsta = container_of(wk, struct ath10k_sta, update_wk);
4858 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4859 arvif = arsta->arvif;
4860 ar = arvif->ar;
4861
4862 spin_lock_bh(&ar->data_lock);
4863
4864 changed = arsta->changed;
4865 arsta->changed = 0;
4866
4867 bw = arsta->bw;
4868 nss = arsta->nss;
4869 smps = arsta->smps;
4870
4871 spin_unlock_bh(&ar->data_lock);
4872
4873 mutex_lock(&ar->conf_mutex);
4874
4875 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004876 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004877 sta->addr, bw);
4878
4879 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4880 WMI_PEER_CHAN_WIDTH, bw);
4881 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004882 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004883 sta->addr, bw, err);
4884 }
4885
4886 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004887 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004888 sta->addr, nss);
4889
4890 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4891 WMI_PEER_NSS, nss);
4892 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004893 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004894 sta->addr, nss, err);
4895 }
4896
4897 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004898 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004899 sta->addr, smps);
4900
4901 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4902 WMI_PEER_SMPS_STATE, smps);
4903 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004904 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004905 sta->addr, smps, err);
4906 }
4907
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004908 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4909 changed & IEEE80211_RC_NSS_CHANGED) {
4910 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004911 sta->addr);
4912
Michal Kazior590922a2014-10-21 10:10:29 +03004913 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004914 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004915 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004916 sta->addr);
4917 }
4918
Michal Kazior9797feb2014-02-14 14:49:48 +01004919 mutex_unlock(&ar->conf_mutex);
4920}
4921
Marek Puzyniak7c354242015-03-30 09:51:52 +03004922static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4923 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004924{
4925 struct ath10k *ar = arvif->ar;
4926
4927 lockdep_assert_held(&ar->conf_mutex);
4928
Marek Puzyniak7c354242015-03-30 09:51:52 +03004929 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004930 return 0;
4931
4932 if (ar->num_stations >= ar->max_num_stations)
4933 return -ENOBUFS;
4934
4935 ar->num_stations++;
4936
4937 return 0;
4938}
4939
Marek Puzyniak7c354242015-03-30 09:51:52 +03004940static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4941 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004942{
4943 struct ath10k *ar = arvif->ar;
4944
4945 lockdep_assert_held(&ar->conf_mutex);
4946
Marek Puzyniak7c354242015-03-30 09:51:52 +03004947 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004948 return;
4949
4950 ar->num_stations--;
4951}
4952
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004953struct ath10k_mac_tdls_iter_data {
4954 u32 num_tdls_stations;
4955 struct ieee80211_vif *curr_vif;
4956};
4957
4958static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4959 struct ieee80211_sta *sta)
4960{
4961 struct ath10k_mac_tdls_iter_data *iter_data = data;
4962 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4963 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4964
4965 if (sta->tdls && sta_vif == iter_data->curr_vif)
4966 iter_data->num_tdls_stations++;
4967}
4968
4969static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4970 struct ieee80211_vif *vif)
4971{
4972 struct ath10k_mac_tdls_iter_data data = {};
4973
4974 data.curr_vif = vif;
4975
4976 ieee80211_iterate_stations_atomic(hw,
4977 ath10k_mac_tdls_vif_stations_count_iter,
4978 &data);
4979 return data.num_tdls_stations;
4980}
4981
4982static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4983 struct ieee80211_vif *vif)
4984{
4985 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4986 int *num_tdls_vifs = data;
4987
4988 if (vif->type != NL80211_IFTYPE_STATION)
4989 return;
4990
4991 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4992 (*num_tdls_vifs)++;
4993}
4994
4995static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4996{
4997 int num_tdls_vifs = 0;
4998
4999 ieee80211_iterate_active_interfaces_atomic(hw,
5000 IEEE80211_IFACE_ITER_NORMAL,
5001 ath10k_mac_tdls_vifs_count_iter,
5002 &num_tdls_vifs);
5003 return num_tdls_vifs;
5004}
5005
Kalle Valo5e3dd152013-06-12 20:52:10 +03005006static int ath10k_sta_state(struct ieee80211_hw *hw,
5007 struct ieee80211_vif *vif,
5008 struct ieee80211_sta *sta,
5009 enum ieee80211_sta_state old_state,
5010 enum ieee80211_sta_state new_state)
5011{
5012 struct ath10k *ar = hw->priv;
5013 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005014 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005015 int ret = 0;
5016
Michal Kazior76f90022014-02-25 09:29:57 +02005017 if (old_state == IEEE80211_STA_NOTEXIST &&
5018 new_state == IEEE80211_STA_NONE) {
5019 memset(arsta, 0, sizeof(*arsta));
5020 arsta->arvif = arvif;
5021 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5022 }
5023
Michal Kazior9797feb2014-02-14 14:49:48 +01005024 /* cancel must be done outside the mutex to avoid deadlock */
5025 if ((old_state == IEEE80211_STA_NONE &&
5026 new_state == IEEE80211_STA_NOTEXIST))
5027 cancel_work_sync(&arsta->update_wk);
5028
Kalle Valo5e3dd152013-06-12 20:52:10 +03005029 mutex_lock(&ar->conf_mutex);
5030
5031 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005032 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005033 /*
5034 * New station addition.
5035 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005036 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5037 u32 num_tdls_stations;
5038 u32 num_tdls_vifs;
5039
Michal Kaziorcfd10612014-11-25 15:16:05 +01005040 ath10k_dbg(ar, ATH10K_DBG_MAC,
5041 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5042 arvif->vdev_id, sta->addr,
5043 ar->num_stations + 1, ar->max_num_stations,
5044 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005045
Marek Puzyniak7c354242015-03-30 09:51:52 +03005046 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005047 if (ret) {
5048 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5049 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005050 goto exit;
5051 }
5052
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005053 if (sta->tdls)
5054 peer_type = WMI_PEER_TYPE_TDLS;
5055
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005056 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005057 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005059 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 -08005060 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005061 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005062 goto exit;
5063 }
Michal Kazior077efc82014-10-21 10:10:29 +03005064
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005065 if (!sta->tdls)
5066 goto exit;
5067
5068 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5069 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5070
5071 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5072 num_tdls_stations == 0) {
5073 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5074 arvif->vdev_id, ar->max_num_tdls_vdevs);
5075 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5076 ath10k_mac_dec_num_stations(arvif, sta);
5077 ret = -ENOBUFS;
5078 goto exit;
5079 }
5080
5081 if (num_tdls_stations == 0) {
5082 /* This is the first tdls peer in current vif */
5083 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5084
5085 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5086 state);
5087 if (ret) {
5088 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5089 arvif->vdev_id, ret);
5090 ath10k_peer_delete(ar, arvif->vdev_id,
5091 sta->addr);
5092 ath10k_mac_dec_num_stations(arvif, sta);
5093 goto exit;
5094 }
5095 }
5096
5097 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5098 WMI_TDLS_PEER_STATE_PEERING);
5099 if (ret) {
5100 ath10k_warn(ar,
5101 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5102 sta->addr, arvif->vdev_id, ret);
5103 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5104 ath10k_mac_dec_num_stations(arvif, sta);
5105
5106 if (num_tdls_stations != 0)
5107 goto exit;
5108 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5109 WMI_TDLS_DISABLE);
5110 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005111 } else if ((old_state == IEEE80211_STA_NONE &&
5112 new_state == IEEE80211_STA_NOTEXIST)) {
5113 /*
5114 * Existing station deletion.
5115 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005116 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005117 "mac vdev %d peer delete %pM (sta gone)\n",
5118 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005119
Kalle Valo5e3dd152013-06-12 20:52:10 +03005120 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5121 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005122 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005123 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005124
Marek Puzyniak7c354242015-03-30 09:51:52 +03005125 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005126
5127 if (!sta->tdls)
5128 goto exit;
5129
5130 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5131 goto exit;
5132
5133 /* This was the last tdls peer in current vif */
5134 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5135 WMI_TDLS_DISABLE);
5136 if (ret) {
5137 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5138 arvif->vdev_id, ret);
5139 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005140 } else if (old_state == IEEE80211_STA_AUTH &&
5141 new_state == IEEE80211_STA_ASSOC &&
5142 (vif->type == NL80211_IFTYPE_AP ||
5143 vif->type == NL80211_IFTYPE_ADHOC)) {
5144 /*
5145 * New association.
5146 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005147 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005148 sta->addr);
5149
Michal Kazior590922a2014-10-21 10:10:29 +03005150 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005151 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005152 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005153 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005154 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005155 new_state == IEEE80211_STA_AUTHORIZED &&
5156 sta->tdls) {
5157 /*
5158 * Tdls station authorized.
5159 */
5160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5161 sta->addr);
5162
5163 ret = ath10k_station_assoc(ar, vif, sta, false);
5164 if (ret) {
5165 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5166 sta->addr, arvif->vdev_id, ret);
5167 goto exit;
5168 }
5169
5170 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5171 WMI_TDLS_PEER_STATE_CONNECTED);
5172 if (ret)
5173 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5174 sta->addr, arvif->vdev_id, ret);
5175 } else if (old_state == IEEE80211_STA_ASSOC &&
5176 new_state == IEEE80211_STA_AUTH &&
5177 (vif->type == NL80211_IFTYPE_AP ||
5178 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005179 /*
5180 * Disassociation.
5181 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005182 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005183 sta->addr);
5184
Michal Kazior590922a2014-10-21 10:10:29 +03005185 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005186 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005187 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005188 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005189 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005190exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005191 mutex_unlock(&ar->conf_mutex);
5192 return ret;
5193}
5194
5195static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005196 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005197{
5198 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005199 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5200 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005201 u32 value = 0;
5202 int ret = 0;
5203
Michal Kazior548db542013-07-05 16:15:15 +03005204 lockdep_assert_held(&ar->conf_mutex);
5205
Kalle Valo5e3dd152013-06-12 20:52:10 +03005206 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5207 return 0;
5208
5209 switch (ac) {
5210 case IEEE80211_AC_VO:
5211 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5212 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005213 prio = 7;
5214 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005215 break;
5216 case IEEE80211_AC_VI:
5217 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5218 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005219 prio = 5;
5220 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005221 break;
5222 case IEEE80211_AC_BE:
5223 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5224 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005225 prio = 2;
5226 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005227 break;
5228 case IEEE80211_AC_BK:
5229 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5230 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005231 prio = 0;
5232 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005233 break;
5234 }
5235
5236 if (enable)
5237 arvif->u.sta.uapsd |= value;
5238 else
5239 arvif->u.sta.uapsd &= ~value;
5240
5241 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5242 WMI_STA_PS_PARAM_UAPSD,
5243 arvif->u.sta.uapsd);
5244 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005245 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005246 goto exit;
5247 }
5248
5249 if (arvif->u.sta.uapsd)
5250 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5251 else
5252 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5253
5254 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5255 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5256 value);
5257 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005258 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005259
Michal Kazior9f9b5742014-12-12 12:41:36 +01005260 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5261 if (ret) {
5262 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5263 arvif->vdev_id, ret);
5264 return ret;
5265 }
5266
5267 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5268 if (ret) {
5269 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5270 arvif->vdev_id, ret);
5271 return ret;
5272 }
5273
Michal Kaziorb0e56152015-01-24 12:14:52 +02005274 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5275 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5276 /* Only userspace can make an educated decision when to send
5277 * trigger frame. The following effectively disables u-UAPSD
5278 * autotrigger in firmware (which is enabled by default
5279 * provided the autotrigger service is available).
5280 */
5281
5282 arg.wmm_ac = acc;
5283 arg.user_priority = prio;
5284 arg.service_interval = 0;
5285 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5286 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5287
5288 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5289 arvif->bssid, &arg, 1);
5290 if (ret) {
5291 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5292 ret);
5293 return ret;
5294 }
5295 }
5296
Kalle Valo5e3dd152013-06-12 20:52:10 +03005297exit:
5298 return ret;
5299}
5300
5301static int ath10k_conf_tx(struct ieee80211_hw *hw,
5302 struct ieee80211_vif *vif, u16 ac,
5303 const struct ieee80211_tx_queue_params *params)
5304{
5305 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005306 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005307 struct wmi_wmm_params_arg *p = NULL;
5308 int ret;
5309
5310 mutex_lock(&ar->conf_mutex);
5311
5312 switch (ac) {
5313 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005314 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005315 break;
5316 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005317 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005318 break;
5319 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005320 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005321 break;
5322 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005323 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005324 break;
5325 }
5326
5327 if (WARN_ON(!p)) {
5328 ret = -EINVAL;
5329 goto exit;
5330 }
5331
5332 p->cwmin = params->cw_min;
5333 p->cwmax = params->cw_max;
5334 p->aifs = params->aifs;
5335
5336 /*
5337 * The channel time duration programmed in the HW is in absolute
5338 * microseconds, while mac80211 gives the txop in units of
5339 * 32 microseconds.
5340 */
5341 p->txop = params->txop * 32;
5342
Michal Kazior7fc979a2015-01-28 09:57:28 +02005343 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5344 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5345 &arvif->wmm_params);
5346 if (ret) {
5347 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5348 arvif->vdev_id, ret);
5349 goto exit;
5350 }
5351 } else {
5352 /* This won't work well with multi-interface cases but it's
5353 * better than nothing.
5354 */
5355 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5356 if (ret) {
5357 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5358 goto exit;
5359 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005360 }
5361
5362 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5363 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005364 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005365
5366exit:
5367 mutex_unlock(&ar->conf_mutex);
5368 return ret;
5369}
5370
5371#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5372
5373static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5374 struct ieee80211_vif *vif,
5375 struct ieee80211_channel *chan,
5376 int duration,
5377 enum ieee80211_roc_type type)
5378{
5379 struct ath10k *ar = hw->priv;
5380 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5381 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005382 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005383 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384
5385 mutex_lock(&ar->conf_mutex);
5386
5387 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005388 switch (ar->scan.state) {
5389 case ATH10K_SCAN_IDLE:
5390 reinit_completion(&ar->scan.started);
5391 reinit_completion(&ar->scan.completed);
5392 reinit_completion(&ar->scan.on_channel);
5393 ar->scan.state = ATH10K_SCAN_STARTING;
5394 ar->scan.is_roc = true;
5395 ar->scan.vdev_id = arvif->vdev_id;
5396 ar->scan.roc_freq = chan->center_freq;
5397 ret = 0;
5398 break;
5399 case ATH10K_SCAN_STARTING:
5400 case ATH10K_SCAN_RUNNING:
5401 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005402 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005403 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005404 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005405 spin_unlock_bh(&ar->data_lock);
5406
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005407 if (ret)
5408 goto exit;
5409
Michal Kaziorfcf98442015-03-31 11:03:47 +00005410 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005411
Kalle Valo5e3dd152013-06-12 20:52:10 +03005412 memset(&arg, 0, sizeof(arg));
5413 ath10k_wmi_start_scan_init(ar, &arg);
5414 arg.vdev_id = arvif->vdev_id;
5415 arg.scan_id = ATH10K_SCAN_ID;
5416 arg.n_channels = 1;
5417 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005418 arg.dwell_time_active = scan_time_msec;
5419 arg.dwell_time_passive = scan_time_msec;
5420 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005421 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5422 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005423 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005424
5425 ret = ath10k_start_scan(ar, &arg);
5426 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005427 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005428 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005429 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005430 spin_unlock_bh(&ar->data_lock);
5431 goto exit;
5432 }
5433
5434 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5435 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005436 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005437
5438 ret = ath10k_scan_stop(ar);
5439 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005440 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005441
Kalle Valo5e3dd152013-06-12 20:52:10 +03005442 ret = -ETIMEDOUT;
5443 goto exit;
5444 }
5445
Michal Kaziorfcf98442015-03-31 11:03:47 +00005446 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5447 msecs_to_jiffies(duration));
5448
Kalle Valo5e3dd152013-06-12 20:52:10 +03005449 ret = 0;
5450exit:
5451 mutex_unlock(&ar->conf_mutex);
5452 return ret;
5453}
5454
5455static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5456{
5457 struct ath10k *ar = hw->priv;
5458
5459 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005460 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005461 mutex_unlock(&ar->conf_mutex);
5462
Michal Kazior4eb2e162014-10-28 10:23:09 +01005463 cancel_delayed_work_sync(&ar->scan.timeout);
5464
Kalle Valo5e3dd152013-06-12 20:52:10 +03005465 return 0;
5466}
5467
5468/*
5469 * Both RTS and Fragmentation threshold are interface-specific
5470 * in ath10k, but device-specific in mac80211.
5471 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005472
5473static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5474{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005475 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005476 struct ath10k_vif *arvif;
5477 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005478
Michal Kaziorad088bf2013-10-16 15:44:46 +03005479 mutex_lock(&ar->conf_mutex);
5480 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005481 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005482 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005483
Michal Kaziorad088bf2013-10-16 15:44:46 +03005484 ret = ath10k_mac_set_rts(arvif, value);
5485 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005486 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005487 arvif->vdev_id, ret);
5488 break;
5489 }
5490 }
5491 mutex_unlock(&ar->conf_mutex);
5492
5493 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005494}
5495
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005496static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5497 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005498{
5499 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005500 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005501 int ret;
5502
5503 /* mac80211 doesn't care if we really xmit queued frames or not
5504 * we'll collect those frames either way if we stop/delete vdevs */
5505 if (drop)
5506 return;
5507
Michal Kazior548db542013-07-05 16:15:15 +03005508 mutex_lock(&ar->conf_mutex);
5509
Michal Kazioraffd3212013-07-16 09:54:35 +02005510 if (ar->state == ATH10K_STATE_WEDGED)
5511 goto skip;
5512
Michal Kazioredb82362013-07-05 16:15:14 +03005513 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005514 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005515
Michal Kazioredb82362013-07-05 16:15:14 +03005516 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005517 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005518 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005519
Michal Kazior7962b0d2014-10-28 10:34:38 +01005520 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5521 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5522 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005523
5524 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005525 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005526
5527 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005528 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005529 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005530
Michal Kazioraffd3212013-07-16 09:54:35 +02005531skip:
Michal Kazior548db542013-07-05 16:15:15 +03005532 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005533}
5534
5535/* TODO: Implement this function properly
5536 * For now it is needed to reply to Probe Requests in IBSS mode.
5537 * Propably we need this information from FW.
5538 */
5539static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5540{
5541 return 1;
5542}
5543
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005544static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5545 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005546{
5547 struct ath10k *ar = hw->priv;
5548
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005549 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5550 return;
5551
Michal Kazioraffd3212013-07-16 09:54:35 +02005552 mutex_lock(&ar->conf_mutex);
5553
5554 /* If device failed to restart it will be in a different state, e.g.
5555 * ATH10K_STATE_WEDGED */
5556 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005557 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005558 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005559 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005560 }
5561
5562 mutex_unlock(&ar->conf_mutex);
5563}
5564
Michal Kazior2e1dea42013-07-31 10:32:40 +02005565static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5566 struct survey_info *survey)
5567{
5568 struct ath10k *ar = hw->priv;
5569 struct ieee80211_supported_band *sband;
5570 struct survey_info *ar_survey = &ar->survey[idx];
5571 int ret = 0;
5572
5573 mutex_lock(&ar->conf_mutex);
5574
5575 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5576 if (sband && idx >= sband->n_channels) {
5577 idx -= sband->n_channels;
5578 sband = NULL;
5579 }
5580
5581 if (!sband)
5582 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5583
5584 if (!sband || idx >= sband->n_channels) {
5585 ret = -ENOENT;
5586 goto exit;
5587 }
5588
5589 spin_lock_bh(&ar->data_lock);
5590 memcpy(survey, ar_survey, sizeof(*survey));
5591 spin_unlock_bh(&ar->data_lock);
5592
5593 survey->channel = &sband->channels[idx];
5594
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005595 if (ar->rx_channel == survey->channel)
5596 survey->filled |= SURVEY_INFO_IN_USE;
5597
Michal Kazior2e1dea42013-07-31 10:32:40 +02005598exit:
5599 mutex_unlock(&ar->conf_mutex);
5600 return ret;
5601}
5602
Michal Kazior3ae54222015-03-31 10:49:20 +00005603static bool
5604ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5605 enum ieee80211_band band,
5606 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005607{
Michal Kazior3ae54222015-03-31 10:49:20 +00005608 int num_rates = 0;
5609 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005610
Michal Kazior3ae54222015-03-31 10:49:20 +00005611 num_rates += hweight32(mask->control[band].legacy);
5612
5613 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5614 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5615
5616 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5617 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5618
5619 return num_rates == 1;
5620}
5621
5622static bool
5623ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5624 enum ieee80211_band band,
5625 const struct cfg80211_bitrate_mask *mask,
5626 int *nss)
5627{
5628 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5629 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5630 u8 ht_nss_mask = 0;
5631 u8 vht_nss_mask = 0;
5632 int i;
5633
5634 if (mask->control[band].legacy)
5635 return false;
5636
5637 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5638 if (mask->control[band].ht_mcs[i] == 0)
5639 continue;
5640 else if (mask->control[band].ht_mcs[i] ==
5641 sband->ht_cap.mcs.rx_mask[i])
5642 ht_nss_mask |= BIT(i);
5643 else
5644 return false;
5645 }
5646
5647 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5648 if (mask->control[band].vht_mcs[i] == 0)
5649 continue;
5650 else if (mask->control[band].vht_mcs[i] ==
5651 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5652 vht_nss_mask |= BIT(i);
5653 else
5654 return false;
5655 }
5656
5657 if (ht_nss_mask != vht_nss_mask)
5658 return false;
5659
5660 if (ht_nss_mask == 0)
5661 return false;
5662
5663 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5664 return false;
5665
5666 *nss = fls(ht_nss_mask);
5667
5668 return true;
5669}
5670
5671static int
5672ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5673 enum ieee80211_band band,
5674 const struct cfg80211_bitrate_mask *mask,
5675 u8 *rate, u8 *nss)
5676{
5677 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5678 int rate_idx;
5679 int i;
5680 u16 bitrate;
5681 u8 preamble;
5682 u8 hw_rate;
5683
5684 if (hweight32(mask->control[band].legacy) == 1) {
5685 rate_idx = ffs(mask->control[band].legacy) - 1;
5686
5687 hw_rate = sband->bitrates[rate_idx].hw_value;
5688 bitrate = sband->bitrates[rate_idx].bitrate;
5689
5690 if (ath10k_mac_bitrate_is_cck(bitrate))
5691 preamble = WMI_RATE_PREAMBLE_CCK;
5692 else
5693 preamble = WMI_RATE_PREAMBLE_OFDM;
5694
5695 *nss = 1;
5696 *rate = preamble << 6 |
5697 (*nss - 1) << 4 |
5698 hw_rate << 0;
5699
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005700 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005701 }
5702
Michal Kazior3ae54222015-03-31 10:49:20 +00005703 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5704 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5705 *nss = i + 1;
5706 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5707 (*nss - 1) << 4 |
5708 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005709
Michal Kazior3ae54222015-03-31 10:49:20 +00005710 return 0;
5711 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005712 }
5713
Michal Kazior3ae54222015-03-31 10:49:20 +00005714 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5715 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5716 *nss = i + 1;
5717 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5718 (*nss - 1) << 4 |
5719 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005720
Michal Kazior3ae54222015-03-31 10:49:20 +00005721 return 0;
5722 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005723 }
5724
Michal Kazior3ae54222015-03-31 10:49:20 +00005725 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005726}
5727
Michal Kazior3ae54222015-03-31 10:49:20 +00005728static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5729 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005730{
5731 struct ath10k *ar = arvif->ar;
5732 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005733 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005734
Michal Kazior3ae54222015-03-31 10:49:20 +00005735 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005736
Michal Kazior3ae54222015-03-31 10:49:20 +00005737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5738 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005739
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005740 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005741 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005742 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005743 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005744 rate, ret);
5745 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005746 }
5747
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005748 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005749 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005750 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005751 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5752 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005753 }
5754
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005755 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005756 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005757 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005758 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5759 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005760 }
5761
Michal Kazior3ae54222015-03-31 10:49:20 +00005762 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005763}
5764
Michal Kazior3ae54222015-03-31 10:49:20 +00005765static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5766 struct ieee80211_vif *vif,
5767 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005768{
5769 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005770 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005771 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005772 enum ieee80211_band band;
Michal Kazior3ae54222015-03-31 10:49:20 +00005773 u8 rate;
5774 u8 nss;
5775 u8 sgi;
5776 int single_nss;
5777 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005778
Michal Kazior500ff9f2015-03-31 10:26:21 +00005779 if (ath10k_mac_vif_chan(vif, &def))
5780 return -EPERM;
5781
Michal Kazior500ff9f2015-03-31 10:26:21 +00005782 band = def.chan->band;
5783
Michal Kazior3ae54222015-03-31 10:49:20 +00005784 sgi = mask->control[band].gi;
5785 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005786 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005787
Michal Kazior3ae54222015-03-31 10:49:20 +00005788 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5789 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5790 &rate, &nss);
5791 if (ret) {
5792 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5793 arvif->vdev_id, ret);
5794 return ret;
5795 }
5796 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5797 &single_nss)) {
5798 rate = WMI_FIXED_RATE_NONE;
5799 nss = single_nss;
5800 } else {
5801 rate = WMI_FIXED_RATE_NONE;
5802 nss = ar->num_rf_chains;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005803 }
5804
Michal Kazior3ae54222015-03-31 10:49:20 +00005805 mutex_lock(&ar->conf_mutex);
5806
5807 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
5808 if (ret) {
5809 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5810 arvif->vdev_id, ret);
5811 goto exit;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005812 }
5813
Michal Kazior3ae54222015-03-31 10:49:20 +00005814exit:
5815 mutex_unlock(&ar->conf_mutex);
5816
5817 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005818}
5819
Michal Kazior9797feb2014-02-14 14:49:48 +01005820static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5821 struct ieee80211_vif *vif,
5822 struct ieee80211_sta *sta,
5823 u32 changed)
5824{
5825 struct ath10k *ar = hw->priv;
5826 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5827 u32 bw, smps;
5828
5829 spin_lock_bh(&ar->data_lock);
5830
Michal Kazior7aa7a722014-08-25 12:09:38 +02005831 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005832 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5833 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5834 sta->smps_mode);
5835
5836 if (changed & IEEE80211_RC_BW_CHANGED) {
5837 bw = WMI_PEER_CHWIDTH_20MHZ;
5838
5839 switch (sta->bandwidth) {
5840 case IEEE80211_STA_RX_BW_20:
5841 bw = WMI_PEER_CHWIDTH_20MHZ;
5842 break;
5843 case IEEE80211_STA_RX_BW_40:
5844 bw = WMI_PEER_CHWIDTH_40MHZ;
5845 break;
5846 case IEEE80211_STA_RX_BW_80:
5847 bw = WMI_PEER_CHWIDTH_80MHZ;
5848 break;
5849 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005850 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005851 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005852 bw = WMI_PEER_CHWIDTH_20MHZ;
5853 break;
5854 }
5855
5856 arsta->bw = bw;
5857 }
5858
5859 if (changed & IEEE80211_RC_NSS_CHANGED)
5860 arsta->nss = sta->rx_nss;
5861
5862 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5863 smps = WMI_PEER_SMPS_PS_NONE;
5864
5865 switch (sta->smps_mode) {
5866 case IEEE80211_SMPS_AUTOMATIC:
5867 case IEEE80211_SMPS_OFF:
5868 smps = WMI_PEER_SMPS_PS_NONE;
5869 break;
5870 case IEEE80211_SMPS_STATIC:
5871 smps = WMI_PEER_SMPS_STATIC;
5872 break;
5873 case IEEE80211_SMPS_DYNAMIC:
5874 smps = WMI_PEER_SMPS_DYNAMIC;
5875 break;
5876 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005877 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005878 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005879 smps = WMI_PEER_SMPS_PS_NONE;
5880 break;
5881 }
5882
5883 arsta->smps = smps;
5884 }
5885
Michal Kazior9797feb2014-02-14 14:49:48 +01005886 arsta->changed |= changed;
5887
5888 spin_unlock_bh(&ar->data_lock);
5889
5890 ieee80211_queue_work(hw, &arsta->update_wk);
5891}
5892
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005893static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5894{
5895 /*
5896 * FIXME: Return 0 for time being. Need to figure out whether FW
5897 * has the API to fetch 64-bit local TSF
5898 */
5899
5900 return 0;
5901}
5902
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005903static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5904 struct ieee80211_vif *vif,
5905 enum ieee80211_ampdu_mlme_action action,
5906 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5907 u8 buf_size)
5908{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005909 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005910 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5911
Michal Kazior7aa7a722014-08-25 12:09:38 +02005912 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 +02005913 arvif->vdev_id, sta->addr, tid, action);
5914
5915 switch (action) {
5916 case IEEE80211_AMPDU_RX_START:
5917 case IEEE80211_AMPDU_RX_STOP:
5918 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5919 * creation/removal. Do we need to verify this?
5920 */
5921 return 0;
5922 case IEEE80211_AMPDU_TX_START:
5923 case IEEE80211_AMPDU_TX_STOP_CONT:
5924 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5925 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5926 case IEEE80211_AMPDU_TX_OPERATIONAL:
5927 /* Firmware offloads Tx aggregation entirely so deny mac80211
5928 * Tx aggregation requests.
5929 */
5930 return -EOPNOTSUPP;
5931 }
5932
5933 return -EINVAL;
5934}
5935
Michal Kazior500ff9f2015-03-31 10:26:21 +00005936static void
5937ath10k_mac_update_rx_channel(struct ath10k *ar)
5938{
5939 struct cfg80211_chan_def *def = NULL;
5940
5941 /* Both locks are required because ar->rx_channel is modified. This
5942 * allows readers to hold either lock.
5943 */
5944 lockdep_assert_held(&ar->conf_mutex);
5945 lockdep_assert_held(&ar->data_lock);
5946
5947 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5948 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5949 * ppdu on Rx may reduce performance on low-end systems. It should be
5950 * possible to make tables/hashmaps to speed the lookup up (be vary of
5951 * cpu data cache lines though regarding sizes) but to keep the initial
5952 * implementation simple and less intrusive fallback to the slow lookup
5953 * only for multi-channel cases. Single-channel cases will remain to
5954 * use the old channel derival and thus performance should not be
5955 * affected much.
5956 */
5957 rcu_read_lock();
5958 if (ath10k_mac_num_chanctxs(ar) == 1) {
5959 ieee80211_iter_chan_contexts_atomic(ar->hw,
5960 ath10k_mac_get_any_chandef_iter,
5961 &def);
5962 ar->rx_channel = def->chan;
5963 } else {
5964 ar->rx_channel = NULL;
5965 }
5966 rcu_read_unlock();
5967}
5968
5969static void
5970ath10k_mac_chan_ctx_init(struct ath10k *ar,
5971 struct ath10k_chanctx *arctx,
5972 struct ieee80211_chanctx_conf *conf)
5973{
5974 lockdep_assert_held(&ar->conf_mutex);
5975 lockdep_assert_held(&ar->data_lock);
5976
5977 memset(arctx, 0, sizeof(*arctx));
5978
5979 arctx->conf = *conf;
5980}
5981
5982static int
5983ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5984 struct ieee80211_chanctx_conf *ctx)
5985{
5986 struct ath10k *ar = hw->priv;
5987 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5988
5989 ath10k_dbg(ar, ATH10K_DBG_MAC,
5990 "mac chanctx add freq %hu width %d ptr %p\n",
5991 ctx->def.chan->center_freq, ctx->def.width, ctx);
5992
5993 mutex_lock(&ar->conf_mutex);
5994
5995 spin_lock_bh(&ar->data_lock);
5996 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
5997 ath10k_mac_update_rx_channel(ar);
5998 spin_unlock_bh(&ar->data_lock);
5999
6000 ath10k_recalc_radar_detection(ar);
6001 ath10k_monitor_recalc(ar);
6002
6003 mutex_unlock(&ar->conf_mutex);
6004
6005 return 0;
6006}
6007
6008static void
6009ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6010 struct ieee80211_chanctx_conf *ctx)
6011{
6012 struct ath10k *ar = hw->priv;
6013
6014 ath10k_dbg(ar, ATH10K_DBG_MAC,
6015 "mac chanctx remove freq %hu width %d ptr %p\n",
6016 ctx->def.chan->center_freq, ctx->def.width, ctx);
6017
6018 mutex_lock(&ar->conf_mutex);
6019
6020 spin_lock_bh(&ar->data_lock);
6021 ath10k_mac_update_rx_channel(ar);
6022 spin_unlock_bh(&ar->data_lock);
6023
6024 ath10k_recalc_radar_detection(ar);
6025 ath10k_monitor_recalc(ar);
6026
6027 mutex_unlock(&ar->conf_mutex);
6028}
6029
6030static void
6031ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6032 struct ieee80211_chanctx_conf *ctx,
6033 u32 changed)
6034{
6035 struct ath10k *ar = hw->priv;
6036 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6037
6038 mutex_lock(&ar->conf_mutex);
6039
6040 ath10k_dbg(ar, ATH10K_DBG_MAC,
6041 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6042 arctx->conf.def.chan->center_freq,
6043 ctx->def.chan->center_freq,
6044 arctx->conf.def.width, ctx->def.width,
6045 ctx, changed);
6046
6047 /* This shouldn't really happen because channel switching should use
6048 * switch_vif_chanctx().
6049 */
6050 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6051 goto unlock;
6052
6053 spin_lock_bh(&ar->data_lock);
6054 arctx->conf = *ctx;
6055 spin_unlock_bh(&ar->data_lock);
6056
6057 ath10k_recalc_radar_detection(ar);
6058
6059 /* FIXME: How to configure Rx chains properly? */
6060
6061 /* No other actions are actually necessary. Firmware maintains channel
6062 * definitions per vdev internally and there's no host-side channel
6063 * context abstraction to configure, e.g. channel width.
6064 */
6065
6066unlock:
6067 mutex_unlock(&ar->conf_mutex);
6068}
6069
6070static int
6071ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6072 struct ieee80211_vif *vif,
6073 struct ieee80211_chanctx_conf *ctx)
6074{
6075 struct ath10k *ar = hw->priv;
6076 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6077 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6078 int ret;
6079
6080 mutex_lock(&ar->conf_mutex);
6081
6082 ath10k_dbg(ar, ATH10K_DBG_MAC,
6083 "mac chanctx assign ptr %p vdev_id %i\n",
6084 ctx, arvif->vdev_id);
6085
6086 if (WARN_ON(arvif->is_started)) {
6087 mutex_unlock(&ar->conf_mutex);
6088 return -EBUSY;
6089 }
6090
6091 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6092 if (ret) {
6093 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6094 arvif->vdev_id, vif->addr,
6095 arctx->conf.def.chan->center_freq, ret);
6096 goto err;
6097 }
6098
6099 arvif->is_started = true;
6100
6101 if (vif->type == NL80211_IFTYPE_MONITOR) {
6102 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6103 if (ret) {
6104 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6105 arvif->vdev_id, ret);
6106 goto err_stop;
6107 }
6108
6109 arvif->is_up = true;
6110 }
6111
6112 mutex_unlock(&ar->conf_mutex);
6113 return 0;
6114
6115err_stop:
6116 ath10k_vdev_stop(arvif);
6117 arvif->is_started = false;
6118
6119err:
6120 mutex_unlock(&ar->conf_mutex);
6121 return ret;
6122}
6123
6124static void
6125ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6126 struct ieee80211_vif *vif,
6127 struct ieee80211_chanctx_conf *ctx)
6128{
6129 struct ath10k *ar = hw->priv;
6130 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6131 int ret;
6132
6133 mutex_lock(&ar->conf_mutex);
6134
6135 ath10k_dbg(ar, ATH10K_DBG_MAC,
6136 "mac chanctx unassign ptr %p vdev_id %i\n",
6137 ctx, arvif->vdev_id);
6138
6139 WARN_ON(!arvif->is_started);
6140
6141 if (vif->type == NL80211_IFTYPE_MONITOR) {
6142 WARN_ON(!arvif->is_up);
6143
6144 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6145 if (ret)
6146 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6147 arvif->vdev_id, ret);
6148
6149 arvif->is_up = false;
6150 }
6151
6152 ret = ath10k_vdev_stop(arvif);
6153 if (ret)
6154 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6155 arvif->vdev_id, ret);
6156
6157 arvif->is_started = false;
6158
6159 mutex_unlock(&ar->conf_mutex);
6160}
6161
6162static int
6163ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6164 struct ieee80211_vif_chanctx_switch *vifs,
6165 int n_vifs,
6166 enum ieee80211_chanctx_switch_mode mode)
6167{
6168 struct ath10k *ar = hw->priv;
6169 struct ath10k_vif *arvif;
6170 struct ath10k_chanctx *arctx_new, *arctx_old;
6171 int i;
6172
6173 mutex_lock(&ar->conf_mutex);
6174
6175 ath10k_dbg(ar, ATH10K_DBG_MAC,
6176 "mac chanctx switch n_vifs %d mode %d\n",
6177 n_vifs, mode);
6178
6179 spin_lock_bh(&ar->data_lock);
6180 for (i = 0; i < n_vifs; i++) {
6181 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6182 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6183 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6184
6185 ath10k_dbg(ar, ATH10K_DBG_MAC,
6186 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6187 arvif->vdev_id,
6188 vifs[i].old_ctx->def.chan->center_freq,
6189 vifs[i].new_ctx->def.chan->center_freq,
6190 vifs[i].old_ctx->def.width,
6191 vifs[i].new_ctx->def.width,
6192 arctx_old, arctx_new);
6193
6194 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6195 ath10k_mac_chan_ctx_init(ar, arctx_new,
6196 vifs[i].new_ctx);
6197 }
6198
6199 arctx_new->conf = *vifs[i].new_ctx;
6200
6201 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6202 * yet updated chanctx_conf pointer.
6203 */
6204 arctx_old->conf = *vifs[i].new_ctx;
6205 }
6206 ath10k_mac_update_rx_channel(ar);
6207 spin_unlock_bh(&ar->data_lock);
6208
6209 /* FIXME: Reconfigure only affected vifs */
6210 ath10k_mac_chan_reconfigure(ar);
6211
6212 mutex_unlock(&ar->conf_mutex);
6213 return 0;
6214}
6215
Kalle Valo5e3dd152013-06-12 20:52:10 +03006216static const struct ieee80211_ops ath10k_ops = {
6217 .tx = ath10k_tx,
6218 .start = ath10k_start,
6219 .stop = ath10k_stop,
6220 .config = ath10k_config,
6221 .add_interface = ath10k_add_interface,
6222 .remove_interface = ath10k_remove_interface,
6223 .configure_filter = ath10k_configure_filter,
6224 .bss_info_changed = ath10k_bss_info_changed,
6225 .hw_scan = ath10k_hw_scan,
6226 .cancel_hw_scan = ath10k_cancel_hw_scan,
6227 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006228 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006229 .sta_state = ath10k_sta_state,
6230 .conf_tx = ath10k_conf_tx,
6231 .remain_on_channel = ath10k_remain_on_channel,
6232 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6233 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006234 .flush = ath10k_flush,
6235 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006236 .set_antenna = ath10k_set_antenna,
6237 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006238 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006239 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006240 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006241 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006242 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006243 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006244 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6245 .get_et_stats = ath10k_debug_get_et_stats,
6246 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006247 .add_chanctx = ath10k_mac_op_add_chanctx,
6248 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6249 .change_chanctx = ath10k_mac_op_change_chanctx,
6250 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6251 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6252 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006253
6254 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6255
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006256#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006257 .suspend = ath10k_wow_op_suspend,
6258 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006259#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006260#ifdef CONFIG_MAC80211_DEBUGFS
6261 .sta_add_debugfs = ath10k_sta_add_debugfs,
6262#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006263};
6264
Kalle Valo5e3dd152013-06-12 20:52:10 +03006265#define CHAN2G(_channel, _freq, _flags) { \
6266 .band = IEEE80211_BAND_2GHZ, \
6267 .hw_value = (_channel), \
6268 .center_freq = (_freq), \
6269 .flags = (_flags), \
6270 .max_antenna_gain = 0, \
6271 .max_power = 30, \
6272}
6273
6274#define CHAN5G(_channel, _freq, _flags) { \
6275 .band = IEEE80211_BAND_5GHZ, \
6276 .hw_value = (_channel), \
6277 .center_freq = (_freq), \
6278 .flags = (_flags), \
6279 .max_antenna_gain = 0, \
6280 .max_power = 30, \
6281}
6282
6283static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6284 CHAN2G(1, 2412, 0),
6285 CHAN2G(2, 2417, 0),
6286 CHAN2G(3, 2422, 0),
6287 CHAN2G(4, 2427, 0),
6288 CHAN2G(5, 2432, 0),
6289 CHAN2G(6, 2437, 0),
6290 CHAN2G(7, 2442, 0),
6291 CHAN2G(8, 2447, 0),
6292 CHAN2G(9, 2452, 0),
6293 CHAN2G(10, 2457, 0),
6294 CHAN2G(11, 2462, 0),
6295 CHAN2G(12, 2467, 0),
6296 CHAN2G(13, 2472, 0),
6297 CHAN2G(14, 2484, 0),
6298};
6299
6300static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006301 CHAN5G(36, 5180, 0),
6302 CHAN5G(40, 5200, 0),
6303 CHAN5G(44, 5220, 0),
6304 CHAN5G(48, 5240, 0),
6305 CHAN5G(52, 5260, 0),
6306 CHAN5G(56, 5280, 0),
6307 CHAN5G(60, 5300, 0),
6308 CHAN5G(64, 5320, 0),
6309 CHAN5G(100, 5500, 0),
6310 CHAN5G(104, 5520, 0),
6311 CHAN5G(108, 5540, 0),
6312 CHAN5G(112, 5560, 0),
6313 CHAN5G(116, 5580, 0),
6314 CHAN5G(120, 5600, 0),
6315 CHAN5G(124, 5620, 0),
6316 CHAN5G(128, 5640, 0),
6317 CHAN5G(132, 5660, 0),
6318 CHAN5G(136, 5680, 0),
6319 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006320 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006321 CHAN5G(149, 5745, 0),
6322 CHAN5G(153, 5765, 0),
6323 CHAN5G(157, 5785, 0),
6324 CHAN5G(161, 5805, 0),
6325 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006326};
6327
Michal Kaziore7b54192014-08-07 11:03:27 +02006328struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006329{
6330 struct ieee80211_hw *hw;
6331 struct ath10k *ar;
6332
Michal Kaziore7b54192014-08-07 11:03:27 +02006333 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006334 if (!hw)
6335 return NULL;
6336
6337 ar = hw->priv;
6338 ar->hw = hw;
6339
6340 return ar;
6341}
6342
6343void ath10k_mac_destroy(struct ath10k *ar)
6344{
6345 ieee80211_free_hw(ar->hw);
6346}
6347
6348static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6349 {
6350 .max = 8,
6351 .types = BIT(NL80211_IFTYPE_STATION)
6352 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006353 },
6354 {
6355 .max = 3,
6356 .types = BIT(NL80211_IFTYPE_P2P_GO)
6357 },
6358 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006359 .max = 1,
6360 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6361 },
6362 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006363 .max = 7,
6364 .types = BIT(NL80211_IFTYPE_AP)
6365 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006366};
6367
Bartosz Markowskif2595092013-12-10 16:20:39 +01006368static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006369 {
6370 .max = 8,
6371 .types = BIT(NL80211_IFTYPE_AP)
6372 },
6373};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006374
6375static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6376 {
6377 .limits = ath10k_if_limits,
6378 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6379 .max_interfaces = 8,
6380 .num_different_channels = 1,
6381 .beacon_int_infra_match = true,
6382 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006383};
6384
6385static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006386 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006387 .limits = ath10k_10x_if_limits,
6388 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006389 .max_interfaces = 8,
6390 .num_different_channels = 1,
6391 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006392#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006393 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6394 BIT(NL80211_CHAN_WIDTH_20) |
6395 BIT(NL80211_CHAN_WIDTH_40) |
6396 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006397#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006398 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006399};
6400
Michal Kaziorcf327842015-03-31 10:26:25 +00006401static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6402 {
6403 .max = 2,
6404 .types = BIT(NL80211_IFTYPE_STATION) |
6405 BIT(NL80211_IFTYPE_AP) |
6406 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6407 BIT(NL80211_IFTYPE_P2P_GO),
6408 },
6409 {
6410 .max = 1,
6411 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6412 },
6413};
6414
6415static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6416 {
6417 .max = 1,
6418 .types = BIT(NL80211_IFTYPE_STATION),
6419 },
6420 {
6421 .max = 1,
6422 .types = BIT(NL80211_IFTYPE_ADHOC),
6423 },
6424};
6425
6426/* FIXME: This is not thouroughly tested. These combinations may over- or
6427 * underestimate hw/fw capabilities.
6428 */
6429static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6430 {
6431 .limits = ath10k_tlv_if_limit,
6432 .num_different_channels = 1,
6433 .max_interfaces = 3,
6434 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6435 },
6436 {
6437 .limits = ath10k_tlv_if_limit_ibss,
6438 .num_different_channels = 1,
6439 .max_interfaces = 2,
6440 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6441 },
6442};
6443
6444static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6445 {
6446 .limits = ath10k_tlv_if_limit,
6447 .num_different_channels = 2,
6448 .max_interfaces = 3,
6449 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6450 },
6451 {
6452 .limits = ath10k_tlv_if_limit_ibss,
6453 .num_different_channels = 1,
6454 .max_interfaces = 2,
6455 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6456 },
6457};
6458
Kalle Valo5e3dd152013-06-12 20:52:10 +03006459static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6460{
6461 struct ieee80211_sta_vht_cap vht_cap = {0};
6462 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006463 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006464 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006465
6466 vht_cap.vht_supported = 1;
6467 vht_cap.cap = ar->vht_cap_info;
6468
Michal Kaziorbc657a362015-02-26 11:11:22 +01006469 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6470 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6471 val = ar->num_rf_chains - 1;
6472 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6473 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6474
6475 vht_cap.cap |= val;
6476 }
6477
6478 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6479 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6480 val = ar->num_rf_chains - 1;
6481 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6482 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6483
6484 vht_cap.cap |= val;
6485 }
6486
Michal Kazior8865bee42013-07-24 12:36:46 +02006487 mcs_map = 0;
6488 for (i = 0; i < 8; i++) {
6489 if (i < ar->num_rf_chains)
6490 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6491 else
6492 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6493 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006494
6495 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6496 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6497
6498 return vht_cap;
6499}
6500
6501static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6502{
6503 int i;
6504 struct ieee80211_sta_ht_cap ht_cap = {0};
6505
6506 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6507 return ht_cap;
6508
6509 ht_cap.ht_supported = 1;
6510 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6511 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6512 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6513 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6514 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6515
6516 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6517 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6518
6519 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6520 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6521
6522 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6523 u32 smps;
6524
6525 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6526 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6527
6528 ht_cap.cap |= smps;
6529 }
6530
6531 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6532 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6533
6534 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6535 u32 stbc;
6536
6537 stbc = ar->ht_cap_info;
6538 stbc &= WMI_HT_CAP_RX_STBC;
6539 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6540 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6541 stbc &= IEEE80211_HT_CAP_RX_STBC;
6542
6543 ht_cap.cap |= stbc;
6544 }
6545
6546 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6547 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6548
6549 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6550 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6551
6552 /* max AMSDU is implicitly taken from vht_cap_info */
6553 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6554 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6555
Michal Kazior8865bee42013-07-24 12:36:46 +02006556 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006557 ht_cap.mcs.rx_mask[i] = 0xFF;
6558
6559 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6560
6561 return ht_cap;
6562}
6563
Kalle Valo5e3dd152013-06-12 20:52:10 +03006564static void ath10k_get_arvif_iter(void *data, u8 *mac,
6565 struct ieee80211_vif *vif)
6566{
6567 struct ath10k_vif_iter *arvif_iter = data;
6568 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6569
6570 if (arvif->vdev_id == arvif_iter->vdev_id)
6571 arvif_iter->arvif = arvif;
6572}
6573
6574struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6575{
6576 struct ath10k_vif_iter arvif_iter;
6577 u32 flags;
6578
6579 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6580 arvif_iter.vdev_id = vdev_id;
6581
6582 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6583 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6584 flags,
6585 ath10k_get_arvif_iter,
6586 &arvif_iter);
6587 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006588 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006589 return NULL;
6590 }
6591
6592 return arvif_iter.arvif;
6593}
6594
6595int ath10k_mac_register(struct ath10k *ar)
6596{
Johannes Berg3cb10942015-01-22 21:38:45 +01006597 static const u32 cipher_suites[] = {
6598 WLAN_CIPHER_SUITE_WEP40,
6599 WLAN_CIPHER_SUITE_WEP104,
6600 WLAN_CIPHER_SUITE_TKIP,
6601 WLAN_CIPHER_SUITE_CCMP,
6602 WLAN_CIPHER_SUITE_AES_CMAC,
6603 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006604 struct ieee80211_supported_band *band;
6605 struct ieee80211_sta_vht_cap vht_cap;
6606 struct ieee80211_sta_ht_cap ht_cap;
6607 void *channels;
6608 int ret;
6609
6610 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6611
6612 SET_IEEE80211_DEV(ar->hw, ar->dev);
6613
6614 ht_cap = ath10k_get_ht_cap(ar);
6615 vht_cap = ath10k_create_vht_cap(ar);
6616
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006617 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6618 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6619 ATH10K_NUM_CHANS);
6620
Kalle Valo5e3dd152013-06-12 20:52:10 +03006621 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6622 channels = kmemdup(ath10k_2ghz_channels,
6623 sizeof(ath10k_2ghz_channels),
6624 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006625 if (!channels) {
6626 ret = -ENOMEM;
6627 goto err_free;
6628 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006629
6630 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6631 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6632 band->channels = channels;
6633 band->n_bitrates = ath10k_g_rates_size;
6634 band->bitrates = ath10k_g_rates;
6635 band->ht_cap = ht_cap;
6636
Yanbo Lid68bb122015-01-23 08:18:20 +08006637 /* Enable the VHT support at 2.4 GHz */
6638 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006639
6640 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6641 }
6642
6643 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6644 channels = kmemdup(ath10k_5ghz_channels,
6645 sizeof(ath10k_5ghz_channels),
6646 GFP_KERNEL);
6647 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006648 ret = -ENOMEM;
6649 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006650 }
6651
6652 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6653 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6654 band->channels = channels;
6655 band->n_bitrates = ath10k_a_rates_size;
6656 band->bitrates = ath10k_a_rates;
6657 band->ht_cap = ht_cap;
6658 band->vht_cap = vht_cap;
6659 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6660 }
6661
6662 ar->hw->wiphy->interface_modes =
6663 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006664 BIT(NL80211_IFTYPE_AP);
6665
Ben Greear46acf7b2014-05-16 17:15:38 +03006666 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6667 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6668
Bartosz Markowskid3541812013-12-10 16:20:40 +01006669 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6670 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006671 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006672 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6673 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006674
6675 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6676 IEEE80211_HW_SUPPORTS_PS |
6677 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006678 IEEE80211_HW_MFP_CAPABLE |
6679 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6680 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006681 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006682 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006683 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006684 IEEE80211_HW_CONNECTION_MONITOR |
6685 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006686 IEEE80211_HW_CHANCTX_STA_CSA |
6687 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006688
Eliad Peller0d8614b2014-09-10 14:07:36 +03006689 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6690
Kalle Valo5e3dd152013-06-12 20:52:10 +03006691 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006692 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006693
6694 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6695 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6696 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6697 }
6698
6699 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6700 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6701
6702 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006703 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006704 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006705
Kalle Valo5e3dd152013-06-12 20:52:10 +03006706 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6707
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006708 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6709 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6710
6711 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6712 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6713 * correct Probe Responses. This is more of a hack advert..
6714 */
6715 ar->hw->wiphy->probe_resp_offload |=
6716 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6717 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6718 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6719 }
6720
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006721 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6722 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6723
Kalle Valo5e3dd152013-06-12 20:52:10 +03006724 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006725 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006726 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6727
6728 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006729 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6730
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006731 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6732
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006733 ret = ath10k_wow_init(ar);
6734 if (ret) {
6735 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6736 goto err_free;
6737 }
6738
Kalle Valo5e3dd152013-06-12 20:52:10 +03006739 /*
6740 * on LL hardware queues are managed entirely by the FW
6741 * so we only advertise to mac we can do the queues thing
6742 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006743 ar->hw->queues = IEEE80211_MAX_QUEUES;
6744
6745 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6746 * something that vdev_ids can't reach so that we don't stop the queue
6747 * accidentally.
6748 */
6749 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006750
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006751 switch (ar->wmi.op_version) {
6752 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006753 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6754 ar->hw->wiphy->n_iface_combinations =
6755 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006756 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006757 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006758 case ATH10K_FW_WMI_OP_VERSION_TLV:
6759 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6760 ar->hw->wiphy->iface_combinations =
6761 ath10k_tlv_qcs_if_comb;
6762 ar->hw->wiphy->n_iface_combinations =
6763 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
6764 } else {
6765 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
6766 ar->hw->wiphy->n_iface_combinations =
6767 ARRAY_SIZE(ath10k_tlv_if_comb);
6768 }
6769 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6770 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006771 case ATH10K_FW_WMI_OP_VERSION_10_1:
6772 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006773 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006774 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6775 ar->hw->wiphy->n_iface_combinations =
6776 ARRAY_SIZE(ath10k_10x_if_comb);
6777 break;
6778 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6779 case ATH10K_FW_WMI_OP_VERSION_MAX:
6780 WARN_ON(1);
6781 ret = -EINVAL;
6782 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006783 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006784
Michal Kazior7c199992013-07-31 10:47:57 +02006785 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6786
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006787 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6788 /* Init ath dfs pattern detector */
6789 ar->ath_common.debug_mask = ATH_DBG_DFS;
6790 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6791 NL80211_DFS_UNSET);
6792
6793 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006794 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006795 }
6796
Kalle Valo5e3dd152013-06-12 20:52:10 +03006797 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6798 ath10k_reg_notifier);
6799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006800 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006801 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006802 }
6803
Johannes Berg3cb10942015-01-22 21:38:45 +01006804 ar->hw->wiphy->cipher_suites = cipher_suites;
6805 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6806
Kalle Valo5e3dd152013-06-12 20:52:10 +03006807 ret = ieee80211_register_hw(ar->hw);
6808 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006809 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006810 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006811 }
6812
6813 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6814 ret = regulatory_hint(ar->hw->wiphy,
6815 ar->ath_common.regulatory.alpha2);
6816 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006817 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006818 }
6819
6820 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006821
6822err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006823 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006824err_free:
6825 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6826 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6827
Kalle Valo5e3dd152013-06-12 20:52:10 +03006828 return ret;
6829}
6830
6831void ath10k_mac_unregister(struct ath10k *ar)
6832{
6833 ieee80211_unregister_hw(ar->hw);
6834
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006835 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6836 ar->dfs_detector->exit(ar->dfs_detector);
6837
Kalle Valo5e3dd152013-06-12 20:52:10 +03006838 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6839 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6840
6841 SET_IEEE80211_DEV(ar->hw, NULL);
6842}