blob: 7a21aee204f42694945a899c81e2f60b670dc039 [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
34/**********/
35/* Crypto */
36/**********/
37
38static int ath10k_send_key(struct ath10k_vif *arvif,
39 struct ieee80211_key_conf *key,
40 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010041 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030042{
Michal Kazior7aa7a722014-08-25 12:09:38 +020043 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030044 struct wmi_vdev_install_key_arg arg = {
45 .vdev_id = arvif->vdev_id,
46 .key_idx = key->keyidx,
47 .key_len = key->keylen,
48 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +010049 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +030050 .macaddr = macaddr,
51 };
52
Michal Kazior548db542013-07-05 16:15:15 +030053 lockdep_assert_held(&arvif->ar->conf_mutex);
54
Kalle Valo5e3dd152013-06-12 20:52:10 +030055 switch (key->cipher) {
56 case WLAN_CIPHER_SUITE_CCMP:
57 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020058 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030059 break;
60 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030061 arg.key_cipher = WMI_CIPHER_TKIP;
62 arg.key_txmic_len = 8;
63 arg.key_rxmic_len = 8;
64 break;
65 case WLAN_CIPHER_SUITE_WEP40:
66 case WLAN_CIPHER_SUITE_WEP104:
67 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +030068 break;
Johannes Berg3cb10942015-01-22 21:38:45 +010069 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +010070 WARN_ON(1);
71 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +030072 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020073 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030074 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010088 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030089{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Wolfram Sang16735d02013-11-14 14:32:02 -080095 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030096
Michal Kazior370e5672015-02-18 14:02:26 +010097 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +030098 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100115 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300116
117 lockdep_assert_held(&ar->conf_mutex);
118
119 spin_lock_bh(&ar->data_lock);
120 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
121 spin_unlock_bh(&ar->data_lock);
122
123 if (!peer)
124 return -ENOENT;
125
126 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
127 if (arvif->wep_keys[i] == NULL)
128 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100129
130 flags = 0;
131 flags |= WMI_KEY_PAIRWISE;
132
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200133 /* set TX_USAGE flag for default key id */
134 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100135 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300136
137 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100138 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300139 if (ret)
140 return ret;
141
Sujith Manoharanae167132014-11-25 11:46:59 +0530142 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300143 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530144 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300145 }
146
147 return 0;
148}
149
150static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
151 const u8 *addr)
152{
153 struct ath10k *ar = arvif->ar;
154 struct ath10k_peer *peer;
155 int first_errno = 0;
156 int ret;
157 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100158 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300159
160 lockdep_assert_held(&ar->conf_mutex);
161
162 spin_lock_bh(&ar->data_lock);
163 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
164 spin_unlock_bh(&ar->data_lock);
165
166 if (!peer)
167 return -ENOENT;
168
169 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
170 if (peer->keys[i] == NULL)
171 continue;
172
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200173 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100175 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300176 if (ret && first_errno == 0)
177 first_errno = ret;
178
179 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200180 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300181 i, ret);
182
Sujith Manoharanae167132014-11-25 11:46:59 +0530183 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300184 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530185 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300186 }
187
188 return first_errno;
189}
190
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530191bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
192 u8 keyidx)
193{
194 struct ath10k_peer *peer;
195 int i;
196
197 lockdep_assert_held(&ar->data_lock);
198
199 /* We don't know which vdev this peer belongs to,
200 * since WMI doesn't give us that information.
201 *
202 * FIXME: multi-bss needs to be handled.
203 */
204 peer = ath10k_peer_find(ar, 0, addr);
205 if (!peer)
206 return false;
207
208 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
209 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
210 return true;
211 }
212
213 return false;
214}
215
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
217 struct ieee80211_key_conf *key)
218{
219 struct ath10k *ar = arvif->ar;
220 struct ath10k_peer *peer;
221 u8 addr[ETH_ALEN];
222 int first_errno = 0;
223 int ret;
224 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100225 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300226
227 lockdep_assert_held(&ar->conf_mutex);
228
229 for (;;) {
230 /* since ath10k_install_key we can't hold data_lock all the
231 * time, so we try to remove the keys incrementally */
232 spin_lock_bh(&ar->data_lock);
233 i = 0;
234 list_for_each_entry(peer, &ar->peers, list) {
235 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
236 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300237 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300238 peer->keys[i] = NULL;
239 break;
240 }
241 }
242
243 if (i < ARRAY_SIZE(peer->keys))
244 break;
245 }
246 spin_unlock_bh(&ar->data_lock);
247
248 if (i == ARRAY_SIZE(peer->keys))
249 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200250 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100251 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300252 if (ret && first_errno == 0)
253 first_errno = ret;
254
255 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200256 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200257 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300258 }
259
260 return first_errno;
261}
262
Michal Kazior370e5672015-02-18 14:02:26 +0100263static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
264{
265 struct ath10k *ar = arvif->ar;
266 enum nl80211_iftype iftype = arvif->vif->type;
267 struct ieee80211_key_conf *key;
268 u32 flags = 0;
269 int num = 0;
270 int i;
271 int ret;
272
273 lockdep_assert_held(&ar->conf_mutex);
274
275 if (iftype != NL80211_IFTYPE_STATION)
276 return 0;
277
278 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
279 if (arvif->wep_keys[i]) {
280 key = arvif->wep_keys[i];
281 ++num;
282 }
283 }
284
285 if (num != 1)
286 return 0;
287
288 flags |= WMI_KEY_PAIRWISE;
289 flags |= WMI_KEY_TX_USAGE;
290
291 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
292 if (ret) {
293 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
294 key->keyidx, arvif->vdev_id, ret);
295 return ret;
296 }
297
298 return 0;
299}
300
Michal Kaziorad325cb2015-02-18 14:02:27 +0100301static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
302 struct ieee80211_key_conf *key)
303{
304 struct ath10k *ar = arvif->ar;
305 struct ath10k_peer *peer;
306 int ret;
307
308 lockdep_assert_held(&ar->conf_mutex);
309
310 list_for_each_entry(peer, &ar->peers, list) {
311 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
312 continue;
313
314 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
315 continue;
316
317 if (peer->keys[key->keyidx] == key)
318 continue;
319
320 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
321 arvif->vdev_id, key->keyidx);
322
323 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
324 if (ret) {
325 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
326 arvif->vdev_id, peer->addr, ret);
327 return ret;
328 }
329 }
330
331 return 0;
332}
333
Kalle Valo5e3dd152013-06-12 20:52:10 +0300334/*********************/
335/* General utilities */
336/*********************/
337
338static inline enum wmi_phy_mode
339chan_to_phymode(const struct cfg80211_chan_def *chandef)
340{
341 enum wmi_phy_mode phymode = MODE_UNKNOWN;
342
343 switch (chandef->chan->band) {
344 case IEEE80211_BAND_2GHZ:
345 switch (chandef->width) {
346 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800347 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
348 phymode = MODE_11B;
349 else
350 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300351 break;
352 case NL80211_CHAN_WIDTH_20:
353 phymode = MODE_11NG_HT20;
354 break;
355 case NL80211_CHAN_WIDTH_40:
356 phymode = MODE_11NG_HT40;
357 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400358 case NL80211_CHAN_WIDTH_5:
359 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300360 case NL80211_CHAN_WIDTH_80:
361 case NL80211_CHAN_WIDTH_80P80:
362 case NL80211_CHAN_WIDTH_160:
363 phymode = MODE_UNKNOWN;
364 break;
365 }
366 break;
367 case IEEE80211_BAND_5GHZ:
368 switch (chandef->width) {
369 case NL80211_CHAN_WIDTH_20_NOHT:
370 phymode = MODE_11A;
371 break;
372 case NL80211_CHAN_WIDTH_20:
373 phymode = MODE_11NA_HT20;
374 break;
375 case NL80211_CHAN_WIDTH_40:
376 phymode = MODE_11NA_HT40;
377 break;
378 case NL80211_CHAN_WIDTH_80:
379 phymode = MODE_11AC_VHT80;
380 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400381 case NL80211_CHAN_WIDTH_5:
382 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300383 case NL80211_CHAN_WIDTH_80P80:
384 case NL80211_CHAN_WIDTH_160:
385 phymode = MODE_UNKNOWN;
386 break;
387 }
388 break;
389 default:
390 break;
391 }
392
393 WARN_ON(phymode == MODE_UNKNOWN);
394 return phymode;
395}
396
397static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
398{
399/*
400 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
401 * 0 for no restriction
402 * 1 for 1/4 us
403 * 2 for 1/2 us
404 * 3 for 1 us
405 * 4 for 2 us
406 * 5 for 4 us
407 * 6 for 8 us
408 * 7 for 16 us
409 */
410 switch (mpdudensity) {
411 case 0:
412 return 0;
413 case 1:
414 case 2:
415 case 3:
416 /* Our lower layer calculations limit our precision to
417 1 microsecond */
418 return 1;
419 case 4:
420 return 2;
421 case 5:
422 return 4;
423 case 6:
424 return 8;
425 case 7:
426 return 16;
427 default:
428 return 0;
429 }
430}
431
432static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
433{
434 int ret;
435
436 lockdep_assert_held(&ar->conf_mutex);
437
Michal Kaziorcfd10612014-11-25 15:16:05 +0100438 if (ar->num_peers >= ar->max_num_peers)
439 return -ENOBUFS;
440
Kalle Valo5e3dd152013-06-12 20:52:10 +0300441 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800442 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200443 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200444 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300445 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800446 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300447
448 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800449 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200450 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200451 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300452 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800453 }
Michal Kazior292a7532014-11-25 15:16:04 +0100454
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100455 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300456
457 return 0;
458}
459
Kalle Valo5a13e762014-01-20 11:01:46 +0200460static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
461{
462 struct ath10k *ar = arvif->ar;
463 u32 param;
464 int ret;
465
466 param = ar->wmi.pdev_param->sta_kickout_th;
467 ret = ath10k_wmi_pdev_set_param(ar, param,
468 ATH10K_KICKOUT_THRESHOLD);
469 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200470 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200471 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200472 return ret;
473 }
474
475 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
476 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
477 ATH10K_KEEPALIVE_MIN_IDLE);
478 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200479 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200480 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200481 return ret;
482 }
483
484 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
485 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
486 ATH10K_KEEPALIVE_MAX_IDLE);
487 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200488 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200489 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200490 return ret;
491 }
492
493 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
494 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
495 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
496 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200497 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200498 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200499 return ret;
500 }
501
502 return 0;
503}
504
Vivek Natarajanacab6402014-11-26 09:06:12 +0200505static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200506{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200507 struct ath10k *ar = arvif->ar;
508 u32 vdev_param;
509
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200510 vdev_param = ar->wmi.vdev_param->rts_threshold;
511 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200512}
513
514static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
515{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200516 struct ath10k *ar = arvif->ar;
517 u32 vdev_param;
518
Michal Kazior424121c2013-07-22 14:13:31 +0200519 if (value != 0xFFFFFFFF)
520 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
521 ATH10K_FRAGMT_THRESHOLD_MIN,
522 ATH10K_FRAGMT_THRESHOLD_MAX);
523
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200524 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
525 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200526}
527
Kalle Valo5e3dd152013-06-12 20:52:10 +0300528static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
529{
530 int ret;
531
532 lockdep_assert_held(&ar->conf_mutex);
533
534 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
535 if (ret)
536 return ret;
537
538 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
539 if (ret)
540 return ret;
541
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100542 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100543
Kalle Valo5e3dd152013-06-12 20:52:10 +0300544 return 0;
545}
546
547static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
548{
549 struct ath10k_peer *peer, *tmp;
550
551 lockdep_assert_held(&ar->conf_mutex);
552
553 spin_lock_bh(&ar->data_lock);
554 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
555 if (peer->vdev_id != vdev_id)
556 continue;
557
Michal Kazior7aa7a722014-08-25 12:09:38 +0200558 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559 peer->addr, vdev_id);
560
561 list_del(&peer->list);
562 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100563 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300564 }
565 spin_unlock_bh(&ar->data_lock);
566}
567
Michal Kaziora96d7742013-07-16 09:38:56 +0200568static void ath10k_peer_cleanup_all(struct ath10k *ar)
569{
570 struct ath10k_peer *peer, *tmp;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
574 spin_lock_bh(&ar->data_lock);
575 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
576 list_del(&peer->list);
577 kfree(peer);
578 }
579 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100580
581 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100582 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200583}
584
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585/************************/
586/* Interface management */
587/************************/
588
Michal Kazior64badcb2014-09-18 11:18:02 +0300589void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
590{
591 struct ath10k *ar = arvif->ar;
592
593 lockdep_assert_held(&ar->data_lock);
594
595 if (!arvif->beacon)
596 return;
597
598 if (!arvif->beacon_buf)
599 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
600 arvif->beacon->len, DMA_TO_DEVICE);
601
Michal Kazioraf213192015-01-29 14:29:52 +0200602 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
603 arvif->beacon_state != ATH10K_BEACON_SENT))
604 return;
605
Michal Kazior64badcb2014-09-18 11:18:02 +0300606 dev_kfree_skb_any(arvif->beacon);
607
608 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200609 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300610}
611
612static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
613{
614 struct ath10k *ar = arvif->ar;
615
616 lockdep_assert_held(&ar->data_lock);
617
618 ath10k_mac_vif_beacon_free(arvif);
619
620 if (arvif->beacon_buf) {
621 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
622 arvif->beacon_buf, arvif->beacon_paddr);
623 arvif->beacon_buf = NULL;
624 }
625}
626
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
628{
629 int ret;
630
Michal Kazior548db542013-07-05 16:15:15 +0300631 lockdep_assert_held(&ar->conf_mutex);
632
Michal Kazior7962b0d2014-10-28 10:34:38 +0100633 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
634 return -ESHUTDOWN;
635
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
637 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
638 if (ret == 0)
639 return -ETIMEDOUT;
640
641 return 0;
642}
643
Michal Kazior1bbc0972014-04-08 09:45:47 +0300644static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645{
Michal Kaziorc930f742014-01-23 11:38:25 +0100646 struct cfg80211_chan_def *chandef = &ar->chandef;
647 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 int ret = 0;
650
651 lockdep_assert_held(&ar->conf_mutex);
652
Kalle Valo5e3dd152013-06-12 20:52:10 +0300653 arg.vdev_id = vdev_id;
654 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100655 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300656
657 /* TODO setup this dynamically, what in case we
658 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100659 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200660 arg.channel.chan_radar =
661 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300662
Michal Kazior89c5c842013-10-23 04:02:13 -0700663 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700664 arg.channel.max_power = channel->max_power * 2;
665 arg.channel.max_reg_power = channel->max_reg_power * 2;
666 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667
Michal Kazior7962b0d2014-10-28 10:34:38 +0100668 reinit_completion(&ar->vdev_setup_done);
669
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670 ret = ath10k_wmi_vdev_start(ar, &arg);
671 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200672 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200673 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 return ret;
675 }
676
677 ret = ath10k_vdev_setup_sync(ar);
678 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200679 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200680 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300681 return ret;
682 }
683
684 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
685 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200686 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200687 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688 goto vdev_stop;
689 }
690
691 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692
Michal Kazior7aa7a722014-08-25 12:09:38 +0200693 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300694 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695 return 0;
696
697vdev_stop:
698 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
699 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200700 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200701 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300702
703 return ret;
704}
705
Michal Kazior1bbc0972014-04-08 09:45:47 +0300706static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707{
708 int ret = 0;
709
710 lockdep_assert_held(&ar->conf_mutex);
711
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200712 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
713 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200714 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200715 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300716
Michal Kazior7962b0d2014-10-28 10:34:38 +0100717 reinit_completion(&ar->vdev_setup_done);
718
Kalle Valo5e3dd152013-06-12 20:52:10 +0300719 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
720 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200721 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200722 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300723
724 ret = ath10k_vdev_setup_sync(ar);
725 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200726 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200727 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728
Michal Kazior7aa7a722014-08-25 12:09:38 +0200729 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300730 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300731 return ret;
732}
733
Michal Kazior1bbc0972014-04-08 09:45:47 +0300734static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300735{
736 int bit, ret = 0;
737
738 lockdep_assert_held(&ar->conf_mutex);
739
Ben Greeara9aefb32014-08-12 11:02:19 +0300740 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200741 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300742 return -ENOMEM;
743 }
744
Ben Greear16c11172014-09-23 14:17:16 -0700745 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300746
Ben Greear16c11172014-09-23 14:17:16 -0700747 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300748
749 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
750 WMI_VDEV_TYPE_MONITOR,
751 0, ar->mac_addr);
752 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200753 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200754 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300755 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300756 }
757
Ben Greear16c11172014-09-23 14:17:16 -0700758 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200759 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300760 ar->monitor_vdev_id);
761
Kalle Valo5e3dd152013-06-12 20:52:10 +0300762 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300763}
764
Michal Kazior1bbc0972014-04-08 09:45:47 +0300765static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300766{
767 int ret = 0;
768
769 lockdep_assert_held(&ar->conf_mutex);
770
Kalle Valo5e3dd152013-06-12 20:52:10 +0300771 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
772 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200773 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200774 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300775 return ret;
776 }
777
Ben Greear16c11172014-09-23 14:17:16 -0700778 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300779
Michal Kazior7aa7a722014-08-25 12:09:38 +0200780 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300781 ar->monitor_vdev_id);
782 return ret;
783}
784
Michal Kazior1bbc0972014-04-08 09:45:47 +0300785static int ath10k_monitor_start(struct ath10k *ar)
786{
787 int ret;
788
789 lockdep_assert_held(&ar->conf_mutex);
790
Michal Kazior1bbc0972014-04-08 09:45:47 +0300791 ret = ath10k_monitor_vdev_create(ar);
792 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200793 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300794 return ret;
795 }
796
797 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
798 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200799 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300800 ath10k_monitor_vdev_delete(ar);
801 return ret;
802 }
803
804 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200805 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300806
807 return 0;
808}
809
Michal Kazior19337472014-08-28 12:58:16 +0200810static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300811{
812 int ret;
813
814 lockdep_assert_held(&ar->conf_mutex);
815
Michal Kazior1bbc0972014-04-08 09:45:47 +0300816 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200817 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200818 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200819 return ret;
820 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300821
822 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200824 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200825 return ret;
826 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300827
828 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200829 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200830
831 return 0;
832}
833
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530834static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
835{
836 struct ath10k_vif *arvif;
837
838 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
839 return true;
840
841 if (!ar->num_started_vdevs)
842 return false;
843
844 list_for_each_entry(arvif, &ar->arvifs, list)
845 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
846 return false;
847
848 ath10k_dbg(ar, ATH10K_DBG_MAC,
849 "mac disabling promiscuous mode because vdev is started\n");
850 return true;
851}
852
Michal Kazior19337472014-08-28 12:58:16 +0200853static int ath10k_monitor_recalc(struct ath10k *ar)
854{
855 bool should_start;
856
857 lockdep_assert_held(&ar->conf_mutex);
858
859 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100860 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200861 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
862
863 ath10k_dbg(ar, ATH10K_DBG_MAC,
864 "mac monitor recalc started? %d should? %d\n",
865 ar->monitor_started, should_start);
866
867 if (should_start == ar->monitor_started)
868 return 0;
869
870 if (should_start)
871 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300872
873 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300874}
875
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200876static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
877{
878 struct ath10k *ar = arvif->ar;
879 u32 vdev_param, rts_cts = 0;
880
881 lockdep_assert_held(&ar->conf_mutex);
882
883 vdev_param = ar->wmi.vdev_param->enable_rtscts;
884
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200885 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200886
887 if (arvif->num_legacy_stations > 0)
888 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
889 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200890 else
891 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
892 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200893
894 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
895 rts_cts);
896}
897
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200898static int ath10k_start_cac(struct ath10k *ar)
899{
900 int ret;
901
902 lockdep_assert_held(&ar->conf_mutex);
903
904 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
905
Michal Kazior19337472014-08-28 12:58:16 +0200906 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200907 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200908 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200909 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
910 return ret;
911 }
912
Michal Kazior7aa7a722014-08-25 12:09:38 +0200913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200914 ar->monitor_vdev_id);
915
916 return 0;
917}
918
919static int ath10k_stop_cac(struct ath10k *ar)
920{
921 lockdep_assert_held(&ar->conf_mutex);
922
923 /* CAC is not running - do nothing */
924 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
925 return 0;
926
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200927 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300928 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200929
Michal Kazior7aa7a722014-08-25 12:09:38 +0200930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200931
932 return 0;
933}
934
Michal Kaziord6500972014-04-08 09:56:09 +0300935static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200936{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200937 int ret;
938
939 lockdep_assert_held(&ar->conf_mutex);
940
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200941 ath10k_stop_cac(ar);
942
Michal Kaziord6500972014-04-08 09:56:09 +0300943 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200944 return;
945
Michal Kaziord6500972014-04-08 09:56:09 +0300946 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200947 return;
948
949 ret = ath10k_start_cac(ar);
950 if (ret) {
951 /*
952 * Not possible to start CAC on current channel so starting
953 * radiation is not allowed, make this channel DFS_UNAVAILABLE
954 * by indicating that radar was detected.
955 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200956 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200957 ieee80211_radar_detected(ar->hw);
958 }
959}
960
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530961static int ath10k_vdev_stop(struct ath10k_vif *arvif)
962{
963 struct ath10k *ar = arvif->ar;
964 int ret;
965
966 lockdep_assert_held(&ar->conf_mutex);
967
968 reinit_completion(&ar->vdev_setup_done);
969
970 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
971 if (ret) {
972 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
973 arvif->vdev_id, ret);
974 return ret;
975 }
976
977 ret = ath10k_vdev_setup_sync(ar);
978 if (ret) {
979 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
980 arvif->vdev_id, ret);
981 return ret;
982 }
983
984 WARN_ON(ar->num_started_vdevs == 0);
985
986 if (ar->num_started_vdevs != 0) {
987 ar->num_started_vdevs--;
988 ath10k_recalc_radar_detection(ar);
989 }
990
991 return ret;
992}
993
Michal Kaziordc55e302014-07-29 12:53:36 +0300994static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300995{
996 struct ath10k *ar = arvif->ar;
997 struct cfg80211_chan_def *chandef = &ar->chandef;
998 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530999 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001000
1001 lockdep_assert_held(&ar->conf_mutex);
1002
1003 reinit_completion(&ar->vdev_setup_done);
1004
1005 arg.vdev_id = arvif->vdev_id;
1006 arg.dtim_period = arvif->dtim_period;
1007 arg.bcn_intval = arvif->beacon_interval;
1008
1009 arg.channel.freq = chandef->chan->center_freq;
1010 arg.channel.band_center_freq1 = chandef->center_freq1;
1011 arg.channel.mode = chan_to_phymode(chandef);
1012
1013 arg.channel.min_power = 0;
1014 arg.channel.max_power = chandef->chan->max_power * 2;
1015 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1016 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1017
1018 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1019 arg.ssid = arvif->u.ap.ssid;
1020 arg.ssid_len = arvif->u.ap.ssid_len;
1021 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1022
1023 /* For now allow DFS for AP mode */
1024 arg.channel.chan_radar =
1025 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1026 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1027 arg.ssid = arvif->vif->bss_conf.ssid;
1028 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1029 }
1030
Michal Kazior7aa7a722014-08-25 12:09:38 +02001031 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001032 "mac vdev %d start center_freq %d phymode %s\n",
1033 arg.vdev_id, arg.channel.freq,
1034 ath10k_wmi_phymode_str(arg.channel.mode));
1035
Michal Kaziordc55e302014-07-29 12:53:36 +03001036 if (restart)
1037 ret = ath10k_wmi_vdev_restart(ar, &arg);
1038 else
1039 ret = ath10k_wmi_vdev_start(ar, &arg);
1040
Michal Kazior72654fa2014-04-08 09:56:09 +03001041 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001042 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001043 arg.vdev_id, ret);
1044 return ret;
1045 }
1046
1047 ret = ath10k_vdev_setup_sync(ar);
1048 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001049 ath10k_warn(ar,
1050 "failed to synchronize setup for vdev %i restart %d: %d\n",
1051 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001052 return ret;
1053 }
1054
Michal Kaziord6500972014-04-08 09:56:09 +03001055 ar->num_started_vdevs++;
1056 ath10k_recalc_radar_detection(ar);
1057
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301058 ret = ath10k_monitor_recalc(ar);
1059 if (ret) {
1060 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1061 arg.vdev_id, restart, ret);
1062 ret2 = ath10k_vdev_stop(arvif);
1063 if (ret2)
1064 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1065 arg.vdev_id, restart, ret2);
1066 }
1067
Michal Kazior72654fa2014-04-08 09:56:09 +03001068 return ret;
1069}
1070
Michal Kaziordc55e302014-07-29 12:53:36 +03001071static int ath10k_vdev_start(struct ath10k_vif *arvif)
1072{
1073 return ath10k_vdev_start_restart(arvif, false);
1074}
1075
1076static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1077{
1078 return ath10k_vdev_start_restart(arvif, true);
1079}
1080
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001081static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1082 struct sk_buff *bcn)
1083{
1084 struct ath10k *ar = arvif->ar;
1085 struct ieee80211_mgmt *mgmt;
1086 const u8 *p2p_ie;
1087 int ret;
1088
1089 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1090 return 0;
1091
1092 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1093 return 0;
1094
1095 mgmt = (void *)bcn->data;
1096 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1097 mgmt->u.beacon.variable,
1098 bcn->len - (mgmt->u.beacon.variable -
1099 bcn->data));
1100 if (!p2p_ie)
1101 return -ENOENT;
1102
1103 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1104 if (ret) {
1105 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1106 arvif->vdev_id, ret);
1107 return ret;
1108 }
1109
1110 return 0;
1111}
1112
1113static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1114 u8 oui_type, size_t ie_offset)
1115{
1116 size_t len;
1117 const u8 *next;
1118 const u8 *end;
1119 u8 *ie;
1120
1121 if (WARN_ON(skb->len < ie_offset))
1122 return -EINVAL;
1123
1124 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1125 skb->data + ie_offset,
1126 skb->len - ie_offset);
1127 if (!ie)
1128 return -ENOENT;
1129
1130 len = ie[1] + 2;
1131 end = skb->data + skb->len;
1132 next = ie + len;
1133
1134 if (WARN_ON(next > end))
1135 return -EINVAL;
1136
1137 memmove(ie, next, end - next);
1138 skb_trim(skb, skb->len - len);
1139
1140 return 0;
1141}
1142
1143static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1144{
1145 struct ath10k *ar = arvif->ar;
1146 struct ieee80211_hw *hw = ar->hw;
1147 struct ieee80211_vif *vif = arvif->vif;
1148 struct ieee80211_mutable_offsets offs = {};
1149 struct sk_buff *bcn;
1150 int ret;
1151
1152 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1153 return 0;
1154
Michal Kazior81a9a172015-03-05 16:02:17 +02001155 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1156 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1157 return 0;
1158
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001159 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1160 if (!bcn) {
1161 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1162 return -EPERM;
1163 }
1164
1165 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1166 if (ret) {
1167 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1168 kfree_skb(bcn);
1169 return ret;
1170 }
1171
1172 /* P2P IE is inserted by firmware automatically (as configured above)
1173 * so remove it from the base beacon template to avoid duplicate P2P
1174 * IEs in beacon frames.
1175 */
1176 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1177 offsetof(struct ieee80211_mgmt,
1178 u.beacon.variable));
1179
1180 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1181 0, NULL, 0);
1182 kfree_skb(bcn);
1183
1184 if (ret) {
1185 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1186 ret);
1187 return ret;
1188 }
1189
1190 return 0;
1191}
1192
1193static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1194{
1195 struct ath10k *ar = arvif->ar;
1196 struct ieee80211_hw *hw = ar->hw;
1197 struct ieee80211_vif *vif = arvif->vif;
1198 struct sk_buff *prb;
1199 int ret;
1200
1201 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1202 return 0;
1203
Michal Kazior81a9a172015-03-05 16:02:17 +02001204 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1205 return 0;
1206
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001207 prb = ieee80211_proberesp_get(hw, vif);
1208 if (!prb) {
1209 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1210 return -EPERM;
1211 }
1212
1213 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1214 kfree_skb(prb);
1215
1216 if (ret) {
1217 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1218 ret);
1219 return ret;
1220 }
1221
1222 return 0;
1223}
1224
Kalle Valo5e3dd152013-06-12 20:52:10 +03001225static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001226 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001227{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001228 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001229 int ret = 0;
1230
Michal Kazior548db542013-07-05 16:15:15 +03001231 lockdep_assert_held(&arvif->ar->conf_mutex);
1232
Kalle Valo5e3dd152013-06-12 20:52:10 +03001233 if (!info->enable_beacon) {
1234 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001235
1236 arvif->is_started = false;
1237 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001238
1239 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001240 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001241 spin_unlock_bh(&arvif->ar->data_lock);
1242
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243 return;
1244 }
1245
1246 arvif->tx_seq_no = 0x1000;
1247
1248 ret = ath10k_vdev_start(arvif);
1249 if (ret)
1250 return;
1251
Michal Kaziorc930f742014-01-23 11:38:25 +01001252 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001253 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001254
1255 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1256 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001257 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001258 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001259 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001260 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001261 return;
1262 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001263
1264 arvif->is_started = true;
1265 arvif->is_up = true;
1266
Michal Kazior7aa7a722014-08-25 12:09:38 +02001267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001268}
1269
1270static void ath10k_control_ibss(struct ath10k_vif *arvif,
1271 struct ieee80211_bss_conf *info,
1272 const u8 self_peer[ETH_ALEN])
1273{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001274 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001275 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001276 int ret = 0;
1277
Michal Kazior548db542013-07-05 16:15:15 +03001278 lockdep_assert_held(&arvif->ar->conf_mutex);
1279
Kalle Valo5e3dd152013-06-12 20:52:10 +03001280 if (!info->ibss_joined) {
1281 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1282 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001283 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001284 self_peer, arvif->vdev_id, ret);
1285
Michal Kaziorc930f742014-01-23 11:38:25 +01001286 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287 return;
1288
Michal Kaziorc930f742014-01-23 11:38:25 +01001289 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001290
1291 return;
1292 }
1293
1294 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1295 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001296 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297 self_peer, arvif->vdev_id, ret);
1298 return;
1299 }
1300
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001301 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1302 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001303 ATH10K_DEFAULT_ATIM);
1304 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001305 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001306 arvif->vdev_id, ret);
1307}
1308
Michal Kazior9f9b5742014-12-12 12:41:36 +01001309static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1310{
1311 struct ath10k *ar = arvif->ar;
1312 u32 param;
1313 u32 value;
1314 int ret;
1315
1316 lockdep_assert_held(&arvif->ar->conf_mutex);
1317
1318 if (arvif->u.sta.uapsd)
1319 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1320 else
1321 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1322
1323 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1324 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1325 if (ret) {
1326 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1327 value, arvif->vdev_id, ret);
1328 return ret;
1329 }
1330
1331 return 0;
1332}
1333
1334static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1335{
1336 struct ath10k *ar = arvif->ar;
1337 u32 param;
1338 u32 value;
1339 int ret;
1340
1341 lockdep_assert_held(&arvif->ar->conf_mutex);
1342
1343 if (arvif->u.sta.uapsd)
1344 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1345 else
1346 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1347
1348 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1349 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1350 param, value);
1351 if (ret) {
1352 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1353 value, arvif->vdev_id, ret);
1354 return ret;
1355 }
1356
1357 return 0;
1358}
1359
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001360static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1361{
1362 struct ath10k_vif *arvif;
1363 int num = 0;
1364
1365 lockdep_assert_held(&ar->conf_mutex);
1366
1367 list_for_each_entry(arvif, &ar->arvifs, list)
1368 if (arvif->ps)
1369 num++;
1370
1371 return num;
1372}
1373
Michal Kaziorad088bf2013-10-16 15:44:46 +03001374static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001375{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001376 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001377 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001378 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 enum wmi_sta_powersave_param param;
1380 enum wmi_sta_ps_mode psmode;
1381 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001382 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001383 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384
Michal Kazior548db542013-07-05 16:15:15 +03001385 lockdep_assert_held(&arvif->ar->conf_mutex);
1386
Michal Kaziorad088bf2013-10-16 15:44:46 +03001387 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1388 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001389
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001390 enable_ps = arvif->ps;
1391
1392 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1393 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1394 ar->fw_features)) {
1395 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1396 arvif->vdev_id);
1397 enable_ps = false;
1398 }
1399
1400 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001401 psmode = WMI_STA_PS_MODE_ENABLED;
1402 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1403
Michal Kazior526549a2014-12-12 12:41:37 +01001404 ps_timeout = conf->dynamic_ps_timeout;
1405 if (ps_timeout == 0) {
1406 /* Firmware doesn't like 0 */
1407 ps_timeout = ieee80211_tu_to_usec(
1408 vif->bss_conf.beacon_int) / 1000;
1409 }
1410
Michal Kaziorad088bf2013-10-16 15:44:46 +03001411 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001412 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001414 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001415 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001416 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001418 } else {
1419 psmode = WMI_STA_PS_MODE_DISABLED;
1420 }
1421
Michal Kazior7aa7a722014-08-25 12:09:38 +02001422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001423 arvif->vdev_id, psmode ? "enable" : "disable");
1424
Michal Kaziorad088bf2013-10-16 15:44:46 +03001425 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1426 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001427 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001428 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001429 return ret;
1430 }
1431
1432 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001433}
1434
Michal Kazior46725b152015-01-28 09:57:49 +02001435static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1436{
1437 struct ath10k *ar = arvif->ar;
1438 struct wmi_sta_keepalive_arg arg = {};
1439 int ret;
1440
1441 lockdep_assert_held(&arvif->ar->conf_mutex);
1442
1443 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1444 return 0;
1445
1446 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1447 return 0;
1448
1449 /* Some firmware revisions have a bug and ignore the `enabled` field.
1450 * Instead use the interval to disable the keepalive.
1451 */
1452 arg.vdev_id = arvif->vdev_id;
1453 arg.enabled = 1;
1454 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1455 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1456
1457 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1458 if (ret) {
1459 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1460 arvif->vdev_id, ret);
1461 return ret;
1462 }
1463
1464 return 0;
1465}
1466
Michal Kazior81a9a172015-03-05 16:02:17 +02001467static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1468{
1469 struct ath10k *ar = arvif->ar;
1470 struct ieee80211_vif *vif = arvif->vif;
1471 int ret;
1472
Michal Kazior8513d952015-03-09 14:19:24 +01001473 lockdep_assert_held(&arvif->ar->conf_mutex);
1474
1475 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1476 return;
1477
Michal Kazior81a9a172015-03-05 16:02:17 +02001478 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1479 return;
1480
1481 if (!vif->csa_active)
1482 return;
1483
1484 if (!arvif->is_up)
1485 return;
1486
1487 if (!ieee80211_csa_is_complete(vif)) {
1488 ieee80211_csa_update_counter(vif);
1489
1490 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1491 if (ret)
1492 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1493 ret);
1494
1495 ret = ath10k_mac_setup_prb_tmpl(arvif);
1496 if (ret)
1497 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1498 ret);
1499 } else {
1500 ieee80211_csa_finish(vif);
1501 }
1502}
1503
1504static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1505{
1506 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1507 ap_csa_work);
1508 struct ath10k *ar = arvif->ar;
1509
1510 mutex_lock(&ar->conf_mutex);
1511 ath10k_mac_vif_ap_csa_count_down(arvif);
1512 mutex_unlock(&ar->conf_mutex);
1513}
1514
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001515static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1516 struct ieee80211_vif *vif)
1517{
1518 struct sk_buff *skb = data;
1519 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1520 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1521
1522 if (vif->type != NL80211_IFTYPE_STATION)
1523 return;
1524
1525 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1526 return;
1527
1528 cancel_delayed_work(&arvif->connection_loss_work);
1529}
1530
1531void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1532{
1533 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1534 IEEE80211_IFACE_ITER_NORMAL,
1535 ath10k_mac_handle_beacon_iter,
1536 skb);
1537}
1538
1539static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1540 struct ieee80211_vif *vif)
1541{
1542 u32 *vdev_id = data;
1543 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1544 struct ath10k *ar = arvif->ar;
1545 struct ieee80211_hw *hw = ar->hw;
1546
1547 if (arvif->vdev_id != *vdev_id)
1548 return;
1549
1550 if (!arvif->is_up)
1551 return;
1552
1553 ieee80211_beacon_loss(vif);
1554
1555 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1556 * (done by mac80211) succeeds but beacons do not resume then it
1557 * doesn't make sense to continue operation. Queue connection loss work
1558 * which can be cancelled when beacon is received.
1559 */
1560 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1561 ATH10K_CONNECTION_LOSS_HZ);
1562}
1563
1564void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1565{
1566 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1567 IEEE80211_IFACE_ITER_NORMAL,
1568 ath10k_mac_handle_beacon_miss_iter,
1569 &vdev_id);
1570}
1571
1572static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1573{
1574 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1575 connection_loss_work.work);
1576 struct ieee80211_vif *vif = arvif->vif;
1577
1578 if (!arvif->is_up)
1579 return;
1580
1581 ieee80211_connection_loss(vif);
1582}
1583
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584/**********************/
1585/* Station management */
1586/**********************/
1587
Michal Kazior590922a2014-10-21 10:10:29 +03001588static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1589 struct ieee80211_vif *vif)
1590{
1591 /* Some firmware revisions have unstable STA powersave when listen
1592 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1593 * generate NullFunc frames properly even if buffered frames have been
1594 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1595 * buffered frames. Often pinging the device from AP would simply fail.
1596 *
1597 * As a workaround set it to 1.
1598 */
1599 if (vif->type == NL80211_IFTYPE_STATION)
1600 return 1;
1601
1602 return ar->hw->conf.listen_interval;
1603}
1604
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001606 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 struct wmi_peer_assoc_complete_arg *arg)
1609{
Michal Kazior590922a2014-10-21 10:10:29 +03001610 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1611
Michal Kazior548db542013-07-05 16:15:15 +03001612 lockdep_assert_held(&ar->conf_mutex);
1613
Kalle Valob25f32c2014-09-14 12:50:49 +03001614 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 arg->vdev_id = arvif->vdev_id;
1616 arg->peer_aid = sta->aid;
1617 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001618 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001620 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621}
1622
1623static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001624 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001625 struct wmi_peer_assoc_complete_arg *arg)
1626{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 struct ieee80211_bss_conf *info = &vif->bss_conf;
1628 struct cfg80211_bss *bss;
1629 const u8 *rsnie = NULL;
1630 const u8 *wpaie = NULL;
1631
Michal Kazior548db542013-07-05 16:15:15 +03001632 lockdep_assert_held(&ar->conf_mutex);
1633
Kalle Valo5e3dd152013-06-12 20:52:10 +03001634 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001635 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1636 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001637 if (bss) {
1638 const struct cfg80211_bss_ies *ies;
1639
1640 rcu_read_lock();
1641 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1642
1643 ies = rcu_dereference(bss->ies);
1644
1645 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001646 WLAN_OUI_TYPE_MICROSOFT_WPA,
1647 ies->data,
1648 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001649 rcu_read_unlock();
1650 cfg80211_put_bss(ar->hw->wiphy, bss);
1651 }
1652
1653 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1654 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001655 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001656 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1657 }
1658
1659 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001660 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1662 }
1663}
1664
1665static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1666 struct ieee80211_sta *sta,
1667 struct wmi_peer_assoc_complete_arg *arg)
1668{
1669 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1670 const struct ieee80211_supported_band *sband;
1671 const struct ieee80211_rate *rates;
1672 u32 ratemask;
1673 int i;
1674
Michal Kazior548db542013-07-05 16:15:15 +03001675 lockdep_assert_held(&ar->conf_mutex);
1676
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1678 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1679 rates = sband->bitrates;
1680
1681 rateset->num_rates = 0;
1682
1683 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1684 if (!(ratemask & 1))
1685 continue;
1686
1687 rateset->rates[rateset->num_rates] = rates->hw_value;
1688 rateset->num_rates++;
1689 }
1690}
1691
1692static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1693 struct ieee80211_sta *sta,
1694 struct wmi_peer_assoc_complete_arg *arg)
1695{
1696 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001698 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699
Michal Kazior548db542013-07-05 16:15:15 +03001700 lockdep_assert_held(&ar->conf_mutex);
1701
Kalle Valo5e3dd152013-06-12 20:52:10 +03001702 if (!ht_cap->ht_supported)
1703 return;
1704
1705 arg->peer_flags |= WMI_PEER_HT;
1706 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1707 ht_cap->ampdu_factor)) - 1;
1708
1709 arg->peer_mpdu_density =
1710 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1711
1712 arg->peer_ht_caps = ht_cap->cap;
1713 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1714
1715 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1716 arg->peer_flags |= WMI_PEER_LDPC;
1717
1718 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1719 arg->peer_flags |= WMI_PEER_40MHZ;
1720 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1721 }
1722
1723 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1724 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1725
1726 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1727 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1728
1729 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1730 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1731 arg->peer_flags |= WMI_PEER_STBC;
1732 }
1733
1734 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1736 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1737 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1738 arg->peer_rate_caps |= stbc;
1739 arg->peer_flags |= WMI_PEER_STBC;
1740 }
1741
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1743 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1744 else if (ht_cap->mcs.rx_mask[1])
1745 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1746
1747 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1748 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1749 arg->peer_ht_rates.rates[n++] = i;
1750
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001751 /*
1752 * This is a workaround for HT-enabled STAs which break the spec
1753 * and have no HT capabilities RX mask (no HT RX MCS map).
1754 *
1755 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1756 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1757 *
1758 * Firmware asserts if such situation occurs.
1759 */
1760 if (n == 0) {
1761 arg->peer_ht_rates.num_rates = 8;
1762 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1763 arg->peer_ht_rates.rates[i] = i;
1764 } else {
1765 arg->peer_ht_rates.num_rates = n;
1766 arg->peer_num_spatial_streams = sta->rx_nss;
1767 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001768
Michal Kazior7aa7a722014-08-25 12:09:38 +02001769 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001770 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001771 arg->peer_ht_rates.num_rates,
1772 arg->peer_num_spatial_streams);
1773}
1774
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001775static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1776 struct ath10k_vif *arvif,
1777 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778{
1779 u32 uapsd = 0;
1780 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001781 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001782
Michal Kazior548db542013-07-05 16:15:15 +03001783 lockdep_assert_held(&ar->conf_mutex);
1784
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001786 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787 sta->uapsd_queues, sta->max_sp);
1788
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1790 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1791 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1792 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1793 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1794 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1795 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1796 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1797 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1798 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1799 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1800 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1801
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1803 max_sp = sta->max_sp;
1804
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001805 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1806 sta->addr,
1807 WMI_AP_PS_PEER_PARAM_UAPSD,
1808 uapsd);
1809 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001810 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001811 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001812 return ret;
1813 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001815 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1816 sta->addr,
1817 WMI_AP_PS_PEER_PARAM_MAX_SP,
1818 max_sp);
1819 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001821 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001822 return ret;
1823 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001824
1825 /* TODO setup this based on STA listen interval and
1826 beacon interval. Currently we don't know
1827 sta->listen_interval - mac80211 patch required.
1828 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001829 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001830 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1831 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001832 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001833 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001834 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001835 return ret;
1836 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001837 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001838
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001839 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001840}
1841
1842static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1843 struct ieee80211_sta *sta,
1844 struct wmi_peer_assoc_complete_arg *arg)
1845{
1846 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001847 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848
1849 if (!vht_cap->vht_supported)
1850 return;
1851
1852 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001853
1854 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1855 arg->peer_flags |= WMI_PEER_VHT_2G;
1856
Kalle Valo5e3dd152013-06-12 20:52:10 +03001857 arg->peer_vht_caps = vht_cap->cap;
1858
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001859 ampdu_factor = (vht_cap->cap &
1860 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1861 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1862
1863 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1864 * zero in VHT IE. Using it would result in degraded throughput.
1865 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1866 * it if VHT max_mpdu is smaller. */
1867 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1868 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1869 ampdu_factor)) - 1);
1870
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1872 arg->peer_flags |= WMI_PEER_80MHZ;
1873
1874 arg->peer_vht_rates.rx_max_rate =
1875 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1876 arg->peer_vht_rates.rx_mcs_set =
1877 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1878 arg->peer_vht_rates.tx_max_rate =
1879 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1880 arg->peer_vht_rates.tx_mcs_set =
1881 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1882
Michal Kazior7aa7a722014-08-25 12:09:38 +02001883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001884 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885}
1886
1887static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001888 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001889 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001890 struct wmi_peer_assoc_complete_arg *arg)
1891{
Michal Kazior590922a2014-10-21 10:10:29 +03001892 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1893
Kalle Valo5e3dd152013-06-12 20:52:10 +03001894 switch (arvif->vdev_type) {
1895 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001896 if (sta->wme)
1897 arg->peer_flags |= WMI_PEER_QOS;
1898
1899 if (sta->wme && sta->uapsd_queues) {
1900 arg->peer_flags |= WMI_PEER_APSD;
1901 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1902 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903 break;
1904 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001905 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001906 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001907 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001908 case WMI_VDEV_TYPE_IBSS:
1909 if (sta->wme)
1910 arg->peer_flags |= WMI_PEER_QOS;
1911 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001912 default:
1913 break;
1914 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001915
1916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1917 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001918}
1919
Michal Kazior91b12082014-12-12 12:41:35 +01001920static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1921{
1922 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1923 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1924}
1925
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001927 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001928 struct ieee80211_sta *sta,
1929 struct wmi_peer_assoc_complete_arg *arg)
1930{
1931 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1932
Kalle Valo5e3dd152013-06-12 20:52:10 +03001933 switch (ar->hw->conf.chandef.chan->band) {
1934 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001935 if (sta->vht_cap.vht_supported) {
1936 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1937 phymode = MODE_11AC_VHT40;
1938 else
1939 phymode = MODE_11AC_VHT20;
1940 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1942 phymode = MODE_11NG_HT40;
1943 else
1944 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001945 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001947 } else {
1948 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949 }
1950
1951 break;
1952 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001953 /*
1954 * Check VHT first.
1955 */
1956 if (sta->vht_cap.vht_supported) {
1957 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1958 phymode = MODE_11AC_VHT80;
1959 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1960 phymode = MODE_11AC_VHT40;
1961 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1962 phymode = MODE_11AC_VHT20;
1963 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1965 phymode = MODE_11NA_HT40;
1966 else
1967 phymode = MODE_11NA_HT20;
1968 } else {
1969 phymode = MODE_11A;
1970 }
1971
1972 break;
1973 default:
1974 break;
1975 }
1976
Michal Kazior7aa7a722014-08-25 12:09:38 +02001977 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001978 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001979
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980 arg->peer_phymode = phymode;
1981 WARN_ON(phymode == MODE_UNKNOWN);
1982}
1983
Kalle Valob9ada652013-10-16 15:44:46 +03001984static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001985 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001986 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001987 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988{
Michal Kazior548db542013-07-05 16:15:15 +03001989 lockdep_assert_held(&ar->conf_mutex);
1990
Kalle Valob9ada652013-10-16 15:44:46 +03001991 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992
Michal Kazior590922a2014-10-21 10:10:29 +03001993 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1994 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001995 ath10k_peer_assoc_h_rates(ar, sta, arg);
1996 ath10k_peer_assoc_h_ht(ar, sta, arg);
1997 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001998 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1999 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002000
Kalle Valob9ada652013-10-16 15:44:46 +03002001 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002}
2003
Michal Kazior90046f52014-02-14 14:45:51 +01002004static const u32 ath10k_smps_map[] = {
2005 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2006 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2007 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2008 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2009};
2010
2011static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2012 const u8 *addr,
2013 const struct ieee80211_sta_ht_cap *ht_cap)
2014{
2015 int smps;
2016
2017 if (!ht_cap->ht_supported)
2018 return 0;
2019
2020 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2021 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2022
2023 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2024 return -EINVAL;
2025
2026 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2027 WMI_PEER_SMPS_STATE,
2028 ath10k_smps_map[smps]);
2029}
2030
Michal Kazior139e1702015-02-15 16:50:42 +02002031static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2032 struct ieee80211_vif *vif,
2033 struct ieee80211_sta_vht_cap vht_cap)
2034{
2035 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2036 int ret;
2037 u32 param;
2038 u32 value;
2039
2040 if (!(ar->vht_cap_info &
2041 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2042 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2043 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2044 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2045 return 0;
2046
2047 param = ar->wmi.vdev_param->txbf;
2048 value = 0;
2049
2050 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2051 return 0;
2052
2053 /* The following logic is correct. If a remote STA advertises support
2054 * for being a beamformer then we should enable us being a beamformee.
2055 */
2056
2057 if (ar->vht_cap_info &
2058 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2059 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2060 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2061 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2062
2063 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2064 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2065 }
2066
2067 if (ar->vht_cap_info &
2068 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2069 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2070 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2071 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2072
2073 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2074 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2075 }
2076
2077 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2078 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2079
2080 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2081 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2082
2083 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2084 if (ret) {
2085 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2086 value, ret);
2087 return ret;
2088 }
2089
2090 return 0;
2091}
2092
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093/* can be called only in mac80211 callbacks due to `key_count` usage */
2094static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2095 struct ieee80211_vif *vif,
2096 struct ieee80211_bss_conf *bss_conf)
2097{
2098 struct ath10k *ar = hw->priv;
2099 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002100 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002101 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002102 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002103 struct ieee80211_sta *ap_sta;
2104 int ret;
2105
Michal Kazior548db542013-07-05 16:15:15 +03002106 lockdep_assert_held(&ar->conf_mutex);
2107
Michal Kazior077efc82014-10-21 10:10:29 +03002108 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2109 arvif->vdev_id, arvif->bssid, arvif->aid);
2110
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111 rcu_read_lock();
2112
2113 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2114 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002115 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002116 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 rcu_read_unlock();
2118 return;
2119 }
2120
Michal Kazior90046f52014-02-14 14:45:51 +01002121 /* ap_sta must be accessed only within rcu section which must be left
2122 * before calling ath10k_setup_peer_smps() which might sleep. */
2123 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002124 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002125
Michal Kazior590922a2014-10-21 10:10:29 +03002126 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002127 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002128 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002129 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130 rcu_read_unlock();
2131 return;
2132 }
2133
2134 rcu_read_unlock();
2135
Kalle Valob9ada652013-10-16 15:44:46 +03002136 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2137 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002138 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002139 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002140 return;
2141 }
2142
Michal Kazior90046f52014-02-14 14:45:51 +01002143 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2144 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002145 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002146 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002147 return;
2148 }
2149
Michal Kazior139e1702015-02-15 16:50:42 +02002150 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2151 if (ret) {
2152 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2153 arvif->vdev_id, bss_conf->bssid, ret);
2154 return;
2155 }
2156
Michal Kazior7aa7a722014-08-25 12:09:38 +02002157 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002158 "mac vdev %d up (associated) bssid %pM aid %d\n",
2159 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2160
Michal Kazior077efc82014-10-21 10:10:29 +03002161 WARN_ON(arvif->is_up);
2162
Michal Kaziorc930f742014-01-23 11:38:25 +01002163 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002164 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002165
2166 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2167 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002168 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002169 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002170 return;
2171 }
2172
2173 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002174
2175 /* Workaround: Some firmware revisions (tested with qca6174
2176 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2177 * poked with peer param command.
2178 */
2179 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2180 WMI_PEER_DUMMY_VAR, 1);
2181 if (ret) {
2182 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2183 arvif->bssid, arvif->vdev_id, ret);
2184 return;
2185 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186}
2187
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2189 struct ieee80211_vif *vif)
2190{
2191 struct ath10k *ar = hw->priv;
2192 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002193 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002194 int ret;
2195
Michal Kazior548db542013-07-05 16:15:15 +03002196 lockdep_assert_held(&ar->conf_mutex);
2197
Michal Kazior077efc82014-10-21 10:10:29 +03002198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2199 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002200
Kalle Valo5e3dd152013-06-12 20:52:10 +03002201 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002202 if (ret)
2203 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2204 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002206 arvif->def_wep_key_idx = -1;
2207
Michal Kazior139e1702015-02-15 16:50:42 +02002208 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2209 if (ret) {
2210 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2211 arvif->vdev_id, ret);
2212 return;
2213 }
2214
Michal Kaziorc930f742014-01-23 11:38:25 +01002215 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002216
2217 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002218}
2219
Michal Kazior590922a2014-10-21 10:10:29 +03002220static int ath10k_station_assoc(struct ath10k *ar,
2221 struct ieee80211_vif *vif,
2222 struct ieee80211_sta *sta,
2223 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224{
Michal Kazior590922a2014-10-21 10:10:29 +03002225 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002226 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002227 int ret = 0;
2228
Michal Kazior548db542013-07-05 16:15:15 +03002229 lockdep_assert_held(&ar->conf_mutex);
2230
Michal Kazior590922a2014-10-21 10:10:29 +03002231 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002233 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002234 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002235 return ret;
2236 }
2237
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002238 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002239 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2240 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002241 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002242 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 return ret;
2244 }
2245
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002246 /* Re-assoc is run only to update supported rates for given station. It
2247 * doesn't make much sense to reconfigure the peer completely.
2248 */
2249 if (!reassoc) {
2250 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2251 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002252 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002253 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002254 arvif->vdev_id, ret);
2255 return ret;
2256 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002257
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002258 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2259 if (ret) {
2260 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2261 sta->addr, arvif->vdev_id, ret);
2262 return ret;
2263 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002264
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002265 if (!sta->wme) {
2266 arvif->num_legacy_stations++;
2267 ret = ath10k_recalc_rtscts_prot(arvif);
2268 if (ret) {
2269 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2270 arvif->vdev_id, ret);
2271 return ret;
2272 }
2273 }
2274
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002275 /* Plumb cached keys only for static WEP */
2276 if (arvif->def_wep_key_idx != -1) {
2277 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2278 if (ret) {
2279 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2280 arvif->vdev_id, ret);
2281 return ret;
2282 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 }
2284 }
2285
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286 return ret;
2287}
2288
Michal Kazior590922a2014-10-21 10:10:29 +03002289static int ath10k_station_disassoc(struct ath10k *ar,
2290 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 struct ieee80211_sta *sta)
2292{
Michal Kazior590922a2014-10-21 10:10:29 +03002293 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002294 int ret = 0;
2295
2296 lockdep_assert_held(&ar->conf_mutex);
2297
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002298 if (!sta->wme) {
2299 arvif->num_legacy_stations--;
2300 ret = ath10k_recalc_rtscts_prot(arvif);
2301 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002302 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002303 arvif->vdev_id, ret);
2304 return ret;
2305 }
2306 }
2307
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2309 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002310 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002311 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002312 return ret;
2313 }
2314
2315 return ret;
2316}
2317
2318/**************/
2319/* Regulatory */
2320/**************/
2321
2322static int ath10k_update_channel_list(struct ath10k *ar)
2323{
2324 struct ieee80211_hw *hw = ar->hw;
2325 struct ieee80211_supported_band **bands;
2326 enum ieee80211_band band;
2327 struct ieee80211_channel *channel;
2328 struct wmi_scan_chan_list_arg arg = {0};
2329 struct wmi_channel_arg *ch;
2330 bool passive;
2331 int len;
2332 int ret;
2333 int i;
2334
Michal Kazior548db542013-07-05 16:15:15 +03002335 lockdep_assert_held(&ar->conf_mutex);
2336
Kalle Valo5e3dd152013-06-12 20:52:10 +03002337 bands = hw->wiphy->bands;
2338 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2339 if (!bands[band])
2340 continue;
2341
2342 for (i = 0; i < bands[band]->n_channels; i++) {
2343 if (bands[band]->channels[i].flags &
2344 IEEE80211_CHAN_DISABLED)
2345 continue;
2346
2347 arg.n_channels++;
2348 }
2349 }
2350
2351 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2352 arg.channels = kzalloc(len, GFP_KERNEL);
2353 if (!arg.channels)
2354 return -ENOMEM;
2355
2356 ch = arg.channels;
2357 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2358 if (!bands[band])
2359 continue;
2360
2361 for (i = 0; i < bands[band]->n_channels; i++) {
2362 channel = &bands[band]->channels[i];
2363
2364 if (channel->flags & IEEE80211_CHAN_DISABLED)
2365 continue;
2366
2367 ch->allow_ht = true;
2368
2369 /* FIXME: when should we really allow VHT? */
2370 ch->allow_vht = true;
2371
2372 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002373 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002374
2375 ch->ht40plus =
2376 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2377
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002378 ch->chan_radar =
2379 !!(channel->flags & IEEE80211_CHAN_RADAR);
2380
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002381 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002382 ch->passive = passive;
2383
2384 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002385 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002386 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002387 ch->max_power = channel->max_power * 2;
2388 ch->max_reg_power = channel->max_reg_power * 2;
2389 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002390 ch->reg_class_id = 0; /* FIXME */
2391
2392 /* FIXME: why use only legacy modes, why not any
2393 * HT/VHT modes? Would that even make any
2394 * difference? */
2395 if (channel->band == IEEE80211_BAND_2GHZ)
2396 ch->mode = MODE_11G;
2397 else
2398 ch->mode = MODE_11A;
2399
2400 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2401 continue;
2402
Michal Kazior7aa7a722014-08-25 12:09:38 +02002403 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002404 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2405 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002406 ch->freq, ch->max_power, ch->max_reg_power,
2407 ch->max_antenna_gain, ch->mode);
2408
2409 ch++;
2410 }
2411 }
2412
2413 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2414 kfree(arg.channels);
2415
2416 return ret;
2417}
2418
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002419static enum wmi_dfs_region
2420ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2421{
2422 switch (dfs_region) {
2423 case NL80211_DFS_UNSET:
2424 return WMI_UNINIT_DFS_DOMAIN;
2425 case NL80211_DFS_FCC:
2426 return WMI_FCC_DFS_DOMAIN;
2427 case NL80211_DFS_ETSI:
2428 return WMI_ETSI_DFS_DOMAIN;
2429 case NL80211_DFS_JP:
2430 return WMI_MKK4_DFS_DOMAIN;
2431 }
2432 return WMI_UNINIT_DFS_DOMAIN;
2433}
2434
Michal Kaziorf7843d72013-07-16 09:38:52 +02002435static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002436{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002437 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002438 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002439 enum wmi_dfs_region wmi_dfs_reg;
2440 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002441
Michal Kaziorf7843d72013-07-16 09:38:52 +02002442 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002443
2444 ret = ath10k_update_channel_list(ar);
2445 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002446 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002447
2448 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002449
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002450 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2451 nl_dfs_reg = ar->dfs_detector->region;
2452 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2453 } else {
2454 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2455 }
2456
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457 /* Target allows setting up per-band regdomain but ath_common provides
2458 * a combined one only */
2459 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002460 regpair->reg_domain,
2461 regpair->reg_domain, /* 2ghz */
2462 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002463 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002464 regpair->reg_5ghz_ctl,
2465 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002467 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002468}
Michal Kazior548db542013-07-05 16:15:15 +03002469
Michal Kaziorf7843d72013-07-16 09:38:52 +02002470static void ath10k_reg_notifier(struct wiphy *wiphy,
2471 struct regulatory_request *request)
2472{
2473 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2474 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002475 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002476
2477 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2478
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002479 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002480 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002481 request->dfs_region);
2482 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2483 request->dfs_region);
2484 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002485 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002486 request->dfs_region);
2487 }
2488
Michal Kaziorf7843d72013-07-16 09:38:52 +02002489 mutex_lock(&ar->conf_mutex);
2490 if (ar->state == ATH10K_STATE_ON)
2491 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002492 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002493}
2494
2495/***************/
2496/* TX handlers */
2497/***************/
2498
Michal Kazior42c3aa62013-10-02 11:03:38 +02002499static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2500{
2501 if (ieee80211_is_mgmt(hdr->frame_control))
2502 return HTT_DATA_TX_EXT_TID_MGMT;
2503
2504 if (!ieee80211_is_data_qos(hdr->frame_control))
2505 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2506
2507 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2508 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2509
2510 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2511}
2512
Michal Kazior2b37c292014-09-02 11:00:22 +03002513static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002514{
Michal Kazior2b37c292014-09-02 11:00:22 +03002515 if (vif)
2516 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002517
Michal Kazior1bbc0972014-04-08 09:45:47 +03002518 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002519 return ar->monitor_vdev_id;
2520
Michal Kazior7aa7a722014-08-25 12:09:38 +02002521 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002522 return 0;
2523}
2524
Michal Kaziord740d8f2015-03-30 09:51:51 +03002525static enum ath10k_hw_txrx_mode
2526ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
2527 struct sk_buff *skb)
2528{
2529 const struct ieee80211_hdr *hdr = (void *)skb->data;
2530 __le16 fc = hdr->frame_control;
2531
2532 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2533 return ATH10K_HW_TXRX_RAW;
2534
2535 if (ieee80211_is_mgmt(fc))
2536 return ATH10K_HW_TXRX_MGMT;
2537
2538 /* Workaround:
2539 *
2540 * NullFunc frames are mostly used to ping if a client or AP are still
2541 * reachable and responsive. This implies tx status reports must be
2542 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2543 * come to a conclusion that the other end disappeared and tear down
2544 * BSS connection or it can never disconnect from BSS/client (which is
2545 * the case).
2546 *
2547 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2548 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2549 * which seems to deliver correct tx reports for NullFunc frames. The
2550 * downside of using it is it ignores client powersave state so it can
2551 * end up disconnecting sleeping clients in AP mode. It should fix STA
2552 * mode though because AP don't sleep.
2553 */
2554 if (ar->htt.target_version_major < 3 &&
2555 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2556 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2557 return ATH10K_HW_TXRX_MGMT;
2558
2559 return ATH10K_HW_TXRX_NATIVE_WIFI;
2560}
2561
Michal Kazior4b604552014-07-21 21:03:09 +03002562/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2563 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002564 */
Michal Kazior4b604552014-07-21 21:03:09 +03002565static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002566{
2567 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002568 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002569 u8 *qos_ctl;
2570
2571 if (!ieee80211_is_data_qos(hdr->frame_control))
2572 return;
2573
2574 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002575 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2576 skb->data, (void *)qos_ctl - (void *)skb->data);
2577 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002578
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002579 /* Some firmware revisions don't handle sending QoS NullFunc well.
2580 * These frames are mainly used for CQM purposes so it doesn't really
2581 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002582 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002583 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002584 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002585 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002586
2587 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588}
2589
Michal Kaziord740d8f2015-03-30 09:51:51 +03002590static void ath10k_tx_h_8023(struct sk_buff *skb)
2591{
2592 struct ieee80211_hdr *hdr;
2593 struct rfc1042_hdr *rfc1042;
2594 struct ethhdr *eth;
2595 size_t hdrlen;
2596 u8 da[ETH_ALEN];
2597 u8 sa[ETH_ALEN];
2598 __be16 type;
2599
2600 hdr = (void *)skb->data;
2601 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2602 rfc1042 = (void *)skb->data + hdrlen;
2603
2604 ether_addr_copy(da, ieee80211_get_DA(hdr));
2605 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2606 type = rfc1042->snap_type;
2607
2608 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2609 skb_push(skb, sizeof(*eth));
2610
2611 eth = (void *)skb->data;
2612 ether_addr_copy(eth->h_dest, da);
2613 ether_addr_copy(eth->h_source, sa);
2614 eth->h_proto = type;
2615}
2616
Michal Kazior4b604552014-07-21 21:03:09 +03002617static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2618 struct ieee80211_vif *vif,
2619 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002620{
2621 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2623
2624 /* This is case only for P2P_GO */
2625 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2626 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2627 return;
2628
2629 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2630 spin_lock_bh(&ar->data_lock);
2631 if (arvif->u.ap.noa_data)
2632 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2633 GFP_ATOMIC))
2634 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2635 arvif->u.ap.noa_data,
2636 arvif->u.ap.noa_len);
2637 spin_unlock_bh(&ar->data_lock);
2638 }
2639}
2640
Michal Kazior8d6d3622014-11-24 14:58:31 +01002641static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2642{
2643 /* FIXME: Not really sure since when the behaviour changed. At some
2644 * point new firmware stopped requiring creation of peer entries for
2645 * offchannel tx (and actually creating them causes issues with wmi-htc
2646 * tx credit replenishment and reliability). Assuming it's at least 3.4
2647 * because that's when the `freq` was introduced to TX_FRM HTT command.
2648 */
2649 return !(ar->htt.target_version_major >= 3 &&
2650 ar->htt.target_version_minor >= 4);
2651}
2652
Michal Kaziord740d8f2015-03-30 09:51:51 +03002653static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002654{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002655 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002656 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657
Michal Kaziord740d8f2015-03-30 09:51:51 +03002658 spin_lock_bh(&ar->data_lock);
2659
2660 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2661 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2662 ret = -ENOSPC;
2663 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002664 }
2665
Michal Kaziord740d8f2015-03-30 09:51:51 +03002666 __skb_queue_tail(q, skb);
2667 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2668
2669unlock:
2670 spin_unlock_bh(&ar->data_lock);
2671
2672 return ret;
2673}
2674
2675static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2676{
2677 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2678 struct ath10k_htt *htt = &ar->htt;
2679 int ret = 0;
2680
2681 switch (cb->txmode) {
2682 case ATH10K_HW_TXRX_RAW:
2683 case ATH10K_HW_TXRX_NATIVE_WIFI:
2684 case ATH10K_HW_TXRX_ETHERNET:
2685 ret = ath10k_htt_tx(htt, skb);
2686 break;
2687 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002688 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002689 ar->fw_features))
2690 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2691 else if (ar->htt.target_version_major >= 3)
2692 ret = ath10k_htt_tx(htt, skb);
2693 else
2694 ret = ath10k_htt_mgmt_tx(htt, skb);
2695 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002696 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002697
2698 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002699 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2700 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002701 ieee80211_free_txskb(ar->hw, skb);
2702 }
2703}
2704
2705void ath10k_offchan_tx_purge(struct ath10k *ar)
2706{
2707 struct sk_buff *skb;
2708
2709 for (;;) {
2710 skb = skb_dequeue(&ar->offchan_tx_queue);
2711 if (!skb)
2712 break;
2713
2714 ieee80211_free_txskb(ar->hw, skb);
2715 }
2716}
2717
2718void ath10k_offchan_tx_work(struct work_struct *work)
2719{
2720 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2721 struct ath10k_peer *peer;
2722 struct ieee80211_hdr *hdr;
2723 struct sk_buff *skb;
2724 const u8 *peer_addr;
2725 int vdev_id;
2726 int ret;
2727
2728 /* FW requirement: We must create a peer before FW will send out
2729 * an offchannel frame. Otherwise the frame will be stuck and
2730 * never transmitted. We delete the peer upon tx completion.
2731 * It is unlikely that a peer for offchannel tx will already be
2732 * present. However it may be in some rare cases so account for that.
2733 * Otherwise we might remove a legitimate peer and break stuff. */
2734
2735 for (;;) {
2736 skb = skb_dequeue(&ar->offchan_tx_queue);
2737 if (!skb)
2738 break;
2739
2740 mutex_lock(&ar->conf_mutex);
2741
Michal Kazior7aa7a722014-08-25 12:09:38 +02002742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002743 skb);
2744
2745 hdr = (struct ieee80211_hdr *)skb->data;
2746 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002747 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748
2749 spin_lock_bh(&ar->data_lock);
2750 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2751 spin_unlock_bh(&ar->data_lock);
2752
2753 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002754 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002755 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002756 peer_addr, vdev_id);
2757
2758 if (!peer) {
2759 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2760 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002761 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 peer_addr, vdev_id, ret);
2763 }
2764
2765 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002766 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002767 ar->offchan_tx_skb = skb;
2768 spin_unlock_bh(&ar->data_lock);
2769
Michal Kaziord740d8f2015-03-30 09:51:51 +03002770 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771
2772 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2773 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002774 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002775 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 skb);
2777
2778 if (!peer) {
2779 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2780 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002781 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002782 peer_addr, vdev_id, ret);
2783 }
2784
2785 mutex_unlock(&ar->conf_mutex);
2786 }
2787}
2788
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002789void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2790{
2791 struct sk_buff *skb;
2792
2793 for (;;) {
2794 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2795 if (!skb)
2796 break;
2797
2798 ieee80211_free_txskb(ar->hw, skb);
2799 }
2800}
2801
2802void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2803{
2804 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2805 struct sk_buff *skb;
2806 int ret;
2807
2808 for (;;) {
2809 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2810 if (!skb)
2811 break;
2812
2813 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002814 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002815 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002816 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002817 ieee80211_free_txskb(ar->hw, skb);
2818 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002819 }
2820}
2821
Kalle Valo5e3dd152013-06-12 20:52:10 +03002822/************/
2823/* Scanning */
2824/************/
2825
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002826void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002827{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002828 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002829
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002830 switch (ar->scan.state) {
2831 case ATH10K_SCAN_IDLE:
2832 break;
2833 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002834 if (ar->scan.is_roc)
2835 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002836 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002837 case ATH10K_SCAN_ABORTING:
2838 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002839 ieee80211_scan_completed(ar->hw,
2840 (ar->scan.state ==
2841 ATH10K_SCAN_ABORTING));
2842 /* fall through */
2843 case ATH10K_SCAN_STARTING:
2844 ar->scan.state = ATH10K_SCAN_IDLE;
2845 ar->scan_channel = NULL;
2846 ath10k_offchan_tx_purge(ar);
2847 cancel_delayed_work(&ar->scan.timeout);
2848 complete_all(&ar->scan.completed);
2849 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002851}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002852
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002853void ath10k_scan_finish(struct ath10k *ar)
2854{
2855 spin_lock_bh(&ar->data_lock);
2856 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002857 spin_unlock_bh(&ar->data_lock);
2858}
2859
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002860static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861{
2862 struct wmi_stop_scan_arg arg = {
2863 .req_id = 1, /* FIXME */
2864 .req_type = WMI_SCAN_STOP_ONE,
2865 .u.scan_id = ATH10K_SCAN_ID,
2866 };
2867 int ret;
2868
2869 lockdep_assert_held(&ar->conf_mutex);
2870
Kalle Valo5e3dd152013-06-12 20:52:10 +03002871 ret = ath10k_wmi_stop_scan(ar, &arg);
2872 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002873 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002874 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002875 }
2876
Kalle Valo5e3dd152013-06-12 20:52:10 +03002877 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002878 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002879 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002880 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002881 } else if (ret > 0) {
2882 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002883 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002884
2885out:
2886 /* Scan state should be updated upon scan completion but in case
2887 * firmware fails to deliver the event (for whatever reason) it is
2888 * desired to clean up scan state anyway. Firmware may have just
2889 * dropped the scan completion event delivery due to transport pipe
2890 * being overflown with data and/or it can recover on its own before
2891 * next scan request is submitted.
2892 */
2893 spin_lock_bh(&ar->data_lock);
2894 if (ar->scan.state != ATH10K_SCAN_IDLE)
2895 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002896 spin_unlock_bh(&ar->data_lock);
2897
2898 return ret;
2899}
2900
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002901static void ath10k_scan_abort(struct ath10k *ar)
2902{
2903 int ret;
2904
2905 lockdep_assert_held(&ar->conf_mutex);
2906
2907 spin_lock_bh(&ar->data_lock);
2908
2909 switch (ar->scan.state) {
2910 case ATH10K_SCAN_IDLE:
2911 /* This can happen if timeout worker kicked in and called
2912 * abortion while scan completion was being processed.
2913 */
2914 break;
2915 case ATH10K_SCAN_STARTING:
2916 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002917 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002918 ath10k_scan_state_str(ar->scan.state),
2919 ar->scan.state);
2920 break;
2921 case ATH10K_SCAN_RUNNING:
2922 ar->scan.state = ATH10K_SCAN_ABORTING;
2923 spin_unlock_bh(&ar->data_lock);
2924
2925 ret = ath10k_scan_stop(ar);
2926 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002927 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002928
2929 spin_lock_bh(&ar->data_lock);
2930 break;
2931 }
2932
2933 spin_unlock_bh(&ar->data_lock);
2934}
2935
2936void ath10k_scan_timeout_work(struct work_struct *work)
2937{
2938 struct ath10k *ar = container_of(work, struct ath10k,
2939 scan.timeout.work);
2940
2941 mutex_lock(&ar->conf_mutex);
2942 ath10k_scan_abort(ar);
2943 mutex_unlock(&ar->conf_mutex);
2944}
2945
Kalle Valo5e3dd152013-06-12 20:52:10 +03002946static int ath10k_start_scan(struct ath10k *ar,
2947 const struct wmi_start_scan_arg *arg)
2948{
2949 int ret;
2950
2951 lockdep_assert_held(&ar->conf_mutex);
2952
2953 ret = ath10k_wmi_start_scan(ar, arg);
2954 if (ret)
2955 return ret;
2956
Kalle Valo5e3dd152013-06-12 20:52:10 +03002957 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2958 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002959 ret = ath10k_scan_stop(ar);
2960 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002961 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002962
2963 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002964 }
2965
Ben Greear2f9eec02015-02-15 16:50:38 +02002966 /* If we failed to start the scan, return error code at
2967 * this point. This is probably due to some issue in the
2968 * firmware, but no need to wedge the driver due to that...
2969 */
2970 spin_lock_bh(&ar->data_lock);
2971 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2972 spin_unlock_bh(&ar->data_lock);
2973 return -EINVAL;
2974 }
2975 spin_unlock_bh(&ar->data_lock);
2976
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002977 /* Add a 200ms margin to account for event/command processing */
2978 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2979 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002980 return 0;
2981}
2982
2983/**********************/
2984/* mac80211 callbacks */
2985/**********************/
2986
2987static void ath10k_tx(struct ieee80211_hw *hw,
2988 struct ieee80211_tx_control *control,
2989 struct sk_buff *skb)
2990{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002991 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002992 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2993 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002994 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03002995 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002996
2997 /* We should disable CCK RATE due to P2P */
2998 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002999 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003000
Michal Kazior4b604552014-07-21 21:03:09 +03003001 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003002 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003003 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003004 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003005 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, skb);
3006 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003007
Michal Kaziord740d8f2015-03-30 09:51:51 +03003008 switch (ATH10K_SKB_CB(skb)->txmode) {
3009 case ATH10K_HW_TXRX_MGMT:
3010 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003011 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003012 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3013 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003014 break;
3015 case ATH10K_HW_TXRX_ETHERNET:
3016 ath10k_tx_h_8023(skb);
3017 break;
3018 case ATH10K_HW_TXRX_RAW:
3019 /* FIXME: Packet injection isn't implemented. It should be
3020 * doable with firmware 10.2 on qca988x.
3021 */
3022 WARN_ON_ONCE(1);
3023 ieee80211_free_txskb(hw, skb);
3024 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003025 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003026
Kalle Valo5e3dd152013-06-12 20:52:10 +03003027 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3028 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003029 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003030 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003031 spin_unlock_bh(&ar->data_lock);
3032
Michal Kazior8d6d3622014-11-24 14:58:31 +01003033 if (ath10k_mac_need_offchan_tx_work(ar)) {
3034 ATH10K_SKB_CB(skb)->htt.freq = 0;
3035 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036
Michal Kazior8d6d3622014-11-24 14:58:31 +01003037 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3038 skb);
3039
3040 skb_queue_tail(&ar->offchan_tx_queue, skb);
3041 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3042 return;
3043 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003044 }
3045
Michal Kaziord740d8f2015-03-30 09:51:51 +03003046 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047}
3048
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003049/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003050void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003051{
3052 /* make sure rcu-protected mac80211 tx path itself is drained */
3053 synchronize_net();
3054
3055 ath10k_offchan_tx_purge(ar);
3056 ath10k_mgmt_over_wmi_tx_purge(ar);
3057
3058 cancel_work_sync(&ar->offchan_tx_work);
3059 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3060}
3061
Michal Kazioraffd3212013-07-16 09:54:35 +02003062void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003063{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003064 struct ath10k_vif *arvif;
3065
Michal Kazior818bdd12013-07-16 09:38:57 +02003066 lockdep_assert_held(&ar->conf_mutex);
3067
Michal Kazior19337472014-08-28 12:58:16 +02003068 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3069 ar->filter_flags = 0;
3070 ar->monitor = false;
3071
3072 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003073 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003074
3075 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003076
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003077 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003078 ath10k_peer_cleanup_all(ar);
3079 ath10k_core_stop(ar);
3080 ath10k_hif_power_down(ar);
3081
3082 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003083 list_for_each_entry(arvif, &ar->arvifs, list)
3084 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003085 spin_unlock_bh(&ar->data_lock);
3086}
3087
Ben Greear46acf7b2014-05-16 17:15:38 +03003088static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3089{
3090 struct ath10k *ar = hw->priv;
3091
3092 mutex_lock(&ar->conf_mutex);
3093
3094 if (ar->cfg_tx_chainmask) {
3095 *tx_ant = ar->cfg_tx_chainmask;
3096 *rx_ant = ar->cfg_rx_chainmask;
3097 } else {
3098 *tx_ant = ar->supp_tx_chainmask;
3099 *rx_ant = ar->supp_rx_chainmask;
3100 }
3101
3102 mutex_unlock(&ar->conf_mutex);
3103
3104 return 0;
3105}
3106
Ben Greear5572a952014-11-24 16:22:10 +02003107static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3108{
3109 /* It is not clear that allowing gaps in chainmask
3110 * is helpful. Probably it will not do what user
3111 * is hoping for, so warn in that case.
3112 */
3113 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3114 return;
3115
3116 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3117 dbg, cm);
3118}
3119
Ben Greear46acf7b2014-05-16 17:15:38 +03003120static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3121{
3122 int ret;
3123
3124 lockdep_assert_held(&ar->conf_mutex);
3125
Ben Greear5572a952014-11-24 16:22:10 +02003126 ath10k_check_chain_mask(ar, tx_ant, "tx");
3127 ath10k_check_chain_mask(ar, rx_ant, "rx");
3128
Ben Greear46acf7b2014-05-16 17:15:38 +03003129 ar->cfg_tx_chainmask = tx_ant;
3130 ar->cfg_rx_chainmask = rx_ant;
3131
3132 if ((ar->state != ATH10K_STATE_ON) &&
3133 (ar->state != ATH10K_STATE_RESTARTED))
3134 return 0;
3135
3136 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3137 tx_ant);
3138 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003139 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003140 ret, tx_ant);
3141 return ret;
3142 }
3143
3144 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3145 rx_ant);
3146 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003147 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003148 ret, rx_ant);
3149 return ret;
3150 }
3151
3152 return 0;
3153}
3154
3155static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3156{
3157 struct ath10k *ar = hw->priv;
3158 int ret;
3159
3160 mutex_lock(&ar->conf_mutex);
3161 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3162 mutex_unlock(&ar->conf_mutex);
3163 return ret;
3164}
3165
Kalle Valo5e3dd152013-06-12 20:52:10 +03003166static int ath10k_start(struct ieee80211_hw *hw)
3167{
3168 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003169 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003170
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003171 /*
3172 * This makes sense only when restarting hw. It is harmless to call
3173 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3174 * commands will be submitted while restarting.
3175 */
3176 ath10k_drain_tx(ar);
3177
Michal Kazior548db542013-07-05 16:15:15 +03003178 mutex_lock(&ar->conf_mutex);
3179
Michal Kaziorc5058f52014-05-26 12:46:03 +03003180 switch (ar->state) {
3181 case ATH10K_STATE_OFF:
3182 ar->state = ATH10K_STATE_ON;
3183 break;
3184 case ATH10K_STATE_RESTARTING:
3185 ath10k_halt(ar);
3186 ar->state = ATH10K_STATE_RESTARTED;
3187 break;
3188 case ATH10K_STATE_ON:
3189 case ATH10K_STATE_RESTARTED:
3190 case ATH10K_STATE_WEDGED:
3191 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003192 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003193 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003194 case ATH10K_STATE_UTF:
3195 ret = -EBUSY;
3196 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003197 }
3198
3199 ret = ath10k_hif_power_up(ar);
3200 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003201 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003202 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003203 }
3204
Kalle Valo43d2a302014-09-10 18:23:30 +03003205 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003206 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003207 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003208 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003209 }
3210
Bartosz Markowski226a3392013-09-26 17:47:16 +02003211 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003212 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003213 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003214 goto err_core_stop;
3215 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003217 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003218 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003219 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003220 goto err_core_stop;
3221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003222
Ben Greear46acf7b2014-05-16 17:15:38 +03003223 if (ar->cfg_tx_chainmask)
3224 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3225 ar->cfg_rx_chainmask);
3226
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003227 /*
3228 * By default FW set ARP frames ac to voice (6). In that case ARP
3229 * exchange is not working properly for UAPSD enabled AP. ARP requests
3230 * which arrives with access category 0 are processed by network stack
3231 * and send back with access category 0, but FW changes access category
3232 * to 6. Set ARP frames access category to best effort (0) solves
3233 * this problem.
3234 */
3235
3236 ret = ath10k_wmi_pdev_set_param(ar,
3237 ar->wmi.pdev_param->arp_ac_override, 0);
3238 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003239 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003240 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003241 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003242 }
3243
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303244 ret = ath10k_wmi_pdev_set_param(ar,
3245 ar->wmi.pdev_param->ani_enable, 1);
3246 if (ret) {
3247 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3248 ret);
3249 goto err_core_stop;
3250 }
3251
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303252 ar->ani_enabled = true;
3253
Michal Kaziord6500972014-04-08 09:56:09 +03003254 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003255 ath10k_regd_update(ar);
3256
Simon Wunderlich855aed12014-08-02 09:12:54 +03003257 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303258 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003259
Michal Kaziorae254432014-05-26 12:46:02 +03003260 mutex_unlock(&ar->conf_mutex);
3261 return 0;
3262
3263err_core_stop:
3264 ath10k_core_stop(ar);
3265
3266err_power_down:
3267 ath10k_hif_power_down(ar);
3268
3269err_off:
3270 ar->state = ATH10K_STATE_OFF;
3271
3272err:
Michal Kazior548db542013-07-05 16:15:15 +03003273 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003274 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003275}
3276
3277static void ath10k_stop(struct ieee80211_hw *hw)
3278{
3279 struct ath10k *ar = hw->priv;
3280
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003281 ath10k_drain_tx(ar);
3282
Michal Kazior548db542013-07-05 16:15:15 +03003283 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003284 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003285 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003286 ar->state = ATH10K_STATE_OFF;
3287 }
Michal Kazior548db542013-07-05 16:15:15 +03003288 mutex_unlock(&ar->conf_mutex);
3289
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003290 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003291 cancel_work_sync(&ar->restart_work);
3292}
3293
Michal Kaziorad088bf2013-10-16 15:44:46 +03003294static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003295{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003296 struct ath10k_vif *arvif;
3297 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003298
3299 lockdep_assert_held(&ar->conf_mutex);
3300
Michal Kaziorad088bf2013-10-16 15:44:46 +03003301 list_for_each_entry(arvif, &ar->arvifs, list) {
3302 ret = ath10k_mac_vif_setup_ps(arvif);
3303 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003304 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003305 break;
3306 }
3307 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003308
Michal Kaziorad088bf2013-10-16 15:44:46 +03003309 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003310}
3311
Michal Kaziorc930f742014-01-23 11:38:25 +01003312static const char *chandef_get_width(enum nl80211_chan_width width)
3313{
3314 switch (width) {
3315 case NL80211_CHAN_WIDTH_20_NOHT:
3316 return "20 (noht)";
3317 case NL80211_CHAN_WIDTH_20:
3318 return "20";
3319 case NL80211_CHAN_WIDTH_40:
3320 return "40";
3321 case NL80211_CHAN_WIDTH_80:
3322 return "80";
3323 case NL80211_CHAN_WIDTH_80P80:
3324 return "80+80";
3325 case NL80211_CHAN_WIDTH_160:
3326 return "160";
3327 case NL80211_CHAN_WIDTH_5:
3328 return "5";
3329 case NL80211_CHAN_WIDTH_10:
3330 return "10";
3331 }
3332 return "?";
3333}
3334
3335static void ath10k_config_chan(struct ath10k *ar)
3336{
3337 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003338 int ret;
3339
3340 lockdep_assert_held(&ar->conf_mutex);
3341
Michal Kazior7aa7a722014-08-25 12:09:38 +02003342 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003343 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3344 ar->chandef.chan->center_freq,
3345 ar->chandef.center_freq1,
3346 ar->chandef.center_freq2,
3347 chandef_get_width(ar->chandef.width));
3348
3349 /* First stop monitor interface. Some FW versions crash if there's a
3350 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003351 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003352 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003353
3354 list_for_each_entry(arvif, &ar->arvifs, list) {
3355 if (!arvif->is_started)
3356 continue;
3357
Michal Kaziordc55e302014-07-29 12:53:36 +03003358 if (!arvif->is_up)
3359 continue;
3360
Michal Kaziorc930f742014-01-23 11:38:25 +01003361 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3362 continue;
3363
Michal Kaziordc55e302014-07-29 12:53:36 +03003364 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003365 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003366 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003367 arvif->vdev_id, ret);
3368 continue;
3369 }
3370 }
3371
Michal Kaziordc55e302014-07-29 12:53:36 +03003372 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003373
3374 list_for_each_entry(arvif, &ar->arvifs, list) {
3375 if (!arvif->is_started)
3376 continue;
3377
3378 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3379 continue;
3380
Michal Kazior81a9a172015-03-05 16:02:17 +02003381 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3382 if (ret)
3383 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3384 ret);
3385
3386 ret = ath10k_mac_setup_prb_tmpl(arvif);
3387 if (ret)
3388 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3389 ret);
3390
Michal Kaziordc55e302014-07-29 12:53:36 +03003391 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003392 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003393 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003394 arvif->vdev_id, ret);
3395 continue;
3396 }
3397
3398 if (!arvif->is_up)
3399 continue;
3400
3401 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3402 arvif->bssid);
3403 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003404 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003405 arvif->vdev_id, ret);
3406 continue;
3407 }
3408 }
3409
Michal Kazior19337472014-08-28 12:58:16 +02003410 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003411}
3412
Michal Kazior7d9d5582014-10-21 10:40:15 +03003413static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3414{
3415 int ret;
3416 u32 param;
3417
3418 lockdep_assert_held(&ar->conf_mutex);
3419
3420 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3421
3422 param = ar->wmi.pdev_param->txpower_limit2g;
3423 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3424 if (ret) {
3425 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3426 txpower, ret);
3427 return ret;
3428 }
3429
3430 param = ar->wmi.pdev_param->txpower_limit5g;
3431 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3432 if (ret) {
3433 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3434 txpower, ret);
3435 return ret;
3436 }
3437
3438 return 0;
3439}
3440
3441static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3442{
3443 struct ath10k_vif *arvif;
3444 int ret, txpower = -1;
3445
3446 lockdep_assert_held(&ar->conf_mutex);
3447
3448 list_for_each_entry(arvif, &ar->arvifs, list) {
3449 WARN_ON(arvif->txpower < 0);
3450
3451 if (txpower == -1)
3452 txpower = arvif->txpower;
3453 else
3454 txpower = min(txpower, arvif->txpower);
3455 }
3456
3457 if (WARN_ON(txpower == -1))
3458 return -EINVAL;
3459
3460 ret = ath10k_mac_txpower_setup(ar, txpower);
3461 if (ret) {
3462 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3463 txpower, ret);
3464 return ret;
3465 }
3466
3467 return 0;
3468}
3469
Kalle Valo5e3dd152013-06-12 20:52:10 +03003470static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3471{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003472 struct ath10k *ar = hw->priv;
3473 struct ieee80211_conf *conf = &hw->conf;
3474 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475
3476 mutex_lock(&ar->conf_mutex);
3477
3478 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003479 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003480 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003481 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003482 conf->chandef.chan->flags,
3483 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003484
Kalle Valo5e3dd152013-06-12 20:52:10 +03003485 spin_lock_bh(&ar->data_lock);
3486 ar->rx_channel = conf->chandef.chan;
3487 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003488
Michal Kaziord6500972014-04-08 09:56:09 +03003489 ar->radar_enabled = conf->radar_enabled;
3490 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003491
3492 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3493 ar->chandef = conf->chandef;
3494 ath10k_config_chan(ar);
3495 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003496 }
3497
Michal Kazioraffd3212013-07-16 09:54:35 +02003498 if (changed & IEEE80211_CONF_CHANGE_PS)
3499 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500
3501 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003502 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3503 ret = ath10k_monitor_recalc(ar);
3504 if (ret)
3505 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003506 }
3507
3508 mutex_unlock(&ar->conf_mutex);
3509 return ret;
3510}
3511
Ben Greear5572a952014-11-24 16:22:10 +02003512static u32 get_nss_from_chainmask(u16 chain_mask)
3513{
3514 if ((chain_mask & 0x15) == 0x15)
3515 return 4;
3516 else if ((chain_mask & 0x7) == 0x7)
3517 return 3;
3518 else if ((chain_mask & 0x3) == 0x3)
3519 return 2;
3520 return 1;
3521}
3522
Kalle Valo5e3dd152013-06-12 20:52:10 +03003523/*
3524 * TODO:
3525 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3526 * because we will send mgmt frames without CCK. This requirement
3527 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3528 * in the TX packet.
3529 */
3530static int ath10k_add_interface(struct ieee80211_hw *hw,
3531 struct ieee80211_vif *vif)
3532{
3533 struct ath10k *ar = hw->priv;
3534 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3535 enum wmi_sta_powersave_param param;
3536 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003537 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003539 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540
Johannes Berg848955c2014-11-11 12:48:42 +01003541 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3542
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543 mutex_lock(&ar->conf_mutex);
3544
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003545 memset(arvif, 0, sizeof(*arvif));
3546
Kalle Valo5e3dd152013-06-12 20:52:10 +03003547 arvif->ar = ar;
3548 arvif->vif = vif;
3549
Ben Greeare63b33f2013-10-22 14:54:14 -07003550 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003551 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003552 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3553 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003554
Ben Greeara9aefb32014-08-12 11:02:19 +03003555 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003556 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003558 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003559 }
Ben Greear16c11172014-09-23 14:17:16 -07003560 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561
Ben Greear16c11172014-09-23 14:17:16 -07003562 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3563 bit, ar->free_vdev_map);
3564
3565 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003566 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003569 case NL80211_IFTYPE_P2P_DEVICE:
3570 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3571 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3572 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003573 case NL80211_IFTYPE_UNSPECIFIED:
3574 case NL80211_IFTYPE_STATION:
3575 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3576 if (vif->p2p)
3577 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3578 break;
3579 case NL80211_IFTYPE_ADHOC:
3580 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3581 break;
3582 case NL80211_IFTYPE_AP:
3583 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3584
3585 if (vif->p2p)
3586 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3587 break;
3588 case NL80211_IFTYPE_MONITOR:
3589 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3590 break;
3591 default:
3592 WARN_ON(1);
3593 break;
3594 }
3595
Michal Kazior64badcb2014-09-18 11:18:02 +03003596 /* Some firmware revisions don't wait for beacon tx completion before
3597 * sending another SWBA event. This could lead to hardware using old
3598 * (freed) beacon data in some cases, e.g. tx credit starvation
3599 * combined with missed TBTT. This is very very rare.
3600 *
3601 * On non-IOMMU-enabled hosts this could be a possible security issue
3602 * because hw could beacon some random data on the air. On
3603 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3604 * device would crash.
3605 *
3606 * Since there are no beacon tx completions (implicit nor explicit)
3607 * propagated to host the only workaround for this is to allocate a
3608 * DMA-coherent buffer for a lifetime of a vif and use it for all
3609 * beacon tx commands. Worst case for this approach is some beacons may
3610 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3611 */
3612 if (vif->type == NL80211_IFTYPE_ADHOC ||
3613 vif->type == NL80211_IFTYPE_AP) {
3614 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3615 IEEE80211_MAX_FRAME_LEN,
3616 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303617 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003618 if (!arvif->beacon_buf) {
3619 ret = -ENOMEM;
3620 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3621 ret);
3622 goto err;
3623 }
3624 }
3625
3626 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3627 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3628 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003629
3630 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3631 arvif->vdev_subtype, vif->addr);
3632 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003633 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003634 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003635 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003636 }
3637
Ben Greear16c11172014-09-23 14:17:16 -07003638 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003639 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003640
Michal Kazior46725b152015-01-28 09:57:49 +02003641 /* It makes no sense to have firmware do keepalives. mac80211 already
3642 * takes care of this with idle connection polling.
3643 */
3644 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003645 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003646 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003647 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003648 goto err_vdev_delete;
3649 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003651 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003652
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003653 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3654 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003656 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003657 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003658 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003659 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003660 goto err_vdev_delete;
3661 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003662
Ben Greear5572a952014-11-24 16:22:10 +02003663 if (ar->cfg_tx_chainmask) {
3664 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3665
3666 vdev_param = ar->wmi.vdev_param->nss;
3667 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3668 nss);
3669 if (ret) {
3670 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3671 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3672 ret);
3673 goto err_vdev_delete;
3674 }
3675 }
3676
Kalle Valo5e3dd152013-06-12 20:52:10 +03003677 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3678 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3679 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003680 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003681 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003682 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003683 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003684
Kalle Valo5a13e762014-01-20 11:01:46 +02003685 ret = ath10k_mac_set_kickout(arvif);
3686 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003687 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003688 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003689 goto err_peer_delete;
3690 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003691 }
3692
3693 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3694 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3695 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3696 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3697 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003698 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003699 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003700 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003701 goto err_peer_delete;
3702 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003703
Michal Kazior9f9b5742014-12-12 12:41:36 +01003704 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003705 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003706 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003707 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003708 goto err_peer_delete;
3709 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710
Michal Kazior9f9b5742014-12-12 12:41:36 +01003711 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003712 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003713 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003714 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003715 goto err_peer_delete;
3716 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003717 }
3718
Michal Kazior424121c2013-07-22 14:13:31 +02003719 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003720 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003721 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003722 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003723 goto err_peer_delete;
3724 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003725
Michal Kazior424121c2013-07-22 14:13:31 +02003726 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003727 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003728 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003729 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003730 goto err_peer_delete;
3731 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003732
Michal Kazior7d9d5582014-10-21 10:40:15 +03003733 arvif->txpower = vif->bss_conf.txpower;
3734 ret = ath10k_mac_txpower_recalc(ar);
3735 if (ret) {
3736 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3737 goto err_peer_delete;
3738 }
3739
Kalle Valo5e3dd152013-06-12 20:52:10 +03003740 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003741 return 0;
3742
3743err_peer_delete:
3744 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3745 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3746
3747err_vdev_delete:
3748 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003749 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003750 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003751
3752err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003753 if (arvif->beacon_buf) {
3754 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3755 arvif->beacon_buf, arvif->beacon_paddr);
3756 arvif->beacon_buf = NULL;
3757 }
3758
Michal Kazior9dad14a2013-10-16 15:44:45 +03003759 mutex_unlock(&ar->conf_mutex);
3760
Kalle Valo5e3dd152013-06-12 20:52:10 +03003761 return ret;
3762}
3763
3764static void ath10k_remove_interface(struct ieee80211_hw *hw,
3765 struct ieee80211_vif *vif)
3766{
3767 struct ath10k *ar = hw->priv;
3768 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3769 int ret;
3770
Michal Kazior81a9a172015-03-05 16:02:17 +02003771 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003772 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003773
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303774 mutex_lock(&ar->conf_mutex);
3775
Michal Kaziored543882013-09-13 14:16:56 +02003776 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003777 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003778 spin_unlock_bh(&ar->data_lock);
3779
Simon Wunderlich855aed12014-08-02 09:12:54 +03003780 ret = ath10k_spectral_vif_stop(arvif);
3781 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003782 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003783 arvif->vdev_id, ret);
3784
Ben Greear16c11172014-09-23 14:17:16 -07003785 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003786 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003787
3788 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003789 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3790 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003791 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003792 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003793 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003794
3795 kfree(arvif->u.ap.noa_data);
3796 }
3797
Michal Kazior7aa7a722014-08-25 12:09:38 +02003798 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003799 arvif->vdev_id);
3800
Kalle Valo5e3dd152013-06-12 20:52:10 +03003801 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3802 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003803 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003804 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805
Michal Kazior2c512052015-02-15 16:50:40 +02003806 /* Some firmware revisions don't notify host about self-peer removal
3807 * until after associated vdev is deleted.
3808 */
3809 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3810 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3811 vif->addr);
3812 if (ret)
3813 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3814 arvif->vdev_id, ret);
3815
3816 spin_lock_bh(&ar->data_lock);
3817 ar->num_peers--;
3818 spin_unlock_bh(&ar->data_lock);
3819 }
3820
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821 ath10k_peer_cleanup(ar, arvif->vdev_id);
3822
3823 mutex_unlock(&ar->conf_mutex);
3824}
3825
3826/*
3827 * FIXME: Has to be verified.
3828 */
3829#define SUPPORTED_FILTERS \
3830 (FIF_PROMISC_IN_BSS | \
3831 FIF_ALLMULTI | \
3832 FIF_CONTROL | \
3833 FIF_PSPOLL | \
3834 FIF_OTHER_BSS | \
3835 FIF_BCN_PRBRESP_PROMISC | \
3836 FIF_PROBE_REQ | \
3837 FIF_FCSFAIL)
3838
3839static void ath10k_configure_filter(struct ieee80211_hw *hw,
3840 unsigned int changed_flags,
3841 unsigned int *total_flags,
3842 u64 multicast)
3843{
3844 struct ath10k *ar = hw->priv;
3845 int ret;
3846
3847 mutex_lock(&ar->conf_mutex);
3848
3849 changed_flags &= SUPPORTED_FILTERS;
3850 *total_flags &= SUPPORTED_FILTERS;
3851 ar->filter_flags = *total_flags;
3852
Michal Kazior19337472014-08-28 12:58:16 +02003853 ret = ath10k_monitor_recalc(ar);
3854 if (ret)
3855 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003856
3857 mutex_unlock(&ar->conf_mutex);
3858}
3859
3860static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3861 struct ieee80211_vif *vif,
3862 struct ieee80211_bss_conf *info,
3863 u32 changed)
3864{
3865 struct ath10k *ar = hw->priv;
3866 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3867 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003868 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869
3870 mutex_lock(&ar->conf_mutex);
3871
3872 if (changed & BSS_CHANGED_IBSS)
3873 ath10k_control_ibss(arvif, info, vif->addr);
3874
3875 if (changed & BSS_CHANGED_BEACON_INT) {
3876 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003877 vdev_param = ar->wmi.vdev_param->beacon_interval;
3878 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003880 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003881 "mac vdev %d beacon_interval %d\n",
3882 arvif->vdev_id, arvif->beacon_interval);
3883
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003885 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003886 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003887 }
3888
3889 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003890 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003891 "vdev %d set beacon tx mode to staggered\n",
3892 arvif->vdev_id);
3893
Bartosz Markowski226a3392013-09-26 17:47:16 +02003894 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3895 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003896 WMI_BEACON_STAGGERED_MODE);
3897 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003898 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003899 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003900
3901 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3902 if (ret)
3903 ath10k_warn(ar, "failed to update beacon template: %d\n",
3904 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003905 }
3906
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003907 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3908 ret = ath10k_mac_setup_prb_tmpl(arvif);
3909 if (ret)
3910 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3911 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003912 }
3913
Michal Kaziorba2479f2015-01-24 12:14:51 +02003914 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915 arvif->dtim_period = info->dtim_period;
3916
Michal Kazior7aa7a722014-08-25 12:09:38 +02003917 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003918 "mac vdev %d dtim_period %d\n",
3919 arvif->vdev_id, arvif->dtim_period);
3920
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003921 vdev_param = ar->wmi.vdev_param->dtim_period;
3922 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003923 arvif->dtim_period);
3924 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003925 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003926 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927 }
3928
3929 if (changed & BSS_CHANGED_SSID &&
3930 vif->type == NL80211_IFTYPE_AP) {
3931 arvif->u.ap.ssid_len = info->ssid_len;
3932 if (info->ssid_len)
3933 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3934 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3935 }
3936
Michal Kazior077efc82014-10-21 10:10:29 +03003937 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3938 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003939
3940 if (changed & BSS_CHANGED_BEACON_ENABLED)
3941 ath10k_control_beaconing(arvif, info);
3942
3943 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003944 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003945 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003946 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003947
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003948 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003949 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003950 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003951 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003952
3953 vdev_param = ar->wmi.vdev_param->protection_mode;
3954 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3955 info->use_cts_prot ? 1 : 0);
3956 if (ret)
3957 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3958 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003959 }
3960
3961 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 if (info->use_short_slot)
3963 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3964
3965 else
3966 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3967
Michal Kazior7aa7a722014-08-25 12:09:38 +02003968 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003969 arvif->vdev_id, slottime);
3970
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003971 vdev_param = ar->wmi.vdev_param->slot_time;
3972 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973 slottime);
3974 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003975 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003976 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977 }
3978
3979 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003980 if (info->use_short_preamble)
3981 preamble = WMI_VDEV_PREAMBLE_SHORT;
3982 else
3983 preamble = WMI_VDEV_PREAMBLE_LONG;
3984
Michal Kazior7aa7a722014-08-25 12:09:38 +02003985 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003986 "mac vdev %d preamble %dn",
3987 arvif->vdev_id, preamble);
3988
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003989 vdev_param = ar->wmi.vdev_param->preamble;
3990 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003991 preamble);
3992 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003993 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003994 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 }
3996
3997 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003998 if (info->assoc) {
3999 /* Workaround: Make sure monitor vdev is not running
4000 * when associating to prevent some firmware revisions
4001 * (e.g. 10.1 and 10.2) from crashing.
4002 */
4003 if (ar->monitor_started)
4004 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004005 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004006 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004007 } else {
4008 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004009 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 }
4011
Michal Kazior7d9d5582014-10-21 10:40:15 +03004012 if (changed & BSS_CHANGED_TXPOWER) {
4013 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4014 arvif->vdev_id, info->txpower);
4015
4016 arvif->txpower = info->txpower;
4017 ret = ath10k_mac_txpower_recalc(ar);
4018 if (ret)
4019 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4020 }
4021
Michal Kaziorbf14e652014-12-12 12:41:38 +01004022 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004023 arvif->ps = vif->bss_conf.ps;
4024
4025 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004026 if (ret)
4027 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4028 arvif->vdev_id, ret);
4029 }
4030
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 mutex_unlock(&ar->conf_mutex);
4032}
4033
4034static int ath10k_hw_scan(struct ieee80211_hw *hw,
4035 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004036 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037{
4038 struct ath10k *ar = hw->priv;
4039 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004040 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041 struct wmi_start_scan_arg arg;
4042 int ret = 0;
4043 int i;
4044
4045 mutex_lock(&ar->conf_mutex);
4046
4047 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004048 switch (ar->scan.state) {
4049 case ATH10K_SCAN_IDLE:
4050 reinit_completion(&ar->scan.started);
4051 reinit_completion(&ar->scan.completed);
4052 ar->scan.state = ATH10K_SCAN_STARTING;
4053 ar->scan.is_roc = false;
4054 ar->scan.vdev_id = arvif->vdev_id;
4055 ret = 0;
4056 break;
4057 case ATH10K_SCAN_STARTING:
4058 case ATH10K_SCAN_RUNNING:
4059 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004060 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004061 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004062 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004063 spin_unlock_bh(&ar->data_lock);
4064
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004065 if (ret)
4066 goto exit;
4067
Kalle Valo5e3dd152013-06-12 20:52:10 +03004068 memset(&arg, 0, sizeof(arg));
4069 ath10k_wmi_start_scan_init(ar, &arg);
4070 arg.vdev_id = arvif->vdev_id;
4071 arg.scan_id = ATH10K_SCAN_ID;
4072
4073 if (!req->no_cck)
4074 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4075
4076 if (req->ie_len) {
4077 arg.ie_len = req->ie_len;
4078 memcpy(arg.ie, req->ie, arg.ie_len);
4079 }
4080
4081 if (req->n_ssids) {
4082 arg.n_ssids = req->n_ssids;
4083 for (i = 0; i < arg.n_ssids; i++) {
4084 arg.ssids[i].len = req->ssids[i].ssid_len;
4085 arg.ssids[i].ssid = req->ssids[i].ssid;
4086 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004087 } else {
4088 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004089 }
4090
4091 if (req->n_channels) {
4092 arg.n_channels = req->n_channels;
4093 for (i = 0; i < arg.n_channels; i++)
4094 arg.channels[i] = req->channels[i]->center_freq;
4095 }
4096
4097 ret = ath10k_start_scan(ar, &arg);
4098 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004099 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004101 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004102 spin_unlock_bh(&ar->data_lock);
4103 }
4104
4105exit:
4106 mutex_unlock(&ar->conf_mutex);
4107 return ret;
4108}
4109
4110static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4111 struct ieee80211_vif *vif)
4112{
4113 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004114
4115 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004116 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004118
4119 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004120}
4121
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004122static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4123 struct ath10k_vif *arvif,
4124 enum set_key_cmd cmd,
4125 struct ieee80211_key_conf *key)
4126{
4127 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4128 int ret;
4129
4130 /* 10.1 firmware branch requires default key index to be set to group
4131 * key index after installing it. Otherwise FW/HW Txes corrupted
4132 * frames with multi-vif APs. This is not required for main firmware
4133 * branch (e.g. 636).
4134 *
4135 * FIXME: This has been tested only in AP. It remains unknown if this
4136 * is required for multi-vif STA interfaces on 10.1 */
4137
4138 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4139 return;
4140
4141 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4142 return;
4143
4144 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4145 return;
4146
4147 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4148 return;
4149
4150 if (cmd != SET_KEY)
4151 return;
4152
4153 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4154 key->keyidx);
4155 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004156 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004157 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004158}
4159
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4161 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4162 struct ieee80211_key_conf *key)
4163{
4164 struct ath10k *ar = hw->priv;
4165 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4166 struct ath10k_peer *peer;
4167 const u8 *peer_addr;
4168 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4169 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4170 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004171 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004172
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004173 /* this one needs to be done in software */
4174 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4175 return 1;
4176
Kalle Valo5e3dd152013-06-12 20:52:10 +03004177 if (key->keyidx > WMI_MAX_KEY_INDEX)
4178 return -ENOSPC;
4179
4180 mutex_lock(&ar->conf_mutex);
4181
4182 if (sta)
4183 peer_addr = sta->addr;
4184 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4185 peer_addr = vif->bss_conf.bssid;
4186 else
4187 peer_addr = vif->addr;
4188
4189 key->hw_key_idx = key->keyidx;
4190
4191 /* the peer should not disappear in mid-way (unless FW goes awry) since
4192 * we already hold conf_mutex. we just make sure its there now. */
4193 spin_lock_bh(&ar->data_lock);
4194 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4195 spin_unlock_bh(&ar->data_lock);
4196
4197 if (!peer) {
4198 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004199 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004200 peer_addr);
4201 ret = -EOPNOTSUPP;
4202 goto exit;
4203 } else {
4204 /* if the peer doesn't exist there is no key to disable
4205 * anymore */
4206 goto exit;
4207 }
4208 }
4209
Michal Kazior7cc45732015-03-09 14:24:17 +01004210 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4211 flags |= WMI_KEY_PAIRWISE;
4212 else
4213 flags |= WMI_KEY_GROUP;
4214
Kalle Valo5e3dd152013-06-12 20:52:10 +03004215 if (is_wep) {
4216 if (cmd == SET_KEY)
4217 arvif->wep_keys[key->keyidx] = key;
4218 else
4219 arvif->wep_keys[key->keyidx] = NULL;
4220
4221 if (cmd == DISABLE_KEY)
4222 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004223
Michal Kaziorad325cb2015-02-18 14:02:27 +01004224 /* When WEP keys are uploaded it's possible that there are
4225 * stations associated already (e.g. when merging) without any
4226 * keys. Static WEP needs an explicit per-peer key upload.
4227 */
4228 if (vif->type == NL80211_IFTYPE_ADHOC &&
4229 cmd == SET_KEY)
4230 ath10k_mac_vif_update_wep_key(arvif, key);
4231
Michal Kazior370e5672015-02-18 14:02:26 +01004232 /* 802.1x never sets the def_wep_key_idx so each set_key()
4233 * call changes default tx key.
4234 *
4235 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4236 * after first set_key().
4237 */
4238 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4239 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004240
Michal Kazior7cc45732015-03-09 14:24:17 +01004241 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4242 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4243 * mode and associated stations in AP/IBSS.
4244 *
4245 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4246 * work fine when mapped directly from mac80211.
4247 *
4248 * Note: When installing first static WEP groupwise key (which
4249 * should be pairwise) def_wep_key_idx isn't known yet (it's
4250 * equal to -1). Since .set_default_unicast_key is called only
4251 * for static WEP it's used to re-upload the key as pairwise.
4252 */
4253 if (arvif->def_wep_key_idx >= 0 &&
4254 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4255 flags &= ~WMI_KEY_GROUP;
4256 flags |= WMI_KEY_PAIRWISE;
4257 }
Michal Kazior370e5672015-02-18 14:02:26 +01004258 }
4259
4260 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004261 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004262 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004263 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004264 goto exit;
4265 }
4266
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004267 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4268
Kalle Valo5e3dd152013-06-12 20:52:10 +03004269 spin_lock_bh(&ar->data_lock);
4270 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4271 if (peer && cmd == SET_KEY)
4272 peer->keys[key->keyidx] = key;
4273 else if (peer && cmd == DISABLE_KEY)
4274 peer->keys[key->keyidx] = NULL;
4275 else if (peer == NULL)
4276 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004277 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004278 spin_unlock_bh(&ar->data_lock);
4279
4280exit:
4281 mutex_unlock(&ar->conf_mutex);
4282 return ret;
4283}
4284
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004285static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4286 struct ieee80211_vif *vif,
4287 int keyidx)
4288{
4289 struct ath10k *ar = hw->priv;
4290 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4291 int ret;
4292
4293 mutex_lock(&arvif->ar->conf_mutex);
4294
4295 if (arvif->ar->state != ATH10K_STATE_ON)
4296 goto unlock;
4297
4298 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4299 arvif->vdev_id, keyidx);
4300
4301 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4302 arvif->vdev_id,
4303 arvif->ar->wmi.vdev_param->def_keyid,
4304 keyidx);
4305
4306 if (ret) {
4307 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4308 arvif->vdev_id,
4309 ret);
4310 goto unlock;
4311 }
4312
4313 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004314
4315 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4316 if (ret) {
4317 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4318 arvif->vdev_id, ret);
4319 goto unlock;
4320 }
4321
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004322unlock:
4323 mutex_unlock(&arvif->ar->conf_mutex);
4324}
4325
Michal Kazior9797feb2014-02-14 14:49:48 +01004326static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4327{
4328 struct ath10k *ar;
4329 struct ath10k_vif *arvif;
4330 struct ath10k_sta *arsta;
4331 struct ieee80211_sta *sta;
4332 u32 changed, bw, nss, smps;
4333 int err;
4334
4335 arsta = container_of(wk, struct ath10k_sta, update_wk);
4336 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4337 arvif = arsta->arvif;
4338 ar = arvif->ar;
4339
4340 spin_lock_bh(&ar->data_lock);
4341
4342 changed = arsta->changed;
4343 arsta->changed = 0;
4344
4345 bw = arsta->bw;
4346 nss = arsta->nss;
4347 smps = arsta->smps;
4348
4349 spin_unlock_bh(&ar->data_lock);
4350
4351 mutex_lock(&ar->conf_mutex);
4352
4353 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004354 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004355 sta->addr, bw);
4356
4357 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4358 WMI_PEER_CHAN_WIDTH, bw);
4359 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004360 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004361 sta->addr, bw, err);
4362 }
4363
4364 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004365 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004366 sta->addr, nss);
4367
4368 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4369 WMI_PEER_NSS, nss);
4370 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004371 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004372 sta->addr, nss, err);
4373 }
4374
4375 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004376 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004377 sta->addr, smps);
4378
4379 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4380 WMI_PEER_SMPS_STATE, smps);
4381 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004382 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004383 sta->addr, smps, err);
4384 }
4385
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004386 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4387 changed & IEEE80211_RC_NSS_CHANGED) {
4388 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004389 sta->addr);
4390
Michal Kazior590922a2014-10-21 10:10:29 +03004391 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004392 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004393 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004394 sta->addr);
4395 }
4396
Michal Kazior9797feb2014-02-14 14:49:48 +01004397 mutex_unlock(&ar->conf_mutex);
4398}
4399
Michal Kaziorcfd10612014-11-25 15:16:05 +01004400static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4401{
4402 struct ath10k *ar = arvif->ar;
4403
4404 lockdep_assert_held(&ar->conf_mutex);
4405
4406 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4407 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4408 return 0;
4409
4410 if (ar->num_stations >= ar->max_num_stations)
4411 return -ENOBUFS;
4412
4413 ar->num_stations++;
4414
4415 return 0;
4416}
4417
4418static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4419{
4420 struct ath10k *ar = arvif->ar;
4421
4422 lockdep_assert_held(&ar->conf_mutex);
4423
4424 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4425 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4426 return;
4427
4428 ar->num_stations--;
4429}
4430
Kalle Valo5e3dd152013-06-12 20:52:10 +03004431static int ath10k_sta_state(struct ieee80211_hw *hw,
4432 struct ieee80211_vif *vif,
4433 struct ieee80211_sta *sta,
4434 enum ieee80211_sta_state old_state,
4435 enum ieee80211_sta_state new_state)
4436{
4437 struct ath10k *ar = hw->priv;
4438 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004439 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004440 int ret = 0;
4441
Michal Kazior76f90022014-02-25 09:29:57 +02004442 if (old_state == IEEE80211_STA_NOTEXIST &&
4443 new_state == IEEE80211_STA_NONE) {
4444 memset(arsta, 0, sizeof(*arsta));
4445 arsta->arvif = arvif;
4446 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4447 }
4448
Michal Kazior9797feb2014-02-14 14:49:48 +01004449 /* cancel must be done outside the mutex to avoid deadlock */
4450 if ((old_state == IEEE80211_STA_NONE &&
4451 new_state == IEEE80211_STA_NOTEXIST))
4452 cancel_work_sync(&arsta->update_wk);
4453
Kalle Valo5e3dd152013-06-12 20:52:10 +03004454 mutex_lock(&ar->conf_mutex);
4455
4456 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004457 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004458 /*
4459 * New station addition.
4460 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004461 ath10k_dbg(ar, ATH10K_DBG_MAC,
4462 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4463 arvif->vdev_id, sta->addr,
4464 ar->num_stations + 1, ar->max_num_stations,
4465 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004466
Michal Kaziorcfd10612014-11-25 15:16:05 +01004467 ret = ath10k_mac_inc_num_stations(arvif);
4468 if (ret) {
4469 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4470 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004471 goto exit;
4472 }
4473
Kalle Valo5e3dd152013-06-12 20:52:10 +03004474 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004475 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004476 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 -08004477 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004478 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004479 goto exit;
4480 }
Michal Kazior077efc82014-10-21 10:10:29 +03004481
4482 if (vif->type == NL80211_IFTYPE_STATION) {
4483 WARN_ON(arvif->is_started);
4484
4485 ret = ath10k_vdev_start(arvif);
4486 if (ret) {
4487 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4488 arvif->vdev_id, ret);
4489 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4490 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004491 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004492 goto exit;
4493 }
4494
4495 arvif->is_started = true;
4496 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004497 } else if ((old_state == IEEE80211_STA_NONE &&
4498 new_state == IEEE80211_STA_NOTEXIST)) {
4499 /*
4500 * Existing station deletion.
4501 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004502 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004503 "mac vdev %d peer delete %pM (sta gone)\n",
4504 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004505
4506 if (vif->type == NL80211_IFTYPE_STATION) {
4507 WARN_ON(!arvif->is_started);
4508
4509 ret = ath10k_vdev_stop(arvif);
4510 if (ret)
4511 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4512 arvif->vdev_id, ret);
4513
4514 arvif->is_started = false;
4515 }
4516
Kalle Valo5e3dd152013-06-12 20:52:10 +03004517 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4518 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004519 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004520 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004521
Michal Kaziorcfd10612014-11-25 15:16:05 +01004522 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004523 } else if (old_state == IEEE80211_STA_AUTH &&
4524 new_state == IEEE80211_STA_ASSOC &&
4525 (vif->type == NL80211_IFTYPE_AP ||
4526 vif->type == NL80211_IFTYPE_ADHOC)) {
4527 /*
4528 * New association.
4529 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004530 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004531 sta->addr);
4532
Michal Kazior590922a2014-10-21 10:10:29 +03004533 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004534 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004535 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004536 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004537 } else if (old_state == IEEE80211_STA_ASSOC &&
4538 new_state == IEEE80211_STA_AUTH &&
4539 (vif->type == NL80211_IFTYPE_AP ||
4540 vif->type == NL80211_IFTYPE_ADHOC)) {
4541 /*
4542 * Disassociation.
4543 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004544 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004545 sta->addr);
4546
Michal Kazior590922a2014-10-21 10:10:29 +03004547 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004549 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004550 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004551 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004552exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004553 mutex_unlock(&ar->conf_mutex);
4554 return ret;
4555}
4556
4557static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004558 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004559{
4560 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004561 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4562 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004563 u32 value = 0;
4564 int ret = 0;
4565
Michal Kazior548db542013-07-05 16:15:15 +03004566 lockdep_assert_held(&ar->conf_mutex);
4567
Kalle Valo5e3dd152013-06-12 20:52:10 +03004568 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4569 return 0;
4570
4571 switch (ac) {
4572 case IEEE80211_AC_VO:
4573 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4574 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004575 prio = 7;
4576 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004577 break;
4578 case IEEE80211_AC_VI:
4579 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4580 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004581 prio = 5;
4582 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583 break;
4584 case IEEE80211_AC_BE:
4585 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4586 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004587 prio = 2;
4588 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004589 break;
4590 case IEEE80211_AC_BK:
4591 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4592 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004593 prio = 0;
4594 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004595 break;
4596 }
4597
4598 if (enable)
4599 arvif->u.sta.uapsd |= value;
4600 else
4601 arvif->u.sta.uapsd &= ~value;
4602
4603 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4604 WMI_STA_PS_PARAM_UAPSD,
4605 arvif->u.sta.uapsd);
4606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004607 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004608 goto exit;
4609 }
4610
4611 if (arvif->u.sta.uapsd)
4612 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4613 else
4614 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4615
4616 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4617 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4618 value);
4619 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004620 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621
Michal Kazior9f9b5742014-12-12 12:41:36 +01004622 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4623 if (ret) {
4624 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4625 arvif->vdev_id, ret);
4626 return ret;
4627 }
4628
4629 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4630 if (ret) {
4631 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4632 arvif->vdev_id, ret);
4633 return ret;
4634 }
4635
Michal Kaziorb0e56152015-01-24 12:14:52 +02004636 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4637 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4638 /* Only userspace can make an educated decision when to send
4639 * trigger frame. The following effectively disables u-UAPSD
4640 * autotrigger in firmware (which is enabled by default
4641 * provided the autotrigger service is available).
4642 */
4643
4644 arg.wmm_ac = acc;
4645 arg.user_priority = prio;
4646 arg.service_interval = 0;
4647 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4648 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4649
4650 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4651 arvif->bssid, &arg, 1);
4652 if (ret) {
4653 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4654 ret);
4655 return ret;
4656 }
4657 }
4658
Kalle Valo5e3dd152013-06-12 20:52:10 +03004659exit:
4660 return ret;
4661}
4662
4663static int ath10k_conf_tx(struct ieee80211_hw *hw,
4664 struct ieee80211_vif *vif, u16 ac,
4665 const struct ieee80211_tx_queue_params *params)
4666{
4667 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004668 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004669 struct wmi_wmm_params_arg *p = NULL;
4670 int ret;
4671
4672 mutex_lock(&ar->conf_mutex);
4673
4674 switch (ac) {
4675 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004676 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004677 break;
4678 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004679 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004680 break;
4681 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004682 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004683 break;
4684 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004685 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004686 break;
4687 }
4688
4689 if (WARN_ON(!p)) {
4690 ret = -EINVAL;
4691 goto exit;
4692 }
4693
4694 p->cwmin = params->cw_min;
4695 p->cwmax = params->cw_max;
4696 p->aifs = params->aifs;
4697
4698 /*
4699 * The channel time duration programmed in the HW is in absolute
4700 * microseconds, while mac80211 gives the txop in units of
4701 * 32 microseconds.
4702 */
4703 p->txop = params->txop * 32;
4704
Michal Kazior7fc979a2015-01-28 09:57:28 +02004705 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4706 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4707 &arvif->wmm_params);
4708 if (ret) {
4709 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4710 arvif->vdev_id, ret);
4711 goto exit;
4712 }
4713 } else {
4714 /* This won't work well with multi-interface cases but it's
4715 * better than nothing.
4716 */
4717 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4718 if (ret) {
4719 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4720 goto exit;
4721 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004722 }
4723
4724 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4725 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004726 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004727
4728exit:
4729 mutex_unlock(&ar->conf_mutex);
4730 return ret;
4731}
4732
4733#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4734
4735static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4736 struct ieee80211_vif *vif,
4737 struct ieee80211_channel *chan,
4738 int duration,
4739 enum ieee80211_roc_type type)
4740{
4741 struct ath10k *ar = hw->priv;
4742 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4743 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004744 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004745
4746 mutex_lock(&ar->conf_mutex);
4747
4748 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004749 switch (ar->scan.state) {
4750 case ATH10K_SCAN_IDLE:
4751 reinit_completion(&ar->scan.started);
4752 reinit_completion(&ar->scan.completed);
4753 reinit_completion(&ar->scan.on_channel);
4754 ar->scan.state = ATH10K_SCAN_STARTING;
4755 ar->scan.is_roc = true;
4756 ar->scan.vdev_id = arvif->vdev_id;
4757 ar->scan.roc_freq = chan->center_freq;
4758 ret = 0;
4759 break;
4760 case ATH10K_SCAN_STARTING:
4761 case ATH10K_SCAN_RUNNING:
4762 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004763 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004764 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004765 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004766 spin_unlock_bh(&ar->data_lock);
4767
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004768 if (ret)
4769 goto exit;
4770
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004771 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4772
Kalle Valo5e3dd152013-06-12 20:52:10 +03004773 memset(&arg, 0, sizeof(arg));
4774 ath10k_wmi_start_scan_init(ar, &arg);
4775 arg.vdev_id = arvif->vdev_id;
4776 arg.scan_id = ATH10K_SCAN_ID;
4777 arg.n_channels = 1;
4778 arg.channels[0] = chan->center_freq;
4779 arg.dwell_time_active = duration;
4780 arg.dwell_time_passive = duration;
4781 arg.max_scan_time = 2 * duration;
4782 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4783 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4784
4785 ret = ath10k_start_scan(ar, &arg);
4786 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004787 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004788 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004789 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004790 spin_unlock_bh(&ar->data_lock);
4791 goto exit;
4792 }
4793
4794 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4795 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004796 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004797
4798 ret = ath10k_scan_stop(ar);
4799 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004800 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004801
Kalle Valo5e3dd152013-06-12 20:52:10 +03004802 ret = -ETIMEDOUT;
4803 goto exit;
4804 }
4805
4806 ret = 0;
4807exit:
4808 mutex_unlock(&ar->conf_mutex);
4809 return ret;
4810}
4811
4812static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4813{
4814 struct ath10k *ar = hw->priv;
4815
4816 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004817 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004818 mutex_unlock(&ar->conf_mutex);
4819
Michal Kazior4eb2e162014-10-28 10:23:09 +01004820 cancel_delayed_work_sync(&ar->scan.timeout);
4821
Kalle Valo5e3dd152013-06-12 20:52:10 +03004822 return 0;
4823}
4824
4825/*
4826 * Both RTS and Fragmentation threshold are interface-specific
4827 * in ath10k, but device-specific in mac80211.
4828 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004829
4830static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4831{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004832 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004833 struct ath10k_vif *arvif;
4834 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004835
Michal Kaziorad088bf2013-10-16 15:44:46 +03004836 mutex_lock(&ar->conf_mutex);
4837 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004838 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004839 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004840
Michal Kaziorad088bf2013-10-16 15:44:46 +03004841 ret = ath10k_mac_set_rts(arvif, value);
4842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004843 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004844 arvif->vdev_id, ret);
4845 break;
4846 }
4847 }
4848 mutex_unlock(&ar->conf_mutex);
4849
4850 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004851}
4852
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004853static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4854 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004855{
4856 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004857 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004858 int ret;
4859
4860 /* mac80211 doesn't care if we really xmit queued frames or not
4861 * we'll collect those frames either way if we stop/delete vdevs */
4862 if (drop)
4863 return;
4864
Michal Kazior548db542013-07-05 16:15:15 +03004865 mutex_lock(&ar->conf_mutex);
4866
Michal Kazioraffd3212013-07-16 09:54:35 +02004867 if (ar->state == ATH10K_STATE_WEDGED)
4868 goto skip;
4869
Michal Kazioredb82362013-07-05 16:15:14 +03004870 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004871 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004872
Michal Kazioredb82362013-07-05 16:15:14 +03004873 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004874 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004875 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004876
Michal Kazior7962b0d2014-10-28 10:34:38 +01004877 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4878 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4879 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004880
4881 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004882 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004883
4884 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004885 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004886 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004887
Michal Kazioraffd3212013-07-16 09:54:35 +02004888skip:
Michal Kazior548db542013-07-05 16:15:15 +03004889 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004890}
4891
4892/* TODO: Implement this function properly
4893 * For now it is needed to reply to Probe Requests in IBSS mode.
4894 * Propably we need this information from FW.
4895 */
4896static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4897{
4898 return 1;
4899}
4900
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004901static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4902 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004903{
4904 struct ath10k *ar = hw->priv;
4905
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004906 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4907 return;
4908
Michal Kazioraffd3212013-07-16 09:54:35 +02004909 mutex_lock(&ar->conf_mutex);
4910
4911 /* If device failed to restart it will be in a different state, e.g.
4912 * ATH10K_STATE_WEDGED */
4913 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004914 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004915 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004916 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004917 }
4918
4919 mutex_unlock(&ar->conf_mutex);
4920}
4921
Michal Kazior2e1dea42013-07-31 10:32:40 +02004922static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4923 struct survey_info *survey)
4924{
4925 struct ath10k *ar = hw->priv;
4926 struct ieee80211_supported_band *sband;
4927 struct survey_info *ar_survey = &ar->survey[idx];
4928 int ret = 0;
4929
4930 mutex_lock(&ar->conf_mutex);
4931
4932 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4933 if (sband && idx >= sband->n_channels) {
4934 idx -= sband->n_channels;
4935 sband = NULL;
4936 }
4937
4938 if (!sband)
4939 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4940
4941 if (!sband || idx >= sband->n_channels) {
4942 ret = -ENOENT;
4943 goto exit;
4944 }
4945
4946 spin_lock_bh(&ar->data_lock);
4947 memcpy(survey, ar_survey, sizeof(*survey));
4948 spin_unlock_bh(&ar->data_lock);
4949
4950 survey->channel = &sband->channels[idx];
4951
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004952 if (ar->rx_channel == survey->channel)
4953 survey->filled |= SURVEY_INFO_IN_USE;
4954
Michal Kazior2e1dea42013-07-31 10:32:40 +02004955exit:
4956 mutex_unlock(&ar->conf_mutex);
4957 return ret;
4958}
4959
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004960/* Helper table for legacy fixed_rate/bitrate_mask */
4961static const u8 cck_ofdm_rate[] = {
4962 /* CCK */
4963 3, /* 1Mbps */
4964 2, /* 2Mbps */
4965 1, /* 5.5Mbps */
4966 0, /* 11Mbps */
4967 /* OFDM */
4968 3, /* 6Mbps */
4969 7, /* 9Mbps */
4970 2, /* 12Mbps */
4971 6, /* 18Mbps */
4972 1, /* 24Mbps */
4973 5, /* 36Mbps */
4974 0, /* 48Mbps */
4975 4, /* 54Mbps */
4976};
4977
4978/* Check if only one bit set */
4979static int ath10k_check_single_mask(u32 mask)
4980{
4981 int bit;
4982
4983 bit = ffs(mask);
4984 if (!bit)
4985 return 0;
4986
4987 mask &= ~BIT(bit - 1);
4988 if (mask)
4989 return 2;
4990
4991 return 1;
4992}
4993
4994static bool
4995ath10k_default_bitrate_mask(struct ath10k *ar,
4996 enum ieee80211_band band,
4997 const struct cfg80211_bitrate_mask *mask)
4998{
4999 u32 legacy = 0x00ff;
5000 u8 ht = 0xff, i;
5001 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005002 u16 nrf = ar->num_rf_chains;
5003
5004 if (ar->cfg_tx_chainmask)
5005 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005006
5007 switch (band) {
5008 case IEEE80211_BAND_2GHZ:
5009 legacy = 0x00fff;
5010 vht = 0;
5011 break;
5012 case IEEE80211_BAND_5GHZ:
5013 break;
5014 default:
5015 return false;
5016 }
5017
5018 if (mask->control[band].legacy != legacy)
5019 return false;
5020
Ben Greearb116ea12014-11-24 16:22:10 +02005021 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005022 if (mask->control[band].ht_mcs[i] != ht)
5023 return false;
5024
Ben Greearb116ea12014-11-24 16:22:10 +02005025 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005026 if (mask->control[band].vht_mcs[i] != vht)
5027 return false;
5028
5029 return true;
5030}
5031
5032static bool
5033ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5034 enum ieee80211_band band,
5035 u8 *fixed_nss)
5036{
5037 int ht_nss = 0, vht_nss = 0, i;
5038
5039 /* check legacy */
5040 if (ath10k_check_single_mask(mask->control[band].legacy))
5041 return false;
5042
5043 /* check HT */
5044 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5045 if (mask->control[band].ht_mcs[i] == 0xff)
5046 continue;
5047 else if (mask->control[band].ht_mcs[i] == 0x00)
5048 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005049
5050 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005051 }
5052
5053 ht_nss = i;
5054
5055 /* check VHT */
5056 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5057 if (mask->control[band].vht_mcs[i] == 0x03ff)
5058 continue;
5059 else if (mask->control[band].vht_mcs[i] == 0x0000)
5060 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005061
5062 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005063 }
5064
5065 vht_nss = i;
5066
5067 if (ht_nss > 0 && vht_nss > 0)
5068 return false;
5069
5070 if (ht_nss)
5071 *fixed_nss = ht_nss;
5072 else if (vht_nss)
5073 *fixed_nss = vht_nss;
5074 else
5075 return false;
5076
5077 return true;
5078}
5079
5080static bool
5081ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5082 enum ieee80211_band band,
5083 enum wmi_rate_preamble *preamble)
5084{
5085 int legacy = 0, ht = 0, vht = 0, i;
5086
5087 *preamble = WMI_RATE_PREAMBLE_OFDM;
5088
5089 /* check legacy */
5090 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5091 if (legacy > 1)
5092 return false;
5093
5094 /* check HT */
5095 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5096 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5097 if (ht > 1)
5098 return false;
5099
5100 /* check VHT */
5101 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5102 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5103 if (vht > 1)
5104 return false;
5105
5106 /* Currently we support only one fixed_rate */
5107 if ((legacy + ht + vht) != 1)
5108 return false;
5109
5110 if (ht)
5111 *preamble = WMI_RATE_PREAMBLE_HT;
5112 else if (vht)
5113 *preamble = WMI_RATE_PREAMBLE_VHT;
5114
5115 return true;
5116}
5117
5118static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005119ath10k_bitrate_mask_rate(struct ath10k *ar,
5120 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005121 enum ieee80211_band band,
5122 u8 *fixed_rate,
5123 u8 *fixed_nss)
5124{
5125 u8 rate = 0, pream = 0, nss = 0, i;
5126 enum wmi_rate_preamble preamble;
5127
5128 /* Check if single rate correct */
5129 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5130 return false;
5131
5132 pream = preamble;
5133
5134 switch (preamble) {
5135 case WMI_RATE_PREAMBLE_CCK:
5136 case WMI_RATE_PREAMBLE_OFDM:
5137 i = ffs(mask->control[band].legacy) - 1;
5138
5139 if (band == IEEE80211_BAND_2GHZ && i < 4)
5140 pream = WMI_RATE_PREAMBLE_CCK;
5141
5142 if (band == IEEE80211_BAND_5GHZ)
5143 i += 4;
5144
5145 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5146 return false;
5147
5148 rate = cck_ofdm_rate[i];
5149 break;
5150 case WMI_RATE_PREAMBLE_HT:
5151 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5152 if (mask->control[band].ht_mcs[i])
5153 break;
5154
5155 if (i == IEEE80211_HT_MCS_MASK_LEN)
5156 return false;
5157
5158 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5159 nss = i;
5160 break;
5161 case WMI_RATE_PREAMBLE_VHT:
5162 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5163 if (mask->control[band].vht_mcs[i])
5164 break;
5165
5166 if (i == NL80211_VHT_NSS_MAX)
5167 return false;
5168
5169 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5170 nss = i;
5171 break;
5172 }
5173
5174 *fixed_nss = nss + 1;
5175 nss <<= 4;
5176 pream <<= 6;
5177
Michal Kazior7aa7a722014-08-25 12:09:38 +02005178 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 +01005179 pream, nss, rate);
5180
5181 *fixed_rate = pream | nss | rate;
5182
5183 return true;
5184}
5185
Michal Kazior7aa7a722014-08-25 12:09:38 +02005186static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5187 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005188 enum ieee80211_band band,
5189 u8 *fixed_rate,
5190 u8 *fixed_nss)
5191{
5192 /* First check full NSS mask, if we can simply limit NSS */
5193 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5194 return true;
5195
5196 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005197 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005198}
5199
5200static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5201 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005202 u8 fixed_nss,
5203 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005204{
5205 struct ath10k *ar = arvif->ar;
5206 u32 vdev_param;
5207 int ret = 0;
5208
5209 mutex_lock(&ar->conf_mutex);
5210
5211 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005212 arvif->fixed_nss == fixed_nss &&
5213 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005214 goto exit;
5215
5216 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005217 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005218
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005219 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005220 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005221
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005222 vdev_param = ar->wmi.vdev_param->fixed_rate;
5223 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5224 vdev_param, fixed_rate);
5225 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005226 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005227 fixed_rate, ret);
5228 ret = -EINVAL;
5229 goto exit;
5230 }
5231
5232 arvif->fixed_rate = fixed_rate;
5233
5234 vdev_param = ar->wmi.vdev_param->nss;
5235 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5236 vdev_param, fixed_nss);
5237
5238 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005239 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005240 fixed_nss, ret);
5241 ret = -EINVAL;
5242 goto exit;
5243 }
5244
5245 arvif->fixed_nss = fixed_nss;
5246
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005247 vdev_param = ar->wmi.vdev_param->sgi;
5248 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5249 force_sgi);
5250
5251 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005252 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005253 force_sgi, ret);
5254 ret = -EINVAL;
5255 goto exit;
5256 }
5257
5258 arvif->force_sgi = force_sgi;
5259
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005260exit:
5261 mutex_unlock(&ar->conf_mutex);
5262 return ret;
5263}
5264
5265static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5266 struct ieee80211_vif *vif,
5267 const struct cfg80211_bitrate_mask *mask)
5268{
5269 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5270 struct ath10k *ar = arvif->ar;
5271 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5272 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5273 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005274 u8 force_sgi;
5275
Ben Greearb116ea12014-11-24 16:22:10 +02005276 if (ar->cfg_tx_chainmask)
5277 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5278
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005279 force_sgi = mask->control[band].gi;
5280 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5281 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005282
5283 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005284 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005285 &fixed_rate,
5286 &fixed_nss))
5287 return -EINVAL;
5288 }
5289
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005290 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005291 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005292 return -EINVAL;
5293 }
5294
5295 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5296 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005297}
5298
Michal Kazior9797feb2014-02-14 14:49:48 +01005299static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5300 struct ieee80211_vif *vif,
5301 struct ieee80211_sta *sta,
5302 u32 changed)
5303{
5304 struct ath10k *ar = hw->priv;
5305 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5306 u32 bw, smps;
5307
5308 spin_lock_bh(&ar->data_lock);
5309
Michal Kazior7aa7a722014-08-25 12:09:38 +02005310 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005311 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5312 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5313 sta->smps_mode);
5314
5315 if (changed & IEEE80211_RC_BW_CHANGED) {
5316 bw = WMI_PEER_CHWIDTH_20MHZ;
5317
5318 switch (sta->bandwidth) {
5319 case IEEE80211_STA_RX_BW_20:
5320 bw = WMI_PEER_CHWIDTH_20MHZ;
5321 break;
5322 case IEEE80211_STA_RX_BW_40:
5323 bw = WMI_PEER_CHWIDTH_40MHZ;
5324 break;
5325 case IEEE80211_STA_RX_BW_80:
5326 bw = WMI_PEER_CHWIDTH_80MHZ;
5327 break;
5328 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005329 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005330 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005331 bw = WMI_PEER_CHWIDTH_20MHZ;
5332 break;
5333 }
5334
5335 arsta->bw = bw;
5336 }
5337
5338 if (changed & IEEE80211_RC_NSS_CHANGED)
5339 arsta->nss = sta->rx_nss;
5340
5341 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5342 smps = WMI_PEER_SMPS_PS_NONE;
5343
5344 switch (sta->smps_mode) {
5345 case IEEE80211_SMPS_AUTOMATIC:
5346 case IEEE80211_SMPS_OFF:
5347 smps = WMI_PEER_SMPS_PS_NONE;
5348 break;
5349 case IEEE80211_SMPS_STATIC:
5350 smps = WMI_PEER_SMPS_STATIC;
5351 break;
5352 case IEEE80211_SMPS_DYNAMIC:
5353 smps = WMI_PEER_SMPS_DYNAMIC;
5354 break;
5355 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005356 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005357 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005358 smps = WMI_PEER_SMPS_PS_NONE;
5359 break;
5360 }
5361
5362 arsta->smps = smps;
5363 }
5364
Michal Kazior9797feb2014-02-14 14:49:48 +01005365 arsta->changed |= changed;
5366
5367 spin_unlock_bh(&ar->data_lock);
5368
5369 ieee80211_queue_work(hw, &arsta->update_wk);
5370}
5371
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005372static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5373{
5374 /*
5375 * FIXME: Return 0 for time being. Need to figure out whether FW
5376 * has the API to fetch 64-bit local TSF
5377 */
5378
5379 return 0;
5380}
5381
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005382static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5383 struct ieee80211_vif *vif,
5384 enum ieee80211_ampdu_mlme_action action,
5385 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5386 u8 buf_size)
5387{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005388 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005389 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5390
Michal Kazior7aa7a722014-08-25 12:09:38 +02005391 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 +02005392 arvif->vdev_id, sta->addr, tid, action);
5393
5394 switch (action) {
5395 case IEEE80211_AMPDU_RX_START:
5396 case IEEE80211_AMPDU_RX_STOP:
5397 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5398 * creation/removal. Do we need to verify this?
5399 */
5400 return 0;
5401 case IEEE80211_AMPDU_TX_START:
5402 case IEEE80211_AMPDU_TX_STOP_CONT:
5403 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5404 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5405 case IEEE80211_AMPDU_TX_OPERATIONAL:
5406 /* Firmware offloads Tx aggregation entirely so deny mac80211
5407 * Tx aggregation requests.
5408 */
5409 return -EOPNOTSUPP;
5410 }
5411
5412 return -EINVAL;
5413}
5414
Kalle Valo5e3dd152013-06-12 20:52:10 +03005415static const struct ieee80211_ops ath10k_ops = {
5416 .tx = ath10k_tx,
5417 .start = ath10k_start,
5418 .stop = ath10k_stop,
5419 .config = ath10k_config,
5420 .add_interface = ath10k_add_interface,
5421 .remove_interface = ath10k_remove_interface,
5422 .configure_filter = ath10k_configure_filter,
5423 .bss_info_changed = ath10k_bss_info_changed,
5424 .hw_scan = ath10k_hw_scan,
5425 .cancel_hw_scan = ath10k_cancel_hw_scan,
5426 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005427 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005428 .sta_state = ath10k_sta_state,
5429 .conf_tx = ath10k_conf_tx,
5430 .remain_on_channel = ath10k_remain_on_channel,
5431 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5432 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005433 .flush = ath10k_flush,
5434 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005435 .set_antenna = ath10k_set_antenna,
5436 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005437 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005438 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005439 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005440 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005441 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005442 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005443 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5444 .get_et_stats = ath10k_debug_get_et_stats,
5445 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005446
5447 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5448
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005449#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005450 .suspend = ath10k_wow_op_suspend,
5451 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005452#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005453#ifdef CONFIG_MAC80211_DEBUGFS
5454 .sta_add_debugfs = ath10k_sta_add_debugfs,
5455#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005456};
5457
5458#define RATETAB_ENT(_rate, _rateid, _flags) { \
5459 .bitrate = (_rate), \
5460 .flags = (_flags), \
5461 .hw_value = (_rateid), \
5462}
5463
5464#define CHAN2G(_channel, _freq, _flags) { \
5465 .band = IEEE80211_BAND_2GHZ, \
5466 .hw_value = (_channel), \
5467 .center_freq = (_freq), \
5468 .flags = (_flags), \
5469 .max_antenna_gain = 0, \
5470 .max_power = 30, \
5471}
5472
5473#define CHAN5G(_channel, _freq, _flags) { \
5474 .band = IEEE80211_BAND_5GHZ, \
5475 .hw_value = (_channel), \
5476 .center_freq = (_freq), \
5477 .flags = (_flags), \
5478 .max_antenna_gain = 0, \
5479 .max_power = 30, \
5480}
5481
5482static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5483 CHAN2G(1, 2412, 0),
5484 CHAN2G(2, 2417, 0),
5485 CHAN2G(3, 2422, 0),
5486 CHAN2G(4, 2427, 0),
5487 CHAN2G(5, 2432, 0),
5488 CHAN2G(6, 2437, 0),
5489 CHAN2G(7, 2442, 0),
5490 CHAN2G(8, 2447, 0),
5491 CHAN2G(9, 2452, 0),
5492 CHAN2G(10, 2457, 0),
5493 CHAN2G(11, 2462, 0),
5494 CHAN2G(12, 2467, 0),
5495 CHAN2G(13, 2472, 0),
5496 CHAN2G(14, 2484, 0),
5497};
5498
5499static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005500 CHAN5G(36, 5180, 0),
5501 CHAN5G(40, 5200, 0),
5502 CHAN5G(44, 5220, 0),
5503 CHAN5G(48, 5240, 0),
5504 CHAN5G(52, 5260, 0),
5505 CHAN5G(56, 5280, 0),
5506 CHAN5G(60, 5300, 0),
5507 CHAN5G(64, 5320, 0),
5508 CHAN5G(100, 5500, 0),
5509 CHAN5G(104, 5520, 0),
5510 CHAN5G(108, 5540, 0),
5511 CHAN5G(112, 5560, 0),
5512 CHAN5G(116, 5580, 0),
5513 CHAN5G(120, 5600, 0),
5514 CHAN5G(124, 5620, 0),
5515 CHAN5G(128, 5640, 0),
5516 CHAN5G(132, 5660, 0),
5517 CHAN5G(136, 5680, 0),
5518 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005519 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005520 CHAN5G(149, 5745, 0),
5521 CHAN5G(153, 5765, 0),
5522 CHAN5G(157, 5785, 0),
5523 CHAN5G(161, 5805, 0),
5524 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005525};
5526
Michal Kazior91b12082014-12-12 12:41:35 +01005527/* Note: Be careful if you re-order these. There is code which depends on this
5528 * ordering.
5529 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005530static struct ieee80211_rate ath10k_rates[] = {
5531 /* CCK */
5532 RATETAB_ENT(10, 0x82, 0),
5533 RATETAB_ENT(20, 0x84, 0),
5534 RATETAB_ENT(55, 0x8b, 0),
5535 RATETAB_ENT(110, 0x96, 0),
5536 /* OFDM */
5537 RATETAB_ENT(60, 0x0c, 0),
5538 RATETAB_ENT(90, 0x12, 0),
5539 RATETAB_ENT(120, 0x18, 0),
5540 RATETAB_ENT(180, 0x24, 0),
5541 RATETAB_ENT(240, 0x30, 0),
5542 RATETAB_ENT(360, 0x48, 0),
5543 RATETAB_ENT(480, 0x60, 0),
5544 RATETAB_ENT(540, 0x6c, 0),
5545};
5546
5547#define ath10k_a_rates (ath10k_rates + 4)
5548#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5549#define ath10k_g_rates (ath10k_rates + 0)
5550#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5551
Michal Kaziore7b54192014-08-07 11:03:27 +02005552struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005553{
5554 struct ieee80211_hw *hw;
5555 struct ath10k *ar;
5556
Michal Kaziore7b54192014-08-07 11:03:27 +02005557 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005558 if (!hw)
5559 return NULL;
5560
5561 ar = hw->priv;
5562 ar->hw = hw;
5563
5564 return ar;
5565}
5566
5567void ath10k_mac_destroy(struct ath10k *ar)
5568{
5569 ieee80211_free_hw(ar->hw);
5570}
5571
5572static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5573 {
5574 .max = 8,
5575 .types = BIT(NL80211_IFTYPE_STATION)
5576 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005577 },
5578 {
5579 .max = 3,
5580 .types = BIT(NL80211_IFTYPE_P2P_GO)
5581 },
5582 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005583 .max = 1,
5584 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5585 },
5586 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005587 .max = 7,
5588 .types = BIT(NL80211_IFTYPE_AP)
5589 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005590};
5591
Bartosz Markowskif2595092013-12-10 16:20:39 +01005592static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005593 {
5594 .max = 8,
5595 .types = BIT(NL80211_IFTYPE_AP)
5596 },
5597};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005598
5599static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5600 {
5601 .limits = ath10k_if_limits,
5602 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5603 .max_interfaces = 8,
5604 .num_different_channels = 1,
5605 .beacon_int_infra_match = true,
5606 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005607};
5608
5609static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005610 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005611 .limits = ath10k_10x_if_limits,
5612 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005613 .max_interfaces = 8,
5614 .num_different_channels = 1,
5615 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005616#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005617 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5618 BIT(NL80211_CHAN_WIDTH_20) |
5619 BIT(NL80211_CHAN_WIDTH_40) |
5620 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005621#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005622 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005623};
5624
5625static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5626{
5627 struct ieee80211_sta_vht_cap vht_cap = {0};
5628 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005629 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005630 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005631
5632 vht_cap.vht_supported = 1;
5633 vht_cap.cap = ar->vht_cap_info;
5634
Michal Kaziorbc657a362015-02-26 11:11:22 +01005635 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5636 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5637 val = ar->num_rf_chains - 1;
5638 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5639 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5640
5641 vht_cap.cap |= val;
5642 }
5643
5644 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5645 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5646 val = ar->num_rf_chains - 1;
5647 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5648 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5649
5650 vht_cap.cap |= val;
5651 }
5652
Michal Kazior8865bee42013-07-24 12:36:46 +02005653 mcs_map = 0;
5654 for (i = 0; i < 8; i++) {
5655 if (i < ar->num_rf_chains)
5656 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5657 else
5658 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5659 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005660
5661 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5662 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5663
5664 return vht_cap;
5665}
5666
5667static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5668{
5669 int i;
5670 struct ieee80211_sta_ht_cap ht_cap = {0};
5671
5672 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5673 return ht_cap;
5674
5675 ht_cap.ht_supported = 1;
5676 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5677 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5678 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5679 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5680 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5681
5682 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5683 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5684
5685 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5686 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5687
5688 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5689 u32 smps;
5690
5691 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5692 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5693
5694 ht_cap.cap |= smps;
5695 }
5696
5697 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5698 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5699
5700 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5701 u32 stbc;
5702
5703 stbc = ar->ht_cap_info;
5704 stbc &= WMI_HT_CAP_RX_STBC;
5705 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5706 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5707 stbc &= IEEE80211_HT_CAP_RX_STBC;
5708
5709 ht_cap.cap |= stbc;
5710 }
5711
5712 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5713 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5714
5715 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5716 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5717
5718 /* max AMSDU is implicitly taken from vht_cap_info */
5719 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5720 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5721
Michal Kazior8865bee42013-07-24 12:36:46 +02005722 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005723 ht_cap.mcs.rx_mask[i] = 0xFF;
5724
5725 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5726
5727 return ht_cap;
5728}
5729
Kalle Valo5e3dd152013-06-12 20:52:10 +03005730static void ath10k_get_arvif_iter(void *data, u8 *mac,
5731 struct ieee80211_vif *vif)
5732{
5733 struct ath10k_vif_iter *arvif_iter = data;
5734 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5735
5736 if (arvif->vdev_id == arvif_iter->vdev_id)
5737 arvif_iter->arvif = arvif;
5738}
5739
5740struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5741{
5742 struct ath10k_vif_iter arvif_iter;
5743 u32 flags;
5744
5745 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5746 arvif_iter.vdev_id = vdev_id;
5747
5748 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5749 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5750 flags,
5751 ath10k_get_arvif_iter,
5752 &arvif_iter);
5753 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005754 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005755 return NULL;
5756 }
5757
5758 return arvif_iter.arvif;
5759}
5760
5761int ath10k_mac_register(struct ath10k *ar)
5762{
Johannes Berg3cb10942015-01-22 21:38:45 +01005763 static const u32 cipher_suites[] = {
5764 WLAN_CIPHER_SUITE_WEP40,
5765 WLAN_CIPHER_SUITE_WEP104,
5766 WLAN_CIPHER_SUITE_TKIP,
5767 WLAN_CIPHER_SUITE_CCMP,
5768 WLAN_CIPHER_SUITE_AES_CMAC,
5769 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005770 struct ieee80211_supported_band *band;
5771 struct ieee80211_sta_vht_cap vht_cap;
5772 struct ieee80211_sta_ht_cap ht_cap;
5773 void *channels;
5774 int ret;
5775
5776 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5777
5778 SET_IEEE80211_DEV(ar->hw, ar->dev);
5779
5780 ht_cap = ath10k_get_ht_cap(ar);
5781 vht_cap = ath10k_create_vht_cap(ar);
5782
5783 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5784 channels = kmemdup(ath10k_2ghz_channels,
5785 sizeof(ath10k_2ghz_channels),
5786 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005787 if (!channels) {
5788 ret = -ENOMEM;
5789 goto err_free;
5790 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005791
5792 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5793 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5794 band->channels = channels;
5795 band->n_bitrates = ath10k_g_rates_size;
5796 band->bitrates = ath10k_g_rates;
5797 band->ht_cap = ht_cap;
5798
Yanbo Lid68bb122015-01-23 08:18:20 +08005799 /* Enable the VHT support at 2.4 GHz */
5800 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005801
5802 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5803 }
5804
5805 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5806 channels = kmemdup(ath10k_5ghz_channels,
5807 sizeof(ath10k_5ghz_channels),
5808 GFP_KERNEL);
5809 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005810 ret = -ENOMEM;
5811 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005812 }
5813
5814 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5815 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5816 band->channels = channels;
5817 band->n_bitrates = ath10k_a_rates_size;
5818 band->bitrates = ath10k_a_rates;
5819 band->ht_cap = ht_cap;
5820 band->vht_cap = vht_cap;
5821 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5822 }
5823
5824 ar->hw->wiphy->interface_modes =
5825 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005826 BIT(NL80211_IFTYPE_AP);
5827
Ben Greear46acf7b2014-05-16 17:15:38 +03005828 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5829 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5830
Bartosz Markowskid3541812013-12-10 16:20:40 +01005831 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5832 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005833 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005834 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5835 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005836
5837 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5838 IEEE80211_HW_SUPPORTS_PS |
5839 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005840 IEEE80211_HW_MFP_CAPABLE |
5841 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5842 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005843 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005844 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005845 IEEE80211_HW_SW_CRYPTO_CONTROL |
5846 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005847
Eliad Peller0d8614b2014-09-10 14:07:36 +03005848 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5849
Kalle Valo5e3dd152013-06-12 20:52:10 +03005850 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005851 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005852
5853 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5854 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5855 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5856 }
5857
5858 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5859 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5860
5861 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005862 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005863
Kalle Valo5e3dd152013-06-12 20:52:10 +03005864 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5865
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005866 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5867 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5868
5869 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5870 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5871 * correct Probe Responses. This is more of a hack advert..
5872 */
5873 ar->hw->wiphy->probe_resp_offload |=
5874 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5875 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5876 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5877 }
5878
Kalle Valo5e3dd152013-06-12 20:52:10 +03005879 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005880 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005881 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5882
5883 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005884 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5885
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005886 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5887
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005888 ret = ath10k_wow_init(ar);
5889 if (ret) {
5890 ath10k_warn(ar, "failed to init wow: %d\n", ret);
5891 goto err_free;
5892 }
5893
Kalle Valo5e3dd152013-06-12 20:52:10 +03005894 /*
5895 * on LL hardware queues are managed entirely by the FW
5896 * so we only advertise to mac we can do the queues thing
5897 */
5898 ar->hw->queues = 4;
5899
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005900 switch (ar->wmi.op_version) {
5901 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5902 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005903 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5904 ar->hw->wiphy->n_iface_combinations =
5905 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005906 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005907 break;
5908 case ATH10K_FW_WMI_OP_VERSION_10_1:
5909 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005910 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005911 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5912 ar->hw->wiphy->n_iface_combinations =
5913 ARRAY_SIZE(ath10k_10x_if_comb);
5914 break;
5915 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5916 case ATH10K_FW_WMI_OP_VERSION_MAX:
5917 WARN_ON(1);
5918 ret = -EINVAL;
5919 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005920 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005921
Michal Kazior7c199992013-07-31 10:47:57 +02005922 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5923
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005924 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5925 /* Init ath dfs pattern detector */
5926 ar->ath_common.debug_mask = ATH_DBG_DFS;
5927 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5928 NL80211_DFS_UNSET);
5929
5930 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005931 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005932 }
5933
Kalle Valo5e3dd152013-06-12 20:52:10 +03005934 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5935 ath10k_reg_notifier);
5936 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005937 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005938 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005939 }
5940
Johannes Berg3cb10942015-01-22 21:38:45 +01005941 ar->hw->wiphy->cipher_suites = cipher_suites;
5942 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5943
Kalle Valo5e3dd152013-06-12 20:52:10 +03005944 ret = ieee80211_register_hw(ar->hw);
5945 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005946 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005947 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005948 }
5949
5950 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5951 ret = regulatory_hint(ar->hw->wiphy,
5952 ar->ath_common.regulatory.alpha2);
5953 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005954 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005955 }
5956
5957 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005958
5959err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005960 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005961err_free:
5962 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5963 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5964
Kalle Valo5e3dd152013-06-12 20:52:10 +03005965 return ret;
5966}
5967
5968void ath10k_mac_unregister(struct ath10k *ar)
5969{
5970 ieee80211_unregister_hw(ar->hw);
5971
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005972 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5973 ar->dfs_detector->exit(ar->dfs_detector);
5974
Kalle Valo5e3dd152013-06-12 20:52:10 +03005975 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5976 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5977
5978 SET_IEEE80211_DEV(ar->hw, NULL);
5979}