blob: 87ecc3e092416ee87e37a192d090bbf409a1264c [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 Kazior4b604552014-07-21 21:03:09 +03002525/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2526 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527 */
Michal Kazior4b604552014-07-21 21:03:09 +03002528static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002529{
2530 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002531 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002532 u8 *qos_ctl;
2533
2534 if (!ieee80211_is_data_qos(hdr->frame_control))
2535 return;
2536
2537 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002538 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2539 skb->data, (void *)qos_ctl - (void *)skb->data);
2540 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002541
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002542 /* Some firmware revisions don't handle sending QoS NullFunc well.
2543 * These frames are mainly used for CQM purposes so it doesn't really
2544 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002545 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002546 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002547 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002548 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002549
2550 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551}
2552
Michal Kazior4b604552014-07-21 21:03:09 +03002553static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2554 struct ieee80211_vif *vif,
2555 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002556{
2557 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2559
2560 /* This is case only for P2P_GO */
2561 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2562 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2563 return;
2564
2565 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2566 spin_lock_bh(&ar->data_lock);
2567 if (arvif->u.ap.noa_data)
2568 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2569 GFP_ATOMIC))
2570 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2571 arvif->u.ap.noa_data,
2572 arvif->u.ap.noa_len);
2573 spin_unlock_bh(&ar->data_lock);
2574 }
2575}
2576
Michal Kazior8d6d3622014-11-24 14:58:31 +01002577static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2578{
2579 /* FIXME: Not really sure since when the behaviour changed. At some
2580 * point new firmware stopped requiring creation of peer entries for
2581 * offchannel tx (and actually creating them causes issues with wmi-htc
2582 * tx credit replenishment and reliability). Assuming it's at least 3.4
2583 * because that's when the `freq` was introduced to TX_FRM HTT command.
2584 */
2585 return !(ar->htt.target_version_major >= 3 &&
2586 ar->htt.target_version_minor >= 4);
2587}
2588
Kalle Valo5e3dd152013-06-12 20:52:10 +03002589static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2590{
2591 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002592 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002593
Michal Kazior961d4c32013-08-09 10:13:34 +02002594 if (ar->htt.target_version_major >= 3) {
2595 /* Since HTT 3.0 there is no separate mgmt tx command */
2596 ret = ath10k_htt_tx(&ar->htt, skb);
2597 goto exit;
2598 }
2599
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002600 if (ieee80211_is_mgmt(hdr->frame_control)) {
2601 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2602 ar->fw_features)) {
2603 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2604 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002605 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002606 ret = -EBUSY;
2607 goto exit;
2608 }
2609
2610 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2611 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2612 } else {
2613 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2614 }
2615 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2616 ar->fw_features) &&
2617 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618 /* FW does not report tx status properly for NullFunc frames
2619 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002620 * those frames when it detects link/beacon loss and depends
2621 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002622 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002623 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002624 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002625 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626
Michal Kazior961d4c32013-08-09 10:13:34 +02002627exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002628 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002629 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2630 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002631 ieee80211_free_txskb(ar->hw, skb);
2632 }
2633}
2634
2635void ath10k_offchan_tx_purge(struct ath10k *ar)
2636{
2637 struct sk_buff *skb;
2638
2639 for (;;) {
2640 skb = skb_dequeue(&ar->offchan_tx_queue);
2641 if (!skb)
2642 break;
2643
2644 ieee80211_free_txskb(ar->hw, skb);
2645 }
2646}
2647
2648void ath10k_offchan_tx_work(struct work_struct *work)
2649{
2650 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2651 struct ath10k_peer *peer;
2652 struct ieee80211_hdr *hdr;
2653 struct sk_buff *skb;
2654 const u8 *peer_addr;
2655 int vdev_id;
2656 int ret;
2657
2658 /* FW requirement: We must create a peer before FW will send out
2659 * an offchannel frame. Otherwise the frame will be stuck and
2660 * never transmitted. We delete the peer upon tx completion.
2661 * It is unlikely that a peer for offchannel tx will already be
2662 * present. However it may be in some rare cases so account for that.
2663 * Otherwise we might remove a legitimate peer and break stuff. */
2664
2665 for (;;) {
2666 skb = skb_dequeue(&ar->offchan_tx_queue);
2667 if (!skb)
2668 break;
2669
2670 mutex_lock(&ar->conf_mutex);
2671
Michal Kazior7aa7a722014-08-25 12:09:38 +02002672 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002673 skb);
2674
2675 hdr = (struct ieee80211_hdr *)skb->data;
2676 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002677 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002678
2679 spin_lock_bh(&ar->data_lock);
2680 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2681 spin_unlock_bh(&ar->data_lock);
2682
2683 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002684 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002685 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686 peer_addr, vdev_id);
2687
2688 if (!peer) {
2689 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2690 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002691 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692 peer_addr, vdev_id, ret);
2693 }
2694
2695 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002696 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002697 ar->offchan_tx_skb = skb;
2698 spin_unlock_bh(&ar->data_lock);
2699
2700 ath10k_tx_htt(ar, skb);
2701
2702 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2703 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002704 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002705 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706 skb);
2707
2708 if (!peer) {
2709 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2710 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002711 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002712 peer_addr, vdev_id, ret);
2713 }
2714
2715 mutex_unlock(&ar->conf_mutex);
2716 }
2717}
2718
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002719void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2720{
2721 struct sk_buff *skb;
2722
2723 for (;;) {
2724 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2725 if (!skb)
2726 break;
2727
2728 ieee80211_free_txskb(ar->hw, skb);
2729 }
2730}
2731
2732void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2733{
2734 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2735 struct sk_buff *skb;
2736 int ret;
2737
2738 for (;;) {
2739 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2740 if (!skb)
2741 break;
2742
2743 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002745 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002746 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002747 ieee80211_free_txskb(ar->hw, skb);
2748 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002749 }
2750}
2751
Kalle Valo5e3dd152013-06-12 20:52:10 +03002752/************/
2753/* Scanning */
2754/************/
2755
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002756void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002758 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002760 switch (ar->scan.state) {
2761 case ATH10K_SCAN_IDLE:
2762 break;
2763 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002764 if (ar->scan.is_roc)
2765 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002766 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002767 case ATH10K_SCAN_ABORTING:
2768 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002769 ieee80211_scan_completed(ar->hw,
2770 (ar->scan.state ==
2771 ATH10K_SCAN_ABORTING));
2772 /* fall through */
2773 case ATH10K_SCAN_STARTING:
2774 ar->scan.state = ATH10K_SCAN_IDLE;
2775 ar->scan_channel = NULL;
2776 ath10k_offchan_tx_purge(ar);
2777 cancel_delayed_work(&ar->scan.timeout);
2778 complete_all(&ar->scan.completed);
2779 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002780 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002781}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002782
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002783void ath10k_scan_finish(struct ath10k *ar)
2784{
2785 spin_lock_bh(&ar->data_lock);
2786 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002787 spin_unlock_bh(&ar->data_lock);
2788}
2789
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002790static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791{
2792 struct wmi_stop_scan_arg arg = {
2793 .req_id = 1, /* FIXME */
2794 .req_type = WMI_SCAN_STOP_ONE,
2795 .u.scan_id = ATH10K_SCAN_ID,
2796 };
2797 int ret;
2798
2799 lockdep_assert_held(&ar->conf_mutex);
2800
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801 ret = ath10k_wmi_stop_scan(ar, &arg);
2802 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002803 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002804 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805 }
2806
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002808 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002809 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002810 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002811 } else if (ret > 0) {
2812 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002813 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002814
2815out:
2816 /* Scan state should be updated upon scan completion but in case
2817 * firmware fails to deliver the event (for whatever reason) it is
2818 * desired to clean up scan state anyway. Firmware may have just
2819 * dropped the scan completion event delivery due to transport pipe
2820 * being overflown with data and/or it can recover on its own before
2821 * next scan request is submitted.
2822 */
2823 spin_lock_bh(&ar->data_lock);
2824 if (ar->scan.state != ATH10K_SCAN_IDLE)
2825 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002826 spin_unlock_bh(&ar->data_lock);
2827
2828 return ret;
2829}
2830
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002831static void ath10k_scan_abort(struct ath10k *ar)
2832{
2833 int ret;
2834
2835 lockdep_assert_held(&ar->conf_mutex);
2836
2837 spin_lock_bh(&ar->data_lock);
2838
2839 switch (ar->scan.state) {
2840 case ATH10K_SCAN_IDLE:
2841 /* This can happen if timeout worker kicked in and called
2842 * abortion while scan completion was being processed.
2843 */
2844 break;
2845 case ATH10K_SCAN_STARTING:
2846 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002847 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002848 ath10k_scan_state_str(ar->scan.state),
2849 ar->scan.state);
2850 break;
2851 case ATH10K_SCAN_RUNNING:
2852 ar->scan.state = ATH10K_SCAN_ABORTING;
2853 spin_unlock_bh(&ar->data_lock);
2854
2855 ret = ath10k_scan_stop(ar);
2856 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002857 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002858
2859 spin_lock_bh(&ar->data_lock);
2860 break;
2861 }
2862
2863 spin_unlock_bh(&ar->data_lock);
2864}
2865
2866void ath10k_scan_timeout_work(struct work_struct *work)
2867{
2868 struct ath10k *ar = container_of(work, struct ath10k,
2869 scan.timeout.work);
2870
2871 mutex_lock(&ar->conf_mutex);
2872 ath10k_scan_abort(ar);
2873 mutex_unlock(&ar->conf_mutex);
2874}
2875
Kalle Valo5e3dd152013-06-12 20:52:10 +03002876static int ath10k_start_scan(struct ath10k *ar,
2877 const struct wmi_start_scan_arg *arg)
2878{
2879 int ret;
2880
2881 lockdep_assert_held(&ar->conf_mutex);
2882
2883 ret = ath10k_wmi_start_scan(ar, arg);
2884 if (ret)
2885 return ret;
2886
Kalle Valo5e3dd152013-06-12 20:52:10 +03002887 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2888 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002889 ret = ath10k_scan_stop(ar);
2890 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002891 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002892
2893 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002894 }
2895
Ben Greear2f9eec02015-02-15 16:50:38 +02002896 /* If we failed to start the scan, return error code at
2897 * this point. This is probably due to some issue in the
2898 * firmware, but no need to wedge the driver due to that...
2899 */
2900 spin_lock_bh(&ar->data_lock);
2901 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2902 spin_unlock_bh(&ar->data_lock);
2903 return -EINVAL;
2904 }
2905 spin_unlock_bh(&ar->data_lock);
2906
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002907 /* Add a 200ms margin to account for event/command processing */
2908 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2909 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002910 return 0;
2911}
2912
2913/**********************/
2914/* mac80211 callbacks */
2915/**********************/
2916
2917static void ath10k_tx(struct ieee80211_hw *hw,
2918 struct ieee80211_tx_control *control,
2919 struct sk_buff *skb)
2920{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002922 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2923 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002924 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925
2926 /* We should disable CCK RATE due to P2P */
2927 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002928 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002929
Michal Kazior4b604552014-07-21 21:03:09 +03002930 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03002931 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03002932 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002933 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002935 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002936 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2937 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002938 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2939 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002940 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002941
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2943 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002944 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002945 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002946 spin_unlock_bh(&ar->data_lock);
2947
Michal Kazior8d6d3622014-11-24 14:58:31 +01002948 if (ath10k_mac_need_offchan_tx_work(ar)) {
2949 ATH10K_SKB_CB(skb)->htt.freq = 0;
2950 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002951
Michal Kazior8d6d3622014-11-24 14:58:31 +01002952 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2953 skb);
2954
2955 skb_queue_tail(&ar->offchan_tx_queue, skb);
2956 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2957 return;
2958 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002959 }
2960
2961 ath10k_tx_htt(ar, skb);
2962}
2963
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002964/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002965void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002966{
2967 /* make sure rcu-protected mac80211 tx path itself is drained */
2968 synchronize_net();
2969
2970 ath10k_offchan_tx_purge(ar);
2971 ath10k_mgmt_over_wmi_tx_purge(ar);
2972
2973 cancel_work_sync(&ar->offchan_tx_work);
2974 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2975}
2976
Michal Kazioraffd3212013-07-16 09:54:35 +02002977void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002978{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002979 struct ath10k_vif *arvif;
2980
Michal Kazior818bdd12013-07-16 09:38:57 +02002981 lockdep_assert_held(&ar->conf_mutex);
2982
Michal Kazior19337472014-08-28 12:58:16 +02002983 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2984 ar->filter_flags = 0;
2985 ar->monitor = false;
2986
2987 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002988 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002989
2990 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002991
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002992 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002993 ath10k_peer_cleanup_all(ar);
2994 ath10k_core_stop(ar);
2995 ath10k_hif_power_down(ar);
2996
2997 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002998 list_for_each_entry(arvif, &ar->arvifs, list)
2999 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003000 spin_unlock_bh(&ar->data_lock);
3001}
3002
Ben Greear46acf7b2014-05-16 17:15:38 +03003003static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3004{
3005 struct ath10k *ar = hw->priv;
3006
3007 mutex_lock(&ar->conf_mutex);
3008
3009 if (ar->cfg_tx_chainmask) {
3010 *tx_ant = ar->cfg_tx_chainmask;
3011 *rx_ant = ar->cfg_rx_chainmask;
3012 } else {
3013 *tx_ant = ar->supp_tx_chainmask;
3014 *rx_ant = ar->supp_rx_chainmask;
3015 }
3016
3017 mutex_unlock(&ar->conf_mutex);
3018
3019 return 0;
3020}
3021
Ben Greear5572a952014-11-24 16:22:10 +02003022static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3023{
3024 /* It is not clear that allowing gaps in chainmask
3025 * is helpful. Probably it will not do what user
3026 * is hoping for, so warn in that case.
3027 */
3028 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3029 return;
3030
3031 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3032 dbg, cm);
3033}
3034
Ben Greear46acf7b2014-05-16 17:15:38 +03003035static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3036{
3037 int ret;
3038
3039 lockdep_assert_held(&ar->conf_mutex);
3040
Ben Greear5572a952014-11-24 16:22:10 +02003041 ath10k_check_chain_mask(ar, tx_ant, "tx");
3042 ath10k_check_chain_mask(ar, rx_ant, "rx");
3043
Ben Greear46acf7b2014-05-16 17:15:38 +03003044 ar->cfg_tx_chainmask = tx_ant;
3045 ar->cfg_rx_chainmask = rx_ant;
3046
3047 if ((ar->state != ATH10K_STATE_ON) &&
3048 (ar->state != ATH10K_STATE_RESTARTED))
3049 return 0;
3050
3051 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3052 tx_ant);
3053 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003054 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003055 ret, tx_ant);
3056 return ret;
3057 }
3058
3059 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3060 rx_ant);
3061 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003062 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003063 ret, rx_ant);
3064 return ret;
3065 }
3066
3067 return 0;
3068}
3069
3070static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3071{
3072 struct ath10k *ar = hw->priv;
3073 int ret;
3074
3075 mutex_lock(&ar->conf_mutex);
3076 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3077 mutex_unlock(&ar->conf_mutex);
3078 return ret;
3079}
3080
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081static int ath10k_start(struct ieee80211_hw *hw)
3082{
3083 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003084 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003085
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003086 /*
3087 * This makes sense only when restarting hw. It is harmless to call
3088 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3089 * commands will be submitted while restarting.
3090 */
3091 ath10k_drain_tx(ar);
3092
Michal Kazior548db542013-07-05 16:15:15 +03003093 mutex_lock(&ar->conf_mutex);
3094
Michal Kaziorc5058f52014-05-26 12:46:03 +03003095 switch (ar->state) {
3096 case ATH10K_STATE_OFF:
3097 ar->state = ATH10K_STATE_ON;
3098 break;
3099 case ATH10K_STATE_RESTARTING:
3100 ath10k_halt(ar);
3101 ar->state = ATH10K_STATE_RESTARTED;
3102 break;
3103 case ATH10K_STATE_ON:
3104 case ATH10K_STATE_RESTARTED:
3105 case ATH10K_STATE_WEDGED:
3106 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003107 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003108 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003109 case ATH10K_STATE_UTF:
3110 ret = -EBUSY;
3111 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003112 }
3113
3114 ret = ath10k_hif_power_up(ar);
3115 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003116 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003117 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003118 }
3119
Kalle Valo43d2a302014-09-10 18:23:30 +03003120 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003121 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003122 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003123 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003124 }
3125
Bartosz Markowski226a3392013-09-26 17:47:16 +02003126 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003127 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003128 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003129 goto err_core_stop;
3130 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003131
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003132 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003133 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003134 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003135 goto err_core_stop;
3136 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003137
Ben Greear46acf7b2014-05-16 17:15:38 +03003138 if (ar->cfg_tx_chainmask)
3139 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3140 ar->cfg_rx_chainmask);
3141
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003142 /*
3143 * By default FW set ARP frames ac to voice (6). In that case ARP
3144 * exchange is not working properly for UAPSD enabled AP. ARP requests
3145 * which arrives with access category 0 are processed by network stack
3146 * and send back with access category 0, but FW changes access category
3147 * to 6. Set ARP frames access category to best effort (0) solves
3148 * this problem.
3149 */
3150
3151 ret = ath10k_wmi_pdev_set_param(ar,
3152 ar->wmi.pdev_param->arp_ac_override, 0);
3153 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003154 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003155 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003156 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003157 }
3158
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303159 ret = ath10k_wmi_pdev_set_param(ar,
3160 ar->wmi.pdev_param->ani_enable, 1);
3161 if (ret) {
3162 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3163 ret);
3164 goto err_core_stop;
3165 }
3166
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303167 ar->ani_enabled = true;
3168
Michal Kaziord6500972014-04-08 09:56:09 +03003169 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003170 ath10k_regd_update(ar);
3171
Simon Wunderlich855aed12014-08-02 09:12:54 +03003172 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303173 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003174
Michal Kaziorae254432014-05-26 12:46:02 +03003175 mutex_unlock(&ar->conf_mutex);
3176 return 0;
3177
3178err_core_stop:
3179 ath10k_core_stop(ar);
3180
3181err_power_down:
3182 ath10k_hif_power_down(ar);
3183
3184err_off:
3185 ar->state = ATH10K_STATE_OFF;
3186
3187err:
Michal Kazior548db542013-07-05 16:15:15 +03003188 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003189 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190}
3191
3192static void ath10k_stop(struct ieee80211_hw *hw)
3193{
3194 struct ath10k *ar = hw->priv;
3195
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003196 ath10k_drain_tx(ar);
3197
Michal Kazior548db542013-07-05 16:15:15 +03003198 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003199 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003200 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003201 ar->state = ATH10K_STATE_OFF;
3202 }
Michal Kazior548db542013-07-05 16:15:15 +03003203 mutex_unlock(&ar->conf_mutex);
3204
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003205 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003206 cancel_work_sync(&ar->restart_work);
3207}
3208
Michal Kaziorad088bf2013-10-16 15:44:46 +03003209static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003210{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003211 struct ath10k_vif *arvif;
3212 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003213
3214 lockdep_assert_held(&ar->conf_mutex);
3215
Michal Kaziorad088bf2013-10-16 15:44:46 +03003216 list_for_each_entry(arvif, &ar->arvifs, list) {
3217 ret = ath10k_mac_vif_setup_ps(arvif);
3218 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003219 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003220 break;
3221 }
3222 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003223
Michal Kaziorad088bf2013-10-16 15:44:46 +03003224 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225}
3226
Michal Kaziorc930f742014-01-23 11:38:25 +01003227static const char *chandef_get_width(enum nl80211_chan_width width)
3228{
3229 switch (width) {
3230 case NL80211_CHAN_WIDTH_20_NOHT:
3231 return "20 (noht)";
3232 case NL80211_CHAN_WIDTH_20:
3233 return "20";
3234 case NL80211_CHAN_WIDTH_40:
3235 return "40";
3236 case NL80211_CHAN_WIDTH_80:
3237 return "80";
3238 case NL80211_CHAN_WIDTH_80P80:
3239 return "80+80";
3240 case NL80211_CHAN_WIDTH_160:
3241 return "160";
3242 case NL80211_CHAN_WIDTH_5:
3243 return "5";
3244 case NL80211_CHAN_WIDTH_10:
3245 return "10";
3246 }
3247 return "?";
3248}
3249
3250static void ath10k_config_chan(struct ath10k *ar)
3251{
3252 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003253 int ret;
3254
3255 lockdep_assert_held(&ar->conf_mutex);
3256
Michal Kazior7aa7a722014-08-25 12:09:38 +02003257 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003258 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3259 ar->chandef.chan->center_freq,
3260 ar->chandef.center_freq1,
3261 ar->chandef.center_freq2,
3262 chandef_get_width(ar->chandef.width));
3263
3264 /* First stop monitor interface. Some FW versions crash if there's a
3265 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003266 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003267 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003268
3269 list_for_each_entry(arvif, &ar->arvifs, list) {
3270 if (!arvif->is_started)
3271 continue;
3272
Michal Kaziordc55e302014-07-29 12:53:36 +03003273 if (!arvif->is_up)
3274 continue;
3275
Michal Kaziorc930f742014-01-23 11:38:25 +01003276 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3277 continue;
3278
Michal Kaziordc55e302014-07-29 12:53:36 +03003279 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003280 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003281 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003282 arvif->vdev_id, ret);
3283 continue;
3284 }
3285 }
3286
Michal Kaziordc55e302014-07-29 12:53:36 +03003287 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003288
3289 list_for_each_entry(arvif, &ar->arvifs, list) {
3290 if (!arvif->is_started)
3291 continue;
3292
3293 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3294 continue;
3295
Michal Kazior81a9a172015-03-05 16:02:17 +02003296 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3297 if (ret)
3298 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3299 ret);
3300
3301 ret = ath10k_mac_setup_prb_tmpl(arvif);
3302 if (ret)
3303 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3304 ret);
3305
Michal Kaziordc55e302014-07-29 12:53:36 +03003306 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003307 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003308 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003309 arvif->vdev_id, ret);
3310 continue;
3311 }
3312
3313 if (!arvif->is_up)
3314 continue;
3315
3316 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3317 arvif->bssid);
3318 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003319 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003320 arvif->vdev_id, ret);
3321 continue;
3322 }
3323 }
3324
Michal Kazior19337472014-08-28 12:58:16 +02003325 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003326}
3327
Michal Kazior7d9d5582014-10-21 10:40:15 +03003328static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3329{
3330 int ret;
3331 u32 param;
3332
3333 lockdep_assert_held(&ar->conf_mutex);
3334
3335 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3336
3337 param = ar->wmi.pdev_param->txpower_limit2g;
3338 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3339 if (ret) {
3340 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3341 txpower, ret);
3342 return ret;
3343 }
3344
3345 param = ar->wmi.pdev_param->txpower_limit5g;
3346 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3347 if (ret) {
3348 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3349 txpower, ret);
3350 return ret;
3351 }
3352
3353 return 0;
3354}
3355
3356static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3357{
3358 struct ath10k_vif *arvif;
3359 int ret, txpower = -1;
3360
3361 lockdep_assert_held(&ar->conf_mutex);
3362
3363 list_for_each_entry(arvif, &ar->arvifs, list) {
3364 WARN_ON(arvif->txpower < 0);
3365
3366 if (txpower == -1)
3367 txpower = arvif->txpower;
3368 else
3369 txpower = min(txpower, arvif->txpower);
3370 }
3371
3372 if (WARN_ON(txpower == -1))
3373 return -EINVAL;
3374
3375 ret = ath10k_mac_txpower_setup(ar, txpower);
3376 if (ret) {
3377 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3378 txpower, ret);
3379 return ret;
3380 }
3381
3382 return 0;
3383}
3384
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3386{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003387 struct ath10k *ar = hw->priv;
3388 struct ieee80211_conf *conf = &hw->conf;
3389 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003390
3391 mutex_lock(&ar->conf_mutex);
3392
3393 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003394 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003395 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003396 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003397 conf->chandef.chan->flags,
3398 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003399
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 spin_lock_bh(&ar->data_lock);
3401 ar->rx_channel = conf->chandef.chan;
3402 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003403
Michal Kaziord6500972014-04-08 09:56:09 +03003404 ar->radar_enabled = conf->radar_enabled;
3405 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003406
3407 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3408 ar->chandef = conf->chandef;
3409 ath10k_config_chan(ar);
3410 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003411 }
3412
Michal Kazioraffd3212013-07-16 09:54:35 +02003413 if (changed & IEEE80211_CONF_CHANGE_PS)
3414 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003415
3416 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003417 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3418 ret = ath10k_monitor_recalc(ar);
3419 if (ret)
3420 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003421 }
3422
3423 mutex_unlock(&ar->conf_mutex);
3424 return ret;
3425}
3426
Ben Greear5572a952014-11-24 16:22:10 +02003427static u32 get_nss_from_chainmask(u16 chain_mask)
3428{
3429 if ((chain_mask & 0x15) == 0x15)
3430 return 4;
3431 else if ((chain_mask & 0x7) == 0x7)
3432 return 3;
3433 else if ((chain_mask & 0x3) == 0x3)
3434 return 2;
3435 return 1;
3436}
3437
Kalle Valo5e3dd152013-06-12 20:52:10 +03003438/*
3439 * TODO:
3440 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3441 * because we will send mgmt frames without CCK. This requirement
3442 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3443 * in the TX packet.
3444 */
3445static int ath10k_add_interface(struct ieee80211_hw *hw,
3446 struct ieee80211_vif *vif)
3447{
3448 struct ath10k *ar = hw->priv;
3449 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3450 enum wmi_sta_powersave_param param;
3451 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003452 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003453 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003454 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003455
Johannes Berg848955c2014-11-11 12:48:42 +01003456 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3457
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458 mutex_lock(&ar->conf_mutex);
3459
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003460 memset(arvif, 0, sizeof(*arvif));
3461
Kalle Valo5e3dd152013-06-12 20:52:10 +03003462 arvif->ar = ar;
3463 arvif->vif = vif;
3464
Ben Greeare63b33f2013-10-22 14:54:14 -07003465 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003466 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003467 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3468 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003469
Ben Greeara9aefb32014-08-12 11:02:19 +03003470 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003471 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003472 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003473 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003474 }
Ben Greear16c11172014-09-23 14:17:16 -07003475 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476
Ben Greear16c11172014-09-23 14:17:16 -07003477 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3478 bit, ar->free_vdev_map);
3479
3480 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482
Kalle Valo5e3dd152013-06-12 20:52:10 +03003483 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003484 case NL80211_IFTYPE_P2P_DEVICE:
3485 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3486 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3487 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003488 case NL80211_IFTYPE_UNSPECIFIED:
3489 case NL80211_IFTYPE_STATION:
3490 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3491 if (vif->p2p)
3492 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3493 break;
3494 case NL80211_IFTYPE_ADHOC:
3495 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3496 break;
3497 case NL80211_IFTYPE_AP:
3498 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3499
3500 if (vif->p2p)
3501 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3502 break;
3503 case NL80211_IFTYPE_MONITOR:
3504 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3505 break;
3506 default:
3507 WARN_ON(1);
3508 break;
3509 }
3510
Michal Kazior64badcb2014-09-18 11:18:02 +03003511 /* Some firmware revisions don't wait for beacon tx completion before
3512 * sending another SWBA event. This could lead to hardware using old
3513 * (freed) beacon data in some cases, e.g. tx credit starvation
3514 * combined with missed TBTT. This is very very rare.
3515 *
3516 * On non-IOMMU-enabled hosts this could be a possible security issue
3517 * because hw could beacon some random data on the air. On
3518 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3519 * device would crash.
3520 *
3521 * Since there are no beacon tx completions (implicit nor explicit)
3522 * propagated to host the only workaround for this is to allocate a
3523 * DMA-coherent buffer for a lifetime of a vif and use it for all
3524 * beacon tx commands. Worst case for this approach is some beacons may
3525 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3526 */
3527 if (vif->type == NL80211_IFTYPE_ADHOC ||
3528 vif->type == NL80211_IFTYPE_AP) {
3529 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3530 IEEE80211_MAX_FRAME_LEN,
3531 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303532 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003533 if (!arvif->beacon_buf) {
3534 ret = -ENOMEM;
3535 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3536 ret);
3537 goto err;
3538 }
3539 }
3540
3541 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3542 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3543 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544
3545 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3546 arvif->vdev_subtype, vif->addr);
3547 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003548 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003549 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003550 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003551 }
3552
Ben Greear16c11172014-09-23 14:17:16 -07003553 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003554 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003555
Michal Kazior46725b152015-01-28 09:57:49 +02003556 /* It makes no sense to have firmware do keepalives. mac80211 already
3557 * takes care of this with idle connection polling.
3558 */
3559 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003560 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003561 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003562 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003563 goto err_vdev_delete;
3564 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003565
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003566 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003568 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3569 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003570 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003571 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003572 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003573 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003574 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003575 goto err_vdev_delete;
3576 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577
Ben Greear5572a952014-11-24 16:22:10 +02003578 if (ar->cfg_tx_chainmask) {
3579 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3580
3581 vdev_param = ar->wmi.vdev_param->nss;
3582 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3583 nss);
3584 if (ret) {
3585 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3586 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3587 ret);
3588 goto err_vdev_delete;
3589 }
3590 }
3591
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3593 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3594 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003595 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003596 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003597 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003598 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003599
Kalle Valo5a13e762014-01-20 11:01:46 +02003600 ret = ath10k_mac_set_kickout(arvif);
3601 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003602 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003603 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003604 goto err_peer_delete;
3605 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003606 }
3607
3608 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3609 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3610 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3611 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3612 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003613 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003614 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003615 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003616 goto err_peer_delete;
3617 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618
Michal Kazior9f9b5742014-12-12 12:41:36 +01003619 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003620 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003621 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003622 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003623 goto err_peer_delete;
3624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003625
Michal Kazior9f9b5742014-12-12 12:41:36 +01003626 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003627 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003628 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003629 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003630 goto err_peer_delete;
3631 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632 }
3633
Michal Kazior424121c2013-07-22 14:13:31 +02003634 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003635 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003636 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003637 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003638 goto err_peer_delete;
3639 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003640
Michal Kazior424121c2013-07-22 14:13:31 +02003641 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003642 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003643 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003644 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003645 goto err_peer_delete;
3646 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003647
Michal Kazior7d9d5582014-10-21 10:40:15 +03003648 arvif->txpower = vif->bss_conf.txpower;
3649 ret = ath10k_mac_txpower_recalc(ar);
3650 if (ret) {
3651 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3652 goto err_peer_delete;
3653 }
3654
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003656 return 0;
3657
3658err_peer_delete:
3659 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3660 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3661
3662err_vdev_delete:
3663 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003664 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003665 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003666
3667err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003668 if (arvif->beacon_buf) {
3669 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3670 arvif->beacon_buf, arvif->beacon_paddr);
3671 arvif->beacon_buf = NULL;
3672 }
3673
Michal Kazior9dad14a2013-10-16 15:44:45 +03003674 mutex_unlock(&ar->conf_mutex);
3675
Kalle Valo5e3dd152013-06-12 20:52:10 +03003676 return ret;
3677}
3678
3679static void ath10k_remove_interface(struct ieee80211_hw *hw,
3680 struct ieee80211_vif *vif)
3681{
3682 struct ath10k *ar = hw->priv;
3683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3684 int ret;
3685
Michal Kazior81a9a172015-03-05 16:02:17 +02003686 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003687 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003688
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303689 mutex_lock(&ar->conf_mutex);
3690
Michal Kaziored543882013-09-13 14:16:56 +02003691 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003692 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003693 spin_unlock_bh(&ar->data_lock);
3694
Simon Wunderlich855aed12014-08-02 09:12:54 +03003695 ret = ath10k_spectral_vif_stop(arvif);
3696 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003697 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003698 arvif->vdev_id, ret);
3699
Ben Greear16c11172014-09-23 14:17:16 -07003700 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003701 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003702
3703 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003704 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3705 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003706 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003707 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003708 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003709
3710 kfree(arvif->u.ap.noa_data);
3711 }
3712
Michal Kazior7aa7a722014-08-25 12:09:38 +02003713 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003714 arvif->vdev_id);
3715
Kalle Valo5e3dd152013-06-12 20:52:10 +03003716 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3717 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003718 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003719 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003720
Michal Kazior2c512052015-02-15 16:50:40 +02003721 /* Some firmware revisions don't notify host about self-peer removal
3722 * until after associated vdev is deleted.
3723 */
3724 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3725 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3726 vif->addr);
3727 if (ret)
3728 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3729 arvif->vdev_id, ret);
3730
3731 spin_lock_bh(&ar->data_lock);
3732 ar->num_peers--;
3733 spin_unlock_bh(&ar->data_lock);
3734 }
3735
Kalle Valo5e3dd152013-06-12 20:52:10 +03003736 ath10k_peer_cleanup(ar, arvif->vdev_id);
3737
3738 mutex_unlock(&ar->conf_mutex);
3739}
3740
3741/*
3742 * FIXME: Has to be verified.
3743 */
3744#define SUPPORTED_FILTERS \
3745 (FIF_PROMISC_IN_BSS | \
3746 FIF_ALLMULTI | \
3747 FIF_CONTROL | \
3748 FIF_PSPOLL | \
3749 FIF_OTHER_BSS | \
3750 FIF_BCN_PRBRESP_PROMISC | \
3751 FIF_PROBE_REQ | \
3752 FIF_FCSFAIL)
3753
3754static void ath10k_configure_filter(struct ieee80211_hw *hw,
3755 unsigned int changed_flags,
3756 unsigned int *total_flags,
3757 u64 multicast)
3758{
3759 struct ath10k *ar = hw->priv;
3760 int ret;
3761
3762 mutex_lock(&ar->conf_mutex);
3763
3764 changed_flags &= SUPPORTED_FILTERS;
3765 *total_flags &= SUPPORTED_FILTERS;
3766 ar->filter_flags = *total_flags;
3767
Michal Kazior19337472014-08-28 12:58:16 +02003768 ret = ath10k_monitor_recalc(ar);
3769 if (ret)
3770 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003771
3772 mutex_unlock(&ar->conf_mutex);
3773}
3774
3775static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3776 struct ieee80211_vif *vif,
3777 struct ieee80211_bss_conf *info,
3778 u32 changed)
3779{
3780 struct ath10k *ar = hw->priv;
3781 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3782 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003783 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003784
3785 mutex_lock(&ar->conf_mutex);
3786
3787 if (changed & BSS_CHANGED_IBSS)
3788 ath10k_control_ibss(arvif, info, vif->addr);
3789
3790 if (changed & BSS_CHANGED_BEACON_INT) {
3791 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003792 vdev_param = ar->wmi.vdev_param->beacon_interval;
3793 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003794 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003795 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003796 "mac vdev %d beacon_interval %d\n",
3797 arvif->vdev_id, arvif->beacon_interval);
3798
Kalle Valo5e3dd152013-06-12 20:52:10 +03003799 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003800 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003801 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003802 }
3803
3804 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003805 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003806 "vdev %d set beacon tx mode to staggered\n",
3807 arvif->vdev_id);
3808
Bartosz Markowski226a3392013-09-26 17:47:16 +02003809 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3810 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003811 WMI_BEACON_STAGGERED_MODE);
3812 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003813 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003814 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003815
3816 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3817 if (ret)
3818 ath10k_warn(ar, "failed to update beacon template: %d\n",
3819 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003820 }
3821
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003822 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3823 ret = ath10k_mac_setup_prb_tmpl(arvif);
3824 if (ret)
3825 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3826 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827 }
3828
Michal Kaziorba2479f2015-01-24 12:14:51 +02003829 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003830 arvif->dtim_period = info->dtim_period;
3831
Michal Kazior7aa7a722014-08-25 12:09:38 +02003832 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003833 "mac vdev %d dtim_period %d\n",
3834 arvif->vdev_id, arvif->dtim_period);
3835
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003836 vdev_param = ar->wmi.vdev_param->dtim_period;
3837 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003838 arvif->dtim_period);
3839 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003840 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003841 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003842 }
3843
3844 if (changed & BSS_CHANGED_SSID &&
3845 vif->type == NL80211_IFTYPE_AP) {
3846 arvif->u.ap.ssid_len = info->ssid_len;
3847 if (info->ssid_len)
3848 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3849 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3850 }
3851
Michal Kazior077efc82014-10-21 10:10:29 +03003852 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3853 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003854
3855 if (changed & BSS_CHANGED_BEACON_ENABLED)
3856 ath10k_control_beaconing(arvif, info);
3857
3858 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003859 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003860 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003861 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003862
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003863 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003864 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003865 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003866 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003867
3868 vdev_param = ar->wmi.vdev_param->protection_mode;
3869 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3870 info->use_cts_prot ? 1 : 0);
3871 if (ret)
3872 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3873 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003874 }
3875
3876 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003877 if (info->use_short_slot)
3878 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3879
3880 else
3881 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3882
Michal Kazior7aa7a722014-08-25 12:09:38 +02003883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003884 arvif->vdev_id, slottime);
3885
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003886 vdev_param = ar->wmi.vdev_param->slot_time;
3887 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888 slottime);
3889 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003890 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003891 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003892 }
3893
3894 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895 if (info->use_short_preamble)
3896 preamble = WMI_VDEV_PREAMBLE_SHORT;
3897 else
3898 preamble = WMI_VDEV_PREAMBLE_LONG;
3899
Michal Kazior7aa7a722014-08-25 12:09:38 +02003900 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003901 "mac vdev %d preamble %dn",
3902 arvif->vdev_id, preamble);
3903
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003904 vdev_param = ar->wmi.vdev_param->preamble;
3905 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003906 preamble);
3907 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003908 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003909 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003910 }
3911
3912 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003913 if (info->assoc) {
3914 /* Workaround: Make sure monitor vdev is not running
3915 * when associating to prevent some firmware revisions
3916 * (e.g. 10.1 and 10.2) from crashing.
3917 */
3918 if (ar->monitor_started)
3919 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003921 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003922 } else {
3923 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003924 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003925 }
3926
Michal Kazior7d9d5582014-10-21 10:40:15 +03003927 if (changed & BSS_CHANGED_TXPOWER) {
3928 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3929 arvif->vdev_id, info->txpower);
3930
3931 arvif->txpower = info->txpower;
3932 ret = ath10k_mac_txpower_recalc(ar);
3933 if (ret)
3934 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3935 }
3936
Michal Kaziorbf14e652014-12-12 12:41:38 +01003937 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003938 arvif->ps = vif->bss_conf.ps;
3939
3940 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003941 if (ret)
3942 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3943 arvif->vdev_id, ret);
3944 }
3945
Kalle Valo5e3dd152013-06-12 20:52:10 +03003946 mutex_unlock(&ar->conf_mutex);
3947}
3948
3949static int ath10k_hw_scan(struct ieee80211_hw *hw,
3950 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003951 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003952{
3953 struct ath10k *ar = hw->priv;
3954 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003955 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003956 struct wmi_start_scan_arg arg;
3957 int ret = 0;
3958 int i;
3959
3960 mutex_lock(&ar->conf_mutex);
3961
3962 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003963 switch (ar->scan.state) {
3964 case ATH10K_SCAN_IDLE:
3965 reinit_completion(&ar->scan.started);
3966 reinit_completion(&ar->scan.completed);
3967 ar->scan.state = ATH10K_SCAN_STARTING;
3968 ar->scan.is_roc = false;
3969 ar->scan.vdev_id = arvif->vdev_id;
3970 ret = 0;
3971 break;
3972 case ATH10K_SCAN_STARTING:
3973 case ATH10K_SCAN_RUNNING:
3974 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003975 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003976 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 spin_unlock_bh(&ar->data_lock);
3979
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003980 if (ret)
3981 goto exit;
3982
Kalle Valo5e3dd152013-06-12 20:52:10 +03003983 memset(&arg, 0, sizeof(arg));
3984 ath10k_wmi_start_scan_init(ar, &arg);
3985 arg.vdev_id = arvif->vdev_id;
3986 arg.scan_id = ATH10K_SCAN_ID;
3987
3988 if (!req->no_cck)
3989 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3990
3991 if (req->ie_len) {
3992 arg.ie_len = req->ie_len;
3993 memcpy(arg.ie, req->ie, arg.ie_len);
3994 }
3995
3996 if (req->n_ssids) {
3997 arg.n_ssids = req->n_ssids;
3998 for (i = 0; i < arg.n_ssids; i++) {
3999 arg.ssids[i].len = req->ssids[i].ssid_len;
4000 arg.ssids[i].ssid = req->ssids[i].ssid;
4001 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004002 } else {
4003 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004004 }
4005
4006 if (req->n_channels) {
4007 arg.n_channels = req->n_channels;
4008 for (i = 0; i < arg.n_channels; i++)
4009 arg.channels[i] = req->channels[i]->center_freq;
4010 }
4011
4012 ret = ath10k_start_scan(ar, &arg);
4013 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004014 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004015 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004016 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017 spin_unlock_bh(&ar->data_lock);
4018 }
4019
4020exit:
4021 mutex_unlock(&ar->conf_mutex);
4022 return ret;
4023}
4024
4025static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4026 struct ieee80211_vif *vif)
4027{
4028 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004029
4030 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004031 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004032 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004033
4034 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004035}
4036
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004037static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4038 struct ath10k_vif *arvif,
4039 enum set_key_cmd cmd,
4040 struct ieee80211_key_conf *key)
4041{
4042 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4043 int ret;
4044
4045 /* 10.1 firmware branch requires default key index to be set to group
4046 * key index after installing it. Otherwise FW/HW Txes corrupted
4047 * frames with multi-vif APs. This is not required for main firmware
4048 * branch (e.g. 636).
4049 *
4050 * FIXME: This has been tested only in AP. It remains unknown if this
4051 * is required for multi-vif STA interfaces on 10.1 */
4052
4053 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4054 return;
4055
4056 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4057 return;
4058
4059 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4060 return;
4061
4062 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4063 return;
4064
4065 if (cmd != SET_KEY)
4066 return;
4067
4068 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4069 key->keyidx);
4070 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004071 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004072 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004073}
4074
Kalle Valo5e3dd152013-06-12 20:52:10 +03004075static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4076 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4077 struct ieee80211_key_conf *key)
4078{
4079 struct ath10k *ar = hw->priv;
4080 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4081 struct ath10k_peer *peer;
4082 const u8 *peer_addr;
4083 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4084 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4085 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004086 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004087
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004088 /* this one needs to be done in software */
4089 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4090 return 1;
4091
Kalle Valo5e3dd152013-06-12 20:52:10 +03004092 if (key->keyidx > WMI_MAX_KEY_INDEX)
4093 return -ENOSPC;
4094
4095 mutex_lock(&ar->conf_mutex);
4096
4097 if (sta)
4098 peer_addr = sta->addr;
4099 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4100 peer_addr = vif->bss_conf.bssid;
4101 else
4102 peer_addr = vif->addr;
4103
4104 key->hw_key_idx = key->keyidx;
4105
4106 /* the peer should not disappear in mid-way (unless FW goes awry) since
4107 * we already hold conf_mutex. we just make sure its there now. */
4108 spin_lock_bh(&ar->data_lock);
4109 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4110 spin_unlock_bh(&ar->data_lock);
4111
4112 if (!peer) {
4113 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004114 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004115 peer_addr);
4116 ret = -EOPNOTSUPP;
4117 goto exit;
4118 } else {
4119 /* if the peer doesn't exist there is no key to disable
4120 * anymore */
4121 goto exit;
4122 }
4123 }
4124
Michal Kazior7cc45732015-03-09 14:24:17 +01004125 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4126 flags |= WMI_KEY_PAIRWISE;
4127 else
4128 flags |= WMI_KEY_GROUP;
4129
Kalle Valo5e3dd152013-06-12 20:52:10 +03004130 if (is_wep) {
4131 if (cmd == SET_KEY)
4132 arvif->wep_keys[key->keyidx] = key;
4133 else
4134 arvif->wep_keys[key->keyidx] = NULL;
4135
4136 if (cmd == DISABLE_KEY)
4137 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004138
Michal Kaziorad325cb2015-02-18 14:02:27 +01004139 /* When WEP keys are uploaded it's possible that there are
4140 * stations associated already (e.g. when merging) without any
4141 * keys. Static WEP needs an explicit per-peer key upload.
4142 */
4143 if (vif->type == NL80211_IFTYPE_ADHOC &&
4144 cmd == SET_KEY)
4145 ath10k_mac_vif_update_wep_key(arvif, key);
4146
Michal Kazior370e5672015-02-18 14:02:26 +01004147 /* 802.1x never sets the def_wep_key_idx so each set_key()
4148 * call changes default tx key.
4149 *
4150 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4151 * after first set_key().
4152 */
4153 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4154 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004155
Michal Kazior7cc45732015-03-09 14:24:17 +01004156 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4157 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4158 * mode and associated stations in AP/IBSS.
4159 *
4160 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4161 * work fine when mapped directly from mac80211.
4162 *
4163 * Note: When installing first static WEP groupwise key (which
4164 * should be pairwise) def_wep_key_idx isn't known yet (it's
4165 * equal to -1). Since .set_default_unicast_key is called only
4166 * for static WEP it's used to re-upload the key as pairwise.
4167 */
4168 if (arvif->def_wep_key_idx >= 0 &&
4169 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4170 flags &= ~WMI_KEY_GROUP;
4171 flags |= WMI_KEY_PAIRWISE;
4172 }
Michal Kazior370e5672015-02-18 14:02:26 +01004173 }
4174
4175 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004176 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004177 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004178 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004179 goto exit;
4180 }
4181
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004182 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4183
Kalle Valo5e3dd152013-06-12 20:52:10 +03004184 spin_lock_bh(&ar->data_lock);
4185 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4186 if (peer && cmd == SET_KEY)
4187 peer->keys[key->keyidx] = key;
4188 else if (peer && cmd == DISABLE_KEY)
4189 peer->keys[key->keyidx] = NULL;
4190 else if (peer == NULL)
4191 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004192 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004193 spin_unlock_bh(&ar->data_lock);
4194
4195exit:
4196 mutex_unlock(&ar->conf_mutex);
4197 return ret;
4198}
4199
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004200static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4201 struct ieee80211_vif *vif,
4202 int keyidx)
4203{
4204 struct ath10k *ar = hw->priv;
4205 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4206 int ret;
4207
4208 mutex_lock(&arvif->ar->conf_mutex);
4209
4210 if (arvif->ar->state != ATH10K_STATE_ON)
4211 goto unlock;
4212
4213 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4214 arvif->vdev_id, keyidx);
4215
4216 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4217 arvif->vdev_id,
4218 arvif->ar->wmi.vdev_param->def_keyid,
4219 keyidx);
4220
4221 if (ret) {
4222 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4223 arvif->vdev_id,
4224 ret);
4225 goto unlock;
4226 }
4227
4228 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004229
4230 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4231 if (ret) {
4232 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4233 arvif->vdev_id, ret);
4234 goto unlock;
4235 }
4236
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004237unlock:
4238 mutex_unlock(&arvif->ar->conf_mutex);
4239}
4240
Michal Kazior9797feb2014-02-14 14:49:48 +01004241static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4242{
4243 struct ath10k *ar;
4244 struct ath10k_vif *arvif;
4245 struct ath10k_sta *arsta;
4246 struct ieee80211_sta *sta;
4247 u32 changed, bw, nss, smps;
4248 int err;
4249
4250 arsta = container_of(wk, struct ath10k_sta, update_wk);
4251 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4252 arvif = arsta->arvif;
4253 ar = arvif->ar;
4254
4255 spin_lock_bh(&ar->data_lock);
4256
4257 changed = arsta->changed;
4258 arsta->changed = 0;
4259
4260 bw = arsta->bw;
4261 nss = arsta->nss;
4262 smps = arsta->smps;
4263
4264 spin_unlock_bh(&ar->data_lock);
4265
4266 mutex_lock(&ar->conf_mutex);
4267
4268 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004269 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004270 sta->addr, bw);
4271
4272 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4273 WMI_PEER_CHAN_WIDTH, bw);
4274 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004275 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004276 sta->addr, bw, err);
4277 }
4278
4279 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004280 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004281 sta->addr, nss);
4282
4283 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4284 WMI_PEER_NSS, nss);
4285 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004286 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004287 sta->addr, nss, err);
4288 }
4289
4290 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004291 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004292 sta->addr, smps);
4293
4294 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4295 WMI_PEER_SMPS_STATE, smps);
4296 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004297 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004298 sta->addr, smps, err);
4299 }
4300
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004301 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4302 changed & IEEE80211_RC_NSS_CHANGED) {
4303 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004304 sta->addr);
4305
Michal Kazior590922a2014-10-21 10:10:29 +03004306 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004307 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004308 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004309 sta->addr);
4310 }
4311
Michal Kazior9797feb2014-02-14 14:49:48 +01004312 mutex_unlock(&ar->conf_mutex);
4313}
4314
Michal Kaziorcfd10612014-11-25 15:16:05 +01004315static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4316{
4317 struct ath10k *ar = arvif->ar;
4318
4319 lockdep_assert_held(&ar->conf_mutex);
4320
4321 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4322 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4323 return 0;
4324
4325 if (ar->num_stations >= ar->max_num_stations)
4326 return -ENOBUFS;
4327
4328 ar->num_stations++;
4329
4330 return 0;
4331}
4332
4333static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4334{
4335 struct ath10k *ar = arvif->ar;
4336
4337 lockdep_assert_held(&ar->conf_mutex);
4338
4339 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4340 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4341 return;
4342
4343 ar->num_stations--;
4344}
4345
Kalle Valo5e3dd152013-06-12 20:52:10 +03004346static int ath10k_sta_state(struct ieee80211_hw *hw,
4347 struct ieee80211_vif *vif,
4348 struct ieee80211_sta *sta,
4349 enum ieee80211_sta_state old_state,
4350 enum ieee80211_sta_state new_state)
4351{
4352 struct ath10k *ar = hw->priv;
4353 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004354 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004355 int ret = 0;
4356
Michal Kazior76f90022014-02-25 09:29:57 +02004357 if (old_state == IEEE80211_STA_NOTEXIST &&
4358 new_state == IEEE80211_STA_NONE) {
4359 memset(arsta, 0, sizeof(*arsta));
4360 arsta->arvif = arvif;
4361 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4362 }
4363
Michal Kazior9797feb2014-02-14 14:49:48 +01004364 /* cancel must be done outside the mutex to avoid deadlock */
4365 if ((old_state == IEEE80211_STA_NONE &&
4366 new_state == IEEE80211_STA_NOTEXIST))
4367 cancel_work_sync(&arsta->update_wk);
4368
Kalle Valo5e3dd152013-06-12 20:52:10 +03004369 mutex_lock(&ar->conf_mutex);
4370
4371 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004372 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 /*
4374 * New station addition.
4375 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004376 ath10k_dbg(ar, ATH10K_DBG_MAC,
4377 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4378 arvif->vdev_id, sta->addr,
4379 ar->num_stations + 1, ar->max_num_stations,
4380 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004381
Michal Kaziorcfd10612014-11-25 15:16:05 +01004382 ret = ath10k_mac_inc_num_stations(arvif);
4383 if (ret) {
4384 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4385 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004386 goto exit;
4387 }
4388
Kalle Valo5e3dd152013-06-12 20:52:10 +03004389 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004390 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004391 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 -08004392 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004393 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004394 goto exit;
4395 }
Michal Kazior077efc82014-10-21 10:10:29 +03004396
4397 if (vif->type == NL80211_IFTYPE_STATION) {
4398 WARN_ON(arvif->is_started);
4399
4400 ret = ath10k_vdev_start(arvif);
4401 if (ret) {
4402 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4403 arvif->vdev_id, ret);
4404 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4405 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004406 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004407 goto exit;
4408 }
4409
4410 arvif->is_started = true;
4411 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412 } else if ((old_state == IEEE80211_STA_NONE &&
4413 new_state == IEEE80211_STA_NOTEXIST)) {
4414 /*
4415 * Existing station deletion.
4416 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004417 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004418 "mac vdev %d peer delete %pM (sta gone)\n",
4419 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004420
4421 if (vif->type == NL80211_IFTYPE_STATION) {
4422 WARN_ON(!arvif->is_started);
4423
4424 ret = ath10k_vdev_stop(arvif);
4425 if (ret)
4426 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4427 arvif->vdev_id, ret);
4428
4429 arvif->is_started = false;
4430 }
4431
Kalle Valo5e3dd152013-06-12 20:52:10 +03004432 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4433 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004434 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004435 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004436
Michal Kaziorcfd10612014-11-25 15:16:05 +01004437 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004438 } else if (old_state == IEEE80211_STA_AUTH &&
4439 new_state == IEEE80211_STA_ASSOC &&
4440 (vif->type == NL80211_IFTYPE_AP ||
4441 vif->type == NL80211_IFTYPE_ADHOC)) {
4442 /*
4443 * New association.
4444 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004445 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004446 sta->addr);
4447
Michal Kazior590922a2014-10-21 10:10:29 +03004448 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004449 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004450 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004451 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004452 } else if (old_state == IEEE80211_STA_ASSOC &&
4453 new_state == IEEE80211_STA_AUTH &&
4454 (vif->type == NL80211_IFTYPE_AP ||
4455 vif->type == NL80211_IFTYPE_ADHOC)) {
4456 /*
4457 * Disassociation.
4458 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004459 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004460 sta->addr);
4461
Michal Kazior590922a2014-10-21 10:10:29 +03004462 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004464 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004465 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004466 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004467exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004468 mutex_unlock(&ar->conf_mutex);
4469 return ret;
4470}
4471
4472static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004473 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004474{
4475 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004476 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4477 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004478 u32 value = 0;
4479 int ret = 0;
4480
Michal Kazior548db542013-07-05 16:15:15 +03004481 lockdep_assert_held(&ar->conf_mutex);
4482
Kalle Valo5e3dd152013-06-12 20:52:10 +03004483 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4484 return 0;
4485
4486 switch (ac) {
4487 case IEEE80211_AC_VO:
4488 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4489 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004490 prio = 7;
4491 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004492 break;
4493 case IEEE80211_AC_VI:
4494 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4495 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004496 prio = 5;
4497 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004498 break;
4499 case IEEE80211_AC_BE:
4500 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4501 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004502 prio = 2;
4503 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004504 break;
4505 case IEEE80211_AC_BK:
4506 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4507 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004508 prio = 0;
4509 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 break;
4511 }
4512
4513 if (enable)
4514 arvif->u.sta.uapsd |= value;
4515 else
4516 arvif->u.sta.uapsd &= ~value;
4517
4518 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4519 WMI_STA_PS_PARAM_UAPSD,
4520 arvif->u.sta.uapsd);
4521 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004522 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004523 goto exit;
4524 }
4525
4526 if (arvif->u.sta.uapsd)
4527 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4528 else
4529 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4530
4531 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4532 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4533 value);
4534 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004535 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004536
Michal Kazior9f9b5742014-12-12 12:41:36 +01004537 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4538 if (ret) {
4539 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4540 arvif->vdev_id, ret);
4541 return ret;
4542 }
4543
4544 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4545 if (ret) {
4546 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4547 arvif->vdev_id, ret);
4548 return ret;
4549 }
4550
Michal Kaziorb0e56152015-01-24 12:14:52 +02004551 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4552 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4553 /* Only userspace can make an educated decision when to send
4554 * trigger frame. The following effectively disables u-UAPSD
4555 * autotrigger in firmware (which is enabled by default
4556 * provided the autotrigger service is available).
4557 */
4558
4559 arg.wmm_ac = acc;
4560 arg.user_priority = prio;
4561 arg.service_interval = 0;
4562 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4563 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4564
4565 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4566 arvif->bssid, &arg, 1);
4567 if (ret) {
4568 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4569 ret);
4570 return ret;
4571 }
4572 }
4573
Kalle Valo5e3dd152013-06-12 20:52:10 +03004574exit:
4575 return ret;
4576}
4577
4578static int ath10k_conf_tx(struct ieee80211_hw *hw,
4579 struct ieee80211_vif *vif, u16 ac,
4580 const struct ieee80211_tx_queue_params *params)
4581{
4582 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004583 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004584 struct wmi_wmm_params_arg *p = NULL;
4585 int ret;
4586
4587 mutex_lock(&ar->conf_mutex);
4588
4589 switch (ac) {
4590 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004591 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592 break;
4593 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004594 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004595 break;
4596 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004597 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004598 break;
4599 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004600 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004601 break;
4602 }
4603
4604 if (WARN_ON(!p)) {
4605 ret = -EINVAL;
4606 goto exit;
4607 }
4608
4609 p->cwmin = params->cw_min;
4610 p->cwmax = params->cw_max;
4611 p->aifs = params->aifs;
4612
4613 /*
4614 * The channel time duration programmed in the HW is in absolute
4615 * microseconds, while mac80211 gives the txop in units of
4616 * 32 microseconds.
4617 */
4618 p->txop = params->txop * 32;
4619
Michal Kazior7fc979a2015-01-28 09:57:28 +02004620 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4621 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4622 &arvif->wmm_params);
4623 if (ret) {
4624 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4625 arvif->vdev_id, ret);
4626 goto exit;
4627 }
4628 } else {
4629 /* This won't work well with multi-interface cases but it's
4630 * better than nothing.
4631 */
4632 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4633 if (ret) {
4634 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4635 goto exit;
4636 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004637 }
4638
4639 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4640 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004641 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004642
4643exit:
4644 mutex_unlock(&ar->conf_mutex);
4645 return ret;
4646}
4647
4648#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4649
4650static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4651 struct ieee80211_vif *vif,
4652 struct ieee80211_channel *chan,
4653 int duration,
4654 enum ieee80211_roc_type type)
4655{
4656 struct ath10k *ar = hw->priv;
4657 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4658 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004659 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004660
4661 mutex_lock(&ar->conf_mutex);
4662
4663 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004664 switch (ar->scan.state) {
4665 case ATH10K_SCAN_IDLE:
4666 reinit_completion(&ar->scan.started);
4667 reinit_completion(&ar->scan.completed);
4668 reinit_completion(&ar->scan.on_channel);
4669 ar->scan.state = ATH10K_SCAN_STARTING;
4670 ar->scan.is_roc = true;
4671 ar->scan.vdev_id = arvif->vdev_id;
4672 ar->scan.roc_freq = chan->center_freq;
4673 ret = 0;
4674 break;
4675 case ATH10K_SCAN_STARTING:
4676 case ATH10K_SCAN_RUNNING:
4677 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004678 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004679 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004680 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004681 spin_unlock_bh(&ar->data_lock);
4682
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004683 if (ret)
4684 goto exit;
4685
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004686 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4687
Kalle Valo5e3dd152013-06-12 20:52:10 +03004688 memset(&arg, 0, sizeof(arg));
4689 ath10k_wmi_start_scan_init(ar, &arg);
4690 arg.vdev_id = arvif->vdev_id;
4691 arg.scan_id = ATH10K_SCAN_ID;
4692 arg.n_channels = 1;
4693 arg.channels[0] = chan->center_freq;
4694 arg.dwell_time_active = duration;
4695 arg.dwell_time_passive = duration;
4696 arg.max_scan_time = 2 * duration;
4697 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4698 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4699
4700 ret = ath10k_start_scan(ar, &arg);
4701 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004702 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004703 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004704 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004705 spin_unlock_bh(&ar->data_lock);
4706 goto exit;
4707 }
4708
4709 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4710 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004711 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004712
4713 ret = ath10k_scan_stop(ar);
4714 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004715 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004716
Kalle Valo5e3dd152013-06-12 20:52:10 +03004717 ret = -ETIMEDOUT;
4718 goto exit;
4719 }
4720
4721 ret = 0;
4722exit:
4723 mutex_unlock(&ar->conf_mutex);
4724 return ret;
4725}
4726
4727static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4728{
4729 struct ath10k *ar = hw->priv;
4730
4731 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004732 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004733 mutex_unlock(&ar->conf_mutex);
4734
Michal Kazior4eb2e162014-10-28 10:23:09 +01004735 cancel_delayed_work_sync(&ar->scan.timeout);
4736
Kalle Valo5e3dd152013-06-12 20:52:10 +03004737 return 0;
4738}
4739
4740/*
4741 * Both RTS and Fragmentation threshold are interface-specific
4742 * in ath10k, but device-specific in mac80211.
4743 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004744
4745static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4746{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004747 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004748 struct ath10k_vif *arvif;
4749 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004750
Michal Kaziorad088bf2013-10-16 15:44:46 +03004751 mutex_lock(&ar->conf_mutex);
4752 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004754 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004755
Michal Kaziorad088bf2013-10-16 15:44:46 +03004756 ret = ath10k_mac_set_rts(arvif, value);
4757 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004758 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004759 arvif->vdev_id, ret);
4760 break;
4761 }
4762 }
4763 mutex_unlock(&ar->conf_mutex);
4764
4765 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004766}
4767
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004768static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4769 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004770{
4771 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004772 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004773 int ret;
4774
4775 /* mac80211 doesn't care if we really xmit queued frames or not
4776 * we'll collect those frames either way if we stop/delete vdevs */
4777 if (drop)
4778 return;
4779
Michal Kazior548db542013-07-05 16:15:15 +03004780 mutex_lock(&ar->conf_mutex);
4781
Michal Kazioraffd3212013-07-16 09:54:35 +02004782 if (ar->state == ATH10K_STATE_WEDGED)
4783 goto skip;
4784
Michal Kazioredb82362013-07-05 16:15:14 +03004785 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004786 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004787
Michal Kazioredb82362013-07-05 16:15:14 +03004788 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004789 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004790 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004791
Michal Kazior7962b0d2014-10-28 10:34:38 +01004792 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4793 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4794 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004795
4796 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004797 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004798
4799 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004800 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004801 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004802
Michal Kazioraffd3212013-07-16 09:54:35 +02004803skip:
Michal Kazior548db542013-07-05 16:15:15 +03004804 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004805}
4806
4807/* TODO: Implement this function properly
4808 * For now it is needed to reply to Probe Requests in IBSS mode.
4809 * Propably we need this information from FW.
4810 */
4811static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4812{
4813 return 1;
4814}
4815
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004816static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4817 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004818{
4819 struct ath10k *ar = hw->priv;
4820
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004821 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4822 return;
4823
Michal Kazioraffd3212013-07-16 09:54:35 +02004824 mutex_lock(&ar->conf_mutex);
4825
4826 /* If device failed to restart it will be in a different state, e.g.
4827 * ATH10K_STATE_WEDGED */
4828 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004829 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004830 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004831 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004832 }
4833
4834 mutex_unlock(&ar->conf_mutex);
4835}
4836
Michal Kazior2e1dea42013-07-31 10:32:40 +02004837static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4838 struct survey_info *survey)
4839{
4840 struct ath10k *ar = hw->priv;
4841 struct ieee80211_supported_band *sband;
4842 struct survey_info *ar_survey = &ar->survey[idx];
4843 int ret = 0;
4844
4845 mutex_lock(&ar->conf_mutex);
4846
4847 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4848 if (sband && idx >= sband->n_channels) {
4849 idx -= sband->n_channels;
4850 sband = NULL;
4851 }
4852
4853 if (!sband)
4854 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4855
4856 if (!sband || idx >= sband->n_channels) {
4857 ret = -ENOENT;
4858 goto exit;
4859 }
4860
4861 spin_lock_bh(&ar->data_lock);
4862 memcpy(survey, ar_survey, sizeof(*survey));
4863 spin_unlock_bh(&ar->data_lock);
4864
4865 survey->channel = &sband->channels[idx];
4866
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004867 if (ar->rx_channel == survey->channel)
4868 survey->filled |= SURVEY_INFO_IN_USE;
4869
Michal Kazior2e1dea42013-07-31 10:32:40 +02004870exit:
4871 mutex_unlock(&ar->conf_mutex);
4872 return ret;
4873}
4874
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004875/* Helper table for legacy fixed_rate/bitrate_mask */
4876static const u8 cck_ofdm_rate[] = {
4877 /* CCK */
4878 3, /* 1Mbps */
4879 2, /* 2Mbps */
4880 1, /* 5.5Mbps */
4881 0, /* 11Mbps */
4882 /* OFDM */
4883 3, /* 6Mbps */
4884 7, /* 9Mbps */
4885 2, /* 12Mbps */
4886 6, /* 18Mbps */
4887 1, /* 24Mbps */
4888 5, /* 36Mbps */
4889 0, /* 48Mbps */
4890 4, /* 54Mbps */
4891};
4892
4893/* Check if only one bit set */
4894static int ath10k_check_single_mask(u32 mask)
4895{
4896 int bit;
4897
4898 bit = ffs(mask);
4899 if (!bit)
4900 return 0;
4901
4902 mask &= ~BIT(bit - 1);
4903 if (mask)
4904 return 2;
4905
4906 return 1;
4907}
4908
4909static bool
4910ath10k_default_bitrate_mask(struct ath10k *ar,
4911 enum ieee80211_band band,
4912 const struct cfg80211_bitrate_mask *mask)
4913{
4914 u32 legacy = 0x00ff;
4915 u8 ht = 0xff, i;
4916 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004917 u16 nrf = ar->num_rf_chains;
4918
4919 if (ar->cfg_tx_chainmask)
4920 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004921
4922 switch (band) {
4923 case IEEE80211_BAND_2GHZ:
4924 legacy = 0x00fff;
4925 vht = 0;
4926 break;
4927 case IEEE80211_BAND_5GHZ:
4928 break;
4929 default:
4930 return false;
4931 }
4932
4933 if (mask->control[band].legacy != legacy)
4934 return false;
4935
Ben Greearb116ea12014-11-24 16:22:10 +02004936 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004937 if (mask->control[band].ht_mcs[i] != ht)
4938 return false;
4939
Ben Greearb116ea12014-11-24 16:22:10 +02004940 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004941 if (mask->control[band].vht_mcs[i] != vht)
4942 return false;
4943
4944 return true;
4945}
4946
4947static bool
4948ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4949 enum ieee80211_band band,
4950 u8 *fixed_nss)
4951{
4952 int ht_nss = 0, vht_nss = 0, i;
4953
4954 /* check legacy */
4955 if (ath10k_check_single_mask(mask->control[band].legacy))
4956 return false;
4957
4958 /* check HT */
4959 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4960 if (mask->control[band].ht_mcs[i] == 0xff)
4961 continue;
4962 else if (mask->control[band].ht_mcs[i] == 0x00)
4963 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004964
4965 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004966 }
4967
4968 ht_nss = i;
4969
4970 /* check VHT */
4971 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4972 if (mask->control[band].vht_mcs[i] == 0x03ff)
4973 continue;
4974 else if (mask->control[band].vht_mcs[i] == 0x0000)
4975 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004976
4977 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004978 }
4979
4980 vht_nss = i;
4981
4982 if (ht_nss > 0 && vht_nss > 0)
4983 return false;
4984
4985 if (ht_nss)
4986 *fixed_nss = ht_nss;
4987 else if (vht_nss)
4988 *fixed_nss = vht_nss;
4989 else
4990 return false;
4991
4992 return true;
4993}
4994
4995static bool
4996ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4997 enum ieee80211_band band,
4998 enum wmi_rate_preamble *preamble)
4999{
5000 int legacy = 0, ht = 0, vht = 0, i;
5001
5002 *preamble = WMI_RATE_PREAMBLE_OFDM;
5003
5004 /* check legacy */
5005 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5006 if (legacy > 1)
5007 return false;
5008
5009 /* check HT */
5010 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5011 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5012 if (ht > 1)
5013 return false;
5014
5015 /* check VHT */
5016 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5017 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5018 if (vht > 1)
5019 return false;
5020
5021 /* Currently we support only one fixed_rate */
5022 if ((legacy + ht + vht) != 1)
5023 return false;
5024
5025 if (ht)
5026 *preamble = WMI_RATE_PREAMBLE_HT;
5027 else if (vht)
5028 *preamble = WMI_RATE_PREAMBLE_VHT;
5029
5030 return true;
5031}
5032
5033static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005034ath10k_bitrate_mask_rate(struct ath10k *ar,
5035 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005036 enum ieee80211_band band,
5037 u8 *fixed_rate,
5038 u8 *fixed_nss)
5039{
5040 u8 rate = 0, pream = 0, nss = 0, i;
5041 enum wmi_rate_preamble preamble;
5042
5043 /* Check if single rate correct */
5044 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5045 return false;
5046
5047 pream = preamble;
5048
5049 switch (preamble) {
5050 case WMI_RATE_PREAMBLE_CCK:
5051 case WMI_RATE_PREAMBLE_OFDM:
5052 i = ffs(mask->control[band].legacy) - 1;
5053
5054 if (band == IEEE80211_BAND_2GHZ && i < 4)
5055 pream = WMI_RATE_PREAMBLE_CCK;
5056
5057 if (band == IEEE80211_BAND_5GHZ)
5058 i += 4;
5059
5060 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5061 return false;
5062
5063 rate = cck_ofdm_rate[i];
5064 break;
5065 case WMI_RATE_PREAMBLE_HT:
5066 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5067 if (mask->control[band].ht_mcs[i])
5068 break;
5069
5070 if (i == IEEE80211_HT_MCS_MASK_LEN)
5071 return false;
5072
5073 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5074 nss = i;
5075 break;
5076 case WMI_RATE_PREAMBLE_VHT:
5077 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5078 if (mask->control[band].vht_mcs[i])
5079 break;
5080
5081 if (i == NL80211_VHT_NSS_MAX)
5082 return false;
5083
5084 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5085 nss = i;
5086 break;
5087 }
5088
5089 *fixed_nss = nss + 1;
5090 nss <<= 4;
5091 pream <<= 6;
5092
Michal Kazior7aa7a722014-08-25 12:09:38 +02005093 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 +01005094 pream, nss, rate);
5095
5096 *fixed_rate = pream | nss | rate;
5097
5098 return true;
5099}
5100
Michal Kazior7aa7a722014-08-25 12:09:38 +02005101static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5102 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005103 enum ieee80211_band band,
5104 u8 *fixed_rate,
5105 u8 *fixed_nss)
5106{
5107 /* First check full NSS mask, if we can simply limit NSS */
5108 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5109 return true;
5110
5111 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005112 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005113}
5114
5115static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5116 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005117 u8 fixed_nss,
5118 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005119{
5120 struct ath10k *ar = arvif->ar;
5121 u32 vdev_param;
5122 int ret = 0;
5123
5124 mutex_lock(&ar->conf_mutex);
5125
5126 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005127 arvif->fixed_nss == fixed_nss &&
5128 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005129 goto exit;
5130
5131 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005132 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005133
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005134 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005136
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005137 vdev_param = ar->wmi.vdev_param->fixed_rate;
5138 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5139 vdev_param, fixed_rate);
5140 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005141 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005142 fixed_rate, ret);
5143 ret = -EINVAL;
5144 goto exit;
5145 }
5146
5147 arvif->fixed_rate = fixed_rate;
5148
5149 vdev_param = ar->wmi.vdev_param->nss;
5150 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5151 vdev_param, fixed_nss);
5152
5153 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005154 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005155 fixed_nss, ret);
5156 ret = -EINVAL;
5157 goto exit;
5158 }
5159
5160 arvif->fixed_nss = fixed_nss;
5161
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005162 vdev_param = ar->wmi.vdev_param->sgi;
5163 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5164 force_sgi);
5165
5166 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005167 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005168 force_sgi, ret);
5169 ret = -EINVAL;
5170 goto exit;
5171 }
5172
5173 arvif->force_sgi = force_sgi;
5174
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005175exit:
5176 mutex_unlock(&ar->conf_mutex);
5177 return ret;
5178}
5179
5180static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5181 struct ieee80211_vif *vif,
5182 const struct cfg80211_bitrate_mask *mask)
5183{
5184 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5185 struct ath10k *ar = arvif->ar;
5186 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5187 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5188 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005189 u8 force_sgi;
5190
Ben Greearb116ea12014-11-24 16:22:10 +02005191 if (ar->cfg_tx_chainmask)
5192 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5193
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005194 force_sgi = mask->control[band].gi;
5195 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5196 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005197
5198 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005199 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005200 &fixed_rate,
5201 &fixed_nss))
5202 return -EINVAL;
5203 }
5204
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005205 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005206 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005207 return -EINVAL;
5208 }
5209
5210 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5211 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005212}
5213
Michal Kazior9797feb2014-02-14 14:49:48 +01005214static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5215 struct ieee80211_vif *vif,
5216 struct ieee80211_sta *sta,
5217 u32 changed)
5218{
5219 struct ath10k *ar = hw->priv;
5220 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5221 u32 bw, smps;
5222
5223 spin_lock_bh(&ar->data_lock);
5224
Michal Kazior7aa7a722014-08-25 12:09:38 +02005225 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005226 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5227 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5228 sta->smps_mode);
5229
5230 if (changed & IEEE80211_RC_BW_CHANGED) {
5231 bw = WMI_PEER_CHWIDTH_20MHZ;
5232
5233 switch (sta->bandwidth) {
5234 case IEEE80211_STA_RX_BW_20:
5235 bw = WMI_PEER_CHWIDTH_20MHZ;
5236 break;
5237 case IEEE80211_STA_RX_BW_40:
5238 bw = WMI_PEER_CHWIDTH_40MHZ;
5239 break;
5240 case IEEE80211_STA_RX_BW_80:
5241 bw = WMI_PEER_CHWIDTH_80MHZ;
5242 break;
5243 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005244 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005245 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005246 bw = WMI_PEER_CHWIDTH_20MHZ;
5247 break;
5248 }
5249
5250 arsta->bw = bw;
5251 }
5252
5253 if (changed & IEEE80211_RC_NSS_CHANGED)
5254 arsta->nss = sta->rx_nss;
5255
5256 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5257 smps = WMI_PEER_SMPS_PS_NONE;
5258
5259 switch (sta->smps_mode) {
5260 case IEEE80211_SMPS_AUTOMATIC:
5261 case IEEE80211_SMPS_OFF:
5262 smps = WMI_PEER_SMPS_PS_NONE;
5263 break;
5264 case IEEE80211_SMPS_STATIC:
5265 smps = WMI_PEER_SMPS_STATIC;
5266 break;
5267 case IEEE80211_SMPS_DYNAMIC:
5268 smps = WMI_PEER_SMPS_DYNAMIC;
5269 break;
5270 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005271 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005272 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005273 smps = WMI_PEER_SMPS_PS_NONE;
5274 break;
5275 }
5276
5277 arsta->smps = smps;
5278 }
5279
Michal Kazior9797feb2014-02-14 14:49:48 +01005280 arsta->changed |= changed;
5281
5282 spin_unlock_bh(&ar->data_lock);
5283
5284 ieee80211_queue_work(hw, &arsta->update_wk);
5285}
5286
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005287static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5288{
5289 /*
5290 * FIXME: Return 0 for time being. Need to figure out whether FW
5291 * has the API to fetch 64-bit local TSF
5292 */
5293
5294 return 0;
5295}
5296
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005297static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5298 struct ieee80211_vif *vif,
5299 enum ieee80211_ampdu_mlme_action action,
5300 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5301 u8 buf_size)
5302{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005303 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005304 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5305
Michal Kazior7aa7a722014-08-25 12:09:38 +02005306 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 +02005307 arvif->vdev_id, sta->addr, tid, action);
5308
5309 switch (action) {
5310 case IEEE80211_AMPDU_RX_START:
5311 case IEEE80211_AMPDU_RX_STOP:
5312 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5313 * creation/removal. Do we need to verify this?
5314 */
5315 return 0;
5316 case IEEE80211_AMPDU_TX_START:
5317 case IEEE80211_AMPDU_TX_STOP_CONT:
5318 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5319 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5320 case IEEE80211_AMPDU_TX_OPERATIONAL:
5321 /* Firmware offloads Tx aggregation entirely so deny mac80211
5322 * Tx aggregation requests.
5323 */
5324 return -EOPNOTSUPP;
5325 }
5326
5327 return -EINVAL;
5328}
5329
Kalle Valo5e3dd152013-06-12 20:52:10 +03005330static const struct ieee80211_ops ath10k_ops = {
5331 .tx = ath10k_tx,
5332 .start = ath10k_start,
5333 .stop = ath10k_stop,
5334 .config = ath10k_config,
5335 .add_interface = ath10k_add_interface,
5336 .remove_interface = ath10k_remove_interface,
5337 .configure_filter = ath10k_configure_filter,
5338 .bss_info_changed = ath10k_bss_info_changed,
5339 .hw_scan = ath10k_hw_scan,
5340 .cancel_hw_scan = ath10k_cancel_hw_scan,
5341 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005342 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005343 .sta_state = ath10k_sta_state,
5344 .conf_tx = ath10k_conf_tx,
5345 .remain_on_channel = ath10k_remain_on_channel,
5346 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5347 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005348 .flush = ath10k_flush,
5349 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005350 .set_antenna = ath10k_set_antenna,
5351 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005352 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005353 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005354 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005355 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005356 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005357 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005358 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5359 .get_et_stats = ath10k_debug_get_et_stats,
5360 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005361
5362 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5363
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005364#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005365 .suspend = ath10k_wow_op_suspend,
5366 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005367#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005368#ifdef CONFIG_MAC80211_DEBUGFS
5369 .sta_add_debugfs = ath10k_sta_add_debugfs,
5370#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005371};
5372
5373#define RATETAB_ENT(_rate, _rateid, _flags) { \
5374 .bitrate = (_rate), \
5375 .flags = (_flags), \
5376 .hw_value = (_rateid), \
5377}
5378
5379#define CHAN2G(_channel, _freq, _flags) { \
5380 .band = IEEE80211_BAND_2GHZ, \
5381 .hw_value = (_channel), \
5382 .center_freq = (_freq), \
5383 .flags = (_flags), \
5384 .max_antenna_gain = 0, \
5385 .max_power = 30, \
5386}
5387
5388#define CHAN5G(_channel, _freq, _flags) { \
5389 .band = IEEE80211_BAND_5GHZ, \
5390 .hw_value = (_channel), \
5391 .center_freq = (_freq), \
5392 .flags = (_flags), \
5393 .max_antenna_gain = 0, \
5394 .max_power = 30, \
5395}
5396
5397static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5398 CHAN2G(1, 2412, 0),
5399 CHAN2G(2, 2417, 0),
5400 CHAN2G(3, 2422, 0),
5401 CHAN2G(4, 2427, 0),
5402 CHAN2G(5, 2432, 0),
5403 CHAN2G(6, 2437, 0),
5404 CHAN2G(7, 2442, 0),
5405 CHAN2G(8, 2447, 0),
5406 CHAN2G(9, 2452, 0),
5407 CHAN2G(10, 2457, 0),
5408 CHAN2G(11, 2462, 0),
5409 CHAN2G(12, 2467, 0),
5410 CHAN2G(13, 2472, 0),
5411 CHAN2G(14, 2484, 0),
5412};
5413
5414static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005415 CHAN5G(36, 5180, 0),
5416 CHAN5G(40, 5200, 0),
5417 CHAN5G(44, 5220, 0),
5418 CHAN5G(48, 5240, 0),
5419 CHAN5G(52, 5260, 0),
5420 CHAN5G(56, 5280, 0),
5421 CHAN5G(60, 5300, 0),
5422 CHAN5G(64, 5320, 0),
5423 CHAN5G(100, 5500, 0),
5424 CHAN5G(104, 5520, 0),
5425 CHAN5G(108, 5540, 0),
5426 CHAN5G(112, 5560, 0),
5427 CHAN5G(116, 5580, 0),
5428 CHAN5G(120, 5600, 0),
5429 CHAN5G(124, 5620, 0),
5430 CHAN5G(128, 5640, 0),
5431 CHAN5G(132, 5660, 0),
5432 CHAN5G(136, 5680, 0),
5433 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005434 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005435 CHAN5G(149, 5745, 0),
5436 CHAN5G(153, 5765, 0),
5437 CHAN5G(157, 5785, 0),
5438 CHAN5G(161, 5805, 0),
5439 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005440};
5441
Michal Kazior91b12082014-12-12 12:41:35 +01005442/* Note: Be careful if you re-order these. There is code which depends on this
5443 * ordering.
5444 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005445static struct ieee80211_rate ath10k_rates[] = {
5446 /* CCK */
5447 RATETAB_ENT(10, 0x82, 0),
5448 RATETAB_ENT(20, 0x84, 0),
5449 RATETAB_ENT(55, 0x8b, 0),
5450 RATETAB_ENT(110, 0x96, 0),
5451 /* OFDM */
5452 RATETAB_ENT(60, 0x0c, 0),
5453 RATETAB_ENT(90, 0x12, 0),
5454 RATETAB_ENT(120, 0x18, 0),
5455 RATETAB_ENT(180, 0x24, 0),
5456 RATETAB_ENT(240, 0x30, 0),
5457 RATETAB_ENT(360, 0x48, 0),
5458 RATETAB_ENT(480, 0x60, 0),
5459 RATETAB_ENT(540, 0x6c, 0),
5460};
5461
5462#define ath10k_a_rates (ath10k_rates + 4)
5463#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5464#define ath10k_g_rates (ath10k_rates + 0)
5465#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5466
Michal Kaziore7b54192014-08-07 11:03:27 +02005467struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005468{
5469 struct ieee80211_hw *hw;
5470 struct ath10k *ar;
5471
Michal Kaziore7b54192014-08-07 11:03:27 +02005472 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005473 if (!hw)
5474 return NULL;
5475
5476 ar = hw->priv;
5477 ar->hw = hw;
5478
5479 return ar;
5480}
5481
5482void ath10k_mac_destroy(struct ath10k *ar)
5483{
5484 ieee80211_free_hw(ar->hw);
5485}
5486
5487static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5488 {
5489 .max = 8,
5490 .types = BIT(NL80211_IFTYPE_STATION)
5491 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005492 },
5493 {
5494 .max = 3,
5495 .types = BIT(NL80211_IFTYPE_P2P_GO)
5496 },
5497 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005498 .max = 1,
5499 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5500 },
5501 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005502 .max = 7,
5503 .types = BIT(NL80211_IFTYPE_AP)
5504 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005505};
5506
Bartosz Markowskif2595092013-12-10 16:20:39 +01005507static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005508 {
5509 .max = 8,
5510 .types = BIT(NL80211_IFTYPE_AP)
5511 },
5512};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005513
5514static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5515 {
5516 .limits = ath10k_if_limits,
5517 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5518 .max_interfaces = 8,
5519 .num_different_channels = 1,
5520 .beacon_int_infra_match = true,
5521 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005522};
5523
5524static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005525 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005526 .limits = ath10k_10x_if_limits,
5527 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005528 .max_interfaces = 8,
5529 .num_different_channels = 1,
5530 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005531#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005532 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5533 BIT(NL80211_CHAN_WIDTH_20) |
5534 BIT(NL80211_CHAN_WIDTH_40) |
5535 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005536#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005537 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005538};
5539
5540static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5541{
5542 struct ieee80211_sta_vht_cap vht_cap = {0};
5543 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005544 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005545 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005546
5547 vht_cap.vht_supported = 1;
5548 vht_cap.cap = ar->vht_cap_info;
5549
Michal Kaziorbc657a362015-02-26 11:11:22 +01005550 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5551 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5552 val = ar->num_rf_chains - 1;
5553 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5554 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5555
5556 vht_cap.cap |= val;
5557 }
5558
5559 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5560 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5561 val = ar->num_rf_chains - 1;
5562 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5563 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5564
5565 vht_cap.cap |= val;
5566 }
5567
Michal Kazior8865bee42013-07-24 12:36:46 +02005568 mcs_map = 0;
5569 for (i = 0; i < 8; i++) {
5570 if (i < ar->num_rf_chains)
5571 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5572 else
5573 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5574 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005575
5576 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5577 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5578
5579 return vht_cap;
5580}
5581
5582static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5583{
5584 int i;
5585 struct ieee80211_sta_ht_cap ht_cap = {0};
5586
5587 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5588 return ht_cap;
5589
5590 ht_cap.ht_supported = 1;
5591 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5592 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5593 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5594 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5595 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5596
5597 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5598 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5599
5600 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5601 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5602
5603 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5604 u32 smps;
5605
5606 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5607 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5608
5609 ht_cap.cap |= smps;
5610 }
5611
5612 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5613 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5614
5615 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5616 u32 stbc;
5617
5618 stbc = ar->ht_cap_info;
5619 stbc &= WMI_HT_CAP_RX_STBC;
5620 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5621 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5622 stbc &= IEEE80211_HT_CAP_RX_STBC;
5623
5624 ht_cap.cap |= stbc;
5625 }
5626
5627 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5628 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5629
5630 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5631 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5632
5633 /* max AMSDU is implicitly taken from vht_cap_info */
5634 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5635 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5636
Michal Kazior8865bee42013-07-24 12:36:46 +02005637 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005638 ht_cap.mcs.rx_mask[i] = 0xFF;
5639
5640 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5641
5642 return ht_cap;
5643}
5644
Kalle Valo5e3dd152013-06-12 20:52:10 +03005645static void ath10k_get_arvif_iter(void *data, u8 *mac,
5646 struct ieee80211_vif *vif)
5647{
5648 struct ath10k_vif_iter *arvif_iter = data;
5649 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5650
5651 if (arvif->vdev_id == arvif_iter->vdev_id)
5652 arvif_iter->arvif = arvif;
5653}
5654
5655struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5656{
5657 struct ath10k_vif_iter arvif_iter;
5658 u32 flags;
5659
5660 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5661 arvif_iter.vdev_id = vdev_id;
5662
5663 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5664 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5665 flags,
5666 ath10k_get_arvif_iter,
5667 &arvif_iter);
5668 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005669 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005670 return NULL;
5671 }
5672
5673 return arvif_iter.arvif;
5674}
5675
5676int ath10k_mac_register(struct ath10k *ar)
5677{
Johannes Berg3cb10942015-01-22 21:38:45 +01005678 static const u32 cipher_suites[] = {
5679 WLAN_CIPHER_SUITE_WEP40,
5680 WLAN_CIPHER_SUITE_WEP104,
5681 WLAN_CIPHER_SUITE_TKIP,
5682 WLAN_CIPHER_SUITE_CCMP,
5683 WLAN_CIPHER_SUITE_AES_CMAC,
5684 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005685 struct ieee80211_supported_band *band;
5686 struct ieee80211_sta_vht_cap vht_cap;
5687 struct ieee80211_sta_ht_cap ht_cap;
5688 void *channels;
5689 int ret;
5690
5691 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5692
5693 SET_IEEE80211_DEV(ar->hw, ar->dev);
5694
5695 ht_cap = ath10k_get_ht_cap(ar);
5696 vht_cap = ath10k_create_vht_cap(ar);
5697
5698 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5699 channels = kmemdup(ath10k_2ghz_channels,
5700 sizeof(ath10k_2ghz_channels),
5701 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005702 if (!channels) {
5703 ret = -ENOMEM;
5704 goto err_free;
5705 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005706
5707 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5708 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5709 band->channels = channels;
5710 band->n_bitrates = ath10k_g_rates_size;
5711 band->bitrates = ath10k_g_rates;
5712 band->ht_cap = ht_cap;
5713
Yanbo Lid68bb122015-01-23 08:18:20 +08005714 /* Enable the VHT support at 2.4 GHz */
5715 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005716
5717 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5718 }
5719
5720 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5721 channels = kmemdup(ath10k_5ghz_channels,
5722 sizeof(ath10k_5ghz_channels),
5723 GFP_KERNEL);
5724 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005725 ret = -ENOMEM;
5726 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005727 }
5728
5729 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5730 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5731 band->channels = channels;
5732 band->n_bitrates = ath10k_a_rates_size;
5733 band->bitrates = ath10k_a_rates;
5734 band->ht_cap = ht_cap;
5735 band->vht_cap = vht_cap;
5736 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5737 }
5738
5739 ar->hw->wiphy->interface_modes =
5740 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005741 BIT(NL80211_IFTYPE_AP);
5742
Ben Greear46acf7b2014-05-16 17:15:38 +03005743 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5744 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5745
Bartosz Markowskid3541812013-12-10 16:20:40 +01005746 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5747 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005748 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005749 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5750 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005751
5752 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5753 IEEE80211_HW_SUPPORTS_PS |
5754 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005755 IEEE80211_HW_MFP_CAPABLE |
5756 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5757 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005758 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005759 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005760 IEEE80211_HW_SW_CRYPTO_CONTROL |
5761 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005762
Eliad Peller0d8614b2014-09-10 14:07:36 +03005763 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5764
Kalle Valo5e3dd152013-06-12 20:52:10 +03005765 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005766 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005767
5768 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5769 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5770 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5771 }
5772
5773 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5774 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5775
5776 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005777 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005778
Kalle Valo5e3dd152013-06-12 20:52:10 +03005779 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5780
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005781 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5782 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5783
5784 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5785 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5786 * correct Probe Responses. This is more of a hack advert..
5787 */
5788 ar->hw->wiphy->probe_resp_offload |=
5789 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5790 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5791 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5792 }
5793
Kalle Valo5e3dd152013-06-12 20:52:10 +03005794 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005795 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005796 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5797
5798 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005799 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5800
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005801 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5802
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005803 ret = ath10k_wow_init(ar);
5804 if (ret) {
5805 ath10k_warn(ar, "failed to init wow: %d\n", ret);
5806 goto err_free;
5807 }
5808
Kalle Valo5e3dd152013-06-12 20:52:10 +03005809 /*
5810 * on LL hardware queues are managed entirely by the FW
5811 * so we only advertise to mac we can do the queues thing
5812 */
5813 ar->hw->queues = 4;
5814
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005815 switch (ar->wmi.op_version) {
5816 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5817 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005818 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5819 ar->hw->wiphy->n_iface_combinations =
5820 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005821 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005822 break;
5823 case ATH10K_FW_WMI_OP_VERSION_10_1:
5824 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005825 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005826 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5827 ar->hw->wiphy->n_iface_combinations =
5828 ARRAY_SIZE(ath10k_10x_if_comb);
5829 break;
5830 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5831 case ATH10K_FW_WMI_OP_VERSION_MAX:
5832 WARN_ON(1);
5833 ret = -EINVAL;
5834 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005835 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005836
Michal Kazior7c199992013-07-31 10:47:57 +02005837 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5838
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005839 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5840 /* Init ath dfs pattern detector */
5841 ar->ath_common.debug_mask = ATH_DBG_DFS;
5842 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5843 NL80211_DFS_UNSET);
5844
5845 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005846 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005847 }
5848
Kalle Valo5e3dd152013-06-12 20:52:10 +03005849 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5850 ath10k_reg_notifier);
5851 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005852 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005853 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005854 }
5855
Johannes Berg3cb10942015-01-22 21:38:45 +01005856 ar->hw->wiphy->cipher_suites = cipher_suites;
5857 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5858
Kalle Valo5e3dd152013-06-12 20:52:10 +03005859 ret = ieee80211_register_hw(ar->hw);
5860 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005861 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005862 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005863 }
5864
5865 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5866 ret = regulatory_hint(ar->hw->wiphy,
5867 ar->ath_common.regulatory.alpha2);
5868 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005869 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005870 }
5871
5872 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005873
5874err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005875 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005876err_free:
5877 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5878 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5879
Kalle Valo5e3dd152013-06-12 20:52:10 +03005880 return ret;
5881}
5882
5883void ath10k_mac_unregister(struct ath10k *ar)
5884{
5885 ieee80211_unregister_hw(ar->hw);
5886
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005887 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5888 ar->dfs_detector->exit(ar->dfs_detector);
5889
Kalle Valo5e3dd152013-06-12 20:52:10 +03005890 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5891 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5892
5893 SET_IEEE80211_DEV(ar->hw, NULL);
5894}