blob: e8f95949d2236eab7000344e0e7a2942b6c2488a [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
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300432static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
433 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434{
435 int ret;
436
437 lockdep_assert_held(&ar->conf_mutex);
438
Michal Kaziorcfd10612014-11-25 15:16:05 +0100439 if (ar->num_peers >= ar->max_num_peers)
440 return -ENOBUFS;
441
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300442 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800443 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200444 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200445 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300446 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800447 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300448
449 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800450 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200451 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200452 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300453 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800454 }
Michal Kazior292a7532014-11-25 15:16:04 +0100455
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100456 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300457
458 return 0;
459}
460
Kalle Valo5a13e762014-01-20 11:01:46 +0200461static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
462{
463 struct ath10k *ar = arvif->ar;
464 u32 param;
465 int ret;
466
467 param = ar->wmi.pdev_param->sta_kickout_th;
468 ret = ath10k_wmi_pdev_set_param(ar, param,
469 ATH10K_KICKOUT_THRESHOLD);
470 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200471 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200472 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200473 return ret;
474 }
475
476 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
477 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
478 ATH10K_KEEPALIVE_MIN_IDLE);
479 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200480 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200481 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200482 return ret;
483 }
484
485 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
486 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
487 ATH10K_KEEPALIVE_MAX_IDLE);
488 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200489 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200490 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200491 return ret;
492 }
493
494 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
495 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
496 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
497 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200498 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200499 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200500 return ret;
501 }
502
503 return 0;
504}
505
Vivek Natarajanacab6402014-11-26 09:06:12 +0200506static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200507{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200508 struct ath10k *ar = arvif->ar;
509 u32 vdev_param;
510
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200511 vdev_param = ar->wmi.vdev_param->rts_threshold;
512 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200513}
514
515static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
516{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200517 struct ath10k *ar = arvif->ar;
518 u32 vdev_param;
519
Michal Kazior424121c2013-07-22 14:13:31 +0200520 if (value != 0xFFFFFFFF)
521 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
522 ATH10K_FRAGMT_THRESHOLD_MIN,
523 ATH10K_FRAGMT_THRESHOLD_MAX);
524
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200525 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
526 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200527}
528
Kalle Valo5e3dd152013-06-12 20:52:10 +0300529static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
530{
531 int ret;
532
533 lockdep_assert_held(&ar->conf_mutex);
534
535 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
536 if (ret)
537 return ret;
538
539 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
540 if (ret)
541 return ret;
542
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100543 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100544
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545 return 0;
546}
547
548static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
549{
550 struct ath10k_peer *peer, *tmp;
551
552 lockdep_assert_held(&ar->conf_mutex);
553
554 spin_lock_bh(&ar->data_lock);
555 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
556 if (peer->vdev_id != vdev_id)
557 continue;
558
Michal Kazior7aa7a722014-08-25 12:09:38 +0200559 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300560 peer->addr, vdev_id);
561
562 list_del(&peer->list);
563 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100564 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300565 }
566 spin_unlock_bh(&ar->data_lock);
567}
568
Michal Kaziora96d7742013-07-16 09:38:56 +0200569static void ath10k_peer_cleanup_all(struct ath10k *ar)
570{
571 struct ath10k_peer *peer, *tmp;
572
573 lockdep_assert_held(&ar->conf_mutex);
574
575 spin_lock_bh(&ar->data_lock);
576 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
577 list_del(&peer->list);
578 kfree(peer);
579 }
580 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100581
582 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100583 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200584}
585
Kalle Valo5e3dd152013-06-12 20:52:10 +0300586/************************/
587/* Interface management */
588/************************/
589
Michal Kazior64badcb2014-09-18 11:18:02 +0300590void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
591{
592 struct ath10k *ar = arvif->ar;
593
594 lockdep_assert_held(&ar->data_lock);
595
596 if (!arvif->beacon)
597 return;
598
599 if (!arvif->beacon_buf)
600 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
601 arvif->beacon->len, DMA_TO_DEVICE);
602
Michal Kazioraf213192015-01-29 14:29:52 +0200603 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
604 arvif->beacon_state != ATH10K_BEACON_SENT))
605 return;
606
Michal Kazior64badcb2014-09-18 11:18:02 +0300607 dev_kfree_skb_any(arvif->beacon);
608
609 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200610 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300611}
612
613static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
614{
615 struct ath10k *ar = arvif->ar;
616
617 lockdep_assert_held(&ar->data_lock);
618
619 ath10k_mac_vif_beacon_free(arvif);
620
621 if (arvif->beacon_buf) {
622 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
623 arvif->beacon_buf, arvif->beacon_paddr);
624 arvif->beacon_buf = NULL;
625 }
626}
627
Kalle Valo5e3dd152013-06-12 20:52:10 +0300628static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
629{
630 int ret;
631
Michal Kazior548db542013-07-05 16:15:15 +0300632 lockdep_assert_held(&ar->conf_mutex);
633
Michal Kazior7962b0d2014-10-28 10:34:38 +0100634 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
635 return -ESHUTDOWN;
636
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
638 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
639 if (ret == 0)
640 return -ETIMEDOUT;
641
642 return 0;
643}
644
Michal Kazior1bbc0972014-04-08 09:45:47 +0300645static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300646{
Michal Kaziorc930f742014-01-23 11:38:25 +0100647 struct cfg80211_chan_def *chandef = &ar->chandef;
648 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300650 int ret = 0;
651
652 lockdep_assert_held(&ar->conf_mutex);
653
Kalle Valo5e3dd152013-06-12 20:52:10 +0300654 arg.vdev_id = vdev_id;
655 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100656 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300657
658 /* TODO setup this dynamically, what in case we
659 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100660 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200661 arg.channel.chan_radar =
662 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663
Michal Kazior89c5c842013-10-23 04:02:13 -0700664 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700665 arg.channel.max_power = channel->max_power * 2;
666 arg.channel.max_reg_power = channel->max_reg_power * 2;
667 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300668
Michal Kazior7962b0d2014-10-28 10:34:38 +0100669 reinit_completion(&ar->vdev_setup_done);
670
Kalle Valo5e3dd152013-06-12 20:52:10 +0300671 ret = ath10k_wmi_vdev_start(ar, &arg);
672 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200673 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200674 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300675 return ret;
676 }
677
678 ret = ath10k_vdev_setup_sync(ar);
679 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200680 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200681 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682 return ret;
683 }
684
685 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
686 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200687 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200688 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689 goto vdev_stop;
690 }
691
692 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300693
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300695 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300696 return 0;
697
698vdev_stop:
699 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
700 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200701 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200702 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703
704 return ret;
705}
706
Michal Kazior1bbc0972014-04-08 09:45:47 +0300707static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300708{
709 int ret = 0;
710
711 lockdep_assert_held(&ar->conf_mutex);
712
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200713 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
714 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200715 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200716 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300717
Michal Kazior7962b0d2014-10-28 10:34:38 +0100718 reinit_completion(&ar->vdev_setup_done);
719
Kalle Valo5e3dd152013-06-12 20:52:10 +0300720 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
721 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200722 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200723 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300724
725 ret = ath10k_vdev_setup_sync(ar);
726 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200727 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200728 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300729
Michal Kazior7aa7a722014-08-25 12:09:38 +0200730 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300731 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300732 return ret;
733}
734
Michal Kazior1bbc0972014-04-08 09:45:47 +0300735static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300736{
737 int bit, ret = 0;
738
739 lockdep_assert_held(&ar->conf_mutex);
740
Ben Greeara9aefb32014-08-12 11:02:19 +0300741 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200742 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300743 return -ENOMEM;
744 }
745
Ben Greear16c11172014-09-23 14:17:16 -0700746 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300747
Ben Greear16c11172014-09-23 14:17:16 -0700748 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300749
750 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
751 WMI_VDEV_TYPE_MONITOR,
752 0, ar->mac_addr);
753 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200754 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200755 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300756 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300757 }
758
Ben Greear16c11172014-09-23 14:17:16 -0700759 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200760 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300761 ar->monitor_vdev_id);
762
Kalle Valo5e3dd152013-06-12 20:52:10 +0300763 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300764}
765
Michal Kazior1bbc0972014-04-08 09:45:47 +0300766static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300767{
768 int ret = 0;
769
770 lockdep_assert_held(&ar->conf_mutex);
771
Kalle Valo5e3dd152013-06-12 20:52:10 +0300772 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200774 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200775 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300776 return ret;
777 }
778
Ben Greear16c11172014-09-23 14:17:16 -0700779 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300780
Michal Kazior7aa7a722014-08-25 12:09:38 +0200781 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300782 ar->monitor_vdev_id);
783 return ret;
784}
785
Michal Kazior1bbc0972014-04-08 09:45:47 +0300786static int ath10k_monitor_start(struct ath10k *ar)
787{
788 int ret;
789
790 lockdep_assert_held(&ar->conf_mutex);
791
Michal Kazior1bbc0972014-04-08 09:45:47 +0300792 ret = ath10k_monitor_vdev_create(ar);
793 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200794 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300795 return ret;
796 }
797
798 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200800 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300801 ath10k_monitor_vdev_delete(ar);
802 return ret;
803 }
804
805 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300807
808 return 0;
809}
810
Michal Kazior19337472014-08-28 12:58:16 +0200811static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300812{
813 int ret;
814
815 lockdep_assert_held(&ar->conf_mutex);
816
Michal Kazior1bbc0972014-04-08 09:45:47 +0300817 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200819 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200820 return ret;
821 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300822
823 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200824 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200825 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200826 return ret;
827 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300828
829 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200831
832 return 0;
833}
834
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530835static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
836{
837 struct ath10k_vif *arvif;
838
839 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
840 return true;
841
842 if (!ar->num_started_vdevs)
843 return false;
844
845 list_for_each_entry(arvif, &ar->arvifs, list)
846 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
847 return false;
848
849 ath10k_dbg(ar, ATH10K_DBG_MAC,
850 "mac disabling promiscuous mode because vdev is started\n");
851 return true;
852}
853
Michal Kazior19337472014-08-28 12:58:16 +0200854static int ath10k_monitor_recalc(struct ath10k *ar)
855{
856 bool should_start;
857
858 lockdep_assert_held(&ar->conf_mutex);
859
860 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100861 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200862 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
863
864 ath10k_dbg(ar, ATH10K_DBG_MAC,
865 "mac monitor recalc started? %d should? %d\n",
866 ar->monitor_started, should_start);
867
868 if (should_start == ar->monitor_started)
869 return 0;
870
871 if (should_start)
872 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300873
874 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300875}
876
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200877static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
878{
879 struct ath10k *ar = arvif->ar;
880 u32 vdev_param, rts_cts = 0;
881
882 lockdep_assert_held(&ar->conf_mutex);
883
884 vdev_param = ar->wmi.vdev_param->enable_rtscts;
885
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200886 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200887
888 if (arvif->num_legacy_stations > 0)
889 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
890 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200891 else
892 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
893 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200894
895 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
896 rts_cts);
897}
898
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200899static int ath10k_start_cac(struct ath10k *ar)
900{
901 int ret;
902
903 lockdep_assert_held(&ar->conf_mutex);
904
905 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
906
Michal Kazior19337472014-08-28 12:58:16 +0200907 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200908 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200910 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
911 return ret;
912 }
913
Michal Kazior7aa7a722014-08-25 12:09:38 +0200914 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200915 ar->monitor_vdev_id);
916
917 return 0;
918}
919
920static int ath10k_stop_cac(struct ath10k *ar)
921{
922 lockdep_assert_held(&ar->conf_mutex);
923
924 /* CAC is not running - do nothing */
925 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
926 return 0;
927
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200928 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300929 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200930
Michal Kazior7aa7a722014-08-25 12:09:38 +0200931 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200932
933 return 0;
934}
935
Michal Kaziord6500972014-04-08 09:56:09 +0300936static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200937{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200938 int ret;
939
940 lockdep_assert_held(&ar->conf_mutex);
941
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200942 ath10k_stop_cac(ar);
943
Michal Kaziord6500972014-04-08 09:56:09 +0300944 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200945 return;
946
Michal Kaziord6500972014-04-08 09:56:09 +0300947 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200948 return;
949
950 ret = ath10k_start_cac(ar);
951 if (ret) {
952 /*
953 * Not possible to start CAC on current channel so starting
954 * radiation is not allowed, make this channel DFS_UNAVAILABLE
955 * by indicating that radar was detected.
956 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200957 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200958 ieee80211_radar_detected(ar->hw);
959 }
960}
961
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530962static int ath10k_vdev_stop(struct ath10k_vif *arvif)
963{
964 struct ath10k *ar = arvif->ar;
965 int ret;
966
967 lockdep_assert_held(&ar->conf_mutex);
968
969 reinit_completion(&ar->vdev_setup_done);
970
971 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
972 if (ret) {
973 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
974 arvif->vdev_id, ret);
975 return ret;
976 }
977
978 ret = ath10k_vdev_setup_sync(ar);
979 if (ret) {
980 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
981 arvif->vdev_id, ret);
982 return ret;
983 }
984
985 WARN_ON(ar->num_started_vdevs == 0);
986
987 if (ar->num_started_vdevs != 0) {
988 ar->num_started_vdevs--;
989 ath10k_recalc_radar_detection(ar);
990 }
991
992 return ret;
993}
994
Michal Kaziordc55e302014-07-29 12:53:36 +0300995static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300996{
997 struct ath10k *ar = arvif->ar;
998 struct cfg80211_chan_def *chandef = &ar->chandef;
999 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301000 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001001
1002 lockdep_assert_held(&ar->conf_mutex);
1003
1004 reinit_completion(&ar->vdev_setup_done);
1005
1006 arg.vdev_id = arvif->vdev_id;
1007 arg.dtim_period = arvif->dtim_period;
1008 arg.bcn_intval = arvif->beacon_interval;
1009
1010 arg.channel.freq = chandef->chan->center_freq;
1011 arg.channel.band_center_freq1 = chandef->center_freq1;
1012 arg.channel.mode = chan_to_phymode(chandef);
1013
1014 arg.channel.min_power = 0;
1015 arg.channel.max_power = chandef->chan->max_power * 2;
1016 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1017 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1018
1019 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1020 arg.ssid = arvif->u.ap.ssid;
1021 arg.ssid_len = arvif->u.ap.ssid_len;
1022 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1023
1024 /* For now allow DFS for AP mode */
1025 arg.channel.chan_radar =
1026 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1027 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1028 arg.ssid = arvif->vif->bss_conf.ssid;
1029 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1030 }
1031
Michal Kazior7aa7a722014-08-25 12:09:38 +02001032 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001033 "mac vdev %d start center_freq %d phymode %s\n",
1034 arg.vdev_id, arg.channel.freq,
1035 ath10k_wmi_phymode_str(arg.channel.mode));
1036
Michal Kaziordc55e302014-07-29 12:53:36 +03001037 if (restart)
1038 ret = ath10k_wmi_vdev_restart(ar, &arg);
1039 else
1040 ret = ath10k_wmi_vdev_start(ar, &arg);
1041
Michal Kazior72654fa2014-04-08 09:56:09 +03001042 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001043 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001044 arg.vdev_id, ret);
1045 return ret;
1046 }
1047
1048 ret = ath10k_vdev_setup_sync(ar);
1049 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001050 ath10k_warn(ar,
1051 "failed to synchronize setup for vdev %i restart %d: %d\n",
1052 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001053 return ret;
1054 }
1055
Michal Kaziord6500972014-04-08 09:56:09 +03001056 ar->num_started_vdevs++;
1057 ath10k_recalc_radar_detection(ar);
1058
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301059 ret = ath10k_monitor_recalc(ar);
1060 if (ret) {
1061 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1062 arg.vdev_id, restart, ret);
1063 ret2 = ath10k_vdev_stop(arvif);
1064 if (ret2)
1065 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1066 arg.vdev_id, restart, ret2);
1067 }
1068
Michal Kazior72654fa2014-04-08 09:56:09 +03001069 return ret;
1070}
1071
Michal Kaziordc55e302014-07-29 12:53:36 +03001072static int ath10k_vdev_start(struct ath10k_vif *arvif)
1073{
1074 return ath10k_vdev_start_restart(arvif, false);
1075}
1076
1077static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1078{
1079 return ath10k_vdev_start_restart(arvif, true);
1080}
1081
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001082static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1083 struct sk_buff *bcn)
1084{
1085 struct ath10k *ar = arvif->ar;
1086 struct ieee80211_mgmt *mgmt;
1087 const u8 *p2p_ie;
1088 int ret;
1089
1090 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1091 return 0;
1092
1093 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1094 return 0;
1095
1096 mgmt = (void *)bcn->data;
1097 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1098 mgmt->u.beacon.variable,
1099 bcn->len - (mgmt->u.beacon.variable -
1100 bcn->data));
1101 if (!p2p_ie)
1102 return -ENOENT;
1103
1104 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1105 if (ret) {
1106 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1107 arvif->vdev_id, ret);
1108 return ret;
1109 }
1110
1111 return 0;
1112}
1113
1114static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1115 u8 oui_type, size_t ie_offset)
1116{
1117 size_t len;
1118 const u8 *next;
1119 const u8 *end;
1120 u8 *ie;
1121
1122 if (WARN_ON(skb->len < ie_offset))
1123 return -EINVAL;
1124
1125 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1126 skb->data + ie_offset,
1127 skb->len - ie_offset);
1128 if (!ie)
1129 return -ENOENT;
1130
1131 len = ie[1] + 2;
1132 end = skb->data + skb->len;
1133 next = ie + len;
1134
1135 if (WARN_ON(next > end))
1136 return -EINVAL;
1137
1138 memmove(ie, next, end - next);
1139 skb_trim(skb, skb->len - len);
1140
1141 return 0;
1142}
1143
1144static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1145{
1146 struct ath10k *ar = arvif->ar;
1147 struct ieee80211_hw *hw = ar->hw;
1148 struct ieee80211_vif *vif = arvif->vif;
1149 struct ieee80211_mutable_offsets offs = {};
1150 struct sk_buff *bcn;
1151 int ret;
1152
1153 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1154 return 0;
1155
Michal Kazior81a9a172015-03-05 16:02:17 +02001156 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1157 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1158 return 0;
1159
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001160 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1161 if (!bcn) {
1162 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1163 return -EPERM;
1164 }
1165
1166 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1167 if (ret) {
1168 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1169 kfree_skb(bcn);
1170 return ret;
1171 }
1172
1173 /* P2P IE is inserted by firmware automatically (as configured above)
1174 * so remove it from the base beacon template to avoid duplicate P2P
1175 * IEs in beacon frames.
1176 */
1177 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1178 offsetof(struct ieee80211_mgmt,
1179 u.beacon.variable));
1180
1181 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1182 0, NULL, 0);
1183 kfree_skb(bcn);
1184
1185 if (ret) {
1186 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1187 ret);
1188 return ret;
1189 }
1190
1191 return 0;
1192}
1193
1194static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1195{
1196 struct ath10k *ar = arvif->ar;
1197 struct ieee80211_hw *hw = ar->hw;
1198 struct ieee80211_vif *vif = arvif->vif;
1199 struct sk_buff *prb;
1200 int ret;
1201
1202 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1203 return 0;
1204
Michal Kazior81a9a172015-03-05 16:02:17 +02001205 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1206 return 0;
1207
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001208 prb = ieee80211_proberesp_get(hw, vif);
1209 if (!prb) {
1210 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1211 return -EPERM;
1212 }
1213
1214 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1215 kfree_skb(prb);
1216
1217 if (ret) {
1218 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1219 ret);
1220 return ret;
1221 }
1222
1223 return 0;
1224}
1225
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001227 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001229 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001230 int ret = 0;
1231
Michal Kazior548db542013-07-05 16:15:15 +03001232 lockdep_assert_held(&arvif->ar->conf_mutex);
1233
Kalle Valo5e3dd152013-06-12 20:52:10 +03001234 if (!info->enable_beacon) {
1235 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001236
1237 arvif->is_started = false;
1238 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001239
1240 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001241 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001242 spin_unlock_bh(&arvif->ar->data_lock);
1243
Kalle Valo5e3dd152013-06-12 20:52:10 +03001244 return;
1245 }
1246
1247 arvif->tx_seq_no = 0x1000;
1248
1249 ret = ath10k_vdev_start(arvif);
1250 if (ret)
1251 return;
1252
Michal Kaziorc930f742014-01-23 11:38:25 +01001253 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001254 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001255
1256 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1257 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001259 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001260 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001261 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262 return;
1263 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001264
1265 arvif->is_started = true;
1266 arvif->is_up = true;
1267
Michal Kazior7aa7a722014-08-25 12:09:38 +02001268 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001269}
1270
1271static void ath10k_control_ibss(struct ath10k_vif *arvif,
1272 struct ieee80211_bss_conf *info,
1273 const u8 self_peer[ETH_ALEN])
1274{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001275 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001276 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277 int ret = 0;
1278
Michal Kazior548db542013-07-05 16:15:15 +03001279 lockdep_assert_held(&arvif->ar->conf_mutex);
1280
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 if (!info->ibss_joined) {
1282 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1283 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001284 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001285 self_peer, arvif->vdev_id, ret);
1286
Michal Kaziorc930f742014-01-23 11:38:25 +01001287 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288 return;
1289
Michal Kaziorc930f742014-01-23 11:38:25 +01001290 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001291
1292 return;
1293 }
1294
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001295 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1296 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001298 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001299 self_peer, arvif->vdev_id, ret);
1300 return;
1301 }
1302
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001303 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1304 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305 ATH10K_DEFAULT_ATIM);
1306 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001307 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308 arvif->vdev_id, ret);
1309}
1310
Michal Kazior9f9b5742014-12-12 12:41:36 +01001311static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1312{
1313 struct ath10k *ar = arvif->ar;
1314 u32 param;
1315 u32 value;
1316 int ret;
1317
1318 lockdep_assert_held(&arvif->ar->conf_mutex);
1319
1320 if (arvif->u.sta.uapsd)
1321 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1322 else
1323 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1324
1325 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1326 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1327 if (ret) {
1328 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1329 value, arvif->vdev_id, ret);
1330 return ret;
1331 }
1332
1333 return 0;
1334}
1335
1336static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1337{
1338 struct ath10k *ar = arvif->ar;
1339 u32 param;
1340 u32 value;
1341 int ret;
1342
1343 lockdep_assert_held(&arvif->ar->conf_mutex);
1344
1345 if (arvif->u.sta.uapsd)
1346 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1347 else
1348 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1349
1350 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1351 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1352 param, value);
1353 if (ret) {
1354 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1355 value, arvif->vdev_id, ret);
1356 return ret;
1357 }
1358
1359 return 0;
1360}
1361
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001362static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1363{
1364 struct ath10k_vif *arvif;
1365 int num = 0;
1366
1367 lockdep_assert_held(&ar->conf_mutex);
1368
1369 list_for_each_entry(arvif, &ar->arvifs, list)
1370 if (arvif->ps)
1371 num++;
1372
1373 return num;
1374}
1375
Michal Kaziorad088bf2013-10-16 15:44:46 +03001376static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001378 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001379 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001380 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381 enum wmi_sta_powersave_param param;
1382 enum wmi_sta_ps_mode psmode;
1383 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001384 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001385 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386
Michal Kazior548db542013-07-05 16:15:15 +03001387 lockdep_assert_held(&arvif->ar->conf_mutex);
1388
Michal Kaziorad088bf2013-10-16 15:44:46 +03001389 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1390 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001392 enable_ps = arvif->ps;
1393
1394 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1395 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1396 ar->fw_features)) {
1397 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1398 arvif->vdev_id);
1399 enable_ps = false;
1400 }
1401
1402 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001403 psmode = WMI_STA_PS_MODE_ENABLED;
1404 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1405
Michal Kazior526549a2014-12-12 12:41:37 +01001406 ps_timeout = conf->dynamic_ps_timeout;
1407 if (ps_timeout == 0) {
1408 /* Firmware doesn't like 0 */
1409 ps_timeout = ieee80211_tu_to_usec(
1410 vif->bss_conf.beacon_int) / 1000;
1411 }
1412
Michal Kaziorad088bf2013-10-16 15:44:46 +03001413 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001414 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001415 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001416 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001417 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001418 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001419 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001420 } else {
1421 psmode = WMI_STA_PS_MODE_DISABLED;
1422 }
1423
Michal Kazior7aa7a722014-08-25 12:09:38 +02001424 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001425 arvif->vdev_id, psmode ? "enable" : "disable");
1426
Michal Kaziorad088bf2013-10-16 15:44:46 +03001427 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001429 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001430 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001431 return ret;
1432 }
1433
1434 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001435}
1436
Michal Kazior46725b152015-01-28 09:57:49 +02001437static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1438{
1439 struct ath10k *ar = arvif->ar;
1440 struct wmi_sta_keepalive_arg arg = {};
1441 int ret;
1442
1443 lockdep_assert_held(&arvif->ar->conf_mutex);
1444
1445 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1446 return 0;
1447
1448 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1449 return 0;
1450
1451 /* Some firmware revisions have a bug and ignore the `enabled` field.
1452 * Instead use the interval to disable the keepalive.
1453 */
1454 arg.vdev_id = arvif->vdev_id;
1455 arg.enabled = 1;
1456 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1457 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1458
1459 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1460 if (ret) {
1461 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1462 arvif->vdev_id, ret);
1463 return ret;
1464 }
1465
1466 return 0;
1467}
1468
Michal Kazior81a9a172015-03-05 16:02:17 +02001469static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1470{
1471 struct ath10k *ar = arvif->ar;
1472 struct ieee80211_vif *vif = arvif->vif;
1473 int ret;
1474
Michal Kazior8513d952015-03-09 14:19:24 +01001475 lockdep_assert_held(&arvif->ar->conf_mutex);
1476
1477 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1478 return;
1479
Michal Kazior81a9a172015-03-05 16:02:17 +02001480 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1481 return;
1482
1483 if (!vif->csa_active)
1484 return;
1485
1486 if (!arvif->is_up)
1487 return;
1488
1489 if (!ieee80211_csa_is_complete(vif)) {
1490 ieee80211_csa_update_counter(vif);
1491
1492 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1493 if (ret)
1494 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1495 ret);
1496
1497 ret = ath10k_mac_setup_prb_tmpl(arvif);
1498 if (ret)
1499 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1500 ret);
1501 } else {
1502 ieee80211_csa_finish(vif);
1503 }
1504}
1505
1506static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1507{
1508 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1509 ap_csa_work);
1510 struct ath10k *ar = arvif->ar;
1511
1512 mutex_lock(&ar->conf_mutex);
1513 ath10k_mac_vif_ap_csa_count_down(arvif);
1514 mutex_unlock(&ar->conf_mutex);
1515}
1516
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001517static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1518 struct ieee80211_vif *vif)
1519{
1520 struct sk_buff *skb = data;
1521 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1522 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1523
1524 if (vif->type != NL80211_IFTYPE_STATION)
1525 return;
1526
1527 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1528 return;
1529
1530 cancel_delayed_work(&arvif->connection_loss_work);
1531}
1532
1533void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1534{
1535 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1536 IEEE80211_IFACE_ITER_NORMAL,
1537 ath10k_mac_handle_beacon_iter,
1538 skb);
1539}
1540
1541static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1542 struct ieee80211_vif *vif)
1543{
1544 u32 *vdev_id = data;
1545 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1546 struct ath10k *ar = arvif->ar;
1547 struct ieee80211_hw *hw = ar->hw;
1548
1549 if (arvif->vdev_id != *vdev_id)
1550 return;
1551
1552 if (!arvif->is_up)
1553 return;
1554
1555 ieee80211_beacon_loss(vif);
1556
1557 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1558 * (done by mac80211) succeeds but beacons do not resume then it
1559 * doesn't make sense to continue operation. Queue connection loss work
1560 * which can be cancelled when beacon is received.
1561 */
1562 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1563 ATH10K_CONNECTION_LOSS_HZ);
1564}
1565
1566void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1567{
1568 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1569 IEEE80211_IFACE_ITER_NORMAL,
1570 ath10k_mac_handle_beacon_miss_iter,
1571 &vdev_id);
1572}
1573
1574static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1575{
1576 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1577 connection_loss_work.work);
1578 struct ieee80211_vif *vif = arvif->vif;
1579
1580 if (!arvif->is_up)
1581 return;
1582
1583 ieee80211_connection_loss(vif);
1584}
1585
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586/**********************/
1587/* Station management */
1588/**********************/
1589
Michal Kazior590922a2014-10-21 10:10:29 +03001590static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1591 struct ieee80211_vif *vif)
1592{
1593 /* Some firmware revisions have unstable STA powersave when listen
1594 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1595 * generate NullFunc frames properly even if buffered frames have been
1596 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1597 * buffered frames. Often pinging the device from AP would simply fail.
1598 *
1599 * As a workaround set it to 1.
1600 */
1601 if (vif->type == NL80211_IFTYPE_STATION)
1602 return 1;
1603
1604 return ar->hw->conf.listen_interval;
1605}
1606
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001608 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001610 struct wmi_peer_assoc_complete_arg *arg)
1611{
Michal Kazior590922a2014-10-21 10:10:29 +03001612 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1613
Michal Kazior548db542013-07-05 16:15:15 +03001614 lockdep_assert_held(&ar->conf_mutex);
1615
Kalle Valob25f32c2014-09-14 12:50:49 +03001616 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617 arg->vdev_id = arvif->vdev_id;
1618 arg->peer_aid = sta->aid;
1619 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001620 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001622 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623}
1624
1625static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001626 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 struct wmi_peer_assoc_complete_arg *arg)
1628{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 struct ieee80211_bss_conf *info = &vif->bss_conf;
1630 struct cfg80211_bss *bss;
1631 const u8 *rsnie = NULL;
1632 const u8 *wpaie = NULL;
1633
Michal Kazior548db542013-07-05 16:15:15 +03001634 lockdep_assert_held(&ar->conf_mutex);
1635
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001637 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1638 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 if (bss) {
1640 const struct cfg80211_bss_ies *ies;
1641
1642 rcu_read_lock();
1643 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1644
1645 ies = rcu_dereference(bss->ies);
1646
1647 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001648 WLAN_OUI_TYPE_MICROSOFT_WPA,
1649 ies->data,
1650 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001651 rcu_read_unlock();
1652 cfg80211_put_bss(ar->hw->wiphy, bss);
1653 }
1654
1655 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1656 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001657 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1659 }
1660
1661 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001662 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001663 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1664 }
1665}
1666
1667static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1668 struct ieee80211_sta *sta,
1669 struct wmi_peer_assoc_complete_arg *arg)
1670{
1671 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1672 const struct ieee80211_supported_band *sband;
1673 const struct ieee80211_rate *rates;
1674 u32 ratemask;
1675 int i;
1676
Michal Kazior548db542013-07-05 16:15:15 +03001677 lockdep_assert_held(&ar->conf_mutex);
1678
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1680 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1681 rates = sband->bitrates;
1682
1683 rateset->num_rates = 0;
1684
1685 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1686 if (!(ratemask & 1))
1687 continue;
1688
1689 rateset->rates[rateset->num_rates] = rates->hw_value;
1690 rateset->num_rates++;
1691 }
1692}
1693
1694static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1695 struct ieee80211_sta *sta,
1696 struct wmi_peer_assoc_complete_arg *arg)
1697{
1698 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001700 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701
Michal Kazior548db542013-07-05 16:15:15 +03001702 lockdep_assert_held(&ar->conf_mutex);
1703
Kalle Valo5e3dd152013-06-12 20:52:10 +03001704 if (!ht_cap->ht_supported)
1705 return;
1706
1707 arg->peer_flags |= WMI_PEER_HT;
1708 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1709 ht_cap->ampdu_factor)) - 1;
1710
1711 arg->peer_mpdu_density =
1712 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1713
1714 arg->peer_ht_caps = ht_cap->cap;
1715 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1716
1717 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1718 arg->peer_flags |= WMI_PEER_LDPC;
1719
1720 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1721 arg->peer_flags |= WMI_PEER_40MHZ;
1722 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1723 }
1724
1725 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1726 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1727
1728 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1729 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1730
1731 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1732 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1733 arg->peer_flags |= WMI_PEER_STBC;
1734 }
1735
1736 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1738 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1739 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1740 arg->peer_rate_caps |= stbc;
1741 arg->peer_flags |= WMI_PEER_STBC;
1742 }
1743
Kalle Valo5e3dd152013-06-12 20:52:10 +03001744 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1745 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1746 else if (ht_cap->mcs.rx_mask[1])
1747 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1748
1749 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1750 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1751 arg->peer_ht_rates.rates[n++] = i;
1752
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001753 /*
1754 * This is a workaround for HT-enabled STAs which break the spec
1755 * and have no HT capabilities RX mask (no HT RX MCS map).
1756 *
1757 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1758 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1759 *
1760 * Firmware asserts if such situation occurs.
1761 */
1762 if (n == 0) {
1763 arg->peer_ht_rates.num_rates = 8;
1764 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1765 arg->peer_ht_rates.rates[i] = i;
1766 } else {
1767 arg->peer_ht_rates.num_rates = n;
1768 arg->peer_num_spatial_streams = sta->rx_nss;
1769 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001770
Michal Kazior7aa7a722014-08-25 12:09:38 +02001771 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001772 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001773 arg->peer_ht_rates.num_rates,
1774 arg->peer_num_spatial_streams);
1775}
1776
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001777static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1778 struct ath10k_vif *arvif,
1779 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001780{
1781 u32 uapsd = 0;
1782 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001783 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784
Michal Kazior548db542013-07-05 16:15:15 +03001785 lockdep_assert_held(&ar->conf_mutex);
1786
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001788 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789 sta->uapsd_queues, sta->max_sp);
1790
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1792 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1793 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1794 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1795 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1796 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1797 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1798 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1799 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1800 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1801 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1802 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1803
Kalle Valo5e3dd152013-06-12 20:52:10 +03001804 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1805 max_sp = sta->max_sp;
1806
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001807 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1808 sta->addr,
1809 WMI_AP_PS_PEER_PARAM_UAPSD,
1810 uapsd);
1811 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001812 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001813 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001814 return ret;
1815 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001817 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1818 sta->addr,
1819 WMI_AP_PS_PEER_PARAM_MAX_SP,
1820 max_sp);
1821 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001822 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001823 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001824 return ret;
1825 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001826
1827 /* TODO setup this based on STA listen interval and
1828 beacon interval. Currently we don't know
1829 sta->listen_interval - mac80211 patch required.
1830 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001831 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001832 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1833 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001834 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001835 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001836 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001837 return ret;
1838 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001840
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001841 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001842}
1843
1844static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1845 struct ieee80211_sta *sta,
1846 struct wmi_peer_assoc_complete_arg *arg)
1847{
1848 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001849 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001850
1851 if (!vht_cap->vht_supported)
1852 return;
1853
1854 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001855
1856 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1857 arg->peer_flags |= WMI_PEER_VHT_2G;
1858
Kalle Valo5e3dd152013-06-12 20:52:10 +03001859 arg->peer_vht_caps = vht_cap->cap;
1860
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001861 ampdu_factor = (vht_cap->cap &
1862 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1863 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1864
1865 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1866 * zero in VHT IE. Using it would result in degraded throughput.
1867 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1868 * it if VHT max_mpdu is smaller. */
1869 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1870 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1871 ampdu_factor)) - 1);
1872
Kalle Valo5e3dd152013-06-12 20:52:10 +03001873 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1874 arg->peer_flags |= WMI_PEER_80MHZ;
1875
1876 arg->peer_vht_rates.rx_max_rate =
1877 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1878 arg->peer_vht_rates.rx_mcs_set =
1879 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1880 arg->peer_vht_rates.tx_max_rate =
1881 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1882 arg->peer_vht_rates.tx_mcs_set =
1883 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1884
Michal Kazior7aa7a722014-08-25 12:09:38 +02001885 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001886 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001887}
1888
1889static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001890 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001891 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892 struct wmi_peer_assoc_complete_arg *arg)
1893{
Michal Kazior590922a2014-10-21 10:10:29 +03001894 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1895
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896 switch (arvif->vdev_type) {
1897 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001898 if (sta->wme)
1899 arg->peer_flags |= WMI_PEER_QOS;
1900
1901 if (sta->wme && sta->uapsd_queues) {
1902 arg->peer_flags |= WMI_PEER_APSD;
1903 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1904 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905 break;
1906 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001907 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001908 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001909 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001910 case WMI_VDEV_TYPE_IBSS:
1911 if (sta->wme)
1912 arg->peer_flags |= WMI_PEER_QOS;
1913 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001914 default:
1915 break;
1916 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001917
1918 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1919 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001920}
1921
Michal Kazior91b12082014-12-12 12:41:35 +01001922static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1923{
1924 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1925 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1926}
1927
Kalle Valo5e3dd152013-06-12 20:52:10 +03001928static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001929 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930 struct ieee80211_sta *sta,
1931 struct wmi_peer_assoc_complete_arg *arg)
1932{
1933 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1934
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935 switch (ar->hw->conf.chandef.chan->band) {
1936 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001937 if (sta->vht_cap.vht_supported) {
1938 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1939 phymode = MODE_11AC_VHT40;
1940 else
1941 phymode = MODE_11AC_VHT20;
1942 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001943 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1944 phymode = MODE_11NG_HT40;
1945 else
1946 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001947 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001949 } else {
1950 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 }
1952
1953 break;
1954 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001955 /*
1956 * Check VHT first.
1957 */
1958 if (sta->vht_cap.vht_supported) {
1959 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1960 phymode = MODE_11AC_VHT80;
1961 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1962 phymode = MODE_11AC_VHT40;
1963 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1964 phymode = MODE_11AC_VHT20;
1965 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001966 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1967 phymode = MODE_11NA_HT40;
1968 else
1969 phymode = MODE_11NA_HT20;
1970 } else {
1971 phymode = MODE_11A;
1972 }
1973
1974 break;
1975 default:
1976 break;
1977 }
1978
Michal Kazior7aa7a722014-08-25 12:09:38 +02001979 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001980 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001981
Kalle Valo5e3dd152013-06-12 20:52:10 +03001982 arg->peer_phymode = phymode;
1983 WARN_ON(phymode == MODE_UNKNOWN);
1984}
1985
Kalle Valob9ada652013-10-16 15:44:46 +03001986static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001987 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001988 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001989 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990{
Michal Kazior548db542013-07-05 16:15:15 +03001991 lockdep_assert_held(&ar->conf_mutex);
1992
Kalle Valob9ada652013-10-16 15:44:46 +03001993 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994
Michal Kazior590922a2014-10-21 10:10:29 +03001995 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1996 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001997 ath10k_peer_assoc_h_rates(ar, sta, arg);
1998 ath10k_peer_assoc_h_ht(ar, sta, arg);
1999 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002000 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2001 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002
Kalle Valob9ada652013-10-16 15:44:46 +03002003 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004}
2005
Michal Kazior90046f52014-02-14 14:45:51 +01002006static const u32 ath10k_smps_map[] = {
2007 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2008 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2009 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2010 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2011};
2012
2013static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2014 const u8 *addr,
2015 const struct ieee80211_sta_ht_cap *ht_cap)
2016{
2017 int smps;
2018
2019 if (!ht_cap->ht_supported)
2020 return 0;
2021
2022 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2023 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2024
2025 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2026 return -EINVAL;
2027
2028 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2029 WMI_PEER_SMPS_STATE,
2030 ath10k_smps_map[smps]);
2031}
2032
Michal Kazior139e1702015-02-15 16:50:42 +02002033static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2034 struct ieee80211_vif *vif,
2035 struct ieee80211_sta_vht_cap vht_cap)
2036{
2037 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2038 int ret;
2039 u32 param;
2040 u32 value;
2041
2042 if (!(ar->vht_cap_info &
2043 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2044 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2045 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2046 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2047 return 0;
2048
2049 param = ar->wmi.vdev_param->txbf;
2050 value = 0;
2051
2052 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2053 return 0;
2054
2055 /* The following logic is correct. If a remote STA advertises support
2056 * for being a beamformer then we should enable us being a beamformee.
2057 */
2058
2059 if (ar->vht_cap_info &
2060 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2061 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2062 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2063 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2064
2065 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2066 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2067 }
2068
2069 if (ar->vht_cap_info &
2070 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2071 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2072 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2073 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2074
2075 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2076 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2077 }
2078
2079 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2080 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2081
2082 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2083 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2084
2085 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2086 if (ret) {
2087 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2088 value, ret);
2089 return ret;
2090 }
2091
2092 return 0;
2093}
2094
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095/* can be called only in mac80211 callbacks due to `key_count` usage */
2096static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2097 struct ieee80211_vif *vif,
2098 struct ieee80211_bss_conf *bss_conf)
2099{
2100 struct ath10k *ar = hw->priv;
2101 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002102 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002103 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002104 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002105 struct ieee80211_sta *ap_sta;
2106 int ret;
2107
Michal Kazior548db542013-07-05 16:15:15 +03002108 lockdep_assert_held(&ar->conf_mutex);
2109
Michal Kazior077efc82014-10-21 10:10:29 +03002110 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2111 arvif->vdev_id, arvif->bssid, arvif->aid);
2112
Kalle Valo5e3dd152013-06-12 20:52:10 +03002113 rcu_read_lock();
2114
2115 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2116 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002117 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002118 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119 rcu_read_unlock();
2120 return;
2121 }
2122
Michal Kazior90046f52014-02-14 14:45:51 +01002123 /* ap_sta must be accessed only within rcu section which must be left
2124 * before calling ath10k_setup_peer_smps() which might sleep. */
2125 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002126 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002127
Michal Kazior590922a2014-10-21 10:10:29 +03002128 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002129 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002130 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002131 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132 rcu_read_unlock();
2133 return;
2134 }
2135
2136 rcu_read_unlock();
2137
Kalle Valob9ada652013-10-16 15:44:46 +03002138 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2139 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002140 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002141 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002142 return;
2143 }
2144
Michal Kazior90046f52014-02-14 14:45:51 +01002145 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2146 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002147 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002148 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002149 return;
2150 }
2151
Michal Kazior139e1702015-02-15 16:50:42 +02002152 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2153 if (ret) {
2154 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2155 arvif->vdev_id, bss_conf->bssid, ret);
2156 return;
2157 }
2158
Michal Kazior7aa7a722014-08-25 12:09:38 +02002159 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002160 "mac vdev %d up (associated) bssid %pM aid %d\n",
2161 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2162
Michal Kazior077efc82014-10-21 10:10:29 +03002163 WARN_ON(arvif->is_up);
2164
Michal Kaziorc930f742014-01-23 11:38:25 +01002165 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002166 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002167
2168 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2169 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002170 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002171 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002172 return;
2173 }
2174
2175 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002176
2177 /* Workaround: Some firmware revisions (tested with qca6174
2178 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2179 * poked with peer param command.
2180 */
2181 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2182 WMI_PEER_DUMMY_VAR, 1);
2183 if (ret) {
2184 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2185 arvif->bssid, arvif->vdev_id, ret);
2186 return;
2187 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188}
2189
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2191 struct ieee80211_vif *vif)
2192{
2193 struct ath10k *ar = hw->priv;
2194 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002195 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002196 int ret;
2197
Michal Kazior548db542013-07-05 16:15:15 +03002198 lockdep_assert_held(&ar->conf_mutex);
2199
Michal Kazior077efc82014-10-21 10:10:29 +03002200 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2201 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002202
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002204 if (ret)
2205 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2206 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002207
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002208 arvif->def_wep_key_idx = -1;
2209
Michal Kazior139e1702015-02-15 16:50:42 +02002210 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2211 if (ret) {
2212 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2213 arvif->vdev_id, ret);
2214 return;
2215 }
2216
Michal Kaziorc930f742014-01-23 11:38:25 +01002217 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002218
2219 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002220}
2221
Michal Kazior590922a2014-10-21 10:10:29 +03002222static int ath10k_station_assoc(struct ath10k *ar,
2223 struct ieee80211_vif *vif,
2224 struct ieee80211_sta *sta,
2225 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002226{
Michal Kazior590922a2014-10-21 10:10:29 +03002227 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002228 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002229 int ret = 0;
2230
Michal Kazior548db542013-07-05 16:15:15 +03002231 lockdep_assert_held(&ar->conf_mutex);
2232
Michal Kazior590922a2014-10-21 10:10:29 +03002233 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002234 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002235 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002236 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002237 return ret;
2238 }
2239
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002240 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002241 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2242 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002243 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002244 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002245 return ret;
2246 }
2247
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002248 /* Re-assoc is run only to update supported rates for given station. It
2249 * doesn't make much sense to reconfigure the peer completely.
2250 */
2251 if (!reassoc) {
2252 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2253 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002254 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002255 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002256 arvif->vdev_id, ret);
2257 return ret;
2258 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002259
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002260 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2261 if (ret) {
2262 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2263 sta->addr, arvif->vdev_id, ret);
2264 return ret;
2265 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002266
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002267 if (!sta->wme) {
2268 arvif->num_legacy_stations++;
2269 ret = ath10k_recalc_rtscts_prot(arvif);
2270 if (ret) {
2271 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2272 arvif->vdev_id, ret);
2273 return ret;
2274 }
2275 }
2276
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002277 /* Plumb cached keys only for static WEP */
2278 if (arvif->def_wep_key_idx != -1) {
2279 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2280 if (ret) {
2281 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2282 arvif->vdev_id, ret);
2283 return ret;
2284 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285 }
2286 }
2287
Kalle Valo5e3dd152013-06-12 20:52:10 +03002288 return ret;
2289}
2290
Michal Kazior590922a2014-10-21 10:10:29 +03002291static int ath10k_station_disassoc(struct ath10k *ar,
2292 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002293 struct ieee80211_sta *sta)
2294{
Michal Kazior590922a2014-10-21 10:10:29 +03002295 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002296 int ret = 0;
2297
2298 lockdep_assert_held(&ar->conf_mutex);
2299
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002300 if (!sta->wme) {
2301 arvif->num_legacy_stations--;
2302 ret = ath10k_recalc_rtscts_prot(arvif);
2303 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002304 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002305 arvif->vdev_id, ret);
2306 return ret;
2307 }
2308 }
2309
Kalle Valo5e3dd152013-06-12 20:52:10 +03002310 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2311 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002312 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002313 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002314 return ret;
2315 }
2316
2317 return ret;
2318}
2319
2320/**************/
2321/* Regulatory */
2322/**************/
2323
2324static int ath10k_update_channel_list(struct ath10k *ar)
2325{
2326 struct ieee80211_hw *hw = ar->hw;
2327 struct ieee80211_supported_band **bands;
2328 enum ieee80211_band band;
2329 struct ieee80211_channel *channel;
2330 struct wmi_scan_chan_list_arg arg = {0};
2331 struct wmi_channel_arg *ch;
2332 bool passive;
2333 int len;
2334 int ret;
2335 int i;
2336
Michal Kazior548db542013-07-05 16:15:15 +03002337 lockdep_assert_held(&ar->conf_mutex);
2338
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339 bands = hw->wiphy->bands;
2340 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2341 if (!bands[band])
2342 continue;
2343
2344 for (i = 0; i < bands[band]->n_channels; i++) {
2345 if (bands[band]->channels[i].flags &
2346 IEEE80211_CHAN_DISABLED)
2347 continue;
2348
2349 arg.n_channels++;
2350 }
2351 }
2352
2353 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2354 arg.channels = kzalloc(len, GFP_KERNEL);
2355 if (!arg.channels)
2356 return -ENOMEM;
2357
2358 ch = arg.channels;
2359 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2360 if (!bands[band])
2361 continue;
2362
2363 for (i = 0; i < bands[band]->n_channels; i++) {
2364 channel = &bands[band]->channels[i];
2365
2366 if (channel->flags & IEEE80211_CHAN_DISABLED)
2367 continue;
2368
2369 ch->allow_ht = true;
2370
2371 /* FIXME: when should we really allow VHT? */
2372 ch->allow_vht = true;
2373
2374 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002375 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376
2377 ch->ht40plus =
2378 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2379
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002380 ch->chan_radar =
2381 !!(channel->flags & IEEE80211_CHAN_RADAR);
2382
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002383 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002384 ch->passive = passive;
2385
2386 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002387 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002388 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002389 ch->max_power = channel->max_power * 2;
2390 ch->max_reg_power = channel->max_reg_power * 2;
2391 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002392 ch->reg_class_id = 0; /* FIXME */
2393
2394 /* FIXME: why use only legacy modes, why not any
2395 * HT/VHT modes? Would that even make any
2396 * difference? */
2397 if (channel->band == IEEE80211_BAND_2GHZ)
2398 ch->mode = MODE_11G;
2399 else
2400 ch->mode = MODE_11A;
2401
2402 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2403 continue;
2404
Michal Kazior7aa7a722014-08-25 12:09:38 +02002405 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002406 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2407 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408 ch->freq, ch->max_power, ch->max_reg_power,
2409 ch->max_antenna_gain, ch->mode);
2410
2411 ch++;
2412 }
2413 }
2414
2415 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2416 kfree(arg.channels);
2417
2418 return ret;
2419}
2420
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002421static enum wmi_dfs_region
2422ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2423{
2424 switch (dfs_region) {
2425 case NL80211_DFS_UNSET:
2426 return WMI_UNINIT_DFS_DOMAIN;
2427 case NL80211_DFS_FCC:
2428 return WMI_FCC_DFS_DOMAIN;
2429 case NL80211_DFS_ETSI:
2430 return WMI_ETSI_DFS_DOMAIN;
2431 case NL80211_DFS_JP:
2432 return WMI_MKK4_DFS_DOMAIN;
2433 }
2434 return WMI_UNINIT_DFS_DOMAIN;
2435}
2436
Michal Kaziorf7843d72013-07-16 09:38:52 +02002437static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002438{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002439 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002440 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002441 enum wmi_dfs_region wmi_dfs_reg;
2442 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002443
Michal Kaziorf7843d72013-07-16 09:38:52 +02002444 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445
2446 ret = ath10k_update_channel_list(ar);
2447 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002448 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002449
2450 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002451
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002452 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2453 nl_dfs_reg = ar->dfs_detector->region;
2454 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2455 } else {
2456 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2457 }
2458
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 /* Target allows setting up per-band regdomain but ath_common provides
2460 * a combined one only */
2461 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002462 regpair->reg_domain,
2463 regpair->reg_domain, /* 2ghz */
2464 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002465 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002466 regpair->reg_5ghz_ctl,
2467 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002469 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002470}
Michal Kazior548db542013-07-05 16:15:15 +03002471
Michal Kaziorf7843d72013-07-16 09:38:52 +02002472static void ath10k_reg_notifier(struct wiphy *wiphy,
2473 struct regulatory_request *request)
2474{
2475 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2476 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002477 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002478
2479 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2480
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002481 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002482 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002483 request->dfs_region);
2484 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2485 request->dfs_region);
2486 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002487 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002488 request->dfs_region);
2489 }
2490
Michal Kaziorf7843d72013-07-16 09:38:52 +02002491 mutex_lock(&ar->conf_mutex);
2492 if (ar->state == ATH10K_STATE_ON)
2493 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002494 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495}
2496
2497/***************/
2498/* TX handlers */
2499/***************/
2500
Michal Kazior42c3aa62013-10-02 11:03:38 +02002501static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2502{
2503 if (ieee80211_is_mgmt(hdr->frame_control))
2504 return HTT_DATA_TX_EXT_TID_MGMT;
2505
2506 if (!ieee80211_is_data_qos(hdr->frame_control))
2507 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2508
2509 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2510 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2511
2512 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2513}
2514
Michal Kazior2b37c292014-09-02 11:00:22 +03002515static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002516{
Michal Kazior2b37c292014-09-02 11:00:22 +03002517 if (vif)
2518 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002519
Michal Kazior1bbc0972014-04-08 09:45:47 +03002520 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002521 return ar->monitor_vdev_id;
2522
Michal Kazior7aa7a722014-08-25 12:09:38 +02002523 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002524 return 0;
2525}
2526
Michal Kaziord740d8f2015-03-30 09:51:51 +03002527static enum ath10k_hw_txrx_mode
2528ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
2529 struct sk_buff *skb)
2530{
2531 const struct ieee80211_hdr *hdr = (void *)skb->data;
2532 __le16 fc = hdr->frame_control;
2533
2534 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2535 return ATH10K_HW_TXRX_RAW;
2536
2537 if (ieee80211_is_mgmt(fc))
2538 return ATH10K_HW_TXRX_MGMT;
2539
2540 /* Workaround:
2541 *
2542 * NullFunc frames are mostly used to ping if a client or AP are still
2543 * reachable and responsive. This implies tx status reports must be
2544 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2545 * come to a conclusion that the other end disappeared and tear down
2546 * BSS connection or it can never disconnect from BSS/client (which is
2547 * the case).
2548 *
2549 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2550 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2551 * which seems to deliver correct tx reports for NullFunc frames. The
2552 * downside of using it is it ignores client powersave state so it can
2553 * end up disconnecting sleeping clients in AP mode. It should fix STA
2554 * mode though because AP don't sleep.
2555 */
2556 if (ar->htt.target_version_major < 3 &&
2557 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2558 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2559 return ATH10K_HW_TXRX_MGMT;
2560
2561 return ATH10K_HW_TXRX_NATIVE_WIFI;
2562}
2563
Michal Kazior4b604552014-07-21 21:03:09 +03002564/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2565 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002566 */
Michal Kazior4b604552014-07-21 21:03:09 +03002567static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568{
2569 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002570 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002571 u8 *qos_ctl;
2572
2573 if (!ieee80211_is_data_qos(hdr->frame_control))
2574 return;
2575
2576 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002577 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2578 skb->data, (void *)qos_ctl - (void *)skb->data);
2579 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002580
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002581 /* Some firmware revisions don't handle sending QoS NullFunc well.
2582 * These frames are mainly used for CQM purposes so it doesn't really
2583 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002584 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002585 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002586 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002587 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002588
2589 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590}
2591
Michal Kaziord740d8f2015-03-30 09:51:51 +03002592static void ath10k_tx_h_8023(struct sk_buff *skb)
2593{
2594 struct ieee80211_hdr *hdr;
2595 struct rfc1042_hdr *rfc1042;
2596 struct ethhdr *eth;
2597 size_t hdrlen;
2598 u8 da[ETH_ALEN];
2599 u8 sa[ETH_ALEN];
2600 __be16 type;
2601
2602 hdr = (void *)skb->data;
2603 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2604 rfc1042 = (void *)skb->data + hdrlen;
2605
2606 ether_addr_copy(da, ieee80211_get_DA(hdr));
2607 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2608 type = rfc1042->snap_type;
2609
2610 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2611 skb_push(skb, sizeof(*eth));
2612
2613 eth = (void *)skb->data;
2614 ether_addr_copy(eth->h_dest, da);
2615 ether_addr_copy(eth->h_source, sa);
2616 eth->h_proto = type;
2617}
2618
Michal Kazior4b604552014-07-21 21:03:09 +03002619static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2620 struct ieee80211_vif *vif,
2621 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622{
2623 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2625
2626 /* This is case only for P2P_GO */
2627 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2628 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2629 return;
2630
2631 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2632 spin_lock_bh(&ar->data_lock);
2633 if (arvif->u.ap.noa_data)
2634 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2635 GFP_ATOMIC))
2636 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2637 arvif->u.ap.noa_data,
2638 arvif->u.ap.noa_len);
2639 spin_unlock_bh(&ar->data_lock);
2640 }
2641}
2642
Michal Kazior8d6d3622014-11-24 14:58:31 +01002643static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2644{
2645 /* FIXME: Not really sure since when the behaviour changed. At some
2646 * point new firmware stopped requiring creation of peer entries for
2647 * offchannel tx (and actually creating them causes issues with wmi-htc
2648 * tx credit replenishment and reliability). Assuming it's at least 3.4
2649 * because that's when the `freq` was introduced to TX_FRM HTT command.
2650 */
2651 return !(ar->htt.target_version_major >= 3 &&
2652 ar->htt.target_version_minor >= 4);
2653}
2654
Michal Kaziord740d8f2015-03-30 09:51:51 +03002655static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002656{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002657 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002658 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002659
Michal Kaziord740d8f2015-03-30 09:51:51 +03002660 spin_lock_bh(&ar->data_lock);
2661
2662 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2663 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2664 ret = -ENOSPC;
2665 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002666 }
2667
Michal Kaziord740d8f2015-03-30 09:51:51 +03002668 __skb_queue_tail(q, skb);
2669 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2670
2671unlock:
2672 spin_unlock_bh(&ar->data_lock);
2673
2674 return ret;
2675}
2676
2677static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2678{
2679 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2680 struct ath10k_htt *htt = &ar->htt;
2681 int ret = 0;
2682
2683 switch (cb->txmode) {
2684 case ATH10K_HW_TXRX_RAW:
2685 case ATH10K_HW_TXRX_NATIVE_WIFI:
2686 case ATH10K_HW_TXRX_ETHERNET:
2687 ret = ath10k_htt_tx(htt, skb);
2688 break;
2689 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002690 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002691 ar->fw_features))
2692 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2693 else if (ar->htt.target_version_major >= 3)
2694 ret = ath10k_htt_tx(htt, skb);
2695 else
2696 ret = ath10k_htt_mgmt_tx(htt, skb);
2697 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002698 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002699
2700 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002701 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2702 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002703 ieee80211_free_txskb(ar->hw, skb);
2704 }
2705}
2706
2707void ath10k_offchan_tx_purge(struct ath10k *ar)
2708{
2709 struct sk_buff *skb;
2710
2711 for (;;) {
2712 skb = skb_dequeue(&ar->offchan_tx_queue);
2713 if (!skb)
2714 break;
2715
2716 ieee80211_free_txskb(ar->hw, skb);
2717 }
2718}
2719
2720void ath10k_offchan_tx_work(struct work_struct *work)
2721{
2722 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2723 struct ath10k_peer *peer;
2724 struct ieee80211_hdr *hdr;
2725 struct sk_buff *skb;
2726 const u8 *peer_addr;
2727 int vdev_id;
2728 int ret;
2729
2730 /* FW requirement: We must create a peer before FW will send out
2731 * an offchannel frame. Otherwise the frame will be stuck and
2732 * never transmitted. We delete the peer upon tx completion.
2733 * It is unlikely that a peer for offchannel tx will already be
2734 * present. However it may be in some rare cases so account for that.
2735 * Otherwise we might remove a legitimate peer and break stuff. */
2736
2737 for (;;) {
2738 skb = skb_dequeue(&ar->offchan_tx_queue);
2739 if (!skb)
2740 break;
2741
2742 mutex_lock(&ar->conf_mutex);
2743
Michal Kazior7aa7a722014-08-25 12:09:38 +02002744 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745 skb);
2746
2747 hdr = (struct ieee80211_hdr *)skb->data;
2748 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002749 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750
2751 spin_lock_bh(&ar->data_lock);
2752 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2753 spin_unlock_bh(&ar->data_lock);
2754
2755 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002756 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002757 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758 peer_addr, vdev_id);
2759
2760 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03002761 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
2762 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002764 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002765 peer_addr, vdev_id, ret);
2766 }
2767
2768 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002769 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002770 ar->offchan_tx_skb = skb;
2771 spin_unlock_bh(&ar->data_lock);
2772
Michal Kaziord740d8f2015-03-30 09:51:51 +03002773 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002774
2775 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2776 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002777 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002778 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779 skb);
2780
2781 if (!peer) {
2782 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2783 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002784 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002785 peer_addr, vdev_id, ret);
2786 }
2787
2788 mutex_unlock(&ar->conf_mutex);
2789 }
2790}
2791
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002792void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2793{
2794 struct sk_buff *skb;
2795
2796 for (;;) {
2797 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2798 if (!skb)
2799 break;
2800
2801 ieee80211_free_txskb(ar->hw, skb);
2802 }
2803}
2804
2805void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2806{
2807 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2808 struct sk_buff *skb;
2809 int ret;
2810
2811 for (;;) {
2812 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2813 if (!skb)
2814 break;
2815
2816 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002817 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002818 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002819 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002820 ieee80211_free_txskb(ar->hw, skb);
2821 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002822 }
2823}
2824
Kalle Valo5e3dd152013-06-12 20:52:10 +03002825/************/
2826/* Scanning */
2827/************/
2828
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002829void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002831 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002832
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002833 switch (ar->scan.state) {
2834 case ATH10K_SCAN_IDLE:
2835 break;
2836 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002837 if (ar->scan.is_roc)
2838 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002839 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002840 case ATH10K_SCAN_ABORTING:
2841 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002842 ieee80211_scan_completed(ar->hw,
2843 (ar->scan.state ==
2844 ATH10K_SCAN_ABORTING));
2845 /* fall through */
2846 case ATH10K_SCAN_STARTING:
2847 ar->scan.state = ATH10K_SCAN_IDLE;
2848 ar->scan_channel = NULL;
2849 ath10k_offchan_tx_purge(ar);
2850 cancel_delayed_work(&ar->scan.timeout);
2851 complete_all(&ar->scan.completed);
2852 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002853 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002854}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002855
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002856void ath10k_scan_finish(struct ath10k *ar)
2857{
2858 spin_lock_bh(&ar->data_lock);
2859 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002860 spin_unlock_bh(&ar->data_lock);
2861}
2862
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002863static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002864{
2865 struct wmi_stop_scan_arg arg = {
2866 .req_id = 1, /* FIXME */
2867 .req_type = WMI_SCAN_STOP_ONE,
2868 .u.scan_id = ATH10K_SCAN_ID,
2869 };
2870 int ret;
2871
2872 lockdep_assert_held(&ar->conf_mutex);
2873
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874 ret = ath10k_wmi_stop_scan(ar, &arg);
2875 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002876 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002877 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002878 }
2879
Kalle Valo5e3dd152013-06-12 20:52:10 +03002880 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002881 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002882 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002883 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002884 } else if (ret > 0) {
2885 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002886 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002887
2888out:
2889 /* Scan state should be updated upon scan completion but in case
2890 * firmware fails to deliver the event (for whatever reason) it is
2891 * desired to clean up scan state anyway. Firmware may have just
2892 * dropped the scan completion event delivery due to transport pipe
2893 * being overflown with data and/or it can recover on its own before
2894 * next scan request is submitted.
2895 */
2896 spin_lock_bh(&ar->data_lock);
2897 if (ar->scan.state != ATH10K_SCAN_IDLE)
2898 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002899 spin_unlock_bh(&ar->data_lock);
2900
2901 return ret;
2902}
2903
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002904static void ath10k_scan_abort(struct ath10k *ar)
2905{
2906 int ret;
2907
2908 lockdep_assert_held(&ar->conf_mutex);
2909
2910 spin_lock_bh(&ar->data_lock);
2911
2912 switch (ar->scan.state) {
2913 case ATH10K_SCAN_IDLE:
2914 /* This can happen if timeout worker kicked in and called
2915 * abortion while scan completion was being processed.
2916 */
2917 break;
2918 case ATH10K_SCAN_STARTING:
2919 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002920 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002921 ath10k_scan_state_str(ar->scan.state),
2922 ar->scan.state);
2923 break;
2924 case ATH10K_SCAN_RUNNING:
2925 ar->scan.state = ATH10K_SCAN_ABORTING;
2926 spin_unlock_bh(&ar->data_lock);
2927
2928 ret = ath10k_scan_stop(ar);
2929 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002930 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002931
2932 spin_lock_bh(&ar->data_lock);
2933 break;
2934 }
2935
2936 spin_unlock_bh(&ar->data_lock);
2937}
2938
2939void ath10k_scan_timeout_work(struct work_struct *work)
2940{
2941 struct ath10k *ar = container_of(work, struct ath10k,
2942 scan.timeout.work);
2943
2944 mutex_lock(&ar->conf_mutex);
2945 ath10k_scan_abort(ar);
2946 mutex_unlock(&ar->conf_mutex);
2947}
2948
Kalle Valo5e3dd152013-06-12 20:52:10 +03002949static int ath10k_start_scan(struct ath10k *ar,
2950 const struct wmi_start_scan_arg *arg)
2951{
2952 int ret;
2953
2954 lockdep_assert_held(&ar->conf_mutex);
2955
2956 ret = ath10k_wmi_start_scan(ar, arg);
2957 if (ret)
2958 return ret;
2959
Kalle Valo5e3dd152013-06-12 20:52:10 +03002960 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2961 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002962 ret = ath10k_scan_stop(ar);
2963 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002964 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002965
2966 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002967 }
2968
Ben Greear2f9eec02015-02-15 16:50:38 +02002969 /* If we failed to start the scan, return error code at
2970 * this point. This is probably due to some issue in the
2971 * firmware, but no need to wedge the driver due to that...
2972 */
2973 spin_lock_bh(&ar->data_lock);
2974 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2975 spin_unlock_bh(&ar->data_lock);
2976 return -EINVAL;
2977 }
2978 spin_unlock_bh(&ar->data_lock);
2979
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002980 /* Add a 200ms margin to account for event/command processing */
2981 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2982 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002983 return 0;
2984}
2985
2986/**********************/
2987/* mac80211 callbacks */
2988/**********************/
2989
2990static void ath10k_tx(struct ieee80211_hw *hw,
2991 struct ieee80211_tx_control *control,
2992 struct sk_buff *skb)
2993{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002994 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002995 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2996 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002997 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03002998 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002999
3000 /* We should disable CCK RATE due to P2P */
3001 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003002 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003003
Michal Kazior4b604552014-07-21 21:03:09 +03003004 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003005 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003006 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003007 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003008 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, skb);
3009 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003010
Michal Kaziord740d8f2015-03-30 09:51:51 +03003011 switch (ATH10K_SKB_CB(skb)->txmode) {
3012 case ATH10K_HW_TXRX_MGMT:
3013 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003014 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003015 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3016 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003017 break;
3018 case ATH10K_HW_TXRX_ETHERNET:
3019 ath10k_tx_h_8023(skb);
3020 break;
3021 case ATH10K_HW_TXRX_RAW:
3022 /* FIXME: Packet injection isn't implemented. It should be
3023 * doable with firmware 10.2 on qca988x.
3024 */
3025 WARN_ON_ONCE(1);
3026 ieee80211_free_txskb(hw, skb);
3027 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003028 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003029
Kalle Valo5e3dd152013-06-12 20:52:10 +03003030 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3031 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003032 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003033 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003034 spin_unlock_bh(&ar->data_lock);
3035
Michal Kazior8d6d3622014-11-24 14:58:31 +01003036 if (ath10k_mac_need_offchan_tx_work(ar)) {
3037 ATH10K_SKB_CB(skb)->htt.freq = 0;
3038 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003039
Michal Kazior8d6d3622014-11-24 14:58:31 +01003040 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3041 skb);
3042
3043 skb_queue_tail(&ar->offchan_tx_queue, skb);
3044 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3045 return;
3046 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047 }
3048
Michal Kaziord740d8f2015-03-30 09:51:51 +03003049 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003050}
3051
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003052/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003053void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003054{
3055 /* make sure rcu-protected mac80211 tx path itself is drained */
3056 synchronize_net();
3057
3058 ath10k_offchan_tx_purge(ar);
3059 ath10k_mgmt_over_wmi_tx_purge(ar);
3060
3061 cancel_work_sync(&ar->offchan_tx_work);
3062 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3063}
3064
Michal Kazioraffd3212013-07-16 09:54:35 +02003065void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003066{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003067 struct ath10k_vif *arvif;
3068
Michal Kazior818bdd12013-07-16 09:38:57 +02003069 lockdep_assert_held(&ar->conf_mutex);
3070
Michal Kazior19337472014-08-28 12:58:16 +02003071 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3072 ar->filter_flags = 0;
3073 ar->monitor = false;
3074
3075 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003076 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003077
3078 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003079
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003080 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003081 ath10k_peer_cleanup_all(ar);
3082 ath10k_core_stop(ar);
3083 ath10k_hif_power_down(ar);
3084
3085 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003086 list_for_each_entry(arvif, &ar->arvifs, list)
3087 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003088 spin_unlock_bh(&ar->data_lock);
3089}
3090
Ben Greear46acf7bb2014-05-16 17:15:38 +03003091static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3092{
3093 struct ath10k *ar = hw->priv;
3094
3095 mutex_lock(&ar->conf_mutex);
3096
3097 if (ar->cfg_tx_chainmask) {
3098 *tx_ant = ar->cfg_tx_chainmask;
3099 *rx_ant = ar->cfg_rx_chainmask;
3100 } else {
3101 *tx_ant = ar->supp_tx_chainmask;
3102 *rx_ant = ar->supp_rx_chainmask;
3103 }
3104
3105 mutex_unlock(&ar->conf_mutex);
3106
3107 return 0;
3108}
3109
Ben Greear5572a952014-11-24 16:22:10 +02003110static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3111{
3112 /* It is not clear that allowing gaps in chainmask
3113 * is helpful. Probably it will not do what user
3114 * is hoping for, so warn in that case.
3115 */
3116 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3117 return;
3118
3119 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3120 dbg, cm);
3121}
3122
Ben Greear46acf7bb2014-05-16 17:15:38 +03003123static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3124{
3125 int ret;
3126
3127 lockdep_assert_held(&ar->conf_mutex);
3128
Ben Greear5572a952014-11-24 16:22:10 +02003129 ath10k_check_chain_mask(ar, tx_ant, "tx");
3130 ath10k_check_chain_mask(ar, rx_ant, "rx");
3131
Ben Greear46acf7bb2014-05-16 17:15:38 +03003132 ar->cfg_tx_chainmask = tx_ant;
3133 ar->cfg_rx_chainmask = rx_ant;
3134
3135 if ((ar->state != ATH10K_STATE_ON) &&
3136 (ar->state != ATH10K_STATE_RESTARTED))
3137 return 0;
3138
3139 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3140 tx_ant);
3141 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003142 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03003143 ret, tx_ant);
3144 return ret;
3145 }
3146
3147 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3148 rx_ant);
3149 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003150 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03003151 ret, rx_ant);
3152 return ret;
3153 }
3154
3155 return 0;
3156}
3157
3158static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3159{
3160 struct ath10k *ar = hw->priv;
3161 int ret;
3162
3163 mutex_lock(&ar->conf_mutex);
3164 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3165 mutex_unlock(&ar->conf_mutex);
3166 return ret;
3167}
3168
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169static int ath10k_start(struct ieee80211_hw *hw)
3170{
3171 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003172 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003173
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003174 /*
3175 * This makes sense only when restarting hw. It is harmless to call
3176 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3177 * commands will be submitted while restarting.
3178 */
3179 ath10k_drain_tx(ar);
3180
Michal Kazior548db542013-07-05 16:15:15 +03003181 mutex_lock(&ar->conf_mutex);
3182
Michal Kaziorc5058f52014-05-26 12:46:03 +03003183 switch (ar->state) {
3184 case ATH10K_STATE_OFF:
3185 ar->state = ATH10K_STATE_ON;
3186 break;
3187 case ATH10K_STATE_RESTARTING:
3188 ath10k_halt(ar);
3189 ar->state = ATH10K_STATE_RESTARTED;
3190 break;
3191 case ATH10K_STATE_ON:
3192 case ATH10K_STATE_RESTARTED:
3193 case ATH10K_STATE_WEDGED:
3194 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003195 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003196 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003197 case ATH10K_STATE_UTF:
3198 ret = -EBUSY;
3199 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003200 }
3201
3202 ret = ath10k_hif_power_up(ar);
3203 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003204 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003205 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003206 }
3207
Kalle Valo43d2a302014-09-10 18:23:30 +03003208 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003209 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003210 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003211 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003212 }
3213
Bartosz Markowski226a3392013-09-26 17:47:16 +02003214 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003215 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003216 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003217 goto err_core_stop;
3218 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003220 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003221 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003222 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003223 goto err_core_stop;
3224 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225
Ben Greear46acf7bb2014-05-16 17:15:38 +03003226 if (ar->cfg_tx_chainmask)
3227 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3228 ar->cfg_rx_chainmask);
3229
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003230 /*
3231 * By default FW set ARP frames ac to voice (6). In that case ARP
3232 * exchange is not working properly for UAPSD enabled AP. ARP requests
3233 * which arrives with access category 0 are processed by network stack
3234 * and send back with access category 0, but FW changes access category
3235 * to 6. Set ARP frames access category to best effort (0) solves
3236 * this problem.
3237 */
3238
3239 ret = ath10k_wmi_pdev_set_param(ar,
3240 ar->wmi.pdev_param->arp_ac_override, 0);
3241 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003242 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003243 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003244 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003245 }
3246
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303247 ret = ath10k_wmi_pdev_set_param(ar,
3248 ar->wmi.pdev_param->ani_enable, 1);
3249 if (ret) {
3250 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3251 ret);
3252 goto err_core_stop;
3253 }
3254
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303255 ar->ani_enabled = true;
3256
Michal Kaziord6500972014-04-08 09:56:09 +03003257 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003258 ath10k_regd_update(ar);
3259
Simon Wunderlich855aed12014-08-02 09:12:54 +03003260 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303261 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003262
Michal Kaziorae254432014-05-26 12:46:02 +03003263 mutex_unlock(&ar->conf_mutex);
3264 return 0;
3265
3266err_core_stop:
3267 ath10k_core_stop(ar);
3268
3269err_power_down:
3270 ath10k_hif_power_down(ar);
3271
3272err_off:
3273 ar->state = ATH10K_STATE_OFF;
3274
3275err:
Michal Kazior548db542013-07-05 16:15:15 +03003276 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003277 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003278}
3279
3280static void ath10k_stop(struct ieee80211_hw *hw)
3281{
3282 struct ath10k *ar = hw->priv;
3283
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003284 ath10k_drain_tx(ar);
3285
Michal Kazior548db542013-07-05 16:15:15 +03003286 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003287 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003288 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003289 ar->state = ATH10K_STATE_OFF;
3290 }
Michal Kazior548db542013-07-05 16:15:15 +03003291 mutex_unlock(&ar->conf_mutex);
3292
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003293 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003294 cancel_work_sync(&ar->restart_work);
3295}
3296
Michal Kaziorad088bf2013-10-16 15:44:46 +03003297static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003298{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003299 struct ath10k_vif *arvif;
3300 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003301
3302 lockdep_assert_held(&ar->conf_mutex);
3303
Michal Kaziorad088bf2013-10-16 15:44:46 +03003304 list_for_each_entry(arvif, &ar->arvifs, list) {
3305 ret = ath10k_mac_vif_setup_ps(arvif);
3306 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003307 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003308 break;
3309 }
3310 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003311
Michal Kaziorad088bf2013-10-16 15:44:46 +03003312 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003313}
3314
Michal Kaziorc930f742014-01-23 11:38:25 +01003315static const char *chandef_get_width(enum nl80211_chan_width width)
3316{
3317 switch (width) {
3318 case NL80211_CHAN_WIDTH_20_NOHT:
3319 return "20 (noht)";
3320 case NL80211_CHAN_WIDTH_20:
3321 return "20";
3322 case NL80211_CHAN_WIDTH_40:
3323 return "40";
3324 case NL80211_CHAN_WIDTH_80:
3325 return "80";
3326 case NL80211_CHAN_WIDTH_80P80:
3327 return "80+80";
3328 case NL80211_CHAN_WIDTH_160:
3329 return "160";
3330 case NL80211_CHAN_WIDTH_5:
3331 return "5";
3332 case NL80211_CHAN_WIDTH_10:
3333 return "10";
3334 }
3335 return "?";
3336}
3337
3338static void ath10k_config_chan(struct ath10k *ar)
3339{
3340 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003341 int ret;
3342
3343 lockdep_assert_held(&ar->conf_mutex);
3344
Michal Kazior7aa7a722014-08-25 12:09:38 +02003345 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003346 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3347 ar->chandef.chan->center_freq,
3348 ar->chandef.center_freq1,
3349 ar->chandef.center_freq2,
3350 chandef_get_width(ar->chandef.width));
3351
3352 /* First stop monitor interface. Some FW versions crash if there's a
3353 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003354 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003355 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003356
3357 list_for_each_entry(arvif, &ar->arvifs, list) {
3358 if (!arvif->is_started)
3359 continue;
3360
Michal Kaziordc55e302014-07-29 12:53:36 +03003361 if (!arvif->is_up)
3362 continue;
3363
Michal Kaziorc930f742014-01-23 11:38:25 +01003364 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3365 continue;
3366
Michal Kaziordc55e302014-07-29 12:53:36 +03003367 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003368 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003369 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003370 arvif->vdev_id, ret);
3371 continue;
3372 }
3373 }
3374
Michal Kaziordc55e302014-07-29 12:53:36 +03003375 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003376
3377 list_for_each_entry(arvif, &ar->arvifs, list) {
3378 if (!arvif->is_started)
3379 continue;
3380
3381 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3382 continue;
3383
Michal Kazior81a9a172015-03-05 16:02:17 +02003384 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3385 if (ret)
3386 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3387 ret);
3388
3389 ret = ath10k_mac_setup_prb_tmpl(arvif);
3390 if (ret)
3391 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3392 ret);
3393
Michal Kaziordc55e302014-07-29 12:53:36 +03003394 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003395 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003396 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003397 arvif->vdev_id, ret);
3398 continue;
3399 }
3400
3401 if (!arvif->is_up)
3402 continue;
3403
3404 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3405 arvif->bssid);
3406 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003407 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003408 arvif->vdev_id, ret);
3409 continue;
3410 }
3411 }
3412
Michal Kazior19337472014-08-28 12:58:16 +02003413 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003414}
3415
Michal Kazior7d9d5582014-10-21 10:40:15 +03003416static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3417{
3418 int ret;
3419 u32 param;
3420
3421 lockdep_assert_held(&ar->conf_mutex);
3422
3423 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3424
3425 param = ar->wmi.pdev_param->txpower_limit2g;
3426 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3427 if (ret) {
3428 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3429 txpower, ret);
3430 return ret;
3431 }
3432
3433 param = ar->wmi.pdev_param->txpower_limit5g;
3434 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3435 if (ret) {
3436 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3437 txpower, ret);
3438 return ret;
3439 }
3440
3441 return 0;
3442}
3443
3444static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3445{
3446 struct ath10k_vif *arvif;
3447 int ret, txpower = -1;
3448
3449 lockdep_assert_held(&ar->conf_mutex);
3450
3451 list_for_each_entry(arvif, &ar->arvifs, list) {
3452 WARN_ON(arvif->txpower < 0);
3453
3454 if (txpower == -1)
3455 txpower = arvif->txpower;
3456 else
3457 txpower = min(txpower, arvif->txpower);
3458 }
3459
3460 if (WARN_ON(txpower == -1))
3461 return -EINVAL;
3462
3463 ret = ath10k_mac_txpower_setup(ar, txpower);
3464 if (ret) {
3465 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3466 txpower, ret);
3467 return ret;
3468 }
3469
3470 return 0;
3471}
3472
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3474{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475 struct ath10k *ar = hw->priv;
3476 struct ieee80211_conf *conf = &hw->conf;
3477 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478
3479 mutex_lock(&ar->conf_mutex);
3480
3481 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003482 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003483 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003484 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003485 conf->chandef.chan->flags,
3486 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003487
Kalle Valo5e3dd152013-06-12 20:52:10 +03003488 spin_lock_bh(&ar->data_lock);
3489 ar->rx_channel = conf->chandef.chan;
3490 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003491
Michal Kaziord6500972014-04-08 09:56:09 +03003492 ar->radar_enabled = conf->radar_enabled;
3493 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003494
3495 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3496 ar->chandef = conf->chandef;
3497 ath10k_config_chan(ar);
3498 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499 }
3500
Michal Kazioraffd3212013-07-16 09:54:35 +02003501 if (changed & IEEE80211_CONF_CHANGE_PS)
3502 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503
3504 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003505 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3506 ret = ath10k_monitor_recalc(ar);
3507 if (ret)
3508 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003509 }
3510
3511 mutex_unlock(&ar->conf_mutex);
3512 return ret;
3513}
3514
Ben Greear5572a952014-11-24 16:22:10 +02003515static u32 get_nss_from_chainmask(u16 chain_mask)
3516{
3517 if ((chain_mask & 0x15) == 0x15)
3518 return 4;
3519 else if ((chain_mask & 0x7) == 0x7)
3520 return 3;
3521 else if ((chain_mask & 0x3) == 0x3)
3522 return 2;
3523 return 1;
3524}
3525
Kalle Valo5e3dd152013-06-12 20:52:10 +03003526/*
3527 * TODO:
3528 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3529 * because we will send mgmt frames without CCK. This requirement
3530 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3531 * in the TX packet.
3532 */
3533static int ath10k_add_interface(struct ieee80211_hw *hw,
3534 struct ieee80211_vif *vif)
3535{
3536 struct ath10k *ar = hw->priv;
3537 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3538 enum wmi_sta_powersave_param param;
3539 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003540 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003542 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543
Johannes Berg848955c2014-11-11 12:48:42 +01003544 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3545
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 mutex_lock(&ar->conf_mutex);
3547
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003548 memset(arvif, 0, sizeof(*arvif));
3549
Kalle Valo5e3dd152013-06-12 20:52:10 +03003550 arvif->ar = ar;
3551 arvif->vif = vif;
3552
Ben Greeare63b33f2013-10-22 14:54:14 -07003553 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003554 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003555 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3556 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003557
Ben Greeara9aefb32014-08-12 11:02:19 +03003558 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003559 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003561 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 }
Ben Greear16c11172014-09-23 14:17:16 -07003563 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003564
Ben Greear16c11172014-09-23 14:17:16 -07003565 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3566 bit, ar->free_vdev_map);
3567
3568 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003569 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003570
Kalle Valo5e3dd152013-06-12 20:52:10 +03003571 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003572 case NL80211_IFTYPE_P2P_DEVICE:
3573 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3574 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3575 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 case NL80211_IFTYPE_UNSPECIFIED:
3577 case NL80211_IFTYPE_STATION:
3578 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3579 if (vif->p2p)
3580 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3581 break;
3582 case NL80211_IFTYPE_ADHOC:
3583 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3584 break;
3585 case NL80211_IFTYPE_AP:
3586 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3587
3588 if (vif->p2p)
3589 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3590 break;
3591 case NL80211_IFTYPE_MONITOR:
3592 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3593 break;
3594 default:
3595 WARN_ON(1);
3596 break;
3597 }
3598
Michal Kazior64badcb2014-09-18 11:18:02 +03003599 /* Some firmware revisions don't wait for beacon tx completion before
3600 * sending another SWBA event. This could lead to hardware using old
3601 * (freed) beacon data in some cases, e.g. tx credit starvation
3602 * combined with missed TBTT. This is very very rare.
3603 *
3604 * On non-IOMMU-enabled hosts this could be a possible security issue
3605 * because hw could beacon some random data on the air. On
3606 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3607 * device would crash.
3608 *
3609 * Since there are no beacon tx completions (implicit nor explicit)
3610 * propagated to host the only workaround for this is to allocate a
3611 * DMA-coherent buffer for a lifetime of a vif and use it for all
3612 * beacon tx commands. Worst case for this approach is some beacons may
3613 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3614 */
3615 if (vif->type == NL80211_IFTYPE_ADHOC ||
3616 vif->type == NL80211_IFTYPE_AP) {
3617 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3618 IEEE80211_MAX_FRAME_LEN,
3619 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303620 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003621 if (!arvif->beacon_buf) {
3622 ret = -ENOMEM;
3623 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3624 ret);
3625 goto err;
3626 }
3627 }
3628
3629 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3630 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3631 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632
3633 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3634 arvif->vdev_subtype, vif->addr);
3635 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003636 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003637 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003638 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003639 }
3640
Ben Greear16c11172014-09-23 14:17:16 -07003641 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003642 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003643
Michal Kazior46725b152015-01-28 09:57:49 +02003644 /* It makes no sense to have firmware do keepalives. mac80211 already
3645 * takes care of this with idle connection polling.
3646 */
3647 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003648 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003649 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003650 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003651 goto err_vdev_delete;
3652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003653
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003654 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003656 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3657 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003658 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003659 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003660 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003661 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003662 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003663 goto err_vdev_delete;
3664 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003665
Ben Greear5572a952014-11-24 16:22:10 +02003666 if (ar->cfg_tx_chainmask) {
3667 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3668
3669 vdev_param = ar->wmi.vdev_param->nss;
3670 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3671 nss);
3672 if (ret) {
3673 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3674 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3675 ret);
3676 goto err_vdev_delete;
3677 }
3678 }
3679
Kalle Valo5e3dd152013-06-12 20:52:10 +03003680 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003681 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
3682 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003683 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003684 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003685 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003686 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003687 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003688
Kalle Valo5a13e762014-01-20 11:01:46 +02003689 ret = ath10k_mac_set_kickout(arvif);
3690 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003691 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003692 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003693 goto err_peer_delete;
3694 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003695 }
3696
3697 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3698 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3699 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3700 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3701 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003702 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003703 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003704 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003705 goto err_peer_delete;
3706 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707
Michal Kazior9f9b5742014-12-12 12:41:36 +01003708 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003709 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003710 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003711 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003712 goto err_peer_delete;
3713 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003714
Michal Kazior9f9b5742014-12-12 12:41:36 +01003715 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003716 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003717 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003718 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003719 goto err_peer_delete;
3720 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003721 }
3722
Michal Kazior424121c2013-07-22 14:13:31 +02003723 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003725 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003726 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003727 goto err_peer_delete;
3728 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003729
Michal Kazior424121c2013-07-22 14:13:31 +02003730 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003731 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003732 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003733 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003734 goto err_peer_delete;
3735 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003736
Michal Kazior7d9d5582014-10-21 10:40:15 +03003737 arvif->txpower = vif->bss_conf.txpower;
3738 ret = ath10k_mac_txpower_recalc(ar);
3739 if (ret) {
3740 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3741 goto err_peer_delete;
3742 }
3743
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003745 return 0;
3746
3747err_peer_delete:
3748 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3749 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3750
3751err_vdev_delete:
3752 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003753 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003754 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003755
3756err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003757 if (arvif->beacon_buf) {
3758 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3759 arvif->beacon_buf, arvif->beacon_paddr);
3760 arvif->beacon_buf = NULL;
3761 }
3762
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003763 mutex_unlock(&ar->conf_mutex);
3764
Kalle Valo5e3dd152013-06-12 20:52:10 +03003765 return ret;
3766}
3767
3768static void ath10k_remove_interface(struct ieee80211_hw *hw,
3769 struct ieee80211_vif *vif)
3770{
3771 struct ath10k *ar = hw->priv;
3772 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3773 int ret;
3774
Michal Kazior81a9a172015-03-05 16:02:17 +02003775 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003776 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003777
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303778 mutex_lock(&ar->conf_mutex);
3779
Michal Kaziored543882013-09-13 14:16:56 +02003780 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003781 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003782 spin_unlock_bh(&ar->data_lock);
3783
Simon Wunderlich855aed12014-08-02 09:12:54 +03003784 ret = ath10k_spectral_vif_stop(arvif);
3785 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003786 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003787 arvif->vdev_id, ret);
3788
Ben Greear16c11172014-09-23 14:17:16 -07003789 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003790 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003791
3792 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003793 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3794 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003795 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003796 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003797 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003798
3799 kfree(arvif->u.ap.noa_data);
3800 }
3801
Michal Kazior7aa7a722014-08-25 12:09:38 +02003802 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003803 arvif->vdev_id);
3804
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3806 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003807 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003808 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003809
Michal Kazior2c512052015-02-15 16:50:40 +02003810 /* Some firmware revisions don't notify host about self-peer removal
3811 * until after associated vdev is deleted.
3812 */
3813 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3814 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3815 vif->addr);
3816 if (ret)
3817 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3818 arvif->vdev_id, ret);
3819
3820 spin_lock_bh(&ar->data_lock);
3821 ar->num_peers--;
3822 spin_unlock_bh(&ar->data_lock);
3823 }
3824
Kalle Valo5e3dd152013-06-12 20:52:10 +03003825 ath10k_peer_cleanup(ar, arvif->vdev_id);
3826
3827 mutex_unlock(&ar->conf_mutex);
3828}
3829
3830/*
3831 * FIXME: Has to be verified.
3832 */
3833#define SUPPORTED_FILTERS \
3834 (FIF_PROMISC_IN_BSS | \
3835 FIF_ALLMULTI | \
3836 FIF_CONTROL | \
3837 FIF_PSPOLL | \
3838 FIF_OTHER_BSS | \
3839 FIF_BCN_PRBRESP_PROMISC | \
3840 FIF_PROBE_REQ | \
3841 FIF_FCSFAIL)
3842
3843static void ath10k_configure_filter(struct ieee80211_hw *hw,
3844 unsigned int changed_flags,
3845 unsigned int *total_flags,
3846 u64 multicast)
3847{
3848 struct ath10k *ar = hw->priv;
3849 int ret;
3850
3851 mutex_lock(&ar->conf_mutex);
3852
3853 changed_flags &= SUPPORTED_FILTERS;
3854 *total_flags &= SUPPORTED_FILTERS;
3855 ar->filter_flags = *total_flags;
3856
Michal Kazior19337472014-08-28 12:58:16 +02003857 ret = ath10k_monitor_recalc(ar);
3858 if (ret)
3859 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003860
3861 mutex_unlock(&ar->conf_mutex);
3862}
3863
3864static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3865 struct ieee80211_vif *vif,
3866 struct ieee80211_bss_conf *info,
3867 u32 changed)
3868{
3869 struct ath10k *ar = hw->priv;
3870 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3871 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003872 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003873
3874 mutex_lock(&ar->conf_mutex);
3875
3876 if (changed & BSS_CHANGED_IBSS)
3877 ath10k_control_ibss(arvif, info, vif->addr);
3878
3879 if (changed & BSS_CHANGED_BEACON_INT) {
3880 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003881 vdev_param = ar->wmi.vdev_param->beacon_interval;
3882 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003883 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003884 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003885 "mac vdev %d beacon_interval %d\n",
3886 arvif->vdev_id, arvif->beacon_interval);
3887
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003889 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003890 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003891 }
3892
3893 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003894 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003895 "vdev %d set beacon tx mode to staggered\n",
3896 arvif->vdev_id);
3897
Bartosz Markowski226a3392013-09-26 17:47:16 +02003898 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3899 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003900 WMI_BEACON_STAGGERED_MODE);
3901 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003902 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003903 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003904
3905 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3906 if (ret)
3907 ath10k_warn(ar, "failed to update beacon template: %d\n",
3908 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909 }
3910
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003911 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3912 ret = ath10k_mac_setup_prb_tmpl(arvif);
3913 if (ret)
3914 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3915 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003916 }
3917
Michal Kaziorba2479f2015-01-24 12:14:51 +02003918 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003919 arvif->dtim_period = info->dtim_period;
3920
Michal Kazior7aa7a722014-08-25 12:09:38 +02003921 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003922 "mac vdev %d dtim_period %d\n",
3923 arvif->vdev_id, arvif->dtim_period);
3924
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003925 vdev_param = ar->wmi.vdev_param->dtim_period;
3926 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927 arvif->dtim_period);
3928 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003929 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003930 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003931 }
3932
3933 if (changed & BSS_CHANGED_SSID &&
3934 vif->type == NL80211_IFTYPE_AP) {
3935 arvif->u.ap.ssid_len = info->ssid_len;
3936 if (info->ssid_len)
3937 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3938 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3939 }
3940
Michal Kazior077efc82014-10-21 10:10:29 +03003941 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3942 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003943
3944 if (changed & BSS_CHANGED_BEACON_ENABLED)
3945 ath10k_control_beaconing(arvif, info);
3946
3947 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003948 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003950 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003951
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003952 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003953 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003954 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003955 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003956
3957 vdev_param = ar->wmi.vdev_param->protection_mode;
3958 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3959 info->use_cts_prot ? 1 : 0);
3960 if (ret)
3961 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3962 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963 }
3964
3965 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003966 if (info->use_short_slot)
3967 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3968
3969 else
3970 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3971
Michal Kazior7aa7a722014-08-25 12:09:38 +02003972 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003973 arvif->vdev_id, slottime);
3974
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003975 vdev_param = ar->wmi.vdev_param->slot_time;
3976 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977 slottime);
3978 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003979 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003980 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003981 }
3982
3983 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003984 if (info->use_short_preamble)
3985 preamble = WMI_VDEV_PREAMBLE_SHORT;
3986 else
3987 preamble = WMI_VDEV_PREAMBLE_LONG;
3988
Michal Kazior7aa7a722014-08-25 12:09:38 +02003989 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003990 "mac vdev %d preamble %dn",
3991 arvif->vdev_id, preamble);
3992
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003993 vdev_param = ar->wmi.vdev_param->preamble;
3994 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 preamble);
3996 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003997 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003998 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 }
4000
4001 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004002 if (info->assoc) {
4003 /* Workaround: Make sure monitor vdev is not running
4004 * when associating to prevent some firmware revisions
4005 * (e.g. 10.1 and 10.2) from crashing.
4006 */
4007 if (ar->monitor_started)
4008 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004009 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004010 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004011 } else {
4012 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004013 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014 }
4015
Michal Kazior7d9d5582014-10-21 10:40:15 +03004016 if (changed & BSS_CHANGED_TXPOWER) {
4017 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4018 arvif->vdev_id, info->txpower);
4019
4020 arvif->txpower = info->txpower;
4021 ret = ath10k_mac_txpower_recalc(ar);
4022 if (ret)
4023 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4024 }
4025
Michal Kaziorbf14e652014-12-12 12:41:38 +01004026 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004027 arvif->ps = vif->bss_conf.ps;
4028
4029 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004030 if (ret)
4031 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4032 arvif->vdev_id, ret);
4033 }
4034
Kalle Valo5e3dd152013-06-12 20:52:10 +03004035 mutex_unlock(&ar->conf_mutex);
4036}
4037
4038static int ath10k_hw_scan(struct ieee80211_hw *hw,
4039 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004040 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041{
4042 struct ath10k *ar = hw->priv;
4043 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004044 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004045 struct wmi_start_scan_arg arg;
4046 int ret = 0;
4047 int i;
4048
4049 mutex_lock(&ar->conf_mutex);
4050
4051 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004052 switch (ar->scan.state) {
4053 case ATH10K_SCAN_IDLE:
4054 reinit_completion(&ar->scan.started);
4055 reinit_completion(&ar->scan.completed);
4056 ar->scan.state = ATH10K_SCAN_STARTING;
4057 ar->scan.is_roc = false;
4058 ar->scan.vdev_id = arvif->vdev_id;
4059 ret = 0;
4060 break;
4061 case ATH10K_SCAN_STARTING:
4062 case ATH10K_SCAN_RUNNING:
4063 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004064 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004065 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004066 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 spin_unlock_bh(&ar->data_lock);
4068
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004069 if (ret)
4070 goto exit;
4071
Kalle Valo5e3dd152013-06-12 20:52:10 +03004072 memset(&arg, 0, sizeof(arg));
4073 ath10k_wmi_start_scan_init(ar, &arg);
4074 arg.vdev_id = arvif->vdev_id;
4075 arg.scan_id = ATH10K_SCAN_ID;
4076
4077 if (!req->no_cck)
4078 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4079
4080 if (req->ie_len) {
4081 arg.ie_len = req->ie_len;
4082 memcpy(arg.ie, req->ie, arg.ie_len);
4083 }
4084
4085 if (req->n_ssids) {
4086 arg.n_ssids = req->n_ssids;
4087 for (i = 0; i < arg.n_ssids; i++) {
4088 arg.ssids[i].len = req->ssids[i].ssid_len;
4089 arg.ssids[i].ssid = req->ssids[i].ssid;
4090 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004091 } else {
4092 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004093 }
4094
4095 if (req->n_channels) {
4096 arg.n_channels = req->n_channels;
4097 for (i = 0; i < arg.n_channels; i++)
4098 arg.channels[i] = req->channels[i]->center_freq;
4099 }
4100
4101 ret = ath10k_start_scan(ar, &arg);
4102 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004103 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004104 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004105 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004106 spin_unlock_bh(&ar->data_lock);
4107 }
4108
4109exit:
4110 mutex_unlock(&ar->conf_mutex);
4111 return ret;
4112}
4113
4114static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4115 struct ieee80211_vif *vif)
4116{
4117 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004118
4119 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004120 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004121 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004122
4123 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004124}
4125
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004126static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4127 struct ath10k_vif *arvif,
4128 enum set_key_cmd cmd,
4129 struct ieee80211_key_conf *key)
4130{
4131 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4132 int ret;
4133
4134 /* 10.1 firmware branch requires default key index to be set to group
4135 * key index after installing it. Otherwise FW/HW Txes corrupted
4136 * frames with multi-vif APs. This is not required for main firmware
4137 * branch (e.g. 636).
4138 *
4139 * FIXME: This has been tested only in AP. It remains unknown if this
4140 * is required for multi-vif STA interfaces on 10.1 */
4141
4142 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4143 return;
4144
4145 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4146 return;
4147
4148 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4149 return;
4150
4151 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4152 return;
4153
4154 if (cmd != SET_KEY)
4155 return;
4156
4157 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4158 key->keyidx);
4159 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004160 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004161 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004162}
4163
Kalle Valo5e3dd152013-06-12 20:52:10 +03004164static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4165 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4166 struct ieee80211_key_conf *key)
4167{
4168 struct ath10k *ar = hw->priv;
4169 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4170 struct ath10k_peer *peer;
4171 const u8 *peer_addr;
4172 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4173 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4174 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004175 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004176
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004177 /* this one needs to be done in software */
4178 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4179 return 1;
4180
Kalle Valo5e3dd152013-06-12 20:52:10 +03004181 if (key->keyidx > WMI_MAX_KEY_INDEX)
4182 return -ENOSPC;
4183
4184 mutex_lock(&ar->conf_mutex);
4185
4186 if (sta)
4187 peer_addr = sta->addr;
4188 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4189 peer_addr = vif->bss_conf.bssid;
4190 else
4191 peer_addr = vif->addr;
4192
4193 key->hw_key_idx = key->keyidx;
4194
4195 /* the peer should not disappear in mid-way (unless FW goes awry) since
4196 * we already hold conf_mutex. we just make sure its there now. */
4197 spin_lock_bh(&ar->data_lock);
4198 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4199 spin_unlock_bh(&ar->data_lock);
4200
4201 if (!peer) {
4202 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004203 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204 peer_addr);
4205 ret = -EOPNOTSUPP;
4206 goto exit;
4207 } else {
4208 /* if the peer doesn't exist there is no key to disable
4209 * anymore */
4210 goto exit;
4211 }
4212 }
4213
Michal Kazior7cc45732015-03-09 14:24:17 +01004214 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4215 flags |= WMI_KEY_PAIRWISE;
4216 else
4217 flags |= WMI_KEY_GROUP;
4218
Kalle Valo5e3dd152013-06-12 20:52:10 +03004219 if (is_wep) {
4220 if (cmd == SET_KEY)
4221 arvif->wep_keys[key->keyidx] = key;
4222 else
4223 arvif->wep_keys[key->keyidx] = NULL;
4224
4225 if (cmd == DISABLE_KEY)
4226 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004227
Michal Kaziorad325cb2015-02-18 14:02:27 +01004228 /* When WEP keys are uploaded it's possible that there are
4229 * stations associated already (e.g. when merging) without any
4230 * keys. Static WEP needs an explicit per-peer key upload.
4231 */
4232 if (vif->type == NL80211_IFTYPE_ADHOC &&
4233 cmd == SET_KEY)
4234 ath10k_mac_vif_update_wep_key(arvif, key);
4235
Michal Kazior370e5672015-02-18 14:02:26 +01004236 /* 802.1x never sets the def_wep_key_idx so each set_key()
4237 * call changes default tx key.
4238 *
4239 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4240 * after first set_key().
4241 */
4242 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4243 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004244
Michal Kazior7cc45732015-03-09 14:24:17 +01004245 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4246 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4247 * mode and associated stations in AP/IBSS.
4248 *
4249 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4250 * work fine when mapped directly from mac80211.
4251 *
4252 * Note: When installing first static WEP groupwise key (which
4253 * should be pairwise) def_wep_key_idx isn't known yet (it's
4254 * equal to -1). Since .set_default_unicast_key is called only
4255 * for static WEP it's used to re-upload the key as pairwise.
4256 */
4257 if (arvif->def_wep_key_idx >= 0 &&
4258 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4259 flags &= ~WMI_KEY_GROUP;
4260 flags |= WMI_KEY_PAIRWISE;
4261 }
Michal Kazior370e5672015-02-18 14:02:26 +01004262 }
4263
4264 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004265 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004266 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004267 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004268 goto exit;
4269 }
4270
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004271 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4272
Kalle Valo5e3dd152013-06-12 20:52:10 +03004273 spin_lock_bh(&ar->data_lock);
4274 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4275 if (peer && cmd == SET_KEY)
4276 peer->keys[key->keyidx] = key;
4277 else if (peer && cmd == DISABLE_KEY)
4278 peer->keys[key->keyidx] = NULL;
4279 else if (peer == NULL)
4280 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004282 spin_unlock_bh(&ar->data_lock);
4283
4284exit:
4285 mutex_unlock(&ar->conf_mutex);
4286 return ret;
4287}
4288
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004289static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4290 struct ieee80211_vif *vif,
4291 int keyidx)
4292{
4293 struct ath10k *ar = hw->priv;
4294 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4295 int ret;
4296
4297 mutex_lock(&arvif->ar->conf_mutex);
4298
4299 if (arvif->ar->state != ATH10K_STATE_ON)
4300 goto unlock;
4301
4302 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4303 arvif->vdev_id, keyidx);
4304
4305 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4306 arvif->vdev_id,
4307 arvif->ar->wmi.vdev_param->def_keyid,
4308 keyidx);
4309
4310 if (ret) {
4311 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4312 arvif->vdev_id,
4313 ret);
4314 goto unlock;
4315 }
4316
4317 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004318
4319 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4320 if (ret) {
4321 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4322 arvif->vdev_id, ret);
4323 goto unlock;
4324 }
4325
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004326unlock:
4327 mutex_unlock(&arvif->ar->conf_mutex);
4328}
4329
Michal Kazior9797feb2014-02-14 14:49:48 +01004330static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4331{
4332 struct ath10k *ar;
4333 struct ath10k_vif *arvif;
4334 struct ath10k_sta *arsta;
4335 struct ieee80211_sta *sta;
4336 u32 changed, bw, nss, smps;
4337 int err;
4338
4339 arsta = container_of(wk, struct ath10k_sta, update_wk);
4340 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4341 arvif = arsta->arvif;
4342 ar = arvif->ar;
4343
4344 spin_lock_bh(&ar->data_lock);
4345
4346 changed = arsta->changed;
4347 arsta->changed = 0;
4348
4349 bw = arsta->bw;
4350 nss = arsta->nss;
4351 smps = arsta->smps;
4352
4353 spin_unlock_bh(&ar->data_lock);
4354
4355 mutex_lock(&ar->conf_mutex);
4356
4357 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004358 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004359 sta->addr, bw);
4360
4361 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4362 WMI_PEER_CHAN_WIDTH, bw);
4363 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004364 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004365 sta->addr, bw, err);
4366 }
4367
4368 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004369 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004370 sta->addr, nss);
4371
4372 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4373 WMI_PEER_NSS, nss);
4374 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004375 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004376 sta->addr, nss, err);
4377 }
4378
4379 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004380 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004381 sta->addr, smps);
4382
4383 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4384 WMI_PEER_SMPS_STATE, smps);
4385 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004386 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004387 sta->addr, smps, err);
4388 }
4389
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004390 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4391 changed & IEEE80211_RC_NSS_CHANGED) {
4392 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004393 sta->addr);
4394
Michal Kazior590922a2014-10-21 10:10:29 +03004395 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004396 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004397 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004398 sta->addr);
4399 }
4400
Michal Kazior9797feb2014-02-14 14:49:48 +01004401 mutex_unlock(&ar->conf_mutex);
4402}
4403
Michal Kaziorcfd10612014-11-25 15:16:05 +01004404static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4405{
4406 struct ath10k *ar = arvif->ar;
4407
4408 lockdep_assert_held(&ar->conf_mutex);
4409
4410 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4411 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4412 return 0;
4413
4414 if (ar->num_stations >= ar->max_num_stations)
4415 return -ENOBUFS;
4416
4417 ar->num_stations++;
4418
4419 return 0;
4420}
4421
4422static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4423{
4424 struct ath10k *ar = arvif->ar;
4425
4426 lockdep_assert_held(&ar->conf_mutex);
4427
4428 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4429 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4430 return;
4431
4432 ar->num_stations--;
4433}
4434
Kalle Valo5e3dd152013-06-12 20:52:10 +03004435static int ath10k_sta_state(struct ieee80211_hw *hw,
4436 struct ieee80211_vif *vif,
4437 struct ieee80211_sta *sta,
4438 enum ieee80211_sta_state old_state,
4439 enum ieee80211_sta_state new_state)
4440{
4441 struct ath10k *ar = hw->priv;
4442 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004443 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004444 int ret = 0;
4445
Michal Kazior76f90022014-02-25 09:29:57 +02004446 if (old_state == IEEE80211_STA_NOTEXIST &&
4447 new_state == IEEE80211_STA_NONE) {
4448 memset(arsta, 0, sizeof(*arsta));
4449 arsta->arvif = arvif;
4450 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4451 }
4452
Michal Kazior9797feb2014-02-14 14:49:48 +01004453 /* cancel must be done outside the mutex to avoid deadlock */
4454 if ((old_state == IEEE80211_STA_NONE &&
4455 new_state == IEEE80211_STA_NOTEXIST))
4456 cancel_work_sync(&arsta->update_wk);
4457
Kalle Valo5e3dd152013-06-12 20:52:10 +03004458 mutex_lock(&ar->conf_mutex);
4459
4460 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004461 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004462 /*
4463 * New station addition.
4464 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004465 ath10k_dbg(ar, ATH10K_DBG_MAC,
4466 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4467 arvif->vdev_id, sta->addr,
4468 ar->num_stations + 1, ar->max_num_stations,
4469 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004470
Michal Kaziorcfd10612014-11-25 15:16:05 +01004471 ret = ath10k_mac_inc_num_stations(arvif);
4472 if (ret) {
4473 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4474 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004475 goto exit;
4476 }
4477
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004478 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
4479 WMI_PEER_TYPE_DEFAULT);
Michal Kaziora52c0282014-11-25 15:16:03 +01004480 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004481 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 -08004482 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004483 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004484 goto exit;
4485 }
Michal Kazior077efc82014-10-21 10:10:29 +03004486
4487 if (vif->type == NL80211_IFTYPE_STATION) {
4488 WARN_ON(arvif->is_started);
4489
4490 ret = ath10k_vdev_start(arvif);
4491 if (ret) {
4492 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4493 arvif->vdev_id, ret);
4494 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4495 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004496 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004497 goto exit;
4498 }
4499
4500 arvif->is_started = true;
4501 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004502 } else if ((old_state == IEEE80211_STA_NONE &&
4503 new_state == IEEE80211_STA_NOTEXIST)) {
4504 /*
4505 * Existing station deletion.
4506 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004507 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004508 "mac vdev %d peer delete %pM (sta gone)\n",
4509 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004510
4511 if (vif->type == NL80211_IFTYPE_STATION) {
4512 WARN_ON(!arvif->is_started);
4513
4514 ret = ath10k_vdev_stop(arvif);
4515 if (ret)
4516 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4517 arvif->vdev_id, ret);
4518
4519 arvif->is_started = false;
4520 }
4521
Kalle Valo5e3dd152013-06-12 20:52:10 +03004522 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4523 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004524 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004525 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004526
Michal Kaziorcfd10612014-11-25 15:16:05 +01004527 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004528 } else if (old_state == IEEE80211_STA_AUTH &&
4529 new_state == IEEE80211_STA_ASSOC &&
4530 (vif->type == NL80211_IFTYPE_AP ||
4531 vif->type == NL80211_IFTYPE_ADHOC)) {
4532 /*
4533 * New association.
4534 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004535 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004536 sta->addr);
4537
Michal Kazior590922a2014-10-21 10:10:29 +03004538 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004539 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004540 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004541 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004542 } else if (old_state == IEEE80211_STA_ASSOC &&
4543 new_state == IEEE80211_STA_AUTH &&
4544 (vif->type == NL80211_IFTYPE_AP ||
4545 vif->type == NL80211_IFTYPE_ADHOC)) {
4546 /*
4547 * Disassociation.
4548 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004549 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004550 sta->addr);
4551
Michal Kazior590922a2014-10-21 10:10:29 +03004552 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004553 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004554 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004555 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004557exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004558 mutex_unlock(&ar->conf_mutex);
4559 return ret;
4560}
4561
4562static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004563 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004564{
4565 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004566 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4567 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004568 u32 value = 0;
4569 int ret = 0;
4570
Michal Kazior548db542013-07-05 16:15:15 +03004571 lockdep_assert_held(&ar->conf_mutex);
4572
Kalle Valo5e3dd152013-06-12 20:52:10 +03004573 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4574 return 0;
4575
4576 switch (ac) {
4577 case IEEE80211_AC_VO:
4578 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4579 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004580 prio = 7;
4581 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004582 break;
4583 case IEEE80211_AC_VI:
4584 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4585 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004586 prio = 5;
4587 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004588 break;
4589 case IEEE80211_AC_BE:
4590 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4591 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004592 prio = 2;
4593 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004594 break;
4595 case IEEE80211_AC_BK:
4596 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4597 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004598 prio = 0;
4599 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004600 break;
4601 }
4602
4603 if (enable)
4604 arvif->u.sta.uapsd |= value;
4605 else
4606 arvif->u.sta.uapsd &= ~value;
4607
4608 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4609 WMI_STA_PS_PARAM_UAPSD,
4610 arvif->u.sta.uapsd);
4611 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004612 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004613 goto exit;
4614 }
4615
4616 if (arvif->u.sta.uapsd)
4617 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4618 else
4619 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4620
4621 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4622 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4623 value);
4624 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004625 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004626
Michal Kazior9f9b5742014-12-12 12:41:36 +01004627 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4628 if (ret) {
4629 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4630 arvif->vdev_id, ret);
4631 return ret;
4632 }
4633
4634 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4635 if (ret) {
4636 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4637 arvif->vdev_id, ret);
4638 return ret;
4639 }
4640
Michal Kaziorb0e56152015-01-24 12:14:52 +02004641 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4642 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4643 /* Only userspace can make an educated decision when to send
4644 * trigger frame. The following effectively disables u-UAPSD
4645 * autotrigger in firmware (which is enabled by default
4646 * provided the autotrigger service is available).
4647 */
4648
4649 arg.wmm_ac = acc;
4650 arg.user_priority = prio;
4651 arg.service_interval = 0;
4652 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4653 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4654
4655 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4656 arvif->bssid, &arg, 1);
4657 if (ret) {
4658 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4659 ret);
4660 return ret;
4661 }
4662 }
4663
Kalle Valo5e3dd152013-06-12 20:52:10 +03004664exit:
4665 return ret;
4666}
4667
4668static int ath10k_conf_tx(struct ieee80211_hw *hw,
4669 struct ieee80211_vif *vif, u16 ac,
4670 const struct ieee80211_tx_queue_params *params)
4671{
4672 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004673 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004674 struct wmi_wmm_params_arg *p = NULL;
4675 int ret;
4676
4677 mutex_lock(&ar->conf_mutex);
4678
4679 switch (ac) {
4680 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004681 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004682 break;
4683 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004684 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004685 break;
4686 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004687 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004688 break;
4689 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004690 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004691 break;
4692 }
4693
4694 if (WARN_ON(!p)) {
4695 ret = -EINVAL;
4696 goto exit;
4697 }
4698
4699 p->cwmin = params->cw_min;
4700 p->cwmax = params->cw_max;
4701 p->aifs = params->aifs;
4702
4703 /*
4704 * The channel time duration programmed in the HW is in absolute
4705 * microseconds, while mac80211 gives the txop in units of
4706 * 32 microseconds.
4707 */
4708 p->txop = params->txop * 32;
4709
Michal Kazior7fc979a2015-01-28 09:57:28 +02004710 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4711 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4712 &arvif->wmm_params);
4713 if (ret) {
4714 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4715 arvif->vdev_id, ret);
4716 goto exit;
4717 }
4718 } else {
4719 /* This won't work well with multi-interface cases but it's
4720 * better than nothing.
4721 */
4722 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4723 if (ret) {
4724 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4725 goto exit;
4726 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004727 }
4728
4729 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4730 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004731 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732
4733exit:
4734 mutex_unlock(&ar->conf_mutex);
4735 return ret;
4736}
4737
4738#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4739
4740static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4741 struct ieee80211_vif *vif,
4742 struct ieee80211_channel *chan,
4743 int duration,
4744 enum ieee80211_roc_type type)
4745{
4746 struct ath10k *ar = hw->priv;
4747 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4748 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004749 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004750
4751 mutex_lock(&ar->conf_mutex);
4752
4753 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004754 switch (ar->scan.state) {
4755 case ATH10K_SCAN_IDLE:
4756 reinit_completion(&ar->scan.started);
4757 reinit_completion(&ar->scan.completed);
4758 reinit_completion(&ar->scan.on_channel);
4759 ar->scan.state = ATH10K_SCAN_STARTING;
4760 ar->scan.is_roc = true;
4761 ar->scan.vdev_id = arvif->vdev_id;
4762 ar->scan.roc_freq = chan->center_freq;
4763 ret = 0;
4764 break;
4765 case ATH10K_SCAN_STARTING:
4766 case ATH10K_SCAN_RUNNING:
4767 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004768 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004769 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004770 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771 spin_unlock_bh(&ar->data_lock);
4772
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004773 if (ret)
4774 goto exit;
4775
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004776 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4777
Kalle Valo5e3dd152013-06-12 20:52:10 +03004778 memset(&arg, 0, sizeof(arg));
4779 ath10k_wmi_start_scan_init(ar, &arg);
4780 arg.vdev_id = arvif->vdev_id;
4781 arg.scan_id = ATH10K_SCAN_ID;
4782 arg.n_channels = 1;
4783 arg.channels[0] = chan->center_freq;
4784 arg.dwell_time_active = duration;
4785 arg.dwell_time_passive = duration;
4786 arg.max_scan_time = 2 * duration;
4787 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4788 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4789
4790 ret = ath10k_start_scan(ar, &arg);
4791 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004792 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004793 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004794 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004795 spin_unlock_bh(&ar->data_lock);
4796 goto exit;
4797 }
4798
4799 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4800 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004801 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004802
4803 ret = ath10k_scan_stop(ar);
4804 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004805 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004806
Kalle Valo5e3dd152013-06-12 20:52:10 +03004807 ret = -ETIMEDOUT;
4808 goto exit;
4809 }
4810
4811 ret = 0;
4812exit:
4813 mutex_unlock(&ar->conf_mutex);
4814 return ret;
4815}
4816
4817static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4818{
4819 struct ath10k *ar = hw->priv;
4820
4821 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004822 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004823 mutex_unlock(&ar->conf_mutex);
4824
Michal Kazior4eb2e162014-10-28 10:23:09 +01004825 cancel_delayed_work_sync(&ar->scan.timeout);
4826
Kalle Valo5e3dd152013-06-12 20:52:10 +03004827 return 0;
4828}
4829
4830/*
4831 * Both RTS and Fragmentation threshold are interface-specific
4832 * in ath10k, but device-specific in mac80211.
4833 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004834
4835static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4836{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004837 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004838 struct ath10k_vif *arvif;
4839 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004840
Michal Kaziorad088bf2013-10-16 15:44:46 +03004841 mutex_lock(&ar->conf_mutex);
4842 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004843 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004844 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004845
Michal Kaziorad088bf2013-10-16 15:44:46 +03004846 ret = ath10k_mac_set_rts(arvif, value);
4847 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004848 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004849 arvif->vdev_id, ret);
4850 break;
4851 }
4852 }
4853 mutex_unlock(&ar->conf_mutex);
4854
4855 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004856}
4857
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004858static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4859 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004860{
4861 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004862 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004863 int ret;
4864
4865 /* mac80211 doesn't care if we really xmit queued frames or not
4866 * we'll collect those frames either way if we stop/delete vdevs */
4867 if (drop)
4868 return;
4869
Michal Kazior548db542013-07-05 16:15:15 +03004870 mutex_lock(&ar->conf_mutex);
4871
Michal Kazioraffd3212013-07-16 09:54:35 +02004872 if (ar->state == ATH10K_STATE_WEDGED)
4873 goto skip;
4874
Michal Kazioredb82362013-07-05 16:15:14 +03004875 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004876 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004877
Michal Kazioredb82362013-07-05 16:15:14 +03004878 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004879 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004880 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004881
Michal Kazior7962b0d2014-10-28 10:34:38 +01004882 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4883 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4884 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004885
4886 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004887 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004888
4889 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004890 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004891 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004892
Michal Kazioraffd3212013-07-16 09:54:35 +02004893skip:
Michal Kazior548db542013-07-05 16:15:15 +03004894 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004895}
4896
4897/* TODO: Implement this function properly
4898 * For now it is needed to reply to Probe Requests in IBSS mode.
4899 * Propably we need this information from FW.
4900 */
4901static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4902{
4903 return 1;
4904}
4905
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004906static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4907 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004908{
4909 struct ath10k *ar = hw->priv;
4910
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004911 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4912 return;
4913
Michal Kazioraffd3212013-07-16 09:54:35 +02004914 mutex_lock(&ar->conf_mutex);
4915
4916 /* If device failed to restart it will be in a different state, e.g.
4917 * ATH10K_STATE_WEDGED */
4918 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004919 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004920 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004921 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004922 }
4923
4924 mutex_unlock(&ar->conf_mutex);
4925}
4926
Michal Kazior2e1dea42013-07-31 10:32:40 +02004927static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4928 struct survey_info *survey)
4929{
4930 struct ath10k *ar = hw->priv;
4931 struct ieee80211_supported_band *sband;
4932 struct survey_info *ar_survey = &ar->survey[idx];
4933 int ret = 0;
4934
4935 mutex_lock(&ar->conf_mutex);
4936
4937 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4938 if (sband && idx >= sband->n_channels) {
4939 idx -= sband->n_channels;
4940 sband = NULL;
4941 }
4942
4943 if (!sband)
4944 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4945
4946 if (!sband || idx >= sband->n_channels) {
4947 ret = -ENOENT;
4948 goto exit;
4949 }
4950
4951 spin_lock_bh(&ar->data_lock);
4952 memcpy(survey, ar_survey, sizeof(*survey));
4953 spin_unlock_bh(&ar->data_lock);
4954
4955 survey->channel = &sband->channels[idx];
4956
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004957 if (ar->rx_channel == survey->channel)
4958 survey->filled |= SURVEY_INFO_IN_USE;
4959
Michal Kazior2e1dea42013-07-31 10:32:40 +02004960exit:
4961 mutex_unlock(&ar->conf_mutex);
4962 return ret;
4963}
4964
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004965/* Helper table for legacy fixed_rate/bitrate_mask */
4966static const u8 cck_ofdm_rate[] = {
4967 /* CCK */
4968 3, /* 1Mbps */
4969 2, /* 2Mbps */
4970 1, /* 5.5Mbps */
4971 0, /* 11Mbps */
4972 /* OFDM */
4973 3, /* 6Mbps */
4974 7, /* 9Mbps */
4975 2, /* 12Mbps */
4976 6, /* 18Mbps */
4977 1, /* 24Mbps */
4978 5, /* 36Mbps */
4979 0, /* 48Mbps */
4980 4, /* 54Mbps */
4981};
4982
4983/* Check if only one bit set */
4984static int ath10k_check_single_mask(u32 mask)
4985{
4986 int bit;
4987
4988 bit = ffs(mask);
4989 if (!bit)
4990 return 0;
4991
4992 mask &= ~BIT(bit - 1);
4993 if (mask)
4994 return 2;
4995
4996 return 1;
4997}
4998
4999static bool
5000ath10k_default_bitrate_mask(struct ath10k *ar,
5001 enum ieee80211_band band,
5002 const struct cfg80211_bitrate_mask *mask)
5003{
5004 u32 legacy = 0x00ff;
5005 u8 ht = 0xff, i;
5006 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005007 u16 nrf = ar->num_rf_chains;
5008
5009 if (ar->cfg_tx_chainmask)
5010 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005011
5012 switch (band) {
5013 case IEEE80211_BAND_2GHZ:
5014 legacy = 0x00fff;
5015 vht = 0;
5016 break;
5017 case IEEE80211_BAND_5GHZ:
5018 break;
5019 default:
5020 return false;
5021 }
5022
5023 if (mask->control[band].legacy != legacy)
5024 return false;
5025
Ben Greearb116ea12014-11-24 16:22:10 +02005026 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005027 if (mask->control[band].ht_mcs[i] != ht)
5028 return false;
5029
Ben Greearb116ea12014-11-24 16:22:10 +02005030 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005031 if (mask->control[band].vht_mcs[i] != vht)
5032 return false;
5033
5034 return true;
5035}
5036
5037static bool
5038ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5039 enum ieee80211_band band,
5040 u8 *fixed_nss)
5041{
5042 int ht_nss = 0, vht_nss = 0, i;
5043
5044 /* check legacy */
5045 if (ath10k_check_single_mask(mask->control[band].legacy))
5046 return false;
5047
5048 /* check HT */
5049 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5050 if (mask->control[band].ht_mcs[i] == 0xff)
5051 continue;
5052 else if (mask->control[band].ht_mcs[i] == 0x00)
5053 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005054
5055 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005056 }
5057
5058 ht_nss = i;
5059
5060 /* check VHT */
5061 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5062 if (mask->control[band].vht_mcs[i] == 0x03ff)
5063 continue;
5064 else if (mask->control[band].vht_mcs[i] == 0x0000)
5065 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005066
5067 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005068 }
5069
5070 vht_nss = i;
5071
5072 if (ht_nss > 0 && vht_nss > 0)
5073 return false;
5074
5075 if (ht_nss)
5076 *fixed_nss = ht_nss;
5077 else if (vht_nss)
5078 *fixed_nss = vht_nss;
5079 else
5080 return false;
5081
5082 return true;
5083}
5084
5085static bool
5086ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5087 enum ieee80211_band band,
5088 enum wmi_rate_preamble *preamble)
5089{
5090 int legacy = 0, ht = 0, vht = 0, i;
5091
5092 *preamble = WMI_RATE_PREAMBLE_OFDM;
5093
5094 /* check legacy */
5095 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5096 if (legacy > 1)
5097 return false;
5098
5099 /* check HT */
5100 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5101 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5102 if (ht > 1)
5103 return false;
5104
5105 /* check VHT */
5106 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5107 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5108 if (vht > 1)
5109 return false;
5110
5111 /* Currently we support only one fixed_rate */
5112 if ((legacy + ht + vht) != 1)
5113 return false;
5114
5115 if (ht)
5116 *preamble = WMI_RATE_PREAMBLE_HT;
5117 else if (vht)
5118 *preamble = WMI_RATE_PREAMBLE_VHT;
5119
5120 return true;
5121}
5122
5123static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005124ath10k_bitrate_mask_rate(struct ath10k *ar,
5125 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005126 enum ieee80211_band band,
5127 u8 *fixed_rate,
5128 u8 *fixed_nss)
5129{
5130 u8 rate = 0, pream = 0, nss = 0, i;
5131 enum wmi_rate_preamble preamble;
5132
5133 /* Check if single rate correct */
5134 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5135 return false;
5136
5137 pream = preamble;
5138
5139 switch (preamble) {
5140 case WMI_RATE_PREAMBLE_CCK:
5141 case WMI_RATE_PREAMBLE_OFDM:
5142 i = ffs(mask->control[band].legacy) - 1;
5143
5144 if (band == IEEE80211_BAND_2GHZ && i < 4)
5145 pream = WMI_RATE_PREAMBLE_CCK;
5146
5147 if (band == IEEE80211_BAND_5GHZ)
5148 i += 4;
5149
5150 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5151 return false;
5152
5153 rate = cck_ofdm_rate[i];
5154 break;
5155 case WMI_RATE_PREAMBLE_HT:
5156 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5157 if (mask->control[band].ht_mcs[i])
5158 break;
5159
5160 if (i == IEEE80211_HT_MCS_MASK_LEN)
5161 return false;
5162
5163 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5164 nss = i;
5165 break;
5166 case WMI_RATE_PREAMBLE_VHT:
5167 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5168 if (mask->control[band].vht_mcs[i])
5169 break;
5170
5171 if (i == NL80211_VHT_NSS_MAX)
5172 return false;
5173
5174 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5175 nss = i;
5176 break;
5177 }
5178
5179 *fixed_nss = nss + 1;
5180 nss <<= 4;
5181 pream <<= 6;
5182
Michal Kazior7aa7a722014-08-25 12:09:38 +02005183 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 +01005184 pream, nss, rate);
5185
5186 *fixed_rate = pream | nss | rate;
5187
5188 return true;
5189}
5190
Michal Kazior7aa7a722014-08-25 12:09:38 +02005191static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5192 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005193 enum ieee80211_band band,
5194 u8 *fixed_rate,
5195 u8 *fixed_nss)
5196{
5197 /* First check full NSS mask, if we can simply limit NSS */
5198 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5199 return true;
5200
5201 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005202 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005203}
5204
5205static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5206 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005207 u8 fixed_nss,
5208 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005209{
5210 struct ath10k *ar = arvif->ar;
5211 u32 vdev_param;
5212 int ret = 0;
5213
5214 mutex_lock(&ar->conf_mutex);
5215
5216 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005217 arvif->fixed_nss == fixed_nss &&
5218 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005219 goto exit;
5220
5221 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005222 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005223
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005224 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005225 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005226
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005227 vdev_param = ar->wmi.vdev_param->fixed_rate;
5228 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5229 vdev_param, fixed_rate);
5230 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005231 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005232 fixed_rate, ret);
5233 ret = -EINVAL;
5234 goto exit;
5235 }
5236
5237 arvif->fixed_rate = fixed_rate;
5238
5239 vdev_param = ar->wmi.vdev_param->nss;
5240 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5241 vdev_param, fixed_nss);
5242
5243 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005244 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005245 fixed_nss, ret);
5246 ret = -EINVAL;
5247 goto exit;
5248 }
5249
5250 arvif->fixed_nss = fixed_nss;
5251
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005252 vdev_param = ar->wmi.vdev_param->sgi;
5253 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5254 force_sgi);
5255
5256 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005257 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005258 force_sgi, ret);
5259 ret = -EINVAL;
5260 goto exit;
5261 }
5262
5263 arvif->force_sgi = force_sgi;
5264
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005265exit:
5266 mutex_unlock(&ar->conf_mutex);
5267 return ret;
5268}
5269
5270static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5271 struct ieee80211_vif *vif,
5272 const struct cfg80211_bitrate_mask *mask)
5273{
5274 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5275 struct ath10k *ar = arvif->ar;
5276 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5277 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5278 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005279 u8 force_sgi;
5280
Ben Greearb116ea12014-11-24 16:22:10 +02005281 if (ar->cfg_tx_chainmask)
5282 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5283
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005284 force_sgi = mask->control[band].gi;
5285 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5286 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005287
5288 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005289 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005290 &fixed_rate,
5291 &fixed_nss))
5292 return -EINVAL;
5293 }
5294
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005295 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005296 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005297 return -EINVAL;
5298 }
5299
5300 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5301 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005302}
5303
Michal Kazior9797feb2014-02-14 14:49:48 +01005304static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5305 struct ieee80211_vif *vif,
5306 struct ieee80211_sta *sta,
5307 u32 changed)
5308{
5309 struct ath10k *ar = hw->priv;
5310 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5311 u32 bw, smps;
5312
5313 spin_lock_bh(&ar->data_lock);
5314
Michal Kazior7aa7a722014-08-25 12:09:38 +02005315 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005316 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5317 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5318 sta->smps_mode);
5319
5320 if (changed & IEEE80211_RC_BW_CHANGED) {
5321 bw = WMI_PEER_CHWIDTH_20MHZ;
5322
5323 switch (sta->bandwidth) {
5324 case IEEE80211_STA_RX_BW_20:
5325 bw = WMI_PEER_CHWIDTH_20MHZ;
5326 break;
5327 case IEEE80211_STA_RX_BW_40:
5328 bw = WMI_PEER_CHWIDTH_40MHZ;
5329 break;
5330 case IEEE80211_STA_RX_BW_80:
5331 bw = WMI_PEER_CHWIDTH_80MHZ;
5332 break;
5333 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005334 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005335 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005336 bw = WMI_PEER_CHWIDTH_20MHZ;
5337 break;
5338 }
5339
5340 arsta->bw = bw;
5341 }
5342
5343 if (changed & IEEE80211_RC_NSS_CHANGED)
5344 arsta->nss = sta->rx_nss;
5345
5346 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5347 smps = WMI_PEER_SMPS_PS_NONE;
5348
5349 switch (sta->smps_mode) {
5350 case IEEE80211_SMPS_AUTOMATIC:
5351 case IEEE80211_SMPS_OFF:
5352 smps = WMI_PEER_SMPS_PS_NONE;
5353 break;
5354 case IEEE80211_SMPS_STATIC:
5355 smps = WMI_PEER_SMPS_STATIC;
5356 break;
5357 case IEEE80211_SMPS_DYNAMIC:
5358 smps = WMI_PEER_SMPS_DYNAMIC;
5359 break;
5360 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005361 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005362 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005363 smps = WMI_PEER_SMPS_PS_NONE;
5364 break;
5365 }
5366
5367 arsta->smps = smps;
5368 }
5369
Michal Kazior9797feb2014-02-14 14:49:48 +01005370 arsta->changed |= changed;
5371
5372 spin_unlock_bh(&ar->data_lock);
5373
5374 ieee80211_queue_work(hw, &arsta->update_wk);
5375}
5376
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005377static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5378{
5379 /*
5380 * FIXME: Return 0 for time being. Need to figure out whether FW
5381 * has the API to fetch 64-bit local TSF
5382 */
5383
5384 return 0;
5385}
5386
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005387static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5388 struct ieee80211_vif *vif,
5389 enum ieee80211_ampdu_mlme_action action,
5390 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5391 u8 buf_size)
5392{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005393 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005394 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5395
Michal Kazior7aa7a722014-08-25 12:09:38 +02005396 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 +02005397 arvif->vdev_id, sta->addr, tid, action);
5398
5399 switch (action) {
5400 case IEEE80211_AMPDU_RX_START:
5401 case IEEE80211_AMPDU_RX_STOP:
5402 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5403 * creation/removal. Do we need to verify this?
5404 */
5405 return 0;
5406 case IEEE80211_AMPDU_TX_START:
5407 case IEEE80211_AMPDU_TX_STOP_CONT:
5408 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5409 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5410 case IEEE80211_AMPDU_TX_OPERATIONAL:
5411 /* Firmware offloads Tx aggregation entirely so deny mac80211
5412 * Tx aggregation requests.
5413 */
5414 return -EOPNOTSUPP;
5415 }
5416
5417 return -EINVAL;
5418}
5419
Kalle Valo5e3dd152013-06-12 20:52:10 +03005420static const struct ieee80211_ops ath10k_ops = {
5421 .tx = ath10k_tx,
5422 .start = ath10k_start,
5423 .stop = ath10k_stop,
5424 .config = ath10k_config,
5425 .add_interface = ath10k_add_interface,
5426 .remove_interface = ath10k_remove_interface,
5427 .configure_filter = ath10k_configure_filter,
5428 .bss_info_changed = ath10k_bss_info_changed,
5429 .hw_scan = ath10k_hw_scan,
5430 .cancel_hw_scan = ath10k_cancel_hw_scan,
5431 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005432 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005433 .sta_state = ath10k_sta_state,
5434 .conf_tx = ath10k_conf_tx,
5435 .remain_on_channel = ath10k_remain_on_channel,
5436 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5437 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438 .flush = ath10k_flush,
5439 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03005440 .set_antenna = ath10k_set_antenna,
5441 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005442 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005443 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005444 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005445 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005446 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005447 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005448 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5449 .get_et_stats = ath10k_debug_get_et_stats,
5450 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005451
5452 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5453
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005454#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005455 .suspend = ath10k_wow_op_suspend,
5456 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005457#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005458#ifdef CONFIG_MAC80211_DEBUGFS
5459 .sta_add_debugfs = ath10k_sta_add_debugfs,
5460#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005461};
5462
5463#define RATETAB_ENT(_rate, _rateid, _flags) { \
5464 .bitrate = (_rate), \
5465 .flags = (_flags), \
5466 .hw_value = (_rateid), \
5467}
5468
5469#define CHAN2G(_channel, _freq, _flags) { \
5470 .band = IEEE80211_BAND_2GHZ, \
5471 .hw_value = (_channel), \
5472 .center_freq = (_freq), \
5473 .flags = (_flags), \
5474 .max_antenna_gain = 0, \
5475 .max_power = 30, \
5476}
5477
5478#define CHAN5G(_channel, _freq, _flags) { \
5479 .band = IEEE80211_BAND_5GHZ, \
5480 .hw_value = (_channel), \
5481 .center_freq = (_freq), \
5482 .flags = (_flags), \
5483 .max_antenna_gain = 0, \
5484 .max_power = 30, \
5485}
5486
5487static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5488 CHAN2G(1, 2412, 0),
5489 CHAN2G(2, 2417, 0),
5490 CHAN2G(3, 2422, 0),
5491 CHAN2G(4, 2427, 0),
5492 CHAN2G(5, 2432, 0),
5493 CHAN2G(6, 2437, 0),
5494 CHAN2G(7, 2442, 0),
5495 CHAN2G(8, 2447, 0),
5496 CHAN2G(9, 2452, 0),
5497 CHAN2G(10, 2457, 0),
5498 CHAN2G(11, 2462, 0),
5499 CHAN2G(12, 2467, 0),
5500 CHAN2G(13, 2472, 0),
5501 CHAN2G(14, 2484, 0),
5502};
5503
5504static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005505 CHAN5G(36, 5180, 0),
5506 CHAN5G(40, 5200, 0),
5507 CHAN5G(44, 5220, 0),
5508 CHAN5G(48, 5240, 0),
5509 CHAN5G(52, 5260, 0),
5510 CHAN5G(56, 5280, 0),
5511 CHAN5G(60, 5300, 0),
5512 CHAN5G(64, 5320, 0),
5513 CHAN5G(100, 5500, 0),
5514 CHAN5G(104, 5520, 0),
5515 CHAN5G(108, 5540, 0),
5516 CHAN5G(112, 5560, 0),
5517 CHAN5G(116, 5580, 0),
5518 CHAN5G(120, 5600, 0),
5519 CHAN5G(124, 5620, 0),
5520 CHAN5G(128, 5640, 0),
5521 CHAN5G(132, 5660, 0),
5522 CHAN5G(136, 5680, 0),
5523 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005524 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005525 CHAN5G(149, 5745, 0),
5526 CHAN5G(153, 5765, 0),
5527 CHAN5G(157, 5785, 0),
5528 CHAN5G(161, 5805, 0),
5529 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005530};
5531
Michal Kazior91b12082014-12-12 12:41:35 +01005532/* Note: Be careful if you re-order these. There is code which depends on this
5533 * ordering.
5534 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005535static struct ieee80211_rate ath10k_rates[] = {
5536 /* CCK */
5537 RATETAB_ENT(10, 0x82, 0),
5538 RATETAB_ENT(20, 0x84, 0),
5539 RATETAB_ENT(55, 0x8b, 0),
5540 RATETAB_ENT(110, 0x96, 0),
5541 /* OFDM */
5542 RATETAB_ENT(60, 0x0c, 0),
5543 RATETAB_ENT(90, 0x12, 0),
5544 RATETAB_ENT(120, 0x18, 0),
5545 RATETAB_ENT(180, 0x24, 0),
5546 RATETAB_ENT(240, 0x30, 0),
5547 RATETAB_ENT(360, 0x48, 0),
5548 RATETAB_ENT(480, 0x60, 0),
5549 RATETAB_ENT(540, 0x6c, 0),
5550};
5551
5552#define ath10k_a_rates (ath10k_rates + 4)
5553#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5554#define ath10k_g_rates (ath10k_rates + 0)
5555#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5556
Michal Kaziore7b54192014-08-07 11:03:27 +02005557struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005558{
5559 struct ieee80211_hw *hw;
5560 struct ath10k *ar;
5561
Michal Kaziore7b54192014-08-07 11:03:27 +02005562 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005563 if (!hw)
5564 return NULL;
5565
5566 ar = hw->priv;
5567 ar->hw = hw;
5568
5569 return ar;
5570}
5571
5572void ath10k_mac_destroy(struct ath10k *ar)
5573{
5574 ieee80211_free_hw(ar->hw);
5575}
5576
5577static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5578 {
5579 .max = 8,
5580 .types = BIT(NL80211_IFTYPE_STATION)
5581 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005582 },
5583 {
5584 .max = 3,
5585 .types = BIT(NL80211_IFTYPE_P2P_GO)
5586 },
5587 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005588 .max = 1,
5589 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5590 },
5591 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005592 .max = 7,
5593 .types = BIT(NL80211_IFTYPE_AP)
5594 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005595};
5596
Bartosz Markowskif2595092013-12-10 16:20:39 +01005597static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005598 {
5599 .max = 8,
5600 .types = BIT(NL80211_IFTYPE_AP)
5601 },
5602};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005603
5604static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5605 {
5606 .limits = ath10k_if_limits,
5607 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5608 .max_interfaces = 8,
5609 .num_different_channels = 1,
5610 .beacon_int_infra_match = true,
5611 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005612};
5613
5614static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005615 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005616 .limits = ath10k_10x_if_limits,
5617 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005618 .max_interfaces = 8,
5619 .num_different_channels = 1,
5620 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005621#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005622 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5623 BIT(NL80211_CHAN_WIDTH_20) |
5624 BIT(NL80211_CHAN_WIDTH_40) |
5625 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005626#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005627 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005628};
5629
5630static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5631{
5632 struct ieee80211_sta_vht_cap vht_cap = {0};
5633 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005634 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005635 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005636
5637 vht_cap.vht_supported = 1;
5638 vht_cap.cap = ar->vht_cap_info;
5639
Michal Kaziorbc657a362015-02-26 11:11:22 +01005640 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5641 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5642 val = ar->num_rf_chains - 1;
5643 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5644 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5645
5646 vht_cap.cap |= val;
5647 }
5648
5649 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5650 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5651 val = ar->num_rf_chains - 1;
5652 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5653 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5654
5655 vht_cap.cap |= val;
5656 }
5657
Michal Kazior8865bee42013-07-24 12:36:46 +02005658 mcs_map = 0;
5659 for (i = 0; i < 8; i++) {
5660 if (i < ar->num_rf_chains)
5661 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5662 else
5663 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5664 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005665
5666 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5667 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5668
5669 return vht_cap;
5670}
5671
5672static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5673{
5674 int i;
5675 struct ieee80211_sta_ht_cap ht_cap = {0};
5676
5677 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5678 return ht_cap;
5679
5680 ht_cap.ht_supported = 1;
5681 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5682 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5683 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5684 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5685 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5686
5687 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5688 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5689
5690 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5691 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5692
5693 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5694 u32 smps;
5695
5696 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5697 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5698
5699 ht_cap.cap |= smps;
5700 }
5701
5702 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5703 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5704
5705 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5706 u32 stbc;
5707
5708 stbc = ar->ht_cap_info;
5709 stbc &= WMI_HT_CAP_RX_STBC;
5710 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5711 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5712 stbc &= IEEE80211_HT_CAP_RX_STBC;
5713
5714 ht_cap.cap |= stbc;
5715 }
5716
5717 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5718 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5719
5720 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5721 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5722
5723 /* max AMSDU is implicitly taken from vht_cap_info */
5724 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5725 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5726
Michal Kazior8865bee42013-07-24 12:36:46 +02005727 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005728 ht_cap.mcs.rx_mask[i] = 0xFF;
5729
5730 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5731
5732 return ht_cap;
5733}
5734
Kalle Valo5e3dd152013-06-12 20:52:10 +03005735static void ath10k_get_arvif_iter(void *data, u8 *mac,
5736 struct ieee80211_vif *vif)
5737{
5738 struct ath10k_vif_iter *arvif_iter = data;
5739 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5740
5741 if (arvif->vdev_id == arvif_iter->vdev_id)
5742 arvif_iter->arvif = arvif;
5743}
5744
5745struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5746{
5747 struct ath10k_vif_iter arvif_iter;
5748 u32 flags;
5749
5750 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5751 arvif_iter.vdev_id = vdev_id;
5752
5753 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5754 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5755 flags,
5756 ath10k_get_arvif_iter,
5757 &arvif_iter);
5758 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005759 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005760 return NULL;
5761 }
5762
5763 return arvif_iter.arvif;
5764}
5765
5766int ath10k_mac_register(struct ath10k *ar)
5767{
Johannes Berg3cb10942015-01-22 21:38:45 +01005768 static const u32 cipher_suites[] = {
5769 WLAN_CIPHER_SUITE_WEP40,
5770 WLAN_CIPHER_SUITE_WEP104,
5771 WLAN_CIPHER_SUITE_TKIP,
5772 WLAN_CIPHER_SUITE_CCMP,
5773 WLAN_CIPHER_SUITE_AES_CMAC,
5774 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005775 struct ieee80211_supported_band *band;
5776 struct ieee80211_sta_vht_cap vht_cap;
5777 struct ieee80211_sta_ht_cap ht_cap;
5778 void *channels;
5779 int ret;
5780
5781 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5782
5783 SET_IEEE80211_DEV(ar->hw, ar->dev);
5784
5785 ht_cap = ath10k_get_ht_cap(ar);
5786 vht_cap = ath10k_create_vht_cap(ar);
5787
5788 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5789 channels = kmemdup(ath10k_2ghz_channels,
5790 sizeof(ath10k_2ghz_channels),
5791 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005792 if (!channels) {
5793 ret = -ENOMEM;
5794 goto err_free;
5795 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005796
5797 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5798 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5799 band->channels = channels;
5800 band->n_bitrates = ath10k_g_rates_size;
5801 band->bitrates = ath10k_g_rates;
5802 band->ht_cap = ht_cap;
5803
Yanbo Lid68bb122015-01-23 08:18:20 +08005804 /* Enable the VHT support at 2.4 GHz */
5805 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005806
5807 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5808 }
5809
5810 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5811 channels = kmemdup(ath10k_5ghz_channels,
5812 sizeof(ath10k_5ghz_channels),
5813 GFP_KERNEL);
5814 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005815 ret = -ENOMEM;
5816 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005817 }
5818
5819 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5820 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5821 band->channels = channels;
5822 band->n_bitrates = ath10k_a_rates_size;
5823 band->bitrates = ath10k_a_rates;
5824 band->ht_cap = ht_cap;
5825 band->vht_cap = vht_cap;
5826 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5827 }
5828
5829 ar->hw->wiphy->interface_modes =
5830 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005831 BIT(NL80211_IFTYPE_AP);
5832
Ben Greear46acf7bb2014-05-16 17:15:38 +03005833 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5834 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5835
Bartosz Markowskid3541812013-12-10 16:20:40 +01005836 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5837 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005838 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005839 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5840 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005841
5842 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5843 IEEE80211_HW_SUPPORTS_PS |
5844 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005845 IEEE80211_HW_MFP_CAPABLE |
5846 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5847 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005848 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005849 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005850 IEEE80211_HW_SW_CRYPTO_CONTROL |
5851 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005852
Eliad Peller0d8614b2014-09-10 14:07:36 +03005853 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5854
Kalle Valo5e3dd152013-06-12 20:52:10 +03005855 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005856 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005857
5858 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5859 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5860 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5861 }
5862
5863 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5864 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5865
5866 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005867 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005868
Kalle Valo5e3dd152013-06-12 20:52:10 +03005869 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5870
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005871 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5872 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5873
5874 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5875 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5876 * correct Probe Responses. This is more of a hack advert..
5877 */
5878 ar->hw->wiphy->probe_resp_offload |=
5879 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5880 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5881 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5882 }
5883
Kalle Valo5e3dd152013-06-12 20:52:10 +03005884 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005885 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005886 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5887
5888 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005889 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5890
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005891 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5892
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005893 ret = ath10k_wow_init(ar);
5894 if (ret) {
5895 ath10k_warn(ar, "failed to init wow: %d\n", ret);
5896 goto err_free;
5897 }
5898
Kalle Valo5e3dd152013-06-12 20:52:10 +03005899 /*
5900 * on LL hardware queues are managed entirely by the FW
5901 * so we only advertise to mac we can do the queues thing
5902 */
5903 ar->hw->queues = 4;
5904
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005905 switch (ar->wmi.op_version) {
5906 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5907 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005908 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5909 ar->hw->wiphy->n_iface_combinations =
5910 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005911 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005912 break;
5913 case ATH10K_FW_WMI_OP_VERSION_10_1:
5914 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005915 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005916 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5917 ar->hw->wiphy->n_iface_combinations =
5918 ARRAY_SIZE(ath10k_10x_if_comb);
5919 break;
5920 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5921 case ATH10K_FW_WMI_OP_VERSION_MAX:
5922 WARN_ON(1);
5923 ret = -EINVAL;
5924 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005925 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005926
Michal Kazior7c199992013-07-31 10:47:57 +02005927 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5928
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005929 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5930 /* Init ath dfs pattern detector */
5931 ar->ath_common.debug_mask = ATH_DBG_DFS;
5932 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5933 NL80211_DFS_UNSET);
5934
5935 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005936 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005937 }
5938
Kalle Valo5e3dd152013-06-12 20:52:10 +03005939 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5940 ath10k_reg_notifier);
5941 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005942 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005943 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005944 }
5945
Johannes Berg3cb10942015-01-22 21:38:45 +01005946 ar->hw->wiphy->cipher_suites = cipher_suites;
5947 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5948
Kalle Valo5e3dd152013-06-12 20:52:10 +03005949 ret = ieee80211_register_hw(ar->hw);
5950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005951 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005952 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005953 }
5954
5955 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5956 ret = regulatory_hint(ar->hw->wiphy,
5957 ar->ath_common.regulatory.alpha2);
5958 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005959 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005960 }
5961
5962 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005963
5964err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005965 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005966err_free:
5967 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5968 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5969
Kalle Valo5e3dd152013-06-12 20:52:10 +03005970 return ret;
5971}
5972
5973void ath10k_mac_unregister(struct ath10k *ar)
5974{
5975 ieee80211_unregister_hw(ar->hw);
5976
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005977 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5978 ar->dfs_detector->exit(ar->dfs_detector);
5979
Kalle Valo5e3dd152013-06-12 20:52:10 +03005980 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5981 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5982
5983 SET_IEEE80211_DEV(ar->hw, NULL);
5984}