blob: de7bf821e8deee8e08dee71c865d9ca6318c77db [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
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300586static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
587 struct ieee80211_sta *sta,
588 enum wmi_tdls_peer_state state)
589{
590 int ret;
591 struct wmi_tdls_peer_update_cmd_arg arg = {};
592 struct wmi_tdls_peer_capab_arg cap = {};
593 struct wmi_channel_arg chan_arg = {};
594
595 lockdep_assert_held(&ar->conf_mutex);
596
597 arg.vdev_id = vdev_id;
598 arg.peer_state = state;
599 ether_addr_copy(arg.addr, sta->addr);
600
601 cap.peer_max_sp = sta->max_sp;
602 cap.peer_uapsd_queues = sta->uapsd_queues;
603
604 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
605 !sta->tdls_initiator)
606 cap.is_peer_responder = 1;
607
608 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
609 if (ret) {
610 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
611 arg.addr, vdev_id, ret);
612 return ret;
613 }
614
615 return 0;
616}
617
Kalle Valo5e3dd152013-06-12 20:52:10 +0300618/************************/
619/* Interface management */
620/************************/
621
Michal Kazior64badcb2014-09-18 11:18:02 +0300622void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
623{
624 struct ath10k *ar = arvif->ar;
625
626 lockdep_assert_held(&ar->data_lock);
627
628 if (!arvif->beacon)
629 return;
630
631 if (!arvif->beacon_buf)
632 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
633 arvif->beacon->len, DMA_TO_DEVICE);
634
Michal Kazioraf213192015-01-29 14:29:52 +0200635 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
636 arvif->beacon_state != ATH10K_BEACON_SENT))
637 return;
638
Michal Kazior64badcb2014-09-18 11:18:02 +0300639 dev_kfree_skb_any(arvif->beacon);
640
641 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200642 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300643}
644
645static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
646{
647 struct ath10k *ar = arvif->ar;
648
649 lockdep_assert_held(&ar->data_lock);
650
651 ath10k_mac_vif_beacon_free(arvif);
652
653 if (arvif->beacon_buf) {
654 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
655 arvif->beacon_buf, arvif->beacon_paddr);
656 arvif->beacon_buf = NULL;
657 }
658}
659
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
661{
662 int ret;
663
Michal Kazior548db542013-07-05 16:15:15 +0300664 lockdep_assert_held(&ar->conf_mutex);
665
Michal Kazior7962b0d2014-10-28 10:34:38 +0100666 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
667 return -ESHUTDOWN;
668
Kalle Valo5e3dd152013-06-12 20:52:10 +0300669 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
670 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
671 if (ret == 0)
672 return -ETIMEDOUT;
673
674 return 0;
675}
676
Michal Kazior1bbc0972014-04-08 09:45:47 +0300677static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300678{
Michal Kaziorc930f742014-01-23 11:38:25 +0100679 struct cfg80211_chan_def *chandef = &ar->chandef;
680 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300681 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682 int ret = 0;
683
684 lockdep_assert_held(&ar->conf_mutex);
685
Kalle Valo5e3dd152013-06-12 20:52:10 +0300686 arg.vdev_id = vdev_id;
687 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100688 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689
690 /* TODO setup this dynamically, what in case we
691 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100692 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200693 arg.channel.chan_radar =
694 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695
Michal Kazior89c5c842013-10-23 04:02:13 -0700696 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700697 arg.channel.max_power = channel->max_power * 2;
698 arg.channel.max_reg_power = channel->max_reg_power * 2;
699 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300700
Michal Kazior7962b0d2014-10-28 10:34:38 +0100701 reinit_completion(&ar->vdev_setup_done);
702
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 ret = ath10k_wmi_vdev_start(ar, &arg);
704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200705 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200706 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707 return ret;
708 }
709
710 ret = ath10k_vdev_setup_sync(ar);
711 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200712 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200713 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300714 return ret;
715 }
716
717 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
718 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200719 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200720 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300721 goto vdev_stop;
722 }
723
724 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300725
Michal Kazior7aa7a722014-08-25 12:09:38 +0200726 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300727 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728 return 0;
729
730vdev_stop:
731 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
732 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200733 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200734 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300735
736 return ret;
737}
738
Michal Kazior1bbc0972014-04-08 09:45:47 +0300739static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300740{
741 int ret = 0;
742
743 lockdep_assert_held(&ar->conf_mutex);
744
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200745 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
746 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200747 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200748 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300749
Michal Kazior7962b0d2014-10-28 10:34:38 +0100750 reinit_completion(&ar->vdev_setup_done);
751
Kalle Valo5e3dd152013-06-12 20:52:10 +0300752 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
753 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200754 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200755 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300756
757 ret = ath10k_vdev_setup_sync(ar);
758 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200759 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200760 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300761
Michal Kazior7aa7a722014-08-25 12:09:38 +0200762 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300763 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300764 return ret;
765}
766
Michal Kazior1bbc0972014-04-08 09:45:47 +0300767static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300768{
769 int bit, ret = 0;
770
771 lockdep_assert_held(&ar->conf_mutex);
772
Ben Greeara9aefb32014-08-12 11:02:19 +0300773 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200774 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300775 return -ENOMEM;
776 }
777
Ben Greear16c11172014-09-23 14:17:16 -0700778 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300779
Ben Greear16c11172014-09-23 14:17:16 -0700780 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300781
782 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
783 WMI_VDEV_TYPE_MONITOR,
784 0, ar->mac_addr);
785 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200786 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200787 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300788 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300789 }
790
Ben Greear16c11172014-09-23 14:17:16 -0700791 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200792 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300793 ar->monitor_vdev_id);
794
Kalle Valo5e3dd152013-06-12 20:52:10 +0300795 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300796}
797
Michal Kazior1bbc0972014-04-08 09:45:47 +0300798static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300799{
800 int ret = 0;
801
802 lockdep_assert_held(&ar->conf_mutex);
803
Kalle Valo5e3dd152013-06-12 20:52:10 +0300804 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
805 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200806 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200807 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300808 return ret;
809 }
810
Ben Greear16c11172014-09-23 14:17:16 -0700811 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300812
Michal Kazior7aa7a722014-08-25 12:09:38 +0200813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300814 ar->monitor_vdev_id);
815 return ret;
816}
817
Michal Kazior1bbc0972014-04-08 09:45:47 +0300818static int ath10k_monitor_start(struct ath10k *ar)
819{
820 int ret;
821
822 lockdep_assert_held(&ar->conf_mutex);
823
Michal Kazior1bbc0972014-04-08 09:45:47 +0300824 ret = ath10k_monitor_vdev_create(ar);
825 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200826 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300827 return ret;
828 }
829
830 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
831 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200832 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300833 ath10k_monitor_vdev_delete(ar);
834 return ret;
835 }
836
837 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200838 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300839
840 return 0;
841}
842
Michal Kazior19337472014-08-28 12:58:16 +0200843static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300844{
845 int ret;
846
847 lockdep_assert_held(&ar->conf_mutex);
848
Michal Kazior1bbc0972014-04-08 09:45:47 +0300849 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200850 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200851 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200852 return ret;
853 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300854
855 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200856 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200857 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200858 return ret;
859 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300860
861 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200862 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200863
864 return 0;
865}
866
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530867static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
868{
869 struct ath10k_vif *arvif;
870
871 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
872 return true;
873
874 if (!ar->num_started_vdevs)
875 return false;
876
877 list_for_each_entry(arvif, &ar->arvifs, list)
878 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
879 return false;
880
881 ath10k_dbg(ar, ATH10K_DBG_MAC,
882 "mac disabling promiscuous mode because vdev is started\n");
883 return true;
884}
885
Michal Kazior19337472014-08-28 12:58:16 +0200886static int ath10k_monitor_recalc(struct ath10k *ar)
887{
888 bool should_start;
889
890 lockdep_assert_held(&ar->conf_mutex);
891
892 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100893 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200894 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
895
896 ath10k_dbg(ar, ATH10K_DBG_MAC,
897 "mac monitor recalc started? %d should? %d\n",
898 ar->monitor_started, should_start);
899
900 if (should_start == ar->monitor_started)
901 return 0;
902
903 if (should_start)
904 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300905
906 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300907}
908
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200909static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
910{
911 struct ath10k *ar = arvif->ar;
912 u32 vdev_param, rts_cts = 0;
913
914 lockdep_assert_held(&ar->conf_mutex);
915
916 vdev_param = ar->wmi.vdev_param->enable_rtscts;
917
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200918 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200919
920 if (arvif->num_legacy_stations > 0)
921 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
922 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200923 else
924 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
925 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200926
927 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
928 rts_cts);
929}
930
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200931static int ath10k_start_cac(struct ath10k *ar)
932{
933 int ret;
934
935 lockdep_assert_held(&ar->conf_mutex);
936
937 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
938
Michal Kazior19337472014-08-28 12:58:16 +0200939 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200940 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200941 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200942 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
943 return ret;
944 }
945
Michal Kazior7aa7a722014-08-25 12:09:38 +0200946 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200947 ar->monitor_vdev_id);
948
949 return 0;
950}
951
952static int ath10k_stop_cac(struct ath10k *ar)
953{
954 lockdep_assert_held(&ar->conf_mutex);
955
956 /* CAC is not running - do nothing */
957 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
958 return 0;
959
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200960 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300961 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200962
Michal Kazior7aa7a722014-08-25 12:09:38 +0200963 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200964
965 return 0;
966}
967
Michal Kaziord6500972014-04-08 09:56:09 +0300968static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200969{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200970 int ret;
971
972 lockdep_assert_held(&ar->conf_mutex);
973
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200974 ath10k_stop_cac(ar);
975
Michal Kaziord6500972014-04-08 09:56:09 +0300976 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200977 return;
978
Michal Kaziord6500972014-04-08 09:56:09 +0300979 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200980 return;
981
982 ret = ath10k_start_cac(ar);
983 if (ret) {
984 /*
985 * Not possible to start CAC on current channel so starting
986 * radiation is not allowed, make this channel DFS_UNAVAILABLE
987 * by indicating that radar was detected.
988 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200989 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200990 ieee80211_radar_detected(ar->hw);
991 }
992}
993
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530994static int ath10k_vdev_stop(struct ath10k_vif *arvif)
995{
996 struct ath10k *ar = arvif->ar;
997 int ret;
998
999 lockdep_assert_held(&ar->conf_mutex);
1000
1001 reinit_completion(&ar->vdev_setup_done);
1002
1003 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1004 if (ret) {
1005 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1006 arvif->vdev_id, ret);
1007 return ret;
1008 }
1009
1010 ret = ath10k_vdev_setup_sync(ar);
1011 if (ret) {
1012 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1013 arvif->vdev_id, ret);
1014 return ret;
1015 }
1016
1017 WARN_ON(ar->num_started_vdevs == 0);
1018
1019 if (ar->num_started_vdevs != 0) {
1020 ar->num_started_vdevs--;
1021 ath10k_recalc_radar_detection(ar);
1022 }
1023
1024 return ret;
1025}
1026
Michal Kaziordc55e302014-07-29 12:53:36 +03001027static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001028{
1029 struct ath10k *ar = arvif->ar;
1030 struct cfg80211_chan_def *chandef = &ar->chandef;
1031 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301032 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001033
1034 lockdep_assert_held(&ar->conf_mutex);
1035
1036 reinit_completion(&ar->vdev_setup_done);
1037
1038 arg.vdev_id = arvif->vdev_id;
1039 arg.dtim_period = arvif->dtim_period;
1040 arg.bcn_intval = arvif->beacon_interval;
1041
1042 arg.channel.freq = chandef->chan->center_freq;
1043 arg.channel.band_center_freq1 = chandef->center_freq1;
1044 arg.channel.mode = chan_to_phymode(chandef);
1045
1046 arg.channel.min_power = 0;
1047 arg.channel.max_power = chandef->chan->max_power * 2;
1048 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1049 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1050
1051 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1052 arg.ssid = arvif->u.ap.ssid;
1053 arg.ssid_len = arvif->u.ap.ssid_len;
1054 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1055
1056 /* For now allow DFS for AP mode */
1057 arg.channel.chan_radar =
1058 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1059 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1060 arg.ssid = arvif->vif->bss_conf.ssid;
1061 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1062 }
1063
Michal Kazior7aa7a722014-08-25 12:09:38 +02001064 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001065 "mac vdev %d start center_freq %d phymode %s\n",
1066 arg.vdev_id, arg.channel.freq,
1067 ath10k_wmi_phymode_str(arg.channel.mode));
1068
Michal Kaziordc55e302014-07-29 12:53:36 +03001069 if (restart)
1070 ret = ath10k_wmi_vdev_restart(ar, &arg);
1071 else
1072 ret = ath10k_wmi_vdev_start(ar, &arg);
1073
Michal Kazior72654fa2014-04-08 09:56:09 +03001074 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001075 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001076 arg.vdev_id, ret);
1077 return ret;
1078 }
1079
1080 ret = ath10k_vdev_setup_sync(ar);
1081 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001082 ath10k_warn(ar,
1083 "failed to synchronize setup for vdev %i restart %d: %d\n",
1084 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001085 return ret;
1086 }
1087
Michal Kaziord6500972014-04-08 09:56:09 +03001088 ar->num_started_vdevs++;
1089 ath10k_recalc_radar_detection(ar);
1090
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301091 ret = ath10k_monitor_recalc(ar);
1092 if (ret) {
1093 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1094 arg.vdev_id, restart, ret);
1095 ret2 = ath10k_vdev_stop(arvif);
1096 if (ret2)
1097 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1098 arg.vdev_id, restart, ret2);
1099 }
1100
Michal Kazior72654fa2014-04-08 09:56:09 +03001101 return ret;
1102}
1103
Michal Kaziordc55e302014-07-29 12:53:36 +03001104static int ath10k_vdev_start(struct ath10k_vif *arvif)
1105{
1106 return ath10k_vdev_start_restart(arvif, false);
1107}
1108
1109static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1110{
1111 return ath10k_vdev_start_restart(arvif, true);
1112}
1113
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001114static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1115 struct sk_buff *bcn)
1116{
1117 struct ath10k *ar = arvif->ar;
1118 struct ieee80211_mgmt *mgmt;
1119 const u8 *p2p_ie;
1120 int ret;
1121
1122 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1123 return 0;
1124
1125 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1126 return 0;
1127
1128 mgmt = (void *)bcn->data;
1129 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1130 mgmt->u.beacon.variable,
1131 bcn->len - (mgmt->u.beacon.variable -
1132 bcn->data));
1133 if (!p2p_ie)
1134 return -ENOENT;
1135
1136 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1137 if (ret) {
1138 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1139 arvif->vdev_id, ret);
1140 return ret;
1141 }
1142
1143 return 0;
1144}
1145
1146static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1147 u8 oui_type, size_t ie_offset)
1148{
1149 size_t len;
1150 const u8 *next;
1151 const u8 *end;
1152 u8 *ie;
1153
1154 if (WARN_ON(skb->len < ie_offset))
1155 return -EINVAL;
1156
1157 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1158 skb->data + ie_offset,
1159 skb->len - ie_offset);
1160 if (!ie)
1161 return -ENOENT;
1162
1163 len = ie[1] + 2;
1164 end = skb->data + skb->len;
1165 next = ie + len;
1166
1167 if (WARN_ON(next > end))
1168 return -EINVAL;
1169
1170 memmove(ie, next, end - next);
1171 skb_trim(skb, skb->len - len);
1172
1173 return 0;
1174}
1175
1176static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1177{
1178 struct ath10k *ar = arvif->ar;
1179 struct ieee80211_hw *hw = ar->hw;
1180 struct ieee80211_vif *vif = arvif->vif;
1181 struct ieee80211_mutable_offsets offs = {};
1182 struct sk_buff *bcn;
1183 int ret;
1184
1185 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1186 return 0;
1187
Michal Kazior81a9a172015-03-05 16:02:17 +02001188 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1189 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1190 return 0;
1191
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001192 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1193 if (!bcn) {
1194 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1195 return -EPERM;
1196 }
1197
1198 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1199 if (ret) {
1200 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1201 kfree_skb(bcn);
1202 return ret;
1203 }
1204
1205 /* P2P IE is inserted by firmware automatically (as configured above)
1206 * so remove it from the base beacon template to avoid duplicate P2P
1207 * IEs in beacon frames.
1208 */
1209 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1210 offsetof(struct ieee80211_mgmt,
1211 u.beacon.variable));
1212
1213 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1214 0, NULL, 0);
1215 kfree_skb(bcn);
1216
1217 if (ret) {
1218 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1219 ret);
1220 return ret;
1221 }
1222
1223 return 0;
1224}
1225
1226static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1227{
1228 struct ath10k *ar = arvif->ar;
1229 struct ieee80211_hw *hw = ar->hw;
1230 struct ieee80211_vif *vif = arvif->vif;
1231 struct sk_buff *prb;
1232 int ret;
1233
1234 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1235 return 0;
1236
Michal Kazior81a9a172015-03-05 16:02:17 +02001237 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1238 return 0;
1239
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001240 prb = ieee80211_proberesp_get(hw, vif);
1241 if (!prb) {
1242 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1243 return -EPERM;
1244 }
1245
1246 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1247 kfree_skb(prb);
1248
1249 if (ret) {
1250 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1251 ret);
1252 return ret;
1253 }
1254
1255 return 0;
1256}
1257
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001259 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001260{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001261 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262 int ret = 0;
1263
Michal Kazior548db542013-07-05 16:15:15 +03001264 lockdep_assert_held(&arvif->ar->conf_mutex);
1265
Kalle Valo5e3dd152013-06-12 20:52:10 +03001266 if (!info->enable_beacon) {
1267 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001268
1269 arvif->is_started = false;
1270 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001271
1272 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001273 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001274 spin_unlock_bh(&arvif->ar->data_lock);
1275
Kalle Valo5e3dd152013-06-12 20:52:10 +03001276 return;
1277 }
1278
1279 arvif->tx_seq_no = 0x1000;
1280
1281 ret = ath10k_vdev_start(arvif);
1282 if (ret)
1283 return;
1284
Michal Kaziorc930f742014-01-23 11:38:25 +01001285 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001286 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001287
1288 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1289 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001290 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001291 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001292 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001293 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001294 return;
1295 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001296
1297 arvif->is_started = true;
1298 arvif->is_up = true;
1299
Michal Kazior7aa7a722014-08-25 12:09:38 +02001300 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001301}
1302
1303static void ath10k_control_ibss(struct ath10k_vif *arvif,
1304 struct ieee80211_bss_conf *info,
1305 const u8 self_peer[ETH_ALEN])
1306{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001307 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001308 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001309 int ret = 0;
1310
Michal Kazior548db542013-07-05 16:15:15 +03001311 lockdep_assert_held(&arvif->ar->conf_mutex);
1312
Kalle Valo5e3dd152013-06-12 20:52:10 +03001313 if (!info->ibss_joined) {
1314 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1315 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001316 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001317 self_peer, arvif->vdev_id, ret);
1318
Michal Kaziorc930f742014-01-23 11:38:25 +01001319 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001320 return;
1321
Michal Kaziorc930f742014-01-23 11:38:25 +01001322 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001323
1324 return;
1325 }
1326
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001327 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1328 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001329 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001330 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001331 self_peer, arvif->vdev_id, ret);
1332 return;
1333 }
1334
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001335 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1336 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001337 ATH10K_DEFAULT_ATIM);
1338 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001339 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340 arvif->vdev_id, ret);
1341}
1342
Michal Kazior9f9b5742014-12-12 12:41:36 +01001343static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1344{
1345 struct ath10k *ar = arvif->ar;
1346 u32 param;
1347 u32 value;
1348 int ret;
1349
1350 lockdep_assert_held(&arvif->ar->conf_mutex);
1351
1352 if (arvif->u.sta.uapsd)
1353 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1354 else
1355 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1356
1357 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1358 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1359 if (ret) {
1360 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1361 value, arvif->vdev_id, ret);
1362 return ret;
1363 }
1364
1365 return 0;
1366}
1367
1368static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1369{
1370 struct ath10k *ar = arvif->ar;
1371 u32 param;
1372 u32 value;
1373 int ret;
1374
1375 lockdep_assert_held(&arvif->ar->conf_mutex);
1376
1377 if (arvif->u.sta.uapsd)
1378 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1379 else
1380 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1381
1382 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1383 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1384 param, value);
1385 if (ret) {
1386 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1387 value, arvif->vdev_id, ret);
1388 return ret;
1389 }
1390
1391 return 0;
1392}
1393
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001394static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1395{
1396 struct ath10k_vif *arvif;
1397 int num = 0;
1398
1399 lockdep_assert_held(&ar->conf_mutex);
1400
1401 list_for_each_entry(arvif, &ar->arvifs, list)
1402 if (arvif->ps)
1403 num++;
1404
1405 return num;
1406}
1407
Michal Kaziorad088bf2013-10-16 15:44:46 +03001408static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001410 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001411 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001412 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 enum wmi_sta_powersave_param param;
1414 enum wmi_sta_ps_mode psmode;
1415 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001416 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001417 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001418
Michal Kazior548db542013-07-05 16:15:15 +03001419 lockdep_assert_held(&arvif->ar->conf_mutex);
1420
Michal Kaziorad088bf2013-10-16 15:44:46 +03001421 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1422 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001423
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001424 enable_ps = arvif->ps;
1425
1426 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1427 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1428 ar->fw_features)) {
1429 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1430 arvif->vdev_id);
1431 enable_ps = false;
1432 }
1433
1434 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001435 psmode = WMI_STA_PS_MODE_ENABLED;
1436 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1437
Michal Kazior526549a2014-12-12 12:41:37 +01001438 ps_timeout = conf->dynamic_ps_timeout;
1439 if (ps_timeout == 0) {
1440 /* Firmware doesn't like 0 */
1441 ps_timeout = ieee80211_tu_to_usec(
1442 vif->bss_conf.beacon_int) / 1000;
1443 }
1444
Michal Kaziorad088bf2013-10-16 15:44:46 +03001445 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001446 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001448 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001449 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001450 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001451 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452 } else {
1453 psmode = WMI_STA_PS_MODE_DISABLED;
1454 }
1455
Michal Kazior7aa7a722014-08-25 12:09:38 +02001456 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001457 arvif->vdev_id, psmode ? "enable" : "disable");
1458
Michal Kaziorad088bf2013-10-16 15:44:46 +03001459 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1460 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001461 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001462 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001463 return ret;
1464 }
1465
1466 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001467}
1468
Michal Kazior46725b152015-01-28 09:57:49 +02001469static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1470{
1471 struct ath10k *ar = arvif->ar;
1472 struct wmi_sta_keepalive_arg arg = {};
1473 int ret;
1474
1475 lockdep_assert_held(&arvif->ar->conf_mutex);
1476
1477 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1478 return 0;
1479
1480 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1481 return 0;
1482
1483 /* Some firmware revisions have a bug and ignore the `enabled` field.
1484 * Instead use the interval to disable the keepalive.
1485 */
1486 arg.vdev_id = arvif->vdev_id;
1487 arg.enabled = 1;
1488 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1489 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1490
1491 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1492 if (ret) {
1493 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1494 arvif->vdev_id, ret);
1495 return ret;
1496 }
1497
1498 return 0;
1499}
1500
Michal Kazior81a9a172015-03-05 16:02:17 +02001501static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1502{
1503 struct ath10k *ar = arvif->ar;
1504 struct ieee80211_vif *vif = arvif->vif;
1505 int ret;
1506
Michal Kazior8513d952015-03-09 14:19:24 +01001507 lockdep_assert_held(&arvif->ar->conf_mutex);
1508
1509 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1510 return;
1511
Michal Kazior81a9a172015-03-05 16:02:17 +02001512 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1513 return;
1514
1515 if (!vif->csa_active)
1516 return;
1517
1518 if (!arvif->is_up)
1519 return;
1520
1521 if (!ieee80211_csa_is_complete(vif)) {
1522 ieee80211_csa_update_counter(vif);
1523
1524 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1525 if (ret)
1526 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1527 ret);
1528
1529 ret = ath10k_mac_setup_prb_tmpl(arvif);
1530 if (ret)
1531 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1532 ret);
1533 } else {
1534 ieee80211_csa_finish(vif);
1535 }
1536}
1537
1538static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1539{
1540 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1541 ap_csa_work);
1542 struct ath10k *ar = arvif->ar;
1543
1544 mutex_lock(&ar->conf_mutex);
1545 ath10k_mac_vif_ap_csa_count_down(arvif);
1546 mutex_unlock(&ar->conf_mutex);
1547}
1548
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001549static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1550 struct ieee80211_vif *vif)
1551{
1552 struct sk_buff *skb = data;
1553 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1554 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1555
1556 if (vif->type != NL80211_IFTYPE_STATION)
1557 return;
1558
1559 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1560 return;
1561
1562 cancel_delayed_work(&arvif->connection_loss_work);
1563}
1564
1565void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1566{
1567 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1568 IEEE80211_IFACE_ITER_NORMAL,
1569 ath10k_mac_handle_beacon_iter,
1570 skb);
1571}
1572
1573static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1574 struct ieee80211_vif *vif)
1575{
1576 u32 *vdev_id = data;
1577 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1578 struct ath10k *ar = arvif->ar;
1579 struct ieee80211_hw *hw = ar->hw;
1580
1581 if (arvif->vdev_id != *vdev_id)
1582 return;
1583
1584 if (!arvif->is_up)
1585 return;
1586
1587 ieee80211_beacon_loss(vif);
1588
1589 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1590 * (done by mac80211) succeeds but beacons do not resume then it
1591 * doesn't make sense to continue operation. Queue connection loss work
1592 * which can be cancelled when beacon is received.
1593 */
1594 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1595 ATH10K_CONNECTION_LOSS_HZ);
1596}
1597
1598void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1599{
1600 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1601 IEEE80211_IFACE_ITER_NORMAL,
1602 ath10k_mac_handle_beacon_miss_iter,
1603 &vdev_id);
1604}
1605
1606static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1607{
1608 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1609 connection_loss_work.work);
1610 struct ieee80211_vif *vif = arvif->vif;
1611
1612 if (!arvif->is_up)
1613 return;
1614
1615 ieee80211_connection_loss(vif);
1616}
1617
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618/**********************/
1619/* Station management */
1620/**********************/
1621
Michal Kazior590922a2014-10-21 10:10:29 +03001622static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1623 struct ieee80211_vif *vif)
1624{
1625 /* Some firmware revisions have unstable STA powersave when listen
1626 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1627 * generate NullFunc frames properly even if buffered frames have been
1628 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1629 * buffered frames. Often pinging the device from AP would simply fail.
1630 *
1631 * As a workaround set it to 1.
1632 */
1633 if (vif->type == NL80211_IFTYPE_STATION)
1634 return 1;
1635
1636 return ar->hw->conf.listen_interval;
1637}
1638
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001640 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001641 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001642 struct wmi_peer_assoc_complete_arg *arg)
1643{
Michal Kazior590922a2014-10-21 10:10:29 +03001644 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1645
Michal Kazior548db542013-07-05 16:15:15 +03001646 lockdep_assert_held(&ar->conf_mutex);
1647
Kalle Valob25f32c2014-09-14 12:50:49 +03001648 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001649 arg->vdev_id = arvif->vdev_id;
1650 arg->peer_aid = sta->aid;
1651 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001652 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001654 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001655}
1656
1657static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001658 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001659 struct wmi_peer_assoc_complete_arg *arg)
1660{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 struct ieee80211_bss_conf *info = &vif->bss_conf;
1662 struct cfg80211_bss *bss;
1663 const u8 *rsnie = NULL;
1664 const u8 *wpaie = NULL;
1665
Michal Kazior548db542013-07-05 16:15:15 +03001666 lockdep_assert_held(&ar->conf_mutex);
1667
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001669 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1670 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 if (bss) {
1672 const struct cfg80211_bss_ies *ies;
1673
1674 rcu_read_lock();
1675 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1676
1677 ies = rcu_dereference(bss->ies);
1678
1679 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001680 WLAN_OUI_TYPE_MICROSOFT_WPA,
1681 ies->data,
1682 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683 rcu_read_unlock();
1684 cfg80211_put_bss(ar->hw->wiphy, bss);
1685 }
1686
1687 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1688 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001689 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1691 }
1692
1693 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001694 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1696 }
1697}
1698
1699static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1700 struct ieee80211_sta *sta,
1701 struct wmi_peer_assoc_complete_arg *arg)
1702{
1703 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1704 const struct ieee80211_supported_band *sband;
1705 const struct ieee80211_rate *rates;
1706 u32 ratemask;
1707 int i;
1708
Michal Kazior548db542013-07-05 16:15:15 +03001709 lockdep_assert_held(&ar->conf_mutex);
1710
Kalle Valo5e3dd152013-06-12 20:52:10 +03001711 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1712 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1713 rates = sband->bitrates;
1714
1715 rateset->num_rates = 0;
1716
1717 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1718 if (!(ratemask & 1))
1719 continue;
1720
1721 rateset->rates[rateset->num_rates] = rates->hw_value;
1722 rateset->num_rates++;
1723 }
1724}
1725
1726static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1727 struct ieee80211_sta *sta,
1728 struct wmi_peer_assoc_complete_arg *arg)
1729{
1730 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001732 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733
Michal Kazior548db542013-07-05 16:15:15 +03001734 lockdep_assert_held(&ar->conf_mutex);
1735
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 if (!ht_cap->ht_supported)
1737 return;
1738
1739 arg->peer_flags |= WMI_PEER_HT;
1740 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1741 ht_cap->ampdu_factor)) - 1;
1742
1743 arg->peer_mpdu_density =
1744 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1745
1746 arg->peer_ht_caps = ht_cap->cap;
1747 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1748
1749 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1750 arg->peer_flags |= WMI_PEER_LDPC;
1751
1752 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1753 arg->peer_flags |= WMI_PEER_40MHZ;
1754 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1755 }
1756
1757 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1758 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1759
1760 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1761 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1762
1763 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1764 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1765 arg->peer_flags |= WMI_PEER_STBC;
1766 }
1767
1768 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001769 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1770 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1771 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1772 arg->peer_rate_caps |= stbc;
1773 arg->peer_flags |= WMI_PEER_STBC;
1774 }
1775
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1777 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1778 else if (ht_cap->mcs.rx_mask[1])
1779 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1780
1781 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1782 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1783 arg->peer_ht_rates.rates[n++] = i;
1784
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001785 /*
1786 * This is a workaround for HT-enabled STAs which break the spec
1787 * and have no HT capabilities RX mask (no HT RX MCS map).
1788 *
1789 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1790 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1791 *
1792 * Firmware asserts if such situation occurs.
1793 */
1794 if (n == 0) {
1795 arg->peer_ht_rates.num_rates = 8;
1796 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1797 arg->peer_ht_rates.rates[i] = i;
1798 } else {
1799 arg->peer_ht_rates.num_rates = n;
1800 arg->peer_num_spatial_streams = sta->rx_nss;
1801 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802
Michal Kazior7aa7a722014-08-25 12:09:38 +02001803 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001804 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001805 arg->peer_ht_rates.num_rates,
1806 arg->peer_num_spatial_streams);
1807}
1808
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001809static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1810 struct ath10k_vif *arvif,
1811 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001812{
1813 u32 uapsd = 0;
1814 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001815 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816
Michal Kazior548db542013-07-05 16:15:15 +03001817 lockdep_assert_held(&ar->conf_mutex);
1818
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001821 sta->uapsd_queues, sta->max_sp);
1822
Kalle Valo5e3dd152013-06-12 20:52:10 +03001823 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1824 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1825 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1826 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1827 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1828 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1829 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1830 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1831 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1832 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1833 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1834 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1835
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1837 max_sp = sta->max_sp;
1838
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001839 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1840 sta->addr,
1841 WMI_AP_PS_PEER_PARAM_UAPSD,
1842 uapsd);
1843 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001844 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001845 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001846 return ret;
1847 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001849 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1850 sta->addr,
1851 WMI_AP_PS_PEER_PARAM_MAX_SP,
1852 max_sp);
1853 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001854 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001855 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001856 return ret;
1857 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001858
1859 /* TODO setup this based on STA listen interval and
1860 beacon interval. Currently we don't know
1861 sta->listen_interval - mac80211 patch required.
1862 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001863 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001864 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1865 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001866 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001867 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001868 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001869 return ret;
1870 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001872
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001873 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001874}
1875
1876static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1877 struct ieee80211_sta *sta,
1878 struct wmi_peer_assoc_complete_arg *arg)
1879{
1880 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001881 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001882
1883 if (!vht_cap->vht_supported)
1884 return;
1885
1886 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001887
1888 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1889 arg->peer_flags |= WMI_PEER_VHT_2G;
1890
Kalle Valo5e3dd152013-06-12 20:52:10 +03001891 arg->peer_vht_caps = vht_cap->cap;
1892
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001893 ampdu_factor = (vht_cap->cap &
1894 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1895 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1896
1897 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1898 * zero in VHT IE. Using it would result in degraded throughput.
1899 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1900 * it if VHT max_mpdu is smaller. */
1901 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1902 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1903 ampdu_factor)) - 1);
1904
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1906 arg->peer_flags |= WMI_PEER_80MHZ;
1907
1908 arg->peer_vht_rates.rx_max_rate =
1909 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1910 arg->peer_vht_rates.rx_mcs_set =
1911 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1912 arg->peer_vht_rates.tx_max_rate =
1913 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1914 arg->peer_vht_rates.tx_mcs_set =
1915 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1916
Michal Kazior7aa7a722014-08-25 12:09:38 +02001917 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001918 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001919}
1920
1921static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001922 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001923 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 struct wmi_peer_assoc_complete_arg *arg)
1925{
Michal Kazior590922a2014-10-21 10:10:29 +03001926 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1927
Kalle Valo5e3dd152013-06-12 20:52:10 +03001928 switch (arvif->vdev_type) {
1929 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001930 if (sta->wme)
1931 arg->peer_flags |= WMI_PEER_QOS;
1932
1933 if (sta->wme && sta->uapsd_queues) {
1934 arg->peer_flags |= WMI_PEER_APSD;
1935 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1936 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937 break;
1938 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001939 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001940 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001942 case WMI_VDEV_TYPE_IBSS:
1943 if (sta->wme)
1944 arg->peer_flags |= WMI_PEER_QOS;
1945 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946 default:
1947 break;
1948 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001949
1950 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1951 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952}
1953
Michal Kazior91b12082014-12-12 12:41:35 +01001954static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1955{
1956 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1957 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1958}
1959
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001961 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962 struct ieee80211_sta *sta,
1963 struct wmi_peer_assoc_complete_arg *arg)
1964{
1965 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1966
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 switch (ar->hw->conf.chandef.chan->band) {
1968 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001969 if (sta->vht_cap.vht_supported) {
1970 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1971 phymode = MODE_11AC_VHT40;
1972 else
1973 phymode = MODE_11AC_VHT20;
1974 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001975 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1976 phymode = MODE_11NG_HT40;
1977 else
1978 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001979 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001981 } else {
1982 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001983 }
1984
1985 break;
1986 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001987 /*
1988 * Check VHT first.
1989 */
1990 if (sta->vht_cap.vht_supported) {
1991 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1992 phymode = MODE_11AC_VHT80;
1993 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1994 phymode = MODE_11AC_VHT40;
1995 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1996 phymode = MODE_11AC_VHT20;
1997 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1999 phymode = MODE_11NA_HT40;
2000 else
2001 phymode = MODE_11NA_HT20;
2002 } else {
2003 phymode = MODE_11A;
2004 }
2005
2006 break;
2007 default:
2008 break;
2009 }
2010
Michal Kazior7aa7a722014-08-25 12:09:38 +02002011 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002012 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002013
Kalle Valo5e3dd152013-06-12 20:52:10 +03002014 arg->peer_phymode = phymode;
2015 WARN_ON(phymode == MODE_UNKNOWN);
2016}
2017
Kalle Valob9ada652013-10-16 15:44:46 +03002018static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002019 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002020 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002021 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002022{
Michal Kazior548db542013-07-05 16:15:15 +03002023 lockdep_assert_held(&ar->conf_mutex);
2024
Kalle Valob9ada652013-10-16 15:44:46 +03002025 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026
Michal Kazior590922a2014-10-21 10:10:29 +03002027 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2028 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002029 ath10k_peer_assoc_h_rates(ar, sta, arg);
2030 ath10k_peer_assoc_h_ht(ar, sta, arg);
2031 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002032 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2033 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002034
Kalle Valob9ada652013-10-16 15:44:46 +03002035 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036}
2037
Michal Kazior90046f52014-02-14 14:45:51 +01002038static const u32 ath10k_smps_map[] = {
2039 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2040 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2041 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2042 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2043};
2044
2045static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2046 const u8 *addr,
2047 const struct ieee80211_sta_ht_cap *ht_cap)
2048{
2049 int smps;
2050
2051 if (!ht_cap->ht_supported)
2052 return 0;
2053
2054 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2055 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2056
2057 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2058 return -EINVAL;
2059
2060 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2061 WMI_PEER_SMPS_STATE,
2062 ath10k_smps_map[smps]);
2063}
2064
Michal Kazior139e1702015-02-15 16:50:42 +02002065static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2066 struct ieee80211_vif *vif,
2067 struct ieee80211_sta_vht_cap vht_cap)
2068{
2069 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2070 int ret;
2071 u32 param;
2072 u32 value;
2073
2074 if (!(ar->vht_cap_info &
2075 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2076 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2077 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2078 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2079 return 0;
2080
2081 param = ar->wmi.vdev_param->txbf;
2082 value = 0;
2083
2084 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2085 return 0;
2086
2087 /* The following logic is correct. If a remote STA advertises support
2088 * for being a beamformer then we should enable us being a beamformee.
2089 */
2090
2091 if (ar->vht_cap_info &
2092 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2093 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2094 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2095 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2096
2097 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2098 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2099 }
2100
2101 if (ar->vht_cap_info &
2102 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2103 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2104 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2105 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2106
2107 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2108 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2109 }
2110
2111 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2112 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2113
2114 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2115 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2116
2117 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2118 if (ret) {
2119 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2120 value, ret);
2121 return ret;
2122 }
2123
2124 return 0;
2125}
2126
Kalle Valo5e3dd152013-06-12 20:52:10 +03002127/* can be called only in mac80211 callbacks due to `key_count` usage */
2128static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2129 struct ieee80211_vif *vif,
2130 struct ieee80211_bss_conf *bss_conf)
2131{
2132 struct ath10k *ar = hw->priv;
2133 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002134 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002135 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002136 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137 struct ieee80211_sta *ap_sta;
2138 int ret;
2139
Michal Kazior548db542013-07-05 16:15:15 +03002140 lockdep_assert_held(&ar->conf_mutex);
2141
Michal Kazior077efc82014-10-21 10:10:29 +03002142 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2143 arvif->vdev_id, arvif->bssid, arvif->aid);
2144
Kalle Valo5e3dd152013-06-12 20:52:10 +03002145 rcu_read_lock();
2146
2147 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2148 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002149 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002150 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002151 rcu_read_unlock();
2152 return;
2153 }
2154
Michal Kazior90046f52014-02-14 14:45:51 +01002155 /* ap_sta must be accessed only within rcu section which must be left
2156 * before calling ath10k_setup_peer_smps() which might sleep. */
2157 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002158 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002159
Michal Kazior590922a2014-10-21 10:10:29 +03002160 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002161 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002162 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002163 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002164 rcu_read_unlock();
2165 return;
2166 }
2167
2168 rcu_read_unlock();
2169
Kalle Valob9ada652013-10-16 15:44:46 +03002170 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2171 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002172 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002173 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002174 return;
2175 }
2176
Michal Kazior90046f52014-02-14 14:45:51 +01002177 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2178 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002179 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002180 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002181 return;
2182 }
2183
Michal Kazior139e1702015-02-15 16:50:42 +02002184 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2185 if (ret) {
2186 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2187 arvif->vdev_id, bss_conf->bssid, ret);
2188 return;
2189 }
2190
Michal Kazior7aa7a722014-08-25 12:09:38 +02002191 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002192 "mac vdev %d up (associated) bssid %pM aid %d\n",
2193 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2194
Michal Kazior077efc82014-10-21 10:10:29 +03002195 WARN_ON(arvif->is_up);
2196
Michal Kaziorc930f742014-01-23 11:38:25 +01002197 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002198 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002199
2200 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2201 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002202 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002204 return;
2205 }
2206
2207 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002208
2209 /* Workaround: Some firmware revisions (tested with qca6174
2210 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2211 * poked with peer param command.
2212 */
2213 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2214 WMI_PEER_DUMMY_VAR, 1);
2215 if (ret) {
2216 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2217 arvif->bssid, arvif->vdev_id, ret);
2218 return;
2219 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002220}
2221
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2223 struct ieee80211_vif *vif)
2224{
2225 struct ath10k *ar = hw->priv;
2226 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002227 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002228 int ret;
2229
Michal Kazior548db542013-07-05 16:15:15 +03002230 lockdep_assert_held(&ar->conf_mutex);
2231
Michal Kazior077efc82014-10-21 10:10:29 +03002232 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2233 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002234
Kalle Valo5e3dd152013-06-12 20:52:10 +03002235 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002236 if (ret)
2237 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2238 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002239
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002240 arvif->def_wep_key_idx = -1;
2241
Michal Kazior139e1702015-02-15 16:50:42 +02002242 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2243 if (ret) {
2244 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2245 arvif->vdev_id, ret);
2246 return;
2247 }
2248
Michal Kaziorc930f742014-01-23 11:38:25 +01002249 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002250
2251 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002252}
2253
Michal Kazior590922a2014-10-21 10:10:29 +03002254static int ath10k_station_assoc(struct ath10k *ar,
2255 struct ieee80211_vif *vif,
2256 struct ieee80211_sta *sta,
2257 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002258{
Michal Kazior590922a2014-10-21 10:10:29 +03002259 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002260 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 int ret = 0;
2262
Michal Kazior548db542013-07-05 16:15:15 +03002263 lockdep_assert_held(&ar->conf_mutex);
2264
Michal Kazior590922a2014-10-21 10:10:29 +03002265 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002266 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002267 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002268 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002269 return ret;
2270 }
2271
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002272 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002273 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2274 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002275 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002276 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002277 return ret;
2278 }
2279
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002280 /* Re-assoc is run only to update supported rates for given station. It
2281 * doesn't make much sense to reconfigure the peer completely.
2282 */
2283 if (!reassoc) {
2284 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2285 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002286 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002287 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002288 arvif->vdev_id, ret);
2289 return ret;
2290 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002291
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002292 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2293 if (ret) {
2294 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2295 sta->addr, arvif->vdev_id, ret);
2296 return ret;
2297 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002298
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002299 if (!sta->wme) {
2300 arvif->num_legacy_stations++;
2301 ret = ath10k_recalc_rtscts_prot(arvif);
2302 if (ret) {
2303 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2304 arvif->vdev_id, ret);
2305 return ret;
2306 }
2307 }
2308
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002309 /* Plumb cached keys only for static WEP */
2310 if (arvif->def_wep_key_idx != -1) {
2311 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2312 if (ret) {
2313 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2314 arvif->vdev_id, ret);
2315 return ret;
2316 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317 }
2318 }
2319
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320 return ret;
2321}
2322
Michal Kazior590922a2014-10-21 10:10:29 +03002323static int ath10k_station_disassoc(struct ath10k *ar,
2324 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325 struct ieee80211_sta *sta)
2326{
Michal Kazior590922a2014-10-21 10:10:29 +03002327 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002328 int ret = 0;
2329
2330 lockdep_assert_held(&ar->conf_mutex);
2331
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002332 if (!sta->wme) {
2333 arvif->num_legacy_stations--;
2334 ret = ath10k_recalc_rtscts_prot(arvif);
2335 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002336 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002337 arvif->vdev_id, ret);
2338 return ret;
2339 }
2340 }
2341
Kalle Valo5e3dd152013-06-12 20:52:10 +03002342 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2343 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002344 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002345 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 return ret;
2347 }
2348
2349 return ret;
2350}
2351
2352/**************/
2353/* Regulatory */
2354/**************/
2355
2356static int ath10k_update_channel_list(struct ath10k *ar)
2357{
2358 struct ieee80211_hw *hw = ar->hw;
2359 struct ieee80211_supported_band **bands;
2360 enum ieee80211_band band;
2361 struct ieee80211_channel *channel;
2362 struct wmi_scan_chan_list_arg arg = {0};
2363 struct wmi_channel_arg *ch;
2364 bool passive;
2365 int len;
2366 int ret;
2367 int i;
2368
Michal Kazior548db542013-07-05 16:15:15 +03002369 lockdep_assert_held(&ar->conf_mutex);
2370
Kalle Valo5e3dd152013-06-12 20:52:10 +03002371 bands = hw->wiphy->bands;
2372 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2373 if (!bands[band])
2374 continue;
2375
2376 for (i = 0; i < bands[band]->n_channels; i++) {
2377 if (bands[band]->channels[i].flags &
2378 IEEE80211_CHAN_DISABLED)
2379 continue;
2380
2381 arg.n_channels++;
2382 }
2383 }
2384
2385 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2386 arg.channels = kzalloc(len, GFP_KERNEL);
2387 if (!arg.channels)
2388 return -ENOMEM;
2389
2390 ch = arg.channels;
2391 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2392 if (!bands[band])
2393 continue;
2394
2395 for (i = 0; i < bands[band]->n_channels; i++) {
2396 channel = &bands[band]->channels[i];
2397
2398 if (channel->flags & IEEE80211_CHAN_DISABLED)
2399 continue;
2400
2401 ch->allow_ht = true;
2402
2403 /* FIXME: when should we really allow VHT? */
2404 ch->allow_vht = true;
2405
2406 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002407 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408
2409 ch->ht40plus =
2410 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2411
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002412 ch->chan_radar =
2413 !!(channel->flags & IEEE80211_CHAN_RADAR);
2414
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002415 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002416 ch->passive = passive;
2417
2418 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002419 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002420 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002421 ch->max_power = channel->max_power * 2;
2422 ch->max_reg_power = channel->max_reg_power * 2;
2423 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002424 ch->reg_class_id = 0; /* FIXME */
2425
2426 /* FIXME: why use only legacy modes, why not any
2427 * HT/VHT modes? Would that even make any
2428 * difference? */
2429 if (channel->band == IEEE80211_BAND_2GHZ)
2430 ch->mode = MODE_11G;
2431 else
2432 ch->mode = MODE_11A;
2433
2434 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2435 continue;
2436
Michal Kazior7aa7a722014-08-25 12:09:38 +02002437 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002438 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2439 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002440 ch->freq, ch->max_power, ch->max_reg_power,
2441 ch->max_antenna_gain, ch->mode);
2442
2443 ch++;
2444 }
2445 }
2446
2447 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2448 kfree(arg.channels);
2449
2450 return ret;
2451}
2452
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002453static enum wmi_dfs_region
2454ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2455{
2456 switch (dfs_region) {
2457 case NL80211_DFS_UNSET:
2458 return WMI_UNINIT_DFS_DOMAIN;
2459 case NL80211_DFS_FCC:
2460 return WMI_FCC_DFS_DOMAIN;
2461 case NL80211_DFS_ETSI:
2462 return WMI_ETSI_DFS_DOMAIN;
2463 case NL80211_DFS_JP:
2464 return WMI_MKK4_DFS_DOMAIN;
2465 }
2466 return WMI_UNINIT_DFS_DOMAIN;
2467}
2468
Michal Kaziorf7843d72013-07-16 09:38:52 +02002469static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002470{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002471 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002473 enum wmi_dfs_region wmi_dfs_reg;
2474 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475
Michal Kaziorf7843d72013-07-16 09:38:52 +02002476 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002477
2478 ret = ath10k_update_channel_list(ar);
2479 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002480 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002481
2482 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002483
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002484 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2485 nl_dfs_reg = ar->dfs_detector->region;
2486 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2487 } else {
2488 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2489 }
2490
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491 /* Target allows setting up per-band regdomain but ath_common provides
2492 * a combined one only */
2493 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002494 regpair->reg_domain,
2495 regpair->reg_domain, /* 2ghz */
2496 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002497 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002498 regpair->reg_5ghz_ctl,
2499 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002500 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002501 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002502}
Michal Kazior548db542013-07-05 16:15:15 +03002503
Michal Kaziorf7843d72013-07-16 09:38:52 +02002504static void ath10k_reg_notifier(struct wiphy *wiphy,
2505 struct regulatory_request *request)
2506{
2507 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2508 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002509 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002510
2511 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2512
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002513 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002514 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002515 request->dfs_region);
2516 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2517 request->dfs_region);
2518 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002519 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002520 request->dfs_region);
2521 }
2522
Michal Kaziorf7843d72013-07-16 09:38:52 +02002523 mutex_lock(&ar->conf_mutex);
2524 if (ar->state == ATH10K_STATE_ON)
2525 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002526 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527}
2528
2529/***************/
2530/* TX handlers */
2531/***************/
2532
Michal Kazior42c3aa62013-10-02 11:03:38 +02002533static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2534{
2535 if (ieee80211_is_mgmt(hdr->frame_control))
2536 return HTT_DATA_TX_EXT_TID_MGMT;
2537
2538 if (!ieee80211_is_data_qos(hdr->frame_control))
2539 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2540
2541 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2542 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2543
2544 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2545}
2546
Michal Kazior2b37c292014-09-02 11:00:22 +03002547static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002548{
Michal Kazior2b37c292014-09-02 11:00:22 +03002549 if (vif)
2550 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002551
Michal Kazior1bbc0972014-04-08 09:45:47 +03002552 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002553 return ar->monitor_vdev_id;
2554
Michal Kazior7aa7a722014-08-25 12:09:38 +02002555 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002556 return 0;
2557}
2558
Michal Kaziord740d8f2015-03-30 09:51:51 +03002559static enum ath10k_hw_txrx_mode
2560ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002561 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002562{
2563 const struct ieee80211_hdr *hdr = (void *)skb->data;
2564 __le16 fc = hdr->frame_control;
2565
2566 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2567 return ATH10K_HW_TXRX_RAW;
2568
2569 if (ieee80211_is_mgmt(fc))
2570 return ATH10K_HW_TXRX_MGMT;
2571
2572 /* Workaround:
2573 *
2574 * NullFunc frames are mostly used to ping if a client or AP are still
2575 * reachable and responsive. This implies tx status reports must be
2576 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2577 * come to a conclusion that the other end disappeared and tear down
2578 * BSS connection or it can never disconnect from BSS/client (which is
2579 * the case).
2580 *
2581 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2582 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2583 * which seems to deliver correct tx reports for NullFunc frames. The
2584 * downside of using it is it ignores client powersave state so it can
2585 * end up disconnecting sleeping clients in AP mode. It should fix STA
2586 * mode though because AP don't sleep.
2587 */
2588 if (ar->htt.target_version_major < 3 &&
2589 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2590 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2591 return ATH10K_HW_TXRX_MGMT;
2592
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002593 /* Workaround:
2594 *
2595 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2596 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2597 * to work with Ethernet txmode so use it.
2598 */
2599 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2600 return ATH10K_HW_TXRX_ETHERNET;
2601
Michal Kaziord740d8f2015-03-30 09:51:51 +03002602 return ATH10K_HW_TXRX_NATIVE_WIFI;
2603}
2604
Michal Kazior4b604552014-07-21 21:03:09 +03002605/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2606 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002607 */
Michal Kazior4b604552014-07-21 21:03:09 +03002608static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002609{
2610 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002611 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002612 u8 *qos_ctl;
2613
2614 if (!ieee80211_is_data_qos(hdr->frame_control))
2615 return;
2616
2617 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002618 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2619 skb->data, (void *)qos_ctl - (void *)skb->data);
2620 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002621
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002622 /* Some firmware revisions don't handle sending QoS NullFunc well.
2623 * These frames are mainly used for CQM purposes so it doesn't really
2624 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002625 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002626 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002627 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002628 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002629
2630 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002631}
2632
Michal Kaziord740d8f2015-03-30 09:51:51 +03002633static void ath10k_tx_h_8023(struct sk_buff *skb)
2634{
2635 struct ieee80211_hdr *hdr;
2636 struct rfc1042_hdr *rfc1042;
2637 struct ethhdr *eth;
2638 size_t hdrlen;
2639 u8 da[ETH_ALEN];
2640 u8 sa[ETH_ALEN];
2641 __be16 type;
2642
2643 hdr = (void *)skb->data;
2644 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2645 rfc1042 = (void *)skb->data + hdrlen;
2646
2647 ether_addr_copy(da, ieee80211_get_DA(hdr));
2648 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2649 type = rfc1042->snap_type;
2650
2651 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2652 skb_push(skb, sizeof(*eth));
2653
2654 eth = (void *)skb->data;
2655 ether_addr_copy(eth->h_dest, da);
2656 ether_addr_copy(eth->h_source, sa);
2657 eth->h_proto = type;
2658}
2659
Michal Kazior4b604552014-07-21 21:03:09 +03002660static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2661 struct ieee80211_vif *vif,
2662 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663{
2664 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002665 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2666
2667 /* This is case only for P2P_GO */
2668 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2669 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2670 return;
2671
2672 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2673 spin_lock_bh(&ar->data_lock);
2674 if (arvif->u.ap.noa_data)
2675 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2676 GFP_ATOMIC))
2677 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2678 arvif->u.ap.noa_data,
2679 arvif->u.ap.noa_len);
2680 spin_unlock_bh(&ar->data_lock);
2681 }
2682}
2683
Michal Kazior8d6d3622014-11-24 14:58:31 +01002684static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2685{
2686 /* FIXME: Not really sure since when the behaviour changed. At some
2687 * point new firmware stopped requiring creation of peer entries for
2688 * offchannel tx (and actually creating them causes issues with wmi-htc
2689 * tx credit replenishment and reliability). Assuming it's at least 3.4
2690 * because that's when the `freq` was introduced to TX_FRM HTT command.
2691 */
2692 return !(ar->htt.target_version_major >= 3 &&
2693 ar->htt.target_version_minor >= 4);
2694}
2695
Michal Kaziord740d8f2015-03-30 09:51:51 +03002696static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002697{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002698 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002699 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700
Michal Kaziord740d8f2015-03-30 09:51:51 +03002701 spin_lock_bh(&ar->data_lock);
2702
2703 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2704 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2705 ret = -ENOSPC;
2706 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002707 }
2708
Michal Kaziord740d8f2015-03-30 09:51:51 +03002709 __skb_queue_tail(q, skb);
2710 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2711
2712unlock:
2713 spin_unlock_bh(&ar->data_lock);
2714
2715 return ret;
2716}
2717
2718static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2719{
2720 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2721 struct ath10k_htt *htt = &ar->htt;
2722 int ret = 0;
2723
2724 switch (cb->txmode) {
2725 case ATH10K_HW_TXRX_RAW:
2726 case ATH10K_HW_TXRX_NATIVE_WIFI:
2727 case ATH10K_HW_TXRX_ETHERNET:
2728 ret = ath10k_htt_tx(htt, skb);
2729 break;
2730 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002731 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002732 ar->fw_features))
2733 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2734 else if (ar->htt.target_version_major >= 3)
2735 ret = ath10k_htt_tx(htt, skb);
2736 else
2737 ret = ath10k_htt_mgmt_tx(htt, skb);
2738 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002739 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002740
2741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002742 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2743 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002744 ieee80211_free_txskb(ar->hw, skb);
2745 }
2746}
2747
2748void ath10k_offchan_tx_purge(struct ath10k *ar)
2749{
2750 struct sk_buff *skb;
2751
2752 for (;;) {
2753 skb = skb_dequeue(&ar->offchan_tx_queue);
2754 if (!skb)
2755 break;
2756
2757 ieee80211_free_txskb(ar->hw, skb);
2758 }
2759}
2760
2761void ath10k_offchan_tx_work(struct work_struct *work)
2762{
2763 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2764 struct ath10k_peer *peer;
2765 struct ieee80211_hdr *hdr;
2766 struct sk_buff *skb;
2767 const u8 *peer_addr;
2768 int vdev_id;
2769 int ret;
2770
2771 /* FW requirement: We must create a peer before FW will send out
2772 * an offchannel frame. Otherwise the frame will be stuck and
2773 * never transmitted. We delete the peer upon tx completion.
2774 * It is unlikely that a peer for offchannel tx will already be
2775 * present. However it may be in some rare cases so account for that.
2776 * Otherwise we might remove a legitimate peer and break stuff. */
2777
2778 for (;;) {
2779 skb = skb_dequeue(&ar->offchan_tx_queue);
2780 if (!skb)
2781 break;
2782
2783 mutex_lock(&ar->conf_mutex);
2784
Michal Kazior7aa7a722014-08-25 12:09:38 +02002785 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002786 skb);
2787
2788 hdr = (struct ieee80211_hdr *)skb->data;
2789 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002790 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791
2792 spin_lock_bh(&ar->data_lock);
2793 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2794 spin_unlock_bh(&ar->data_lock);
2795
2796 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002797 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002798 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002799 peer_addr, vdev_id);
2800
2801 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03002802 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
2803 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002804 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002805 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002806 peer_addr, vdev_id, ret);
2807 }
2808
2809 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002810 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002811 ar->offchan_tx_skb = skb;
2812 spin_unlock_bh(&ar->data_lock);
2813
Michal Kaziord740d8f2015-03-30 09:51:51 +03002814 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815
2816 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2817 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002818 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002819 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 skb);
2821
2822 if (!peer) {
2823 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2824 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002825 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002826 peer_addr, vdev_id, ret);
2827 }
2828
2829 mutex_unlock(&ar->conf_mutex);
2830 }
2831}
2832
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002833void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2834{
2835 struct sk_buff *skb;
2836
2837 for (;;) {
2838 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2839 if (!skb)
2840 break;
2841
2842 ieee80211_free_txskb(ar->hw, skb);
2843 }
2844}
2845
2846void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2847{
2848 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2849 struct sk_buff *skb;
2850 int ret;
2851
2852 for (;;) {
2853 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2854 if (!skb)
2855 break;
2856
2857 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002858 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002859 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002860 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002861 ieee80211_free_txskb(ar->hw, skb);
2862 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002863 }
2864}
2865
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866/************/
2867/* Scanning */
2868/************/
2869
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002870void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002871{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002872 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002874 switch (ar->scan.state) {
2875 case ATH10K_SCAN_IDLE:
2876 break;
2877 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002878 if (ar->scan.is_roc)
2879 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002880 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002881 case ATH10K_SCAN_ABORTING:
2882 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002883 ieee80211_scan_completed(ar->hw,
2884 (ar->scan.state ==
2885 ATH10K_SCAN_ABORTING));
2886 /* fall through */
2887 case ATH10K_SCAN_STARTING:
2888 ar->scan.state = ATH10K_SCAN_IDLE;
2889 ar->scan_channel = NULL;
2890 ath10k_offchan_tx_purge(ar);
2891 cancel_delayed_work(&ar->scan.timeout);
2892 complete_all(&ar->scan.completed);
2893 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002894 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002895}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002896
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002897void ath10k_scan_finish(struct ath10k *ar)
2898{
2899 spin_lock_bh(&ar->data_lock);
2900 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901 spin_unlock_bh(&ar->data_lock);
2902}
2903
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002904static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905{
2906 struct wmi_stop_scan_arg arg = {
2907 .req_id = 1, /* FIXME */
2908 .req_type = WMI_SCAN_STOP_ONE,
2909 .u.scan_id = ATH10K_SCAN_ID,
2910 };
2911 int ret;
2912
2913 lockdep_assert_held(&ar->conf_mutex);
2914
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915 ret = ath10k_wmi_stop_scan(ar, &arg);
2916 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002917 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002918 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919 }
2920
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002922 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002923 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002924 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002925 } else if (ret > 0) {
2926 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002927 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002928
2929out:
2930 /* Scan state should be updated upon scan completion but in case
2931 * firmware fails to deliver the event (for whatever reason) it is
2932 * desired to clean up scan state anyway. Firmware may have just
2933 * dropped the scan completion event delivery due to transport pipe
2934 * being overflown with data and/or it can recover on its own before
2935 * next scan request is submitted.
2936 */
2937 spin_lock_bh(&ar->data_lock);
2938 if (ar->scan.state != ATH10K_SCAN_IDLE)
2939 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002940 spin_unlock_bh(&ar->data_lock);
2941
2942 return ret;
2943}
2944
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002945static void ath10k_scan_abort(struct ath10k *ar)
2946{
2947 int ret;
2948
2949 lockdep_assert_held(&ar->conf_mutex);
2950
2951 spin_lock_bh(&ar->data_lock);
2952
2953 switch (ar->scan.state) {
2954 case ATH10K_SCAN_IDLE:
2955 /* This can happen if timeout worker kicked in and called
2956 * abortion while scan completion was being processed.
2957 */
2958 break;
2959 case ATH10K_SCAN_STARTING:
2960 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002961 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002962 ath10k_scan_state_str(ar->scan.state),
2963 ar->scan.state);
2964 break;
2965 case ATH10K_SCAN_RUNNING:
2966 ar->scan.state = ATH10K_SCAN_ABORTING;
2967 spin_unlock_bh(&ar->data_lock);
2968
2969 ret = ath10k_scan_stop(ar);
2970 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002971 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002972
2973 spin_lock_bh(&ar->data_lock);
2974 break;
2975 }
2976
2977 spin_unlock_bh(&ar->data_lock);
2978}
2979
2980void ath10k_scan_timeout_work(struct work_struct *work)
2981{
2982 struct ath10k *ar = container_of(work, struct ath10k,
2983 scan.timeout.work);
2984
2985 mutex_lock(&ar->conf_mutex);
2986 ath10k_scan_abort(ar);
2987 mutex_unlock(&ar->conf_mutex);
2988}
2989
Kalle Valo5e3dd152013-06-12 20:52:10 +03002990static int ath10k_start_scan(struct ath10k *ar,
2991 const struct wmi_start_scan_arg *arg)
2992{
2993 int ret;
2994
2995 lockdep_assert_held(&ar->conf_mutex);
2996
2997 ret = ath10k_wmi_start_scan(ar, arg);
2998 if (ret)
2999 return ret;
3000
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3002 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003003 ret = ath10k_scan_stop(ar);
3004 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003005 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003006
3007 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003008 }
3009
Ben Greear2f9eec02015-02-15 16:50:38 +02003010 /* If we failed to start the scan, return error code at
3011 * this point. This is probably due to some issue in the
3012 * firmware, but no need to wedge the driver due to that...
3013 */
3014 spin_lock_bh(&ar->data_lock);
3015 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3016 spin_unlock_bh(&ar->data_lock);
3017 return -EINVAL;
3018 }
3019 spin_unlock_bh(&ar->data_lock);
3020
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003021 /* Add a 200ms margin to account for event/command processing */
3022 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3023 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003024 return 0;
3025}
3026
3027/**********************/
3028/* mac80211 callbacks */
3029/**********************/
3030
3031static void ath10k_tx(struct ieee80211_hw *hw,
3032 struct ieee80211_tx_control *control,
3033 struct sk_buff *skb)
3034{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003035 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003036 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3037 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003038 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003039 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003040 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003041
3042 /* We should disable CCK RATE due to P2P */
3043 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003044 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045
Michal Kazior4b604552014-07-21 21:03:09 +03003046 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003047 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003048 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003049 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003050 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003051 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003052
Michal Kaziord740d8f2015-03-30 09:51:51 +03003053 switch (ATH10K_SKB_CB(skb)->txmode) {
3054 case ATH10K_HW_TXRX_MGMT:
3055 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003056 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003057 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3058 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003059 break;
3060 case ATH10K_HW_TXRX_ETHERNET:
3061 ath10k_tx_h_8023(skb);
3062 break;
3063 case ATH10K_HW_TXRX_RAW:
3064 /* FIXME: Packet injection isn't implemented. It should be
3065 * doable with firmware 10.2 on qca988x.
3066 */
3067 WARN_ON_ONCE(1);
3068 ieee80211_free_txskb(hw, skb);
3069 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003070 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003071
Kalle Valo5e3dd152013-06-12 20:52:10 +03003072 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3073 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003074 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003075 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076 spin_unlock_bh(&ar->data_lock);
3077
Michal Kazior8d6d3622014-11-24 14:58:31 +01003078 if (ath10k_mac_need_offchan_tx_work(ar)) {
3079 ATH10K_SKB_CB(skb)->htt.freq = 0;
3080 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081
Michal Kazior8d6d3622014-11-24 14:58:31 +01003082 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3083 skb);
3084
3085 skb_queue_tail(&ar->offchan_tx_queue, skb);
3086 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3087 return;
3088 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089 }
3090
Michal Kaziord740d8f2015-03-30 09:51:51 +03003091 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003092}
3093
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003094/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003095void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003096{
3097 /* make sure rcu-protected mac80211 tx path itself is drained */
3098 synchronize_net();
3099
3100 ath10k_offchan_tx_purge(ar);
3101 ath10k_mgmt_over_wmi_tx_purge(ar);
3102
3103 cancel_work_sync(&ar->offchan_tx_work);
3104 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3105}
3106
Michal Kazioraffd3212013-07-16 09:54:35 +02003107void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003108{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003109 struct ath10k_vif *arvif;
3110
Michal Kazior818bdd12013-07-16 09:38:57 +02003111 lockdep_assert_held(&ar->conf_mutex);
3112
Michal Kazior19337472014-08-28 12:58:16 +02003113 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3114 ar->filter_flags = 0;
3115 ar->monitor = false;
3116
3117 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003118 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003119
3120 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003121
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003122 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003123 ath10k_peer_cleanup_all(ar);
3124 ath10k_core_stop(ar);
3125 ath10k_hif_power_down(ar);
3126
3127 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003128 list_for_each_entry(arvif, &ar->arvifs, list)
3129 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003130 spin_unlock_bh(&ar->data_lock);
3131}
3132
Ben Greear46acf7b2014-05-16 17:15:38 +03003133static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3134{
3135 struct ath10k *ar = hw->priv;
3136
3137 mutex_lock(&ar->conf_mutex);
3138
3139 if (ar->cfg_tx_chainmask) {
3140 *tx_ant = ar->cfg_tx_chainmask;
3141 *rx_ant = ar->cfg_rx_chainmask;
3142 } else {
3143 *tx_ant = ar->supp_tx_chainmask;
3144 *rx_ant = ar->supp_rx_chainmask;
3145 }
3146
3147 mutex_unlock(&ar->conf_mutex);
3148
3149 return 0;
3150}
3151
Ben Greear5572a952014-11-24 16:22:10 +02003152static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3153{
3154 /* It is not clear that allowing gaps in chainmask
3155 * is helpful. Probably it will not do what user
3156 * is hoping for, so warn in that case.
3157 */
3158 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3159 return;
3160
3161 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3162 dbg, cm);
3163}
3164
Ben Greear46acf7b2014-05-16 17:15:38 +03003165static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3166{
3167 int ret;
3168
3169 lockdep_assert_held(&ar->conf_mutex);
3170
Ben Greear5572a952014-11-24 16:22:10 +02003171 ath10k_check_chain_mask(ar, tx_ant, "tx");
3172 ath10k_check_chain_mask(ar, rx_ant, "rx");
3173
Ben Greear46acf7b2014-05-16 17:15:38 +03003174 ar->cfg_tx_chainmask = tx_ant;
3175 ar->cfg_rx_chainmask = rx_ant;
3176
3177 if ((ar->state != ATH10K_STATE_ON) &&
3178 (ar->state != ATH10K_STATE_RESTARTED))
3179 return 0;
3180
3181 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3182 tx_ant);
3183 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003184 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003185 ret, tx_ant);
3186 return ret;
3187 }
3188
3189 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3190 rx_ant);
3191 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003192 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003193 ret, rx_ant);
3194 return ret;
3195 }
3196
3197 return 0;
3198}
3199
3200static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3201{
3202 struct ath10k *ar = hw->priv;
3203 int ret;
3204
3205 mutex_lock(&ar->conf_mutex);
3206 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3207 mutex_unlock(&ar->conf_mutex);
3208 return ret;
3209}
3210
Kalle Valo5e3dd152013-06-12 20:52:10 +03003211static int ath10k_start(struct ieee80211_hw *hw)
3212{
3213 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003214 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003215
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003216 /*
3217 * This makes sense only when restarting hw. It is harmless to call
3218 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3219 * commands will be submitted while restarting.
3220 */
3221 ath10k_drain_tx(ar);
3222
Michal Kazior548db542013-07-05 16:15:15 +03003223 mutex_lock(&ar->conf_mutex);
3224
Michal Kaziorc5058f52014-05-26 12:46:03 +03003225 switch (ar->state) {
3226 case ATH10K_STATE_OFF:
3227 ar->state = ATH10K_STATE_ON;
3228 break;
3229 case ATH10K_STATE_RESTARTING:
3230 ath10k_halt(ar);
3231 ar->state = ATH10K_STATE_RESTARTED;
3232 break;
3233 case ATH10K_STATE_ON:
3234 case ATH10K_STATE_RESTARTED:
3235 case ATH10K_STATE_WEDGED:
3236 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003237 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003238 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003239 case ATH10K_STATE_UTF:
3240 ret = -EBUSY;
3241 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003242 }
3243
3244 ret = ath10k_hif_power_up(ar);
3245 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003246 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003247 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003248 }
3249
Kalle Valo43d2a302014-09-10 18:23:30 +03003250 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003251 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003252 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003253 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003254 }
3255
Bartosz Markowski226a3392013-09-26 17:47:16 +02003256 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003257 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003258 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003259 goto err_core_stop;
3260 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003261
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003262 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003263 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003264 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003265 goto err_core_stop;
3266 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267
Ben Greear46acf7b2014-05-16 17:15:38 +03003268 if (ar->cfg_tx_chainmask)
3269 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3270 ar->cfg_rx_chainmask);
3271
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003272 /*
3273 * By default FW set ARP frames ac to voice (6). In that case ARP
3274 * exchange is not working properly for UAPSD enabled AP. ARP requests
3275 * which arrives with access category 0 are processed by network stack
3276 * and send back with access category 0, but FW changes access category
3277 * to 6. Set ARP frames access category to best effort (0) solves
3278 * this problem.
3279 */
3280
3281 ret = ath10k_wmi_pdev_set_param(ar,
3282 ar->wmi.pdev_param->arp_ac_override, 0);
3283 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003284 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003285 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003286 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003287 }
3288
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303289 ret = ath10k_wmi_pdev_set_param(ar,
3290 ar->wmi.pdev_param->ani_enable, 1);
3291 if (ret) {
3292 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3293 ret);
3294 goto err_core_stop;
3295 }
3296
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303297 ar->ani_enabled = true;
3298
Michal Kaziord6500972014-04-08 09:56:09 +03003299 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003300 ath10k_regd_update(ar);
3301
Simon Wunderlich855aed12014-08-02 09:12:54 +03003302 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303303 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003304
Michal Kaziorae254432014-05-26 12:46:02 +03003305 mutex_unlock(&ar->conf_mutex);
3306 return 0;
3307
3308err_core_stop:
3309 ath10k_core_stop(ar);
3310
3311err_power_down:
3312 ath10k_hif_power_down(ar);
3313
3314err_off:
3315 ar->state = ATH10K_STATE_OFF;
3316
3317err:
Michal Kazior548db542013-07-05 16:15:15 +03003318 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003319 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320}
3321
3322static void ath10k_stop(struct ieee80211_hw *hw)
3323{
3324 struct ath10k *ar = hw->priv;
3325
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003326 ath10k_drain_tx(ar);
3327
Michal Kazior548db542013-07-05 16:15:15 +03003328 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003329 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003330 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003331 ar->state = ATH10K_STATE_OFF;
3332 }
Michal Kazior548db542013-07-05 16:15:15 +03003333 mutex_unlock(&ar->conf_mutex);
3334
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003335 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003336 cancel_work_sync(&ar->restart_work);
3337}
3338
Michal Kaziorad088bf2013-10-16 15:44:46 +03003339static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003340{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003341 struct ath10k_vif *arvif;
3342 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003343
3344 lockdep_assert_held(&ar->conf_mutex);
3345
Michal Kaziorad088bf2013-10-16 15:44:46 +03003346 list_for_each_entry(arvif, &ar->arvifs, list) {
3347 ret = ath10k_mac_vif_setup_ps(arvif);
3348 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003349 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003350 break;
3351 }
3352 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003353
Michal Kaziorad088bf2013-10-16 15:44:46 +03003354 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003355}
3356
Michal Kaziorc930f742014-01-23 11:38:25 +01003357static const char *chandef_get_width(enum nl80211_chan_width width)
3358{
3359 switch (width) {
3360 case NL80211_CHAN_WIDTH_20_NOHT:
3361 return "20 (noht)";
3362 case NL80211_CHAN_WIDTH_20:
3363 return "20";
3364 case NL80211_CHAN_WIDTH_40:
3365 return "40";
3366 case NL80211_CHAN_WIDTH_80:
3367 return "80";
3368 case NL80211_CHAN_WIDTH_80P80:
3369 return "80+80";
3370 case NL80211_CHAN_WIDTH_160:
3371 return "160";
3372 case NL80211_CHAN_WIDTH_5:
3373 return "5";
3374 case NL80211_CHAN_WIDTH_10:
3375 return "10";
3376 }
3377 return "?";
3378}
3379
3380static void ath10k_config_chan(struct ath10k *ar)
3381{
3382 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003383 int ret;
3384
3385 lockdep_assert_held(&ar->conf_mutex);
3386
Michal Kazior7aa7a722014-08-25 12:09:38 +02003387 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003388 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3389 ar->chandef.chan->center_freq,
3390 ar->chandef.center_freq1,
3391 ar->chandef.center_freq2,
3392 chandef_get_width(ar->chandef.width));
3393
3394 /* First stop monitor interface. Some FW versions crash if there's a
3395 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003396 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003397 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003398
3399 list_for_each_entry(arvif, &ar->arvifs, list) {
3400 if (!arvif->is_started)
3401 continue;
3402
Michal Kaziordc55e302014-07-29 12:53:36 +03003403 if (!arvif->is_up)
3404 continue;
3405
Michal Kaziorc930f742014-01-23 11:38:25 +01003406 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3407 continue;
3408
Michal Kaziordc55e302014-07-29 12:53:36 +03003409 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003411 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003412 arvif->vdev_id, ret);
3413 continue;
3414 }
3415 }
3416
Michal Kaziordc55e302014-07-29 12:53:36 +03003417 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003418
3419 list_for_each_entry(arvif, &ar->arvifs, list) {
3420 if (!arvif->is_started)
3421 continue;
3422
3423 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3424 continue;
3425
Michal Kazior81a9a172015-03-05 16:02:17 +02003426 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3427 if (ret)
3428 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3429 ret);
3430
3431 ret = ath10k_mac_setup_prb_tmpl(arvif);
3432 if (ret)
3433 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3434 ret);
3435
Michal Kaziordc55e302014-07-29 12:53:36 +03003436 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003437 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003438 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003439 arvif->vdev_id, ret);
3440 continue;
3441 }
3442
3443 if (!arvif->is_up)
3444 continue;
3445
3446 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3447 arvif->bssid);
3448 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003449 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003450 arvif->vdev_id, ret);
3451 continue;
3452 }
3453 }
3454
Michal Kazior19337472014-08-28 12:58:16 +02003455 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003456}
3457
Michal Kazior7d9d5582014-10-21 10:40:15 +03003458static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3459{
3460 int ret;
3461 u32 param;
3462
3463 lockdep_assert_held(&ar->conf_mutex);
3464
3465 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3466
3467 param = ar->wmi.pdev_param->txpower_limit2g;
3468 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3469 if (ret) {
3470 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3471 txpower, ret);
3472 return ret;
3473 }
3474
3475 param = ar->wmi.pdev_param->txpower_limit5g;
3476 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3477 if (ret) {
3478 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3479 txpower, ret);
3480 return ret;
3481 }
3482
3483 return 0;
3484}
3485
3486static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3487{
3488 struct ath10k_vif *arvif;
3489 int ret, txpower = -1;
3490
3491 lockdep_assert_held(&ar->conf_mutex);
3492
3493 list_for_each_entry(arvif, &ar->arvifs, list) {
3494 WARN_ON(arvif->txpower < 0);
3495
3496 if (txpower == -1)
3497 txpower = arvif->txpower;
3498 else
3499 txpower = min(txpower, arvif->txpower);
3500 }
3501
3502 if (WARN_ON(txpower == -1))
3503 return -EINVAL;
3504
3505 ret = ath10k_mac_txpower_setup(ar, txpower);
3506 if (ret) {
3507 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3508 txpower, ret);
3509 return ret;
3510 }
3511
3512 return 0;
3513}
3514
Kalle Valo5e3dd152013-06-12 20:52:10 +03003515static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3516{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517 struct ath10k *ar = hw->priv;
3518 struct ieee80211_conf *conf = &hw->conf;
3519 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003520
3521 mutex_lock(&ar->conf_mutex);
3522
3523 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003524 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003525 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003526 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003527 conf->chandef.chan->flags,
3528 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003529
Kalle Valo5e3dd152013-06-12 20:52:10 +03003530 spin_lock_bh(&ar->data_lock);
3531 ar->rx_channel = conf->chandef.chan;
3532 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003533
Michal Kaziord6500972014-04-08 09:56:09 +03003534 ar->radar_enabled = conf->radar_enabled;
3535 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003536
3537 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3538 ar->chandef = conf->chandef;
3539 ath10k_config_chan(ar);
3540 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 }
3542
Michal Kazioraffd3212013-07-16 09:54:35 +02003543 if (changed & IEEE80211_CONF_CHANGE_PS)
3544 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003545
3546 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003547 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3548 ret = ath10k_monitor_recalc(ar);
3549 if (ret)
3550 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003551 }
3552
3553 mutex_unlock(&ar->conf_mutex);
3554 return ret;
3555}
3556
Ben Greear5572a952014-11-24 16:22:10 +02003557static u32 get_nss_from_chainmask(u16 chain_mask)
3558{
3559 if ((chain_mask & 0x15) == 0x15)
3560 return 4;
3561 else if ((chain_mask & 0x7) == 0x7)
3562 return 3;
3563 else if ((chain_mask & 0x3) == 0x3)
3564 return 2;
3565 return 1;
3566}
3567
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568/*
3569 * TODO:
3570 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3571 * because we will send mgmt frames without CCK. This requirement
3572 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3573 * in the TX packet.
3574 */
3575static int ath10k_add_interface(struct ieee80211_hw *hw,
3576 struct ieee80211_vif *vif)
3577{
3578 struct ath10k *ar = hw->priv;
3579 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3580 enum wmi_sta_powersave_param param;
3581 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003582 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003583 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003584 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003585
Johannes Berg848955c2014-11-11 12:48:42 +01003586 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3587
Kalle Valo5e3dd152013-06-12 20:52:10 +03003588 mutex_lock(&ar->conf_mutex);
3589
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003590 memset(arvif, 0, sizeof(*arvif));
3591
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592 arvif->ar = ar;
3593 arvif->vif = vif;
3594
Ben Greeare63b33f2013-10-22 14:54:14 -07003595 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003596 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003597 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3598 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003599
Ben Greeara9aefb32014-08-12 11:02:19 +03003600 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003601 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003602 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003603 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003604 }
Ben Greear16c11172014-09-23 14:17:16 -07003605 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003606
Ben Greear16c11172014-09-23 14:17:16 -07003607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3608 bit, ar->free_vdev_map);
3609
3610 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003611 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003612
Kalle Valo5e3dd152013-06-12 20:52:10 +03003613 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003614 case NL80211_IFTYPE_P2P_DEVICE:
3615 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3616 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3617 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618 case NL80211_IFTYPE_UNSPECIFIED:
3619 case NL80211_IFTYPE_STATION:
3620 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3621 if (vif->p2p)
3622 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3623 break;
3624 case NL80211_IFTYPE_ADHOC:
3625 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3626 break;
3627 case NL80211_IFTYPE_AP:
3628 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3629
3630 if (vif->p2p)
3631 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3632 break;
3633 case NL80211_IFTYPE_MONITOR:
3634 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3635 break;
3636 default:
3637 WARN_ON(1);
3638 break;
3639 }
3640
Michal Kazior64badcb2014-09-18 11:18:02 +03003641 /* Some firmware revisions don't wait for beacon tx completion before
3642 * sending another SWBA event. This could lead to hardware using old
3643 * (freed) beacon data in some cases, e.g. tx credit starvation
3644 * combined with missed TBTT. This is very very rare.
3645 *
3646 * On non-IOMMU-enabled hosts this could be a possible security issue
3647 * because hw could beacon some random data on the air. On
3648 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3649 * device would crash.
3650 *
3651 * Since there are no beacon tx completions (implicit nor explicit)
3652 * propagated to host the only workaround for this is to allocate a
3653 * DMA-coherent buffer for a lifetime of a vif and use it for all
3654 * beacon tx commands. Worst case for this approach is some beacons may
3655 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3656 */
3657 if (vif->type == NL80211_IFTYPE_ADHOC ||
3658 vif->type == NL80211_IFTYPE_AP) {
3659 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3660 IEEE80211_MAX_FRAME_LEN,
3661 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303662 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003663 if (!arvif->beacon_buf) {
3664 ret = -ENOMEM;
3665 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3666 ret);
3667 goto err;
3668 }
3669 }
3670
3671 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3672 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3673 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003674
3675 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3676 arvif->vdev_subtype, vif->addr);
3677 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003678 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003679 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003680 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003681 }
3682
Ben Greear16c11172014-09-23 14:17:16 -07003683 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003684 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003685
Michal Kazior46725b152015-01-28 09:57:49 +02003686 /* It makes no sense to have firmware do keepalives. mac80211 already
3687 * takes care of this with idle connection polling.
3688 */
3689 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003690 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003691 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003692 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003693 goto err_vdev_delete;
3694 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003695
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003696 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003697
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003698 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3699 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003701 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003702 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003703 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003704 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003705 goto err_vdev_delete;
3706 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707
Ben Greear5572a952014-11-24 16:22:10 +02003708 if (ar->cfg_tx_chainmask) {
3709 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3710
3711 vdev_param = ar->wmi.vdev_param->nss;
3712 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3713 nss);
3714 if (ret) {
3715 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3716 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3717 ret);
3718 goto err_vdev_delete;
3719 }
3720 }
3721
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003723 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
3724 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003725 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003726 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003727 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003728 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003729 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003730
Kalle Valo5a13e762014-01-20 11:01:46 +02003731 ret = ath10k_mac_set_kickout(arvif);
3732 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003733 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003734 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003735 goto err_peer_delete;
3736 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003737 }
3738
3739 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3740 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3741 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3742 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3743 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003745 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003746 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003747 goto err_peer_delete;
3748 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003749
Michal Kazior9f9b5742014-12-12 12:41:36 +01003750 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003751 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003752 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003753 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003754 goto err_peer_delete;
3755 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003756
Michal Kazior9f9b5742014-12-12 12:41:36 +01003757 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003758 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003759 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003760 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003761 goto err_peer_delete;
3762 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003763 }
3764
Michal Kazior424121c2013-07-22 14:13:31 +02003765 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003766 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003767 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003768 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003769 goto err_peer_delete;
3770 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003771
Michal Kazior424121c2013-07-22 14:13:31 +02003772 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003774 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003775 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003776 goto err_peer_delete;
3777 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003778
Michal Kazior7d9d5582014-10-21 10:40:15 +03003779 arvif->txpower = vif->bss_conf.txpower;
3780 ret = ath10k_mac_txpower_recalc(ar);
3781 if (ret) {
3782 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3783 goto err_peer_delete;
3784 }
3785
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003787 return 0;
3788
3789err_peer_delete:
3790 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3791 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3792
3793err_vdev_delete:
3794 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003795 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003796 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003797
3798err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003799 if (arvif->beacon_buf) {
3800 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3801 arvif->beacon_buf, arvif->beacon_paddr);
3802 arvif->beacon_buf = NULL;
3803 }
3804
Michal Kazior9dad14a2013-10-16 15:44:45 +03003805 mutex_unlock(&ar->conf_mutex);
3806
Kalle Valo5e3dd152013-06-12 20:52:10 +03003807 return ret;
3808}
3809
3810static void ath10k_remove_interface(struct ieee80211_hw *hw,
3811 struct ieee80211_vif *vif)
3812{
3813 struct ath10k *ar = hw->priv;
3814 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3815 int ret;
3816
Michal Kazior81a9a172015-03-05 16:02:17 +02003817 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003818 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003819
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303820 mutex_lock(&ar->conf_mutex);
3821
Michal Kaziored543882013-09-13 14:16:56 +02003822 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003823 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003824 spin_unlock_bh(&ar->data_lock);
3825
Simon Wunderlich855aed12014-08-02 09:12:54 +03003826 ret = ath10k_spectral_vif_stop(arvif);
3827 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003828 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003829 arvif->vdev_id, ret);
3830
Ben Greear16c11172014-09-23 14:17:16 -07003831 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003832 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003833
3834 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003835 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3836 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003837 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003838 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003839 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003840
3841 kfree(arvif->u.ap.noa_data);
3842 }
3843
Michal Kazior7aa7a722014-08-25 12:09:38 +02003844 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003845 arvif->vdev_id);
3846
Kalle Valo5e3dd152013-06-12 20:52:10 +03003847 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3848 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003849 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003850 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003851
Michal Kazior2c512052015-02-15 16:50:40 +02003852 /* Some firmware revisions don't notify host about self-peer removal
3853 * until after associated vdev is deleted.
3854 */
3855 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3856 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3857 vif->addr);
3858 if (ret)
3859 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3860 arvif->vdev_id, ret);
3861
3862 spin_lock_bh(&ar->data_lock);
3863 ar->num_peers--;
3864 spin_unlock_bh(&ar->data_lock);
3865 }
3866
Kalle Valo5e3dd152013-06-12 20:52:10 +03003867 ath10k_peer_cleanup(ar, arvif->vdev_id);
3868
3869 mutex_unlock(&ar->conf_mutex);
3870}
3871
3872/*
3873 * FIXME: Has to be verified.
3874 */
3875#define SUPPORTED_FILTERS \
3876 (FIF_PROMISC_IN_BSS | \
3877 FIF_ALLMULTI | \
3878 FIF_CONTROL | \
3879 FIF_PSPOLL | \
3880 FIF_OTHER_BSS | \
3881 FIF_BCN_PRBRESP_PROMISC | \
3882 FIF_PROBE_REQ | \
3883 FIF_FCSFAIL)
3884
3885static void ath10k_configure_filter(struct ieee80211_hw *hw,
3886 unsigned int changed_flags,
3887 unsigned int *total_flags,
3888 u64 multicast)
3889{
3890 struct ath10k *ar = hw->priv;
3891 int ret;
3892
3893 mutex_lock(&ar->conf_mutex);
3894
3895 changed_flags &= SUPPORTED_FILTERS;
3896 *total_flags &= SUPPORTED_FILTERS;
3897 ar->filter_flags = *total_flags;
3898
Michal Kazior19337472014-08-28 12:58:16 +02003899 ret = ath10k_monitor_recalc(ar);
3900 if (ret)
3901 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003902
3903 mutex_unlock(&ar->conf_mutex);
3904}
3905
3906static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3907 struct ieee80211_vif *vif,
3908 struct ieee80211_bss_conf *info,
3909 u32 changed)
3910{
3911 struct ath10k *ar = hw->priv;
3912 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3913 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003914 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915
3916 mutex_lock(&ar->conf_mutex);
3917
3918 if (changed & BSS_CHANGED_IBSS)
3919 ath10k_control_ibss(arvif, info, vif->addr);
3920
3921 if (changed & BSS_CHANGED_BEACON_INT) {
3922 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003923 vdev_param = ar->wmi.vdev_param->beacon_interval;
3924 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003925 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003926 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003927 "mac vdev %d beacon_interval %d\n",
3928 arvif->vdev_id, arvif->beacon_interval);
3929
Kalle Valo5e3dd152013-06-12 20:52:10 +03003930 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003931 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003932 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003933 }
3934
3935 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003936 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003937 "vdev %d set beacon tx mode to staggered\n",
3938 arvif->vdev_id);
3939
Bartosz Markowski226a3392013-09-26 17:47:16 +02003940 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3941 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003942 WMI_BEACON_STAGGERED_MODE);
3943 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003944 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003945 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003946
3947 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3948 if (ret)
3949 ath10k_warn(ar, "failed to update beacon template: %d\n",
3950 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003951 }
3952
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003953 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3954 ret = ath10k_mac_setup_prb_tmpl(arvif);
3955 if (ret)
3956 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3957 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003958 }
3959
Michal Kaziorba2479f2015-01-24 12:14:51 +02003960 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003961 arvif->dtim_period = info->dtim_period;
3962
Michal Kazior7aa7a722014-08-25 12:09:38 +02003963 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003964 "mac vdev %d dtim_period %d\n",
3965 arvif->vdev_id, arvif->dtim_period);
3966
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003967 vdev_param = ar->wmi.vdev_param->dtim_period;
3968 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003969 arvif->dtim_period);
3970 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003971 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003972 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973 }
3974
3975 if (changed & BSS_CHANGED_SSID &&
3976 vif->type == NL80211_IFTYPE_AP) {
3977 arvif->u.ap.ssid_len = info->ssid_len;
3978 if (info->ssid_len)
3979 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3980 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3981 }
3982
Michal Kazior077efc82014-10-21 10:10:29 +03003983 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3984 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003985
3986 if (changed & BSS_CHANGED_BEACON_ENABLED)
3987 ath10k_control_beaconing(arvif, info);
3988
3989 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003990 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003991 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003992 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003993
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003994 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003996 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003997 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003998
3999 vdev_param = ar->wmi.vdev_param->protection_mode;
4000 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4001 info->use_cts_prot ? 1 : 0);
4002 if (ret)
4003 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4004 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004005 }
4006
4007 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004008 if (info->use_short_slot)
4009 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4010
4011 else
4012 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4013
Michal Kazior7aa7a722014-08-25 12:09:38 +02004014 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004015 arvif->vdev_id, slottime);
4016
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004017 vdev_param = ar->wmi.vdev_param->slot_time;
4018 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019 slottime);
4020 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004021 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004022 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023 }
4024
4025 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 if (info->use_short_preamble)
4027 preamble = WMI_VDEV_PREAMBLE_SHORT;
4028 else
4029 preamble = WMI_VDEV_PREAMBLE_LONG;
4030
Michal Kazior7aa7a722014-08-25 12:09:38 +02004031 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004032 "mac vdev %d preamble %dn",
4033 arvif->vdev_id, preamble);
4034
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004035 vdev_param = ar->wmi.vdev_param->preamble;
4036 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037 preamble);
4038 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004039 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004040 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041 }
4042
4043 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004044 if (info->assoc) {
4045 /* Workaround: Make sure monitor vdev is not running
4046 * when associating to prevent some firmware revisions
4047 * (e.g. 10.1 and 10.2) from crashing.
4048 */
4049 if (ar->monitor_started)
4050 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004051 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004052 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004053 } else {
4054 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004055 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004056 }
4057
Michal Kazior7d9d5582014-10-21 10:40:15 +03004058 if (changed & BSS_CHANGED_TXPOWER) {
4059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4060 arvif->vdev_id, info->txpower);
4061
4062 arvif->txpower = info->txpower;
4063 ret = ath10k_mac_txpower_recalc(ar);
4064 if (ret)
4065 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4066 }
4067
Michal Kaziorbf14e652014-12-12 12:41:38 +01004068 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004069 arvif->ps = vif->bss_conf.ps;
4070
4071 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004072 if (ret)
4073 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4074 arvif->vdev_id, ret);
4075 }
4076
Kalle Valo5e3dd152013-06-12 20:52:10 +03004077 mutex_unlock(&ar->conf_mutex);
4078}
4079
4080static int ath10k_hw_scan(struct ieee80211_hw *hw,
4081 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004082 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083{
4084 struct ath10k *ar = hw->priv;
4085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004086 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004087 struct wmi_start_scan_arg arg;
4088 int ret = 0;
4089 int i;
4090
4091 mutex_lock(&ar->conf_mutex);
4092
4093 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004094 switch (ar->scan.state) {
4095 case ATH10K_SCAN_IDLE:
4096 reinit_completion(&ar->scan.started);
4097 reinit_completion(&ar->scan.completed);
4098 ar->scan.state = ATH10K_SCAN_STARTING;
4099 ar->scan.is_roc = false;
4100 ar->scan.vdev_id = arvif->vdev_id;
4101 ret = 0;
4102 break;
4103 case ATH10K_SCAN_STARTING:
4104 case ATH10K_SCAN_RUNNING:
4105 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004106 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004107 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004108 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004109 spin_unlock_bh(&ar->data_lock);
4110
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004111 if (ret)
4112 goto exit;
4113
Kalle Valo5e3dd152013-06-12 20:52:10 +03004114 memset(&arg, 0, sizeof(arg));
4115 ath10k_wmi_start_scan_init(ar, &arg);
4116 arg.vdev_id = arvif->vdev_id;
4117 arg.scan_id = ATH10K_SCAN_ID;
4118
4119 if (!req->no_cck)
4120 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4121
4122 if (req->ie_len) {
4123 arg.ie_len = req->ie_len;
4124 memcpy(arg.ie, req->ie, arg.ie_len);
4125 }
4126
4127 if (req->n_ssids) {
4128 arg.n_ssids = req->n_ssids;
4129 for (i = 0; i < arg.n_ssids; i++) {
4130 arg.ssids[i].len = req->ssids[i].ssid_len;
4131 arg.ssids[i].ssid = req->ssids[i].ssid;
4132 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004133 } else {
4134 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004135 }
4136
4137 if (req->n_channels) {
4138 arg.n_channels = req->n_channels;
4139 for (i = 0; i < arg.n_channels; i++)
4140 arg.channels[i] = req->channels[i]->center_freq;
4141 }
4142
4143 ret = ath10k_start_scan(ar, &arg);
4144 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004145 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004146 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004147 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004148 spin_unlock_bh(&ar->data_lock);
4149 }
4150
4151exit:
4152 mutex_unlock(&ar->conf_mutex);
4153 return ret;
4154}
4155
4156static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4157 struct ieee80211_vif *vif)
4158{
4159 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160
4161 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004162 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004163 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004164
4165 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004166}
4167
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004168static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4169 struct ath10k_vif *arvif,
4170 enum set_key_cmd cmd,
4171 struct ieee80211_key_conf *key)
4172{
4173 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4174 int ret;
4175
4176 /* 10.1 firmware branch requires default key index to be set to group
4177 * key index after installing it. Otherwise FW/HW Txes corrupted
4178 * frames with multi-vif APs. This is not required for main firmware
4179 * branch (e.g. 636).
4180 *
4181 * FIXME: This has been tested only in AP. It remains unknown if this
4182 * is required for multi-vif STA interfaces on 10.1 */
4183
4184 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4185 return;
4186
4187 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4188 return;
4189
4190 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4191 return;
4192
4193 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4194 return;
4195
4196 if (cmd != SET_KEY)
4197 return;
4198
4199 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4200 key->keyidx);
4201 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004202 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004203 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004204}
4205
Kalle Valo5e3dd152013-06-12 20:52:10 +03004206static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4207 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4208 struct ieee80211_key_conf *key)
4209{
4210 struct ath10k *ar = hw->priv;
4211 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4212 struct ath10k_peer *peer;
4213 const u8 *peer_addr;
4214 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4215 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4216 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004217 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004218
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004219 /* this one needs to be done in software */
4220 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4221 return 1;
4222
Kalle Valo5e3dd152013-06-12 20:52:10 +03004223 if (key->keyidx > WMI_MAX_KEY_INDEX)
4224 return -ENOSPC;
4225
4226 mutex_lock(&ar->conf_mutex);
4227
4228 if (sta)
4229 peer_addr = sta->addr;
4230 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4231 peer_addr = vif->bss_conf.bssid;
4232 else
4233 peer_addr = vif->addr;
4234
4235 key->hw_key_idx = key->keyidx;
4236
4237 /* the peer should not disappear in mid-way (unless FW goes awry) since
4238 * we already hold conf_mutex. we just make sure its there now. */
4239 spin_lock_bh(&ar->data_lock);
4240 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4241 spin_unlock_bh(&ar->data_lock);
4242
4243 if (!peer) {
4244 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004245 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004246 peer_addr);
4247 ret = -EOPNOTSUPP;
4248 goto exit;
4249 } else {
4250 /* if the peer doesn't exist there is no key to disable
4251 * anymore */
4252 goto exit;
4253 }
4254 }
4255
Michal Kazior7cc45732015-03-09 14:24:17 +01004256 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4257 flags |= WMI_KEY_PAIRWISE;
4258 else
4259 flags |= WMI_KEY_GROUP;
4260
Kalle Valo5e3dd152013-06-12 20:52:10 +03004261 if (is_wep) {
4262 if (cmd == SET_KEY)
4263 arvif->wep_keys[key->keyidx] = key;
4264 else
4265 arvif->wep_keys[key->keyidx] = NULL;
4266
4267 if (cmd == DISABLE_KEY)
4268 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004269
Michal Kaziorad325cb2015-02-18 14:02:27 +01004270 /* When WEP keys are uploaded it's possible that there are
4271 * stations associated already (e.g. when merging) without any
4272 * keys. Static WEP needs an explicit per-peer key upload.
4273 */
4274 if (vif->type == NL80211_IFTYPE_ADHOC &&
4275 cmd == SET_KEY)
4276 ath10k_mac_vif_update_wep_key(arvif, key);
4277
Michal Kazior370e5672015-02-18 14:02:26 +01004278 /* 802.1x never sets the def_wep_key_idx so each set_key()
4279 * call changes default tx key.
4280 *
4281 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4282 * after first set_key().
4283 */
4284 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4285 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004286
Michal Kazior7cc45732015-03-09 14:24:17 +01004287 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4288 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4289 * mode and associated stations in AP/IBSS.
4290 *
4291 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4292 * work fine when mapped directly from mac80211.
4293 *
4294 * Note: When installing first static WEP groupwise key (which
4295 * should be pairwise) def_wep_key_idx isn't known yet (it's
4296 * equal to -1). Since .set_default_unicast_key is called only
4297 * for static WEP it's used to re-upload the key as pairwise.
4298 */
4299 if (arvif->def_wep_key_idx >= 0 &&
4300 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4301 flags &= ~WMI_KEY_GROUP;
4302 flags |= WMI_KEY_PAIRWISE;
4303 }
Michal Kazior370e5672015-02-18 14:02:26 +01004304 }
4305
4306 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004308 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004309 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004310 goto exit;
4311 }
4312
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004313 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4314
Kalle Valo5e3dd152013-06-12 20:52:10 +03004315 spin_lock_bh(&ar->data_lock);
4316 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4317 if (peer && cmd == SET_KEY)
4318 peer->keys[key->keyidx] = key;
4319 else if (peer && cmd == DISABLE_KEY)
4320 peer->keys[key->keyidx] = NULL;
4321 else if (peer == NULL)
4322 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004323 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004324 spin_unlock_bh(&ar->data_lock);
4325
4326exit:
4327 mutex_unlock(&ar->conf_mutex);
4328 return ret;
4329}
4330
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004331static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4332 struct ieee80211_vif *vif,
4333 int keyidx)
4334{
4335 struct ath10k *ar = hw->priv;
4336 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4337 int ret;
4338
4339 mutex_lock(&arvif->ar->conf_mutex);
4340
4341 if (arvif->ar->state != ATH10K_STATE_ON)
4342 goto unlock;
4343
4344 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4345 arvif->vdev_id, keyidx);
4346
4347 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4348 arvif->vdev_id,
4349 arvif->ar->wmi.vdev_param->def_keyid,
4350 keyidx);
4351
4352 if (ret) {
4353 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4354 arvif->vdev_id,
4355 ret);
4356 goto unlock;
4357 }
4358
4359 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004360
4361 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4362 if (ret) {
4363 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4364 arvif->vdev_id, ret);
4365 goto unlock;
4366 }
4367
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004368unlock:
4369 mutex_unlock(&arvif->ar->conf_mutex);
4370}
4371
Michal Kazior9797feb2014-02-14 14:49:48 +01004372static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4373{
4374 struct ath10k *ar;
4375 struct ath10k_vif *arvif;
4376 struct ath10k_sta *arsta;
4377 struct ieee80211_sta *sta;
4378 u32 changed, bw, nss, smps;
4379 int err;
4380
4381 arsta = container_of(wk, struct ath10k_sta, update_wk);
4382 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4383 arvif = arsta->arvif;
4384 ar = arvif->ar;
4385
4386 spin_lock_bh(&ar->data_lock);
4387
4388 changed = arsta->changed;
4389 arsta->changed = 0;
4390
4391 bw = arsta->bw;
4392 nss = arsta->nss;
4393 smps = arsta->smps;
4394
4395 spin_unlock_bh(&ar->data_lock);
4396
4397 mutex_lock(&ar->conf_mutex);
4398
4399 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004400 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004401 sta->addr, bw);
4402
4403 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4404 WMI_PEER_CHAN_WIDTH, bw);
4405 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004406 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004407 sta->addr, bw, err);
4408 }
4409
4410 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004411 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004412 sta->addr, nss);
4413
4414 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4415 WMI_PEER_NSS, nss);
4416 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004417 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004418 sta->addr, nss, err);
4419 }
4420
4421 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004423 sta->addr, smps);
4424
4425 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4426 WMI_PEER_SMPS_STATE, smps);
4427 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004428 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004429 sta->addr, smps, err);
4430 }
4431
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004432 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4433 changed & IEEE80211_RC_NSS_CHANGED) {
4434 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004435 sta->addr);
4436
Michal Kazior590922a2014-10-21 10:10:29 +03004437 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004438 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004439 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004440 sta->addr);
4441 }
4442
Michal Kazior9797feb2014-02-14 14:49:48 +01004443 mutex_unlock(&ar->conf_mutex);
4444}
4445
Marek Puzyniak7c354242015-03-30 09:51:52 +03004446static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4447 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004448{
4449 struct ath10k *ar = arvif->ar;
4450
4451 lockdep_assert_held(&ar->conf_mutex);
4452
Marek Puzyniak7c354242015-03-30 09:51:52 +03004453 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004454 return 0;
4455
4456 if (ar->num_stations >= ar->max_num_stations)
4457 return -ENOBUFS;
4458
4459 ar->num_stations++;
4460
4461 return 0;
4462}
4463
Marek Puzyniak7c354242015-03-30 09:51:52 +03004464static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4465 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004466{
4467 struct ath10k *ar = arvif->ar;
4468
4469 lockdep_assert_held(&ar->conf_mutex);
4470
Marek Puzyniak7c354242015-03-30 09:51:52 +03004471 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004472 return;
4473
4474 ar->num_stations--;
4475}
4476
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004477struct ath10k_mac_tdls_iter_data {
4478 u32 num_tdls_stations;
4479 struct ieee80211_vif *curr_vif;
4480};
4481
4482static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4483 struct ieee80211_sta *sta)
4484{
4485 struct ath10k_mac_tdls_iter_data *iter_data = data;
4486 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4487 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4488
4489 if (sta->tdls && sta_vif == iter_data->curr_vif)
4490 iter_data->num_tdls_stations++;
4491}
4492
4493static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4494 struct ieee80211_vif *vif)
4495{
4496 struct ath10k_mac_tdls_iter_data data = {};
4497
4498 data.curr_vif = vif;
4499
4500 ieee80211_iterate_stations_atomic(hw,
4501 ath10k_mac_tdls_vif_stations_count_iter,
4502 &data);
4503 return data.num_tdls_stations;
4504}
4505
4506static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4507 struct ieee80211_vif *vif)
4508{
4509 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4510 int *num_tdls_vifs = data;
4511
4512 if (vif->type != NL80211_IFTYPE_STATION)
4513 return;
4514
4515 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4516 (*num_tdls_vifs)++;
4517}
4518
4519static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4520{
4521 int num_tdls_vifs = 0;
4522
4523 ieee80211_iterate_active_interfaces_atomic(hw,
4524 IEEE80211_IFACE_ITER_NORMAL,
4525 ath10k_mac_tdls_vifs_count_iter,
4526 &num_tdls_vifs);
4527 return num_tdls_vifs;
4528}
4529
Kalle Valo5e3dd152013-06-12 20:52:10 +03004530static int ath10k_sta_state(struct ieee80211_hw *hw,
4531 struct ieee80211_vif *vif,
4532 struct ieee80211_sta *sta,
4533 enum ieee80211_sta_state old_state,
4534 enum ieee80211_sta_state new_state)
4535{
4536 struct ath10k *ar = hw->priv;
4537 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004538 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004539 int ret = 0;
4540
Michal Kazior76f90022014-02-25 09:29:57 +02004541 if (old_state == IEEE80211_STA_NOTEXIST &&
4542 new_state == IEEE80211_STA_NONE) {
4543 memset(arsta, 0, sizeof(*arsta));
4544 arsta->arvif = arvif;
4545 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4546 }
4547
Michal Kazior9797feb2014-02-14 14:49:48 +01004548 /* cancel must be done outside the mutex to avoid deadlock */
4549 if ((old_state == IEEE80211_STA_NONE &&
4550 new_state == IEEE80211_STA_NOTEXIST))
4551 cancel_work_sync(&arsta->update_wk);
4552
Kalle Valo5e3dd152013-06-12 20:52:10 +03004553 mutex_lock(&ar->conf_mutex);
4554
4555 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004556 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004557 /*
4558 * New station addition.
4559 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004560 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4561 u32 num_tdls_stations;
4562 u32 num_tdls_vifs;
4563
Michal Kaziorcfd10612014-11-25 15:16:05 +01004564 ath10k_dbg(ar, ATH10K_DBG_MAC,
4565 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4566 arvif->vdev_id, sta->addr,
4567 ar->num_stations + 1, ar->max_num_stations,
4568 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004569
Marek Puzyniak7c354242015-03-30 09:51:52 +03004570 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004571 if (ret) {
4572 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4573 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004574 goto exit;
4575 }
4576
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004577 if (sta->tdls)
4578 peer_type = WMI_PEER_TYPE_TDLS;
4579
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004580 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004581 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004583 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 -08004584 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004585 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004586 goto exit;
4587 }
Michal Kazior077efc82014-10-21 10:10:29 +03004588
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004589 if (vif->type == NL80211_IFTYPE_STATION &&
4590 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004591 WARN_ON(arvif->is_started);
4592
4593 ret = ath10k_vdev_start(arvif);
4594 if (ret) {
4595 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4596 arvif->vdev_id, ret);
4597 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4598 sta->addr));
Marek Puzyniak7c354242015-03-30 09:51:52 +03004599 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03004600 goto exit;
4601 }
4602
4603 arvif->is_started = true;
4604 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004605
4606 if (!sta->tdls)
4607 goto exit;
4608
4609 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4610 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4611
4612 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4613 num_tdls_stations == 0) {
4614 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4615 arvif->vdev_id, ar->max_num_tdls_vdevs);
4616 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4617 ath10k_mac_dec_num_stations(arvif, sta);
4618 ret = -ENOBUFS;
4619 goto exit;
4620 }
4621
4622 if (num_tdls_stations == 0) {
4623 /* This is the first tdls peer in current vif */
4624 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4625
4626 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4627 state);
4628 if (ret) {
4629 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4630 arvif->vdev_id, ret);
4631 ath10k_peer_delete(ar, arvif->vdev_id,
4632 sta->addr);
4633 ath10k_mac_dec_num_stations(arvif, sta);
4634 goto exit;
4635 }
4636 }
4637
4638 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4639 WMI_TDLS_PEER_STATE_PEERING);
4640 if (ret) {
4641 ath10k_warn(ar,
4642 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4643 sta->addr, arvif->vdev_id, ret);
4644 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4645 ath10k_mac_dec_num_stations(arvif, sta);
4646
4647 if (num_tdls_stations != 0)
4648 goto exit;
4649 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4650 WMI_TDLS_DISABLE);
4651 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004652 } else if ((old_state == IEEE80211_STA_NONE &&
4653 new_state == IEEE80211_STA_NOTEXIST)) {
4654 /*
4655 * Existing station deletion.
4656 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004657 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004658 "mac vdev %d peer delete %pM (sta gone)\n",
4659 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004660
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004661 if (vif->type == NL80211_IFTYPE_STATION &&
4662 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004663 WARN_ON(!arvif->is_started);
4664
4665 ret = ath10k_vdev_stop(arvif);
4666 if (ret)
4667 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4668 arvif->vdev_id, ret);
4669
4670 arvif->is_started = false;
4671 }
4672
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4674 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004675 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004676 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004677
Marek Puzyniak7c354242015-03-30 09:51:52 +03004678 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004679
4680 if (!sta->tdls)
4681 goto exit;
4682
4683 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
4684 goto exit;
4685
4686 /* This was the last tdls peer in current vif */
4687 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4688 WMI_TDLS_DISABLE);
4689 if (ret) {
4690 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4691 arvif->vdev_id, ret);
4692 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004693 } else if (old_state == IEEE80211_STA_AUTH &&
4694 new_state == IEEE80211_STA_ASSOC &&
4695 (vif->type == NL80211_IFTYPE_AP ||
4696 vif->type == NL80211_IFTYPE_ADHOC)) {
4697 /*
4698 * New association.
4699 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004700 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004701 sta->addr);
4702
Michal Kazior590922a2014-10-21 10:10:29 +03004703 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004705 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004706 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004707 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004708 new_state == IEEE80211_STA_AUTHORIZED &&
4709 sta->tdls) {
4710 /*
4711 * Tdls station authorized.
4712 */
4713 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
4714 sta->addr);
4715
4716 ret = ath10k_station_assoc(ar, vif, sta, false);
4717 if (ret) {
4718 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
4719 sta->addr, arvif->vdev_id, ret);
4720 goto exit;
4721 }
4722
4723 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4724 WMI_TDLS_PEER_STATE_CONNECTED);
4725 if (ret)
4726 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
4727 sta->addr, arvif->vdev_id, ret);
4728 } else if (old_state == IEEE80211_STA_ASSOC &&
4729 new_state == IEEE80211_STA_AUTH &&
4730 (vif->type == NL80211_IFTYPE_AP ||
4731 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732 /*
4733 * Disassociation.
4734 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004735 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004736 sta->addr);
4737
Michal Kazior590922a2014-10-21 10:10:29 +03004738 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004739 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004740 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004741 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004742 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004743exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004744 mutex_unlock(&ar->conf_mutex);
4745 return ret;
4746}
4747
4748static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004749 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004750{
4751 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004752 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4753 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004754 u32 value = 0;
4755 int ret = 0;
4756
Michal Kazior548db542013-07-05 16:15:15 +03004757 lockdep_assert_held(&ar->conf_mutex);
4758
Kalle Valo5e3dd152013-06-12 20:52:10 +03004759 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4760 return 0;
4761
4762 switch (ac) {
4763 case IEEE80211_AC_VO:
4764 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4765 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004766 prio = 7;
4767 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004768 break;
4769 case IEEE80211_AC_VI:
4770 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4771 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004772 prio = 5;
4773 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004774 break;
4775 case IEEE80211_AC_BE:
4776 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4777 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004778 prio = 2;
4779 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004780 break;
4781 case IEEE80211_AC_BK:
4782 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4783 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004784 prio = 0;
4785 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004786 break;
4787 }
4788
4789 if (enable)
4790 arvif->u.sta.uapsd |= value;
4791 else
4792 arvif->u.sta.uapsd &= ~value;
4793
4794 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4795 WMI_STA_PS_PARAM_UAPSD,
4796 arvif->u.sta.uapsd);
4797 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004798 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004799 goto exit;
4800 }
4801
4802 if (arvif->u.sta.uapsd)
4803 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4804 else
4805 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4806
4807 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4808 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4809 value);
4810 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004811 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004812
Michal Kazior9f9b5742014-12-12 12:41:36 +01004813 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4814 if (ret) {
4815 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4816 arvif->vdev_id, ret);
4817 return ret;
4818 }
4819
4820 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4821 if (ret) {
4822 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4823 arvif->vdev_id, ret);
4824 return ret;
4825 }
4826
Michal Kaziorb0e56152015-01-24 12:14:52 +02004827 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4828 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4829 /* Only userspace can make an educated decision when to send
4830 * trigger frame. The following effectively disables u-UAPSD
4831 * autotrigger in firmware (which is enabled by default
4832 * provided the autotrigger service is available).
4833 */
4834
4835 arg.wmm_ac = acc;
4836 arg.user_priority = prio;
4837 arg.service_interval = 0;
4838 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4839 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4840
4841 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4842 arvif->bssid, &arg, 1);
4843 if (ret) {
4844 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4845 ret);
4846 return ret;
4847 }
4848 }
4849
Kalle Valo5e3dd152013-06-12 20:52:10 +03004850exit:
4851 return ret;
4852}
4853
4854static int ath10k_conf_tx(struct ieee80211_hw *hw,
4855 struct ieee80211_vif *vif, u16 ac,
4856 const struct ieee80211_tx_queue_params *params)
4857{
4858 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004859 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004860 struct wmi_wmm_params_arg *p = NULL;
4861 int ret;
4862
4863 mutex_lock(&ar->conf_mutex);
4864
4865 switch (ac) {
4866 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004867 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004868 break;
4869 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004870 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004871 break;
4872 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004873 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004874 break;
4875 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004876 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004877 break;
4878 }
4879
4880 if (WARN_ON(!p)) {
4881 ret = -EINVAL;
4882 goto exit;
4883 }
4884
4885 p->cwmin = params->cw_min;
4886 p->cwmax = params->cw_max;
4887 p->aifs = params->aifs;
4888
4889 /*
4890 * The channel time duration programmed in the HW is in absolute
4891 * microseconds, while mac80211 gives the txop in units of
4892 * 32 microseconds.
4893 */
4894 p->txop = params->txop * 32;
4895
Michal Kazior7fc979a2015-01-28 09:57:28 +02004896 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4897 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4898 &arvif->wmm_params);
4899 if (ret) {
4900 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4901 arvif->vdev_id, ret);
4902 goto exit;
4903 }
4904 } else {
4905 /* This won't work well with multi-interface cases but it's
4906 * better than nothing.
4907 */
4908 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4909 if (ret) {
4910 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4911 goto exit;
4912 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004913 }
4914
4915 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4916 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004917 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004918
4919exit:
4920 mutex_unlock(&ar->conf_mutex);
4921 return ret;
4922}
4923
4924#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4925
4926static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4927 struct ieee80211_vif *vif,
4928 struct ieee80211_channel *chan,
4929 int duration,
4930 enum ieee80211_roc_type type)
4931{
4932 struct ath10k *ar = hw->priv;
4933 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4934 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004935 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004936
4937 mutex_lock(&ar->conf_mutex);
4938
4939 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004940 switch (ar->scan.state) {
4941 case ATH10K_SCAN_IDLE:
4942 reinit_completion(&ar->scan.started);
4943 reinit_completion(&ar->scan.completed);
4944 reinit_completion(&ar->scan.on_channel);
4945 ar->scan.state = ATH10K_SCAN_STARTING;
4946 ar->scan.is_roc = true;
4947 ar->scan.vdev_id = arvif->vdev_id;
4948 ar->scan.roc_freq = chan->center_freq;
4949 ret = 0;
4950 break;
4951 case ATH10K_SCAN_STARTING:
4952 case ATH10K_SCAN_RUNNING:
4953 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004954 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004955 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004956 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004957 spin_unlock_bh(&ar->data_lock);
4958
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004959 if (ret)
4960 goto exit;
4961
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004962 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4963
Kalle Valo5e3dd152013-06-12 20:52:10 +03004964 memset(&arg, 0, sizeof(arg));
4965 ath10k_wmi_start_scan_init(ar, &arg);
4966 arg.vdev_id = arvif->vdev_id;
4967 arg.scan_id = ATH10K_SCAN_ID;
4968 arg.n_channels = 1;
4969 arg.channels[0] = chan->center_freq;
4970 arg.dwell_time_active = duration;
4971 arg.dwell_time_passive = duration;
4972 arg.max_scan_time = 2 * duration;
4973 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4974 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4975
4976 ret = ath10k_start_scan(ar, &arg);
4977 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004978 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004979 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004980 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004981 spin_unlock_bh(&ar->data_lock);
4982 goto exit;
4983 }
4984
4985 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4986 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004987 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004988
4989 ret = ath10k_scan_stop(ar);
4990 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004991 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004992
Kalle Valo5e3dd152013-06-12 20:52:10 +03004993 ret = -ETIMEDOUT;
4994 goto exit;
4995 }
4996
4997 ret = 0;
4998exit:
4999 mutex_unlock(&ar->conf_mutex);
5000 return ret;
5001}
5002
5003static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5004{
5005 struct ath10k *ar = hw->priv;
5006
5007 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005008 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005009 mutex_unlock(&ar->conf_mutex);
5010
Michal Kazior4eb2e162014-10-28 10:23:09 +01005011 cancel_delayed_work_sync(&ar->scan.timeout);
5012
Kalle Valo5e3dd152013-06-12 20:52:10 +03005013 return 0;
5014}
5015
5016/*
5017 * Both RTS and Fragmentation threshold are interface-specific
5018 * in ath10k, but device-specific in mac80211.
5019 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005020
5021static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5022{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005023 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005024 struct ath10k_vif *arvif;
5025 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005026
Michal Kaziorad088bf2013-10-16 15:44:46 +03005027 mutex_lock(&ar->conf_mutex);
5028 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005030 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005031
Michal Kaziorad088bf2013-10-16 15:44:46 +03005032 ret = ath10k_mac_set_rts(arvif, value);
5033 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005034 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005035 arvif->vdev_id, ret);
5036 break;
5037 }
5038 }
5039 mutex_unlock(&ar->conf_mutex);
5040
5041 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005042}
5043
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005044static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5045 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005046{
5047 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005048 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005049 int ret;
5050
5051 /* mac80211 doesn't care if we really xmit queued frames or not
5052 * we'll collect those frames either way if we stop/delete vdevs */
5053 if (drop)
5054 return;
5055
Michal Kazior548db542013-07-05 16:15:15 +03005056 mutex_lock(&ar->conf_mutex);
5057
Michal Kazioraffd3212013-07-16 09:54:35 +02005058 if (ar->state == ATH10K_STATE_WEDGED)
5059 goto skip;
5060
Michal Kazioredb82362013-07-05 16:15:14 +03005061 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005062 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005063
Michal Kazioredb82362013-07-05 16:15:14 +03005064 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005065 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005066 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005067
Michal Kazior7962b0d2014-10-28 10:34:38 +01005068 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5069 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5070 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005071
5072 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005073 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005074
5075 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005076 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005077 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005078
Michal Kazioraffd3212013-07-16 09:54:35 +02005079skip:
Michal Kazior548db542013-07-05 16:15:15 +03005080 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005081}
5082
5083/* TODO: Implement this function properly
5084 * For now it is needed to reply to Probe Requests in IBSS mode.
5085 * Propably we need this information from FW.
5086 */
5087static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5088{
5089 return 1;
5090}
5091
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005092static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5093 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005094{
5095 struct ath10k *ar = hw->priv;
5096
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005097 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5098 return;
5099
Michal Kazioraffd3212013-07-16 09:54:35 +02005100 mutex_lock(&ar->conf_mutex);
5101
5102 /* If device failed to restart it will be in a different state, e.g.
5103 * ATH10K_STATE_WEDGED */
5104 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005105 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005106 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005107 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005108 }
5109
5110 mutex_unlock(&ar->conf_mutex);
5111}
5112
Michal Kazior2e1dea42013-07-31 10:32:40 +02005113static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5114 struct survey_info *survey)
5115{
5116 struct ath10k *ar = hw->priv;
5117 struct ieee80211_supported_band *sband;
5118 struct survey_info *ar_survey = &ar->survey[idx];
5119 int ret = 0;
5120
5121 mutex_lock(&ar->conf_mutex);
5122
5123 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5124 if (sband && idx >= sband->n_channels) {
5125 idx -= sband->n_channels;
5126 sband = NULL;
5127 }
5128
5129 if (!sband)
5130 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5131
5132 if (!sband || idx >= sband->n_channels) {
5133 ret = -ENOENT;
5134 goto exit;
5135 }
5136
5137 spin_lock_bh(&ar->data_lock);
5138 memcpy(survey, ar_survey, sizeof(*survey));
5139 spin_unlock_bh(&ar->data_lock);
5140
5141 survey->channel = &sband->channels[idx];
5142
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005143 if (ar->rx_channel == survey->channel)
5144 survey->filled |= SURVEY_INFO_IN_USE;
5145
Michal Kazior2e1dea42013-07-31 10:32:40 +02005146exit:
5147 mutex_unlock(&ar->conf_mutex);
5148 return ret;
5149}
5150
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005151/* Helper table for legacy fixed_rate/bitrate_mask */
5152static const u8 cck_ofdm_rate[] = {
5153 /* CCK */
5154 3, /* 1Mbps */
5155 2, /* 2Mbps */
5156 1, /* 5.5Mbps */
5157 0, /* 11Mbps */
5158 /* OFDM */
5159 3, /* 6Mbps */
5160 7, /* 9Mbps */
5161 2, /* 12Mbps */
5162 6, /* 18Mbps */
5163 1, /* 24Mbps */
5164 5, /* 36Mbps */
5165 0, /* 48Mbps */
5166 4, /* 54Mbps */
5167};
5168
5169/* Check if only one bit set */
5170static int ath10k_check_single_mask(u32 mask)
5171{
5172 int bit;
5173
5174 bit = ffs(mask);
5175 if (!bit)
5176 return 0;
5177
5178 mask &= ~BIT(bit - 1);
5179 if (mask)
5180 return 2;
5181
5182 return 1;
5183}
5184
5185static bool
5186ath10k_default_bitrate_mask(struct ath10k *ar,
5187 enum ieee80211_band band,
5188 const struct cfg80211_bitrate_mask *mask)
5189{
5190 u32 legacy = 0x00ff;
5191 u8 ht = 0xff, i;
5192 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005193 u16 nrf = ar->num_rf_chains;
5194
5195 if (ar->cfg_tx_chainmask)
5196 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005197
5198 switch (band) {
5199 case IEEE80211_BAND_2GHZ:
5200 legacy = 0x00fff;
5201 vht = 0;
5202 break;
5203 case IEEE80211_BAND_5GHZ:
5204 break;
5205 default:
5206 return false;
5207 }
5208
5209 if (mask->control[band].legacy != legacy)
5210 return false;
5211
Ben Greearb116ea12014-11-24 16:22:10 +02005212 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005213 if (mask->control[band].ht_mcs[i] != ht)
5214 return false;
5215
Ben Greearb116ea12014-11-24 16:22:10 +02005216 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005217 if (mask->control[band].vht_mcs[i] != vht)
5218 return false;
5219
5220 return true;
5221}
5222
5223static bool
5224ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5225 enum ieee80211_band band,
5226 u8 *fixed_nss)
5227{
5228 int ht_nss = 0, vht_nss = 0, i;
5229
5230 /* check legacy */
5231 if (ath10k_check_single_mask(mask->control[band].legacy))
5232 return false;
5233
5234 /* check HT */
5235 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5236 if (mask->control[band].ht_mcs[i] == 0xff)
5237 continue;
5238 else if (mask->control[band].ht_mcs[i] == 0x00)
5239 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005240
5241 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005242 }
5243
5244 ht_nss = i;
5245
5246 /* check VHT */
5247 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5248 if (mask->control[band].vht_mcs[i] == 0x03ff)
5249 continue;
5250 else if (mask->control[band].vht_mcs[i] == 0x0000)
5251 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005252
5253 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005254 }
5255
5256 vht_nss = i;
5257
5258 if (ht_nss > 0 && vht_nss > 0)
5259 return false;
5260
5261 if (ht_nss)
5262 *fixed_nss = ht_nss;
5263 else if (vht_nss)
5264 *fixed_nss = vht_nss;
5265 else
5266 return false;
5267
5268 return true;
5269}
5270
5271static bool
5272ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5273 enum ieee80211_band band,
5274 enum wmi_rate_preamble *preamble)
5275{
5276 int legacy = 0, ht = 0, vht = 0, i;
5277
5278 *preamble = WMI_RATE_PREAMBLE_OFDM;
5279
5280 /* check legacy */
5281 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5282 if (legacy > 1)
5283 return false;
5284
5285 /* check HT */
5286 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5287 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5288 if (ht > 1)
5289 return false;
5290
5291 /* check VHT */
5292 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5293 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5294 if (vht > 1)
5295 return false;
5296
5297 /* Currently we support only one fixed_rate */
5298 if ((legacy + ht + vht) != 1)
5299 return false;
5300
5301 if (ht)
5302 *preamble = WMI_RATE_PREAMBLE_HT;
5303 else if (vht)
5304 *preamble = WMI_RATE_PREAMBLE_VHT;
5305
5306 return true;
5307}
5308
5309static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005310ath10k_bitrate_mask_rate(struct ath10k *ar,
5311 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005312 enum ieee80211_band band,
5313 u8 *fixed_rate,
5314 u8 *fixed_nss)
5315{
5316 u8 rate = 0, pream = 0, nss = 0, i;
5317 enum wmi_rate_preamble preamble;
5318
5319 /* Check if single rate correct */
5320 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5321 return false;
5322
5323 pream = preamble;
5324
5325 switch (preamble) {
5326 case WMI_RATE_PREAMBLE_CCK:
5327 case WMI_RATE_PREAMBLE_OFDM:
5328 i = ffs(mask->control[band].legacy) - 1;
5329
5330 if (band == IEEE80211_BAND_2GHZ && i < 4)
5331 pream = WMI_RATE_PREAMBLE_CCK;
5332
5333 if (band == IEEE80211_BAND_5GHZ)
5334 i += 4;
5335
5336 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5337 return false;
5338
5339 rate = cck_ofdm_rate[i];
5340 break;
5341 case WMI_RATE_PREAMBLE_HT:
5342 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5343 if (mask->control[band].ht_mcs[i])
5344 break;
5345
5346 if (i == IEEE80211_HT_MCS_MASK_LEN)
5347 return false;
5348
5349 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5350 nss = i;
5351 break;
5352 case WMI_RATE_PREAMBLE_VHT:
5353 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5354 if (mask->control[band].vht_mcs[i])
5355 break;
5356
5357 if (i == NL80211_VHT_NSS_MAX)
5358 return false;
5359
5360 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5361 nss = i;
5362 break;
5363 }
5364
5365 *fixed_nss = nss + 1;
5366 nss <<= 4;
5367 pream <<= 6;
5368
Michal Kazior7aa7a722014-08-25 12:09:38 +02005369 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 +01005370 pream, nss, rate);
5371
5372 *fixed_rate = pream | nss | rate;
5373
5374 return true;
5375}
5376
Michal Kazior7aa7a722014-08-25 12:09:38 +02005377static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5378 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005379 enum ieee80211_band band,
5380 u8 *fixed_rate,
5381 u8 *fixed_nss)
5382{
5383 /* First check full NSS mask, if we can simply limit NSS */
5384 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5385 return true;
5386
5387 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005388 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005389}
5390
5391static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5392 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005393 u8 fixed_nss,
5394 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005395{
5396 struct ath10k *ar = arvif->ar;
5397 u32 vdev_param;
5398 int ret = 0;
5399
5400 mutex_lock(&ar->conf_mutex);
5401
5402 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005403 arvif->fixed_nss == fixed_nss &&
5404 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005405 goto exit;
5406
5407 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005408 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005409
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005410 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005411 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005412
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005413 vdev_param = ar->wmi.vdev_param->fixed_rate;
5414 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5415 vdev_param, fixed_rate);
5416 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005417 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005418 fixed_rate, ret);
5419 ret = -EINVAL;
5420 goto exit;
5421 }
5422
5423 arvif->fixed_rate = fixed_rate;
5424
5425 vdev_param = ar->wmi.vdev_param->nss;
5426 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5427 vdev_param, fixed_nss);
5428
5429 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005430 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005431 fixed_nss, ret);
5432 ret = -EINVAL;
5433 goto exit;
5434 }
5435
5436 arvif->fixed_nss = fixed_nss;
5437
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005438 vdev_param = ar->wmi.vdev_param->sgi;
5439 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5440 force_sgi);
5441
5442 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005443 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005444 force_sgi, ret);
5445 ret = -EINVAL;
5446 goto exit;
5447 }
5448
5449 arvif->force_sgi = force_sgi;
5450
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005451exit:
5452 mutex_unlock(&ar->conf_mutex);
5453 return ret;
5454}
5455
5456static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5457 struct ieee80211_vif *vif,
5458 const struct cfg80211_bitrate_mask *mask)
5459{
5460 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5461 struct ath10k *ar = arvif->ar;
5462 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5463 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5464 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005465 u8 force_sgi;
5466
Ben Greearb116ea12014-11-24 16:22:10 +02005467 if (ar->cfg_tx_chainmask)
5468 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5469
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005470 force_sgi = mask->control[band].gi;
5471 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5472 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005473
5474 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005475 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005476 &fixed_rate,
5477 &fixed_nss))
5478 return -EINVAL;
5479 }
5480
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005481 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005482 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005483 return -EINVAL;
5484 }
5485
5486 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5487 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005488}
5489
Michal Kazior9797feb2014-02-14 14:49:48 +01005490static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5491 struct ieee80211_vif *vif,
5492 struct ieee80211_sta *sta,
5493 u32 changed)
5494{
5495 struct ath10k *ar = hw->priv;
5496 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5497 u32 bw, smps;
5498
5499 spin_lock_bh(&ar->data_lock);
5500
Michal Kazior7aa7a722014-08-25 12:09:38 +02005501 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005502 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5503 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5504 sta->smps_mode);
5505
5506 if (changed & IEEE80211_RC_BW_CHANGED) {
5507 bw = WMI_PEER_CHWIDTH_20MHZ;
5508
5509 switch (sta->bandwidth) {
5510 case IEEE80211_STA_RX_BW_20:
5511 bw = WMI_PEER_CHWIDTH_20MHZ;
5512 break;
5513 case IEEE80211_STA_RX_BW_40:
5514 bw = WMI_PEER_CHWIDTH_40MHZ;
5515 break;
5516 case IEEE80211_STA_RX_BW_80:
5517 bw = WMI_PEER_CHWIDTH_80MHZ;
5518 break;
5519 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005520 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005521 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005522 bw = WMI_PEER_CHWIDTH_20MHZ;
5523 break;
5524 }
5525
5526 arsta->bw = bw;
5527 }
5528
5529 if (changed & IEEE80211_RC_NSS_CHANGED)
5530 arsta->nss = sta->rx_nss;
5531
5532 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5533 smps = WMI_PEER_SMPS_PS_NONE;
5534
5535 switch (sta->smps_mode) {
5536 case IEEE80211_SMPS_AUTOMATIC:
5537 case IEEE80211_SMPS_OFF:
5538 smps = WMI_PEER_SMPS_PS_NONE;
5539 break;
5540 case IEEE80211_SMPS_STATIC:
5541 smps = WMI_PEER_SMPS_STATIC;
5542 break;
5543 case IEEE80211_SMPS_DYNAMIC:
5544 smps = WMI_PEER_SMPS_DYNAMIC;
5545 break;
5546 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005547 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005548 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005549 smps = WMI_PEER_SMPS_PS_NONE;
5550 break;
5551 }
5552
5553 arsta->smps = smps;
5554 }
5555
Michal Kazior9797feb2014-02-14 14:49:48 +01005556 arsta->changed |= changed;
5557
5558 spin_unlock_bh(&ar->data_lock);
5559
5560 ieee80211_queue_work(hw, &arsta->update_wk);
5561}
5562
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005563static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5564{
5565 /*
5566 * FIXME: Return 0 for time being. Need to figure out whether FW
5567 * has the API to fetch 64-bit local TSF
5568 */
5569
5570 return 0;
5571}
5572
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005573static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5574 struct ieee80211_vif *vif,
5575 enum ieee80211_ampdu_mlme_action action,
5576 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5577 u8 buf_size)
5578{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005579 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005580 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5581
Michal Kazior7aa7a722014-08-25 12:09:38 +02005582 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 +02005583 arvif->vdev_id, sta->addr, tid, action);
5584
5585 switch (action) {
5586 case IEEE80211_AMPDU_RX_START:
5587 case IEEE80211_AMPDU_RX_STOP:
5588 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5589 * creation/removal. Do we need to verify this?
5590 */
5591 return 0;
5592 case IEEE80211_AMPDU_TX_START:
5593 case IEEE80211_AMPDU_TX_STOP_CONT:
5594 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5595 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5596 case IEEE80211_AMPDU_TX_OPERATIONAL:
5597 /* Firmware offloads Tx aggregation entirely so deny mac80211
5598 * Tx aggregation requests.
5599 */
5600 return -EOPNOTSUPP;
5601 }
5602
5603 return -EINVAL;
5604}
5605
Kalle Valo5e3dd152013-06-12 20:52:10 +03005606static const struct ieee80211_ops ath10k_ops = {
5607 .tx = ath10k_tx,
5608 .start = ath10k_start,
5609 .stop = ath10k_stop,
5610 .config = ath10k_config,
5611 .add_interface = ath10k_add_interface,
5612 .remove_interface = ath10k_remove_interface,
5613 .configure_filter = ath10k_configure_filter,
5614 .bss_info_changed = ath10k_bss_info_changed,
5615 .hw_scan = ath10k_hw_scan,
5616 .cancel_hw_scan = ath10k_cancel_hw_scan,
5617 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005618 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005619 .sta_state = ath10k_sta_state,
5620 .conf_tx = ath10k_conf_tx,
5621 .remain_on_channel = ath10k_remain_on_channel,
5622 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5623 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005624 .flush = ath10k_flush,
5625 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005626 .set_antenna = ath10k_set_antenna,
5627 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005628 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005629 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005630 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005631 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005632 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005633 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005634 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5635 .get_et_stats = ath10k_debug_get_et_stats,
5636 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005637
5638 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5639
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005640#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005641 .suspend = ath10k_wow_op_suspend,
5642 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005643#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005644#ifdef CONFIG_MAC80211_DEBUGFS
5645 .sta_add_debugfs = ath10k_sta_add_debugfs,
5646#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005647};
5648
5649#define RATETAB_ENT(_rate, _rateid, _flags) { \
5650 .bitrate = (_rate), \
5651 .flags = (_flags), \
5652 .hw_value = (_rateid), \
5653}
5654
5655#define CHAN2G(_channel, _freq, _flags) { \
5656 .band = IEEE80211_BAND_2GHZ, \
5657 .hw_value = (_channel), \
5658 .center_freq = (_freq), \
5659 .flags = (_flags), \
5660 .max_antenna_gain = 0, \
5661 .max_power = 30, \
5662}
5663
5664#define CHAN5G(_channel, _freq, _flags) { \
5665 .band = IEEE80211_BAND_5GHZ, \
5666 .hw_value = (_channel), \
5667 .center_freq = (_freq), \
5668 .flags = (_flags), \
5669 .max_antenna_gain = 0, \
5670 .max_power = 30, \
5671}
5672
5673static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5674 CHAN2G(1, 2412, 0),
5675 CHAN2G(2, 2417, 0),
5676 CHAN2G(3, 2422, 0),
5677 CHAN2G(4, 2427, 0),
5678 CHAN2G(5, 2432, 0),
5679 CHAN2G(6, 2437, 0),
5680 CHAN2G(7, 2442, 0),
5681 CHAN2G(8, 2447, 0),
5682 CHAN2G(9, 2452, 0),
5683 CHAN2G(10, 2457, 0),
5684 CHAN2G(11, 2462, 0),
5685 CHAN2G(12, 2467, 0),
5686 CHAN2G(13, 2472, 0),
5687 CHAN2G(14, 2484, 0),
5688};
5689
5690static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005691 CHAN5G(36, 5180, 0),
5692 CHAN5G(40, 5200, 0),
5693 CHAN5G(44, 5220, 0),
5694 CHAN5G(48, 5240, 0),
5695 CHAN5G(52, 5260, 0),
5696 CHAN5G(56, 5280, 0),
5697 CHAN5G(60, 5300, 0),
5698 CHAN5G(64, 5320, 0),
5699 CHAN5G(100, 5500, 0),
5700 CHAN5G(104, 5520, 0),
5701 CHAN5G(108, 5540, 0),
5702 CHAN5G(112, 5560, 0),
5703 CHAN5G(116, 5580, 0),
5704 CHAN5G(120, 5600, 0),
5705 CHAN5G(124, 5620, 0),
5706 CHAN5G(128, 5640, 0),
5707 CHAN5G(132, 5660, 0),
5708 CHAN5G(136, 5680, 0),
5709 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005710 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005711 CHAN5G(149, 5745, 0),
5712 CHAN5G(153, 5765, 0),
5713 CHAN5G(157, 5785, 0),
5714 CHAN5G(161, 5805, 0),
5715 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005716};
5717
Michal Kazior91b12082014-12-12 12:41:35 +01005718/* Note: Be careful if you re-order these. There is code which depends on this
5719 * ordering.
5720 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005721static struct ieee80211_rate ath10k_rates[] = {
5722 /* CCK */
5723 RATETAB_ENT(10, 0x82, 0),
5724 RATETAB_ENT(20, 0x84, 0),
5725 RATETAB_ENT(55, 0x8b, 0),
5726 RATETAB_ENT(110, 0x96, 0),
5727 /* OFDM */
5728 RATETAB_ENT(60, 0x0c, 0),
5729 RATETAB_ENT(90, 0x12, 0),
5730 RATETAB_ENT(120, 0x18, 0),
5731 RATETAB_ENT(180, 0x24, 0),
5732 RATETAB_ENT(240, 0x30, 0),
5733 RATETAB_ENT(360, 0x48, 0),
5734 RATETAB_ENT(480, 0x60, 0),
5735 RATETAB_ENT(540, 0x6c, 0),
5736};
5737
5738#define ath10k_a_rates (ath10k_rates + 4)
5739#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5740#define ath10k_g_rates (ath10k_rates + 0)
5741#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5742
Michal Kaziore7b54192014-08-07 11:03:27 +02005743struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005744{
5745 struct ieee80211_hw *hw;
5746 struct ath10k *ar;
5747
Michal Kaziore7b54192014-08-07 11:03:27 +02005748 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005749 if (!hw)
5750 return NULL;
5751
5752 ar = hw->priv;
5753 ar->hw = hw;
5754
5755 return ar;
5756}
5757
5758void ath10k_mac_destroy(struct ath10k *ar)
5759{
5760 ieee80211_free_hw(ar->hw);
5761}
5762
5763static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5764 {
5765 .max = 8,
5766 .types = BIT(NL80211_IFTYPE_STATION)
5767 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005768 },
5769 {
5770 .max = 3,
5771 .types = BIT(NL80211_IFTYPE_P2P_GO)
5772 },
5773 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005774 .max = 1,
5775 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5776 },
5777 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005778 .max = 7,
5779 .types = BIT(NL80211_IFTYPE_AP)
5780 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005781};
5782
Bartosz Markowskif2595092013-12-10 16:20:39 +01005783static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005784 {
5785 .max = 8,
5786 .types = BIT(NL80211_IFTYPE_AP)
5787 },
5788};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005789
5790static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5791 {
5792 .limits = ath10k_if_limits,
5793 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5794 .max_interfaces = 8,
5795 .num_different_channels = 1,
5796 .beacon_int_infra_match = true,
5797 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005798};
5799
5800static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005801 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005802 .limits = ath10k_10x_if_limits,
5803 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005804 .max_interfaces = 8,
5805 .num_different_channels = 1,
5806 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005807#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005808 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5809 BIT(NL80211_CHAN_WIDTH_20) |
5810 BIT(NL80211_CHAN_WIDTH_40) |
5811 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005812#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005813 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005814};
5815
5816static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5817{
5818 struct ieee80211_sta_vht_cap vht_cap = {0};
5819 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005820 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005821 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005822
5823 vht_cap.vht_supported = 1;
5824 vht_cap.cap = ar->vht_cap_info;
5825
Michal Kaziorbc657a362015-02-26 11:11:22 +01005826 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5827 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5828 val = ar->num_rf_chains - 1;
5829 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5830 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5831
5832 vht_cap.cap |= val;
5833 }
5834
5835 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5836 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5837 val = ar->num_rf_chains - 1;
5838 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5839 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5840
5841 vht_cap.cap |= val;
5842 }
5843
Michal Kazior8865bee42013-07-24 12:36:46 +02005844 mcs_map = 0;
5845 for (i = 0; i < 8; i++) {
5846 if (i < ar->num_rf_chains)
5847 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5848 else
5849 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5850 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005851
5852 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5853 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5854
5855 return vht_cap;
5856}
5857
5858static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5859{
5860 int i;
5861 struct ieee80211_sta_ht_cap ht_cap = {0};
5862
5863 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5864 return ht_cap;
5865
5866 ht_cap.ht_supported = 1;
5867 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5868 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5869 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5870 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5871 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5872
5873 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5874 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5875
5876 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5877 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5878
5879 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5880 u32 smps;
5881
5882 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5883 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5884
5885 ht_cap.cap |= smps;
5886 }
5887
5888 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5889 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5890
5891 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5892 u32 stbc;
5893
5894 stbc = ar->ht_cap_info;
5895 stbc &= WMI_HT_CAP_RX_STBC;
5896 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5897 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5898 stbc &= IEEE80211_HT_CAP_RX_STBC;
5899
5900 ht_cap.cap |= stbc;
5901 }
5902
5903 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5904 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5905
5906 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5907 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5908
5909 /* max AMSDU is implicitly taken from vht_cap_info */
5910 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5911 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5912
Michal Kazior8865bee42013-07-24 12:36:46 +02005913 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005914 ht_cap.mcs.rx_mask[i] = 0xFF;
5915
5916 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5917
5918 return ht_cap;
5919}
5920
Kalle Valo5e3dd152013-06-12 20:52:10 +03005921static void ath10k_get_arvif_iter(void *data, u8 *mac,
5922 struct ieee80211_vif *vif)
5923{
5924 struct ath10k_vif_iter *arvif_iter = data;
5925 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5926
5927 if (arvif->vdev_id == arvif_iter->vdev_id)
5928 arvif_iter->arvif = arvif;
5929}
5930
5931struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5932{
5933 struct ath10k_vif_iter arvif_iter;
5934 u32 flags;
5935
5936 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5937 arvif_iter.vdev_id = vdev_id;
5938
5939 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5940 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5941 flags,
5942 ath10k_get_arvif_iter,
5943 &arvif_iter);
5944 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005945 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005946 return NULL;
5947 }
5948
5949 return arvif_iter.arvif;
5950}
5951
5952int ath10k_mac_register(struct ath10k *ar)
5953{
Johannes Berg3cb10942015-01-22 21:38:45 +01005954 static const u32 cipher_suites[] = {
5955 WLAN_CIPHER_SUITE_WEP40,
5956 WLAN_CIPHER_SUITE_WEP104,
5957 WLAN_CIPHER_SUITE_TKIP,
5958 WLAN_CIPHER_SUITE_CCMP,
5959 WLAN_CIPHER_SUITE_AES_CMAC,
5960 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005961 struct ieee80211_supported_band *band;
5962 struct ieee80211_sta_vht_cap vht_cap;
5963 struct ieee80211_sta_ht_cap ht_cap;
5964 void *channels;
5965 int ret;
5966
5967 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5968
5969 SET_IEEE80211_DEV(ar->hw, ar->dev);
5970
5971 ht_cap = ath10k_get_ht_cap(ar);
5972 vht_cap = ath10k_create_vht_cap(ar);
5973
5974 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5975 channels = kmemdup(ath10k_2ghz_channels,
5976 sizeof(ath10k_2ghz_channels),
5977 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005978 if (!channels) {
5979 ret = -ENOMEM;
5980 goto err_free;
5981 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005982
5983 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5984 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5985 band->channels = channels;
5986 band->n_bitrates = ath10k_g_rates_size;
5987 band->bitrates = ath10k_g_rates;
5988 band->ht_cap = ht_cap;
5989
Yanbo Lid68bb122015-01-23 08:18:20 +08005990 /* Enable the VHT support at 2.4 GHz */
5991 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005992
5993 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5994 }
5995
5996 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5997 channels = kmemdup(ath10k_5ghz_channels,
5998 sizeof(ath10k_5ghz_channels),
5999 GFP_KERNEL);
6000 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006001 ret = -ENOMEM;
6002 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006003 }
6004
6005 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6006 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6007 band->channels = channels;
6008 band->n_bitrates = ath10k_a_rates_size;
6009 band->bitrates = ath10k_a_rates;
6010 band->ht_cap = ht_cap;
6011 band->vht_cap = vht_cap;
6012 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6013 }
6014
6015 ar->hw->wiphy->interface_modes =
6016 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006017 BIT(NL80211_IFTYPE_AP);
6018
Ben Greear46acf7b2014-05-16 17:15:38 +03006019 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6020 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6021
Bartosz Markowskid3541812013-12-10 16:20:40 +01006022 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6023 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006024 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006025 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6026 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006027
6028 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6029 IEEE80211_HW_SUPPORTS_PS |
6030 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006031 IEEE80211_HW_MFP_CAPABLE |
6032 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6033 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006034 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006035 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006036 IEEE80211_HW_SW_CRYPTO_CONTROL |
6037 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006038
Eliad Peller0d8614b2014-09-10 14:07:36 +03006039 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6040
Kalle Valo5e3dd152013-06-12 20:52:10 +03006041 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006042 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006043
6044 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6045 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6046 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6047 }
6048
6049 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6050 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6051
6052 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006053 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006054
Kalle Valo5e3dd152013-06-12 20:52:10 +03006055 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6056
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006057 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6058 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6059
6060 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6061 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6062 * correct Probe Responses. This is more of a hack advert..
6063 */
6064 ar->hw->wiphy->probe_resp_offload |=
6065 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6066 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6067 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6068 }
6069
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006070 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6071 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6072
Kalle Valo5e3dd152013-06-12 20:52:10 +03006073 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006074 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006075 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6076
6077 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006078 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6079
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006080 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6081
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006082 ret = ath10k_wow_init(ar);
6083 if (ret) {
6084 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6085 goto err_free;
6086 }
6087
Kalle Valo5e3dd152013-06-12 20:52:10 +03006088 /*
6089 * on LL hardware queues are managed entirely by the FW
6090 * so we only advertise to mac we can do the queues thing
6091 */
6092 ar->hw->queues = 4;
6093
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006094 switch (ar->wmi.op_version) {
6095 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6096 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006097 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6098 ar->hw->wiphy->n_iface_combinations =
6099 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006100 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006101 break;
6102 case ATH10K_FW_WMI_OP_VERSION_10_1:
6103 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006104 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006105 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6106 ar->hw->wiphy->n_iface_combinations =
6107 ARRAY_SIZE(ath10k_10x_if_comb);
6108 break;
6109 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6110 case ATH10K_FW_WMI_OP_VERSION_MAX:
6111 WARN_ON(1);
6112 ret = -EINVAL;
6113 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006114 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006115
Michal Kazior7c199992013-07-31 10:47:57 +02006116 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6117
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006118 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6119 /* Init ath dfs pattern detector */
6120 ar->ath_common.debug_mask = ATH_DBG_DFS;
6121 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6122 NL80211_DFS_UNSET);
6123
6124 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006125 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006126 }
6127
Kalle Valo5e3dd152013-06-12 20:52:10 +03006128 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6129 ath10k_reg_notifier);
6130 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006131 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006132 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006133 }
6134
Johannes Berg3cb10942015-01-22 21:38:45 +01006135 ar->hw->wiphy->cipher_suites = cipher_suites;
6136 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6137
Kalle Valo5e3dd152013-06-12 20:52:10 +03006138 ret = ieee80211_register_hw(ar->hw);
6139 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006140 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006141 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006142 }
6143
6144 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6145 ret = regulatory_hint(ar->hw->wiphy,
6146 ar->ath_common.regulatory.alpha2);
6147 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006148 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006149 }
6150
6151 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006152
6153err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006154 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006155err_free:
6156 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6157 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6158
Kalle Valo5e3dd152013-06-12 20:52:10 +03006159 return ret;
6160}
6161
6162void ath10k_mac_unregister(struct ath10k *ar)
6163{
6164 ieee80211_unregister_hw(ar->hw);
6165
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006166 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6167 ar->dfs_detector->exit(ar->dfs_detector);
6168
Kalle Valo5e3dd152013-06-12 20:52:10 +03006169 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6170 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6171
6172 SET_IEEE80211_DEV(ar->hw, NULL);
6173}