blob: 9474fc8a341da540426e8b3b4c6cb20e4d68d529 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020032#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030033
Michal Kaziordcc33092015-03-30 09:51:54 +030034/*********/
35/* Rates */
36/*********/
37
38#define RATETAB_ENT(_rate, _rateid, _flags) { \
39 .bitrate = (_rate), \
40 .flags = (_flags), \
41 .hw_value = (_rateid), \
42}
43
44static struct ieee80211_rate ath10k_rates[] = {
45 /* CCK */
Michal Kazior486017c2015-03-30 09:51:54 +030046 RATETAB_ENT(10, 0, 0),
47 RATETAB_ENT(20, 0, 0),
48 RATETAB_ENT(55, 0, 0),
49 RATETAB_ENT(110, 0, 0),
Michal Kaziordcc33092015-03-30 09:51:54 +030050 /* OFDM */
Michal Kazior486017c2015-03-30 09:51:54 +030051 RATETAB_ENT(60, 0, 0),
52 RATETAB_ENT(90, 0, 0),
53 RATETAB_ENT(120, 0, 0),
54 RATETAB_ENT(180, 0, 0),
55 RATETAB_ENT(240, 0, 0),
56 RATETAB_ENT(360, 0, 0),
57 RATETAB_ENT(480, 0, 0),
58 RATETAB_ENT(540, 0, 0),
Michal Kaziordcc33092015-03-30 09:51:54 +030059};
60
61#define ath10k_a_rates (ath10k_rates + 4)
62#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
63#define ath10k_g_rates (ath10k_rates + 0)
64#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
65
Michal Kazior486017c2015-03-30 09:51:54 +030066static bool ath10k_mac_bitrate_is_cck(int bitrate)
67{
68 switch (bitrate) {
69 case 10:
70 case 20:
71 case 55:
72 case 110:
73 return true;
74 }
75
76 return false;
77}
78
79static u8 ath10k_mac_bitrate_to_rate(int bitrate)
80{
81 return DIV_ROUND_UP(bitrate, 5) |
82 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
83}
84
Kalle Valo5e3dd152013-06-12 20:52:10 +030085/**********/
86/* Crypto */
87/**********/
88
89static int ath10k_send_key(struct ath10k_vif *arvif,
90 struct ieee80211_key_conf *key,
91 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010092 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030093{
Michal Kazior7aa7a722014-08-25 12:09:38 +020094 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030095 struct wmi_vdev_install_key_arg arg = {
96 .vdev_id = arvif->vdev_id,
97 .key_idx = key->keyidx,
98 .key_len = key->keylen,
99 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100100 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300101 .macaddr = macaddr,
102 };
103
Michal Kazior548db542013-07-05 16:15:15 +0300104 lockdep_assert_held(&arvif->ar->conf_mutex);
105
Kalle Valo5e3dd152013-06-12 20:52:10 +0300106 switch (key->cipher) {
107 case WLAN_CIPHER_SUITE_CCMP:
108 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200109 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300110 break;
111 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300112 arg.key_cipher = WMI_CIPHER_TKIP;
113 arg.key_txmic_len = 8;
114 arg.key_rxmic_len = 8;
115 break;
116 case WLAN_CIPHER_SUITE_WEP40:
117 case WLAN_CIPHER_SUITE_WEP104:
118 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300119 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100120 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100121 WARN_ON(1);
122 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300123 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200124 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300125 return -EOPNOTSUPP;
126 }
127
128 if (cmd == DISABLE_KEY) {
129 arg.key_cipher = WMI_CIPHER_NONE;
130 arg.key_data = NULL;
131 }
132
133 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
134}
135
136static int ath10k_install_key(struct ath10k_vif *arvif,
137 struct ieee80211_key_conf *key,
138 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100139 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300140{
141 struct ath10k *ar = arvif->ar;
142 int ret;
143
Michal Kazior548db542013-07-05 16:15:15 +0300144 lockdep_assert_held(&ar->conf_mutex);
145
Wolfram Sang16735d02013-11-14 14:32:02 -0800146 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300147
Michal Kazior370e5672015-02-18 14:02:26 +0100148 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300149 if (ret)
150 return ret;
151
152 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
153 if (ret == 0)
154 return -ETIMEDOUT;
155
156 return 0;
157}
158
159static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
160 const u8 *addr)
161{
162 struct ath10k *ar = arvif->ar;
163 struct ath10k_peer *peer;
164 int ret;
165 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100166 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300167
168 lockdep_assert_held(&ar->conf_mutex);
169
170 spin_lock_bh(&ar->data_lock);
171 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
172 spin_unlock_bh(&ar->data_lock);
173
174 if (!peer)
175 return -ENOENT;
176
177 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
178 if (arvif->wep_keys[i] == NULL)
179 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100180
181 flags = 0;
182 flags |= WMI_KEY_PAIRWISE;
183
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200184 /* set TX_USAGE flag for default key id */
185 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100186 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300187
188 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100189 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300190 if (ret)
191 return ret;
192
Sujith Manoharanae167132014-11-25 11:46:59 +0530193 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300194 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530195 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300196 }
197
198 return 0;
199}
200
201static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
202 const u8 *addr)
203{
204 struct ath10k *ar = arvif->ar;
205 struct ath10k_peer *peer;
206 int first_errno = 0;
207 int ret;
208 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100209 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300210
211 lockdep_assert_held(&ar->conf_mutex);
212
213 spin_lock_bh(&ar->data_lock);
214 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
215 spin_unlock_bh(&ar->data_lock);
216
217 if (!peer)
218 return -ENOENT;
219
220 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
221 if (peer->keys[i] == NULL)
222 continue;
223
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200224 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100226 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300227 if (ret && first_errno == 0)
228 first_errno = ret;
229
230 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200231 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232 i, ret);
233
Sujith Manoharanae167132014-11-25 11:46:59 +0530234 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300235 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530236 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300237 }
238
239 return first_errno;
240}
241
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530242bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
243 u8 keyidx)
244{
245 struct ath10k_peer *peer;
246 int i;
247
248 lockdep_assert_held(&ar->data_lock);
249
250 /* We don't know which vdev this peer belongs to,
251 * since WMI doesn't give us that information.
252 *
253 * FIXME: multi-bss needs to be handled.
254 */
255 peer = ath10k_peer_find(ar, 0, addr);
256 if (!peer)
257 return false;
258
259 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
260 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
261 return true;
262 }
263
264 return false;
265}
266
Kalle Valo5e3dd152013-06-12 20:52:10 +0300267static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
268 struct ieee80211_key_conf *key)
269{
270 struct ath10k *ar = arvif->ar;
271 struct ath10k_peer *peer;
272 u8 addr[ETH_ALEN];
273 int first_errno = 0;
274 int ret;
275 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100276 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300277
278 lockdep_assert_held(&ar->conf_mutex);
279
280 for (;;) {
281 /* since ath10k_install_key we can't hold data_lock all the
282 * time, so we try to remove the keys incrementally */
283 spin_lock_bh(&ar->data_lock);
284 i = 0;
285 list_for_each_entry(peer, &ar->peers, list) {
286 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
287 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300288 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300289 peer->keys[i] = NULL;
290 break;
291 }
292 }
293
294 if (i < ARRAY_SIZE(peer->keys))
295 break;
296 }
297 spin_unlock_bh(&ar->data_lock);
298
299 if (i == ARRAY_SIZE(peer->keys))
300 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200301 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100302 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300303 if (ret && first_errno == 0)
304 first_errno = ret;
305
306 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200307 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200308 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300309 }
310
311 return first_errno;
312}
313
Michal Kazior370e5672015-02-18 14:02:26 +0100314static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
315{
316 struct ath10k *ar = arvif->ar;
317 enum nl80211_iftype iftype = arvif->vif->type;
318 struct ieee80211_key_conf *key;
319 u32 flags = 0;
320 int num = 0;
321 int i;
322 int ret;
323
324 lockdep_assert_held(&ar->conf_mutex);
325
326 if (iftype != NL80211_IFTYPE_STATION)
327 return 0;
328
329 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
330 if (arvif->wep_keys[i]) {
331 key = arvif->wep_keys[i];
332 ++num;
333 }
334 }
335
336 if (num != 1)
337 return 0;
338
339 flags |= WMI_KEY_PAIRWISE;
340 flags |= WMI_KEY_TX_USAGE;
341
342 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
343 if (ret) {
344 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
345 key->keyidx, arvif->vdev_id, ret);
346 return ret;
347 }
348
349 return 0;
350}
351
Michal Kaziorad325cb2015-02-18 14:02:27 +0100352static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
353 struct ieee80211_key_conf *key)
354{
355 struct ath10k *ar = arvif->ar;
356 struct ath10k_peer *peer;
357 int ret;
358
359 lockdep_assert_held(&ar->conf_mutex);
360
361 list_for_each_entry(peer, &ar->peers, list) {
362 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
363 continue;
364
365 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
366 continue;
367
368 if (peer->keys[key->keyidx] == key)
369 continue;
370
371 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
372 arvif->vdev_id, key->keyidx);
373
374 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
375 if (ret) {
376 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
377 arvif->vdev_id, peer->addr, ret);
378 return ret;
379 }
380 }
381
382 return 0;
383}
384
Kalle Valo5e3dd152013-06-12 20:52:10 +0300385/*********************/
386/* General utilities */
387/*********************/
388
389static inline enum wmi_phy_mode
390chan_to_phymode(const struct cfg80211_chan_def *chandef)
391{
392 enum wmi_phy_mode phymode = MODE_UNKNOWN;
393
394 switch (chandef->chan->band) {
395 case IEEE80211_BAND_2GHZ:
396 switch (chandef->width) {
397 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800398 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
399 phymode = MODE_11B;
400 else
401 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300402 break;
403 case NL80211_CHAN_WIDTH_20:
404 phymode = MODE_11NG_HT20;
405 break;
406 case NL80211_CHAN_WIDTH_40:
407 phymode = MODE_11NG_HT40;
408 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400409 case NL80211_CHAN_WIDTH_5:
410 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300411 case NL80211_CHAN_WIDTH_80:
412 case NL80211_CHAN_WIDTH_80P80:
413 case NL80211_CHAN_WIDTH_160:
414 phymode = MODE_UNKNOWN;
415 break;
416 }
417 break;
418 case IEEE80211_BAND_5GHZ:
419 switch (chandef->width) {
420 case NL80211_CHAN_WIDTH_20_NOHT:
421 phymode = MODE_11A;
422 break;
423 case NL80211_CHAN_WIDTH_20:
424 phymode = MODE_11NA_HT20;
425 break;
426 case NL80211_CHAN_WIDTH_40:
427 phymode = MODE_11NA_HT40;
428 break;
429 case NL80211_CHAN_WIDTH_80:
430 phymode = MODE_11AC_VHT80;
431 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400432 case NL80211_CHAN_WIDTH_5:
433 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434 case NL80211_CHAN_WIDTH_80P80:
435 case NL80211_CHAN_WIDTH_160:
436 phymode = MODE_UNKNOWN;
437 break;
438 }
439 break;
440 default:
441 break;
442 }
443
444 WARN_ON(phymode == MODE_UNKNOWN);
445 return phymode;
446}
447
448static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
449{
450/*
451 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
452 * 0 for no restriction
453 * 1 for 1/4 us
454 * 2 for 1/2 us
455 * 3 for 1 us
456 * 4 for 2 us
457 * 5 for 4 us
458 * 6 for 8 us
459 * 7 for 16 us
460 */
461 switch (mpdudensity) {
462 case 0:
463 return 0;
464 case 1:
465 case 2:
466 case 3:
467 /* Our lower layer calculations limit our precision to
468 1 microsecond */
469 return 1;
470 case 4:
471 return 2;
472 case 5:
473 return 4;
474 case 6:
475 return 8;
476 case 7:
477 return 16;
478 default:
479 return 0;
480 }
481}
482
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300483static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
484 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300485{
486 int ret;
487
488 lockdep_assert_held(&ar->conf_mutex);
489
Michal Kaziorcfd10612014-11-25 15:16:05 +0100490 if (ar->num_peers >= ar->max_num_peers)
491 return -ENOBUFS;
492
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300493 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200495 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200496 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300497 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800498 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300499
500 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800501 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200502 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200503 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300504 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800505 }
Michal Kazior292a7532014-11-25 15:16:04 +0100506
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100507 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300508
509 return 0;
510}
511
Kalle Valo5a13e762014-01-20 11:01:46 +0200512static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
513{
514 struct ath10k *ar = arvif->ar;
515 u32 param;
516 int ret;
517
518 param = ar->wmi.pdev_param->sta_kickout_th;
519 ret = ath10k_wmi_pdev_set_param(ar, param,
520 ATH10K_KICKOUT_THRESHOLD);
521 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200522 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200523 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200524 return ret;
525 }
526
527 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
528 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
529 ATH10K_KEEPALIVE_MIN_IDLE);
530 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200531 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200532 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200533 return ret;
534 }
535
536 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
537 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
538 ATH10K_KEEPALIVE_MAX_IDLE);
539 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200540 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200541 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200542 return ret;
543 }
544
545 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
546 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
547 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
548 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200549 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200550 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200551 return ret;
552 }
553
554 return 0;
555}
556
Vivek Natarajanacab6402014-11-26 09:06:12 +0200557static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200558{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200559 struct ath10k *ar = arvif->ar;
560 u32 vdev_param;
561
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200562 vdev_param = ar->wmi.vdev_param->rts_threshold;
563 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200564}
565
566static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
567{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200568 struct ath10k *ar = arvif->ar;
569 u32 vdev_param;
570
Michal Kazior424121c2013-07-22 14:13:31 +0200571 if (value != 0xFFFFFFFF)
572 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
573 ATH10K_FRAGMT_THRESHOLD_MIN,
574 ATH10K_FRAGMT_THRESHOLD_MAX);
575
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200576 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
577 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200578}
579
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
581{
582 int ret;
583
584 lockdep_assert_held(&ar->conf_mutex);
585
586 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
587 if (ret)
588 return ret;
589
590 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
591 if (ret)
592 return ret;
593
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100594 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100595
Kalle Valo5e3dd152013-06-12 20:52:10 +0300596 return 0;
597}
598
599static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
600{
601 struct ath10k_peer *peer, *tmp;
602
603 lockdep_assert_held(&ar->conf_mutex);
604
605 spin_lock_bh(&ar->data_lock);
606 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
607 if (peer->vdev_id != vdev_id)
608 continue;
609
Michal Kazior7aa7a722014-08-25 12:09:38 +0200610 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300611 peer->addr, vdev_id);
612
613 list_del(&peer->list);
614 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100615 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616 }
617 spin_unlock_bh(&ar->data_lock);
618}
619
Michal Kaziora96d7742013-07-16 09:38:56 +0200620static void ath10k_peer_cleanup_all(struct ath10k *ar)
621{
622 struct ath10k_peer *peer, *tmp;
623
624 lockdep_assert_held(&ar->conf_mutex);
625
626 spin_lock_bh(&ar->data_lock);
627 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
628 list_del(&peer->list);
629 kfree(peer);
630 }
631 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100632
633 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100634 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200635}
636
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300637static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
638 struct ieee80211_sta *sta,
639 enum wmi_tdls_peer_state state)
640{
641 int ret;
642 struct wmi_tdls_peer_update_cmd_arg arg = {};
643 struct wmi_tdls_peer_capab_arg cap = {};
644 struct wmi_channel_arg chan_arg = {};
645
646 lockdep_assert_held(&ar->conf_mutex);
647
648 arg.vdev_id = vdev_id;
649 arg.peer_state = state;
650 ether_addr_copy(arg.addr, sta->addr);
651
652 cap.peer_max_sp = sta->max_sp;
653 cap.peer_uapsd_queues = sta->uapsd_queues;
654
655 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
656 !sta->tdls_initiator)
657 cap.is_peer_responder = 1;
658
659 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
660 if (ret) {
661 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
662 arg.addr, vdev_id, ret);
663 return ret;
664 }
665
666 return 0;
667}
668
Kalle Valo5e3dd152013-06-12 20:52:10 +0300669/************************/
670/* Interface management */
671/************************/
672
Michal Kazior64badcb2014-09-18 11:18:02 +0300673void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
674{
675 struct ath10k *ar = arvif->ar;
676
677 lockdep_assert_held(&ar->data_lock);
678
679 if (!arvif->beacon)
680 return;
681
682 if (!arvif->beacon_buf)
683 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
684 arvif->beacon->len, DMA_TO_DEVICE);
685
Michal Kazioraf213192015-01-29 14:29:52 +0200686 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
687 arvif->beacon_state != ATH10K_BEACON_SENT))
688 return;
689
Michal Kazior64badcb2014-09-18 11:18:02 +0300690 dev_kfree_skb_any(arvif->beacon);
691
692 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200693 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300694}
695
696static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
697{
698 struct ath10k *ar = arvif->ar;
699
700 lockdep_assert_held(&ar->data_lock);
701
702 ath10k_mac_vif_beacon_free(arvif);
703
704 if (arvif->beacon_buf) {
705 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
706 arvif->beacon_buf, arvif->beacon_paddr);
707 arvif->beacon_buf = NULL;
708 }
709}
710
Kalle Valo5e3dd152013-06-12 20:52:10 +0300711static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
712{
713 int ret;
714
Michal Kazior548db542013-07-05 16:15:15 +0300715 lockdep_assert_held(&ar->conf_mutex);
716
Michal Kazior7962b0d2014-10-28 10:34:38 +0100717 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
718 return -ESHUTDOWN;
719
Kalle Valo5e3dd152013-06-12 20:52:10 +0300720 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
721 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
722 if (ret == 0)
723 return -ETIMEDOUT;
724
725 return 0;
726}
727
Michal Kazior1bbc0972014-04-08 09:45:47 +0300728static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300729{
Michal Kaziorc930f742014-01-23 11:38:25 +0100730 struct cfg80211_chan_def *chandef = &ar->chandef;
731 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300732 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300733 int ret = 0;
734
735 lockdep_assert_held(&ar->conf_mutex);
736
Kalle Valo5e3dd152013-06-12 20:52:10 +0300737 arg.vdev_id = vdev_id;
738 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100739 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300740
741 /* TODO setup this dynamically, what in case we
742 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100743 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200744 arg.channel.chan_radar =
745 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300746
Michal Kazior89c5c842013-10-23 04:02:13 -0700747 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700748 arg.channel.max_power = channel->max_power * 2;
749 arg.channel.max_reg_power = channel->max_reg_power * 2;
750 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300751
Michal Kazior7962b0d2014-10-28 10:34:38 +0100752 reinit_completion(&ar->vdev_setup_done);
753
Kalle Valo5e3dd152013-06-12 20:52:10 +0300754 ret = ath10k_wmi_vdev_start(ar, &arg);
755 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200756 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200757 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300758 return ret;
759 }
760
761 ret = ath10k_vdev_setup_sync(ar);
762 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200763 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200764 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300765 return ret;
766 }
767
768 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200770 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200771 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300772 goto vdev_stop;
773 }
774
775 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300776
Michal Kazior7aa7a722014-08-25 12:09:38 +0200777 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300778 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300779 return 0;
780
781vdev_stop:
782 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
783 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200784 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200785 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300786
787 return ret;
788}
789
Michal Kazior1bbc0972014-04-08 09:45:47 +0300790static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300791{
792 int ret = 0;
793
794 lockdep_assert_held(&ar->conf_mutex);
795
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200796 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
797 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200798 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200799 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300800
Michal Kazior7962b0d2014-10-28 10:34:38 +0100801 reinit_completion(&ar->vdev_setup_done);
802
Kalle Valo5e3dd152013-06-12 20:52:10 +0300803 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
804 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200805 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200806 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300807
808 ret = ath10k_vdev_setup_sync(ar);
809 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200810 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200811 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300812
Michal Kazior7aa7a722014-08-25 12:09:38 +0200813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300814 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300815 return ret;
816}
817
Michal Kazior1bbc0972014-04-08 09:45:47 +0300818static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300819{
820 int bit, ret = 0;
821
822 lockdep_assert_held(&ar->conf_mutex);
823
Ben Greeara9aefb32014-08-12 11:02:19 +0300824 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200825 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300826 return -ENOMEM;
827 }
828
Ben Greear16c11172014-09-23 14:17:16 -0700829 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300830
Ben Greear16c11172014-09-23 14:17:16 -0700831 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300832
833 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
834 WMI_VDEV_TYPE_MONITOR,
835 0, ar->mac_addr);
836 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200837 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200838 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300839 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840 }
841
Ben Greear16c11172014-09-23 14:17:16 -0700842 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200843 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300844 ar->monitor_vdev_id);
845
Kalle Valo5e3dd152013-06-12 20:52:10 +0300846 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300847}
848
Michal Kazior1bbc0972014-04-08 09:45:47 +0300849static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850{
851 int ret = 0;
852
853 lockdep_assert_held(&ar->conf_mutex);
854
Kalle Valo5e3dd152013-06-12 20:52:10 +0300855 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
856 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200857 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200858 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300859 return ret;
860 }
861
Ben Greear16c11172014-09-23 14:17:16 -0700862 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863
Michal Kazior7aa7a722014-08-25 12:09:38 +0200864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300865 ar->monitor_vdev_id);
866 return ret;
867}
868
Michal Kazior1bbc0972014-04-08 09:45:47 +0300869static int ath10k_monitor_start(struct ath10k *ar)
870{
871 int ret;
872
873 lockdep_assert_held(&ar->conf_mutex);
874
Michal Kazior1bbc0972014-04-08 09:45:47 +0300875 ret = ath10k_monitor_vdev_create(ar);
876 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200877 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300878 return ret;
879 }
880
881 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
882 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200883 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300884 ath10k_monitor_vdev_delete(ar);
885 return ret;
886 }
887
888 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200889 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300890
891 return 0;
892}
893
Michal Kazior19337472014-08-28 12:58:16 +0200894static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300895{
896 int ret;
897
898 lockdep_assert_held(&ar->conf_mutex);
899
Michal Kazior1bbc0972014-04-08 09:45:47 +0300900 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200902 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200903 return ret;
904 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300905
906 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200907 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200908 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200909 return ret;
910 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300911
912 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200914
915 return 0;
916}
917
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530918static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
919{
920 struct ath10k_vif *arvif;
921
922 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
923 return true;
924
925 if (!ar->num_started_vdevs)
926 return false;
927
928 list_for_each_entry(arvif, &ar->arvifs, list)
929 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
930 return false;
931
932 ath10k_dbg(ar, ATH10K_DBG_MAC,
933 "mac disabling promiscuous mode because vdev is started\n");
934 return true;
935}
936
Michal Kazior19337472014-08-28 12:58:16 +0200937static int ath10k_monitor_recalc(struct ath10k *ar)
938{
939 bool should_start;
940
941 lockdep_assert_held(&ar->conf_mutex);
942
943 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100944 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200945 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
946
947 ath10k_dbg(ar, ATH10K_DBG_MAC,
948 "mac monitor recalc started? %d should? %d\n",
949 ar->monitor_started, should_start);
950
951 if (should_start == ar->monitor_started)
952 return 0;
953
954 if (should_start)
955 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300956
957 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300958}
959
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200960static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
961{
962 struct ath10k *ar = arvif->ar;
963 u32 vdev_param, rts_cts = 0;
964
965 lockdep_assert_held(&ar->conf_mutex);
966
967 vdev_param = ar->wmi.vdev_param->enable_rtscts;
968
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200969 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200970
971 if (arvif->num_legacy_stations > 0)
972 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
973 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200974 else
975 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
976 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200977
978 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
979 rts_cts);
980}
981
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200982static int ath10k_start_cac(struct ath10k *ar)
983{
984 int ret;
985
986 lockdep_assert_held(&ar->conf_mutex);
987
988 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
989
Michal Kazior19337472014-08-28 12:58:16 +0200990 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200991 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200992 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200993 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
994 return ret;
995 }
996
Michal Kazior7aa7a722014-08-25 12:09:38 +0200997 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200998 ar->monitor_vdev_id);
999
1000 return 0;
1001}
1002
1003static int ath10k_stop_cac(struct ath10k *ar)
1004{
1005 lockdep_assert_held(&ar->conf_mutex);
1006
1007 /* CAC is not running - do nothing */
1008 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1009 return 0;
1010
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001011 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001012 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001013
Michal Kazior7aa7a722014-08-25 12:09:38 +02001014 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001015
1016 return 0;
1017}
1018
Michal Kaziord6500972014-04-08 09:56:09 +03001019static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001020{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001021 int ret;
1022
1023 lockdep_assert_held(&ar->conf_mutex);
1024
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001025 ath10k_stop_cac(ar);
1026
Michal Kaziord6500972014-04-08 09:56:09 +03001027 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001028 return;
1029
Michal Kaziord6500972014-04-08 09:56:09 +03001030 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001031 return;
1032
1033 ret = ath10k_start_cac(ar);
1034 if (ret) {
1035 /*
1036 * Not possible to start CAC on current channel so starting
1037 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1038 * by indicating that radar was detected.
1039 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001040 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001041 ieee80211_radar_detected(ar->hw);
1042 }
1043}
1044
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301045static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1046{
1047 struct ath10k *ar = arvif->ar;
1048 int ret;
1049
1050 lockdep_assert_held(&ar->conf_mutex);
1051
1052 reinit_completion(&ar->vdev_setup_done);
1053
1054 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1055 if (ret) {
1056 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1057 arvif->vdev_id, ret);
1058 return ret;
1059 }
1060
1061 ret = ath10k_vdev_setup_sync(ar);
1062 if (ret) {
1063 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1064 arvif->vdev_id, ret);
1065 return ret;
1066 }
1067
1068 WARN_ON(ar->num_started_vdevs == 0);
1069
1070 if (ar->num_started_vdevs != 0) {
1071 ar->num_started_vdevs--;
1072 ath10k_recalc_radar_detection(ar);
1073 }
1074
1075 return ret;
1076}
1077
Michal Kaziordc55e302014-07-29 12:53:36 +03001078static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001079{
1080 struct ath10k *ar = arvif->ar;
1081 struct cfg80211_chan_def *chandef = &ar->chandef;
1082 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301083 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001084
1085 lockdep_assert_held(&ar->conf_mutex);
1086
1087 reinit_completion(&ar->vdev_setup_done);
1088
1089 arg.vdev_id = arvif->vdev_id;
1090 arg.dtim_period = arvif->dtim_period;
1091 arg.bcn_intval = arvif->beacon_interval;
1092
1093 arg.channel.freq = chandef->chan->center_freq;
1094 arg.channel.band_center_freq1 = chandef->center_freq1;
1095 arg.channel.mode = chan_to_phymode(chandef);
1096
1097 arg.channel.min_power = 0;
1098 arg.channel.max_power = chandef->chan->max_power * 2;
1099 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1100 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1101
1102 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1103 arg.ssid = arvif->u.ap.ssid;
1104 arg.ssid_len = arvif->u.ap.ssid_len;
1105 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1106
1107 /* For now allow DFS for AP mode */
1108 arg.channel.chan_radar =
1109 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1110 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1111 arg.ssid = arvif->vif->bss_conf.ssid;
1112 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1113 }
1114
Michal Kazior7aa7a722014-08-25 12:09:38 +02001115 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001116 "mac vdev %d start center_freq %d phymode %s\n",
1117 arg.vdev_id, arg.channel.freq,
1118 ath10k_wmi_phymode_str(arg.channel.mode));
1119
Michal Kaziordc55e302014-07-29 12:53:36 +03001120 if (restart)
1121 ret = ath10k_wmi_vdev_restart(ar, &arg);
1122 else
1123 ret = ath10k_wmi_vdev_start(ar, &arg);
1124
Michal Kazior72654fa2014-04-08 09:56:09 +03001125 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001126 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001127 arg.vdev_id, ret);
1128 return ret;
1129 }
1130
1131 ret = ath10k_vdev_setup_sync(ar);
1132 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001133 ath10k_warn(ar,
1134 "failed to synchronize setup for vdev %i restart %d: %d\n",
1135 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001136 return ret;
1137 }
1138
Michal Kaziord6500972014-04-08 09:56:09 +03001139 ar->num_started_vdevs++;
1140 ath10k_recalc_radar_detection(ar);
1141
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301142 ret = ath10k_monitor_recalc(ar);
1143 if (ret) {
1144 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1145 arg.vdev_id, restart, ret);
1146 ret2 = ath10k_vdev_stop(arvif);
1147 if (ret2)
1148 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1149 arg.vdev_id, restart, ret2);
1150 }
1151
Michal Kazior72654fa2014-04-08 09:56:09 +03001152 return ret;
1153}
1154
Michal Kaziordc55e302014-07-29 12:53:36 +03001155static int ath10k_vdev_start(struct ath10k_vif *arvif)
1156{
1157 return ath10k_vdev_start_restart(arvif, false);
1158}
1159
1160static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1161{
1162 return ath10k_vdev_start_restart(arvif, true);
1163}
1164
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001165static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1166 struct sk_buff *bcn)
1167{
1168 struct ath10k *ar = arvif->ar;
1169 struct ieee80211_mgmt *mgmt;
1170 const u8 *p2p_ie;
1171 int ret;
1172
1173 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1174 return 0;
1175
1176 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1177 return 0;
1178
1179 mgmt = (void *)bcn->data;
1180 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1181 mgmt->u.beacon.variable,
1182 bcn->len - (mgmt->u.beacon.variable -
1183 bcn->data));
1184 if (!p2p_ie)
1185 return -ENOENT;
1186
1187 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1188 if (ret) {
1189 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1190 arvif->vdev_id, ret);
1191 return ret;
1192 }
1193
1194 return 0;
1195}
1196
1197static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1198 u8 oui_type, size_t ie_offset)
1199{
1200 size_t len;
1201 const u8 *next;
1202 const u8 *end;
1203 u8 *ie;
1204
1205 if (WARN_ON(skb->len < ie_offset))
1206 return -EINVAL;
1207
1208 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1209 skb->data + ie_offset,
1210 skb->len - ie_offset);
1211 if (!ie)
1212 return -ENOENT;
1213
1214 len = ie[1] + 2;
1215 end = skb->data + skb->len;
1216 next = ie + len;
1217
1218 if (WARN_ON(next > end))
1219 return -EINVAL;
1220
1221 memmove(ie, next, end - next);
1222 skb_trim(skb, skb->len - len);
1223
1224 return 0;
1225}
1226
1227static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1228{
1229 struct ath10k *ar = arvif->ar;
1230 struct ieee80211_hw *hw = ar->hw;
1231 struct ieee80211_vif *vif = arvif->vif;
1232 struct ieee80211_mutable_offsets offs = {};
1233 struct sk_buff *bcn;
1234 int ret;
1235
1236 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1237 return 0;
1238
Michal Kazior81a9a172015-03-05 16:02:17 +02001239 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1240 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1241 return 0;
1242
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001243 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1244 if (!bcn) {
1245 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1246 return -EPERM;
1247 }
1248
1249 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1250 if (ret) {
1251 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1252 kfree_skb(bcn);
1253 return ret;
1254 }
1255
1256 /* P2P IE is inserted by firmware automatically (as configured above)
1257 * so remove it from the base beacon template to avoid duplicate P2P
1258 * IEs in beacon frames.
1259 */
1260 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1261 offsetof(struct ieee80211_mgmt,
1262 u.beacon.variable));
1263
1264 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1265 0, NULL, 0);
1266 kfree_skb(bcn);
1267
1268 if (ret) {
1269 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1270 ret);
1271 return ret;
1272 }
1273
1274 return 0;
1275}
1276
1277static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1278{
1279 struct ath10k *ar = arvif->ar;
1280 struct ieee80211_hw *hw = ar->hw;
1281 struct ieee80211_vif *vif = arvif->vif;
1282 struct sk_buff *prb;
1283 int ret;
1284
1285 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1286 return 0;
1287
Michal Kazior81a9a172015-03-05 16:02:17 +02001288 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1289 return 0;
1290
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001291 prb = ieee80211_proberesp_get(hw, vif);
1292 if (!prb) {
1293 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1294 return -EPERM;
1295 }
1296
1297 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1298 kfree_skb(prb);
1299
1300 if (ret) {
1301 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1302 ret);
1303 return ret;
1304 }
1305
1306 return 0;
1307}
1308
Kalle Valo5e3dd152013-06-12 20:52:10 +03001309static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001310 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001311{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001312 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001313 int ret = 0;
1314
Michal Kazior548db542013-07-05 16:15:15 +03001315 lockdep_assert_held(&arvif->ar->conf_mutex);
1316
Kalle Valo5e3dd152013-06-12 20:52:10 +03001317 if (!info->enable_beacon) {
1318 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001319
1320 arvif->is_started = false;
1321 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001322
1323 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001324 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001325 spin_unlock_bh(&arvif->ar->data_lock);
1326
Kalle Valo5e3dd152013-06-12 20:52:10 +03001327 return;
1328 }
1329
1330 arvif->tx_seq_no = 0x1000;
1331
1332 ret = ath10k_vdev_start(arvif);
1333 if (ret)
1334 return;
1335
Michal Kaziorc930f742014-01-23 11:38:25 +01001336 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001337 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001338
1339 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1340 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001342 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001343 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001344 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001345 return;
1346 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001347
1348 arvif->is_started = true;
1349 arvif->is_up = true;
1350
Michal Kazior7aa7a722014-08-25 12:09:38 +02001351 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352}
1353
1354static void ath10k_control_ibss(struct ath10k_vif *arvif,
1355 struct ieee80211_bss_conf *info,
1356 const u8 self_peer[ETH_ALEN])
1357{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001358 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001359 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001360 int ret = 0;
1361
Michal Kazior548db542013-07-05 16:15:15 +03001362 lockdep_assert_held(&arvif->ar->conf_mutex);
1363
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364 if (!info->ibss_joined) {
1365 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1366 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001367 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368 self_peer, arvif->vdev_id, ret);
1369
Michal Kaziorc930f742014-01-23 11:38:25 +01001370 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 return;
1372
Michal Kaziorc930f742014-01-23 11:38:25 +01001373 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001374
1375 return;
1376 }
1377
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001378 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1379 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001380 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001381 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001382 self_peer, arvif->vdev_id, ret);
1383 return;
1384 }
1385
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001386 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1387 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001388 ATH10K_DEFAULT_ATIM);
1389 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001390 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391 arvif->vdev_id, ret);
1392}
1393
Michal Kazior9f9b5742014-12-12 12:41:36 +01001394static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1395{
1396 struct ath10k *ar = arvif->ar;
1397 u32 param;
1398 u32 value;
1399 int ret;
1400
1401 lockdep_assert_held(&arvif->ar->conf_mutex);
1402
1403 if (arvif->u.sta.uapsd)
1404 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1405 else
1406 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1407
1408 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1409 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1410 if (ret) {
1411 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1412 value, arvif->vdev_id, ret);
1413 return ret;
1414 }
1415
1416 return 0;
1417}
1418
1419static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1420{
1421 struct ath10k *ar = arvif->ar;
1422 u32 param;
1423 u32 value;
1424 int ret;
1425
1426 lockdep_assert_held(&arvif->ar->conf_mutex);
1427
1428 if (arvif->u.sta.uapsd)
1429 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1430 else
1431 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1432
1433 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1434 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1435 param, value);
1436 if (ret) {
1437 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1438 value, arvif->vdev_id, ret);
1439 return ret;
1440 }
1441
1442 return 0;
1443}
1444
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001445static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1446{
1447 struct ath10k_vif *arvif;
1448 int num = 0;
1449
1450 lockdep_assert_held(&ar->conf_mutex);
1451
1452 list_for_each_entry(arvif, &ar->arvifs, list)
1453 if (arvif->ps)
1454 num++;
1455
1456 return num;
1457}
1458
Michal Kaziorad088bf2013-10-16 15:44:46 +03001459static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001460{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001461 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001462 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001463 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001464 enum wmi_sta_powersave_param param;
1465 enum wmi_sta_ps_mode psmode;
1466 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001467 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001468 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001469
Michal Kazior548db542013-07-05 16:15:15 +03001470 lockdep_assert_held(&arvif->ar->conf_mutex);
1471
Michal Kaziorad088bf2013-10-16 15:44:46 +03001472 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1473 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001475 enable_ps = arvif->ps;
1476
1477 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1478 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1479 ar->fw_features)) {
1480 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1481 arvif->vdev_id);
1482 enable_ps = false;
1483 }
1484
1485 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001486 psmode = WMI_STA_PS_MODE_ENABLED;
1487 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1488
Michal Kazior526549a2014-12-12 12:41:37 +01001489 ps_timeout = conf->dynamic_ps_timeout;
1490 if (ps_timeout == 0) {
1491 /* Firmware doesn't like 0 */
1492 ps_timeout = ieee80211_tu_to_usec(
1493 vif->bss_conf.beacon_int) / 1000;
1494 }
1495
Michal Kaziorad088bf2013-10-16 15:44:46 +03001496 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001497 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001499 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001500 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001501 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001503 } else {
1504 psmode = WMI_STA_PS_MODE_DISABLED;
1505 }
1506
Michal Kazior7aa7a722014-08-25 12:09:38 +02001507 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001508 arvif->vdev_id, psmode ? "enable" : "disable");
1509
Michal Kaziorad088bf2013-10-16 15:44:46 +03001510 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1511 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001512 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001513 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001514 return ret;
1515 }
1516
1517 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518}
1519
Michal Kazior46725b152015-01-28 09:57:49 +02001520static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1521{
1522 struct ath10k *ar = arvif->ar;
1523 struct wmi_sta_keepalive_arg arg = {};
1524 int ret;
1525
1526 lockdep_assert_held(&arvif->ar->conf_mutex);
1527
1528 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1529 return 0;
1530
1531 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1532 return 0;
1533
1534 /* Some firmware revisions have a bug and ignore the `enabled` field.
1535 * Instead use the interval to disable the keepalive.
1536 */
1537 arg.vdev_id = arvif->vdev_id;
1538 arg.enabled = 1;
1539 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1540 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1541
1542 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1543 if (ret) {
1544 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1545 arvif->vdev_id, ret);
1546 return ret;
1547 }
1548
1549 return 0;
1550}
1551
Michal Kazior81a9a172015-03-05 16:02:17 +02001552static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1553{
1554 struct ath10k *ar = arvif->ar;
1555 struct ieee80211_vif *vif = arvif->vif;
1556 int ret;
1557
Michal Kazior8513d952015-03-09 14:19:24 +01001558 lockdep_assert_held(&arvif->ar->conf_mutex);
1559
1560 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1561 return;
1562
Michal Kazior81a9a172015-03-05 16:02:17 +02001563 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1564 return;
1565
1566 if (!vif->csa_active)
1567 return;
1568
1569 if (!arvif->is_up)
1570 return;
1571
1572 if (!ieee80211_csa_is_complete(vif)) {
1573 ieee80211_csa_update_counter(vif);
1574
1575 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1576 if (ret)
1577 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1578 ret);
1579
1580 ret = ath10k_mac_setup_prb_tmpl(arvif);
1581 if (ret)
1582 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1583 ret);
1584 } else {
1585 ieee80211_csa_finish(vif);
1586 }
1587}
1588
1589static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1590{
1591 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1592 ap_csa_work);
1593 struct ath10k *ar = arvif->ar;
1594
1595 mutex_lock(&ar->conf_mutex);
1596 ath10k_mac_vif_ap_csa_count_down(arvif);
1597 mutex_unlock(&ar->conf_mutex);
1598}
1599
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001600static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1601 struct ieee80211_vif *vif)
1602{
1603 struct sk_buff *skb = data;
1604 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1605 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1606
1607 if (vif->type != NL80211_IFTYPE_STATION)
1608 return;
1609
1610 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1611 return;
1612
1613 cancel_delayed_work(&arvif->connection_loss_work);
1614}
1615
1616void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1617{
1618 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1619 IEEE80211_IFACE_ITER_NORMAL,
1620 ath10k_mac_handle_beacon_iter,
1621 skb);
1622}
1623
1624static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1625 struct ieee80211_vif *vif)
1626{
1627 u32 *vdev_id = data;
1628 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1629 struct ath10k *ar = arvif->ar;
1630 struct ieee80211_hw *hw = ar->hw;
1631
1632 if (arvif->vdev_id != *vdev_id)
1633 return;
1634
1635 if (!arvif->is_up)
1636 return;
1637
1638 ieee80211_beacon_loss(vif);
1639
1640 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1641 * (done by mac80211) succeeds but beacons do not resume then it
1642 * doesn't make sense to continue operation. Queue connection loss work
1643 * which can be cancelled when beacon is received.
1644 */
1645 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1646 ATH10K_CONNECTION_LOSS_HZ);
1647}
1648
1649void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1650{
1651 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1652 IEEE80211_IFACE_ITER_NORMAL,
1653 ath10k_mac_handle_beacon_miss_iter,
1654 &vdev_id);
1655}
1656
1657static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1658{
1659 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1660 connection_loss_work.work);
1661 struct ieee80211_vif *vif = arvif->vif;
1662
1663 if (!arvif->is_up)
1664 return;
1665
1666 ieee80211_connection_loss(vif);
1667}
1668
Kalle Valo5e3dd152013-06-12 20:52:10 +03001669/**********************/
1670/* Station management */
1671/**********************/
1672
Michal Kazior590922a2014-10-21 10:10:29 +03001673static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1674 struct ieee80211_vif *vif)
1675{
1676 /* Some firmware revisions have unstable STA powersave when listen
1677 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1678 * generate NullFunc frames properly even if buffered frames have been
1679 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1680 * buffered frames. Often pinging the device from AP would simply fail.
1681 *
1682 * As a workaround set it to 1.
1683 */
1684 if (vif->type == NL80211_IFTYPE_STATION)
1685 return 1;
1686
1687 return ar->hw->conf.listen_interval;
1688}
1689
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001691 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001693 struct wmi_peer_assoc_complete_arg *arg)
1694{
Michal Kazior590922a2014-10-21 10:10:29 +03001695 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1696
Michal Kazior548db542013-07-05 16:15:15 +03001697 lockdep_assert_held(&ar->conf_mutex);
1698
Kalle Valob25f32c2014-09-14 12:50:49 +03001699 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700 arg->vdev_id = arvif->vdev_id;
1701 arg->peer_aid = sta->aid;
1702 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001703 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001704 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001705 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706}
1707
1708static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001709 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001710 struct wmi_peer_assoc_complete_arg *arg)
1711{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001712 struct ieee80211_bss_conf *info = &vif->bss_conf;
1713 struct cfg80211_bss *bss;
1714 const u8 *rsnie = NULL;
1715 const u8 *wpaie = NULL;
1716
Michal Kazior548db542013-07-05 16:15:15 +03001717 lockdep_assert_held(&ar->conf_mutex);
1718
Kalle Valo5e3dd152013-06-12 20:52:10 +03001719 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001720 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1721 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722 if (bss) {
1723 const struct cfg80211_bss_ies *ies;
1724
1725 rcu_read_lock();
1726 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1727
1728 ies = rcu_dereference(bss->ies);
1729
1730 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001731 WLAN_OUI_TYPE_MICROSOFT_WPA,
1732 ies->data,
1733 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001734 rcu_read_unlock();
1735 cfg80211_put_bss(ar->hw->wiphy, bss);
1736 }
1737
1738 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1739 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001740 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001741 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1742 }
1743
1744 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001745 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1747 }
1748}
1749
1750static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1751 struct ieee80211_sta *sta,
1752 struct wmi_peer_assoc_complete_arg *arg)
1753{
1754 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1755 const struct ieee80211_supported_band *sband;
1756 const struct ieee80211_rate *rates;
1757 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03001758 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759 int i;
1760
Michal Kazior548db542013-07-05 16:15:15 +03001761 lockdep_assert_held(&ar->conf_mutex);
1762
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1764 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1765 rates = sband->bitrates;
1766
1767 rateset->num_rates = 0;
1768
1769 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1770 if (!(ratemask & 1))
1771 continue;
1772
Michal Kazior486017c2015-03-30 09:51:54 +03001773 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
1774 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001775 rateset->num_rates++;
1776 }
1777}
1778
1779static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1780 struct ieee80211_sta *sta,
1781 struct wmi_peer_assoc_complete_arg *arg)
1782{
1783 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001785 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786
Michal Kazior548db542013-07-05 16:15:15 +03001787 lockdep_assert_held(&ar->conf_mutex);
1788
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789 if (!ht_cap->ht_supported)
1790 return;
1791
1792 arg->peer_flags |= WMI_PEER_HT;
1793 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1794 ht_cap->ampdu_factor)) - 1;
1795
1796 arg->peer_mpdu_density =
1797 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1798
1799 arg->peer_ht_caps = ht_cap->cap;
1800 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1801
1802 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1803 arg->peer_flags |= WMI_PEER_LDPC;
1804
1805 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1806 arg->peer_flags |= WMI_PEER_40MHZ;
1807 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1808 }
1809
1810 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1811 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1812
1813 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1814 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1815
1816 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1817 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1818 arg->peer_flags |= WMI_PEER_STBC;
1819 }
1820
1821 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001822 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1823 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1824 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1825 arg->peer_rate_caps |= stbc;
1826 arg->peer_flags |= WMI_PEER_STBC;
1827 }
1828
Kalle Valo5e3dd152013-06-12 20:52:10 +03001829 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1830 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1831 else if (ht_cap->mcs.rx_mask[1])
1832 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1833
1834 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1835 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1836 arg->peer_ht_rates.rates[n++] = i;
1837
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001838 /*
1839 * This is a workaround for HT-enabled STAs which break the spec
1840 * and have no HT capabilities RX mask (no HT RX MCS map).
1841 *
1842 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1843 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1844 *
1845 * Firmware asserts if such situation occurs.
1846 */
1847 if (n == 0) {
1848 arg->peer_ht_rates.num_rates = 8;
1849 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1850 arg->peer_ht_rates.rates[i] = i;
1851 } else {
1852 arg->peer_ht_rates.num_rates = n;
1853 arg->peer_num_spatial_streams = sta->rx_nss;
1854 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855
Michal Kazior7aa7a722014-08-25 12:09:38 +02001856 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001857 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001858 arg->peer_ht_rates.num_rates,
1859 arg->peer_num_spatial_streams);
1860}
1861
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001862static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1863 struct ath10k_vif *arvif,
1864 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001865{
1866 u32 uapsd = 0;
1867 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001868 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869
Michal Kazior548db542013-07-05 16:15:15 +03001870 lockdep_assert_held(&ar->conf_mutex);
1871
Kalle Valo5e3dd152013-06-12 20:52:10 +03001872 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001873 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001874 sta->uapsd_queues, sta->max_sp);
1875
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1877 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1878 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1879 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1880 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1881 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1882 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1883 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1884 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1885 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1886 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1887 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1888
Kalle Valo5e3dd152013-06-12 20:52:10 +03001889 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1890 max_sp = sta->max_sp;
1891
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001892 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1893 sta->addr,
1894 WMI_AP_PS_PEER_PARAM_UAPSD,
1895 uapsd);
1896 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001897 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001898 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001899 return ret;
1900 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001901
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001902 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1903 sta->addr,
1904 WMI_AP_PS_PEER_PARAM_MAX_SP,
1905 max_sp);
1906 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001907 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001908 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001909 return ret;
1910 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001911
1912 /* TODO setup this based on STA listen interval and
1913 beacon interval. Currently we don't know
1914 sta->listen_interval - mac80211 patch required.
1915 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001916 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001917 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1918 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001920 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001921 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001922 return ret;
1923 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001926 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001927}
1928
1929static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1930 struct ieee80211_sta *sta,
1931 struct wmi_peer_assoc_complete_arg *arg)
1932{
1933 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001934 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935
1936 if (!vht_cap->vht_supported)
1937 return;
1938
1939 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001940
1941 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1942 arg->peer_flags |= WMI_PEER_VHT_2G;
1943
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 arg->peer_vht_caps = vht_cap->cap;
1945
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001946 ampdu_factor = (vht_cap->cap &
1947 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1948 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1949
1950 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1951 * zero in VHT IE. Using it would result in degraded throughput.
1952 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1953 * it if VHT max_mpdu is smaller. */
1954 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1955 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1956 ampdu_factor)) - 1);
1957
Kalle Valo5e3dd152013-06-12 20:52:10 +03001958 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1959 arg->peer_flags |= WMI_PEER_80MHZ;
1960
1961 arg->peer_vht_rates.rx_max_rate =
1962 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1963 arg->peer_vht_rates.rx_mcs_set =
1964 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1965 arg->peer_vht_rates.tx_max_rate =
1966 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1967 arg->peer_vht_rates.tx_mcs_set =
1968 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1969
Michal Kazior7aa7a722014-08-25 12:09:38 +02001970 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001971 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972}
1973
1974static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001975 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001977 struct wmi_peer_assoc_complete_arg *arg)
1978{
Michal Kazior590922a2014-10-21 10:10:29 +03001979 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1980
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981 switch (arvif->vdev_type) {
1982 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001983 if (sta->wme)
1984 arg->peer_flags |= WMI_PEER_QOS;
1985
1986 if (sta->wme && sta->uapsd_queues) {
1987 arg->peer_flags |= WMI_PEER_APSD;
1988 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1989 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 break;
1991 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001992 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001993 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001995 case WMI_VDEV_TYPE_IBSS:
1996 if (sta->wme)
1997 arg->peer_flags |= WMI_PEER_QOS;
1998 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999 default:
2000 break;
2001 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002002
2003 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2004 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002005}
2006
Michal Kazior91b12082014-12-12 12:41:35 +01002007static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
2008{
2009 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
2010 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
2011}
2012
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002014 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 struct ieee80211_sta *sta,
2016 struct wmi_peer_assoc_complete_arg *arg)
2017{
2018 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2019
Kalle Valo5e3dd152013-06-12 20:52:10 +03002020 switch (ar->hw->conf.chandef.chan->band) {
2021 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002022 if (sta->vht_cap.vht_supported) {
2023 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2024 phymode = MODE_11AC_VHT40;
2025 else
2026 phymode = MODE_11AC_VHT20;
2027 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2029 phymode = MODE_11NG_HT40;
2030 else
2031 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01002032 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002033 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002034 } else {
2035 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 }
2037
2038 break;
2039 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002040 /*
2041 * Check VHT first.
2042 */
2043 if (sta->vht_cap.vht_supported) {
2044 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2045 phymode = MODE_11AC_VHT80;
2046 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2047 phymode = MODE_11AC_VHT40;
2048 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2049 phymode = MODE_11AC_VHT20;
2050 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2052 phymode = MODE_11NA_HT40;
2053 else
2054 phymode = MODE_11NA_HT20;
2055 } else {
2056 phymode = MODE_11A;
2057 }
2058
2059 break;
2060 default:
2061 break;
2062 }
2063
Michal Kazior7aa7a722014-08-25 12:09:38 +02002064 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002065 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002066
Kalle Valo5e3dd152013-06-12 20:52:10 +03002067 arg->peer_phymode = phymode;
2068 WARN_ON(phymode == MODE_UNKNOWN);
2069}
2070
Kalle Valob9ada652013-10-16 15:44:46 +03002071static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002072 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002073 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002074 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075{
Michal Kazior548db542013-07-05 16:15:15 +03002076 lockdep_assert_held(&ar->conf_mutex);
2077
Kalle Valob9ada652013-10-16 15:44:46 +03002078 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079
Michal Kazior590922a2014-10-21 10:10:29 +03002080 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2081 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002082 ath10k_peer_assoc_h_rates(ar, sta, arg);
2083 ath10k_peer_assoc_h_ht(ar, sta, arg);
2084 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002085 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2086 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002087
Kalle Valob9ada652013-10-16 15:44:46 +03002088 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089}
2090
Michal Kazior90046f52014-02-14 14:45:51 +01002091static const u32 ath10k_smps_map[] = {
2092 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2093 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2094 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2095 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2096};
2097
2098static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2099 const u8 *addr,
2100 const struct ieee80211_sta_ht_cap *ht_cap)
2101{
2102 int smps;
2103
2104 if (!ht_cap->ht_supported)
2105 return 0;
2106
2107 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2108 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2109
2110 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2111 return -EINVAL;
2112
2113 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2114 WMI_PEER_SMPS_STATE,
2115 ath10k_smps_map[smps]);
2116}
2117
Michal Kazior139e1702015-02-15 16:50:42 +02002118static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2119 struct ieee80211_vif *vif,
2120 struct ieee80211_sta_vht_cap vht_cap)
2121{
2122 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2123 int ret;
2124 u32 param;
2125 u32 value;
2126
2127 if (!(ar->vht_cap_info &
2128 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2129 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2130 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2131 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2132 return 0;
2133
2134 param = ar->wmi.vdev_param->txbf;
2135 value = 0;
2136
2137 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2138 return 0;
2139
2140 /* The following logic is correct. If a remote STA advertises support
2141 * for being a beamformer then we should enable us being a beamformee.
2142 */
2143
2144 if (ar->vht_cap_info &
2145 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2146 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2147 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2148 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2149
2150 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2151 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2152 }
2153
2154 if (ar->vht_cap_info &
2155 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2156 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2157 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2158 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2159
2160 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2161 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2162 }
2163
2164 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2165 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2166
2167 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2168 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2169
2170 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2171 if (ret) {
2172 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2173 value, ret);
2174 return ret;
2175 }
2176
2177 return 0;
2178}
2179
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180/* can be called only in mac80211 callbacks due to `key_count` usage */
2181static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2182 struct ieee80211_vif *vif,
2183 struct ieee80211_bss_conf *bss_conf)
2184{
2185 struct ath10k *ar = hw->priv;
2186 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002187 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002188 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002189 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190 struct ieee80211_sta *ap_sta;
2191 int ret;
2192
Michal Kazior548db542013-07-05 16:15:15 +03002193 lockdep_assert_held(&ar->conf_mutex);
2194
Michal Kazior077efc82014-10-21 10:10:29 +03002195 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2196 arvif->vdev_id, arvif->bssid, arvif->aid);
2197
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198 rcu_read_lock();
2199
2200 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2201 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002202 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002203 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002204 rcu_read_unlock();
2205 return;
2206 }
2207
Michal Kazior90046f52014-02-14 14:45:51 +01002208 /* ap_sta must be accessed only within rcu section which must be left
2209 * before calling ath10k_setup_peer_smps() which might sleep. */
2210 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002211 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002212
Michal Kazior590922a2014-10-21 10:10:29 +03002213 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002215 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002216 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002217 rcu_read_unlock();
2218 return;
2219 }
2220
2221 rcu_read_unlock();
2222
Kalle Valob9ada652013-10-16 15:44:46 +03002223 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2224 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002225 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002226 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002227 return;
2228 }
2229
Michal Kazior90046f52014-02-14 14:45:51 +01002230 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2231 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002232 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002233 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002234 return;
2235 }
2236
Michal Kazior139e1702015-02-15 16:50:42 +02002237 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2238 if (ret) {
2239 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2240 arvif->vdev_id, bss_conf->bssid, ret);
2241 return;
2242 }
2243
Michal Kazior7aa7a722014-08-25 12:09:38 +02002244 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002245 "mac vdev %d up (associated) bssid %pM aid %d\n",
2246 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2247
Michal Kazior077efc82014-10-21 10:10:29 +03002248 WARN_ON(arvif->is_up);
2249
Michal Kaziorc930f742014-01-23 11:38:25 +01002250 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002251 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002252
2253 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2254 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002255 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002256 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002257 return;
2258 }
2259
2260 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002261
2262 /* Workaround: Some firmware revisions (tested with qca6174
2263 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2264 * poked with peer param command.
2265 */
2266 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2267 WMI_PEER_DUMMY_VAR, 1);
2268 if (ret) {
2269 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2270 arvif->bssid, arvif->vdev_id, ret);
2271 return;
2272 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002273}
2274
Kalle Valo5e3dd152013-06-12 20:52:10 +03002275static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2276 struct ieee80211_vif *vif)
2277{
2278 struct ath10k *ar = hw->priv;
2279 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002280 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 int ret;
2282
Michal Kazior548db542013-07-05 16:15:15 +03002283 lockdep_assert_held(&ar->conf_mutex);
2284
Michal Kazior077efc82014-10-21 10:10:29 +03002285 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2286 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002287
Kalle Valo5e3dd152013-06-12 20:52:10 +03002288 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002289 if (ret)
2290 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2291 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002293 arvif->def_wep_key_idx = -1;
2294
Michal Kazior139e1702015-02-15 16:50:42 +02002295 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2296 if (ret) {
2297 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2298 arvif->vdev_id, ret);
2299 return;
2300 }
2301
Michal Kaziorc930f742014-01-23 11:38:25 +01002302 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002303
2304 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002305}
2306
Michal Kazior590922a2014-10-21 10:10:29 +03002307static int ath10k_station_assoc(struct ath10k *ar,
2308 struct ieee80211_vif *vif,
2309 struct ieee80211_sta *sta,
2310 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002311{
Michal Kazior590922a2014-10-21 10:10:29 +03002312 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002313 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002314 int ret = 0;
2315
Michal Kazior548db542013-07-05 16:15:15 +03002316 lockdep_assert_held(&ar->conf_mutex);
2317
Michal Kazior590922a2014-10-21 10:10:29 +03002318 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002320 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002321 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002322 return ret;
2323 }
2324
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002325 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002326 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2327 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002328 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002329 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002330 return ret;
2331 }
2332
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002333 /* Re-assoc is run only to update supported rates for given station. It
2334 * doesn't make much sense to reconfigure the peer completely.
2335 */
2336 if (!reassoc) {
2337 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2338 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002339 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002340 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002341 arvif->vdev_id, ret);
2342 return ret;
2343 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002344
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002345 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2346 if (ret) {
2347 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2348 sta->addr, arvif->vdev_id, ret);
2349 return ret;
2350 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002351
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002352 if (!sta->wme) {
2353 arvif->num_legacy_stations++;
2354 ret = ath10k_recalc_rtscts_prot(arvif);
2355 if (ret) {
2356 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2357 arvif->vdev_id, ret);
2358 return ret;
2359 }
2360 }
2361
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002362 /* Plumb cached keys only for static WEP */
2363 if (arvif->def_wep_key_idx != -1) {
2364 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2365 if (ret) {
2366 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2367 arvif->vdev_id, ret);
2368 return ret;
2369 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 }
2371 }
2372
Kalle Valo5e3dd152013-06-12 20:52:10 +03002373 return ret;
2374}
2375
Michal Kazior590922a2014-10-21 10:10:29 +03002376static int ath10k_station_disassoc(struct ath10k *ar,
2377 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378 struct ieee80211_sta *sta)
2379{
Michal Kazior590922a2014-10-21 10:10:29 +03002380 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002381 int ret = 0;
2382
2383 lockdep_assert_held(&ar->conf_mutex);
2384
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002385 if (!sta->wme) {
2386 arvif->num_legacy_stations--;
2387 ret = ath10k_recalc_rtscts_prot(arvif);
2388 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002389 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002390 arvif->vdev_id, ret);
2391 return ret;
2392 }
2393 }
2394
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2396 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002397 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002398 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002399 return ret;
2400 }
2401
2402 return ret;
2403}
2404
2405/**************/
2406/* Regulatory */
2407/**************/
2408
2409static int ath10k_update_channel_list(struct ath10k *ar)
2410{
2411 struct ieee80211_hw *hw = ar->hw;
2412 struct ieee80211_supported_band **bands;
2413 enum ieee80211_band band;
2414 struct ieee80211_channel *channel;
2415 struct wmi_scan_chan_list_arg arg = {0};
2416 struct wmi_channel_arg *ch;
2417 bool passive;
2418 int len;
2419 int ret;
2420 int i;
2421
Michal Kazior548db542013-07-05 16:15:15 +03002422 lockdep_assert_held(&ar->conf_mutex);
2423
Kalle Valo5e3dd152013-06-12 20:52:10 +03002424 bands = hw->wiphy->bands;
2425 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2426 if (!bands[band])
2427 continue;
2428
2429 for (i = 0; i < bands[band]->n_channels; i++) {
2430 if (bands[band]->channels[i].flags &
2431 IEEE80211_CHAN_DISABLED)
2432 continue;
2433
2434 arg.n_channels++;
2435 }
2436 }
2437
2438 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2439 arg.channels = kzalloc(len, GFP_KERNEL);
2440 if (!arg.channels)
2441 return -ENOMEM;
2442
2443 ch = arg.channels;
2444 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2445 if (!bands[band])
2446 continue;
2447
2448 for (i = 0; i < bands[band]->n_channels; i++) {
2449 channel = &bands[band]->channels[i];
2450
2451 if (channel->flags & IEEE80211_CHAN_DISABLED)
2452 continue;
2453
2454 ch->allow_ht = true;
2455
2456 /* FIXME: when should we really allow VHT? */
2457 ch->allow_vht = true;
2458
2459 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002460 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461
2462 ch->ht40plus =
2463 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2464
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002465 ch->chan_radar =
2466 !!(channel->flags & IEEE80211_CHAN_RADAR);
2467
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002468 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002469 ch->passive = passive;
2470
2471 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002472 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002473 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002474 ch->max_power = channel->max_power * 2;
2475 ch->max_reg_power = channel->max_reg_power * 2;
2476 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002477 ch->reg_class_id = 0; /* FIXME */
2478
2479 /* FIXME: why use only legacy modes, why not any
2480 * HT/VHT modes? Would that even make any
2481 * difference? */
2482 if (channel->band == IEEE80211_BAND_2GHZ)
2483 ch->mode = MODE_11G;
2484 else
2485 ch->mode = MODE_11A;
2486
2487 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2488 continue;
2489
Michal Kazior7aa7a722014-08-25 12:09:38 +02002490 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002491 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2492 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002493 ch->freq, ch->max_power, ch->max_reg_power,
2494 ch->max_antenna_gain, ch->mode);
2495
2496 ch++;
2497 }
2498 }
2499
2500 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2501 kfree(arg.channels);
2502
2503 return ret;
2504}
2505
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002506static enum wmi_dfs_region
2507ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2508{
2509 switch (dfs_region) {
2510 case NL80211_DFS_UNSET:
2511 return WMI_UNINIT_DFS_DOMAIN;
2512 case NL80211_DFS_FCC:
2513 return WMI_FCC_DFS_DOMAIN;
2514 case NL80211_DFS_ETSI:
2515 return WMI_ETSI_DFS_DOMAIN;
2516 case NL80211_DFS_JP:
2517 return WMI_MKK4_DFS_DOMAIN;
2518 }
2519 return WMI_UNINIT_DFS_DOMAIN;
2520}
2521
Michal Kaziorf7843d72013-07-16 09:38:52 +02002522static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002524 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002526 enum wmi_dfs_region wmi_dfs_reg;
2527 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528
Michal Kaziorf7843d72013-07-16 09:38:52 +02002529 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002530
2531 ret = ath10k_update_channel_list(ar);
2532 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002533 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534
2535 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002536
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002537 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2538 nl_dfs_reg = ar->dfs_detector->region;
2539 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2540 } else {
2541 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2542 }
2543
Kalle Valo5e3dd152013-06-12 20:52:10 +03002544 /* Target allows setting up per-band regdomain but ath_common provides
2545 * a combined one only */
2546 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002547 regpair->reg_domain,
2548 regpair->reg_domain, /* 2ghz */
2549 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002550 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002551 regpair->reg_5ghz_ctl,
2552 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002553 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002554 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002555}
Michal Kazior548db542013-07-05 16:15:15 +03002556
Michal Kaziorf7843d72013-07-16 09:38:52 +02002557static void ath10k_reg_notifier(struct wiphy *wiphy,
2558 struct regulatory_request *request)
2559{
2560 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2561 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002562 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002563
2564 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2565
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002566 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002567 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002568 request->dfs_region);
2569 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2570 request->dfs_region);
2571 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002572 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002573 request->dfs_region);
2574 }
2575
Michal Kaziorf7843d72013-07-16 09:38:52 +02002576 mutex_lock(&ar->conf_mutex);
2577 if (ar->state == ATH10K_STATE_ON)
2578 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002579 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580}
2581
2582/***************/
2583/* TX handlers */
2584/***************/
2585
Michal Kazior42c3aa62013-10-02 11:03:38 +02002586static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2587{
2588 if (ieee80211_is_mgmt(hdr->frame_control))
2589 return HTT_DATA_TX_EXT_TID_MGMT;
2590
2591 if (!ieee80211_is_data_qos(hdr->frame_control))
2592 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2593
2594 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2595 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2596
2597 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2598}
2599
Michal Kazior2b37c292014-09-02 11:00:22 +03002600static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002601{
Michal Kazior2b37c292014-09-02 11:00:22 +03002602 if (vif)
2603 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002604
Michal Kazior1bbc0972014-04-08 09:45:47 +03002605 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002606 return ar->monitor_vdev_id;
2607
Michal Kazior7aa7a722014-08-25 12:09:38 +02002608 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002609 return 0;
2610}
2611
Michal Kaziord740d8f2015-03-30 09:51:51 +03002612static enum ath10k_hw_txrx_mode
2613ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002614 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002615{
2616 const struct ieee80211_hdr *hdr = (void *)skb->data;
2617 __le16 fc = hdr->frame_control;
2618
2619 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2620 return ATH10K_HW_TXRX_RAW;
2621
2622 if (ieee80211_is_mgmt(fc))
2623 return ATH10K_HW_TXRX_MGMT;
2624
2625 /* Workaround:
2626 *
2627 * NullFunc frames are mostly used to ping if a client or AP are still
2628 * reachable and responsive. This implies tx status reports must be
2629 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2630 * come to a conclusion that the other end disappeared and tear down
2631 * BSS connection or it can never disconnect from BSS/client (which is
2632 * the case).
2633 *
2634 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2635 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2636 * which seems to deliver correct tx reports for NullFunc frames. The
2637 * downside of using it is it ignores client powersave state so it can
2638 * end up disconnecting sleeping clients in AP mode. It should fix STA
2639 * mode though because AP don't sleep.
2640 */
2641 if (ar->htt.target_version_major < 3 &&
2642 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2643 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2644 return ATH10K_HW_TXRX_MGMT;
2645
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002646 /* Workaround:
2647 *
2648 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2649 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2650 * to work with Ethernet txmode so use it.
2651 */
2652 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2653 return ATH10K_HW_TXRX_ETHERNET;
2654
Michal Kaziord740d8f2015-03-30 09:51:51 +03002655 return ATH10K_HW_TXRX_NATIVE_WIFI;
2656}
2657
Michal Kazior4b604552014-07-21 21:03:09 +03002658/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2659 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660 */
Michal Kazior4b604552014-07-21 21:03:09 +03002661static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002662{
2663 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002664 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002665 u8 *qos_ctl;
2666
2667 if (!ieee80211_is_data_qos(hdr->frame_control))
2668 return;
2669
2670 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002671 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2672 skb->data, (void *)qos_ctl - (void *)skb->data);
2673 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002674
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002675 /* Some firmware revisions don't handle sending QoS NullFunc well.
2676 * These frames are mainly used for CQM purposes so it doesn't really
2677 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002678 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002679 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002680 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002681 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002682
2683 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002684}
2685
Michal Kaziord740d8f2015-03-30 09:51:51 +03002686static void ath10k_tx_h_8023(struct sk_buff *skb)
2687{
2688 struct ieee80211_hdr *hdr;
2689 struct rfc1042_hdr *rfc1042;
2690 struct ethhdr *eth;
2691 size_t hdrlen;
2692 u8 da[ETH_ALEN];
2693 u8 sa[ETH_ALEN];
2694 __be16 type;
2695
2696 hdr = (void *)skb->data;
2697 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2698 rfc1042 = (void *)skb->data + hdrlen;
2699
2700 ether_addr_copy(da, ieee80211_get_DA(hdr));
2701 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2702 type = rfc1042->snap_type;
2703
2704 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2705 skb_push(skb, sizeof(*eth));
2706
2707 eth = (void *)skb->data;
2708 ether_addr_copy(eth->h_dest, da);
2709 ether_addr_copy(eth->h_source, sa);
2710 eth->h_proto = type;
2711}
2712
Michal Kazior4b604552014-07-21 21:03:09 +03002713static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2714 struct ieee80211_vif *vif,
2715 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002716{
2717 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002718 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2719
2720 /* This is case only for P2P_GO */
2721 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2722 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2723 return;
2724
2725 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2726 spin_lock_bh(&ar->data_lock);
2727 if (arvif->u.ap.noa_data)
2728 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2729 GFP_ATOMIC))
2730 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2731 arvif->u.ap.noa_data,
2732 arvif->u.ap.noa_len);
2733 spin_unlock_bh(&ar->data_lock);
2734 }
2735}
2736
Michal Kazior8d6d3622014-11-24 14:58:31 +01002737static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2738{
2739 /* FIXME: Not really sure since when the behaviour changed. At some
2740 * point new firmware stopped requiring creation of peer entries for
2741 * offchannel tx (and actually creating them causes issues with wmi-htc
2742 * tx credit replenishment and reliability). Assuming it's at least 3.4
2743 * because that's when the `freq` was introduced to TX_FRM HTT command.
2744 */
2745 return !(ar->htt.target_version_major >= 3 &&
2746 ar->htt.target_version_minor >= 4);
2747}
2748
Michal Kaziord740d8f2015-03-30 09:51:51 +03002749static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002751 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002752 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002753
Michal Kaziord740d8f2015-03-30 09:51:51 +03002754 spin_lock_bh(&ar->data_lock);
2755
2756 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2757 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2758 ret = -ENOSPC;
2759 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002760 }
2761
Michal Kaziord740d8f2015-03-30 09:51:51 +03002762 __skb_queue_tail(q, skb);
2763 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2764
2765unlock:
2766 spin_unlock_bh(&ar->data_lock);
2767
2768 return ret;
2769}
2770
2771static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2772{
2773 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2774 struct ath10k_htt *htt = &ar->htt;
2775 int ret = 0;
2776
2777 switch (cb->txmode) {
2778 case ATH10K_HW_TXRX_RAW:
2779 case ATH10K_HW_TXRX_NATIVE_WIFI:
2780 case ATH10K_HW_TXRX_ETHERNET:
2781 ret = ath10k_htt_tx(htt, skb);
2782 break;
2783 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002784 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002785 ar->fw_features))
2786 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2787 else if (ar->htt.target_version_major >= 3)
2788 ret = ath10k_htt_tx(htt, skb);
2789 else
2790 ret = ath10k_htt_mgmt_tx(htt, skb);
2791 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002792 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002793
2794 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002795 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2796 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002797 ieee80211_free_txskb(ar->hw, skb);
2798 }
2799}
2800
2801void ath10k_offchan_tx_purge(struct ath10k *ar)
2802{
2803 struct sk_buff *skb;
2804
2805 for (;;) {
2806 skb = skb_dequeue(&ar->offchan_tx_queue);
2807 if (!skb)
2808 break;
2809
2810 ieee80211_free_txskb(ar->hw, skb);
2811 }
2812}
2813
2814void ath10k_offchan_tx_work(struct work_struct *work)
2815{
2816 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2817 struct ath10k_peer *peer;
2818 struct ieee80211_hdr *hdr;
2819 struct sk_buff *skb;
2820 const u8 *peer_addr;
2821 int vdev_id;
2822 int ret;
2823
2824 /* FW requirement: We must create a peer before FW will send out
2825 * an offchannel frame. Otherwise the frame will be stuck and
2826 * never transmitted. We delete the peer upon tx completion.
2827 * It is unlikely that a peer for offchannel tx will already be
2828 * present. However it may be in some rare cases so account for that.
2829 * Otherwise we might remove a legitimate peer and break stuff. */
2830
2831 for (;;) {
2832 skb = skb_dequeue(&ar->offchan_tx_queue);
2833 if (!skb)
2834 break;
2835
2836 mutex_lock(&ar->conf_mutex);
2837
Michal Kazior7aa7a722014-08-25 12:09:38 +02002838 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002839 skb);
2840
2841 hdr = (struct ieee80211_hdr *)skb->data;
2842 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002843 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002844
2845 spin_lock_bh(&ar->data_lock);
2846 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2847 spin_unlock_bh(&ar->data_lock);
2848
2849 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002850 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002851 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002852 peer_addr, vdev_id);
2853
2854 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03002855 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
2856 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002857 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002858 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859 peer_addr, vdev_id, ret);
2860 }
2861
2862 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002863 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002864 ar->offchan_tx_skb = skb;
2865 spin_unlock_bh(&ar->data_lock);
2866
Michal Kaziord740d8f2015-03-30 09:51:51 +03002867 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002868
2869 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2870 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002871 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002872 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873 skb);
2874
2875 if (!peer) {
2876 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2877 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002878 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002879 peer_addr, vdev_id, ret);
2880 }
2881
2882 mutex_unlock(&ar->conf_mutex);
2883 }
2884}
2885
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002886void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2887{
2888 struct sk_buff *skb;
2889
2890 for (;;) {
2891 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2892 if (!skb)
2893 break;
2894
2895 ieee80211_free_txskb(ar->hw, skb);
2896 }
2897}
2898
2899void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2900{
2901 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2902 struct sk_buff *skb;
2903 int ret;
2904
2905 for (;;) {
2906 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2907 if (!skb)
2908 break;
2909
2910 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002911 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002912 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002913 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002914 ieee80211_free_txskb(ar->hw, skb);
2915 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002916 }
2917}
2918
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919/************/
2920/* Scanning */
2921/************/
2922
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002923void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002924{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002925 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002926
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002927 switch (ar->scan.state) {
2928 case ATH10K_SCAN_IDLE:
2929 break;
2930 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002931 if (ar->scan.is_roc)
2932 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002933 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002934 case ATH10K_SCAN_ABORTING:
2935 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002936 ieee80211_scan_completed(ar->hw,
2937 (ar->scan.state ==
2938 ATH10K_SCAN_ABORTING));
2939 /* fall through */
2940 case ATH10K_SCAN_STARTING:
2941 ar->scan.state = ATH10K_SCAN_IDLE;
2942 ar->scan_channel = NULL;
2943 ath10k_offchan_tx_purge(ar);
2944 cancel_delayed_work(&ar->scan.timeout);
2945 complete_all(&ar->scan.completed);
2946 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002947 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002948}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002949
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002950void ath10k_scan_finish(struct ath10k *ar)
2951{
2952 spin_lock_bh(&ar->data_lock);
2953 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002954 spin_unlock_bh(&ar->data_lock);
2955}
2956
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002957static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002958{
2959 struct wmi_stop_scan_arg arg = {
2960 .req_id = 1, /* FIXME */
2961 .req_type = WMI_SCAN_STOP_ONE,
2962 .u.scan_id = ATH10K_SCAN_ID,
2963 };
2964 int ret;
2965
2966 lockdep_assert_held(&ar->conf_mutex);
2967
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968 ret = ath10k_wmi_stop_scan(ar, &arg);
2969 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002970 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002971 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002972 }
2973
Kalle Valo5e3dd152013-06-12 20:52:10 +03002974 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002975 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002976 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002977 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002978 } else if (ret > 0) {
2979 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002980 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002981
2982out:
2983 /* Scan state should be updated upon scan completion but in case
2984 * firmware fails to deliver the event (for whatever reason) it is
2985 * desired to clean up scan state anyway. Firmware may have just
2986 * dropped the scan completion event delivery due to transport pipe
2987 * being overflown with data and/or it can recover on its own before
2988 * next scan request is submitted.
2989 */
2990 spin_lock_bh(&ar->data_lock);
2991 if (ar->scan.state != ATH10K_SCAN_IDLE)
2992 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002993 spin_unlock_bh(&ar->data_lock);
2994
2995 return ret;
2996}
2997
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002998static void ath10k_scan_abort(struct ath10k *ar)
2999{
3000 int ret;
3001
3002 lockdep_assert_held(&ar->conf_mutex);
3003
3004 spin_lock_bh(&ar->data_lock);
3005
3006 switch (ar->scan.state) {
3007 case ATH10K_SCAN_IDLE:
3008 /* This can happen if timeout worker kicked in and called
3009 * abortion while scan completion was being processed.
3010 */
3011 break;
3012 case ATH10K_SCAN_STARTING:
3013 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003014 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003015 ath10k_scan_state_str(ar->scan.state),
3016 ar->scan.state);
3017 break;
3018 case ATH10K_SCAN_RUNNING:
3019 ar->scan.state = ATH10K_SCAN_ABORTING;
3020 spin_unlock_bh(&ar->data_lock);
3021
3022 ret = ath10k_scan_stop(ar);
3023 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003024 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003025
3026 spin_lock_bh(&ar->data_lock);
3027 break;
3028 }
3029
3030 spin_unlock_bh(&ar->data_lock);
3031}
3032
3033void ath10k_scan_timeout_work(struct work_struct *work)
3034{
3035 struct ath10k *ar = container_of(work, struct ath10k,
3036 scan.timeout.work);
3037
3038 mutex_lock(&ar->conf_mutex);
3039 ath10k_scan_abort(ar);
3040 mutex_unlock(&ar->conf_mutex);
3041}
3042
Kalle Valo5e3dd152013-06-12 20:52:10 +03003043static int ath10k_start_scan(struct ath10k *ar,
3044 const struct wmi_start_scan_arg *arg)
3045{
3046 int ret;
3047
3048 lockdep_assert_held(&ar->conf_mutex);
3049
3050 ret = ath10k_wmi_start_scan(ar, arg);
3051 if (ret)
3052 return ret;
3053
Kalle Valo5e3dd152013-06-12 20:52:10 +03003054 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3055 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003056 ret = ath10k_scan_stop(ar);
3057 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003059
3060 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003061 }
3062
Ben Greear2f9eec02015-02-15 16:50:38 +02003063 /* If we failed to start the scan, return error code at
3064 * this point. This is probably due to some issue in the
3065 * firmware, but no need to wedge the driver due to that...
3066 */
3067 spin_lock_bh(&ar->data_lock);
3068 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3069 spin_unlock_bh(&ar->data_lock);
3070 return -EINVAL;
3071 }
3072 spin_unlock_bh(&ar->data_lock);
3073
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003074 /* Add a 200ms margin to account for event/command processing */
3075 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3076 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003077 return 0;
3078}
3079
3080/**********************/
3081/* mac80211 callbacks */
3082/**********************/
3083
3084static void ath10k_tx(struct ieee80211_hw *hw,
3085 struct ieee80211_tx_control *control,
3086 struct sk_buff *skb)
3087{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003088 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003089 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3090 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003091 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003092 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003093 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094
3095 /* We should disable CCK RATE due to P2P */
3096 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003097 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098
Michal Kazior4b604552014-07-21 21:03:09 +03003099 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003100 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003101 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003102 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003103 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003104 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003105
Michal Kaziord740d8f2015-03-30 09:51:51 +03003106 switch (ATH10K_SKB_CB(skb)->txmode) {
3107 case ATH10K_HW_TXRX_MGMT:
3108 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003109 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003110 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3111 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003112 break;
3113 case ATH10K_HW_TXRX_ETHERNET:
3114 ath10k_tx_h_8023(skb);
3115 break;
3116 case ATH10K_HW_TXRX_RAW:
3117 /* FIXME: Packet injection isn't implemented. It should be
3118 * doable with firmware 10.2 on qca988x.
3119 */
3120 WARN_ON_ONCE(1);
3121 ieee80211_free_txskb(hw, skb);
3122 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003123 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003124
Kalle Valo5e3dd152013-06-12 20:52:10 +03003125 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3126 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003127 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003128 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 spin_unlock_bh(&ar->data_lock);
3130
Michal Kazior8d6d3622014-11-24 14:58:31 +01003131 if (ath10k_mac_need_offchan_tx_work(ar)) {
3132 ATH10K_SKB_CB(skb)->htt.freq = 0;
3133 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003134
Michal Kazior8d6d3622014-11-24 14:58:31 +01003135 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3136 skb);
3137
3138 skb_queue_tail(&ar->offchan_tx_queue, skb);
3139 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3140 return;
3141 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003142 }
3143
Michal Kaziord740d8f2015-03-30 09:51:51 +03003144 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003145}
3146
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003147/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003148void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003149{
3150 /* make sure rcu-protected mac80211 tx path itself is drained */
3151 synchronize_net();
3152
3153 ath10k_offchan_tx_purge(ar);
3154 ath10k_mgmt_over_wmi_tx_purge(ar);
3155
3156 cancel_work_sync(&ar->offchan_tx_work);
3157 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3158}
3159
Michal Kazioraffd3212013-07-16 09:54:35 +02003160void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003161{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003162 struct ath10k_vif *arvif;
3163
Michal Kazior818bdd12013-07-16 09:38:57 +02003164 lockdep_assert_held(&ar->conf_mutex);
3165
Michal Kazior19337472014-08-28 12:58:16 +02003166 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3167 ar->filter_flags = 0;
3168 ar->monitor = false;
3169
3170 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003171 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003172
3173 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003174
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003175 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003176 ath10k_peer_cleanup_all(ar);
3177 ath10k_core_stop(ar);
3178 ath10k_hif_power_down(ar);
3179
3180 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003181 list_for_each_entry(arvif, &ar->arvifs, list)
3182 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003183 spin_unlock_bh(&ar->data_lock);
3184}
3185
Ben Greear46acf7b2014-05-16 17:15:38 +03003186static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3187{
3188 struct ath10k *ar = hw->priv;
3189
3190 mutex_lock(&ar->conf_mutex);
3191
3192 if (ar->cfg_tx_chainmask) {
3193 *tx_ant = ar->cfg_tx_chainmask;
3194 *rx_ant = ar->cfg_rx_chainmask;
3195 } else {
3196 *tx_ant = ar->supp_tx_chainmask;
3197 *rx_ant = ar->supp_rx_chainmask;
3198 }
3199
3200 mutex_unlock(&ar->conf_mutex);
3201
3202 return 0;
3203}
3204
Ben Greear5572a952014-11-24 16:22:10 +02003205static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3206{
3207 /* It is not clear that allowing gaps in chainmask
3208 * is helpful. Probably it will not do what user
3209 * is hoping for, so warn in that case.
3210 */
3211 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3212 return;
3213
3214 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3215 dbg, cm);
3216}
3217
Ben Greear46acf7b2014-05-16 17:15:38 +03003218static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3219{
3220 int ret;
3221
3222 lockdep_assert_held(&ar->conf_mutex);
3223
Ben Greear5572a952014-11-24 16:22:10 +02003224 ath10k_check_chain_mask(ar, tx_ant, "tx");
3225 ath10k_check_chain_mask(ar, rx_ant, "rx");
3226
Ben Greear46acf7b2014-05-16 17:15:38 +03003227 ar->cfg_tx_chainmask = tx_ant;
3228 ar->cfg_rx_chainmask = rx_ant;
3229
3230 if ((ar->state != ATH10K_STATE_ON) &&
3231 (ar->state != ATH10K_STATE_RESTARTED))
3232 return 0;
3233
3234 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3235 tx_ant);
3236 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003237 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003238 ret, tx_ant);
3239 return ret;
3240 }
3241
3242 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3243 rx_ant);
3244 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003245 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003246 ret, rx_ant);
3247 return ret;
3248 }
3249
3250 return 0;
3251}
3252
3253static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3254{
3255 struct ath10k *ar = hw->priv;
3256 int ret;
3257
3258 mutex_lock(&ar->conf_mutex);
3259 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3260 mutex_unlock(&ar->conf_mutex);
3261 return ret;
3262}
3263
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264static int ath10k_start(struct ieee80211_hw *hw)
3265{
3266 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003267 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003268
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003269 /*
3270 * This makes sense only when restarting hw. It is harmless to call
3271 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3272 * commands will be submitted while restarting.
3273 */
3274 ath10k_drain_tx(ar);
3275
Michal Kazior548db542013-07-05 16:15:15 +03003276 mutex_lock(&ar->conf_mutex);
3277
Michal Kaziorc5058f52014-05-26 12:46:03 +03003278 switch (ar->state) {
3279 case ATH10K_STATE_OFF:
3280 ar->state = ATH10K_STATE_ON;
3281 break;
3282 case ATH10K_STATE_RESTARTING:
3283 ath10k_halt(ar);
3284 ar->state = ATH10K_STATE_RESTARTED;
3285 break;
3286 case ATH10K_STATE_ON:
3287 case ATH10K_STATE_RESTARTED:
3288 case ATH10K_STATE_WEDGED:
3289 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003290 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003291 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003292 case ATH10K_STATE_UTF:
3293 ret = -EBUSY;
3294 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003295 }
3296
3297 ret = ath10k_hif_power_up(ar);
3298 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003299 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003300 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003301 }
3302
Kalle Valo43d2a302014-09-10 18:23:30 +03003303 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003304 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003305 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003306 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003307 }
3308
Bartosz Markowski226a3392013-09-26 17:47:16 +02003309 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003310 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003311 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003312 goto err_core_stop;
3313 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003314
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003315 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003316 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003317 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003318 goto err_core_stop;
3319 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320
Ben Greear46acf7b2014-05-16 17:15:38 +03003321 if (ar->cfg_tx_chainmask)
3322 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3323 ar->cfg_rx_chainmask);
3324
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003325 /*
3326 * By default FW set ARP frames ac to voice (6). In that case ARP
3327 * exchange is not working properly for UAPSD enabled AP. ARP requests
3328 * which arrives with access category 0 are processed by network stack
3329 * and send back with access category 0, but FW changes access category
3330 * to 6. Set ARP frames access category to best effort (0) solves
3331 * this problem.
3332 */
3333
3334 ret = ath10k_wmi_pdev_set_param(ar,
3335 ar->wmi.pdev_param->arp_ac_override, 0);
3336 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003337 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003338 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003339 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003340 }
3341
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303342 ret = ath10k_wmi_pdev_set_param(ar,
3343 ar->wmi.pdev_param->ani_enable, 1);
3344 if (ret) {
3345 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3346 ret);
3347 goto err_core_stop;
3348 }
3349
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303350 ar->ani_enabled = true;
3351
Michal Kaziord6500972014-04-08 09:56:09 +03003352 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003353 ath10k_regd_update(ar);
3354
Simon Wunderlich855aed12014-08-02 09:12:54 +03003355 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303356 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003357
Michal Kaziorae254432014-05-26 12:46:02 +03003358 mutex_unlock(&ar->conf_mutex);
3359 return 0;
3360
3361err_core_stop:
3362 ath10k_core_stop(ar);
3363
3364err_power_down:
3365 ath10k_hif_power_down(ar);
3366
3367err_off:
3368 ar->state = ATH10K_STATE_OFF;
3369
3370err:
Michal Kazior548db542013-07-05 16:15:15 +03003371 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003372 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003373}
3374
3375static void ath10k_stop(struct ieee80211_hw *hw)
3376{
3377 struct ath10k *ar = hw->priv;
3378
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003379 ath10k_drain_tx(ar);
3380
Michal Kazior548db542013-07-05 16:15:15 +03003381 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003382 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003383 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003384 ar->state = ATH10K_STATE_OFF;
3385 }
Michal Kazior548db542013-07-05 16:15:15 +03003386 mutex_unlock(&ar->conf_mutex);
3387
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003388 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003389 cancel_work_sync(&ar->restart_work);
3390}
3391
Michal Kaziorad088bf2013-10-16 15:44:46 +03003392static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003393{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003394 struct ath10k_vif *arvif;
3395 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003396
3397 lockdep_assert_held(&ar->conf_mutex);
3398
Michal Kaziorad088bf2013-10-16 15:44:46 +03003399 list_for_each_entry(arvif, &ar->arvifs, list) {
3400 ret = ath10k_mac_vif_setup_ps(arvif);
3401 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003402 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003403 break;
3404 }
3405 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003406
Michal Kaziorad088bf2013-10-16 15:44:46 +03003407 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408}
3409
Michal Kaziorc930f742014-01-23 11:38:25 +01003410static const char *chandef_get_width(enum nl80211_chan_width width)
3411{
3412 switch (width) {
3413 case NL80211_CHAN_WIDTH_20_NOHT:
3414 return "20 (noht)";
3415 case NL80211_CHAN_WIDTH_20:
3416 return "20";
3417 case NL80211_CHAN_WIDTH_40:
3418 return "40";
3419 case NL80211_CHAN_WIDTH_80:
3420 return "80";
3421 case NL80211_CHAN_WIDTH_80P80:
3422 return "80+80";
3423 case NL80211_CHAN_WIDTH_160:
3424 return "160";
3425 case NL80211_CHAN_WIDTH_5:
3426 return "5";
3427 case NL80211_CHAN_WIDTH_10:
3428 return "10";
3429 }
3430 return "?";
3431}
3432
3433static void ath10k_config_chan(struct ath10k *ar)
3434{
3435 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003436 int ret;
3437
3438 lockdep_assert_held(&ar->conf_mutex);
3439
Michal Kazior7aa7a722014-08-25 12:09:38 +02003440 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003441 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3442 ar->chandef.chan->center_freq,
3443 ar->chandef.center_freq1,
3444 ar->chandef.center_freq2,
3445 chandef_get_width(ar->chandef.width));
3446
3447 /* First stop monitor interface. Some FW versions crash if there's a
3448 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003449 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003450 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003451
3452 list_for_each_entry(arvif, &ar->arvifs, list) {
3453 if (!arvif->is_started)
3454 continue;
3455
Michal Kaziordc55e302014-07-29 12:53:36 +03003456 if (!arvif->is_up)
3457 continue;
3458
Michal Kaziorc930f742014-01-23 11:38:25 +01003459 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3460 continue;
3461
Michal Kaziordc55e302014-07-29 12:53:36 +03003462 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003463 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003464 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003465 arvif->vdev_id, ret);
3466 continue;
3467 }
3468 }
3469
Michal Kaziordc55e302014-07-29 12:53:36 +03003470 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003471
3472 list_for_each_entry(arvif, &ar->arvifs, list) {
3473 if (!arvif->is_started)
3474 continue;
3475
3476 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3477 continue;
3478
Michal Kazior81a9a172015-03-05 16:02:17 +02003479 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3480 if (ret)
3481 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3482 ret);
3483
3484 ret = ath10k_mac_setup_prb_tmpl(arvif);
3485 if (ret)
3486 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3487 ret);
3488
Michal Kaziordc55e302014-07-29 12:53:36 +03003489 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003491 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003492 arvif->vdev_id, ret);
3493 continue;
3494 }
3495
3496 if (!arvif->is_up)
3497 continue;
3498
3499 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3500 arvif->bssid);
3501 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003502 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003503 arvif->vdev_id, ret);
3504 continue;
3505 }
3506 }
3507
Michal Kazior19337472014-08-28 12:58:16 +02003508 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003509}
3510
Michal Kazior7d9d5582014-10-21 10:40:15 +03003511static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3512{
3513 int ret;
3514 u32 param;
3515
3516 lockdep_assert_held(&ar->conf_mutex);
3517
3518 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3519
3520 param = ar->wmi.pdev_param->txpower_limit2g;
3521 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3522 if (ret) {
3523 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3524 txpower, ret);
3525 return ret;
3526 }
3527
3528 param = ar->wmi.pdev_param->txpower_limit5g;
3529 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3530 if (ret) {
3531 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3532 txpower, ret);
3533 return ret;
3534 }
3535
3536 return 0;
3537}
3538
3539static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3540{
3541 struct ath10k_vif *arvif;
3542 int ret, txpower = -1;
3543
3544 lockdep_assert_held(&ar->conf_mutex);
3545
3546 list_for_each_entry(arvif, &ar->arvifs, list) {
3547 WARN_ON(arvif->txpower < 0);
3548
3549 if (txpower == -1)
3550 txpower = arvif->txpower;
3551 else
3552 txpower = min(txpower, arvif->txpower);
3553 }
3554
3555 if (WARN_ON(txpower == -1))
3556 return -EINVAL;
3557
3558 ret = ath10k_mac_txpower_setup(ar, txpower);
3559 if (ret) {
3560 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3561 txpower, ret);
3562 return ret;
3563 }
3564
3565 return 0;
3566}
3567
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3569{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003570 struct ath10k *ar = hw->priv;
3571 struct ieee80211_conf *conf = &hw->conf;
3572 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003573
3574 mutex_lock(&ar->conf_mutex);
3575
3576 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003577 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003578 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003579 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003580 conf->chandef.chan->flags,
3581 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003582
Kalle Valo5e3dd152013-06-12 20:52:10 +03003583 spin_lock_bh(&ar->data_lock);
3584 ar->rx_channel = conf->chandef.chan;
3585 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003586
Michal Kaziord6500972014-04-08 09:56:09 +03003587 ar->radar_enabled = conf->radar_enabled;
3588 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003589
3590 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3591 ar->chandef = conf->chandef;
3592 ath10k_config_chan(ar);
3593 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003594 }
3595
Michal Kazioraffd3212013-07-16 09:54:35 +02003596 if (changed & IEEE80211_CONF_CHANGE_PS)
3597 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003598
3599 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003600 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3601 ret = ath10k_monitor_recalc(ar);
3602 if (ret)
3603 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003604 }
3605
3606 mutex_unlock(&ar->conf_mutex);
3607 return ret;
3608}
3609
Ben Greear5572a952014-11-24 16:22:10 +02003610static u32 get_nss_from_chainmask(u16 chain_mask)
3611{
3612 if ((chain_mask & 0x15) == 0x15)
3613 return 4;
3614 else if ((chain_mask & 0x7) == 0x7)
3615 return 3;
3616 else if ((chain_mask & 0x3) == 0x3)
3617 return 2;
3618 return 1;
3619}
3620
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621/*
3622 * TODO:
3623 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3624 * because we will send mgmt frames without CCK. This requirement
3625 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3626 * in the TX packet.
3627 */
3628static int ath10k_add_interface(struct ieee80211_hw *hw,
3629 struct ieee80211_vif *vif)
3630{
3631 struct ath10k *ar = hw->priv;
3632 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3633 enum wmi_sta_powersave_param param;
3634 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003635 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003636 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003637 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003638
Johannes Berg848955c2014-11-11 12:48:42 +01003639 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3640
Kalle Valo5e3dd152013-06-12 20:52:10 +03003641 mutex_lock(&ar->conf_mutex);
3642
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003643 memset(arvif, 0, sizeof(*arvif));
3644
Kalle Valo5e3dd152013-06-12 20:52:10 +03003645 arvif->ar = ar;
3646 arvif->vif = vif;
3647
Ben Greeare63b33f2013-10-22 14:54:14 -07003648 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003649 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003650 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3651 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003652
Ben Greeara9aefb32014-08-12 11:02:19 +03003653 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003654 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003656 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003657 }
Ben Greear16c11172014-09-23 14:17:16 -07003658 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659
Ben Greear16c11172014-09-23 14:17:16 -07003660 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3661 bit, ar->free_vdev_map);
3662
3663 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003664 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003665
Kalle Valo5e3dd152013-06-12 20:52:10 +03003666 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003667 case NL80211_IFTYPE_P2P_DEVICE:
3668 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3669 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3670 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003671 case NL80211_IFTYPE_UNSPECIFIED:
3672 case NL80211_IFTYPE_STATION:
3673 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3674 if (vif->p2p)
3675 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3676 break;
3677 case NL80211_IFTYPE_ADHOC:
3678 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3679 break;
3680 case NL80211_IFTYPE_AP:
3681 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3682
3683 if (vif->p2p)
3684 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3685 break;
3686 case NL80211_IFTYPE_MONITOR:
3687 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3688 break;
3689 default:
3690 WARN_ON(1);
3691 break;
3692 }
3693
Michal Kazior64badcb2014-09-18 11:18:02 +03003694 /* Some firmware revisions don't wait for beacon tx completion before
3695 * sending another SWBA event. This could lead to hardware using old
3696 * (freed) beacon data in some cases, e.g. tx credit starvation
3697 * combined with missed TBTT. This is very very rare.
3698 *
3699 * On non-IOMMU-enabled hosts this could be a possible security issue
3700 * because hw could beacon some random data on the air. On
3701 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3702 * device would crash.
3703 *
3704 * Since there are no beacon tx completions (implicit nor explicit)
3705 * propagated to host the only workaround for this is to allocate a
3706 * DMA-coherent buffer for a lifetime of a vif and use it for all
3707 * beacon tx commands. Worst case for this approach is some beacons may
3708 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3709 */
3710 if (vif->type == NL80211_IFTYPE_ADHOC ||
3711 vif->type == NL80211_IFTYPE_AP) {
3712 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3713 IEEE80211_MAX_FRAME_LEN,
3714 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303715 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003716 if (!arvif->beacon_buf) {
3717 ret = -ENOMEM;
3718 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3719 ret);
3720 goto err;
3721 }
3722 }
3723
3724 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3725 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3726 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003727
3728 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3729 arvif->vdev_subtype, vif->addr);
3730 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003731 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003732 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003733 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003734 }
3735
Ben Greear16c11172014-09-23 14:17:16 -07003736 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003737 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003738
Michal Kazior46725b152015-01-28 09:57:49 +02003739 /* It makes no sense to have firmware do keepalives. mac80211 already
3740 * takes care of this with idle connection polling.
3741 */
3742 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003743 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003744 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003745 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003746 goto err_vdev_delete;
3747 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003749 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003750
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003751 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3752 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003753 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003754 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003755 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003756 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003757 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003758 goto err_vdev_delete;
3759 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003760
Ben Greear5572a952014-11-24 16:22:10 +02003761 if (ar->cfg_tx_chainmask) {
3762 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3763
3764 vdev_param = ar->wmi.vdev_param->nss;
3765 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3766 nss);
3767 if (ret) {
3768 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3769 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3770 ret);
3771 goto err_vdev_delete;
3772 }
3773 }
3774
Kalle Valo5e3dd152013-06-12 20:52:10 +03003775 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003776 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
3777 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003778 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003779 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003780 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003781 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003782 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003783
Kalle Valo5a13e762014-01-20 11:01:46 +02003784 ret = ath10k_mac_set_kickout(arvif);
3785 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003786 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003787 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003788 goto err_peer_delete;
3789 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003790 }
3791
3792 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3793 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3794 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3795 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3796 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003797 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003798 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003799 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003800 goto err_peer_delete;
3801 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003802
Michal Kazior9f9b5742014-12-12 12:41:36 +01003803 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003804 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003805 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003806 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003807 goto err_peer_delete;
3808 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003809
Michal Kazior9f9b5742014-12-12 12:41:36 +01003810 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003811 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003812 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003813 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003814 goto err_peer_delete;
3815 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003816 }
3817
Michal Kazior424121c2013-07-22 14:13:31 +02003818 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003819 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003820 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003821 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003822 goto err_peer_delete;
3823 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003824
Michal Kazior424121c2013-07-22 14:13:31 +02003825 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003826 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003827 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003828 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003829 goto err_peer_delete;
3830 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003831
Michal Kazior7d9d5582014-10-21 10:40:15 +03003832 arvif->txpower = vif->bss_conf.txpower;
3833 ret = ath10k_mac_txpower_recalc(ar);
3834 if (ret) {
3835 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3836 goto err_peer_delete;
3837 }
3838
Kalle Valo5e3dd152013-06-12 20:52:10 +03003839 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003840 return 0;
3841
3842err_peer_delete:
3843 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3844 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3845
3846err_vdev_delete:
3847 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003848 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003849 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003850
3851err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003852 if (arvif->beacon_buf) {
3853 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3854 arvif->beacon_buf, arvif->beacon_paddr);
3855 arvif->beacon_buf = NULL;
3856 }
3857
Michal Kazior9dad14a2013-10-16 15:44:45 +03003858 mutex_unlock(&ar->conf_mutex);
3859
Kalle Valo5e3dd152013-06-12 20:52:10 +03003860 return ret;
3861}
3862
3863static void ath10k_remove_interface(struct ieee80211_hw *hw,
3864 struct ieee80211_vif *vif)
3865{
3866 struct ath10k *ar = hw->priv;
3867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3868 int ret;
3869
Michal Kazior81a9a172015-03-05 16:02:17 +02003870 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003871 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003872
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303873 mutex_lock(&ar->conf_mutex);
3874
Michal Kaziored543882013-09-13 14:16:56 +02003875 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003876 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003877 spin_unlock_bh(&ar->data_lock);
3878
Simon Wunderlich855aed12014-08-02 09:12:54 +03003879 ret = ath10k_spectral_vif_stop(arvif);
3880 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003881 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003882 arvif->vdev_id, ret);
3883
Ben Greear16c11172014-09-23 14:17:16 -07003884 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003885 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003886
3887 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003888 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3889 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003890 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003891 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003892 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893
3894 kfree(arvif->u.ap.noa_data);
3895 }
3896
Michal Kazior7aa7a722014-08-25 12:09:38 +02003897 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003898 arvif->vdev_id);
3899
Kalle Valo5e3dd152013-06-12 20:52:10 +03003900 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3901 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003902 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003903 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003904
Michal Kazior2c512052015-02-15 16:50:40 +02003905 /* Some firmware revisions don't notify host about self-peer removal
3906 * until after associated vdev is deleted.
3907 */
3908 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3909 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3910 vif->addr);
3911 if (ret)
3912 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3913 arvif->vdev_id, ret);
3914
3915 spin_lock_bh(&ar->data_lock);
3916 ar->num_peers--;
3917 spin_unlock_bh(&ar->data_lock);
3918 }
3919
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920 ath10k_peer_cleanup(ar, arvif->vdev_id);
3921
3922 mutex_unlock(&ar->conf_mutex);
3923}
3924
3925/*
3926 * FIXME: Has to be verified.
3927 */
3928#define SUPPORTED_FILTERS \
3929 (FIF_PROMISC_IN_BSS | \
3930 FIF_ALLMULTI | \
3931 FIF_CONTROL | \
3932 FIF_PSPOLL | \
3933 FIF_OTHER_BSS | \
3934 FIF_BCN_PRBRESP_PROMISC | \
3935 FIF_PROBE_REQ | \
3936 FIF_FCSFAIL)
3937
3938static void ath10k_configure_filter(struct ieee80211_hw *hw,
3939 unsigned int changed_flags,
3940 unsigned int *total_flags,
3941 u64 multicast)
3942{
3943 struct ath10k *ar = hw->priv;
3944 int ret;
3945
3946 mutex_lock(&ar->conf_mutex);
3947
3948 changed_flags &= SUPPORTED_FILTERS;
3949 *total_flags &= SUPPORTED_FILTERS;
3950 ar->filter_flags = *total_flags;
3951
Michal Kazior19337472014-08-28 12:58:16 +02003952 ret = ath10k_monitor_recalc(ar);
3953 if (ret)
3954 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955
3956 mutex_unlock(&ar->conf_mutex);
3957}
3958
3959static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3960 struct ieee80211_vif *vif,
3961 struct ieee80211_bss_conf *info,
3962 u32 changed)
3963{
3964 struct ath10k *ar = hw->priv;
3965 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3966 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003967 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003968
3969 mutex_lock(&ar->conf_mutex);
3970
3971 if (changed & BSS_CHANGED_IBSS)
3972 ath10k_control_ibss(arvif, info, vif->addr);
3973
3974 if (changed & BSS_CHANGED_BEACON_INT) {
3975 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003976 vdev_param = ar->wmi.vdev_param->beacon_interval;
3977 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003979 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003980 "mac vdev %d beacon_interval %d\n",
3981 arvif->vdev_id, arvif->beacon_interval);
3982
Kalle Valo5e3dd152013-06-12 20:52:10 +03003983 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003984 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003985 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003986 }
3987
3988 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003989 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003990 "vdev %d set beacon tx mode to staggered\n",
3991 arvif->vdev_id);
3992
Bartosz Markowski226a3392013-09-26 17:47:16 +02003993 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3994 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 WMI_BEACON_STAGGERED_MODE);
3996 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003997 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003998 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003999
4000 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4001 if (ret)
4002 ath10k_warn(ar, "failed to update beacon template: %d\n",
4003 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004004 }
4005
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004006 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4007 ret = ath10k_mac_setup_prb_tmpl(arvif);
4008 if (ret)
4009 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4010 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004011 }
4012
Michal Kaziorba2479f2015-01-24 12:14:51 +02004013 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014 arvif->dtim_period = info->dtim_period;
4015
Michal Kazior7aa7a722014-08-25 12:09:38 +02004016 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004017 "mac vdev %d dtim_period %d\n",
4018 arvif->vdev_id, arvif->dtim_period);
4019
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004020 vdev_param = ar->wmi.vdev_param->dtim_period;
4021 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022 arvif->dtim_period);
4023 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004024 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004025 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 }
4027
4028 if (changed & BSS_CHANGED_SSID &&
4029 vif->type == NL80211_IFTYPE_AP) {
4030 arvif->u.ap.ssid_len = info->ssid_len;
4031 if (info->ssid_len)
4032 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4033 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4034 }
4035
Michal Kazior077efc82014-10-21 10:10:29 +03004036 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4037 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004038
4039 if (changed & BSS_CHANGED_BEACON_ENABLED)
4040 ath10k_control_beaconing(arvif, info);
4041
4042 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004043 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004044 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004045 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004046
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004047 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004048 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004049 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004050 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004051
4052 vdev_param = ar->wmi.vdev_param->protection_mode;
4053 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4054 info->use_cts_prot ? 1 : 0);
4055 if (ret)
4056 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4057 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004058 }
4059
4060 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004061 if (info->use_short_slot)
4062 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4063
4064 else
4065 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4066
Michal Kazior7aa7a722014-08-25 12:09:38 +02004067 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004068 arvif->vdev_id, slottime);
4069
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004070 vdev_param = ar->wmi.vdev_param->slot_time;
4071 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004072 slottime);
4073 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004074 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004075 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004076 }
4077
4078 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004079 if (info->use_short_preamble)
4080 preamble = WMI_VDEV_PREAMBLE_SHORT;
4081 else
4082 preamble = WMI_VDEV_PREAMBLE_LONG;
4083
Michal Kazior7aa7a722014-08-25 12:09:38 +02004084 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004085 "mac vdev %d preamble %dn",
4086 arvif->vdev_id, preamble);
4087
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004088 vdev_param = ar->wmi.vdev_param->preamble;
4089 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004090 preamble);
4091 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004092 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004093 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004094 }
4095
4096 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004097 if (info->assoc) {
4098 /* Workaround: Make sure monitor vdev is not running
4099 * when associating to prevent some firmware revisions
4100 * (e.g. 10.1 and 10.2) from crashing.
4101 */
4102 if (ar->monitor_started)
4103 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004104 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004105 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004106 } else {
4107 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004108 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004109 }
4110
Michal Kazior7d9d5582014-10-21 10:40:15 +03004111 if (changed & BSS_CHANGED_TXPOWER) {
4112 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4113 arvif->vdev_id, info->txpower);
4114
4115 arvif->txpower = info->txpower;
4116 ret = ath10k_mac_txpower_recalc(ar);
4117 if (ret)
4118 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4119 }
4120
Michal Kaziorbf14e652014-12-12 12:41:38 +01004121 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004122 arvif->ps = vif->bss_conf.ps;
4123
4124 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004125 if (ret)
4126 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4127 arvif->vdev_id, ret);
4128 }
4129
Kalle Valo5e3dd152013-06-12 20:52:10 +03004130 mutex_unlock(&ar->conf_mutex);
4131}
4132
4133static int ath10k_hw_scan(struct ieee80211_hw *hw,
4134 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004135 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004136{
4137 struct ath10k *ar = hw->priv;
4138 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004139 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004140 struct wmi_start_scan_arg arg;
4141 int ret = 0;
4142 int i;
4143
4144 mutex_lock(&ar->conf_mutex);
4145
4146 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004147 switch (ar->scan.state) {
4148 case ATH10K_SCAN_IDLE:
4149 reinit_completion(&ar->scan.started);
4150 reinit_completion(&ar->scan.completed);
4151 ar->scan.state = ATH10K_SCAN_STARTING;
4152 ar->scan.is_roc = false;
4153 ar->scan.vdev_id = arvif->vdev_id;
4154 ret = 0;
4155 break;
4156 case ATH10K_SCAN_STARTING:
4157 case ATH10K_SCAN_RUNNING:
4158 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004159 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004160 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004162 spin_unlock_bh(&ar->data_lock);
4163
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004164 if (ret)
4165 goto exit;
4166
Kalle Valo5e3dd152013-06-12 20:52:10 +03004167 memset(&arg, 0, sizeof(arg));
4168 ath10k_wmi_start_scan_init(ar, &arg);
4169 arg.vdev_id = arvif->vdev_id;
4170 arg.scan_id = ATH10K_SCAN_ID;
4171
4172 if (!req->no_cck)
4173 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4174
4175 if (req->ie_len) {
4176 arg.ie_len = req->ie_len;
4177 memcpy(arg.ie, req->ie, arg.ie_len);
4178 }
4179
4180 if (req->n_ssids) {
4181 arg.n_ssids = req->n_ssids;
4182 for (i = 0; i < arg.n_ssids; i++) {
4183 arg.ssids[i].len = req->ssids[i].ssid_len;
4184 arg.ssids[i].ssid = req->ssids[i].ssid;
4185 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004186 } else {
4187 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004188 }
4189
4190 if (req->n_channels) {
4191 arg.n_channels = req->n_channels;
4192 for (i = 0; i < arg.n_channels; i++)
4193 arg.channels[i] = req->channels[i]->center_freq;
4194 }
4195
4196 ret = ath10k_start_scan(ar, &arg);
4197 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004198 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004199 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004200 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004201 spin_unlock_bh(&ar->data_lock);
4202 }
4203
4204exit:
4205 mutex_unlock(&ar->conf_mutex);
4206 return ret;
4207}
4208
4209static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4210 struct ieee80211_vif *vif)
4211{
4212 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004213
4214 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004215 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004216 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004217
4218 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004219}
4220
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004221static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4222 struct ath10k_vif *arvif,
4223 enum set_key_cmd cmd,
4224 struct ieee80211_key_conf *key)
4225{
4226 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4227 int ret;
4228
4229 /* 10.1 firmware branch requires default key index to be set to group
4230 * key index after installing it. Otherwise FW/HW Txes corrupted
4231 * frames with multi-vif APs. This is not required for main firmware
4232 * branch (e.g. 636).
4233 *
4234 * FIXME: This has been tested only in AP. It remains unknown if this
4235 * is required for multi-vif STA interfaces on 10.1 */
4236
4237 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4238 return;
4239
4240 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4241 return;
4242
4243 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4244 return;
4245
4246 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4247 return;
4248
4249 if (cmd != SET_KEY)
4250 return;
4251
4252 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4253 key->keyidx);
4254 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004255 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004256 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004257}
4258
Kalle Valo5e3dd152013-06-12 20:52:10 +03004259static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4260 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4261 struct ieee80211_key_conf *key)
4262{
4263 struct ath10k *ar = hw->priv;
4264 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4265 struct ath10k_peer *peer;
4266 const u8 *peer_addr;
4267 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4268 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4269 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004270 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004271
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004272 /* this one needs to be done in software */
4273 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4274 return 1;
4275
Kalle Valo5e3dd152013-06-12 20:52:10 +03004276 if (key->keyidx > WMI_MAX_KEY_INDEX)
4277 return -ENOSPC;
4278
4279 mutex_lock(&ar->conf_mutex);
4280
4281 if (sta)
4282 peer_addr = sta->addr;
4283 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4284 peer_addr = vif->bss_conf.bssid;
4285 else
4286 peer_addr = vif->addr;
4287
4288 key->hw_key_idx = key->keyidx;
4289
4290 /* the peer should not disappear in mid-way (unless FW goes awry) since
4291 * we already hold conf_mutex. we just make sure its there now. */
4292 spin_lock_bh(&ar->data_lock);
4293 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4294 spin_unlock_bh(&ar->data_lock);
4295
4296 if (!peer) {
4297 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004298 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299 peer_addr);
4300 ret = -EOPNOTSUPP;
4301 goto exit;
4302 } else {
4303 /* if the peer doesn't exist there is no key to disable
4304 * anymore */
4305 goto exit;
4306 }
4307 }
4308
Michal Kazior7cc45732015-03-09 14:24:17 +01004309 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4310 flags |= WMI_KEY_PAIRWISE;
4311 else
4312 flags |= WMI_KEY_GROUP;
4313
Kalle Valo5e3dd152013-06-12 20:52:10 +03004314 if (is_wep) {
4315 if (cmd == SET_KEY)
4316 arvif->wep_keys[key->keyidx] = key;
4317 else
4318 arvif->wep_keys[key->keyidx] = NULL;
4319
4320 if (cmd == DISABLE_KEY)
4321 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004322
Michal Kaziorad325cb2015-02-18 14:02:27 +01004323 /* When WEP keys are uploaded it's possible that there are
4324 * stations associated already (e.g. when merging) without any
4325 * keys. Static WEP needs an explicit per-peer key upload.
4326 */
4327 if (vif->type == NL80211_IFTYPE_ADHOC &&
4328 cmd == SET_KEY)
4329 ath10k_mac_vif_update_wep_key(arvif, key);
4330
Michal Kazior370e5672015-02-18 14:02:26 +01004331 /* 802.1x never sets the def_wep_key_idx so each set_key()
4332 * call changes default tx key.
4333 *
4334 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4335 * after first set_key().
4336 */
4337 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4338 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004339
Michal Kazior7cc45732015-03-09 14:24:17 +01004340 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4341 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4342 * mode and associated stations in AP/IBSS.
4343 *
4344 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4345 * work fine when mapped directly from mac80211.
4346 *
4347 * Note: When installing first static WEP groupwise key (which
4348 * should be pairwise) def_wep_key_idx isn't known yet (it's
4349 * equal to -1). Since .set_default_unicast_key is called only
4350 * for static WEP it's used to re-upload the key as pairwise.
4351 */
4352 if (arvif->def_wep_key_idx >= 0 &&
4353 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4354 flags &= ~WMI_KEY_GROUP;
4355 flags |= WMI_KEY_PAIRWISE;
4356 }
Michal Kazior370e5672015-02-18 14:02:26 +01004357 }
4358
4359 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004360 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004361 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004362 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004363 goto exit;
4364 }
4365
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004366 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4367
Kalle Valo5e3dd152013-06-12 20:52:10 +03004368 spin_lock_bh(&ar->data_lock);
4369 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4370 if (peer && cmd == SET_KEY)
4371 peer->keys[key->keyidx] = key;
4372 else if (peer && cmd == DISABLE_KEY)
4373 peer->keys[key->keyidx] = NULL;
4374 else if (peer == NULL)
4375 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004376 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004377 spin_unlock_bh(&ar->data_lock);
4378
4379exit:
4380 mutex_unlock(&ar->conf_mutex);
4381 return ret;
4382}
4383
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004384static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4385 struct ieee80211_vif *vif,
4386 int keyidx)
4387{
4388 struct ath10k *ar = hw->priv;
4389 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4390 int ret;
4391
4392 mutex_lock(&arvif->ar->conf_mutex);
4393
4394 if (arvif->ar->state != ATH10K_STATE_ON)
4395 goto unlock;
4396
4397 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4398 arvif->vdev_id, keyidx);
4399
4400 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4401 arvif->vdev_id,
4402 arvif->ar->wmi.vdev_param->def_keyid,
4403 keyidx);
4404
4405 if (ret) {
4406 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4407 arvif->vdev_id,
4408 ret);
4409 goto unlock;
4410 }
4411
4412 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004413
4414 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4415 if (ret) {
4416 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4417 arvif->vdev_id, ret);
4418 goto unlock;
4419 }
4420
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004421unlock:
4422 mutex_unlock(&arvif->ar->conf_mutex);
4423}
4424
Michal Kazior9797feb2014-02-14 14:49:48 +01004425static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4426{
4427 struct ath10k *ar;
4428 struct ath10k_vif *arvif;
4429 struct ath10k_sta *arsta;
4430 struct ieee80211_sta *sta;
4431 u32 changed, bw, nss, smps;
4432 int err;
4433
4434 arsta = container_of(wk, struct ath10k_sta, update_wk);
4435 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4436 arvif = arsta->arvif;
4437 ar = arvif->ar;
4438
4439 spin_lock_bh(&ar->data_lock);
4440
4441 changed = arsta->changed;
4442 arsta->changed = 0;
4443
4444 bw = arsta->bw;
4445 nss = arsta->nss;
4446 smps = arsta->smps;
4447
4448 spin_unlock_bh(&ar->data_lock);
4449
4450 mutex_lock(&ar->conf_mutex);
4451
4452 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004453 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004454 sta->addr, bw);
4455
4456 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4457 WMI_PEER_CHAN_WIDTH, bw);
4458 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004459 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004460 sta->addr, bw, err);
4461 }
4462
4463 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004465 sta->addr, nss);
4466
4467 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4468 WMI_PEER_NSS, nss);
4469 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004470 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004471 sta->addr, nss, err);
4472 }
4473
4474 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004475 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004476 sta->addr, smps);
4477
4478 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4479 WMI_PEER_SMPS_STATE, smps);
4480 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004481 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004482 sta->addr, smps, err);
4483 }
4484
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004485 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4486 changed & IEEE80211_RC_NSS_CHANGED) {
4487 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004488 sta->addr);
4489
Michal Kazior590922a2014-10-21 10:10:29 +03004490 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004491 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004492 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004493 sta->addr);
4494 }
4495
Michal Kazior9797feb2014-02-14 14:49:48 +01004496 mutex_unlock(&ar->conf_mutex);
4497}
4498
Marek Puzyniak7c354242015-03-30 09:51:52 +03004499static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4500 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004501{
4502 struct ath10k *ar = arvif->ar;
4503
4504 lockdep_assert_held(&ar->conf_mutex);
4505
Marek Puzyniak7c354242015-03-30 09:51:52 +03004506 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004507 return 0;
4508
4509 if (ar->num_stations >= ar->max_num_stations)
4510 return -ENOBUFS;
4511
4512 ar->num_stations++;
4513
4514 return 0;
4515}
4516
Marek Puzyniak7c354242015-03-30 09:51:52 +03004517static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4518 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004519{
4520 struct ath10k *ar = arvif->ar;
4521
4522 lockdep_assert_held(&ar->conf_mutex);
4523
Marek Puzyniak7c354242015-03-30 09:51:52 +03004524 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004525 return;
4526
4527 ar->num_stations--;
4528}
4529
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004530struct ath10k_mac_tdls_iter_data {
4531 u32 num_tdls_stations;
4532 struct ieee80211_vif *curr_vif;
4533};
4534
4535static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4536 struct ieee80211_sta *sta)
4537{
4538 struct ath10k_mac_tdls_iter_data *iter_data = data;
4539 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4540 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4541
4542 if (sta->tdls && sta_vif == iter_data->curr_vif)
4543 iter_data->num_tdls_stations++;
4544}
4545
4546static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4547 struct ieee80211_vif *vif)
4548{
4549 struct ath10k_mac_tdls_iter_data data = {};
4550
4551 data.curr_vif = vif;
4552
4553 ieee80211_iterate_stations_atomic(hw,
4554 ath10k_mac_tdls_vif_stations_count_iter,
4555 &data);
4556 return data.num_tdls_stations;
4557}
4558
4559static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4560 struct ieee80211_vif *vif)
4561{
4562 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4563 int *num_tdls_vifs = data;
4564
4565 if (vif->type != NL80211_IFTYPE_STATION)
4566 return;
4567
4568 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4569 (*num_tdls_vifs)++;
4570}
4571
4572static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4573{
4574 int num_tdls_vifs = 0;
4575
4576 ieee80211_iterate_active_interfaces_atomic(hw,
4577 IEEE80211_IFACE_ITER_NORMAL,
4578 ath10k_mac_tdls_vifs_count_iter,
4579 &num_tdls_vifs);
4580 return num_tdls_vifs;
4581}
4582
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583static int ath10k_sta_state(struct ieee80211_hw *hw,
4584 struct ieee80211_vif *vif,
4585 struct ieee80211_sta *sta,
4586 enum ieee80211_sta_state old_state,
4587 enum ieee80211_sta_state new_state)
4588{
4589 struct ath10k *ar = hw->priv;
4590 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004591 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592 int ret = 0;
4593
Michal Kazior76f90022014-02-25 09:29:57 +02004594 if (old_state == IEEE80211_STA_NOTEXIST &&
4595 new_state == IEEE80211_STA_NONE) {
4596 memset(arsta, 0, sizeof(*arsta));
4597 arsta->arvif = arvif;
4598 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4599 }
4600
Michal Kazior9797feb2014-02-14 14:49:48 +01004601 /* cancel must be done outside the mutex to avoid deadlock */
4602 if ((old_state == IEEE80211_STA_NONE &&
4603 new_state == IEEE80211_STA_NOTEXIST))
4604 cancel_work_sync(&arsta->update_wk);
4605
Kalle Valo5e3dd152013-06-12 20:52:10 +03004606 mutex_lock(&ar->conf_mutex);
4607
4608 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004609 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004610 /*
4611 * New station addition.
4612 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004613 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4614 u32 num_tdls_stations;
4615 u32 num_tdls_vifs;
4616
Michal Kaziorcfd10612014-11-25 15:16:05 +01004617 ath10k_dbg(ar, ATH10K_DBG_MAC,
4618 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4619 arvif->vdev_id, sta->addr,
4620 ar->num_stations + 1, ar->max_num_stations,
4621 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004622
Marek Puzyniak7c354242015-03-30 09:51:52 +03004623 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004624 if (ret) {
4625 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4626 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004627 goto exit;
4628 }
4629
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004630 if (sta->tdls)
4631 peer_type = WMI_PEER_TYPE_TDLS;
4632
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004633 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004634 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004635 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004636 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 -08004637 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004638 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004639 goto exit;
4640 }
Michal Kazior077efc82014-10-21 10:10:29 +03004641
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004642 if (vif->type == NL80211_IFTYPE_STATION &&
4643 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004644 WARN_ON(arvif->is_started);
4645
4646 ret = ath10k_vdev_start(arvif);
4647 if (ret) {
4648 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4649 arvif->vdev_id, ret);
4650 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4651 sta->addr));
Marek Puzyniak7c354242015-03-30 09:51:52 +03004652 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03004653 goto exit;
4654 }
4655
4656 arvif->is_started = true;
4657 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004658
4659 if (!sta->tdls)
4660 goto exit;
4661
4662 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4663 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4664
4665 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4666 num_tdls_stations == 0) {
4667 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4668 arvif->vdev_id, ar->max_num_tdls_vdevs);
4669 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4670 ath10k_mac_dec_num_stations(arvif, sta);
4671 ret = -ENOBUFS;
4672 goto exit;
4673 }
4674
4675 if (num_tdls_stations == 0) {
4676 /* This is the first tdls peer in current vif */
4677 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4678
4679 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4680 state);
4681 if (ret) {
4682 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4683 arvif->vdev_id, ret);
4684 ath10k_peer_delete(ar, arvif->vdev_id,
4685 sta->addr);
4686 ath10k_mac_dec_num_stations(arvif, sta);
4687 goto exit;
4688 }
4689 }
4690
4691 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4692 WMI_TDLS_PEER_STATE_PEERING);
4693 if (ret) {
4694 ath10k_warn(ar,
4695 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4696 sta->addr, arvif->vdev_id, ret);
4697 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4698 ath10k_mac_dec_num_stations(arvif, sta);
4699
4700 if (num_tdls_stations != 0)
4701 goto exit;
4702 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4703 WMI_TDLS_DISABLE);
4704 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004705 } else if ((old_state == IEEE80211_STA_NONE &&
4706 new_state == IEEE80211_STA_NOTEXIST)) {
4707 /*
4708 * Existing station deletion.
4709 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004710 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004711 "mac vdev %d peer delete %pM (sta gone)\n",
4712 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004713
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004714 if (vif->type == NL80211_IFTYPE_STATION &&
4715 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004716 WARN_ON(!arvif->is_started);
4717
4718 ret = ath10k_vdev_stop(arvif);
4719 if (ret)
4720 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4721 arvif->vdev_id, ret);
4722
4723 arvif->is_started = false;
4724 }
4725
Kalle Valo5e3dd152013-06-12 20:52:10 +03004726 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4727 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004728 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004729 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004730
Marek Puzyniak7c354242015-03-30 09:51:52 +03004731 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004732
4733 if (!sta->tdls)
4734 goto exit;
4735
4736 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
4737 goto exit;
4738
4739 /* This was the last tdls peer in current vif */
4740 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4741 WMI_TDLS_DISABLE);
4742 if (ret) {
4743 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4744 arvif->vdev_id, ret);
4745 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004746 } else if (old_state == IEEE80211_STA_AUTH &&
4747 new_state == IEEE80211_STA_ASSOC &&
4748 (vif->type == NL80211_IFTYPE_AP ||
4749 vif->type == NL80211_IFTYPE_ADHOC)) {
4750 /*
4751 * New association.
4752 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004754 sta->addr);
4755
Michal Kazior590922a2014-10-21 10:10:29 +03004756 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004757 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004758 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004759 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004760 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004761 new_state == IEEE80211_STA_AUTHORIZED &&
4762 sta->tdls) {
4763 /*
4764 * Tdls station authorized.
4765 */
4766 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
4767 sta->addr);
4768
4769 ret = ath10k_station_assoc(ar, vif, sta, false);
4770 if (ret) {
4771 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
4772 sta->addr, arvif->vdev_id, ret);
4773 goto exit;
4774 }
4775
4776 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4777 WMI_TDLS_PEER_STATE_CONNECTED);
4778 if (ret)
4779 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
4780 sta->addr, arvif->vdev_id, ret);
4781 } else if (old_state == IEEE80211_STA_ASSOC &&
4782 new_state == IEEE80211_STA_AUTH &&
4783 (vif->type == NL80211_IFTYPE_AP ||
4784 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004785 /*
4786 * Disassociation.
4787 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004788 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004789 sta->addr);
4790
Michal Kazior590922a2014-10-21 10:10:29 +03004791 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004793 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004794 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004795 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004796exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004797 mutex_unlock(&ar->conf_mutex);
4798 return ret;
4799}
4800
4801static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004802 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004803{
4804 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004805 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4806 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004807 u32 value = 0;
4808 int ret = 0;
4809
Michal Kazior548db542013-07-05 16:15:15 +03004810 lockdep_assert_held(&ar->conf_mutex);
4811
Kalle Valo5e3dd152013-06-12 20:52:10 +03004812 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4813 return 0;
4814
4815 switch (ac) {
4816 case IEEE80211_AC_VO:
4817 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4818 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004819 prio = 7;
4820 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004821 break;
4822 case IEEE80211_AC_VI:
4823 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4824 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004825 prio = 5;
4826 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004827 break;
4828 case IEEE80211_AC_BE:
4829 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4830 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004831 prio = 2;
4832 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004833 break;
4834 case IEEE80211_AC_BK:
4835 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4836 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004837 prio = 0;
4838 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004839 break;
4840 }
4841
4842 if (enable)
4843 arvif->u.sta.uapsd |= value;
4844 else
4845 arvif->u.sta.uapsd &= ~value;
4846
4847 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4848 WMI_STA_PS_PARAM_UAPSD,
4849 arvif->u.sta.uapsd);
4850 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004851 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004852 goto exit;
4853 }
4854
4855 if (arvif->u.sta.uapsd)
4856 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4857 else
4858 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4859
4860 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4861 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4862 value);
4863 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004864 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004865
Michal Kazior9f9b5742014-12-12 12:41:36 +01004866 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4867 if (ret) {
4868 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4869 arvif->vdev_id, ret);
4870 return ret;
4871 }
4872
4873 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4874 if (ret) {
4875 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4876 arvif->vdev_id, ret);
4877 return ret;
4878 }
4879
Michal Kaziorb0e56152015-01-24 12:14:52 +02004880 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4881 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4882 /* Only userspace can make an educated decision when to send
4883 * trigger frame. The following effectively disables u-UAPSD
4884 * autotrigger in firmware (which is enabled by default
4885 * provided the autotrigger service is available).
4886 */
4887
4888 arg.wmm_ac = acc;
4889 arg.user_priority = prio;
4890 arg.service_interval = 0;
4891 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4892 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4893
4894 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4895 arvif->bssid, &arg, 1);
4896 if (ret) {
4897 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4898 ret);
4899 return ret;
4900 }
4901 }
4902
Kalle Valo5e3dd152013-06-12 20:52:10 +03004903exit:
4904 return ret;
4905}
4906
4907static int ath10k_conf_tx(struct ieee80211_hw *hw,
4908 struct ieee80211_vif *vif, u16 ac,
4909 const struct ieee80211_tx_queue_params *params)
4910{
4911 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004912 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004913 struct wmi_wmm_params_arg *p = NULL;
4914 int ret;
4915
4916 mutex_lock(&ar->conf_mutex);
4917
4918 switch (ac) {
4919 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004920 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004921 break;
4922 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004923 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004924 break;
4925 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004926 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004927 break;
4928 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004929 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004930 break;
4931 }
4932
4933 if (WARN_ON(!p)) {
4934 ret = -EINVAL;
4935 goto exit;
4936 }
4937
4938 p->cwmin = params->cw_min;
4939 p->cwmax = params->cw_max;
4940 p->aifs = params->aifs;
4941
4942 /*
4943 * The channel time duration programmed in the HW is in absolute
4944 * microseconds, while mac80211 gives the txop in units of
4945 * 32 microseconds.
4946 */
4947 p->txop = params->txop * 32;
4948
Michal Kazior7fc979a2015-01-28 09:57:28 +02004949 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4950 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4951 &arvif->wmm_params);
4952 if (ret) {
4953 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4954 arvif->vdev_id, ret);
4955 goto exit;
4956 }
4957 } else {
4958 /* This won't work well with multi-interface cases but it's
4959 * better than nothing.
4960 */
4961 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4962 if (ret) {
4963 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4964 goto exit;
4965 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004966 }
4967
4968 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4969 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004970 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004971
4972exit:
4973 mutex_unlock(&ar->conf_mutex);
4974 return ret;
4975}
4976
4977#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4978
4979static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4980 struct ieee80211_vif *vif,
4981 struct ieee80211_channel *chan,
4982 int duration,
4983 enum ieee80211_roc_type type)
4984{
4985 struct ath10k *ar = hw->priv;
4986 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4987 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004988 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004989
4990 mutex_lock(&ar->conf_mutex);
4991
4992 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004993 switch (ar->scan.state) {
4994 case ATH10K_SCAN_IDLE:
4995 reinit_completion(&ar->scan.started);
4996 reinit_completion(&ar->scan.completed);
4997 reinit_completion(&ar->scan.on_channel);
4998 ar->scan.state = ATH10K_SCAN_STARTING;
4999 ar->scan.is_roc = true;
5000 ar->scan.vdev_id = arvif->vdev_id;
5001 ar->scan.roc_freq = chan->center_freq;
5002 ret = 0;
5003 break;
5004 case ATH10K_SCAN_STARTING:
5005 case ATH10K_SCAN_RUNNING:
5006 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005007 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005008 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005009 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005010 spin_unlock_bh(&ar->data_lock);
5011
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005012 if (ret)
5013 goto exit;
5014
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005015 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5016
Kalle Valo5e3dd152013-06-12 20:52:10 +03005017 memset(&arg, 0, sizeof(arg));
5018 ath10k_wmi_start_scan_init(ar, &arg);
5019 arg.vdev_id = arvif->vdev_id;
5020 arg.scan_id = ATH10K_SCAN_ID;
5021 arg.n_channels = 1;
5022 arg.channels[0] = chan->center_freq;
5023 arg.dwell_time_active = duration;
5024 arg.dwell_time_passive = duration;
5025 arg.max_scan_time = 2 * duration;
5026 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5027 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5028
5029 ret = ath10k_start_scan(ar, &arg);
5030 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005031 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005032 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005033 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005034 spin_unlock_bh(&ar->data_lock);
5035 goto exit;
5036 }
5037
5038 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5039 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005040 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005041
5042 ret = ath10k_scan_stop(ar);
5043 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005044 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005045
Kalle Valo5e3dd152013-06-12 20:52:10 +03005046 ret = -ETIMEDOUT;
5047 goto exit;
5048 }
5049
5050 ret = 0;
5051exit:
5052 mutex_unlock(&ar->conf_mutex);
5053 return ret;
5054}
5055
5056static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5057{
5058 struct ath10k *ar = hw->priv;
5059
5060 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005061 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005062 mutex_unlock(&ar->conf_mutex);
5063
Michal Kazior4eb2e162014-10-28 10:23:09 +01005064 cancel_delayed_work_sync(&ar->scan.timeout);
5065
Kalle Valo5e3dd152013-06-12 20:52:10 +03005066 return 0;
5067}
5068
5069/*
5070 * Both RTS and Fragmentation threshold are interface-specific
5071 * in ath10k, but device-specific in mac80211.
5072 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005073
5074static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5075{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005076 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005077 struct ath10k_vif *arvif;
5078 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005079
Michal Kaziorad088bf2013-10-16 15:44:46 +03005080 mutex_lock(&ar->conf_mutex);
5081 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005082 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005083 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005084
Michal Kaziorad088bf2013-10-16 15:44:46 +03005085 ret = ath10k_mac_set_rts(arvif, value);
5086 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005087 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005088 arvif->vdev_id, ret);
5089 break;
5090 }
5091 }
5092 mutex_unlock(&ar->conf_mutex);
5093
5094 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005095}
5096
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005097static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5098 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005099{
5100 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005101 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005102 int ret;
5103
5104 /* mac80211 doesn't care if we really xmit queued frames or not
5105 * we'll collect those frames either way if we stop/delete vdevs */
5106 if (drop)
5107 return;
5108
Michal Kazior548db542013-07-05 16:15:15 +03005109 mutex_lock(&ar->conf_mutex);
5110
Michal Kazioraffd3212013-07-16 09:54:35 +02005111 if (ar->state == ATH10K_STATE_WEDGED)
5112 goto skip;
5113
Michal Kazioredb82362013-07-05 16:15:14 +03005114 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005115 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005116
Michal Kazioredb82362013-07-05 16:15:14 +03005117 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005118 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005119 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005120
Michal Kazior7962b0d2014-10-28 10:34:38 +01005121 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5122 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5123 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005124
5125 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005126 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005127
5128 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005129 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005130 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005131
Michal Kazioraffd3212013-07-16 09:54:35 +02005132skip:
Michal Kazior548db542013-07-05 16:15:15 +03005133 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005134}
5135
5136/* TODO: Implement this function properly
5137 * For now it is needed to reply to Probe Requests in IBSS mode.
5138 * Propably we need this information from FW.
5139 */
5140static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5141{
5142 return 1;
5143}
5144
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005145static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5146 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005147{
5148 struct ath10k *ar = hw->priv;
5149
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005150 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5151 return;
5152
Michal Kazioraffd3212013-07-16 09:54:35 +02005153 mutex_lock(&ar->conf_mutex);
5154
5155 /* If device failed to restart it will be in a different state, e.g.
5156 * ATH10K_STATE_WEDGED */
5157 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005158 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005159 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005160 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005161 }
5162
5163 mutex_unlock(&ar->conf_mutex);
5164}
5165
Michal Kazior2e1dea42013-07-31 10:32:40 +02005166static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5167 struct survey_info *survey)
5168{
5169 struct ath10k *ar = hw->priv;
5170 struct ieee80211_supported_band *sband;
5171 struct survey_info *ar_survey = &ar->survey[idx];
5172 int ret = 0;
5173
5174 mutex_lock(&ar->conf_mutex);
5175
5176 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5177 if (sband && idx >= sband->n_channels) {
5178 idx -= sband->n_channels;
5179 sband = NULL;
5180 }
5181
5182 if (!sband)
5183 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5184
5185 if (!sband || idx >= sband->n_channels) {
5186 ret = -ENOENT;
5187 goto exit;
5188 }
5189
5190 spin_lock_bh(&ar->data_lock);
5191 memcpy(survey, ar_survey, sizeof(*survey));
5192 spin_unlock_bh(&ar->data_lock);
5193
5194 survey->channel = &sband->channels[idx];
5195
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005196 if (ar->rx_channel == survey->channel)
5197 survey->filled |= SURVEY_INFO_IN_USE;
5198
Michal Kazior2e1dea42013-07-31 10:32:40 +02005199exit:
5200 mutex_unlock(&ar->conf_mutex);
5201 return ret;
5202}
5203
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005204/* Helper table for legacy fixed_rate/bitrate_mask */
5205static const u8 cck_ofdm_rate[] = {
5206 /* CCK */
5207 3, /* 1Mbps */
5208 2, /* 2Mbps */
5209 1, /* 5.5Mbps */
5210 0, /* 11Mbps */
5211 /* OFDM */
5212 3, /* 6Mbps */
5213 7, /* 9Mbps */
5214 2, /* 12Mbps */
5215 6, /* 18Mbps */
5216 1, /* 24Mbps */
5217 5, /* 36Mbps */
5218 0, /* 48Mbps */
5219 4, /* 54Mbps */
5220};
5221
5222/* Check if only one bit set */
5223static int ath10k_check_single_mask(u32 mask)
5224{
5225 int bit;
5226
5227 bit = ffs(mask);
5228 if (!bit)
5229 return 0;
5230
5231 mask &= ~BIT(bit - 1);
5232 if (mask)
5233 return 2;
5234
5235 return 1;
5236}
5237
5238static bool
5239ath10k_default_bitrate_mask(struct ath10k *ar,
5240 enum ieee80211_band band,
5241 const struct cfg80211_bitrate_mask *mask)
5242{
5243 u32 legacy = 0x00ff;
5244 u8 ht = 0xff, i;
5245 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005246 u16 nrf = ar->num_rf_chains;
5247
5248 if (ar->cfg_tx_chainmask)
5249 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005250
5251 switch (band) {
5252 case IEEE80211_BAND_2GHZ:
5253 legacy = 0x00fff;
5254 vht = 0;
5255 break;
5256 case IEEE80211_BAND_5GHZ:
5257 break;
5258 default:
5259 return false;
5260 }
5261
5262 if (mask->control[band].legacy != legacy)
5263 return false;
5264
Ben Greearb116ea12014-11-24 16:22:10 +02005265 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005266 if (mask->control[band].ht_mcs[i] != ht)
5267 return false;
5268
Ben Greearb116ea12014-11-24 16:22:10 +02005269 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005270 if (mask->control[band].vht_mcs[i] != vht)
5271 return false;
5272
5273 return true;
5274}
5275
5276static bool
5277ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5278 enum ieee80211_band band,
5279 u8 *fixed_nss)
5280{
5281 int ht_nss = 0, vht_nss = 0, i;
5282
5283 /* check legacy */
5284 if (ath10k_check_single_mask(mask->control[band].legacy))
5285 return false;
5286
5287 /* check HT */
5288 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5289 if (mask->control[band].ht_mcs[i] == 0xff)
5290 continue;
5291 else if (mask->control[band].ht_mcs[i] == 0x00)
5292 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005293
5294 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005295 }
5296
5297 ht_nss = i;
5298
5299 /* check VHT */
5300 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5301 if (mask->control[band].vht_mcs[i] == 0x03ff)
5302 continue;
5303 else if (mask->control[band].vht_mcs[i] == 0x0000)
5304 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005305
5306 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005307 }
5308
5309 vht_nss = i;
5310
5311 if (ht_nss > 0 && vht_nss > 0)
5312 return false;
5313
5314 if (ht_nss)
5315 *fixed_nss = ht_nss;
5316 else if (vht_nss)
5317 *fixed_nss = vht_nss;
5318 else
5319 return false;
5320
5321 return true;
5322}
5323
5324static bool
5325ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5326 enum ieee80211_band band,
5327 enum wmi_rate_preamble *preamble)
5328{
5329 int legacy = 0, ht = 0, vht = 0, i;
5330
5331 *preamble = WMI_RATE_PREAMBLE_OFDM;
5332
5333 /* check legacy */
5334 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5335 if (legacy > 1)
5336 return false;
5337
5338 /* check HT */
5339 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5340 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5341 if (ht > 1)
5342 return false;
5343
5344 /* check VHT */
5345 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5346 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5347 if (vht > 1)
5348 return false;
5349
5350 /* Currently we support only one fixed_rate */
5351 if ((legacy + ht + vht) != 1)
5352 return false;
5353
5354 if (ht)
5355 *preamble = WMI_RATE_PREAMBLE_HT;
5356 else if (vht)
5357 *preamble = WMI_RATE_PREAMBLE_VHT;
5358
5359 return true;
5360}
5361
5362static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005363ath10k_bitrate_mask_rate(struct ath10k *ar,
5364 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005365 enum ieee80211_band band,
5366 u8 *fixed_rate,
5367 u8 *fixed_nss)
5368{
5369 u8 rate = 0, pream = 0, nss = 0, i;
5370 enum wmi_rate_preamble preamble;
5371
5372 /* Check if single rate correct */
5373 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5374 return false;
5375
5376 pream = preamble;
5377
5378 switch (preamble) {
5379 case WMI_RATE_PREAMBLE_CCK:
5380 case WMI_RATE_PREAMBLE_OFDM:
5381 i = ffs(mask->control[band].legacy) - 1;
5382
5383 if (band == IEEE80211_BAND_2GHZ && i < 4)
5384 pream = WMI_RATE_PREAMBLE_CCK;
5385
5386 if (band == IEEE80211_BAND_5GHZ)
5387 i += 4;
5388
5389 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5390 return false;
5391
5392 rate = cck_ofdm_rate[i];
5393 break;
5394 case WMI_RATE_PREAMBLE_HT:
5395 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5396 if (mask->control[band].ht_mcs[i])
5397 break;
5398
5399 if (i == IEEE80211_HT_MCS_MASK_LEN)
5400 return false;
5401
5402 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5403 nss = i;
5404 break;
5405 case WMI_RATE_PREAMBLE_VHT:
5406 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5407 if (mask->control[band].vht_mcs[i])
5408 break;
5409
5410 if (i == NL80211_VHT_NSS_MAX)
5411 return false;
5412
5413 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5414 nss = i;
5415 break;
5416 }
5417
5418 *fixed_nss = nss + 1;
5419 nss <<= 4;
5420 pream <<= 6;
5421
Michal Kazior7aa7a722014-08-25 12:09:38 +02005422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005423 pream, nss, rate);
5424
5425 *fixed_rate = pream | nss | rate;
5426
5427 return true;
5428}
5429
Michal Kazior7aa7a722014-08-25 12:09:38 +02005430static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5431 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005432 enum ieee80211_band band,
5433 u8 *fixed_rate,
5434 u8 *fixed_nss)
5435{
5436 /* First check full NSS mask, if we can simply limit NSS */
5437 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5438 return true;
5439
5440 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005441 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005442}
5443
5444static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5445 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005446 u8 fixed_nss,
5447 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005448{
5449 struct ath10k *ar = arvif->ar;
5450 u32 vdev_param;
5451 int ret = 0;
5452
5453 mutex_lock(&ar->conf_mutex);
5454
5455 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005456 arvif->fixed_nss == fixed_nss &&
5457 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005458 goto exit;
5459
5460 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005461 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005462
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005463 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005465
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005466 vdev_param = ar->wmi.vdev_param->fixed_rate;
5467 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5468 vdev_param, fixed_rate);
5469 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005470 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005471 fixed_rate, ret);
5472 ret = -EINVAL;
5473 goto exit;
5474 }
5475
5476 arvif->fixed_rate = fixed_rate;
5477
5478 vdev_param = ar->wmi.vdev_param->nss;
5479 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5480 vdev_param, fixed_nss);
5481
5482 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005483 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005484 fixed_nss, ret);
5485 ret = -EINVAL;
5486 goto exit;
5487 }
5488
5489 arvif->fixed_nss = fixed_nss;
5490
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005491 vdev_param = ar->wmi.vdev_param->sgi;
5492 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5493 force_sgi);
5494
5495 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005496 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005497 force_sgi, ret);
5498 ret = -EINVAL;
5499 goto exit;
5500 }
5501
5502 arvif->force_sgi = force_sgi;
5503
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005504exit:
5505 mutex_unlock(&ar->conf_mutex);
5506 return ret;
5507}
5508
5509static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5510 struct ieee80211_vif *vif,
5511 const struct cfg80211_bitrate_mask *mask)
5512{
5513 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5514 struct ath10k *ar = arvif->ar;
5515 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5516 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5517 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005518 u8 force_sgi;
5519
Ben Greearb116ea12014-11-24 16:22:10 +02005520 if (ar->cfg_tx_chainmask)
5521 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5522
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005523 force_sgi = mask->control[band].gi;
5524 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5525 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005526
5527 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005528 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005529 &fixed_rate,
5530 &fixed_nss))
5531 return -EINVAL;
5532 }
5533
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005534 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005535 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005536 return -EINVAL;
5537 }
5538
5539 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5540 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005541}
5542
Michal Kazior9797feb2014-02-14 14:49:48 +01005543static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5544 struct ieee80211_vif *vif,
5545 struct ieee80211_sta *sta,
5546 u32 changed)
5547{
5548 struct ath10k *ar = hw->priv;
5549 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5550 u32 bw, smps;
5551
5552 spin_lock_bh(&ar->data_lock);
5553
Michal Kazior7aa7a722014-08-25 12:09:38 +02005554 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005555 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5556 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5557 sta->smps_mode);
5558
5559 if (changed & IEEE80211_RC_BW_CHANGED) {
5560 bw = WMI_PEER_CHWIDTH_20MHZ;
5561
5562 switch (sta->bandwidth) {
5563 case IEEE80211_STA_RX_BW_20:
5564 bw = WMI_PEER_CHWIDTH_20MHZ;
5565 break;
5566 case IEEE80211_STA_RX_BW_40:
5567 bw = WMI_PEER_CHWIDTH_40MHZ;
5568 break;
5569 case IEEE80211_STA_RX_BW_80:
5570 bw = WMI_PEER_CHWIDTH_80MHZ;
5571 break;
5572 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005573 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005574 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005575 bw = WMI_PEER_CHWIDTH_20MHZ;
5576 break;
5577 }
5578
5579 arsta->bw = bw;
5580 }
5581
5582 if (changed & IEEE80211_RC_NSS_CHANGED)
5583 arsta->nss = sta->rx_nss;
5584
5585 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5586 smps = WMI_PEER_SMPS_PS_NONE;
5587
5588 switch (sta->smps_mode) {
5589 case IEEE80211_SMPS_AUTOMATIC:
5590 case IEEE80211_SMPS_OFF:
5591 smps = WMI_PEER_SMPS_PS_NONE;
5592 break;
5593 case IEEE80211_SMPS_STATIC:
5594 smps = WMI_PEER_SMPS_STATIC;
5595 break;
5596 case IEEE80211_SMPS_DYNAMIC:
5597 smps = WMI_PEER_SMPS_DYNAMIC;
5598 break;
5599 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005600 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005601 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005602 smps = WMI_PEER_SMPS_PS_NONE;
5603 break;
5604 }
5605
5606 arsta->smps = smps;
5607 }
5608
Michal Kazior9797feb2014-02-14 14:49:48 +01005609 arsta->changed |= changed;
5610
5611 spin_unlock_bh(&ar->data_lock);
5612
5613 ieee80211_queue_work(hw, &arsta->update_wk);
5614}
5615
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005616static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5617{
5618 /*
5619 * FIXME: Return 0 for time being. Need to figure out whether FW
5620 * has the API to fetch 64-bit local TSF
5621 */
5622
5623 return 0;
5624}
5625
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005626static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5627 struct ieee80211_vif *vif,
5628 enum ieee80211_ampdu_mlme_action action,
5629 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5630 u8 buf_size)
5631{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005632 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005633 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5634
Michal Kazior7aa7a722014-08-25 12:09:38 +02005635 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 +02005636 arvif->vdev_id, sta->addr, tid, action);
5637
5638 switch (action) {
5639 case IEEE80211_AMPDU_RX_START:
5640 case IEEE80211_AMPDU_RX_STOP:
5641 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5642 * creation/removal. Do we need to verify this?
5643 */
5644 return 0;
5645 case IEEE80211_AMPDU_TX_START:
5646 case IEEE80211_AMPDU_TX_STOP_CONT:
5647 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5648 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5649 case IEEE80211_AMPDU_TX_OPERATIONAL:
5650 /* Firmware offloads Tx aggregation entirely so deny mac80211
5651 * Tx aggregation requests.
5652 */
5653 return -EOPNOTSUPP;
5654 }
5655
5656 return -EINVAL;
5657}
5658
Kalle Valo5e3dd152013-06-12 20:52:10 +03005659static const struct ieee80211_ops ath10k_ops = {
5660 .tx = ath10k_tx,
5661 .start = ath10k_start,
5662 .stop = ath10k_stop,
5663 .config = ath10k_config,
5664 .add_interface = ath10k_add_interface,
5665 .remove_interface = ath10k_remove_interface,
5666 .configure_filter = ath10k_configure_filter,
5667 .bss_info_changed = ath10k_bss_info_changed,
5668 .hw_scan = ath10k_hw_scan,
5669 .cancel_hw_scan = ath10k_cancel_hw_scan,
5670 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005671 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005672 .sta_state = ath10k_sta_state,
5673 .conf_tx = ath10k_conf_tx,
5674 .remain_on_channel = ath10k_remain_on_channel,
5675 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5676 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005677 .flush = ath10k_flush,
5678 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005679 .set_antenna = ath10k_set_antenna,
5680 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005681 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005682 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005683 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005684 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005685 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005686 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005687 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5688 .get_et_stats = ath10k_debug_get_et_stats,
5689 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005690
5691 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5692
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005693#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005694 .suspend = ath10k_wow_op_suspend,
5695 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005696#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005697#ifdef CONFIG_MAC80211_DEBUGFS
5698 .sta_add_debugfs = ath10k_sta_add_debugfs,
5699#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005700};
5701
Kalle Valo5e3dd152013-06-12 20:52:10 +03005702#define CHAN2G(_channel, _freq, _flags) { \
5703 .band = IEEE80211_BAND_2GHZ, \
5704 .hw_value = (_channel), \
5705 .center_freq = (_freq), \
5706 .flags = (_flags), \
5707 .max_antenna_gain = 0, \
5708 .max_power = 30, \
5709}
5710
5711#define CHAN5G(_channel, _freq, _flags) { \
5712 .band = IEEE80211_BAND_5GHZ, \
5713 .hw_value = (_channel), \
5714 .center_freq = (_freq), \
5715 .flags = (_flags), \
5716 .max_antenna_gain = 0, \
5717 .max_power = 30, \
5718}
5719
5720static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5721 CHAN2G(1, 2412, 0),
5722 CHAN2G(2, 2417, 0),
5723 CHAN2G(3, 2422, 0),
5724 CHAN2G(4, 2427, 0),
5725 CHAN2G(5, 2432, 0),
5726 CHAN2G(6, 2437, 0),
5727 CHAN2G(7, 2442, 0),
5728 CHAN2G(8, 2447, 0),
5729 CHAN2G(9, 2452, 0),
5730 CHAN2G(10, 2457, 0),
5731 CHAN2G(11, 2462, 0),
5732 CHAN2G(12, 2467, 0),
5733 CHAN2G(13, 2472, 0),
5734 CHAN2G(14, 2484, 0),
5735};
5736
5737static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005738 CHAN5G(36, 5180, 0),
5739 CHAN5G(40, 5200, 0),
5740 CHAN5G(44, 5220, 0),
5741 CHAN5G(48, 5240, 0),
5742 CHAN5G(52, 5260, 0),
5743 CHAN5G(56, 5280, 0),
5744 CHAN5G(60, 5300, 0),
5745 CHAN5G(64, 5320, 0),
5746 CHAN5G(100, 5500, 0),
5747 CHAN5G(104, 5520, 0),
5748 CHAN5G(108, 5540, 0),
5749 CHAN5G(112, 5560, 0),
5750 CHAN5G(116, 5580, 0),
5751 CHAN5G(120, 5600, 0),
5752 CHAN5G(124, 5620, 0),
5753 CHAN5G(128, 5640, 0),
5754 CHAN5G(132, 5660, 0),
5755 CHAN5G(136, 5680, 0),
5756 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005757 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005758 CHAN5G(149, 5745, 0),
5759 CHAN5G(153, 5765, 0),
5760 CHAN5G(157, 5785, 0),
5761 CHAN5G(161, 5805, 0),
5762 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005763};
5764
Michal Kaziore7b54192014-08-07 11:03:27 +02005765struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005766{
5767 struct ieee80211_hw *hw;
5768 struct ath10k *ar;
5769
Michal Kaziore7b54192014-08-07 11:03:27 +02005770 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005771 if (!hw)
5772 return NULL;
5773
5774 ar = hw->priv;
5775 ar->hw = hw;
5776
5777 return ar;
5778}
5779
5780void ath10k_mac_destroy(struct ath10k *ar)
5781{
5782 ieee80211_free_hw(ar->hw);
5783}
5784
5785static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5786 {
5787 .max = 8,
5788 .types = BIT(NL80211_IFTYPE_STATION)
5789 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005790 },
5791 {
5792 .max = 3,
5793 .types = BIT(NL80211_IFTYPE_P2P_GO)
5794 },
5795 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005796 .max = 1,
5797 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5798 },
5799 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005800 .max = 7,
5801 .types = BIT(NL80211_IFTYPE_AP)
5802 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005803};
5804
Bartosz Markowskif2595092013-12-10 16:20:39 +01005805static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005806 {
5807 .max = 8,
5808 .types = BIT(NL80211_IFTYPE_AP)
5809 },
5810};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005811
5812static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5813 {
5814 .limits = ath10k_if_limits,
5815 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5816 .max_interfaces = 8,
5817 .num_different_channels = 1,
5818 .beacon_int_infra_match = true,
5819 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005820};
5821
5822static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005823 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005824 .limits = ath10k_10x_if_limits,
5825 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005826 .max_interfaces = 8,
5827 .num_different_channels = 1,
5828 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005829#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005830 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5831 BIT(NL80211_CHAN_WIDTH_20) |
5832 BIT(NL80211_CHAN_WIDTH_40) |
5833 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005834#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005835 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005836};
5837
5838static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5839{
5840 struct ieee80211_sta_vht_cap vht_cap = {0};
5841 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005842 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005843 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005844
5845 vht_cap.vht_supported = 1;
5846 vht_cap.cap = ar->vht_cap_info;
5847
Michal Kaziorbc657a362015-02-26 11:11:22 +01005848 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5849 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5850 val = ar->num_rf_chains - 1;
5851 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5852 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5853
5854 vht_cap.cap |= val;
5855 }
5856
5857 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5858 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5859 val = ar->num_rf_chains - 1;
5860 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5861 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5862
5863 vht_cap.cap |= val;
5864 }
5865
Michal Kazior8865bee42013-07-24 12:36:46 +02005866 mcs_map = 0;
5867 for (i = 0; i < 8; i++) {
5868 if (i < ar->num_rf_chains)
5869 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5870 else
5871 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5872 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005873
5874 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5875 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5876
5877 return vht_cap;
5878}
5879
5880static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5881{
5882 int i;
5883 struct ieee80211_sta_ht_cap ht_cap = {0};
5884
5885 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5886 return ht_cap;
5887
5888 ht_cap.ht_supported = 1;
5889 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5890 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5891 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5892 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5893 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5894
5895 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5896 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5897
5898 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5899 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5900
5901 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5902 u32 smps;
5903
5904 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5905 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5906
5907 ht_cap.cap |= smps;
5908 }
5909
5910 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5911 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5912
5913 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5914 u32 stbc;
5915
5916 stbc = ar->ht_cap_info;
5917 stbc &= WMI_HT_CAP_RX_STBC;
5918 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5919 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5920 stbc &= IEEE80211_HT_CAP_RX_STBC;
5921
5922 ht_cap.cap |= stbc;
5923 }
5924
5925 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5926 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5927
5928 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5929 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5930
5931 /* max AMSDU is implicitly taken from vht_cap_info */
5932 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5933 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5934
Michal Kazior8865bee42013-07-24 12:36:46 +02005935 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005936 ht_cap.mcs.rx_mask[i] = 0xFF;
5937
5938 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5939
5940 return ht_cap;
5941}
5942
Kalle Valo5e3dd152013-06-12 20:52:10 +03005943static void ath10k_get_arvif_iter(void *data, u8 *mac,
5944 struct ieee80211_vif *vif)
5945{
5946 struct ath10k_vif_iter *arvif_iter = data;
5947 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5948
5949 if (arvif->vdev_id == arvif_iter->vdev_id)
5950 arvif_iter->arvif = arvif;
5951}
5952
5953struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5954{
5955 struct ath10k_vif_iter arvif_iter;
5956 u32 flags;
5957
5958 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5959 arvif_iter.vdev_id = vdev_id;
5960
5961 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5962 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5963 flags,
5964 ath10k_get_arvif_iter,
5965 &arvif_iter);
5966 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005967 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005968 return NULL;
5969 }
5970
5971 return arvif_iter.arvif;
5972}
5973
5974int ath10k_mac_register(struct ath10k *ar)
5975{
Johannes Berg3cb10942015-01-22 21:38:45 +01005976 static const u32 cipher_suites[] = {
5977 WLAN_CIPHER_SUITE_WEP40,
5978 WLAN_CIPHER_SUITE_WEP104,
5979 WLAN_CIPHER_SUITE_TKIP,
5980 WLAN_CIPHER_SUITE_CCMP,
5981 WLAN_CIPHER_SUITE_AES_CMAC,
5982 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005983 struct ieee80211_supported_band *band;
5984 struct ieee80211_sta_vht_cap vht_cap;
5985 struct ieee80211_sta_ht_cap ht_cap;
5986 void *channels;
5987 int ret;
5988
5989 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5990
5991 SET_IEEE80211_DEV(ar->hw, ar->dev);
5992
5993 ht_cap = ath10k_get_ht_cap(ar);
5994 vht_cap = ath10k_create_vht_cap(ar);
5995
5996 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5997 channels = kmemdup(ath10k_2ghz_channels,
5998 sizeof(ath10k_2ghz_channels),
5999 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006000 if (!channels) {
6001 ret = -ENOMEM;
6002 goto err_free;
6003 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006004
6005 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6006 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6007 band->channels = channels;
6008 band->n_bitrates = ath10k_g_rates_size;
6009 band->bitrates = ath10k_g_rates;
6010 band->ht_cap = ht_cap;
6011
Yanbo Lid68bb122015-01-23 08:18:20 +08006012 /* Enable the VHT support at 2.4 GHz */
6013 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006014
6015 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6016 }
6017
6018 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6019 channels = kmemdup(ath10k_5ghz_channels,
6020 sizeof(ath10k_5ghz_channels),
6021 GFP_KERNEL);
6022 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006023 ret = -ENOMEM;
6024 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006025 }
6026
6027 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6028 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6029 band->channels = channels;
6030 band->n_bitrates = ath10k_a_rates_size;
6031 band->bitrates = ath10k_a_rates;
6032 band->ht_cap = ht_cap;
6033 band->vht_cap = vht_cap;
6034 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6035 }
6036
6037 ar->hw->wiphy->interface_modes =
6038 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006039 BIT(NL80211_IFTYPE_AP);
6040
Ben Greear46acf7b2014-05-16 17:15:38 +03006041 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6042 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6043
Bartosz Markowskid3541812013-12-10 16:20:40 +01006044 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6045 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006046 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006047 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6048 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006049
6050 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6051 IEEE80211_HW_SUPPORTS_PS |
6052 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006053 IEEE80211_HW_MFP_CAPABLE |
6054 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6055 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006056 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006057 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006058 IEEE80211_HW_SW_CRYPTO_CONTROL |
6059 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006060
Eliad Peller0d8614b2014-09-10 14:07:36 +03006061 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6062
Kalle Valo5e3dd152013-06-12 20:52:10 +03006063 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006064 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006065
6066 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6067 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6068 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6069 }
6070
6071 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6072 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6073
6074 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006075 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006076
Kalle Valo5e3dd152013-06-12 20:52:10 +03006077 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6078
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006079 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6080 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6081
6082 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6083 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6084 * correct Probe Responses. This is more of a hack advert..
6085 */
6086 ar->hw->wiphy->probe_resp_offload |=
6087 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6088 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6089 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6090 }
6091
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006092 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6093 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6094
Kalle Valo5e3dd152013-06-12 20:52:10 +03006095 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006096 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006097 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6098
6099 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006100 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6101
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006102 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6103
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006104 ret = ath10k_wow_init(ar);
6105 if (ret) {
6106 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6107 goto err_free;
6108 }
6109
Kalle Valo5e3dd152013-06-12 20:52:10 +03006110 /*
6111 * on LL hardware queues are managed entirely by the FW
6112 * so we only advertise to mac we can do the queues thing
6113 */
6114 ar->hw->queues = 4;
6115
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006116 switch (ar->wmi.op_version) {
6117 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6118 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006119 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6120 ar->hw->wiphy->n_iface_combinations =
6121 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006122 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006123 break;
6124 case ATH10K_FW_WMI_OP_VERSION_10_1:
6125 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006126 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006127 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6128 ar->hw->wiphy->n_iface_combinations =
6129 ARRAY_SIZE(ath10k_10x_if_comb);
6130 break;
6131 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6132 case ATH10K_FW_WMI_OP_VERSION_MAX:
6133 WARN_ON(1);
6134 ret = -EINVAL;
6135 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006136 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006137
Michal Kazior7c199992013-07-31 10:47:57 +02006138 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6139
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006140 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6141 /* Init ath dfs pattern detector */
6142 ar->ath_common.debug_mask = ATH_DBG_DFS;
6143 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6144 NL80211_DFS_UNSET);
6145
6146 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006147 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006148 }
6149
Kalle Valo5e3dd152013-06-12 20:52:10 +03006150 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6151 ath10k_reg_notifier);
6152 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006153 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006154 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006155 }
6156
Johannes Berg3cb10942015-01-22 21:38:45 +01006157 ar->hw->wiphy->cipher_suites = cipher_suites;
6158 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6159
Kalle Valo5e3dd152013-06-12 20:52:10 +03006160 ret = ieee80211_register_hw(ar->hw);
6161 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006162 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006163 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006164 }
6165
6166 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6167 ret = regulatory_hint(ar->hw->wiphy,
6168 ar->ath_common.regulatory.alpha2);
6169 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006170 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006171 }
6172
6173 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006174
6175err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006176 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006177err_free:
6178 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6179 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6180
Kalle Valo5e3dd152013-06-12 20:52:10 +03006181 return ret;
6182}
6183
6184void ath10k_mac_unregister(struct ath10k *ar)
6185{
6186 ieee80211_unregister_hw(ar->hw);
6187
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006188 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6189 ar->dfs_detector->exit(ar->dfs_detector);
6190
Kalle Valo5e3dd152013-06-12 20:52:10 +03006191 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6192 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6193
6194 SET_IEEE80211_DEV(ar->hw, NULL);
6195}