blob: 663c1381203809296fa50e863e28738f122cbaf0 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020032#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030033
Michal Kaziordcc33092015-03-30 09:51:54 +030034/*********/
35/* Rates */
36/*********/
37
Michal Kaziordcc33092015-03-30 09:51:54 +030038static struct ieee80211_rate ath10k_rates[] = {
39 /* CCK */
Michal Kazior5653b392015-03-30 09:51:54 +030040 { .bitrate = 10 },
41 { .bitrate = 20 },
42 { .bitrate = 55 },
43 { .bitrate = 110 },
44
Michal Kaziordcc33092015-03-30 09:51:54 +030045 /* OFDM */
Michal Kazior5653b392015-03-30 09:51:54 +030046 { .bitrate = 60 },
47 { .bitrate = 90 },
48 { .bitrate = 120 },
49 { .bitrate = 180 },
50 { .bitrate = 240 },
51 { .bitrate = 360 },
52 { .bitrate = 480 },
53 { .bitrate = 540 },
Michal Kaziordcc33092015-03-30 09:51:54 +030054};
55
56#define ath10k_a_rates (ath10k_rates + 4)
57#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
58#define ath10k_g_rates (ath10k_rates + 0)
59#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
60
Michal Kazior486017c2015-03-30 09:51:54 +030061static bool ath10k_mac_bitrate_is_cck(int bitrate)
62{
63 switch (bitrate) {
64 case 10:
65 case 20:
66 case 55:
67 case 110:
68 return true;
69 }
70
71 return false;
72}
73
74static u8 ath10k_mac_bitrate_to_rate(int bitrate)
75{
76 return DIV_ROUND_UP(bitrate, 5) |
77 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
78}
79
Kalle Valo5e3dd152013-06-12 20:52:10 +030080/**********/
81/* Crypto */
82/**********/
83
84static int ath10k_send_key(struct ath10k_vif *arvif,
85 struct ieee80211_key_conf *key,
86 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010087 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030088{
Michal Kazior7aa7a722014-08-25 12:09:38 +020089 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030090 struct wmi_vdev_install_key_arg arg = {
91 .vdev_id = arvif->vdev_id,
92 .key_idx = key->keyidx,
93 .key_len = key->keylen,
94 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +010095 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +030096 .macaddr = macaddr,
97 };
98
Michal Kazior548db542013-07-05 16:15:15 +030099 lockdep_assert_held(&arvif->ar->conf_mutex);
100
Kalle Valo5e3dd152013-06-12 20:52:10 +0300101 switch (key->cipher) {
102 case WLAN_CIPHER_SUITE_CCMP:
103 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200104 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300105 break;
106 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300107 arg.key_cipher = WMI_CIPHER_TKIP;
108 arg.key_txmic_len = 8;
109 arg.key_rxmic_len = 8;
110 break;
111 case WLAN_CIPHER_SUITE_WEP40:
112 case WLAN_CIPHER_SUITE_WEP104:
113 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300114 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100115 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100116 WARN_ON(1);
117 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300118 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200119 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300120 return -EOPNOTSUPP;
121 }
122
123 if (cmd == DISABLE_KEY) {
124 arg.key_cipher = WMI_CIPHER_NONE;
125 arg.key_data = NULL;
126 }
127
128 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
129}
130
131static int ath10k_install_key(struct ath10k_vif *arvif,
132 struct ieee80211_key_conf *key,
133 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100134 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300135{
136 struct ath10k *ar = arvif->ar;
137 int ret;
138
Michal Kazior548db542013-07-05 16:15:15 +0300139 lockdep_assert_held(&ar->conf_mutex);
140
Wolfram Sang16735d02013-11-14 14:32:02 -0800141 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300142
Michal Kazior370e5672015-02-18 14:02:26 +0100143 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 if (ret)
145 return ret;
146
147 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
148 if (ret == 0)
149 return -ETIMEDOUT;
150
151 return 0;
152}
153
154static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
155 const u8 *addr)
156{
157 struct ath10k *ar = arvif->ar;
158 struct ath10k_peer *peer;
159 int ret;
160 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100161 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300162
163 lockdep_assert_held(&ar->conf_mutex);
164
165 spin_lock_bh(&ar->data_lock);
166 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
167 spin_unlock_bh(&ar->data_lock);
168
169 if (!peer)
170 return -ENOENT;
171
172 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
173 if (arvif->wep_keys[i] == NULL)
174 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100175
176 flags = 0;
177 flags |= WMI_KEY_PAIRWISE;
178
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200179 /* set TX_USAGE flag for default key id */
180 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100181 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300182
183 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100184 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 if (ret)
186 return ret;
187
Sujith Manoharanae167132014-11-25 11:46:59 +0530188 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300189 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530190 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300191 }
192
193 return 0;
194}
195
196static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
197 const u8 *addr)
198{
199 struct ath10k *ar = arvif->ar;
200 struct ath10k_peer *peer;
201 int first_errno = 0;
202 int ret;
203 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100204 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300205
206 lockdep_assert_held(&ar->conf_mutex);
207
208 spin_lock_bh(&ar->data_lock);
209 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
210 spin_unlock_bh(&ar->data_lock);
211
212 if (!peer)
213 return -ENOENT;
214
215 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
216 if (peer->keys[i] == NULL)
217 continue;
218
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200219 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100221 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300222 if (ret && first_errno == 0)
223 first_errno = ret;
224
225 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200226 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300227 i, ret);
228
Sujith Manoharanae167132014-11-25 11:46:59 +0530229 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300230 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530231 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232 }
233
234 return first_errno;
235}
236
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530237bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
238 u8 keyidx)
239{
240 struct ath10k_peer *peer;
241 int i;
242
243 lockdep_assert_held(&ar->data_lock);
244
245 /* We don't know which vdev this peer belongs to,
246 * since WMI doesn't give us that information.
247 *
248 * FIXME: multi-bss needs to be handled.
249 */
250 peer = ath10k_peer_find(ar, 0, addr);
251 if (!peer)
252 return false;
253
254 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
255 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
256 return true;
257 }
258
259 return false;
260}
261
Kalle Valo5e3dd152013-06-12 20:52:10 +0300262static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
263 struct ieee80211_key_conf *key)
264{
265 struct ath10k *ar = arvif->ar;
266 struct ath10k_peer *peer;
267 u8 addr[ETH_ALEN];
268 int first_errno = 0;
269 int ret;
270 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100271 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300272
273 lockdep_assert_held(&ar->conf_mutex);
274
275 for (;;) {
276 /* since ath10k_install_key we can't hold data_lock all the
277 * time, so we try to remove the keys incrementally */
278 spin_lock_bh(&ar->data_lock);
279 i = 0;
280 list_for_each_entry(peer, &ar->peers, list) {
281 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
282 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300283 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300284 peer->keys[i] = NULL;
285 break;
286 }
287 }
288
289 if (i < ARRAY_SIZE(peer->keys))
290 break;
291 }
292 spin_unlock_bh(&ar->data_lock);
293
294 if (i == ARRAY_SIZE(peer->keys))
295 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200296 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100297 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300298 if (ret && first_errno == 0)
299 first_errno = ret;
300
301 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200302 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200303 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300304 }
305
306 return first_errno;
307}
308
Michal Kazior370e5672015-02-18 14:02:26 +0100309static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
310{
311 struct ath10k *ar = arvif->ar;
312 enum nl80211_iftype iftype = arvif->vif->type;
313 struct ieee80211_key_conf *key;
314 u32 flags = 0;
315 int num = 0;
316 int i;
317 int ret;
318
319 lockdep_assert_held(&ar->conf_mutex);
320
321 if (iftype != NL80211_IFTYPE_STATION)
322 return 0;
323
324 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
325 if (arvif->wep_keys[i]) {
326 key = arvif->wep_keys[i];
327 ++num;
328 }
329 }
330
331 if (num != 1)
332 return 0;
333
334 flags |= WMI_KEY_PAIRWISE;
335 flags |= WMI_KEY_TX_USAGE;
336
337 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
338 if (ret) {
339 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
340 key->keyidx, arvif->vdev_id, ret);
341 return ret;
342 }
343
344 return 0;
345}
346
Michal Kaziorad325cb2015-02-18 14:02:27 +0100347static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
348 struct ieee80211_key_conf *key)
349{
350 struct ath10k *ar = arvif->ar;
351 struct ath10k_peer *peer;
352 int ret;
353
354 lockdep_assert_held(&ar->conf_mutex);
355
356 list_for_each_entry(peer, &ar->peers, list) {
357 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
358 continue;
359
360 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
361 continue;
362
363 if (peer->keys[key->keyidx] == key)
364 continue;
365
366 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
367 arvif->vdev_id, key->keyidx);
368
369 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
370 if (ret) {
371 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
372 arvif->vdev_id, peer->addr, ret);
373 return ret;
374 }
375 }
376
377 return 0;
378}
379
Kalle Valo5e3dd152013-06-12 20:52:10 +0300380/*********************/
381/* General utilities */
382/*********************/
383
384static inline enum wmi_phy_mode
385chan_to_phymode(const struct cfg80211_chan_def *chandef)
386{
387 enum wmi_phy_mode phymode = MODE_UNKNOWN;
388
389 switch (chandef->chan->band) {
390 case IEEE80211_BAND_2GHZ:
391 switch (chandef->width) {
392 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800393 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
394 phymode = MODE_11B;
395 else
396 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300397 break;
398 case NL80211_CHAN_WIDTH_20:
399 phymode = MODE_11NG_HT20;
400 break;
401 case NL80211_CHAN_WIDTH_40:
402 phymode = MODE_11NG_HT40;
403 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400404 case NL80211_CHAN_WIDTH_5:
405 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300406 case NL80211_CHAN_WIDTH_80:
407 case NL80211_CHAN_WIDTH_80P80:
408 case NL80211_CHAN_WIDTH_160:
409 phymode = MODE_UNKNOWN;
410 break;
411 }
412 break;
413 case IEEE80211_BAND_5GHZ:
414 switch (chandef->width) {
415 case NL80211_CHAN_WIDTH_20_NOHT:
416 phymode = MODE_11A;
417 break;
418 case NL80211_CHAN_WIDTH_20:
419 phymode = MODE_11NA_HT20;
420 break;
421 case NL80211_CHAN_WIDTH_40:
422 phymode = MODE_11NA_HT40;
423 break;
424 case NL80211_CHAN_WIDTH_80:
425 phymode = MODE_11AC_VHT80;
426 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400427 case NL80211_CHAN_WIDTH_5:
428 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300429 case NL80211_CHAN_WIDTH_80P80:
430 case NL80211_CHAN_WIDTH_160:
431 phymode = MODE_UNKNOWN;
432 break;
433 }
434 break;
435 default:
436 break;
437 }
438
439 WARN_ON(phymode == MODE_UNKNOWN);
440 return phymode;
441}
442
443static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
444{
445/*
446 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
447 * 0 for no restriction
448 * 1 for 1/4 us
449 * 2 for 1/2 us
450 * 3 for 1 us
451 * 4 for 2 us
452 * 5 for 4 us
453 * 6 for 8 us
454 * 7 for 16 us
455 */
456 switch (mpdudensity) {
457 case 0:
458 return 0;
459 case 1:
460 case 2:
461 case 3:
462 /* Our lower layer calculations limit our precision to
463 1 microsecond */
464 return 1;
465 case 4:
466 return 2;
467 case 5:
468 return 4;
469 case 6:
470 return 8;
471 case 7:
472 return 16;
473 default:
474 return 0;
475 }
476}
477
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300478static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
479 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300480{
481 int ret;
482
483 lockdep_assert_held(&ar->conf_mutex);
484
Michal Kaziorcfd10612014-11-25 15:16:05 +0100485 if (ar->num_peers >= ar->max_num_peers)
486 return -ENOBUFS;
487
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300488 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800489 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200490 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200491 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300492 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800493 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300494
495 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800496 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200497 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200498 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300499 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800500 }
Michal Kazior292a7532014-11-25 15:16:04 +0100501
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100502 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300503
504 return 0;
505}
506
Kalle Valo5a13e762014-01-20 11:01:46 +0200507static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
508{
509 struct ath10k *ar = arvif->ar;
510 u32 param;
511 int ret;
512
513 param = ar->wmi.pdev_param->sta_kickout_th;
514 ret = ath10k_wmi_pdev_set_param(ar, param,
515 ATH10K_KICKOUT_THRESHOLD);
516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200517 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200518 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200519 return ret;
520 }
521
522 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
523 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
524 ATH10K_KEEPALIVE_MIN_IDLE);
525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200526 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200527 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200528 return ret;
529 }
530
531 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
532 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
533 ATH10K_KEEPALIVE_MAX_IDLE);
534 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200535 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200536 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200537 return ret;
538 }
539
540 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
541 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
542 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
543 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200544 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200545 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200546 return ret;
547 }
548
549 return 0;
550}
551
Vivek Natarajanacab6402014-11-26 09:06:12 +0200552static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200553{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200554 struct ath10k *ar = arvif->ar;
555 u32 vdev_param;
556
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200557 vdev_param = ar->wmi.vdev_param->rts_threshold;
558 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200559}
560
561static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
562{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200563 struct ath10k *ar = arvif->ar;
564 u32 vdev_param;
565
Michal Kazior424121c2013-07-22 14:13:31 +0200566 if (value != 0xFFFFFFFF)
567 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
568 ATH10K_FRAGMT_THRESHOLD_MIN,
569 ATH10K_FRAGMT_THRESHOLD_MAX);
570
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200571 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
572 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200573}
574
Kalle Valo5e3dd152013-06-12 20:52:10 +0300575static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
576{
577 int ret;
578
579 lockdep_assert_held(&ar->conf_mutex);
580
581 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
582 if (ret)
583 return ret;
584
585 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
586 if (ret)
587 return ret;
588
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100589 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100590
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591 return 0;
592}
593
594static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
595{
596 struct ath10k_peer *peer, *tmp;
597
598 lockdep_assert_held(&ar->conf_mutex);
599
600 spin_lock_bh(&ar->data_lock);
601 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
602 if (peer->vdev_id != vdev_id)
603 continue;
604
Michal Kazior7aa7a722014-08-25 12:09:38 +0200605 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 peer->addr, vdev_id);
607
608 list_del(&peer->list);
609 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100610 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300611 }
612 spin_unlock_bh(&ar->data_lock);
613}
614
Michal Kaziora96d7742013-07-16 09:38:56 +0200615static void ath10k_peer_cleanup_all(struct ath10k *ar)
616{
617 struct ath10k_peer *peer, *tmp;
618
619 lockdep_assert_held(&ar->conf_mutex);
620
621 spin_lock_bh(&ar->data_lock);
622 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
623 list_del(&peer->list);
624 kfree(peer);
625 }
626 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100627
628 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100629 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200630}
631
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300632static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
633 struct ieee80211_sta *sta,
634 enum wmi_tdls_peer_state state)
635{
636 int ret;
637 struct wmi_tdls_peer_update_cmd_arg arg = {};
638 struct wmi_tdls_peer_capab_arg cap = {};
639 struct wmi_channel_arg chan_arg = {};
640
641 lockdep_assert_held(&ar->conf_mutex);
642
643 arg.vdev_id = vdev_id;
644 arg.peer_state = state;
645 ether_addr_copy(arg.addr, sta->addr);
646
647 cap.peer_max_sp = sta->max_sp;
648 cap.peer_uapsd_queues = sta->uapsd_queues;
649
650 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
651 !sta->tdls_initiator)
652 cap.is_peer_responder = 1;
653
654 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
655 if (ret) {
656 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
657 arg.addr, vdev_id, ret);
658 return ret;
659 }
660
661 return 0;
662}
663
Kalle Valo5e3dd152013-06-12 20:52:10 +0300664/************************/
665/* Interface management */
666/************************/
667
Michal Kazior64badcb2014-09-18 11:18:02 +0300668void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
669{
670 struct ath10k *ar = arvif->ar;
671
672 lockdep_assert_held(&ar->data_lock);
673
674 if (!arvif->beacon)
675 return;
676
677 if (!arvif->beacon_buf)
678 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
679 arvif->beacon->len, DMA_TO_DEVICE);
680
Michal Kazioraf213192015-01-29 14:29:52 +0200681 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
682 arvif->beacon_state != ATH10K_BEACON_SENT))
683 return;
684
Michal Kazior64badcb2014-09-18 11:18:02 +0300685 dev_kfree_skb_any(arvif->beacon);
686
687 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200688 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300689}
690
691static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
692{
693 struct ath10k *ar = arvif->ar;
694
695 lockdep_assert_held(&ar->data_lock);
696
697 ath10k_mac_vif_beacon_free(arvif);
698
699 if (arvif->beacon_buf) {
700 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
701 arvif->beacon_buf, arvif->beacon_paddr);
702 arvif->beacon_buf = NULL;
703 }
704}
705
Kalle Valo5e3dd152013-06-12 20:52:10 +0300706static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
707{
708 int ret;
709
Michal Kazior548db542013-07-05 16:15:15 +0300710 lockdep_assert_held(&ar->conf_mutex);
711
Michal Kazior7962b0d2014-10-28 10:34:38 +0100712 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
713 return -ESHUTDOWN;
714
Kalle Valo5e3dd152013-06-12 20:52:10 +0300715 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
716 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
717 if (ret == 0)
718 return -ETIMEDOUT;
719
720 return 0;
721}
722
Michal Kazior1bbc0972014-04-08 09:45:47 +0300723static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300724{
Michal Kaziorc930f742014-01-23 11:38:25 +0100725 struct cfg80211_chan_def *chandef = &ar->chandef;
726 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300727 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728 int ret = 0;
729
730 lockdep_assert_held(&ar->conf_mutex);
731
Kalle Valo5e3dd152013-06-12 20:52:10 +0300732 arg.vdev_id = vdev_id;
733 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100734 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300735
736 /* TODO setup this dynamically, what in case we
737 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100738 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200739 arg.channel.chan_radar =
740 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300741
Michal Kazior89c5c842013-10-23 04:02:13 -0700742 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700743 arg.channel.max_power = channel->max_power * 2;
744 arg.channel.max_reg_power = channel->max_reg_power * 2;
745 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300746
Michal Kazior7962b0d2014-10-28 10:34:38 +0100747 reinit_completion(&ar->vdev_setup_done);
748
Kalle Valo5e3dd152013-06-12 20:52:10 +0300749 ret = ath10k_wmi_vdev_start(ar, &arg);
750 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200751 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200752 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300753 return ret;
754 }
755
756 ret = ath10k_vdev_setup_sync(ar);
757 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200758 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200759 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300760 return ret;
761 }
762
763 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200765 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200766 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300767 goto vdev_stop;
768 }
769
770 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300771
Michal Kazior7aa7a722014-08-25 12:09:38 +0200772 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300773 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300774 return 0;
775
776vdev_stop:
777 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
778 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200779 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200780 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300781
782 return ret;
783}
784
Michal Kazior1bbc0972014-04-08 09:45:47 +0300785static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300786{
787 int ret = 0;
788
789 lockdep_assert_held(&ar->conf_mutex);
790
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200791 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
792 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200793 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200794 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300795
Michal Kazior7962b0d2014-10-28 10:34:38 +0100796 reinit_completion(&ar->vdev_setup_done);
797
Kalle Valo5e3dd152013-06-12 20:52:10 +0300798 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
799 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200800 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200801 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300802
803 ret = ath10k_vdev_setup_sync(ar);
804 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200805 ath10k_warn(ar, "failed to synchronize 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
Michal Kazior7aa7a722014-08-25 12:09:38 +0200808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300809 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300810 return ret;
811}
812
Michal Kazior1bbc0972014-04-08 09:45:47 +0300813static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300814{
815 int bit, ret = 0;
816
817 lockdep_assert_held(&ar->conf_mutex);
818
Ben Greeara9aefb32014-08-12 11:02:19 +0300819 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200820 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300821 return -ENOMEM;
822 }
823
Ben Greear16c11172014-09-23 14:17:16 -0700824 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300825
Ben Greear16c11172014-09-23 14:17:16 -0700826 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300827
828 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
829 WMI_VDEV_TYPE_MONITOR,
830 0, ar->mac_addr);
831 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200832 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200833 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300834 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300835 }
836
Ben Greear16c11172014-09-23 14:17:16 -0700837 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200838 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300839 ar->monitor_vdev_id);
840
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300842}
843
Michal Kazior1bbc0972014-04-08 09:45:47 +0300844static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300845{
846 int ret = 0;
847
848 lockdep_assert_held(&ar->conf_mutex);
849
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
851 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200852 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200853 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854 return ret;
855 }
856
Ben Greear16c11172014-09-23 14:17:16 -0700857 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300858
Michal Kazior7aa7a722014-08-25 12:09:38 +0200859 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300860 ar->monitor_vdev_id);
861 return ret;
862}
863
Michal Kazior1bbc0972014-04-08 09:45:47 +0300864static int ath10k_monitor_start(struct ath10k *ar)
865{
866 int ret;
867
868 lockdep_assert_held(&ar->conf_mutex);
869
Michal Kazior1bbc0972014-04-08 09:45:47 +0300870 ret = ath10k_monitor_vdev_create(ar);
871 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200872 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300873 return ret;
874 }
875
876 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
877 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200878 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300879 ath10k_monitor_vdev_delete(ar);
880 return ret;
881 }
882
883 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200884 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300885
886 return 0;
887}
888
Michal Kazior19337472014-08-28 12:58:16 +0200889static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300890{
891 int ret;
892
893 lockdep_assert_held(&ar->conf_mutex);
894
Michal Kazior1bbc0972014-04-08 09:45:47 +0300895 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200896 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200897 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200898 return ret;
899 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300900
901 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200903 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200904 return ret;
905 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300906
907 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200908 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200909
910 return 0;
911}
912
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530913static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
914{
915 struct ath10k_vif *arvif;
916
917 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
918 return true;
919
920 if (!ar->num_started_vdevs)
921 return false;
922
923 list_for_each_entry(arvif, &ar->arvifs, list)
924 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
925 return false;
926
927 ath10k_dbg(ar, ATH10K_DBG_MAC,
928 "mac disabling promiscuous mode because vdev is started\n");
929 return true;
930}
931
Michal Kazior19337472014-08-28 12:58:16 +0200932static int ath10k_monitor_recalc(struct ath10k *ar)
933{
934 bool should_start;
935
936 lockdep_assert_held(&ar->conf_mutex);
937
938 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100939 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200940 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
941
942 ath10k_dbg(ar, ATH10K_DBG_MAC,
943 "mac monitor recalc started? %d should? %d\n",
944 ar->monitor_started, should_start);
945
946 if (should_start == ar->monitor_started)
947 return 0;
948
949 if (should_start)
950 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300951
952 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300953}
954
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200955static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
956{
957 struct ath10k *ar = arvif->ar;
958 u32 vdev_param, rts_cts = 0;
959
960 lockdep_assert_held(&ar->conf_mutex);
961
962 vdev_param = ar->wmi.vdev_param->enable_rtscts;
963
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200964 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200965
966 if (arvif->num_legacy_stations > 0)
967 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
968 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200969 else
970 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
971 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200972
973 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
974 rts_cts);
975}
976
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200977static int ath10k_start_cac(struct ath10k *ar)
978{
979 int ret;
980
981 lockdep_assert_held(&ar->conf_mutex);
982
983 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
984
Michal Kazior19337472014-08-28 12:58:16 +0200985 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200986 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200987 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200988 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
989 return ret;
990 }
991
Michal Kazior7aa7a722014-08-25 12:09:38 +0200992 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200993 ar->monitor_vdev_id);
994
995 return 0;
996}
997
998static int ath10k_stop_cac(struct ath10k *ar)
999{
1000 lockdep_assert_held(&ar->conf_mutex);
1001
1002 /* CAC is not running - do nothing */
1003 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1004 return 0;
1005
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001006 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001007 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001008
Michal Kazior7aa7a722014-08-25 12:09:38 +02001009 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001010
1011 return 0;
1012}
1013
Michal Kaziord6500972014-04-08 09:56:09 +03001014static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001015{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001016 int ret;
1017
1018 lockdep_assert_held(&ar->conf_mutex);
1019
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001020 ath10k_stop_cac(ar);
1021
Michal Kaziord6500972014-04-08 09:56:09 +03001022 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001023 return;
1024
Michal Kaziord6500972014-04-08 09:56:09 +03001025 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001026 return;
1027
1028 ret = ath10k_start_cac(ar);
1029 if (ret) {
1030 /*
1031 * Not possible to start CAC on current channel so starting
1032 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1033 * by indicating that radar was detected.
1034 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001035 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001036 ieee80211_radar_detected(ar->hw);
1037 }
1038}
1039
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301040static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1041{
1042 struct ath10k *ar = arvif->ar;
1043 int ret;
1044
1045 lockdep_assert_held(&ar->conf_mutex);
1046
1047 reinit_completion(&ar->vdev_setup_done);
1048
1049 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1050 if (ret) {
1051 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1052 arvif->vdev_id, ret);
1053 return ret;
1054 }
1055
1056 ret = ath10k_vdev_setup_sync(ar);
1057 if (ret) {
1058 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1059 arvif->vdev_id, ret);
1060 return ret;
1061 }
1062
1063 WARN_ON(ar->num_started_vdevs == 0);
1064
1065 if (ar->num_started_vdevs != 0) {
1066 ar->num_started_vdevs--;
1067 ath10k_recalc_radar_detection(ar);
1068 }
1069
1070 return ret;
1071}
1072
Michal Kaziordc55e302014-07-29 12:53:36 +03001073static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001074{
1075 struct ath10k *ar = arvif->ar;
1076 struct cfg80211_chan_def *chandef = &ar->chandef;
1077 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301078 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001079
1080 lockdep_assert_held(&ar->conf_mutex);
1081
1082 reinit_completion(&ar->vdev_setup_done);
1083
1084 arg.vdev_id = arvif->vdev_id;
1085 arg.dtim_period = arvif->dtim_period;
1086 arg.bcn_intval = arvif->beacon_interval;
1087
1088 arg.channel.freq = chandef->chan->center_freq;
1089 arg.channel.band_center_freq1 = chandef->center_freq1;
1090 arg.channel.mode = chan_to_phymode(chandef);
1091
1092 arg.channel.min_power = 0;
1093 arg.channel.max_power = chandef->chan->max_power * 2;
1094 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1095 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1096
1097 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1098 arg.ssid = arvif->u.ap.ssid;
1099 arg.ssid_len = arvif->u.ap.ssid_len;
1100 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1101
1102 /* For now allow DFS for AP mode */
1103 arg.channel.chan_radar =
1104 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1105 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1106 arg.ssid = arvif->vif->bss_conf.ssid;
1107 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1108 }
1109
Michal Kazior7aa7a722014-08-25 12:09:38 +02001110 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001111 "mac vdev %d start center_freq %d phymode %s\n",
1112 arg.vdev_id, arg.channel.freq,
1113 ath10k_wmi_phymode_str(arg.channel.mode));
1114
Michal Kaziordc55e302014-07-29 12:53:36 +03001115 if (restart)
1116 ret = ath10k_wmi_vdev_restart(ar, &arg);
1117 else
1118 ret = ath10k_wmi_vdev_start(ar, &arg);
1119
Michal Kazior72654fa2014-04-08 09:56:09 +03001120 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001121 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001122 arg.vdev_id, ret);
1123 return ret;
1124 }
1125
1126 ret = ath10k_vdev_setup_sync(ar);
1127 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001128 ath10k_warn(ar,
1129 "failed to synchronize setup for vdev %i restart %d: %d\n",
1130 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001131 return ret;
1132 }
1133
Michal Kaziord6500972014-04-08 09:56:09 +03001134 ar->num_started_vdevs++;
1135 ath10k_recalc_radar_detection(ar);
1136
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301137 ret = ath10k_monitor_recalc(ar);
1138 if (ret) {
1139 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1140 arg.vdev_id, restart, ret);
1141 ret2 = ath10k_vdev_stop(arvif);
1142 if (ret2)
1143 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1144 arg.vdev_id, restart, ret2);
1145 }
1146
Michal Kazior72654fa2014-04-08 09:56:09 +03001147 return ret;
1148}
1149
Michal Kaziordc55e302014-07-29 12:53:36 +03001150static int ath10k_vdev_start(struct ath10k_vif *arvif)
1151{
1152 return ath10k_vdev_start_restart(arvif, false);
1153}
1154
1155static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1156{
1157 return ath10k_vdev_start_restart(arvif, true);
1158}
1159
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001160static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1161 struct sk_buff *bcn)
1162{
1163 struct ath10k *ar = arvif->ar;
1164 struct ieee80211_mgmt *mgmt;
1165 const u8 *p2p_ie;
1166 int ret;
1167
1168 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1169 return 0;
1170
1171 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1172 return 0;
1173
1174 mgmt = (void *)bcn->data;
1175 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1176 mgmt->u.beacon.variable,
1177 bcn->len - (mgmt->u.beacon.variable -
1178 bcn->data));
1179 if (!p2p_ie)
1180 return -ENOENT;
1181
1182 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1183 if (ret) {
1184 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1185 arvif->vdev_id, ret);
1186 return ret;
1187 }
1188
1189 return 0;
1190}
1191
1192static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1193 u8 oui_type, size_t ie_offset)
1194{
1195 size_t len;
1196 const u8 *next;
1197 const u8 *end;
1198 u8 *ie;
1199
1200 if (WARN_ON(skb->len < ie_offset))
1201 return -EINVAL;
1202
1203 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1204 skb->data + ie_offset,
1205 skb->len - ie_offset);
1206 if (!ie)
1207 return -ENOENT;
1208
1209 len = ie[1] + 2;
1210 end = skb->data + skb->len;
1211 next = ie + len;
1212
1213 if (WARN_ON(next > end))
1214 return -EINVAL;
1215
1216 memmove(ie, next, end - next);
1217 skb_trim(skb, skb->len - len);
1218
1219 return 0;
1220}
1221
1222static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1223{
1224 struct ath10k *ar = arvif->ar;
1225 struct ieee80211_hw *hw = ar->hw;
1226 struct ieee80211_vif *vif = arvif->vif;
1227 struct ieee80211_mutable_offsets offs = {};
1228 struct sk_buff *bcn;
1229 int ret;
1230
1231 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1232 return 0;
1233
Michal Kazior81a9a172015-03-05 16:02:17 +02001234 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1235 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1236 return 0;
1237
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001238 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1239 if (!bcn) {
1240 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1241 return -EPERM;
1242 }
1243
1244 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1245 if (ret) {
1246 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1247 kfree_skb(bcn);
1248 return ret;
1249 }
1250
1251 /* P2P IE is inserted by firmware automatically (as configured above)
1252 * so remove it from the base beacon template to avoid duplicate P2P
1253 * IEs in beacon frames.
1254 */
1255 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1256 offsetof(struct ieee80211_mgmt,
1257 u.beacon.variable));
1258
1259 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1260 0, NULL, 0);
1261 kfree_skb(bcn);
1262
1263 if (ret) {
1264 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1265 ret);
1266 return ret;
1267 }
1268
1269 return 0;
1270}
1271
1272static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1273{
1274 struct ath10k *ar = arvif->ar;
1275 struct ieee80211_hw *hw = ar->hw;
1276 struct ieee80211_vif *vif = arvif->vif;
1277 struct sk_buff *prb;
1278 int ret;
1279
1280 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1281 return 0;
1282
Michal Kazior81a9a172015-03-05 16:02:17 +02001283 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1284 return 0;
1285
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001286 prb = ieee80211_proberesp_get(hw, vif);
1287 if (!prb) {
1288 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1289 return -EPERM;
1290 }
1291
1292 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1293 kfree_skb(prb);
1294
1295 if (ret) {
1296 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1297 ret);
1298 return ret;
1299 }
1300
1301 return 0;
1302}
1303
Kalle Valo5e3dd152013-06-12 20:52:10 +03001304static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001305 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001306{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001307 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308 int ret = 0;
1309
Michal Kazior548db542013-07-05 16:15:15 +03001310 lockdep_assert_held(&arvif->ar->conf_mutex);
1311
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312 if (!info->enable_beacon) {
1313 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001314
1315 arvif->is_started = false;
1316 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001317
1318 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001319 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001320 spin_unlock_bh(&arvif->ar->data_lock);
1321
Kalle Valo5e3dd152013-06-12 20:52:10 +03001322 return;
1323 }
1324
1325 arvif->tx_seq_no = 0x1000;
1326
1327 ret = ath10k_vdev_start(arvif);
1328 if (ret)
1329 return;
1330
Michal Kaziorc930f742014-01-23 11:38:25 +01001331 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001332 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001333
1334 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1335 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001337 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001338 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001339 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340 return;
1341 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001342
1343 arvif->is_started = true;
1344 arvif->is_up = true;
1345
Michal Kazior7aa7a722014-08-25 12:09:38 +02001346 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347}
1348
1349static void ath10k_control_ibss(struct ath10k_vif *arvif,
1350 struct ieee80211_bss_conf *info,
1351 const u8 self_peer[ETH_ALEN])
1352{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001353 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001354 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355 int ret = 0;
1356
Michal Kazior548db542013-07-05 16:15:15 +03001357 lockdep_assert_held(&arvif->ar->conf_mutex);
1358
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 if (!info->ibss_joined) {
1360 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1361 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001362 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001363 self_peer, arvif->vdev_id, ret);
1364
Michal Kaziorc930f742014-01-23 11:38:25 +01001365 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 return;
1367
Michal Kaziorc930f742014-01-23 11:38:25 +01001368 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369
1370 return;
1371 }
1372
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001373 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1374 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001375 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001376 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 self_peer, arvif->vdev_id, ret);
1378 return;
1379 }
1380
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001381 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1382 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383 ATH10K_DEFAULT_ATIM);
1384 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001385 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386 arvif->vdev_id, ret);
1387}
1388
Michal Kazior9f9b5742014-12-12 12:41:36 +01001389static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1390{
1391 struct ath10k *ar = arvif->ar;
1392 u32 param;
1393 u32 value;
1394 int ret;
1395
1396 lockdep_assert_held(&arvif->ar->conf_mutex);
1397
1398 if (arvif->u.sta.uapsd)
1399 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1400 else
1401 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1402
1403 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1404 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1405 if (ret) {
1406 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1407 value, arvif->vdev_id, ret);
1408 return ret;
1409 }
1410
1411 return 0;
1412}
1413
1414static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1415{
1416 struct ath10k *ar = arvif->ar;
1417 u32 param;
1418 u32 value;
1419 int ret;
1420
1421 lockdep_assert_held(&arvif->ar->conf_mutex);
1422
1423 if (arvif->u.sta.uapsd)
1424 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1425 else
1426 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1427
1428 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1429 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1430 param, value);
1431 if (ret) {
1432 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1433 value, arvif->vdev_id, ret);
1434 return ret;
1435 }
1436
1437 return 0;
1438}
1439
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001440static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1441{
1442 struct ath10k_vif *arvif;
1443 int num = 0;
1444
1445 lockdep_assert_held(&ar->conf_mutex);
1446
1447 list_for_each_entry(arvif, &ar->arvifs, list)
1448 if (arvif->ps)
1449 num++;
1450
1451 return num;
1452}
1453
Michal Kaziorad088bf2013-10-16 15:44:46 +03001454static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001455{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001456 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001457 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001458 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459 enum wmi_sta_powersave_param param;
1460 enum wmi_sta_ps_mode psmode;
1461 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001462 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001463 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001464
Michal Kazior548db542013-07-05 16:15:15 +03001465 lockdep_assert_held(&arvif->ar->conf_mutex);
1466
Michal Kaziorad088bf2013-10-16 15:44:46 +03001467 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1468 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001469
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001470 enable_ps = arvif->ps;
1471
1472 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1473 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1474 ar->fw_features)) {
1475 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1476 arvif->vdev_id);
1477 enable_ps = false;
1478 }
1479
1480 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481 psmode = WMI_STA_PS_MODE_ENABLED;
1482 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1483
Michal Kazior526549a2014-12-12 12:41:37 +01001484 ps_timeout = conf->dynamic_ps_timeout;
1485 if (ps_timeout == 0) {
1486 /* Firmware doesn't like 0 */
1487 ps_timeout = ieee80211_tu_to_usec(
1488 vif->bss_conf.beacon_int) / 1000;
1489 }
1490
Michal Kaziorad088bf2013-10-16 15:44:46 +03001491 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001492 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001493 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001494 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001495 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001496 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001497 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498 } else {
1499 psmode = WMI_STA_PS_MODE_DISABLED;
1500 }
1501
Michal Kazior7aa7a722014-08-25 12:09:38 +02001502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001503 arvif->vdev_id, psmode ? "enable" : "disable");
1504
Michal Kaziorad088bf2013-10-16 15:44:46 +03001505 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001507 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001508 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001509 return ret;
1510 }
1511
1512 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513}
1514
Michal Kazior46725b152015-01-28 09:57:49 +02001515static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1516{
1517 struct ath10k *ar = arvif->ar;
1518 struct wmi_sta_keepalive_arg arg = {};
1519 int ret;
1520
1521 lockdep_assert_held(&arvif->ar->conf_mutex);
1522
1523 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1524 return 0;
1525
1526 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1527 return 0;
1528
1529 /* Some firmware revisions have a bug and ignore the `enabled` field.
1530 * Instead use the interval to disable the keepalive.
1531 */
1532 arg.vdev_id = arvif->vdev_id;
1533 arg.enabled = 1;
1534 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1535 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1536
1537 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1538 if (ret) {
1539 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1540 arvif->vdev_id, ret);
1541 return ret;
1542 }
1543
1544 return 0;
1545}
1546
Michal Kazior81a9a172015-03-05 16:02:17 +02001547static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1548{
1549 struct ath10k *ar = arvif->ar;
1550 struct ieee80211_vif *vif = arvif->vif;
1551 int ret;
1552
Michal Kazior8513d952015-03-09 14:19:24 +01001553 lockdep_assert_held(&arvif->ar->conf_mutex);
1554
1555 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1556 return;
1557
Michal Kazior81a9a172015-03-05 16:02:17 +02001558 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1559 return;
1560
1561 if (!vif->csa_active)
1562 return;
1563
1564 if (!arvif->is_up)
1565 return;
1566
1567 if (!ieee80211_csa_is_complete(vif)) {
1568 ieee80211_csa_update_counter(vif);
1569
1570 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1571 if (ret)
1572 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1573 ret);
1574
1575 ret = ath10k_mac_setup_prb_tmpl(arvif);
1576 if (ret)
1577 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1578 ret);
1579 } else {
1580 ieee80211_csa_finish(vif);
1581 }
1582}
1583
1584static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1585{
1586 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1587 ap_csa_work);
1588 struct ath10k *ar = arvif->ar;
1589
1590 mutex_lock(&ar->conf_mutex);
1591 ath10k_mac_vif_ap_csa_count_down(arvif);
1592 mutex_unlock(&ar->conf_mutex);
1593}
1594
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001595static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1596 struct ieee80211_vif *vif)
1597{
1598 struct sk_buff *skb = data;
1599 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1600 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1601
1602 if (vif->type != NL80211_IFTYPE_STATION)
1603 return;
1604
1605 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1606 return;
1607
1608 cancel_delayed_work(&arvif->connection_loss_work);
1609}
1610
1611void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1612{
1613 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1614 IEEE80211_IFACE_ITER_NORMAL,
1615 ath10k_mac_handle_beacon_iter,
1616 skb);
1617}
1618
1619static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1620 struct ieee80211_vif *vif)
1621{
1622 u32 *vdev_id = data;
1623 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1624 struct ath10k *ar = arvif->ar;
1625 struct ieee80211_hw *hw = ar->hw;
1626
1627 if (arvif->vdev_id != *vdev_id)
1628 return;
1629
1630 if (!arvif->is_up)
1631 return;
1632
1633 ieee80211_beacon_loss(vif);
1634
1635 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1636 * (done by mac80211) succeeds but beacons do not resume then it
1637 * doesn't make sense to continue operation. Queue connection loss work
1638 * which can be cancelled when beacon is received.
1639 */
1640 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1641 ATH10K_CONNECTION_LOSS_HZ);
1642}
1643
1644void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1645{
1646 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1647 IEEE80211_IFACE_ITER_NORMAL,
1648 ath10k_mac_handle_beacon_miss_iter,
1649 &vdev_id);
1650}
1651
1652static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1653{
1654 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1655 connection_loss_work.work);
1656 struct ieee80211_vif *vif = arvif->vif;
1657
1658 if (!arvif->is_up)
1659 return;
1660
1661 ieee80211_connection_loss(vif);
1662}
1663
Kalle Valo5e3dd152013-06-12 20:52:10 +03001664/**********************/
1665/* Station management */
1666/**********************/
1667
Michal Kazior590922a2014-10-21 10:10:29 +03001668static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1669 struct ieee80211_vif *vif)
1670{
1671 /* Some firmware revisions have unstable STA powersave when listen
1672 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1673 * generate NullFunc frames properly even if buffered frames have been
1674 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1675 * buffered frames. Often pinging the device from AP would simply fail.
1676 *
1677 * As a workaround set it to 1.
1678 */
1679 if (vif->type == NL80211_IFTYPE_STATION)
1680 return 1;
1681
1682 return ar->hw->conf.listen_interval;
1683}
1684
Kalle Valo5e3dd152013-06-12 20:52:10 +03001685static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001686 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001687 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001688 struct wmi_peer_assoc_complete_arg *arg)
1689{
Michal Kazior590922a2014-10-21 10:10:29 +03001690 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1691
Michal Kazior548db542013-07-05 16:15:15 +03001692 lockdep_assert_held(&ar->conf_mutex);
1693
Kalle Valob25f32c2014-09-14 12:50:49 +03001694 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695 arg->vdev_id = arvif->vdev_id;
1696 arg->peer_aid = sta->aid;
1697 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001698 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001700 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701}
1702
1703static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001704 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001705 struct wmi_peer_assoc_complete_arg *arg)
1706{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707 struct ieee80211_bss_conf *info = &vif->bss_conf;
1708 struct cfg80211_bss *bss;
1709 const u8 *rsnie = NULL;
1710 const u8 *wpaie = NULL;
1711
Michal Kazior548db542013-07-05 16:15:15 +03001712 lockdep_assert_held(&ar->conf_mutex);
1713
Kalle Valo5e3dd152013-06-12 20:52:10 +03001714 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001715 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1716 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001717 if (bss) {
1718 const struct cfg80211_bss_ies *ies;
1719
1720 rcu_read_lock();
1721 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1722
1723 ies = rcu_dereference(bss->ies);
1724
1725 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001726 WLAN_OUI_TYPE_MICROSOFT_WPA,
1727 ies->data,
1728 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729 rcu_read_unlock();
1730 cfg80211_put_bss(ar->hw->wiphy, bss);
1731 }
1732
1733 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1734 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001735 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1737 }
1738
1739 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001740 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001741 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1742 }
1743}
1744
1745static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1746 struct ieee80211_sta *sta,
1747 struct wmi_peer_assoc_complete_arg *arg)
1748{
1749 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1750 const struct ieee80211_supported_band *sband;
1751 const struct ieee80211_rate *rates;
1752 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03001753 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001754 int i;
1755
Michal Kazior548db542013-07-05 16:15:15 +03001756 lockdep_assert_held(&ar->conf_mutex);
1757
Kalle Valo5e3dd152013-06-12 20:52:10 +03001758 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1759 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1760 rates = sband->bitrates;
1761
1762 rateset->num_rates = 0;
1763
1764 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1765 if (!(ratemask & 1))
1766 continue;
1767
Michal Kazior486017c2015-03-30 09:51:54 +03001768 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
1769 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001770 rateset->num_rates++;
1771 }
1772}
1773
1774static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1775 struct ieee80211_sta *sta,
1776 struct wmi_peer_assoc_complete_arg *arg)
1777{
1778 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001779 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001780 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781
Michal Kazior548db542013-07-05 16:15:15 +03001782 lockdep_assert_held(&ar->conf_mutex);
1783
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 if (!ht_cap->ht_supported)
1785 return;
1786
1787 arg->peer_flags |= WMI_PEER_HT;
1788 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1789 ht_cap->ampdu_factor)) - 1;
1790
1791 arg->peer_mpdu_density =
1792 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1793
1794 arg->peer_ht_caps = ht_cap->cap;
1795 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1796
1797 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1798 arg->peer_flags |= WMI_PEER_LDPC;
1799
1800 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1801 arg->peer_flags |= WMI_PEER_40MHZ;
1802 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1803 }
1804
1805 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1806 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1807
1808 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1809 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1810
1811 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1812 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1813 arg->peer_flags |= WMI_PEER_STBC;
1814 }
1815
1816 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001817 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1818 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1819 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1820 arg->peer_rate_caps |= stbc;
1821 arg->peer_flags |= WMI_PEER_STBC;
1822 }
1823
Kalle Valo5e3dd152013-06-12 20:52:10 +03001824 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1825 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1826 else if (ht_cap->mcs.rx_mask[1])
1827 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1828
1829 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1830 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1831 arg->peer_ht_rates.rates[n++] = i;
1832
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001833 /*
1834 * This is a workaround for HT-enabled STAs which break the spec
1835 * and have no HT capabilities RX mask (no HT RX MCS map).
1836 *
1837 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1838 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1839 *
1840 * Firmware asserts if such situation occurs.
1841 */
1842 if (n == 0) {
1843 arg->peer_ht_rates.num_rates = 8;
1844 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1845 arg->peer_ht_rates.rates[i] = i;
1846 } else {
1847 arg->peer_ht_rates.num_rates = n;
1848 arg->peer_num_spatial_streams = sta->rx_nss;
1849 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001850
Michal Kazior7aa7a722014-08-25 12:09:38 +02001851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001852 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853 arg->peer_ht_rates.num_rates,
1854 arg->peer_num_spatial_streams);
1855}
1856
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001857static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1858 struct ath10k_vif *arvif,
1859 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001860{
1861 u32 uapsd = 0;
1862 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001863 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001864
Michal Kazior548db542013-07-05 16:15:15 +03001865 lockdep_assert_held(&ar->conf_mutex);
1866
Kalle Valo5e3dd152013-06-12 20:52:10 +03001867 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001868 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869 sta->uapsd_queues, sta->max_sp);
1870
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1872 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1873 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1874 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1875 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1876 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1877 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1878 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1879 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1880 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1881 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1882 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1883
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1885 max_sp = sta->max_sp;
1886
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001887 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1888 sta->addr,
1889 WMI_AP_PS_PEER_PARAM_UAPSD,
1890 uapsd);
1891 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001892 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001893 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001894 return ret;
1895 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001897 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1898 sta->addr,
1899 WMI_AP_PS_PEER_PARAM_MAX_SP,
1900 max_sp);
1901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001902 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001903 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001904 return ret;
1905 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001906
1907 /* TODO setup this based on STA listen interval and
1908 beacon interval. Currently we don't know
1909 sta->listen_interval - mac80211 patch required.
1910 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001911 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001912 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1913 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001914 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001915 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001916 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001917 return ret;
1918 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001919 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001920
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001921 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001922}
1923
1924static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1925 struct ieee80211_sta *sta,
1926 struct wmi_peer_assoc_complete_arg *arg)
1927{
1928 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001929 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930
1931 if (!vht_cap->vht_supported)
1932 return;
1933
1934 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001935
1936 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1937 arg->peer_flags |= WMI_PEER_VHT_2G;
1938
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 arg->peer_vht_caps = vht_cap->cap;
1940
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001941 ampdu_factor = (vht_cap->cap &
1942 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1943 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1944
1945 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1946 * zero in VHT IE. Using it would result in degraded throughput.
1947 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1948 * it if VHT max_mpdu is smaller. */
1949 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1950 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1951 ampdu_factor)) - 1);
1952
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1954 arg->peer_flags |= WMI_PEER_80MHZ;
1955
1956 arg->peer_vht_rates.rx_max_rate =
1957 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1958 arg->peer_vht_rates.rx_mcs_set =
1959 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1960 arg->peer_vht_rates.tx_max_rate =
1961 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1962 arg->peer_vht_rates.tx_mcs_set =
1963 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1964
Michal Kazior7aa7a722014-08-25 12:09:38 +02001965 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001966 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967}
1968
1969static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001970 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001971 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972 struct wmi_peer_assoc_complete_arg *arg)
1973{
Michal Kazior590922a2014-10-21 10:10:29 +03001974 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1975
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 switch (arvif->vdev_type) {
1977 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001978 if (sta->wme)
1979 arg->peer_flags |= WMI_PEER_QOS;
1980
1981 if (sta->wme && sta->uapsd_queues) {
1982 arg->peer_flags |= WMI_PEER_APSD;
1983 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1984 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001985 break;
1986 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001987 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001988 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001989 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001990 case WMI_VDEV_TYPE_IBSS:
1991 if (sta->wme)
1992 arg->peer_flags |= WMI_PEER_QOS;
1993 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 default:
1995 break;
1996 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001997
1998 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1999 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002000}
2001
Michal Kazior91b12082014-12-12 12:41:35 +01002002static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
2003{
2004 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
2005 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
2006}
2007
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002009 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002010 struct ieee80211_sta *sta,
2011 struct wmi_peer_assoc_complete_arg *arg)
2012{
2013 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2014
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 switch (ar->hw->conf.chandef.chan->band) {
2016 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002017 if (sta->vht_cap.vht_supported) {
2018 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2019 phymode = MODE_11AC_VHT40;
2020 else
2021 phymode = MODE_11AC_VHT20;
2022 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2024 phymode = MODE_11NG_HT40;
2025 else
2026 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01002027 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002029 } else {
2030 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002031 }
2032
2033 break;
2034 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002035 /*
2036 * Check VHT first.
2037 */
2038 if (sta->vht_cap.vht_supported) {
2039 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2040 phymode = MODE_11AC_VHT80;
2041 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2042 phymode = MODE_11AC_VHT40;
2043 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2044 phymode = MODE_11AC_VHT20;
2045 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002046 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2047 phymode = MODE_11NA_HT40;
2048 else
2049 phymode = MODE_11NA_HT20;
2050 } else {
2051 phymode = MODE_11A;
2052 }
2053
2054 break;
2055 default:
2056 break;
2057 }
2058
Michal Kazior7aa7a722014-08-25 12:09:38 +02002059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002060 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002061
Kalle Valo5e3dd152013-06-12 20:52:10 +03002062 arg->peer_phymode = phymode;
2063 WARN_ON(phymode == MODE_UNKNOWN);
2064}
2065
Kalle Valob9ada652013-10-16 15:44:46 +03002066static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002067 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002068 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002069 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002070{
Michal Kazior548db542013-07-05 16:15:15 +03002071 lockdep_assert_held(&ar->conf_mutex);
2072
Kalle Valob9ada652013-10-16 15:44:46 +03002073 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074
Michal Kazior590922a2014-10-21 10:10:29 +03002075 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2076 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002077 ath10k_peer_assoc_h_rates(ar, sta, arg);
2078 ath10k_peer_assoc_h_ht(ar, sta, arg);
2079 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002080 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2081 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082
Kalle Valob9ada652013-10-16 15:44:46 +03002083 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002084}
2085
Michal Kazior90046f52014-02-14 14:45:51 +01002086static const u32 ath10k_smps_map[] = {
2087 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2088 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2089 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2090 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2091};
2092
2093static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2094 const u8 *addr,
2095 const struct ieee80211_sta_ht_cap *ht_cap)
2096{
2097 int smps;
2098
2099 if (!ht_cap->ht_supported)
2100 return 0;
2101
2102 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2103 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2104
2105 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2106 return -EINVAL;
2107
2108 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2109 WMI_PEER_SMPS_STATE,
2110 ath10k_smps_map[smps]);
2111}
2112
Michal Kazior139e1702015-02-15 16:50:42 +02002113static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2114 struct ieee80211_vif *vif,
2115 struct ieee80211_sta_vht_cap vht_cap)
2116{
2117 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2118 int ret;
2119 u32 param;
2120 u32 value;
2121
2122 if (!(ar->vht_cap_info &
2123 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2124 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2125 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2126 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2127 return 0;
2128
2129 param = ar->wmi.vdev_param->txbf;
2130 value = 0;
2131
2132 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2133 return 0;
2134
2135 /* The following logic is correct. If a remote STA advertises support
2136 * for being a beamformer then we should enable us being a beamformee.
2137 */
2138
2139 if (ar->vht_cap_info &
2140 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2141 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2142 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2143 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2144
2145 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2146 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2147 }
2148
2149 if (ar->vht_cap_info &
2150 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2151 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2152 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2153 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2154
2155 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2156 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2157 }
2158
2159 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2160 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2161
2162 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2163 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2164
2165 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2166 if (ret) {
2167 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2168 value, ret);
2169 return ret;
2170 }
2171
2172 return 0;
2173}
2174
Kalle Valo5e3dd152013-06-12 20:52:10 +03002175/* can be called only in mac80211 callbacks due to `key_count` usage */
2176static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2177 struct ieee80211_vif *vif,
2178 struct ieee80211_bss_conf *bss_conf)
2179{
2180 struct ath10k *ar = hw->priv;
2181 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002182 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002183 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002184 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 struct ieee80211_sta *ap_sta;
2186 int ret;
2187
Michal Kazior548db542013-07-05 16:15:15 +03002188 lockdep_assert_held(&ar->conf_mutex);
2189
Michal Kazior077efc82014-10-21 10:10:29 +03002190 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2191 arvif->vdev_id, arvif->bssid, arvif->aid);
2192
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193 rcu_read_lock();
2194
2195 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2196 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002197 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002198 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199 rcu_read_unlock();
2200 return;
2201 }
2202
Michal Kazior90046f52014-02-14 14:45:51 +01002203 /* ap_sta must be accessed only within rcu section which must be left
2204 * before calling ath10k_setup_peer_smps() which might sleep. */
2205 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002206 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002207
Michal Kazior590922a2014-10-21 10:10:29 +03002208 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002210 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002211 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002212 rcu_read_unlock();
2213 return;
2214 }
2215
2216 rcu_read_unlock();
2217
Kalle Valob9ada652013-10-16 15:44:46 +03002218 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2219 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002220 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002221 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002222 return;
2223 }
2224
Michal Kazior90046f52014-02-14 14:45:51 +01002225 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2226 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002227 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002228 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002229 return;
2230 }
2231
Michal Kazior139e1702015-02-15 16:50:42 +02002232 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2233 if (ret) {
2234 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2235 arvif->vdev_id, bss_conf->bssid, ret);
2236 return;
2237 }
2238
Michal Kazior7aa7a722014-08-25 12:09:38 +02002239 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002240 "mac vdev %d up (associated) bssid %pM aid %d\n",
2241 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2242
Michal Kazior077efc82014-10-21 10:10:29 +03002243 WARN_ON(arvif->is_up);
2244
Michal Kaziorc930f742014-01-23 11:38:25 +01002245 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002246 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002247
2248 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2249 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002250 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002251 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002252 return;
2253 }
2254
2255 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002256
2257 /* Workaround: Some firmware revisions (tested with qca6174
2258 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2259 * poked with peer param command.
2260 */
2261 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2262 WMI_PEER_DUMMY_VAR, 1);
2263 if (ret) {
2264 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2265 arvif->bssid, arvif->vdev_id, ret);
2266 return;
2267 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002268}
2269
Kalle Valo5e3dd152013-06-12 20:52:10 +03002270static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2271 struct ieee80211_vif *vif)
2272{
2273 struct ath10k *ar = hw->priv;
2274 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002275 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 int ret;
2277
Michal Kazior548db542013-07-05 16:15:15 +03002278 lockdep_assert_held(&ar->conf_mutex);
2279
Michal Kazior077efc82014-10-21 10:10:29 +03002280 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2281 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002282
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002284 if (ret)
2285 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2286 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002288 arvif->def_wep_key_idx = -1;
2289
Michal Kazior139e1702015-02-15 16:50:42 +02002290 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2291 if (ret) {
2292 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2293 arvif->vdev_id, ret);
2294 return;
2295 }
2296
Michal Kaziorc930f742014-01-23 11:38:25 +01002297 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002298
2299 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002300}
2301
Michal Kazior590922a2014-10-21 10:10:29 +03002302static int ath10k_station_assoc(struct ath10k *ar,
2303 struct ieee80211_vif *vif,
2304 struct ieee80211_sta *sta,
2305 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306{
Michal Kazior590922a2014-10-21 10:10:29 +03002307 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002308 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002309 int ret = 0;
2310
Michal Kazior548db542013-07-05 16:15:15 +03002311 lockdep_assert_held(&ar->conf_mutex);
2312
Michal Kazior590922a2014-10-21 10:10:29 +03002313 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002314 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002315 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002316 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002317 return ret;
2318 }
2319
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002320 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002321 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2322 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002323 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002324 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325 return ret;
2326 }
2327
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002328 /* Re-assoc is run only to update supported rates for given station. It
2329 * doesn't make much sense to reconfigure the peer completely.
2330 */
2331 if (!reassoc) {
2332 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2333 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002334 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002335 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002336 arvif->vdev_id, ret);
2337 return ret;
2338 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002339
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002340 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2341 if (ret) {
2342 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2343 sta->addr, arvif->vdev_id, ret);
2344 return ret;
2345 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002347 if (!sta->wme) {
2348 arvif->num_legacy_stations++;
2349 ret = ath10k_recalc_rtscts_prot(arvif);
2350 if (ret) {
2351 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2352 arvif->vdev_id, ret);
2353 return ret;
2354 }
2355 }
2356
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002357 /* Plumb cached keys only for static WEP */
2358 if (arvif->def_wep_key_idx != -1) {
2359 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2360 if (ret) {
2361 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2362 arvif->vdev_id, ret);
2363 return ret;
2364 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002365 }
2366 }
2367
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368 return ret;
2369}
2370
Michal Kazior590922a2014-10-21 10:10:29 +03002371static int ath10k_station_disassoc(struct ath10k *ar,
2372 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002373 struct ieee80211_sta *sta)
2374{
Michal Kazior590922a2014-10-21 10:10:29 +03002375 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376 int ret = 0;
2377
2378 lockdep_assert_held(&ar->conf_mutex);
2379
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002380 if (!sta->wme) {
2381 arvif->num_legacy_stations--;
2382 ret = ath10k_recalc_rtscts_prot(arvif);
2383 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002384 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002385 arvif->vdev_id, ret);
2386 return ret;
2387 }
2388 }
2389
Kalle Valo5e3dd152013-06-12 20:52:10 +03002390 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2391 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002392 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002393 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002394 return ret;
2395 }
2396
2397 return ret;
2398}
2399
2400/**************/
2401/* Regulatory */
2402/**************/
2403
2404static int ath10k_update_channel_list(struct ath10k *ar)
2405{
2406 struct ieee80211_hw *hw = ar->hw;
2407 struct ieee80211_supported_band **bands;
2408 enum ieee80211_band band;
2409 struct ieee80211_channel *channel;
2410 struct wmi_scan_chan_list_arg arg = {0};
2411 struct wmi_channel_arg *ch;
2412 bool passive;
2413 int len;
2414 int ret;
2415 int i;
2416
Michal Kazior548db542013-07-05 16:15:15 +03002417 lockdep_assert_held(&ar->conf_mutex);
2418
Kalle Valo5e3dd152013-06-12 20:52:10 +03002419 bands = hw->wiphy->bands;
2420 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2421 if (!bands[band])
2422 continue;
2423
2424 for (i = 0; i < bands[band]->n_channels; i++) {
2425 if (bands[band]->channels[i].flags &
2426 IEEE80211_CHAN_DISABLED)
2427 continue;
2428
2429 arg.n_channels++;
2430 }
2431 }
2432
2433 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2434 arg.channels = kzalloc(len, GFP_KERNEL);
2435 if (!arg.channels)
2436 return -ENOMEM;
2437
2438 ch = arg.channels;
2439 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2440 if (!bands[band])
2441 continue;
2442
2443 for (i = 0; i < bands[band]->n_channels; i++) {
2444 channel = &bands[band]->channels[i];
2445
2446 if (channel->flags & IEEE80211_CHAN_DISABLED)
2447 continue;
2448
2449 ch->allow_ht = true;
2450
2451 /* FIXME: when should we really allow VHT? */
2452 ch->allow_vht = true;
2453
2454 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002455 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456
2457 ch->ht40plus =
2458 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2459
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002460 ch->chan_radar =
2461 !!(channel->flags & IEEE80211_CHAN_RADAR);
2462
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002463 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464 ch->passive = passive;
2465
2466 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002467 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002468 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002469 ch->max_power = channel->max_power * 2;
2470 ch->max_reg_power = channel->max_reg_power * 2;
2471 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 ch->reg_class_id = 0; /* FIXME */
2473
2474 /* FIXME: why use only legacy modes, why not any
2475 * HT/VHT modes? Would that even make any
2476 * difference? */
2477 if (channel->band == IEEE80211_BAND_2GHZ)
2478 ch->mode = MODE_11G;
2479 else
2480 ch->mode = MODE_11A;
2481
2482 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2483 continue;
2484
Michal Kazior7aa7a722014-08-25 12:09:38 +02002485 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002486 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2487 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488 ch->freq, ch->max_power, ch->max_reg_power,
2489 ch->max_antenna_gain, ch->mode);
2490
2491 ch++;
2492 }
2493 }
2494
2495 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2496 kfree(arg.channels);
2497
2498 return ret;
2499}
2500
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002501static enum wmi_dfs_region
2502ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2503{
2504 switch (dfs_region) {
2505 case NL80211_DFS_UNSET:
2506 return WMI_UNINIT_DFS_DOMAIN;
2507 case NL80211_DFS_FCC:
2508 return WMI_FCC_DFS_DOMAIN;
2509 case NL80211_DFS_ETSI:
2510 return WMI_ETSI_DFS_DOMAIN;
2511 case NL80211_DFS_JP:
2512 return WMI_MKK4_DFS_DOMAIN;
2513 }
2514 return WMI_UNINIT_DFS_DOMAIN;
2515}
2516
Michal Kaziorf7843d72013-07-16 09:38:52 +02002517static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002518{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002519 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002520 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002521 enum wmi_dfs_region wmi_dfs_reg;
2522 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523
Michal Kaziorf7843d72013-07-16 09:38:52 +02002524 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525
2526 ret = ath10k_update_channel_list(ar);
2527 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002528 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002529
2530 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002531
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002532 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2533 nl_dfs_reg = ar->dfs_detector->region;
2534 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2535 } else {
2536 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2537 }
2538
Kalle Valo5e3dd152013-06-12 20:52:10 +03002539 /* Target allows setting up per-band regdomain but ath_common provides
2540 * a combined one only */
2541 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002542 regpair->reg_domain,
2543 regpair->reg_domain, /* 2ghz */
2544 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002546 regpair->reg_5ghz_ctl,
2547 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002549 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002550}
Michal Kazior548db542013-07-05 16:15:15 +03002551
Michal Kaziorf7843d72013-07-16 09:38:52 +02002552static void ath10k_reg_notifier(struct wiphy *wiphy,
2553 struct regulatory_request *request)
2554{
2555 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2556 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002557 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002558
2559 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2560
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002561 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002562 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002563 request->dfs_region);
2564 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2565 request->dfs_region);
2566 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002567 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002568 request->dfs_region);
2569 }
2570
Michal Kaziorf7843d72013-07-16 09:38:52 +02002571 mutex_lock(&ar->conf_mutex);
2572 if (ar->state == ATH10K_STATE_ON)
2573 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002574 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575}
2576
2577/***************/
2578/* TX handlers */
2579/***************/
2580
Michal Kazior42c3aa62013-10-02 11:03:38 +02002581static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2582{
2583 if (ieee80211_is_mgmt(hdr->frame_control))
2584 return HTT_DATA_TX_EXT_TID_MGMT;
2585
2586 if (!ieee80211_is_data_qos(hdr->frame_control))
2587 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2588
2589 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2590 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2591
2592 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2593}
2594
Michal Kazior2b37c292014-09-02 11:00:22 +03002595static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002596{
Michal Kazior2b37c292014-09-02 11:00:22 +03002597 if (vif)
2598 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002599
Michal Kazior1bbc0972014-04-08 09:45:47 +03002600 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002601 return ar->monitor_vdev_id;
2602
Michal Kazior7aa7a722014-08-25 12:09:38 +02002603 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002604 return 0;
2605}
2606
Michal Kaziord740d8f2015-03-30 09:51:51 +03002607static enum ath10k_hw_txrx_mode
2608ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002609 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002610{
2611 const struct ieee80211_hdr *hdr = (void *)skb->data;
2612 __le16 fc = hdr->frame_control;
2613
2614 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2615 return ATH10K_HW_TXRX_RAW;
2616
2617 if (ieee80211_is_mgmt(fc))
2618 return ATH10K_HW_TXRX_MGMT;
2619
2620 /* Workaround:
2621 *
2622 * NullFunc frames are mostly used to ping if a client or AP are still
2623 * reachable and responsive. This implies tx status reports must be
2624 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2625 * come to a conclusion that the other end disappeared and tear down
2626 * BSS connection or it can never disconnect from BSS/client (which is
2627 * the case).
2628 *
2629 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2630 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2631 * which seems to deliver correct tx reports for NullFunc frames. The
2632 * downside of using it is it ignores client powersave state so it can
2633 * end up disconnecting sleeping clients in AP mode. It should fix STA
2634 * mode though because AP don't sleep.
2635 */
2636 if (ar->htt.target_version_major < 3 &&
2637 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2638 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2639 return ATH10K_HW_TXRX_MGMT;
2640
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002641 /* Workaround:
2642 *
2643 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2644 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2645 * to work with Ethernet txmode so use it.
2646 */
2647 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2648 return ATH10K_HW_TXRX_ETHERNET;
2649
Michal Kaziord740d8f2015-03-30 09:51:51 +03002650 return ATH10K_HW_TXRX_NATIVE_WIFI;
2651}
2652
Michal Kazior4b604552014-07-21 21:03:09 +03002653/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2654 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655 */
Michal Kazior4b604552014-07-21 21:03:09 +03002656static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657{
2658 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002659 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660 u8 *qos_ctl;
2661
2662 if (!ieee80211_is_data_qos(hdr->frame_control))
2663 return;
2664
2665 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002666 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2667 skb->data, (void *)qos_ctl - (void *)skb->data);
2668 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002669
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002670 /* Some firmware revisions don't handle sending QoS NullFunc well.
2671 * These frames are mainly used for CQM purposes so it doesn't really
2672 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002673 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002674 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002675 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002676 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002677
2678 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679}
2680
Michal Kaziord740d8f2015-03-30 09:51:51 +03002681static void ath10k_tx_h_8023(struct sk_buff *skb)
2682{
2683 struct ieee80211_hdr *hdr;
2684 struct rfc1042_hdr *rfc1042;
2685 struct ethhdr *eth;
2686 size_t hdrlen;
2687 u8 da[ETH_ALEN];
2688 u8 sa[ETH_ALEN];
2689 __be16 type;
2690
2691 hdr = (void *)skb->data;
2692 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2693 rfc1042 = (void *)skb->data + hdrlen;
2694
2695 ether_addr_copy(da, ieee80211_get_DA(hdr));
2696 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2697 type = rfc1042->snap_type;
2698
2699 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2700 skb_push(skb, sizeof(*eth));
2701
2702 eth = (void *)skb->data;
2703 ether_addr_copy(eth->h_dest, da);
2704 ether_addr_copy(eth->h_source, sa);
2705 eth->h_proto = type;
2706}
2707
Michal Kazior4b604552014-07-21 21:03:09 +03002708static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2709 struct ieee80211_vif *vif,
2710 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711{
2712 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002713 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2714
2715 /* This is case only for P2P_GO */
2716 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2717 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2718 return;
2719
2720 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2721 spin_lock_bh(&ar->data_lock);
2722 if (arvif->u.ap.noa_data)
2723 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2724 GFP_ATOMIC))
2725 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2726 arvif->u.ap.noa_data,
2727 arvif->u.ap.noa_len);
2728 spin_unlock_bh(&ar->data_lock);
2729 }
2730}
2731
Michal Kazior8d6d3622014-11-24 14:58:31 +01002732static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2733{
2734 /* FIXME: Not really sure since when the behaviour changed. At some
2735 * point new firmware stopped requiring creation of peer entries for
2736 * offchannel tx (and actually creating them causes issues with wmi-htc
2737 * tx credit replenishment and reliability). Assuming it's at least 3.4
2738 * because that's when the `freq` was introduced to TX_FRM HTT command.
2739 */
2740 return !(ar->htt.target_version_major >= 3 &&
2741 ar->htt.target_version_minor >= 4);
2742}
2743
Michal Kaziord740d8f2015-03-30 09:51:51 +03002744static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002746 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002747 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748
Michal Kaziord740d8f2015-03-30 09:51:51 +03002749 spin_lock_bh(&ar->data_lock);
2750
2751 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2752 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2753 ret = -ENOSPC;
2754 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002755 }
2756
Michal Kaziord740d8f2015-03-30 09:51:51 +03002757 __skb_queue_tail(q, skb);
2758 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2759
2760unlock:
2761 spin_unlock_bh(&ar->data_lock);
2762
2763 return ret;
2764}
2765
2766static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2767{
2768 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2769 struct ath10k_htt *htt = &ar->htt;
2770 int ret = 0;
2771
2772 switch (cb->txmode) {
2773 case ATH10K_HW_TXRX_RAW:
2774 case ATH10K_HW_TXRX_NATIVE_WIFI:
2775 case ATH10K_HW_TXRX_ETHERNET:
2776 ret = ath10k_htt_tx(htt, skb);
2777 break;
2778 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002779 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002780 ar->fw_features))
2781 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2782 else if (ar->htt.target_version_major >= 3)
2783 ret = ath10k_htt_tx(htt, skb);
2784 else
2785 ret = ath10k_htt_mgmt_tx(htt, skb);
2786 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002787 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002788
2789 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002790 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2791 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792 ieee80211_free_txskb(ar->hw, skb);
2793 }
2794}
2795
2796void ath10k_offchan_tx_purge(struct ath10k *ar)
2797{
2798 struct sk_buff *skb;
2799
2800 for (;;) {
2801 skb = skb_dequeue(&ar->offchan_tx_queue);
2802 if (!skb)
2803 break;
2804
2805 ieee80211_free_txskb(ar->hw, skb);
2806 }
2807}
2808
2809void ath10k_offchan_tx_work(struct work_struct *work)
2810{
2811 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2812 struct ath10k_peer *peer;
2813 struct ieee80211_hdr *hdr;
2814 struct sk_buff *skb;
2815 const u8 *peer_addr;
2816 int vdev_id;
2817 int ret;
2818
2819 /* FW requirement: We must create a peer before FW will send out
2820 * an offchannel frame. Otherwise the frame will be stuck and
2821 * never transmitted. We delete the peer upon tx completion.
2822 * It is unlikely that a peer for offchannel tx will already be
2823 * present. However it may be in some rare cases so account for that.
2824 * Otherwise we might remove a legitimate peer and break stuff. */
2825
2826 for (;;) {
2827 skb = skb_dequeue(&ar->offchan_tx_queue);
2828 if (!skb)
2829 break;
2830
2831 mutex_lock(&ar->conf_mutex);
2832
Michal Kazior7aa7a722014-08-25 12:09:38 +02002833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002834 skb);
2835
2836 hdr = (struct ieee80211_hdr *)skb->data;
2837 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002838 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002839
2840 spin_lock_bh(&ar->data_lock);
2841 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2842 spin_unlock_bh(&ar->data_lock);
2843
2844 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002845 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002846 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002847 peer_addr, vdev_id);
2848
2849 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03002850 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
2851 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002852 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002853 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854 peer_addr, vdev_id, ret);
2855 }
2856
2857 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002858 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859 ar->offchan_tx_skb = skb;
2860 spin_unlock_bh(&ar->data_lock);
2861
Michal Kaziord740d8f2015-03-30 09:51:51 +03002862 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002863
2864 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2865 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002866 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002867 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002868 skb);
2869
2870 if (!peer) {
2871 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2872 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002873 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874 peer_addr, vdev_id, ret);
2875 }
2876
2877 mutex_unlock(&ar->conf_mutex);
2878 }
2879}
2880
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002881void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2882{
2883 struct sk_buff *skb;
2884
2885 for (;;) {
2886 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2887 if (!skb)
2888 break;
2889
2890 ieee80211_free_txskb(ar->hw, skb);
2891 }
2892}
2893
2894void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2895{
2896 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2897 struct sk_buff *skb;
2898 int ret;
2899
2900 for (;;) {
2901 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2902 if (!skb)
2903 break;
2904
2905 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002906 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002907 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002908 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002909 ieee80211_free_txskb(ar->hw, skb);
2910 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002911 }
2912}
2913
Kalle Valo5e3dd152013-06-12 20:52:10 +03002914/************/
2915/* Scanning */
2916/************/
2917
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002918void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002920 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002922 switch (ar->scan.state) {
2923 case ATH10K_SCAN_IDLE:
2924 break;
2925 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002926 if (ar->scan.is_roc)
2927 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002928 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002929 case ATH10K_SCAN_ABORTING:
2930 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002931 ieee80211_scan_completed(ar->hw,
2932 (ar->scan.state ==
2933 ATH10K_SCAN_ABORTING));
2934 /* fall through */
2935 case ATH10K_SCAN_STARTING:
2936 ar->scan.state = ATH10K_SCAN_IDLE;
2937 ar->scan_channel = NULL;
2938 ath10k_offchan_tx_purge(ar);
2939 cancel_delayed_work(&ar->scan.timeout);
2940 complete_all(&ar->scan.completed);
2941 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002943}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002944
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002945void ath10k_scan_finish(struct ath10k *ar)
2946{
2947 spin_lock_bh(&ar->data_lock);
2948 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002949 spin_unlock_bh(&ar->data_lock);
2950}
2951
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002952static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002953{
2954 struct wmi_stop_scan_arg arg = {
2955 .req_id = 1, /* FIXME */
2956 .req_type = WMI_SCAN_STOP_ONE,
2957 .u.scan_id = ATH10K_SCAN_ID,
2958 };
2959 int ret;
2960
2961 lockdep_assert_held(&ar->conf_mutex);
2962
Kalle Valo5e3dd152013-06-12 20:52:10 +03002963 ret = ath10k_wmi_stop_scan(ar, &arg);
2964 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002965 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002966 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002967 }
2968
Kalle Valo5e3dd152013-06-12 20:52:10 +03002969 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002970 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002971 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002972 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002973 } else if (ret > 0) {
2974 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002975 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002976
2977out:
2978 /* Scan state should be updated upon scan completion but in case
2979 * firmware fails to deliver the event (for whatever reason) it is
2980 * desired to clean up scan state anyway. Firmware may have just
2981 * dropped the scan completion event delivery due to transport pipe
2982 * being overflown with data and/or it can recover on its own before
2983 * next scan request is submitted.
2984 */
2985 spin_lock_bh(&ar->data_lock);
2986 if (ar->scan.state != ATH10K_SCAN_IDLE)
2987 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002988 spin_unlock_bh(&ar->data_lock);
2989
2990 return ret;
2991}
2992
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002993static void ath10k_scan_abort(struct ath10k *ar)
2994{
2995 int ret;
2996
2997 lockdep_assert_held(&ar->conf_mutex);
2998
2999 spin_lock_bh(&ar->data_lock);
3000
3001 switch (ar->scan.state) {
3002 case ATH10K_SCAN_IDLE:
3003 /* This can happen if timeout worker kicked in and called
3004 * abortion while scan completion was being processed.
3005 */
3006 break;
3007 case ATH10K_SCAN_STARTING:
3008 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003009 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003010 ath10k_scan_state_str(ar->scan.state),
3011 ar->scan.state);
3012 break;
3013 case ATH10K_SCAN_RUNNING:
3014 ar->scan.state = ATH10K_SCAN_ABORTING;
3015 spin_unlock_bh(&ar->data_lock);
3016
3017 ret = ath10k_scan_stop(ar);
3018 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003019 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003020
3021 spin_lock_bh(&ar->data_lock);
3022 break;
3023 }
3024
3025 spin_unlock_bh(&ar->data_lock);
3026}
3027
3028void ath10k_scan_timeout_work(struct work_struct *work)
3029{
3030 struct ath10k *ar = container_of(work, struct ath10k,
3031 scan.timeout.work);
3032
3033 mutex_lock(&ar->conf_mutex);
3034 ath10k_scan_abort(ar);
3035 mutex_unlock(&ar->conf_mutex);
3036}
3037
Kalle Valo5e3dd152013-06-12 20:52:10 +03003038static int ath10k_start_scan(struct ath10k *ar,
3039 const struct wmi_start_scan_arg *arg)
3040{
3041 int ret;
3042
3043 lockdep_assert_held(&ar->conf_mutex);
3044
3045 ret = ath10k_wmi_start_scan(ar, arg);
3046 if (ret)
3047 return ret;
3048
Kalle Valo5e3dd152013-06-12 20:52:10 +03003049 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3050 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003051 ret = ath10k_scan_stop(ar);
3052 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003053 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003054
3055 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003056 }
3057
Ben Greear2f9eec02015-02-15 16:50:38 +02003058 /* If we failed to start the scan, return error code at
3059 * this point. This is probably due to some issue in the
3060 * firmware, but no need to wedge the driver due to that...
3061 */
3062 spin_lock_bh(&ar->data_lock);
3063 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3064 spin_unlock_bh(&ar->data_lock);
3065 return -EINVAL;
3066 }
3067 spin_unlock_bh(&ar->data_lock);
3068
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003069 /* Add a 200ms margin to account for event/command processing */
3070 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3071 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003072 return 0;
3073}
3074
3075/**********************/
3076/* mac80211 callbacks */
3077/**********************/
3078
3079static void ath10k_tx(struct ieee80211_hw *hw,
3080 struct ieee80211_tx_control *control,
3081 struct sk_buff *skb)
3082{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003083 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003084 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3085 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003086 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003087 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003088 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089
3090 /* We should disable CCK RATE due to P2P */
3091 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003092 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003093
Michal Kazior4b604552014-07-21 21:03:09 +03003094 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003095 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003096 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003097 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003098 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003099 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003100
Michal Kaziord740d8f2015-03-30 09:51:51 +03003101 switch (ATH10K_SKB_CB(skb)->txmode) {
3102 case ATH10K_HW_TXRX_MGMT:
3103 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003104 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003105 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3106 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003107 break;
3108 case ATH10K_HW_TXRX_ETHERNET:
3109 ath10k_tx_h_8023(skb);
3110 break;
3111 case ATH10K_HW_TXRX_RAW:
3112 /* FIXME: Packet injection isn't implemented. It should be
3113 * doable with firmware 10.2 on qca988x.
3114 */
3115 WARN_ON_ONCE(1);
3116 ieee80211_free_txskb(hw, skb);
3117 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003118 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003119
Kalle Valo5e3dd152013-06-12 20:52:10 +03003120 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3121 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003122 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003123 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003124 spin_unlock_bh(&ar->data_lock);
3125
Michal Kazior8d6d3622014-11-24 14:58:31 +01003126 if (ath10k_mac_need_offchan_tx_work(ar)) {
3127 ATH10K_SKB_CB(skb)->htt.freq = 0;
3128 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129
Michal Kazior8d6d3622014-11-24 14:58:31 +01003130 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3131 skb);
3132
3133 skb_queue_tail(&ar->offchan_tx_queue, skb);
3134 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3135 return;
3136 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003137 }
3138
Michal Kaziord740d8f2015-03-30 09:51:51 +03003139 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003140}
3141
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003142/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003143void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003144{
3145 /* make sure rcu-protected mac80211 tx path itself is drained */
3146 synchronize_net();
3147
3148 ath10k_offchan_tx_purge(ar);
3149 ath10k_mgmt_over_wmi_tx_purge(ar);
3150
3151 cancel_work_sync(&ar->offchan_tx_work);
3152 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3153}
3154
Michal Kazioraffd3212013-07-16 09:54:35 +02003155void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003156{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003157 struct ath10k_vif *arvif;
3158
Michal Kazior818bdd12013-07-16 09:38:57 +02003159 lockdep_assert_held(&ar->conf_mutex);
3160
Michal Kazior19337472014-08-28 12:58:16 +02003161 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3162 ar->filter_flags = 0;
3163 ar->monitor = false;
3164
3165 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003166 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003167
3168 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003169
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003170 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003171 ath10k_peer_cleanup_all(ar);
3172 ath10k_core_stop(ar);
3173 ath10k_hif_power_down(ar);
3174
3175 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003176 list_for_each_entry(arvif, &ar->arvifs, list)
3177 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003178 spin_unlock_bh(&ar->data_lock);
3179}
3180
Ben Greear46acf7b2014-05-16 17:15:38 +03003181static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3182{
3183 struct ath10k *ar = hw->priv;
3184
3185 mutex_lock(&ar->conf_mutex);
3186
3187 if (ar->cfg_tx_chainmask) {
3188 *tx_ant = ar->cfg_tx_chainmask;
3189 *rx_ant = ar->cfg_rx_chainmask;
3190 } else {
3191 *tx_ant = ar->supp_tx_chainmask;
3192 *rx_ant = ar->supp_rx_chainmask;
3193 }
3194
3195 mutex_unlock(&ar->conf_mutex);
3196
3197 return 0;
3198}
3199
Ben Greear5572a952014-11-24 16:22:10 +02003200static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3201{
3202 /* It is not clear that allowing gaps in chainmask
3203 * is helpful. Probably it will not do what user
3204 * is hoping for, so warn in that case.
3205 */
3206 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3207 return;
3208
3209 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3210 dbg, cm);
3211}
3212
Ben Greear46acf7b2014-05-16 17:15:38 +03003213static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3214{
3215 int ret;
3216
3217 lockdep_assert_held(&ar->conf_mutex);
3218
Ben Greear5572a952014-11-24 16:22:10 +02003219 ath10k_check_chain_mask(ar, tx_ant, "tx");
3220 ath10k_check_chain_mask(ar, rx_ant, "rx");
3221
Ben Greear46acf7b2014-05-16 17:15:38 +03003222 ar->cfg_tx_chainmask = tx_ant;
3223 ar->cfg_rx_chainmask = rx_ant;
3224
3225 if ((ar->state != ATH10K_STATE_ON) &&
3226 (ar->state != ATH10K_STATE_RESTARTED))
3227 return 0;
3228
3229 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3230 tx_ant);
3231 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003232 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003233 ret, tx_ant);
3234 return ret;
3235 }
3236
3237 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3238 rx_ant);
3239 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003240 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003241 ret, rx_ant);
3242 return ret;
3243 }
3244
3245 return 0;
3246}
3247
3248static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3249{
3250 struct ath10k *ar = hw->priv;
3251 int ret;
3252
3253 mutex_lock(&ar->conf_mutex);
3254 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3255 mutex_unlock(&ar->conf_mutex);
3256 return ret;
3257}
3258
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259static int ath10k_start(struct ieee80211_hw *hw)
3260{
3261 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003262 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003264 /*
3265 * This makes sense only when restarting hw. It is harmless to call
3266 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3267 * commands will be submitted while restarting.
3268 */
3269 ath10k_drain_tx(ar);
3270
Michal Kazior548db542013-07-05 16:15:15 +03003271 mutex_lock(&ar->conf_mutex);
3272
Michal Kaziorc5058f52014-05-26 12:46:03 +03003273 switch (ar->state) {
3274 case ATH10K_STATE_OFF:
3275 ar->state = ATH10K_STATE_ON;
3276 break;
3277 case ATH10K_STATE_RESTARTING:
3278 ath10k_halt(ar);
3279 ar->state = ATH10K_STATE_RESTARTED;
3280 break;
3281 case ATH10K_STATE_ON:
3282 case ATH10K_STATE_RESTARTED:
3283 case ATH10K_STATE_WEDGED:
3284 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003285 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003286 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003287 case ATH10K_STATE_UTF:
3288 ret = -EBUSY;
3289 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003290 }
3291
3292 ret = ath10k_hif_power_up(ar);
3293 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003294 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003295 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003296 }
3297
Kalle Valo43d2a302014-09-10 18:23:30 +03003298 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003299 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003300 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003301 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003302 }
3303
Bartosz Markowski226a3392013-09-26 17:47:16 +02003304 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003305 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003306 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003307 goto err_core_stop;
3308 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003310 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003311 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003312 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003313 goto err_core_stop;
3314 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315
Ben Greear46acf7b2014-05-16 17:15:38 +03003316 if (ar->cfg_tx_chainmask)
3317 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3318 ar->cfg_rx_chainmask);
3319
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003320 /*
3321 * By default FW set ARP frames ac to voice (6). In that case ARP
3322 * exchange is not working properly for UAPSD enabled AP. ARP requests
3323 * which arrives with access category 0 are processed by network stack
3324 * and send back with access category 0, but FW changes access category
3325 * to 6. Set ARP frames access category to best effort (0) solves
3326 * this problem.
3327 */
3328
3329 ret = ath10k_wmi_pdev_set_param(ar,
3330 ar->wmi.pdev_param->arp_ac_override, 0);
3331 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003332 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003333 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003334 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003335 }
3336
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303337 ret = ath10k_wmi_pdev_set_param(ar,
3338 ar->wmi.pdev_param->ani_enable, 1);
3339 if (ret) {
3340 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3341 ret);
3342 goto err_core_stop;
3343 }
3344
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303345 ar->ani_enabled = true;
3346
Michal Kaziord6500972014-04-08 09:56:09 +03003347 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003348 ath10k_regd_update(ar);
3349
Simon Wunderlich855aed12014-08-02 09:12:54 +03003350 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303351 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003352
Michal Kaziorae254432014-05-26 12:46:02 +03003353 mutex_unlock(&ar->conf_mutex);
3354 return 0;
3355
3356err_core_stop:
3357 ath10k_core_stop(ar);
3358
3359err_power_down:
3360 ath10k_hif_power_down(ar);
3361
3362err_off:
3363 ar->state = ATH10K_STATE_OFF;
3364
3365err:
Michal Kazior548db542013-07-05 16:15:15 +03003366 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003367 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003368}
3369
3370static void ath10k_stop(struct ieee80211_hw *hw)
3371{
3372 struct ath10k *ar = hw->priv;
3373
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003374 ath10k_drain_tx(ar);
3375
Michal Kazior548db542013-07-05 16:15:15 +03003376 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003377 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003378 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003379 ar->state = ATH10K_STATE_OFF;
3380 }
Michal Kazior548db542013-07-05 16:15:15 +03003381 mutex_unlock(&ar->conf_mutex);
3382
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003383 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003384 cancel_work_sync(&ar->restart_work);
3385}
3386
Michal Kaziorad088bf2013-10-16 15:44:46 +03003387static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003388{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003389 struct ath10k_vif *arvif;
3390 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003391
3392 lockdep_assert_held(&ar->conf_mutex);
3393
Michal Kaziorad088bf2013-10-16 15:44:46 +03003394 list_for_each_entry(arvif, &ar->arvifs, list) {
3395 ret = ath10k_mac_vif_setup_ps(arvif);
3396 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003397 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003398 break;
3399 }
3400 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003401
Michal Kaziorad088bf2013-10-16 15:44:46 +03003402 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403}
3404
Michal Kaziorc930f742014-01-23 11:38:25 +01003405static const char *chandef_get_width(enum nl80211_chan_width width)
3406{
3407 switch (width) {
3408 case NL80211_CHAN_WIDTH_20_NOHT:
3409 return "20 (noht)";
3410 case NL80211_CHAN_WIDTH_20:
3411 return "20";
3412 case NL80211_CHAN_WIDTH_40:
3413 return "40";
3414 case NL80211_CHAN_WIDTH_80:
3415 return "80";
3416 case NL80211_CHAN_WIDTH_80P80:
3417 return "80+80";
3418 case NL80211_CHAN_WIDTH_160:
3419 return "160";
3420 case NL80211_CHAN_WIDTH_5:
3421 return "5";
3422 case NL80211_CHAN_WIDTH_10:
3423 return "10";
3424 }
3425 return "?";
3426}
3427
3428static void ath10k_config_chan(struct ath10k *ar)
3429{
3430 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003431 int ret;
3432
3433 lockdep_assert_held(&ar->conf_mutex);
3434
Michal Kazior7aa7a722014-08-25 12:09:38 +02003435 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003436 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3437 ar->chandef.chan->center_freq,
3438 ar->chandef.center_freq1,
3439 ar->chandef.center_freq2,
3440 chandef_get_width(ar->chandef.width));
3441
3442 /* First stop monitor interface. Some FW versions crash if there's a
3443 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003444 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003445 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003446
3447 list_for_each_entry(arvif, &ar->arvifs, list) {
3448 if (!arvif->is_started)
3449 continue;
3450
Michal Kaziordc55e302014-07-29 12:53:36 +03003451 if (!arvif->is_up)
3452 continue;
3453
Michal Kaziorc930f742014-01-23 11:38:25 +01003454 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3455 continue;
3456
Michal Kaziordc55e302014-07-29 12:53:36 +03003457 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003458 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003459 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003460 arvif->vdev_id, ret);
3461 continue;
3462 }
3463 }
3464
Michal Kaziordc55e302014-07-29 12:53:36 +03003465 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003466
3467 list_for_each_entry(arvif, &ar->arvifs, list) {
3468 if (!arvif->is_started)
3469 continue;
3470
3471 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3472 continue;
3473
Michal Kazior81a9a172015-03-05 16:02:17 +02003474 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3475 if (ret)
3476 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3477 ret);
3478
3479 ret = ath10k_mac_setup_prb_tmpl(arvif);
3480 if (ret)
3481 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3482 ret);
3483
Michal Kaziordc55e302014-07-29 12:53:36 +03003484 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003485 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003486 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003487 arvif->vdev_id, ret);
3488 continue;
3489 }
3490
3491 if (!arvif->is_up)
3492 continue;
3493
3494 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3495 arvif->bssid);
3496 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003497 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003498 arvif->vdev_id, ret);
3499 continue;
3500 }
3501 }
3502
Michal Kazior19337472014-08-28 12:58:16 +02003503 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003504}
3505
Michal Kazior7d9d5582014-10-21 10:40:15 +03003506static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3507{
3508 int ret;
3509 u32 param;
3510
3511 lockdep_assert_held(&ar->conf_mutex);
3512
3513 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3514
3515 param = ar->wmi.pdev_param->txpower_limit2g;
3516 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3517 if (ret) {
3518 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3519 txpower, ret);
3520 return ret;
3521 }
3522
3523 param = ar->wmi.pdev_param->txpower_limit5g;
3524 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3525 if (ret) {
3526 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3527 txpower, ret);
3528 return ret;
3529 }
3530
3531 return 0;
3532}
3533
3534static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3535{
3536 struct ath10k_vif *arvif;
3537 int ret, txpower = -1;
3538
3539 lockdep_assert_held(&ar->conf_mutex);
3540
3541 list_for_each_entry(arvif, &ar->arvifs, list) {
3542 WARN_ON(arvif->txpower < 0);
3543
3544 if (txpower == -1)
3545 txpower = arvif->txpower;
3546 else
3547 txpower = min(txpower, arvif->txpower);
3548 }
3549
3550 if (WARN_ON(txpower == -1))
3551 return -EINVAL;
3552
3553 ret = ath10k_mac_txpower_setup(ar, txpower);
3554 if (ret) {
3555 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3556 txpower, ret);
3557 return ret;
3558 }
3559
3560 return 0;
3561}
3562
Kalle Valo5e3dd152013-06-12 20:52:10 +03003563static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3564{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003565 struct ath10k *ar = hw->priv;
3566 struct ieee80211_conf *conf = &hw->conf;
3567 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568
3569 mutex_lock(&ar->conf_mutex);
3570
3571 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003572 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003573 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003574 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003575 conf->chandef.chan->flags,
3576 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003577
Kalle Valo5e3dd152013-06-12 20:52:10 +03003578 spin_lock_bh(&ar->data_lock);
3579 ar->rx_channel = conf->chandef.chan;
3580 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003581
Michal Kaziord6500972014-04-08 09:56:09 +03003582 ar->radar_enabled = conf->radar_enabled;
3583 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003584
3585 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3586 ar->chandef = conf->chandef;
3587 ath10k_config_chan(ar);
3588 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589 }
3590
Michal Kazioraffd3212013-07-16 09:54:35 +02003591 if (changed & IEEE80211_CONF_CHANGE_PS)
3592 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003593
3594 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003595 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3596 ret = ath10k_monitor_recalc(ar);
3597 if (ret)
3598 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003599 }
3600
3601 mutex_unlock(&ar->conf_mutex);
3602 return ret;
3603}
3604
Ben Greear5572a952014-11-24 16:22:10 +02003605static u32 get_nss_from_chainmask(u16 chain_mask)
3606{
3607 if ((chain_mask & 0x15) == 0x15)
3608 return 4;
3609 else if ((chain_mask & 0x7) == 0x7)
3610 return 3;
3611 else if ((chain_mask & 0x3) == 0x3)
3612 return 2;
3613 return 1;
3614}
3615
Kalle Valo5e3dd152013-06-12 20:52:10 +03003616/*
3617 * TODO:
3618 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3619 * because we will send mgmt frames without CCK. This requirement
3620 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3621 * in the TX packet.
3622 */
3623static int ath10k_add_interface(struct ieee80211_hw *hw,
3624 struct ieee80211_vif *vif)
3625{
3626 struct ath10k *ar = hw->priv;
3627 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3628 enum wmi_sta_powersave_param param;
3629 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003630 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003631 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003632 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003633
Johannes Berg848955c2014-11-11 12:48:42 +01003634 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3635
Kalle Valo5e3dd152013-06-12 20:52:10 +03003636 mutex_lock(&ar->conf_mutex);
3637
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003638 memset(arvif, 0, sizeof(*arvif));
3639
Kalle Valo5e3dd152013-06-12 20:52:10 +03003640 arvif->ar = ar;
3641 arvif->vif = vif;
3642
Ben Greeare63b33f2013-10-22 14:54:14 -07003643 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003644 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003645 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3646 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003647
Ben Greeara9aefb32014-08-12 11:02:19 +03003648 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003649 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003651 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003652 }
Ben Greear16c11172014-09-23 14:17:16 -07003653 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003654
Ben Greear16c11172014-09-23 14:17:16 -07003655 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3656 bit, ar->free_vdev_map);
3657
3658 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003660
Kalle Valo5e3dd152013-06-12 20:52:10 +03003661 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003662 case NL80211_IFTYPE_P2P_DEVICE:
3663 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3664 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3665 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003666 case NL80211_IFTYPE_UNSPECIFIED:
3667 case NL80211_IFTYPE_STATION:
3668 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3669 if (vif->p2p)
3670 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3671 break;
3672 case NL80211_IFTYPE_ADHOC:
3673 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3674 break;
3675 case NL80211_IFTYPE_AP:
3676 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3677
3678 if (vif->p2p)
3679 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3680 break;
3681 case NL80211_IFTYPE_MONITOR:
3682 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3683 break;
3684 default:
3685 WARN_ON(1);
3686 break;
3687 }
3688
Michal Kazior64badcb2014-09-18 11:18:02 +03003689 /* Some firmware revisions don't wait for beacon tx completion before
3690 * sending another SWBA event. This could lead to hardware using old
3691 * (freed) beacon data in some cases, e.g. tx credit starvation
3692 * combined with missed TBTT. This is very very rare.
3693 *
3694 * On non-IOMMU-enabled hosts this could be a possible security issue
3695 * because hw could beacon some random data on the air. On
3696 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3697 * device would crash.
3698 *
3699 * Since there are no beacon tx completions (implicit nor explicit)
3700 * propagated to host the only workaround for this is to allocate a
3701 * DMA-coherent buffer for a lifetime of a vif and use it for all
3702 * beacon tx commands. Worst case for this approach is some beacons may
3703 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3704 */
3705 if (vif->type == NL80211_IFTYPE_ADHOC ||
3706 vif->type == NL80211_IFTYPE_AP) {
3707 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3708 IEEE80211_MAX_FRAME_LEN,
3709 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303710 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003711 if (!arvif->beacon_buf) {
3712 ret = -ENOMEM;
3713 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3714 ret);
3715 goto err;
3716 }
3717 }
3718
3719 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3720 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3721 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722
3723 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3724 arvif->vdev_subtype, vif->addr);
3725 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003726 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003727 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003728 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003729 }
3730
Ben Greear16c11172014-09-23 14:17:16 -07003731 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003732 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003733
Michal Kazior46725b152015-01-28 09:57:49 +02003734 /* It makes no sense to have firmware do keepalives. mac80211 already
3735 * takes care of this with idle connection polling.
3736 */
3737 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003738 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003739 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003740 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003741 goto err_vdev_delete;
3742 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003743
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003744 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003745
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003746 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3747 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003749 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003750 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003751 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003752 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003753 goto err_vdev_delete;
3754 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003755
Ben Greear5572a952014-11-24 16:22:10 +02003756 if (ar->cfg_tx_chainmask) {
3757 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3758
3759 vdev_param = ar->wmi.vdev_param->nss;
3760 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3761 nss);
3762 if (ret) {
3763 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3764 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3765 ret);
3766 goto err_vdev_delete;
3767 }
3768 }
3769
Kalle Valo5e3dd152013-06-12 20:52:10 +03003770 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003771 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
3772 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003774 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003775 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003776 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003777 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003778
Kalle Valo5a13e762014-01-20 11:01:46 +02003779 ret = ath10k_mac_set_kickout(arvif);
3780 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003781 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003782 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003783 goto err_peer_delete;
3784 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003785 }
3786
3787 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3788 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3789 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3790 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3791 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003792 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003793 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003794 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003795 goto err_peer_delete;
3796 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003797
Michal Kazior9f9b5742014-12-12 12:41:36 +01003798 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003799 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003800 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003801 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003802 goto err_peer_delete;
3803 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003804
Michal Kazior9f9b5742014-12-12 12:41:36 +01003805 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003806 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003807 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003808 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003809 goto err_peer_delete;
3810 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003811 }
3812
Michal Kazior424121c2013-07-22 14:13:31 +02003813 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003814 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003815 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003816 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003817 goto err_peer_delete;
3818 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003819
Michal Kazior424121c2013-07-22 14:13:31 +02003820 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003821 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003822 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003823 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003824 goto err_peer_delete;
3825 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003826
Michal Kazior7d9d5582014-10-21 10:40:15 +03003827 arvif->txpower = vif->bss_conf.txpower;
3828 ret = ath10k_mac_txpower_recalc(ar);
3829 if (ret) {
3830 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3831 goto err_peer_delete;
3832 }
3833
Kalle Valo5e3dd152013-06-12 20:52:10 +03003834 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003835 return 0;
3836
3837err_peer_delete:
3838 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3839 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3840
3841err_vdev_delete:
3842 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003843 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003844 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003845
3846err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003847 if (arvif->beacon_buf) {
3848 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3849 arvif->beacon_buf, arvif->beacon_paddr);
3850 arvif->beacon_buf = NULL;
3851 }
3852
Michal Kazior9dad14a2013-10-16 15:44:45 +03003853 mutex_unlock(&ar->conf_mutex);
3854
Kalle Valo5e3dd152013-06-12 20:52:10 +03003855 return ret;
3856}
3857
3858static void ath10k_remove_interface(struct ieee80211_hw *hw,
3859 struct ieee80211_vif *vif)
3860{
3861 struct ath10k *ar = hw->priv;
3862 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3863 int ret;
3864
Michal Kazior81a9a172015-03-05 16:02:17 +02003865 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003866 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003867
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303868 mutex_lock(&ar->conf_mutex);
3869
Michal Kaziored543882013-09-13 14:16:56 +02003870 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003871 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003872 spin_unlock_bh(&ar->data_lock);
3873
Simon Wunderlich855aed12014-08-02 09:12:54 +03003874 ret = ath10k_spectral_vif_stop(arvif);
3875 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003876 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003877 arvif->vdev_id, ret);
3878
Ben Greear16c11172014-09-23 14:17:16 -07003879 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003880 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003881
3882 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003883 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3884 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003885 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003886 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003887 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888
3889 kfree(arvif->u.ap.noa_data);
3890 }
3891
Michal Kazior7aa7a722014-08-25 12:09:38 +02003892 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003893 arvif->vdev_id);
3894
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3896 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003897 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003898 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003899
Michal Kazior2c512052015-02-15 16:50:40 +02003900 /* Some firmware revisions don't notify host about self-peer removal
3901 * until after associated vdev is deleted.
3902 */
3903 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3904 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3905 vif->addr);
3906 if (ret)
3907 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3908 arvif->vdev_id, ret);
3909
3910 spin_lock_bh(&ar->data_lock);
3911 ar->num_peers--;
3912 spin_unlock_bh(&ar->data_lock);
3913 }
3914
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915 ath10k_peer_cleanup(ar, arvif->vdev_id);
3916
3917 mutex_unlock(&ar->conf_mutex);
3918}
3919
3920/*
3921 * FIXME: Has to be verified.
3922 */
3923#define SUPPORTED_FILTERS \
3924 (FIF_PROMISC_IN_BSS | \
3925 FIF_ALLMULTI | \
3926 FIF_CONTROL | \
3927 FIF_PSPOLL | \
3928 FIF_OTHER_BSS | \
3929 FIF_BCN_PRBRESP_PROMISC | \
3930 FIF_PROBE_REQ | \
3931 FIF_FCSFAIL)
3932
3933static void ath10k_configure_filter(struct ieee80211_hw *hw,
3934 unsigned int changed_flags,
3935 unsigned int *total_flags,
3936 u64 multicast)
3937{
3938 struct ath10k *ar = hw->priv;
3939 int ret;
3940
3941 mutex_lock(&ar->conf_mutex);
3942
3943 changed_flags &= SUPPORTED_FILTERS;
3944 *total_flags &= SUPPORTED_FILTERS;
3945 ar->filter_flags = *total_flags;
3946
Michal Kazior19337472014-08-28 12:58:16 +02003947 ret = ath10k_monitor_recalc(ar);
3948 if (ret)
3949 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003950
3951 mutex_unlock(&ar->conf_mutex);
3952}
3953
3954static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3955 struct ieee80211_vif *vif,
3956 struct ieee80211_bss_conf *info,
3957 u32 changed)
3958{
3959 struct ath10k *ar = hw->priv;
3960 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3961 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003962 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963
3964 mutex_lock(&ar->conf_mutex);
3965
3966 if (changed & BSS_CHANGED_IBSS)
3967 ath10k_control_ibss(arvif, info, vif->addr);
3968
3969 if (changed & BSS_CHANGED_BEACON_INT) {
3970 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003971 vdev_param = ar->wmi.vdev_param->beacon_interval;
3972 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003974 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003975 "mac vdev %d beacon_interval %d\n",
3976 arvif->vdev_id, arvif->beacon_interval);
3977
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003979 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003980 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003981 }
3982
3983 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003984 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003985 "vdev %d set beacon tx mode to staggered\n",
3986 arvif->vdev_id);
3987
Bartosz Markowski226a3392013-09-26 17:47:16 +02003988 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3989 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003990 WMI_BEACON_STAGGERED_MODE);
3991 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003992 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003993 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003994
3995 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3996 if (ret)
3997 ath10k_warn(ar, "failed to update beacon template: %d\n",
3998 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 }
4000
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004001 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4002 ret = ath10k_mac_setup_prb_tmpl(arvif);
4003 if (ret)
4004 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4005 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004006 }
4007
Michal Kaziorba2479f2015-01-24 12:14:51 +02004008 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004009 arvif->dtim_period = info->dtim_period;
4010
Michal Kazior7aa7a722014-08-25 12:09:38 +02004011 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004012 "mac vdev %d dtim_period %d\n",
4013 arvif->vdev_id, arvif->dtim_period);
4014
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004015 vdev_param = ar->wmi.vdev_param->dtim_period;
4016 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017 arvif->dtim_period);
4018 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004019 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004020 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021 }
4022
4023 if (changed & BSS_CHANGED_SSID &&
4024 vif->type == NL80211_IFTYPE_AP) {
4025 arvif->u.ap.ssid_len = info->ssid_len;
4026 if (info->ssid_len)
4027 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4028 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4029 }
4030
Michal Kazior077efc82014-10-21 10:10:29 +03004031 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4032 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004033
4034 if (changed & BSS_CHANGED_BEACON_ENABLED)
4035 ath10k_control_beaconing(arvif, info);
4036
4037 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004038 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004039 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004040 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004041
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004042 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004043 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004044 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004045 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004046
4047 vdev_param = ar->wmi.vdev_param->protection_mode;
4048 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4049 info->use_cts_prot ? 1 : 0);
4050 if (ret)
4051 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4052 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004053 }
4054
4055 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004056 if (info->use_short_slot)
4057 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4058
4059 else
4060 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4061
Michal Kazior7aa7a722014-08-25 12:09:38 +02004062 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004063 arvif->vdev_id, slottime);
4064
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004065 vdev_param = ar->wmi.vdev_param->slot_time;
4066 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 slottime);
4068 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004069 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004070 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004071 }
4072
4073 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004074 if (info->use_short_preamble)
4075 preamble = WMI_VDEV_PREAMBLE_SHORT;
4076 else
4077 preamble = WMI_VDEV_PREAMBLE_LONG;
4078
Michal Kazior7aa7a722014-08-25 12:09:38 +02004079 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004080 "mac vdev %d preamble %dn",
4081 arvif->vdev_id, preamble);
4082
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004083 vdev_param = ar->wmi.vdev_param->preamble;
4084 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004085 preamble);
4086 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004087 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004088 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004089 }
4090
4091 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004092 if (info->assoc) {
4093 /* Workaround: Make sure monitor vdev is not running
4094 * when associating to prevent some firmware revisions
4095 * (e.g. 10.1 and 10.2) from crashing.
4096 */
4097 if (ar->monitor_started)
4098 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004099 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004100 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004101 } else {
4102 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004103 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004104 }
4105
Michal Kazior7d9d5582014-10-21 10:40:15 +03004106 if (changed & BSS_CHANGED_TXPOWER) {
4107 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4108 arvif->vdev_id, info->txpower);
4109
4110 arvif->txpower = info->txpower;
4111 ret = ath10k_mac_txpower_recalc(ar);
4112 if (ret)
4113 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4114 }
4115
Michal Kaziorbf14e652014-12-12 12:41:38 +01004116 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004117 arvif->ps = vif->bss_conf.ps;
4118
4119 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004120 if (ret)
4121 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4122 arvif->vdev_id, ret);
4123 }
4124
Kalle Valo5e3dd152013-06-12 20:52:10 +03004125 mutex_unlock(&ar->conf_mutex);
4126}
4127
4128static int ath10k_hw_scan(struct ieee80211_hw *hw,
4129 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004130 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004131{
4132 struct ath10k *ar = hw->priv;
4133 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004134 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004135 struct wmi_start_scan_arg arg;
4136 int ret = 0;
4137 int i;
4138
4139 mutex_lock(&ar->conf_mutex);
4140
4141 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004142 switch (ar->scan.state) {
4143 case ATH10K_SCAN_IDLE:
4144 reinit_completion(&ar->scan.started);
4145 reinit_completion(&ar->scan.completed);
4146 ar->scan.state = ATH10K_SCAN_STARTING;
4147 ar->scan.is_roc = false;
4148 ar->scan.vdev_id = arvif->vdev_id;
4149 ret = 0;
4150 break;
4151 case ATH10K_SCAN_STARTING:
4152 case ATH10K_SCAN_RUNNING:
4153 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004154 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004155 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004156 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004157 spin_unlock_bh(&ar->data_lock);
4158
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004159 if (ret)
4160 goto exit;
4161
Kalle Valo5e3dd152013-06-12 20:52:10 +03004162 memset(&arg, 0, sizeof(arg));
4163 ath10k_wmi_start_scan_init(ar, &arg);
4164 arg.vdev_id = arvif->vdev_id;
4165 arg.scan_id = ATH10K_SCAN_ID;
4166
4167 if (!req->no_cck)
4168 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4169
4170 if (req->ie_len) {
4171 arg.ie_len = req->ie_len;
4172 memcpy(arg.ie, req->ie, arg.ie_len);
4173 }
4174
4175 if (req->n_ssids) {
4176 arg.n_ssids = req->n_ssids;
4177 for (i = 0; i < arg.n_ssids; i++) {
4178 arg.ssids[i].len = req->ssids[i].ssid_len;
4179 arg.ssids[i].ssid = req->ssids[i].ssid;
4180 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004181 } else {
4182 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004183 }
4184
4185 if (req->n_channels) {
4186 arg.n_channels = req->n_channels;
4187 for (i = 0; i < arg.n_channels; i++)
4188 arg.channels[i] = req->channels[i]->center_freq;
4189 }
4190
4191 ret = ath10k_start_scan(ar, &arg);
4192 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004193 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004194 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004195 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004196 spin_unlock_bh(&ar->data_lock);
4197 }
4198
4199exit:
4200 mutex_unlock(&ar->conf_mutex);
4201 return ret;
4202}
4203
4204static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4205 struct ieee80211_vif *vif)
4206{
4207 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004208
4209 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004210 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004211 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004212
4213 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004214}
4215
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004216static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4217 struct ath10k_vif *arvif,
4218 enum set_key_cmd cmd,
4219 struct ieee80211_key_conf *key)
4220{
4221 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4222 int ret;
4223
4224 /* 10.1 firmware branch requires default key index to be set to group
4225 * key index after installing it. Otherwise FW/HW Txes corrupted
4226 * frames with multi-vif APs. This is not required for main firmware
4227 * branch (e.g. 636).
4228 *
4229 * FIXME: This has been tested only in AP. It remains unknown if this
4230 * is required for multi-vif STA interfaces on 10.1 */
4231
4232 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4233 return;
4234
4235 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4236 return;
4237
4238 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4239 return;
4240
4241 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4242 return;
4243
4244 if (cmd != SET_KEY)
4245 return;
4246
4247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4248 key->keyidx);
4249 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004250 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004251 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004252}
4253
Kalle Valo5e3dd152013-06-12 20:52:10 +03004254static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4255 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4256 struct ieee80211_key_conf *key)
4257{
4258 struct ath10k *ar = hw->priv;
4259 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4260 struct ath10k_peer *peer;
4261 const u8 *peer_addr;
4262 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4263 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4264 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004265 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004267 /* this one needs to be done in software */
4268 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4269 return 1;
4270
Kalle Valo5e3dd152013-06-12 20:52:10 +03004271 if (key->keyidx > WMI_MAX_KEY_INDEX)
4272 return -ENOSPC;
4273
4274 mutex_lock(&ar->conf_mutex);
4275
4276 if (sta)
4277 peer_addr = sta->addr;
4278 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4279 peer_addr = vif->bss_conf.bssid;
4280 else
4281 peer_addr = vif->addr;
4282
4283 key->hw_key_idx = key->keyidx;
4284
4285 /* the peer should not disappear in mid-way (unless FW goes awry) since
4286 * we already hold conf_mutex. we just make sure its there now. */
4287 spin_lock_bh(&ar->data_lock);
4288 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4289 spin_unlock_bh(&ar->data_lock);
4290
4291 if (!peer) {
4292 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004293 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004294 peer_addr);
4295 ret = -EOPNOTSUPP;
4296 goto exit;
4297 } else {
4298 /* if the peer doesn't exist there is no key to disable
4299 * anymore */
4300 goto exit;
4301 }
4302 }
4303
Michal Kazior7cc45732015-03-09 14:24:17 +01004304 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4305 flags |= WMI_KEY_PAIRWISE;
4306 else
4307 flags |= WMI_KEY_GROUP;
4308
Kalle Valo5e3dd152013-06-12 20:52:10 +03004309 if (is_wep) {
4310 if (cmd == SET_KEY)
4311 arvif->wep_keys[key->keyidx] = key;
4312 else
4313 arvif->wep_keys[key->keyidx] = NULL;
4314
4315 if (cmd == DISABLE_KEY)
4316 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004317
Michal Kaziorad325cb2015-02-18 14:02:27 +01004318 /* When WEP keys are uploaded it's possible that there are
4319 * stations associated already (e.g. when merging) without any
4320 * keys. Static WEP needs an explicit per-peer key upload.
4321 */
4322 if (vif->type == NL80211_IFTYPE_ADHOC &&
4323 cmd == SET_KEY)
4324 ath10k_mac_vif_update_wep_key(arvif, key);
4325
Michal Kazior370e5672015-02-18 14:02:26 +01004326 /* 802.1x never sets the def_wep_key_idx so each set_key()
4327 * call changes default tx key.
4328 *
4329 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4330 * after first set_key().
4331 */
4332 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4333 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004334
Michal Kazior7cc45732015-03-09 14:24:17 +01004335 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4336 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4337 * mode and associated stations in AP/IBSS.
4338 *
4339 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4340 * work fine when mapped directly from mac80211.
4341 *
4342 * Note: When installing first static WEP groupwise key (which
4343 * should be pairwise) def_wep_key_idx isn't known yet (it's
4344 * equal to -1). Since .set_default_unicast_key is called only
4345 * for static WEP it's used to re-upload the key as pairwise.
4346 */
4347 if (arvif->def_wep_key_idx >= 0 &&
4348 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4349 flags &= ~WMI_KEY_GROUP;
4350 flags |= WMI_KEY_PAIRWISE;
4351 }
Michal Kazior370e5672015-02-18 14:02:26 +01004352 }
4353
4354 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004355 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004356 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004357 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004358 goto exit;
4359 }
4360
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004361 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4362
Kalle Valo5e3dd152013-06-12 20:52:10 +03004363 spin_lock_bh(&ar->data_lock);
4364 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4365 if (peer && cmd == SET_KEY)
4366 peer->keys[key->keyidx] = key;
4367 else if (peer && cmd == DISABLE_KEY)
4368 peer->keys[key->keyidx] = NULL;
4369 else if (peer == NULL)
4370 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004371 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004372 spin_unlock_bh(&ar->data_lock);
4373
4374exit:
4375 mutex_unlock(&ar->conf_mutex);
4376 return ret;
4377}
4378
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004379static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4380 struct ieee80211_vif *vif,
4381 int keyidx)
4382{
4383 struct ath10k *ar = hw->priv;
4384 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4385 int ret;
4386
4387 mutex_lock(&arvif->ar->conf_mutex);
4388
4389 if (arvif->ar->state != ATH10K_STATE_ON)
4390 goto unlock;
4391
4392 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4393 arvif->vdev_id, keyidx);
4394
4395 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4396 arvif->vdev_id,
4397 arvif->ar->wmi.vdev_param->def_keyid,
4398 keyidx);
4399
4400 if (ret) {
4401 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4402 arvif->vdev_id,
4403 ret);
4404 goto unlock;
4405 }
4406
4407 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004408
4409 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4410 if (ret) {
4411 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4412 arvif->vdev_id, ret);
4413 goto unlock;
4414 }
4415
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004416unlock:
4417 mutex_unlock(&arvif->ar->conf_mutex);
4418}
4419
Michal Kazior9797feb2014-02-14 14:49:48 +01004420static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4421{
4422 struct ath10k *ar;
4423 struct ath10k_vif *arvif;
4424 struct ath10k_sta *arsta;
4425 struct ieee80211_sta *sta;
4426 u32 changed, bw, nss, smps;
4427 int err;
4428
4429 arsta = container_of(wk, struct ath10k_sta, update_wk);
4430 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4431 arvif = arsta->arvif;
4432 ar = arvif->ar;
4433
4434 spin_lock_bh(&ar->data_lock);
4435
4436 changed = arsta->changed;
4437 arsta->changed = 0;
4438
4439 bw = arsta->bw;
4440 nss = arsta->nss;
4441 smps = arsta->smps;
4442
4443 spin_unlock_bh(&ar->data_lock);
4444
4445 mutex_lock(&ar->conf_mutex);
4446
4447 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004448 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004449 sta->addr, bw);
4450
4451 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4452 WMI_PEER_CHAN_WIDTH, bw);
4453 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004454 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004455 sta->addr, bw, err);
4456 }
4457
4458 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004459 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004460 sta->addr, nss);
4461
4462 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4463 WMI_PEER_NSS, nss);
4464 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004465 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004466 sta->addr, nss, err);
4467 }
4468
4469 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004470 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004471 sta->addr, smps);
4472
4473 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4474 WMI_PEER_SMPS_STATE, smps);
4475 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004476 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004477 sta->addr, smps, err);
4478 }
4479
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004480 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4481 changed & IEEE80211_RC_NSS_CHANGED) {
4482 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004483 sta->addr);
4484
Michal Kazior590922a2014-10-21 10:10:29 +03004485 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004486 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004487 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004488 sta->addr);
4489 }
4490
Michal Kazior9797feb2014-02-14 14:49:48 +01004491 mutex_unlock(&ar->conf_mutex);
4492}
4493
Marek Puzyniak7c354242015-03-30 09:51:52 +03004494static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4495 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004496{
4497 struct ath10k *ar = arvif->ar;
4498
4499 lockdep_assert_held(&ar->conf_mutex);
4500
Marek Puzyniak7c354242015-03-30 09:51:52 +03004501 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004502 return 0;
4503
4504 if (ar->num_stations >= ar->max_num_stations)
4505 return -ENOBUFS;
4506
4507 ar->num_stations++;
4508
4509 return 0;
4510}
4511
Marek Puzyniak7c354242015-03-30 09:51:52 +03004512static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4513 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004514{
4515 struct ath10k *ar = arvif->ar;
4516
4517 lockdep_assert_held(&ar->conf_mutex);
4518
Marek Puzyniak7c354242015-03-30 09:51:52 +03004519 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004520 return;
4521
4522 ar->num_stations--;
4523}
4524
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004525struct ath10k_mac_tdls_iter_data {
4526 u32 num_tdls_stations;
4527 struct ieee80211_vif *curr_vif;
4528};
4529
4530static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4531 struct ieee80211_sta *sta)
4532{
4533 struct ath10k_mac_tdls_iter_data *iter_data = data;
4534 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4535 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4536
4537 if (sta->tdls && sta_vif == iter_data->curr_vif)
4538 iter_data->num_tdls_stations++;
4539}
4540
4541static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4542 struct ieee80211_vif *vif)
4543{
4544 struct ath10k_mac_tdls_iter_data data = {};
4545
4546 data.curr_vif = vif;
4547
4548 ieee80211_iterate_stations_atomic(hw,
4549 ath10k_mac_tdls_vif_stations_count_iter,
4550 &data);
4551 return data.num_tdls_stations;
4552}
4553
4554static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4555 struct ieee80211_vif *vif)
4556{
4557 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4558 int *num_tdls_vifs = data;
4559
4560 if (vif->type != NL80211_IFTYPE_STATION)
4561 return;
4562
4563 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4564 (*num_tdls_vifs)++;
4565}
4566
4567static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4568{
4569 int num_tdls_vifs = 0;
4570
4571 ieee80211_iterate_active_interfaces_atomic(hw,
4572 IEEE80211_IFACE_ITER_NORMAL,
4573 ath10k_mac_tdls_vifs_count_iter,
4574 &num_tdls_vifs);
4575 return num_tdls_vifs;
4576}
4577
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578static int ath10k_sta_state(struct ieee80211_hw *hw,
4579 struct ieee80211_vif *vif,
4580 struct ieee80211_sta *sta,
4581 enum ieee80211_sta_state old_state,
4582 enum ieee80211_sta_state new_state)
4583{
4584 struct ath10k *ar = hw->priv;
4585 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004586 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004587 int ret = 0;
4588
Michal Kazior76f90022014-02-25 09:29:57 +02004589 if (old_state == IEEE80211_STA_NOTEXIST &&
4590 new_state == IEEE80211_STA_NONE) {
4591 memset(arsta, 0, sizeof(*arsta));
4592 arsta->arvif = arvif;
4593 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4594 }
4595
Michal Kazior9797feb2014-02-14 14:49:48 +01004596 /* cancel must be done outside the mutex to avoid deadlock */
4597 if ((old_state == IEEE80211_STA_NONE &&
4598 new_state == IEEE80211_STA_NOTEXIST))
4599 cancel_work_sync(&arsta->update_wk);
4600
Kalle Valo5e3dd152013-06-12 20:52:10 +03004601 mutex_lock(&ar->conf_mutex);
4602
4603 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004604 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004605 /*
4606 * New station addition.
4607 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004608 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4609 u32 num_tdls_stations;
4610 u32 num_tdls_vifs;
4611
Michal Kaziorcfd10612014-11-25 15:16:05 +01004612 ath10k_dbg(ar, ATH10K_DBG_MAC,
4613 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4614 arvif->vdev_id, sta->addr,
4615 ar->num_stations + 1, ar->max_num_stations,
4616 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004617
Marek Puzyniak7c354242015-03-30 09:51:52 +03004618 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004619 if (ret) {
4620 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4621 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004622 goto exit;
4623 }
4624
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004625 if (sta->tdls)
4626 peer_type = WMI_PEER_TYPE_TDLS;
4627
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004628 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004629 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004630 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004631 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 -08004632 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004633 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004634 goto exit;
4635 }
Michal Kazior077efc82014-10-21 10:10:29 +03004636
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004637 if (vif->type == NL80211_IFTYPE_STATION &&
4638 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004639 WARN_ON(arvif->is_started);
4640
4641 ret = ath10k_vdev_start(arvif);
4642 if (ret) {
4643 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4644 arvif->vdev_id, ret);
4645 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4646 sta->addr));
Marek Puzyniak7c354242015-03-30 09:51:52 +03004647 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03004648 goto exit;
4649 }
4650
4651 arvif->is_started = true;
4652 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004653
4654 if (!sta->tdls)
4655 goto exit;
4656
4657 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4658 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4659
4660 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4661 num_tdls_stations == 0) {
4662 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4663 arvif->vdev_id, ar->max_num_tdls_vdevs);
4664 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4665 ath10k_mac_dec_num_stations(arvif, sta);
4666 ret = -ENOBUFS;
4667 goto exit;
4668 }
4669
4670 if (num_tdls_stations == 0) {
4671 /* This is the first tdls peer in current vif */
4672 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4673
4674 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4675 state);
4676 if (ret) {
4677 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4678 arvif->vdev_id, ret);
4679 ath10k_peer_delete(ar, arvif->vdev_id,
4680 sta->addr);
4681 ath10k_mac_dec_num_stations(arvif, sta);
4682 goto exit;
4683 }
4684 }
4685
4686 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4687 WMI_TDLS_PEER_STATE_PEERING);
4688 if (ret) {
4689 ath10k_warn(ar,
4690 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4691 sta->addr, arvif->vdev_id, ret);
4692 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4693 ath10k_mac_dec_num_stations(arvif, sta);
4694
4695 if (num_tdls_stations != 0)
4696 goto exit;
4697 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4698 WMI_TDLS_DISABLE);
4699 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004700 } else if ((old_state == IEEE80211_STA_NONE &&
4701 new_state == IEEE80211_STA_NOTEXIST)) {
4702 /*
4703 * Existing station deletion.
4704 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004705 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004706 "mac vdev %d peer delete %pM (sta gone)\n",
4707 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004708
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004709 if (vif->type == NL80211_IFTYPE_STATION &&
4710 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004711 WARN_ON(!arvif->is_started);
4712
4713 ret = ath10k_vdev_stop(arvif);
4714 if (ret)
4715 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4716 arvif->vdev_id, ret);
4717
4718 arvif->is_started = false;
4719 }
4720
Kalle Valo5e3dd152013-06-12 20:52:10 +03004721 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4722 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004723 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004724 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004725
Marek Puzyniak7c354242015-03-30 09:51:52 +03004726 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004727
4728 if (!sta->tdls)
4729 goto exit;
4730
4731 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
4732 goto exit;
4733
4734 /* This was the last tdls peer in current vif */
4735 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4736 WMI_TDLS_DISABLE);
4737 if (ret) {
4738 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4739 arvif->vdev_id, ret);
4740 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004741 } else if (old_state == IEEE80211_STA_AUTH &&
4742 new_state == IEEE80211_STA_ASSOC &&
4743 (vif->type == NL80211_IFTYPE_AP ||
4744 vif->type == NL80211_IFTYPE_ADHOC)) {
4745 /*
4746 * New association.
4747 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004748 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004749 sta->addr);
4750
Michal Kazior590922a2014-10-21 10:10:29 +03004751 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004752 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004753 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004754 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004755 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004756 new_state == IEEE80211_STA_AUTHORIZED &&
4757 sta->tdls) {
4758 /*
4759 * Tdls station authorized.
4760 */
4761 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
4762 sta->addr);
4763
4764 ret = ath10k_station_assoc(ar, vif, sta, false);
4765 if (ret) {
4766 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
4767 sta->addr, arvif->vdev_id, ret);
4768 goto exit;
4769 }
4770
4771 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4772 WMI_TDLS_PEER_STATE_CONNECTED);
4773 if (ret)
4774 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
4775 sta->addr, arvif->vdev_id, ret);
4776 } else if (old_state == IEEE80211_STA_ASSOC &&
4777 new_state == IEEE80211_STA_AUTH &&
4778 (vif->type == NL80211_IFTYPE_AP ||
4779 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004780 /*
4781 * Disassociation.
4782 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004783 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004784 sta->addr);
4785
Michal Kazior590922a2014-10-21 10:10:29 +03004786 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004787 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004788 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004789 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004790 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004791exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792 mutex_unlock(&ar->conf_mutex);
4793 return ret;
4794}
4795
4796static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004797 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004798{
4799 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004800 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4801 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004802 u32 value = 0;
4803 int ret = 0;
4804
Michal Kazior548db542013-07-05 16:15:15 +03004805 lockdep_assert_held(&ar->conf_mutex);
4806
Kalle Valo5e3dd152013-06-12 20:52:10 +03004807 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4808 return 0;
4809
4810 switch (ac) {
4811 case IEEE80211_AC_VO:
4812 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4813 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004814 prio = 7;
4815 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004816 break;
4817 case IEEE80211_AC_VI:
4818 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4819 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004820 prio = 5;
4821 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004822 break;
4823 case IEEE80211_AC_BE:
4824 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4825 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004826 prio = 2;
4827 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004828 break;
4829 case IEEE80211_AC_BK:
4830 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4831 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004832 prio = 0;
4833 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004834 break;
4835 }
4836
4837 if (enable)
4838 arvif->u.sta.uapsd |= value;
4839 else
4840 arvif->u.sta.uapsd &= ~value;
4841
4842 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4843 WMI_STA_PS_PARAM_UAPSD,
4844 arvif->u.sta.uapsd);
4845 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004846 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004847 goto exit;
4848 }
4849
4850 if (arvif->u.sta.uapsd)
4851 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4852 else
4853 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4854
4855 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4856 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4857 value);
4858 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004859 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004860
Michal Kazior9f9b5742014-12-12 12:41:36 +01004861 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4862 if (ret) {
4863 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4864 arvif->vdev_id, ret);
4865 return ret;
4866 }
4867
4868 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4869 if (ret) {
4870 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4871 arvif->vdev_id, ret);
4872 return ret;
4873 }
4874
Michal Kaziorb0e56152015-01-24 12:14:52 +02004875 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4876 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4877 /* Only userspace can make an educated decision when to send
4878 * trigger frame. The following effectively disables u-UAPSD
4879 * autotrigger in firmware (which is enabled by default
4880 * provided the autotrigger service is available).
4881 */
4882
4883 arg.wmm_ac = acc;
4884 arg.user_priority = prio;
4885 arg.service_interval = 0;
4886 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4887 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4888
4889 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4890 arvif->bssid, &arg, 1);
4891 if (ret) {
4892 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4893 ret);
4894 return ret;
4895 }
4896 }
4897
Kalle Valo5e3dd152013-06-12 20:52:10 +03004898exit:
4899 return ret;
4900}
4901
4902static int ath10k_conf_tx(struct ieee80211_hw *hw,
4903 struct ieee80211_vif *vif, u16 ac,
4904 const struct ieee80211_tx_queue_params *params)
4905{
4906 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004907 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004908 struct wmi_wmm_params_arg *p = NULL;
4909 int ret;
4910
4911 mutex_lock(&ar->conf_mutex);
4912
4913 switch (ac) {
4914 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004915 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004916 break;
4917 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004918 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004919 break;
4920 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004921 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004922 break;
4923 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004924 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004925 break;
4926 }
4927
4928 if (WARN_ON(!p)) {
4929 ret = -EINVAL;
4930 goto exit;
4931 }
4932
4933 p->cwmin = params->cw_min;
4934 p->cwmax = params->cw_max;
4935 p->aifs = params->aifs;
4936
4937 /*
4938 * The channel time duration programmed in the HW is in absolute
4939 * microseconds, while mac80211 gives the txop in units of
4940 * 32 microseconds.
4941 */
4942 p->txop = params->txop * 32;
4943
Michal Kazior7fc979a2015-01-28 09:57:28 +02004944 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4945 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4946 &arvif->wmm_params);
4947 if (ret) {
4948 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4949 arvif->vdev_id, ret);
4950 goto exit;
4951 }
4952 } else {
4953 /* This won't work well with multi-interface cases but it's
4954 * better than nothing.
4955 */
4956 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4957 if (ret) {
4958 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4959 goto exit;
4960 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004961 }
4962
4963 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4964 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004965 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004966
4967exit:
4968 mutex_unlock(&ar->conf_mutex);
4969 return ret;
4970}
4971
4972#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4973
4974static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4975 struct ieee80211_vif *vif,
4976 struct ieee80211_channel *chan,
4977 int duration,
4978 enum ieee80211_roc_type type)
4979{
4980 struct ath10k *ar = hw->priv;
4981 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4982 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004983 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004984
4985 mutex_lock(&ar->conf_mutex);
4986
4987 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004988 switch (ar->scan.state) {
4989 case ATH10K_SCAN_IDLE:
4990 reinit_completion(&ar->scan.started);
4991 reinit_completion(&ar->scan.completed);
4992 reinit_completion(&ar->scan.on_channel);
4993 ar->scan.state = ATH10K_SCAN_STARTING;
4994 ar->scan.is_roc = true;
4995 ar->scan.vdev_id = arvif->vdev_id;
4996 ar->scan.roc_freq = chan->center_freq;
4997 ret = 0;
4998 break;
4999 case ATH10K_SCAN_STARTING:
5000 case ATH10K_SCAN_RUNNING:
5001 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005002 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005003 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005004 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005005 spin_unlock_bh(&ar->data_lock);
5006
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005007 if (ret)
5008 goto exit;
5009
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005010 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5011
Kalle Valo5e3dd152013-06-12 20:52:10 +03005012 memset(&arg, 0, sizeof(arg));
5013 ath10k_wmi_start_scan_init(ar, &arg);
5014 arg.vdev_id = arvif->vdev_id;
5015 arg.scan_id = ATH10K_SCAN_ID;
5016 arg.n_channels = 1;
5017 arg.channels[0] = chan->center_freq;
5018 arg.dwell_time_active = duration;
5019 arg.dwell_time_passive = duration;
5020 arg.max_scan_time = 2 * duration;
5021 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5022 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5023
5024 ret = ath10k_start_scan(ar, &arg);
5025 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005026 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005027 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005028 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005029 spin_unlock_bh(&ar->data_lock);
5030 goto exit;
5031 }
5032
5033 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5034 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005035 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005036
5037 ret = ath10k_scan_stop(ar);
5038 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005039 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005040
Kalle Valo5e3dd152013-06-12 20:52:10 +03005041 ret = -ETIMEDOUT;
5042 goto exit;
5043 }
5044
5045 ret = 0;
5046exit:
5047 mutex_unlock(&ar->conf_mutex);
5048 return ret;
5049}
5050
5051static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5052{
5053 struct ath10k *ar = hw->priv;
5054
5055 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005056 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005057 mutex_unlock(&ar->conf_mutex);
5058
Michal Kazior4eb2e162014-10-28 10:23:09 +01005059 cancel_delayed_work_sync(&ar->scan.timeout);
5060
Kalle Valo5e3dd152013-06-12 20:52:10 +03005061 return 0;
5062}
5063
5064/*
5065 * Both RTS and Fragmentation threshold are interface-specific
5066 * in ath10k, but device-specific in mac80211.
5067 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005068
5069static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5070{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005071 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005072 struct ath10k_vif *arvif;
5073 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005074
Michal Kaziorad088bf2013-10-16 15:44:46 +03005075 mutex_lock(&ar->conf_mutex);
5076 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005077 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005078 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005079
Michal Kaziorad088bf2013-10-16 15:44:46 +03005080 ret = ath10k_mac_set_rts(arvif, value);
5081 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005082 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005083 arvif->vdev_id, ret);
5084 break;
5085 }
5086 }
5087 mutex_unlock(&ar->conf_mutex);
5088
5089 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005090}
5091
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005092static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5093 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005094{
5095 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005096 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005097 int ret;
5098
5099 /* mac80211 doesn't care if we really xmit queued frames or not
5100 * we'll collect those frames either way if we stop/delete vdevs */
5101 if (drop)
5102 return;
5103
Michal Kazior548db542013-07-05 16:15:15 +03005104 mutex_lock(&ar->conf_mutex);
5105
Michal Kazioraffd3212013-07-16 09:54:35 +02005106 if (ar->state == ATH10K_STATE_WEDGED)
5107 goto skip;
5108
Michal Kazioredb82362013-07-05 16:15:14 +03005109 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005110 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005111
Michal Kazioredb82362013-07-05 16:15:14 +03005112 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005113 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005114 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005115
Michal Kazior7962b0d2014-10-28 10:34:38 +01005116 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5117 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5118 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005119
5120 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005121 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005122
5123 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005124 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005125 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005126
Michal Kazioraffd3212013-07-16 09:54:35 +02005127skip:
Michal Kazior548db542013-07-05 16:15:15 +03005128 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005129}
5130
5131/* TODO: Implement this function properly
5132 * For now it is needed to reply to Probe Requests in IBSS mode.
5133 * Propably we need this information from FW.
5134 */
5135static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5136{
5137 return 1;
5138}
5139
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005140static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5141 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005142{
5143 struct ath10k *ar = hw->priv;
5144
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005145 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5146 return;
5147
Michal Kazioraffd3212013-07-16 09:54:35 +02005148 mutex_lock(&ar->conf_mutex);
5149
5150 /* If device failed to restart it will be in a different state, e.g.
5151 * ATH10K_STATE_WEDGED */
5152 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005153 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005154 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005155 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005156 }
5157
5158 mutex_unlock(&ar->conf_mutex);
5159}
5160
Michal Kazior2e1dea42013-07-31 10:32:40 +02005161static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5162 struct survey_info *survey)
5163{
5164 struct ath10k *ar = hw->priv;
5165 struct ieee80211_supported_band *sband;
5166 struct survey_info *ar_survey = &ar->survey[idx];
5167 int ret = 0;
5168
5169 mutex_lock(&ar->conf_mutex);
5170
5171 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5172 if (sband && idx >= sband->n_channels) {
5173 idx -= sband->n_channels;
5174 sband = NULL;
5175 }
5176
5177 if (!sband)
5178 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5179
5180 if (!sband || idx >= sband->n_channels) {
5181 ret = -ENOENT;
5182 goto exit;
5183 }
5184
5185 spin_lock_bh(&ar->data_lock);
5186 memcpy(survey, ar_survey, sizeof(*survey));
5187 spin_unlock_bh(&ar->data_lock);
5188
5189 survey->channel = &sband->channels[idx];
5190
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005191 if (ar->rx_channel == survey->channel)
5192 survey->filled |= SURVEY_INFO_IN_USE;
5193
Michal Kazior2e1dea42013-07-31 10:32:40 +02005194exit:
5195 mutex_unlock(&ar->conf_mutex);
5196 return ret;
5197}
5198
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005199/* Helper table for legacy fixed_rate/bitrate_mask */
5200static const u8 cck_ofdm_rate[] = {
5201 /* CCK */
5202 3, /* 1Mbps */
5203 2, /* 2Mbps */
5204 1, /* 5.5Mbps */
5205 0, /* 11Mbps */
5206 /* OFDM */
5207 3, /* 6Mbps */
5208 7, /* 9Mbps */
5209 2, /* 12Mbps */
5210 6, /* 18Mbps */
5211 1, /* 24Mbps */
5212 5, /* 36Mbps */
5213 0, /* 48Mbps */
5214 4, /* 54Mbps */
5215};
5216
5217/* Check if only one bit set */
5218static int ath10k_check_single_mask(u32 mask)
5219{
5220 int bit;
5221
5222 bit = ffs(mask);
5223 if (!bit)
5224 return 0;
5225
5226 mask &= ~BIT(bit - 1);
5227 if (mask)
5228 return 2;
5229
5230 return 1;
5231}
5232
5233static bool
5234ath10k_default_bitrate_mask(struct ath10k *ar,
5235 enum ieee80211_band band,
5236 const struct cfg80211_bitrate_mask *mask)
5237{
5238 u32 legacy = 0x00ff;
5239 u8 ht = 0xff, i;
5240 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005241 u16 nrf = ar->num_rf_chains;
5242
5243 if (ar->cfg_tx_chainmask)
5244 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005245
5246 switch (band) {
5247 case IEEE80211_BAND_2GHZ:
5248 legacy = 0x00fff;
5249 vht = 0;
5250 break;
5251 case IEEE80211_BAND_5GHZ:
5252 break;
5253 default:
5254 return false;
5255 }
5256
5257 if (mask->control[band].legacy != legacy)
5258 return false;
5259
Ben Greearb116ea12014-11-24 16:22:10 +02005260 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005261 if (mask->control[band].ht_mcs[i] != ht)
5262 return false;
5263
Ben Greearb116ea12014-11-24 16:22:10 +02005264 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005265 if (mask->control[band].vht_mcs[i] != vht)
5266 return false;
5267
5268 return true;
5269}
5270
5271static bool
5272ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5273 enum ieee80211_band band,
5274 u8 *fixed_nss)
5275{
5276 int ht_nss = 0, vht_nss = 0, i;
5277
5278 /* check legacy */
5279 if (ath10k_check_single_mask(mask->control[band].legacy))
5280 return false;
5281
5282 /* check HT */
5283 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5284 if (mask->control[band].ht_mcs[i] == 0xff)
5285 continue;
5286 else if (mask->control[band].ht_mcs[i] == 0x00)
5287 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005288
5289 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005290 }
5291
5292 ht_nss = i;
5293
5294 /* check VHT */
5295 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5296 if (mask->control[band].vht_mcs[i] == 0x03ff)
5297 continue;
5298 else if (mask->control[band].vht_mcs[i] == 0x0000)
5299 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005300
5301 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005302 }
5303
5304 vht_nss = i;
5305
5306 if (ht_nss > 0 && vht_nss > 0)
5307 return false;
5308
5309 if (ht_nss)
5310 *fixed_nss = ht_nss;
5311 else if (vht_nss)
5312 *fixed_nss = vht_nss;
5313 else
5314 return false;
5315
5316 return true;
5317}
5318
5319static bool
5320ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5321 enum ieee80211_band band,
5322 enum wmi_rate_preamble *preamble)
5323{
5324 int legacy = 0, ht = 0, vht = 0, i;
5325
5326 *preamble = WMI_RATE_PREAMBLE_OFDM;
5327
5328 /* check legacy */
5329 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5330 if (legacy > 1)
5331 return false;
5332
5333 /* check HT */
5334 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5335 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5336 if (ht > 1)
5337 return false;
5338
5339 /* check VHT */
5340 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5341 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5342 if (vht > 1)
5343 return false;
5344
5345 /* Currently we support only one fixed_rate */
5346 if ((legacy + ht + vht) != 1)
5347 return false;
5348
5349 if (ht)
5350 *preamble = WMI_RATE_PREAMBLE_HT;
5351 else if (vht)
5352 *preamble = WMI_RATE_PREAMBLE_VHT;
5353
5354 return true;
5355}
5356
5357static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005358ath10k_bitrate_mask_rate(struct ath10k *ar,
5359 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005360 enum ieee80211_band band,
5361 u8 *fixed_rate,
5362 u8 *fixed_nss)
5363{
5364 u8 rate = 0, pream = 0, nss = 0, i;
5365 enum wmi_rate_preamble preamble;
5366
5367 /* Check if single rate correct */
5368 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5369 return false;
5370
5371 pream = preamble;
5372
5373 switch (preamble) {
5374 case WMI_RATE_PREAMBLE_CCK:
5375 case WMI_RATE_PREAMBLE_OFDM:
5376 i = ffs(mask->control[band].legacy) - 1;
5377
5378 if (band == IEEE80211_BAND_2GHZ && i < 4)
5379 pream = WMI_RATE_PREAMBLE_CCK;
5380
5381 if (band == IEEE80211_BAND_5GHZ)
5382 i += 4;
5383
5384 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5385 return false;
5386
5387 rate = cck_ofdm_rate[i];
5388 break;
5389 case WMI_RATE_PREAMBLE_HT:
5390 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5391 if (mask->control[band].ht_mcs[i])
5392 break;
5393
5394 if (i == IEEE80211_HT_MCS_MASK_LEN)
5395 return false;
5396
5397 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5398 nss = i;
5399 break;
5400 case WMI_RATE_PREAMBLE_VHT:
5401 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5402 if (mask->control[band].vht_mcs[i])
5403 break;
5404
5405 if (i == NL80211_VHT_NSS_MAX)
5406 return false;
5407
5408 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5409 nss = i;
5410 break;
5411 }
5412
5413 *fixed_nss = nss + 1;
5414 nss <<= 4;
5415 pream <<= 6;
5416
Michal Kazior7aa7a722014-08-25 12:09:38 +02005417 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 +01005418 pream, nss, rate);
5419
5420 *fixed_rate = pream | nss | rate;
5421
5422 return true;
5423}
5424
Michal Kazior7aa7a722014-08-25 12:09:38 +02005425static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5426 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005427 enum ieee80211_band band,
5428 u8 *fixed_rate,
5429 u8 *fixed_nss)
5430{
5431 /* First check full NSS mask, if we can simply limit NSS */
5432 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5433 return true;
5434
5435 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005436 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005437}
5438
5439static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5440 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005441 u8 fixed_nss,
5442 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005443{
5444 struct ath10k *ar = arvif->ar;
5445 u32 vdev_param;
5446 int ret = 0;
5447
5448 mutex_lock(&ar->conf_mutex);
5449
5450 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005451 arvif->fixed_nss == fixed_nss &&
5452 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005453 goto exit;
5454
5455 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005456 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005457
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005458 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005459 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005460
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005461 vdev_param = ar->wmi.vdev_param->fixed_rate;
5462 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5463 vdev_param, fixed_rate);
5464 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005465 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005466 fixed_rate, ret);
5467 ret = -EINVAL;
5468 goto exit;
5469 }
5470
5471 arvif->fixed_rate = fixed_rate;
5472
5473 vdev_param = ar->wmi.vdev_param->nss;
5474 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5475 vdev_param, fixed_nss);
5476
5477 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005478 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005479 fixed_nss, ret);
5480 ret = -EINVAL;
5481 goto exit;
5482 }
5483
5484 arvif->fixed_nss = fixed_nss;
5485
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005486 vdev_param = ar->wmi.vdev_param->sgi;
5487 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5488 force_sgi);
5489
5490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005491 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005492 force_sgi, ret);
5493 ret = -EINVAL;
5494 goto exit;
5495 }
5496
5497 arvif->force_sgi = force_sgi;
5498
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005499exit:
5500 mutex_unlock(&ar->conf_mutex);
5501 return ret;
5502}
5503
5504static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5505 struct ieee80211_vif *vif,
5506 const struct cfg80211_bitrate_mask *mask)
5507{
5508 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5509 struct ath10k *ar = arvif->ar;
5510 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5511 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5512 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005513 u8 force_sgi;
5514
Ben Greearb116ea12014-11-24 16:22:10 +02005515 if (ar->cfg_tx_chainmask)
5516 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5517
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005518 force_sgi = mask->control[band].gi;
5519 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5520 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005521
5522 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005523 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005524 &fixed_rate,
5525 &fixed_nss))
5526 return -EINVAL;
5527 }
5528
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005529 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005530 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005531 return -EINVAL;
5532 }
5533
5534 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5535 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005536}
5537
Michal Kazior9797feb2014-02-14 14:49:48 +01005538static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5539 struct ieee80211_vif *vif,
5540 struct ieee80211_sta *sta,
5541 u32 changed)
5542{
5543 struct ath10k *ar = hw->priv;
5544 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5545 u32 bw, smps;
5546
5547 spin_lock_bh(&ar->data_lock);
5548
Michal Kazior7aa7a722014-08-25 12:09:38 +02005549 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005550 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5551 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5552 sta->smps_mode);
5553
5554 if (changed & IEEE80211_RC_BW_CHANGED) {
5555 bw = WMI_PEER_CHWIDTH_20MHZ;
5556
5557 switch (sta->bandwidth) {
5558 case IEEE80211_STA_RX_BW_20:
5559 bw = WMI_PEER_CHWIDTH_20MHZ;
5560 break;
5561 case IEEE80211_STA_RX_BW_40:
5562 bw = WMI_PEER_CHWIDTH_40MHZ;
5563 break;
5564 case IEEE80211_STA_RX_BW_80:
5565 bw = WMI_PEER_CHWIDTH_80MHZ;
5566 break;
5567 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005568 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005569 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005570 bw = WMI_PEER_CHWIDTH_20MHZ;
5571 break;
5572 }
5573
5574 arsta->bw = bw;
5575 }
5576
5577 if (changed & IEEE80211_RC_NSS_CHANGED)
5578 arsta->nss = sta->rx_nss;
5579
5580 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5581 smps = WMI_PEER_SMPS_PS_NONE;
5582
5583 switch (sta->smps_mode) {
5584 case IEEE80211_SMPS_AUTOMATIC:
5585 case IEEE80211_SMPS_OFF:
5586 smps = WMI_PEER_SMPS_PS_NONE;
5587 break;
5588 case IEEE80211_SMPS_STATIC:
5589 smps = WMI_PEER_SMPS_STATIC;
5590 break;
5591 case IEEE80211_SMPS_DYNAMIC:
5592 smps = WMI_PEER_SMPS_DYNAMIC;
5593 break;
5594 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005595 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005596 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005597 smps = WMI_PEER_SMPS_PS_NONE;
5598 break;
5599 }
5600
5601 arsta->smps = smps;
5602 }
5603
Michal Kazior9797feb2014-02-14 14:49:48 +01005604 arsta->changed |= changed;
5605
5606 spin_unlock_bh(&ar->data_lock);
5607
5608 ieee80211_queue_work(hw, &arsta->update_wk);
5609}
5610
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005611static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5612{
5613 /*
5614 * FIXME: Return 0 for time being. Need to figure out whether FW
5615 * has the API to fetch 64-bit local TSF
5616 */
5617
5618 return 0;
5619}
5620
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005621static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5622 struct ieee80211_vif *vif,
5623 enum ieee80211_ampdu_mlme_action action,
5624 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5625 u8 buf_size)
5626{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005627 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005628 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5629
Michal Kazior7aa7a722014-08-25 12:09:38 +02005630 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 +02005631 arvif->vdev_id, sta->addr, tid, action);
5632
5633 switch (action) {
5634 case IEEE80211_AMPDU_RX_START:
5635 case IEEE80211_AMPDU_RX_STOP:
5636 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5637 * creation/removal. Do we need to verify this?
5638 */
5639 return 0;
5640 case IEEE80211_AMPDU_TX_START:
5641 case IEEE80211_AMPDU_TX_STOP_CONT:
5642 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5643 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5644 case IEEE80211_AMPDU_TX_OPERATIONAL:
5645 /* Firmware offloads Tx aggregation entirely so deny mac80211
5646 * Tx aggregation requests.
5647 */
5648 return -EOPNOTSUPP;
5649 }
5650
5651 return -EINVAL;
5652}
5653
Kalle Valo5e3dd152013-06-12 20:52:10 +03005654static const struct ieee80211_ops ath10k_ops = {
5655 .tx = ath10k_tx,
5656 .start = ath10k_start,
5657 .stop = ath10k_stop,
5658 .config = ath10k_config,
5659 .add_interface = ath10k_add_interface,
5660 .remove_interface = ath10k_remove_interface,
5661 .configure_filter = ath10k_configure_filter,
5662 .bss_info_changed = ath10k_bss_info_changed,
5663 .hw_scan = ath10k_hw_scan,
5664 .cancel_hw_scan = ath10k_cancel_hw_scan,
5665 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005666 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005667 .sta_state = ath10k_sta_state,
5668 .conf_tx = ath10k_conf_tx,
5669 .remain_on_channel = ath10k_remain_on_channel,
5670 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5671 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005672 .flush = ath10k_flush,
5673 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005674 .set_antenna = ath10k_set_antenna,
5675 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005676 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005677 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005678 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005679 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005680 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005681 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005682 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5683 .get_et_stats = ath10k_debug_get_et_stats,
5684 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005685
5686 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5687
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005688#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005689 .suspend = ath10k_wow_op_suspend,
5690 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005691#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005692#ifdef CONFIG_MAC80211_DEBUGFS
5693 .sta_add_debugfs = ath10k_sta_add_debugfs,
5694#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005695};
5696
Kalle Valo5e3dd152013-06-12 20:52:10 +03005697#define CHAN2G(_channel, _freq, _flags) { \
5698 .band = IEEE80211_BAND_2GHZ, \
5699 .hw_value = (_channel), \
5700 .center_freq = (_freq), \
5701 .flags = (_flags), \
5702 .max_antenna_gain = 0, \
5703 .max_power = 30, \
5704}
5705
5706#define CHAN5G(_channel, _freq, _flags) { \
5707 .band = IEEE80211_BAND_5GHZ, \
5708 .hw_value = (_channel), \
5709 .center_freq = (_freq), \
5710 .flags = (_flags), \
5711 .max_antenna_gain = 0, \
5712 .max_power = 30, \
5713}
5714
5715static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5716 CHAN2G(1, 2412, 0),
5717 CHAN2G(2, 2417, 0),
5718 CHAN2G(3, 2422, 0),
5719 CHAN2G(4, 2427, 0),
5720 CHAN2G(5, 2432, 0),
5721 CHAN2G(6, 2437, 0),
5722 CHAN2G(7, 2442, 0),
5723 CHAN2G(8, 2447, 0),
5724 CHAN2G(9, 2452, 0),
5725 CHAN2G(10, 2457, 0),
5726 CHAN2G(11, 2462, 0),
5727 CHAN2G(12, 2467, 0),
5728 CHAN2G(13, 2472, 0),
5729 CHAN2G(14, 2484, 0),
5730};
5731
5732static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005733 CHAN5G(36, 5180, 0),
5734 CHAN5G(40, 5200, 0),
5735 CHAN5G(44, 5220, 0),
5736 CHAN5G(48, 5240, 0),
5737 CHAN5G(52, 5260, 0),
5738 CHAN5G(56, 5280, 0),
5739 CHAN5G(60, 5300, 0),
5740 CHAN5G(64, 5320, 0),
5741 CHAN5G(100, 5500, 0),
5742 CHAN5G(104, 5520, 0),
5743 CHAN5G(108, 5540, 0),
5744 CHAN5G(112, 5560, 0),
5745 CHAN5G(116, 5580, 0),
5746 CHAN5G(120, 5600, 0),
5747 CHAN5G(124, 5620, 0),
5748 CHAN5G(128, 5640, 0),
5749 CHAN5G(132, 5660, 0),
5750 CHAN5G(136, 5680, 0),
5751 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005752 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005753 CHAN5G(149, 5745, 0),
5754 CHAN5G(153, 5765, 0),
5755 CHAN5G(157, 5785, 0),
5756 CHAN5G(161, 5805, 0),
5757 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005758};
5759
Michal Kaziore7b54192014-08-07 11:03:27 +02005760struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005761{
5762 struct ieee80211_hw *hw;
5763 struct ath10k *ar;
5764
Michal Kaziore7b54192014-08-07 11:03:27 +02005765 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005766 if (!hw)
5767 return NULL;
5768
5769 ar = hw->priv;
5770 ar->hw = hw;
5771
5772 return ar;
5773}
5774
5775void ath10k_mac_destroy(struct ath10k *ar)
5776{
5777 ieee80211_free_hw(ar->hw);
5778}
5779
5780static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5781 {
5782 .max = 8,
5783 .types = BIT(NL80211_IFTYPE_STATION)
5784 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005785 },
5786 {
5787 .max = 3,
5788 .types = BIT(NL80211_IFTYPE_P2P_GO)
5789 },
5790 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005791 .max = 1,
5792 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5793 },
5794 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005795 .max = 7,
5796 .types = BIT(NL80211_IFTYPE_AP)
5797 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005798};
5799
Bartosz Markowskif2595092013-12-10 16:20:39 +01005800static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005801 {
5802 .max = 8,
5803 .types = BIT(NL80211_IFTYPE_AP)
5804 },
5805};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005806
5807static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5808 {
5809 .limits = ath10k_if_limits,
5810 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5811 .max_interfaces = 8,
5812 .num_different_channels = 1,
5813 .beacon_int_infra_match = true,
5814 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005815};
5816
5817static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005818 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005819 .limits = ath10k_10x_if_limits,
5820 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005821 .max_interfaces = 8,
5822 .num_different_channels = 1,
5823 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005824#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005825 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5826 BIT(NL80211_CHAN_WIDTH_20) |
5827 BIT(NL80211_CHAN_WIDTH_40) |
5828 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005829#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005830 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005831};
5832
5833static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5834{
5835 struct ieee80211_sta_vht_cap vht_cap = {0};
5836 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005837 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005838 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005839
5840 vht_cap.vht_supported = 1;
5841 vht_cap.cap = ar->vht_cap_info;
5842
Michal Kaziorbc657a362015-02-26 11:11:22 +01005843 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5844 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5845 val = ar->num_rf_chains - 1;
5846 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5847 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5848
5849 vht_cap.cap |= val;
5850 }
5851
5852 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5853 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5854 val = ar->num_rf_chains - 1;
5855 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5856 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5857
5858 vht_cap.cap |= val;
5859 }
5860
Michal Kazior8865bee42013-07-24 12:36:46 +02005861 mcs_map = 0;
5862 for (i = 0; i < 8; i++) {
5863 if (i < ar->num_rf_chains)
5864 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5865 else
5866 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5867 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005868
5869 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5870 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5871
5872 return vht_cap;
5873}
5874
5875static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5876{
5877 int i;
5878 struct ieee80211_sta_ht_cap ht_cap = {0};
5879
5880 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5881 return ht_cap;
5882
5883 ht_cap.ht_supported = 1;
5884 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5885 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5886 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5887 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5888 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5889
5890 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5891 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5892
5893 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5894 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5895
5896 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5897 u32 smps;
5898
5899 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5900 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5901
5902 ht_cap.cap |= smps;
5903 }
5904
5905 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5906 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5907
5908 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5909 u32 stbc;
5910
5911 stbc = ar->ht_cap_info;
5912 stbc &= WMI_HT_CAP_RX_STBC;
5913 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5914 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5915 stbc &= IEEE80211_HT_CAP_RX_STBC;
5916
5917 ht_cap.cap |= stbc;
5918 }
5919
5920 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5921 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5922
5923 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5924 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5925
5926 /* max AMSDU is implicitly taken from vht_cap_info */
5927 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5928 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5929
Michal Kazior8865bee42013-07-24 12:36:46 +02005930 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005931 ht_cap.mcs.rx_mask[i] = 0xFF;
5932
5933 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5934
5935 return ht_cap;
5936}
5937
Kalle Valo5e3dd152013-06-12 20:52:10 +03005938static void ath10k_get_arvif_iter(void *data, u8 *mac,
5939 struct ieee80211_vif *vif)
5940{
5941 struct ath10k_vif_iter *arvif_iter = data;
5942 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5943
5944 if (arvif->vdev_id == arvif_iter->vdev_id)
5945 arvif_iter->arvif = arvif;
5946}
5947
5948struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5949{
5950 struct ath10k_vif_iter arvif_iter;
5951 u32 flags;
5952
5953 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5954 arvif_iter.vdev_id = vdev_id;
5955
5956 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5957 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5958 flags,
5959 ath10k_get_arvif_iter,
5960 &arvif_iter);
5961 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005962 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005963 return NULL;
5964 }
5965
5966 return arvif_iter.arvif;
5967}
5968
5969int ath10k_mac_register(struct ath10k *ar)
5970{
Johannes Berg3cb10942015-01-22 21:38:45 +01005971 static const u32 cipher_suites[] = {
5972 WLAN_CIPHER_SUITE_WEP40,
5973 WLAN_CIPHER_SUITE_WEP104,
5974 WLAN_CIPHER_SUITE_TKIP,
5975 WLAN_CIPHER_SUITE_CCMP,
5976 WLAN_CIPHER_SUITE_AES_CMAC,
5977 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005978 struct ieee80211_supported_band *band;
5979 struct ieee80211_sta_vht_cap vht_cap;
5980 struct ieee80211_sta_ht_cap ht_cap;
5981 void *channels;
5982 int ret;
5983
5984 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5985
5986 SET_IEEE80211_DEV(ar->hw, ar->dev);
5987
5988 ht_cap = ath10k_get_ht_cap(ar);
5989 vht_cap = ath10k_create_vht_cap(ar);
5990
5991 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5992 channels = kmemdup(ath10k_2ghz_channels,
5993 sizeof(ath10k_2ghz_channels),
5994 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005995 if (!channels) {
5996 ret = -ENOMEM;
5997 goto err_free;
5998 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005999
6000 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6001 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6002 band->channels = channels;
6003 band->n_bitrates = ath10k_g_rates_size;
6004 band->bitrates = ath10k_g_rates;
6005 band->ht_cap = ht_cap;
6006
Yanbo Lid68bb122015-01-23 08:18:20 +08006007 /* Enable the VHT support at 2.4 GHz */
6008 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006009
6010 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6011 }
6012
6013 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6014 channels = kmemdup(ath10k_5ghz_channels,
6015 sizeof(ath10k_5ghz_channels),
6016 GFP_KERNEL);
6017 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006018 ret = -ENOMEM;
6019 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006020 }
6021
6022 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6023 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6024 band->channels = channels;
6025 band->n_bitrates = ath10k_a_rates_size;
6026 band->bitrates = ath10k_a_rates;
6027 band->ht_cap = ht_cap;
6028 band->vht_cap = vht_cap;
6029 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6030 }
6031
6032 ar->hw->wiphy->interface_modes =
6033 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006034 BIT(NL80211_IFTYPE_AP);
6035
Ben Greear46acf7b2014-05-16 17:15:38 +03006036 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6037 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6038
Bartosz Markowskid3541812013-12-10 16:20:40 +01006039 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6040 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006041 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006042 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6043 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006044
6045 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6046 IEEE80211_HW_SUPPORTS_PS |
6047 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006048 IEEE80211_HW_MFP_CAPABLE |
6049 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6050 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006051 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006052 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006053 IEEE80211_HW_SW_CRYPTO_CONTROL |
6054 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006055
Eliad Peller0d8614b2014-09-10 14:07:36 +03006056 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6057
Kalle Valo5e3dd152013-06-12 20:52:10 +03006058 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006059 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006060
6061 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6062 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6063 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6064 }
6065
6066 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6067 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6068
6069 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006070 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006071
Kalle Valo5e3dd152013-06-12 20:52:10 +03006072 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6073
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006074 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6075 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6076
6077 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6078 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6079 * correct Probe Responses. This is more of a hack advert..
6080 */
6081 ar->hw->wiphy->probe_resp_offload |=
6082 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6083 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6084 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6085 }
6086
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006087 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6088 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6089
Kalle Valo5e3dd152013-06-12 20:52:10 +03006090 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006091 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006092 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6093
6094 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006095 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6096
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006097 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6098
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006099 ret = ath10k_wow_init(ar);
6100 if (ret) {
6101 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6102 goto err_free;
6103 }
6104
Kalle Valo5e3dd152013-06-12 20:52:10 +03006105 /*
6106 * on LL hardware queues are managed entirely by the FW
6107 * so we only advertise to mac we can do the queues thing
6108 */
6109 ar->hw->queues = 4;
6110
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006111 switch (ar->wmi.op_version) {
6112 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6113 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006114 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6115 ar->hw->wiphy->n_iface_combinations =
6116 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006117 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006118 break;
6119 case ATH10K_FW_WMI_OP_VERSION_10_1:
6120 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006121 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006122 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6123 ar->hw->wiphy->n_iface_combinations =
6124 ARRAY_SIZE(ath10k_10x_if_comb);
6125 break;
6126 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6127 case ATH10K_FW_WMI_OP_VERSION_MAX:
6128 WARN_ON(1);
6129 ret = -EINVAL;
6130 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006131 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006132
Michal Kazior7c199992013-07-31 10:47:57 +02006133 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6134
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006135 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6136 /* Init ath dfs pattern detector */
6137 ar->ath_common.debug_mask = ATH_DBG_DFS;
6138 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6139 NL80211_DFS_UNSET);
6140
6141 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006142 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006143 }
6144
Kalle Valo5e3dd152013-06-12 20:52:10 +03006145 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6146 ath10k_reg_notifier);
6147 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006148 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006149 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006150 }
6151
Johannes Berg3cb10942015-01-22 21:38:45 +01006152 ar->hw->wiphy->cipher_suites = cipher_suites;
6153 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6154
Kalle Valo5e3dd152013-06-12 20:52:10 +03006155 ret = ieee80211_register_hw(ar->hw);
6156 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006157 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006158 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006159 }
6160
6161 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6162 ret = regulatory_hint(ar->hw->wiphy,
6163 ar->ath_common.regulatory.alpha2);
6164 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006165 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006166 }
6167
6168 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006169
6170err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006171 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006172err_free:
6173 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6174 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6175
Kalle Valo5e3dd152013-06-12 20:52:10 +03006176 return ret;
6177}
6178
6179void ath10k_mac_unregister(struct ath10k *ar)
6180{
6181 ieee80211_unregister_hw(ar->hw);
6182
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006183 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6184 ar->dfs_detector->exit(ar->dfs_detector);
6185
Kalle Valo5e3dd152013-06-12 20:52:10 +03006186 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6187 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6188
6189 SET_IEEE80211_DEV(ar->hw, NULL);
6190}