blob: cd806c50f3cb3973e517528b1877699281b9de7b [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"
Kalle Valo5e3dd152013-06-12 20:52:10 +030032
33/**********/
34/* Crypto */
35/**********/
36
37static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
39 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010040 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030041{
Michal Kazior7aa7a722014-08-25 12:09:38 +020042 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030043 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
47 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +010048 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 .macaddr = macaddr,
50 };
51
Michal Kazior548db542013-07-05 16:15:15 +030052 lockdep_assert_held(&arvif->ar->conf_mutex);
53
Kalle Valo5e3dd152013-06-12 20:52:10 +030054 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020057 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030058 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +030067 break;
Johannes Berg3cb10942015-01-22 21:38:45 +010068 case WLAN_CIPHER_SUITE_AES_CMAC:
69 /* this one needs to be done in software */
70 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +030071 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020072 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030073 return -EOPNOTSUPP;
74 }
75
76 if (cmd == DISABLE_KEY) {
77 arg.key_cipher = WMI_CIPHER_NONE;
78 arg.key_data = NULL;
79 }
80
81 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
82}
83
84static int ath10k_install_key(struct ath10k_vif *arvif,
85 struct ieee80211_key_conf *key,
86 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010087 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030088{
89 struct ath10k *ar = arvif->ar;
90 int ret;
91
Michal Kazior548db542013-07-05 16:15:15 +030092 lockdep_assert_held(&ar->conf_mutex);
93
Wolfram Sang16735d02013-11-14 14:32:02 -080094 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030095
Michal Kazior370e5672015-02-18 14:02:26 +010096 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +030097 if (ret)
98 return ret;
99
100 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
101 if (ret == 0)
102 return -ETIMEDOUT;
103
104 return 0;
105}
106
107static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
108 const u8 *addr)
109{
110 struct ath10k *ar = arvif->ar;
111 struct ath10k_peer *peer;
112 int ret;
113 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100114 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100128
129 flags = 0;
130 flags |= WMI_KEY_PAIRWISE;
131
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200132 /* set TX_USAGE flag for default key id */
133 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100134 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300135
136 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100137 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300138 if (ret)
139 return ret;
140
Sujith Manoharanae167132014-11-25 11:46:59 +0530141 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300142 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530143 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 }
145
146 return 0;
147}
148
149static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
150 const u8 *addr)
151{
152 struct ath10k *ar = arvif->ar;
153 struct ath10k_peer *peer;
154 int first_errno = 0;
155 int ret;
156 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100157 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300158
159 lockdep_assert_held(&ar->conf_mutex);
160
161 spin_lock_bh(&ar->data_lock);
162 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
163 spin_unlock_bh(&ar->data_lock);
164
165 if (!peer)
166 return -ENOENT;
167
168 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
169 if (peer->keys[i] == NULL)
170 continue;
171
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200172 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100174 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300175 if (ret && first_errno == 0)
176 first_errno = ret;
177
178 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200179 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 i, ret);
181
Sujith Manoharanae167132014-11-25 11:46:59 +0530182 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300183 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530184 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 }
186
187 return first_errno;
188}
189
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530190bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
191 u8 keyidx)
192{
193 struct ath10k_peer *peer;
194 int i;
195
196 lockdep_assert_held(&ar->data_lock);
197
198 /* We don't know which vdev this peer belongs to,
199 * since WMI doesn't give us that information.
200 *
201 * FIXME: multi-bss needs to be handled.
202 */
203 peer = ath10k_peer_find(ar, 0, addr);
204 if (!peer)
205 return false;
206
207 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
208 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
209 return true;
210 }
211
212 return false;
213}
214
Kalle Valo5e3dd152013-06-12 20:52:10 +0300215static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
216 struct ieee80211_key_conf *key)
217{
218 struct ath10k *ar = arvif->ar;
219 struct ath10k_peer *peer;
220 u8 addr[ETH_ALEN];
221 int first_errno = 0;
222 int ret;
223 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100224 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225
226 lockdep_assert_held(&ar->conf_mutex);
227
228 for (;;) {
229 /* since ath10k_install_key we can't hold data_lock all the
230 * time, so we try to remove the keys incrementally */
231 spin_lock_bh(&ar->data_lock);
232 i = 0;
233 list_for_each_entry(peer, &ar->peers, list) {
234 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
235 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300236 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300237 peer->keys[i] = NULL;
238 break;
239 }
240 }
241
242 if (i < ARRAY_SIZE(peer->keys))
243 break;
244 }
245 spin_unlock_bh(&ar->data_lock);
246
247 if (i == ARRAY_SIZE(peer->keys))
248 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200249 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100250 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 if (ret && first_errno == 0)
252 first_errno = ret;
253
254 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200255 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200256 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300257 }
258
259 return first_errno;
260}
261
Michal Kazior370e5672015-02-18 14:02:26 +0100262static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
263{
264 struct ath10k *ar = arvif->ar;
265 enum nl80211_iftype iftype = arvif->vif->type;
266 struct ieee80211_key_conf *key;
267 u32 flags = 0;
268 int num = 0;
269 int i;
270 int ret;
271
272 lockdep_assert_held(&ar->conf_mutex);
273
274 if (iftype != NL80211_IFTYPE_STATION)
275 return 0;
276
277 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
278 if (arvif->wep_keys[i]) {
279 key = arvif->wep_keys[i];
280 ++num;
281 }
282 }
283
284 if (num != 1)
285 return 0;
286
287 flags |= WMI_KEY_PAIRWISE;
288 flags |= WMI_KEY_TX_USAGE;
289
290 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
291 if (ret) {
292 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
293 key->keyidx, arvif->vdev_id, ret);
294 return ret;
295 }
296
297 return 0;
298}
299
Michal Kaziorad325cb2015-02-18 14:02:27 +0100300static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
301 struct ieee80211_key_conf *key)
302{
303 struct ath10k *ar = arvif->ar;
304 struct ath10k_peer *peer;
305 int ret;
306
307 lockdep_assert_held(&ar->conf_mutex);
308
309 list_for_each_entry(peer, &ar->peers, list) {
310 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
311 continue;
312
313 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
314 continue;
315
316 if (peer->keys[key->keyidx] == key)
317 continue;
318
319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
320 arvif->vdev_id, key->keyidx);
321
322 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
323 if (ret) {
324 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
325 arvif->vdev_id, peer->addr, ret);
326 return ret;
327 }
328 }
329
330 return 0;
331}
332
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333/*********************/
334/* General utilities */
335/*********************/
336
337static inline enum wmi_phy_mode
338chan_to_phymode(const struct cfg80211_chan_def *chandef)
339{
340 enum wmi_phy_mode phymode = MODE_UNKNOWN;
341
342 switch (chandef->chan->band) {
343 case IEEE80211_BAND_2GHZ:
344 switch (chandef->width) {
345 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800346 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
347 phymode = MODE_11B;
348 else
349 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300350 break;
351 case NL80211_CHAN_WIDTH_20:
352 phymode = MODE_11NG_HT20;
353 break;
354 case NL80211_CHAN_WIDTH_40:
355 phymode = MODE_11NG_HT40;
356 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400357 case NL80211_CHAN_WIDTH_5:
358 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300359 case NL80211_CHAN_WIDTH_80:
360 case NL80211_CHAN_WIDTH_80P80:
361 case NL80211_CHAN_WIDTH_160:
362 phymode = MODE_UNKNOWN;
363 break;
364 }
365 break;
366 case IEEE80211_BAND_5GHZ:
367 switch (chandef->width) {
368 case NL80211_CHAN_WIDTH_20_NOHT:
369 phymode = MODE_11A;
370 break;
371 case NL80211_CHAN_WIDTH_20:
372 phymode = MODE_11NA_HT20;
373 break;
374 case NL80211_CHAN_WIDTH_40:
375 phymode = MODE_11NA_HT40;
376 break;
377 case NL80211_CHAN_WIDTH_80:
378 phymode = MODE_11AC_VHT80;
379 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400380 case NL80211_CHAN_WIDTH_5:
381 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300382 case NL80211_CHAN_WIDTH_80P80:
383 case NL80211_CHAN_WIDTH_160:
384 phymode = MODE_UNKNOWN;
385 break;
386 }
387 break;
388 default:
389 break;
390 }
391
392 WARN_ON(phymode == MODE_UNKNOWN);
393 return phymode;
394}
395
396static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
397{
398/*
399 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
400 * 0 for no restriction
401 * 1 for 1/4 us
402 * 2 for 1/2 us
403 * 3 for 1 us
404 * 4 for 2 us
405 * 5 for 4 us
406 * 6 for 8 us
407 * 7 for 16 us
408 */
409 switch (mpdudensity) {
410 case 0:
411 return 0;
412 case 1:
413 case 2:
414 case 3:
415 /* Our lower layer calculations limit our precision to
416 1 microsecond */
417 return 1;
418 case 4:
419 return 2;
420 case 5:
421 return 4;
422 case 6:
423 return 8;
424 case 7:
425 return 16;
426 default:
427 return 0;
428 }
429}
430
431static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
432{
433 int ret;
434
435 lockdep_assert_held(&ar->conf_mutex);
436
Michal Kaziorcfd10612014-11-25 15:16:05 +0100437 if (ar->num_peers >= ar->max_num_peers)
438 return -ENOBUFS;
439
Kalle Valo5e3dd152013-06-12 20:52:10 +0300440 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800441 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200442 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200443 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300444 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800445 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300446
447 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800448 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200449 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200450 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300451 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800452 }
Michal Kazior292a7532014-11-25 15:16:04 +0100453
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100454 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300455
456 return 0;
457}
458
Kalle Valo5a13e762014-01-20 11:01:46 +0200459static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
460{
461 struct ath10k *ar = arvif->ar;
462 u32 param;
463 int ret;
464
465 param = ar->wmi.pdev_param->sta_kickout_th;
466 ret = ath10k_wmi_pdev_set_param(ar, param,
467 ATH10K_KICKOUT_THRESHOLD);
468 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200469 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200470 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200471 return ret;
472 }
473
474 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
475 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
476 ATH10K_KEEPALIVE_MIN_IDLE);
477 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200478 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200479 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200480 return ret;
481 }
482
483 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
484 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
485 ATH10K_KEEPALIVE_MAX_IDLE);
486 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200487 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200488 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200489 return ret;
490 }
491
492 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
493 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
494 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
495 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200496 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200497 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200498 return ret;
499 }
500
501 return 0;
502}
503
Vivek Natarajanacab6402014-11-26 09:06:12 +0200504static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200505{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200506 struct ath10k *ar = arvif->ar;
507 u32 vdev_param;
508
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200509 vdev_param = ar->wmi.vdev_param->rts_threshold;
510 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200511}
512
513static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
514{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200515 struct ath10k *ar = arvif->ar;
516 u32 vdev_param;
517
Michal Kazior424121c2013-07-22 14:13:31 +0200518 if (value != 0xFFFFFFFF)
519 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
520 ATH10K_FRAGMT_THRESHOLD_MIN,
521 ATH10K_FRAGMT_THRESHOLD_MAX);
522
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200523 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
524 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200525}
526
Kalle Valo5e3dd152013-06-12 20:52:10 +0300527static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
528{
529 int ret;
530
531 lockdep_assert_held(&ar->conf_mutex);
532
533 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
534 if (ret)
535 return ret;
536
537 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
538 if (ret)
539 return ret;
540
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100541 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100542
Kalle Valo5e3dd152013-06-12 20:52:10 +0300543 return 0;
544}
545
546static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
547{
548 struct ath10k_peer *peer, *tmp;
549
550 lockdep_assert_held(&ar->conf_mutex);
551
552 spin_lock_bh(&ar->data_lock);
553 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
554 if (peer->vdev_id != vdev_id)
555 continue;
556
Michal Kazior7aa7a722014-08-25 12:09:38 +0200557 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558 peer->addr, vdev_id);
559
560 list_del(&peer->list);
561 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100562 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563 }
564 spin_unlock_bh(&ar->data_lock);
565}
566
Michal Kaziora96d7742013-07-16 09:38:56 +0200567static void ath10k_peer_cleanup_all(struct ath10k *ar)
568{
569 struct ath10k_peer *peer, *tmp;
570
571 lockdep_assert_held(&ar->conf_mutex);
572
573 spin_lock_bh(&ar->data_lock);
574 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
575 list_del(&peer->list);
576 kfree(peer);
577 }
578 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100579
580 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100581 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200582}
583
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584/************************/
585/* Interface management */
586/************************/
587
Michal Kazior64badcb2014-09-18 11:18:02 +0300588void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
589{
590 struct ath10k *ar = arvif->ar;
591
592 lockdep_assert_held(&ar->data_lock);
593
594 if (!arvif->beacon)
595 return;
596
597 if (!arvif->beacon_buf)
598 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
599 arvif->beacon->len, DMA_TO_DEVICE);
600
Michal Kazioraf213192015-01-29 14:29:52 +0200601 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
602 arvif->beacon_state != ATH10K_BEACON_SENT))
603 return;
604
Michal Kazior64badcb2014-09-18 11:18:02 +0300605 dev_kfree_skb_any(arvif->beacon);
606
607 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200608 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300609}
610
611static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
612{
613 struct ath10k *ar = arvif->ar;
614
615 lockdep_assert_held(&ar->data_lock);
616
617 ath10k_mac_vif_beacon_free(arvif);
618
619 if (arvif->beacon_buf) {
620 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
621 arvif->beacon_buf, arvif->beacon_paddr);
622 arvif->beacon_buf = NULL;
623 }
624}
625
Kalle Valo5e3dd152013-06-12 20:52:10 +0300626static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
627{
628 int ret;
629
Michal Kazior548db542013-07-05 16:15:15 +0300630 lockdep_assert_held(&ar->conf_mutex);
631
Michal Kazior7962b0d2014-10-28 10:34:38 +0100632 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
633 return -ESHUTDOWN;
634
Kalle Valo5e3dd152013-06-12 20:52:10 +0300635 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
636 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
637 if (ret == 0)
638 return -ETIMEDOUT;
639
640 return 0;
641}
642
Michal Kazior1bbc0972014-04-08 09:45:47 +0300643static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300644{
Michal Kaziorc930f742014-01-23 11:38:25 +0100645 struct cfg80211_chan_def *chandef = &ar->chandef;
646 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300647 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648 int ret = 0;
649
650 lockdep_assert_held(&ar->conf_mutex);
651
Kalle Valo5e3dd152013-06-12 20:52:10 +0300652 arg.vdev_id = vdev_id;
653 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100654 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655
656 /* TODO setup this dynamically, what in case we
657 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100658 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200659 arg.channel.chan_radar =
660 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300661
Michal Kazior89c5c842013-10-23 04:02:13 -0700662 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700663 arg.channel.max_power = channel->max_power * 2;
664 arg.channel.max_reg_power = channel->max_reg_power * 2;
665 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666
Michal Kazior7962b0d2014-10-28 10:34:38 +0100667 reinit_completion(&ar->vdev_setup_done);
668
Kalle Valo5e3dd152013-06-12 20:52:10 +0300669 ret = ath10k_wmi_vdev_start(ar, &arg);
670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200671 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200672 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300673 return ret;
674 }
675
676 ret = ath10k_vdev_setup_sync(ar);
677 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200678 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200679 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680 return ret;
681 }
682
683 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200685 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200686 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300687 goto vdev_stop;
688 }
689
690 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300691
Michal Kazior7aa7a722014-08-25 12:09:38 +0200692 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300693 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 return 0;
695
696vdev_stop:
697 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
698 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200699 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200700 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300701
702 return ret;
703}
704
Michal Kazior1bbc0972014-04-08 09:45:47 +0300705static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300706{
707 int ret = 0;
708
709 lockdep_assert_held(&ar->conf_mutex);
710
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200711 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
712 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200713 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200714 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300715
Michal Kazior7962b0d2014-10-28 10:34:38 +0100716 reinit_completion(&ar->vdev_setup_done);
717
Kalle Valo5e3dd152013-06-12 20:52:10 +0300718 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200720 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200721 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300722
723 ret = ath10k_vdev_setup_sync(ar);
724 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200725 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200726 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300727
Michal Kazior7aa7a722014-08-25 12:09:38 +0200728 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300729 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300730 return ret;
731}
732
Michal Kazior1bbc0972014-04-08 09:45:47 +0300733static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300734{
735 int bit, ret = 0;
736
737 lockdep_assert_held(&ar->conf_mutex);
738
Ben Greeara9aefb32014-08-12 11:02:19 +0300739 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200740 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300741 return -ENOMEM;
742 }
743
Ben Greear16c11172014-09-23 14:17:16 -0700744 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300745
Ben Greear16c11172014-09-23 14:17:16 -0700746 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300747
748 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
749 WMI_VDEV_TYPE_MONITOR,
750 0, ar->mac_addr);
751 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200752 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200753 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300754 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300755 }
756
Ben Greear16c11172014-09-23 14:17:16 -0700757 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200758 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300759 ar->monitor_vdev_id);
760
Kalle Valo5e3dd152013-06-12 20:52:10 +0300761 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300762}
763
Michal Kazior1bbc0972014-04-08 09:45:47 +0300764static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300765{
766 int ret = 0;
767
768 lockdep_assert_held(&ar->conf_mutex);
769
Kalle Valo5e3dd152013-06-12 20:52:10 +0300770 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200772 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200773 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300774 return ret;
775 }
776
Ben Greear16c11172014-09-23 14:17:16 -0700777 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300778
Michal Kazior7aa7a722014-08-25 12:09:38 +0200779 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300780 ar->monitor_vdev_id);
781 return ret;
782}
783
Michal Kazior1bbc0972014-04-08 09:45:47 +0300784static int ath10k_monitor_start(struct ath10k *ar)
785{
786 int ret;
787
788 lockdep_assert_held(&ar->conf_mutex);
789
Michal Kazior1bbc0972014-04-08 09:45:47 +0300790 ret = ath10k_monitor_vdev_create(ar);
791 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200792 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300793 return ret;
794 }
795
796 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
797 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200798 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300799 ath10k_monitor_vdev_delete(ar);
800 return ret;
801 }
802
803 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200804 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300805
806 return 0;
807}
808
Michal Kazior19337472014-08-28 12:58:16 +0200809static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300810{
811 int ret;
812
813 lockdep_assert_held(&ar->conf_mutex);
814
Michal Kazior1bbc0972014-04-08 09:45:47 +0300815 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200816 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200817 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200818 return ret;
819 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300820
821 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200822 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200823 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200824 return ret;
825 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300826
827 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200829
830 return 0;
831}
832
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530833static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
834{
835 struct ath10k_vif *arvif;
836
837 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
838 return true;
839
840 if (!ar->num_started_vdevs)
841 return false;
842
843 list_for_each_entry(arvif, &ar->arvifs, list)
844 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
845 return false;
846
847 ath10k_dbg(ar, ATH10K_DBG_MAC,
848 "mac disabling promiscuous mode because vdev is started\n");
849 return true;
850}
851
Michal Kazior19337472014-08-28 12:58:16 +0200852static int ath10k_monitor_recalc(struct ath10k *ar)
853{
854 bool should_start;
855
856 lockdep_assert_held(&ar->conf_mutex);
857
858 should_start = ar->monitor ||
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530859 !ath10k_mac_should_disable_promisc(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200860 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
861
862 ath10k_dbg(ar, ATH10K_DBG_MAC,
863 "mac monitor recalc started? %d should? %d\n",
864 ar->monitor_started, should_start);
865
866 if (should_start == ar->monitor_started)
867 return 0;
868
869 if (should_start)
870 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300871
872 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300873}
874
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200875static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
876{
877 struct ath10k *ar = arvif->ar;
878 u32 vdev_param, rts_cts = 0;
879
880 lockdep_assert_held(&ar->conf_mutex);
881
882 vdev_param = ar->wmi.vdev_param->enable_rtscts;
883
884 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
885 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
886
887 if (arvif->num_legacy_stations > 0)
888 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
889 WMI_RTSCTS_PROFILE);
890
891 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
892 rts_cts);
893}
894
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200895static int ath10k_start_cac(struct ath10k *ar)
896{
897 int ret;
898
899 lockdep_assert_held(&ar->conf_mutex);
900
901 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
902
Michal Kazior19337472014-08-28 12:58:16 +0200903 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200904 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200905 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200906 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
907 return ret;
908 }
909
Michal Kazior7aa7a722014-08-25 12:09:38 +0200910 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200911 ar->monitor_vdev_id);
912
913 return 0;
914}
915
916static int ath10k_stop_cac(struct ath10k *ar)
917{
918 lockdep_assert_held(&ar->conf_mutex);
919
920 /* CAC is not running - do nothing */
921 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
922 return 0;
923
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200924 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300925 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200926
Michal Kazior7aa7a722014-08-25 12:09:38 +0200927 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200928
929 return 0;
930}
931
Michal Kaziord6500972014-04-08 09:56:09 +0300932static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200933{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200934 int ret;
935
936 lockdep_assert_held(&ar->conf_mutex);
937
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200938 ath10k_stop_cac(ar);
939
Michal Kaziord6500972014-04-08 09:56:09 +0300940 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200941 return;
942
Michal Kaziord6500972014-04-08 09:56:09 +0300943 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200944 return;
945
946 ret = ath10k_start_cac(ar);
947 if (ret) {
948 /*
949 * Not possible to start CAC on current channel so starting
950 * radiation is not allowed, make this channel DFS_UNAVAILABLE
951 * by indicating that radar was detected.
952 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200953 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200954 ieee80211_radar_detected(ar->hw);
955 }
956}
957
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530958static int ath10k_vdev_stop(struct ath10k_vif *arvif)
959{
960 struct ath10k *ar = arvif->ar;
961 int ret;
962
963 lockdep_assert_held(&ar->conf_mutex);
964
965 reinit_completion(&ar->vdev_setup_done);
966
967 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
968 if (ret) {
969 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
970 arvif->vdev_id, ret);
971 return ret;
972 }
973
974 ret = ath10k_vdev_setup_sync(ar);
975 if (ret) {
976 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
977 arvif->vdev_id, ret);
978 return ret;
979 }
980
981 WARN_ON(ar->num_started_vdevs == 0);
982
983 if (ar->num_started_vdevs != 0) {
984 ar->num_started_vdevs--;
985 ath10k_recalc_radar_detection(ar);
986 }
987
988 return ret;
989}
990
Michal Kaziordc55e302014-07-29 12:53:36 +0300991static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300992{
993 struct ath10k *ar = arvif->ar;
994 struct cfg80211_chan_def *chandef = &ar->chandef;
995 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530996 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +0300997
998 lockdep_assert_held(&ar->conf_mutex);
999
1000 reinit_completion(&ar->vdev_setup_done);
1001
1002 arg.vdev_id = arvif->vdev_id;
1003 arg.dtim_period = arvif->dtim_period;
1004 arg.bcn_intval = arvif->beacon_interval;
1005
1006 arg.channel.freq = chandef->chan->center_freq;
1007 arg.channel.band_center_freq1 = chandef->center_freq1;
1008 arg.channel.mode = chan_to_phymode(chandef);
1009
1010 arg.channel.min_power = 0;
1011 arg.channel.max_power = chandef->chan->max_power * 2;
1012 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1013 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1014
1015 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1016 arg.ssid = arvif->u.ap.ssid;
1017 arg.ssid_len = arvif->u.ap.ssid_len;
1018 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1019
1020 /* For now allow DFS for AP mode */
1021 arg.channel.chan_radar =
1022 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1023 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1024 arg.ssid = arvif->vif->bss_conf.ssid;
1025 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1026 }
1027
Michal Kazior7aa7a722014-08-25 12:09:38 +02001028 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001029 "mac vdev %d start center_freq %d phymode %s\n",
1030 arg.vdev_id, arg.channel.freq,
1031 ath10k_wmi_phymode_str(arg.channel.mode));
1032
Michal Kaziordc55e302014-07-29 12:53:36 +03001033 if (restart)
1034 ret = ath10k_wmi_vdev_restart(ar, &arg);
1035 else
1036 ret = ath10k_wmi_vdev_start(ar, &arg);
1037
Michal Kazior72654fa2014-04-08 09:56:09 +03001038 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001039 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001040 arg.vdev_id, ret);
1041 return ret;
1042 }
1043
1044 ret = ath10k_vdev_setup_sync(ar);
1045 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001046 ath10k_warn(ar,
1047 "failed to synchronize setup for vdev %i restart %d: %d\n",
1048 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001049 return ret;
1050 }
1051
Michal Kaziord6500972014-04-08 09:56:09 +03001052 ar->num_started_vdevs++;
1053 ath10k_recalc_radar_detection(ar);
1054
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301055 ret = ath10k_monitor_recalc(ar);
1056 if (ret) {
1057 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1058 arg.vdev_id, restart, ret);
1059 ret2 = ath10k_vdev_stop(arvif);
1060 if (ret2)
1061 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1062 arg.vdev_id, restart, ret2);
1063 }
1064
Michal Kazior72654fa2014-04-08 09:56:09 +03001065 return ret;
1066}
1067
Michal Kaziordc55e302014-07-29 12:53:36 +03001068static int ath10k_vdev_start(struct ath10k_vif *arvif)
1069{
1070 return ath10k_vdev_start_restart(arvif, false);
1071}
1072
1073static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1074{
1075 return ath10k_vdev_start_restart(arvif, true);
1076}
1077
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001078static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1079 struct sk_buff *bcn)
1080{
1081 struct ath10k *ar = arvif->ar;
1082 struct ieee80211_mgmt *mgmt;
1083 const u8 *p2p_ie;
1084 int ret;
1085
1086 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1087 return 0;
1088
1089 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1090 return 0;
1091
1092 mgmt = (void *)bcn->data;
1093 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1094 mgmt->u.beacon.variable,
1095 bcn->len - (mgmt->u.beacon.variable -
1096 bcn->data));
1097 if (!p2p_ie)
1098 return -ENOENT;
1099
1100 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1101 if (ret) {
1102 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1103 arvif->vdev_id, ret);
1104 return ret;
1105 }
1106
1107 return 0;
1108}
1109
1110static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1111 u8 oui_type, size_t ie_offset)
1112{
1113 size_t len;
1114 const u8 *next;
1115 const u8 *end;
1116 u8 *ie;
1117
1118 if (WARN_ON(skb->len < ie_offset))
1119 return -EINVAL;
1120
1121 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1122 skb->data + ie_offset,
1123 skb->len - ie_offset);
1124 if (!ie)
1125 return -ENOENT;
1126
1127 len = ie[1] + 2;
1128 end = skb->data + skb->len;
1129 next = ie + len;
1130
1131 if (WARN_ON(next > end))
1132 return -EINVAL;
1133
1134 memmove(ie, next, end - next);
1135 skb_trim(skb, skb->len - len);
1136
1137 return 0;
1138}
1139
1140static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1141{
1142 struct ath10k *ar = arvif->ar;
1143 struct ieee80211_hw *hw = ar->hw;
1144 struct ieee80211_vif *vif = arvif->vif;
1145 struct ieee80211_mutable_offsets offs = {};
1146 struct sk_buff *bcn;
1147 int ret;
1148
1149 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1150 return 0;
1151
Michal Kazior81a9a172015-03-05 16:02:17 +02001152 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1153 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1154 return 0;
1155
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001156 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1157 if (!bcn) {
1158 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1159 return -EPERM;
1160 }
1161
1162 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1163 if (ret) {
1164 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1165 kfree_skb(bcn);
1166 return ret;
1167 }
1168
1169 /* P2P IE is inserted by firmware automatically (as configured above)
1170 * so remove it from the base beacon template to avoid duplicate P2P
1171 * IEs in beacon frames.
1172 */
1173 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1174 offsetof(struct ieee80211_mgmt,
1175 u.beacon.variable));
1176
1177 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1178 0, NULL, 0);
1179 kfree_skb(bcn);
1180
1181 if (ret) {
1182 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1183 ret);
1184 return ret;
1185 }
1186
1187 return 0;
1188}
1189
1190static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1191{
1192 struct ath10k *ar = arvif->ar;
1193 struct ieee80211_hw *hw = ar->hw;
1194 struct ieee80211_vif *vif = arvif->vif;
1195 struct sk_buff *prb;
1196 int ret;
1197
1198 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1199 return 0;
1200
Michal Kazior81a9a172015-03-05 16:02:17 +02001201 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1202 return 0;
1203
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001204 prb = ieee80211_proberesp_get(hw, vif);
1205 if (!prb) {
1206 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1207 return -EPERM;
1208 }
1209
1210 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1211 kfree_skb(prb);
1212
1213 if (ret) {
1214 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1215 ret);
1216 return ret;
1217 }
1218
1219 return 0;
1220}
1221
Kalle Valo5e3dd152013-06-12 20:52:10 +03001222static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001223 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001224{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001225 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226 int ret = 0;
1227
Michal Kazior548db542013-07-05 16:15:15 +03001228 lockdep_assert_held(&arvif->ar->conf_mutex);
1229
Kalle Valo5e3dd152013-06-12 20:52:10 +03001230 if (!info->enable_beacon) {
1231 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001232
1233 arvif->is_started = false;
1234 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001235
1236 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001237 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001238 spin_unlock_bh(&arvif->ar->data_lock);
1239
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240 return;
1241 }
1242
1243 arvif->tx_seq_no = 0x1000;
1244
1245 ret = ath10k_vdev_start(arvif);
1246 if (ret)
1247 return;
1248
Michal Kaziorc930f742014-01-23 11:38:25 +01001249 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001250 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001251
1252 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1253 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001255 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001256 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001257 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 return;
1259 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001260
1261 arvif->is_started = true;
1262 arvif->is_up = true;
1263
Michal Kazior7aa7a722014-08-25 12:09:38 +02001264 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001265}
1266
1267static void ath10k_control_ibss(struct ath10k_vif *arvif,
1268 struct ieee80211_bss_conf *info,
1269 const u8 self_peer[ETH_ALEN])
1270{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001271 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001272 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001273 int ret = 0;
1274
Michal Kazior548db542013-07-05 16:15:15 +03001275 lockdep_assert_held(&arvif->ar->conf_mutex);
1276
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277 if (!info->ibss_joined) {
1278 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1279 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001280 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 self_peer, arvif->vdev_id, ret);
1282
Michal Kaziorc930f742014-01-23 11:38:25 +01001283 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001284 return;
1285
Michal Kaziorc930f742014-01-23 11:38:25 +01001286 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287
1288 return;
1289 }
1290
1291 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1292 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001293 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001294 self_peer, arvif->vdev_id, ret);
1295 return;
1296 }
1297
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001298 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1299 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001300 ATH10K_DEFAULT_ATIM);
1301 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001302 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001303 arvif->vdev_id, ret);
1304}
1305
Michal Kazior9f9b5742014-12-12 12:41:36 +01001306static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1307{
1308 struct ath10k *ar = arvif->ar;
1309 u32 param;
1310 u32 value;
1311 int ret;
1312
1313 lockdep_assert_held(&arvif->ar->conf_mutex);
1314
1315 if (arvif->u.sta.uapsd)
1316 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1317 else
1318 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1319
1320 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1321 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1322 if (ret) {
1323 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1324 value, arvif->vdev_id, ret);
1325 return ret;
1326 }
1327
1328 return 0;
1329}
1330
1331static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1332{
1333 struct ath10k *ar = arvif->ar;
1334 u32 param;
1335 u32 value;
1336 int ret;
1337
1338 lockdep_assert_held(&arvif->ar->conf_mutex);
1339
1340 if (arvif->u.sta.uapsd)
1341 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1342 else
1343 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1344
1345 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1346 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1347 param, value);
1348 if (ret) {
1349 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1350 value, arvif->vdev_id, ret);
1351 return ret;
1352 }
1353
1354 return 0;
1355}
1356
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001357static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1358{
1359 struct ath10k_vif *arvif;
1360 int num = 0;
1361
1362 lockdep_assert_held(&ar->conf_mutex);
1363
1364 list_for_each_entry(arvif, &ar->arvifs, list)
1365 if (arvif->ps)
1366 num++;
1367
1368 return num;
1369}
1370
Michal Kaziorad088bf2013-10-16 15:44:46 +03001371static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001372{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001373 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001374 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001375 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001376 enum wmi_sta_powersave_param param;
1377 enum wmi_sta_ps_mode psmode;
1378 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001379 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001380 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381
Michal Kazior548db542013-07-05 16:15:15 +03001382 lockdep_assert_held(&arvif->ar->conf_mutex);
1383
Michal Kaziorad088bf2013-10-16 15:44:46 +03001384 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1385 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001387 enable_ps = arvif->ps;
1388
1389 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1390 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1391 ar->fw_features)) {
1392 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1393 arvif->vdev_id);
1394 enable_ps = false;
1395 }
1396
1397 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398 psmode = WMI_STA_PS_MODE_ENABLED;
1399 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1400
Michal Kazior526549a2014-12-12 12:41:37 +01001401 ps_timeout = conf->dynamic_ps_timeout;
1402 if (ps_timeout == 0) {
1403 /* Firmware doesn't like 0 */
1404 ps_timeout = ieee80211_tu_to_usec(
1405 vif->bss_conf.beacon_int) / 1000;
1406 }
1407
Michal Kaziorad088bf2013-10-16 15:44:46 +03001408 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001409 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001411 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001412 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001413 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001414 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001415 } else {
1416 psmode = WMI_STA_PS_MODE_DISABLED;
1417 }
1418
Michal Kazior7aa7a722014-08-25 12:09:38 +02001419 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001420 arvif->vdev_id, psmode ? "enable" : "disable");
1421
Michal Kaziorad088bf2013-10-16 15:44:46 +03001422 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1423 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001424 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001425 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001426 return ret;
1427 }
1428
1429 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001430}
1431
Michal Kazior46725b152015-01-28 09:57:49 +02001432static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1433{
1434 struct ath10k *ar = arvif->ar;
1435 struct wmi_sta_keepalive_arg arg = {};
1436 int ret;
1437
1438 lockdep_assert_held(&arvif->ar->conf_mutex);
1439
1440 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1441 return 0;
1442
1443 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1444 return 0;
1445
1446 /* Some firmware revisions have a bug and ignore the `enabled` field.
1447 * Instead use the interval to disable the keepalive.
1448 */
1449 arg.vdev_id = arvif->vdev_id;
1450 arg.enabled = 1;
1451 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1452 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1453
1454 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1455 if (ret) {
1456 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1457 arvif->vdev_id, ret);
1458 return ret;
1459 }
1460
1461 return 0;
1462}
1463
Michal Kazior81a9a172015-03-05 16:02:17 +02001464static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1465{
1466 struct ath10k *ar = arvif->ar;
1467 struct ieee80211_vif *vif = arvif->vif;
1468 int ret;
1469
Michal Kazior8513d952015-03-09 14:19:24 +01001470 lockdep_assert_held(&arvif->ar->conf_mutex);
1471
1472 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1473 return;
1474
Michal Kazior81a9a172015-03-05 16:02:17 +02001475 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1476 return;
1477
1478 if (!vif->csa_active)
1479 return;
1480
1481 if (!arvif->is_up)
1482 return;
1483
1484 if (!ieee80211_csa_is_complete(vif)) {
1485 ieee80211_csa_update_counter(vif);
1486
1487 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1488 if (ret)
1489 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1490 ret);
1491
1492 ret = ath10k_mac_setup_prb_tmpl(arvif);
1493 if (ret)
1494 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1495 ret);
1496 } else {
1497 ieee80211_csa_finish(vif);
1498 }
1499}
1500
1501static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1502{
1503 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1504 ap_csa_work);
1505 struct ath10k *ar = arvif->ar;
1506
1507 mutex_lock(&ar->conf_mutex);
1508 ath10k_mac_vif_ap_csa_count_down(arvif);
1509 mutex_unlock(&ar->conf_mutex);
1510}
1511
Kalle Valo5e3dd152013-06-12 20:52:10 +03001512/**********************/
1513/* Station management */
1514/**********************/
1515
Michal Kazior590922a2014-10-21 10:10:29 +03001516static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1517 struct ieee80211_vif *vif)
1518{
1519 /* Some firmware revisions have unstable STA powersave when listen
1520 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1521 * generate NullFunc frames properly even if buffered frames have been
1522 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1523 * buffered frames. Often pinging the device from AP would simply fail.
1524 *
1525 * As a workaround set it to 1.
1526 */
1527 if (vif->type == NL80211_IFTYPE_STATION)
1528 return 1;
1529
1530 return ar->hw->conf.listen_interval;
1531}
1532
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001534 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001535 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001536 struct wmi_peer_assoc_complete_arg *arg)
1537{
Michal Kazior590922a2014-10-21 10:10:29 +03001538 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1539
Michal Kazior548db542013-07-05 16:15:15 +03001540 lockdep_assert_held(&ar->conf_mutex);
1541
Kalle Valob25f32c2014-09-14 12:50:49 +03001542 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001543 arg->vdev_id = arvif->vdev_id;
1544 arg->peer_aid = sta->aid;
1545 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001546 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001547 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001548 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001549}
1550
1551static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001552 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553 struct wmi_peer_assoc_complete_arg *arg)
1554{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555 struct ieee80211_bss_conf *info = &vif->bss_conf;
1556 struct cfg80211_bss *bss;
1557 const u8 *rsnie = NULL;
1558 const u8 *wpaie = NULL;
1559
Michal Kazior548db542013-07-05 16:15:15 +03001560 lockdep_assert_held(&ar->conf_mutex);
1561
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1563 info->bssid, NULL, 0, 0, 0);
1564 if (bss) {
1565 const struct cfg80211_bss_ies *ies;
1566
1567 rcu_read_lock();
1568 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1569
1570 ies = rcu_dereference(bss->ies);
1571
1572 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001573 WLAN_OUI_TYPE_MICROSOFT_WPA,
1574 ies->data,
1575 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576 rcu_read_unlock();
1577 cfg80211_put_bss(ar->hw->wiphy, bss);
1578 }
1579
1580 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1581 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001582 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1584 }
1585
1586 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001587 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1589 }
1590}
1591
1592static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1593 struct ieee80211_sta *sta,
1594 struct wmi_peer_assoc_complete_arg *arg)
1595{
1596 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1597 const struct ieee80211_supported_band *sband;
1598 const struct ieee80211_rate *rates;
1599 u32 ratemask;
1600 int i;
1601
Michal Kazior548db542013-07-05 16:15:15 +03001602 lockdep_assert_held(&ar->conf_mutex);
1603
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1605 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1606 rates = sband->bitrates;
1607
1608 rateset->num_rates = 0;
1609
1610 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1611 if (!(ratemask & 1))
1612 continue;
1613
1614 rateset->rates[rateset->num_rates] = rates->hw_value;
1615 rateset->num_rates++;
1616 }
1617}
1618
1619static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1620 struct ieee80211_sta *sta,
1621 struct wmi_peer_assoc_complete_arg *arg)
1622{
1623 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001625 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626
Michal Kazior548db542013-07-05 16:15:15 +03001627 lockdep_assert_held(&ar->conf_mutex);
1628
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 if (!ht_cap->ht_supported)
1630 return;
1631
1632 arg->peer_flags |= WMI_PEER_HT;
1633 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1634 ht_cap->ampdu_factor)) - 1;
1635
1636 arg->peer_mpdu_density =
1637 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1638
1639 arg->peer_ht_caps = ht_cap->cap;
1640 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1641
1642 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1643 arg->peer_flags |= WMI_PEER_LDPC;
1644
1645 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1646 arg->peer_flags |= WMI_PEER_40MHZ;
1647 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1648 }
1649
1650 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1651 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1652
1653 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1654 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1655
1656 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1657 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1658 arg->peer_flags |= WMI_PEER_STBC;
1659 }
1660
1661 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1663 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1664 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1665 arg->peer_rate_caps |= stbc;
1666 arg->peer_flags |= WMI_PEER_STBC;
1667 }
1668
Kalle Valo5e3dd152013-06-12 20:52:10 +03001669 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1670 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1671 else if (ht_cap->mcs.rx_mask[1])
1672 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1673
1674 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1675 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1676 arg->peer_ht_rates.rates[n++] = i;
1677
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001678 /*
1679 * This is a workaround for HT-enabled STAs which break the spec
1680 * and have no HT capabilities RX mask (no HT RX MCS map).
1681 *
1682 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1683 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1684 *
1685 * Firmware asserts if such situation occurs.
1686 */
1687 if (n == 0) {
1688 arg->peer_ht_rates.num_rates = 8;
1689 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1690 arg->peer_ht_rates.rates[i] = i;
1691 } else {
1692 arg->peer_ht_rates.num_rates = n;
1693 arg->peer_num_spatial_streams = sta->rx_nss;
1694 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
Michal Kazior7aa7a722014-08-25 12:09:38 +02001696 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001697 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001698 arg->peer_ht_rates.num_rates,
1699 arg->peer_num_spatial_streams);
1700}
1701
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001702static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1703 struct ath10k_vif *arvif,
1704 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001705{
1706 u32 uapsd = 0;
1707 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001708 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001709
Michal Kazior548db542013-07-05 16:15:15 +03001710 lockdep_assert_held(&ar->conf_mutex);
1711
Kalle Valo5e3dd152013-06-12 20:52:10 +03001712 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001713 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001714 sta->uapsd_queues, sta->max_sp);
1715
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1717 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1718 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1719 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1720 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1721 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1722 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1723 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1724 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1725 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1726 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1727 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1728
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1730 max_sp = sta->max_sp;
1731
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001732 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1733 sta->addr,
1734 WMI_AP_PS_PEER_PARAM_UAPSD,
1735 uapsd);
1736 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001737 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001738 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001739 return ret;
1740 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001741
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001742 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1743 sta->addr,
1744 WMI_AP_PS_PEER_PARAM_MAX_SP,
1745 max_sp);
1746 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001747 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001748 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001749 return ret;
1750 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001751
1752 /* TODO setup this based on STA listen interval and
1753 beacon interval. Currently we don't know
1754 sta->listen_interval - mac80211 patch required.
1755 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001756 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001757 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1758 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001759 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001760 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001761 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001762 return ret;
1763 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001764 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001765
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001766 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767}
1768
1769static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1770 struct ieee80211_sta *sta,
1771 struct wmi_peer_assoc_complete_arg *arg)
1772{
1773 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001774 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001775
1776 if (!vht_cap->vht_supported)
1777 return;
1778
1779 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001780
1781 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1782 arg->peer_flags |= WMI_PEER_VHT_2G;
1783
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 arg->peer_vht_caps = vht_cap->cap;
1785
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001786 ampdu_factor = (vht_cap->cap &
1787 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1788 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1789
1790 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1791 * zero in VHT IE. Using it would result in degraded throughput.
1792 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1793 * it if VHT max_mpdu is smaller. */
1794 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1795 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1796 ampdu_factor)) - 1);
1797
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1799 arg->peer_flags |= WMI_PEER_80MHZ;
1800
1801 arg->peer_vht_rates.rx_max_rate =
1802 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1803 arg->peer_vht_rates.rx_mcs_set =
1804 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1805 arg->peer_vht_rates.tx_max_rate =
1806 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1807 arg->peer_vht_rates.tx_mcs_set =
1808 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1809
Michal Kazior7aa7a722014-08-25 12:09:38 +02001810 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001811 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001812}
1813
1814static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001815 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001817 struct wmi_peer_assoc_complete_arg *arg)
1818{
Michal Kazior590922a2014-10-21 10:10:29 +03001819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1820
Kalle Valo5e3dd152013-06-12 20:52:10 +03001821 switch (arvif->vdev_type) {
1822 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001823 if (sta->wme)
1824 arg->peer_flags |= WMI_PEER_QOS;
1825
1826 if (sta->wme && sta->uapsd_queues) {
1827 arg->peer_flags |= WMI_PEER_APSD;
1828 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1829 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830 break;
1831 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001832 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001833 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001834 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001835 case WMI_VDEV_TYPE_IBSS:
1836 if (sta->wme)
1837 arg->peer_flags |= WMI_PEER_QOS;
1838 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839 default:
1840 break;
1841 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001842
1843 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1844 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001845}
1846
Michal Kazior91b12082014-12-12 12:41:35 +01001847static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1848{
1849 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1850 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1851}
1852
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001854 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855 struct ieee80211_sta *sta,
1856 struct wmi_peer_assoc_complete_arg *arg)
1857{
1858 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1859
Kalle Valo5e3dd152013-06-12 20:52:10 +03001860 switch (ar->hw->conf.chandef.chan->band) {
1861 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001862 if (sta->vht_cap.vht_supported) {
1863 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1864 phymode = MODE_11AC_VHT40;
1865 else
1866 phymode = MODE_11AC_VHT20;
1867 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001868 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1869 phymode = MODE_11NG_HT40;
1870 else
1871 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001872 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001873 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001874 } else {
1875 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876 }
1877
1878 break;
1879 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001880 /*
1881 * Check VHT first.
1882 */
1883 if (sta->vht_cap.vht_supported) {
1884 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1885 phymode = MODE_11AC_VHT80;
1886 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1887 phymode = MODE_11AC_VHT40;
1888 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1889 phymode = MODE_11AC_VHT20;
1890 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001891 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1892 phymode = MODE_11NA_HT40;
1893 else
1894 phymode = MODE_11NA_HT20;
1895 } else {
1896 phymode = MODE_11A;
1897 }
1898
1899 break;
1900 default:
1901 break;
1902 }
1903
Michal Kazior7aa7a722014-08-25 12:09:38 +02001904 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001905 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001906
Kalle Valo5e3dd152013-06-12 20:52:10 +03001907 arg->peer_phymode = phymode;
1908 WARN_ON(phymode == MODE_UNKNOWN);
1909}
1910
Kalle Valob9ada652013-10-16 15:44:46 +03001911static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001912 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001913 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001914 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001915{
Michal Kazior548db542013-07-05 16:15:15 +03001916 lockdep_assert_held(&ar->conf_mutex);
1917
Kalle Valob9ada652013-10-16 15:44:46 +03001918 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001919
Michal Kazior590922a2014-10-21 10:10:29 +03001920 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1921 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001922 ath10k_peer_assoc_h_rates(ar, sta, arg);
1923 ath10k_peer_assoc_h_ht(ar, sta, arg);
1924 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001925 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1926 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001927
Kalle Valob9ada652013-10-16 15:44:46 +03001928 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001929}
1930
Michal Kazior90046f52014-02-14 14:45:51 +01001931static const u32 ath10k_smps_map[] = {
1932 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1933 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1934 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1935 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1936};
1937
1938static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1939 const u8 *addr,
1940 const struct ieee80211_sta_ht_cap *ht_cap)
1941{
1942 int smps;
1943
1944 if (!ht_cap->ht_supported)
1945 return 0;
1946
1947 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1948 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1949
1950 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1951 return -EINVAL;
1952
1953 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1954 WMI_PEER_SMPS_STATE,
1955 ath10k_smps_map[smps]);
1956}
1957
Michal Kazior139e1702015-02-15 16:50:42 +02001958static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1959 struct ieee80211_vif *vif,
1960 struct ieee80211_sta_vht_cap vht_cap)
1961{
1962 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1963 int ret;
1964 u32 param;
1965 u32 value;
1966
1967 if (!(ar->vht_cap_info &
1968 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1969 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1970 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1971 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1972 return 0;
1973
1974 param = ar->wmi.vdev_param->txbf;
1975 value = 0;
1976
1977 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1978 return 0;
1979
1980 /* The following logic is correct. If a remote STA advertises support
1981 * for being a beamformer then we should enable us being a beamformee.
1982 */
1983
1984 if (ar->vht_cap_info &
1985 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1986 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1987 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1988 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1989
1990 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1991 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1992 }
1993
1994 if (ar->vht_cap_info &
1995 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1996 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1997 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1998 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1999
2000 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2001 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2002 }
2003
2004 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2005 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2006
2007 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2008 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2009
2010 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2011 if (ret) {
2012 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2013 value, ret);
2014 return ret;
2015 }
2016
2017 return 0;
2018}
2019
Kalle Valo5e3dd152013-06-12 20:52:10 +03002020/* can be called only in mac80211 callbacks due to `key_count` usage */
2021static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2022 struct ieee80211_vif *vif,
2023 struct ieee80211_bss_conf *bss_conf)
2024{
2025 struct ath10k *ar = hw->priv;
2026 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002027 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002028 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002029 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002030 struct ieee80211_sta *ap_sta;
2031 int ret;
2032
Michal Kazior548db542013-07-05 16:15:15 +03002033 lockdep_assert_held(&ar->conf_mutex);
2034
Michal Kazior077efc82014-10-21 10:10:29 +03002035 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2036 arvif->vdev_id, arvif->bssid, arvif->aid);
2037
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038 rcu_read_lock();
2039
2040 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2041 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002042 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002043 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002044 rcu_read_unlock();
2045 return;
2046 }
2047
Michal Kazior90046f52014-02-14 14:45:51 +01002048 /* ap_sta must be accessed only within rcu section which must be left
2049 * before calling ath10k_setup_peer_smps() which might sleep. */
2050 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002051 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002052
Michal Kazior590922a2014-10-21 10:10:29 +03002053 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002054 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002055 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002056 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 rcu_read_unlock();
2058 return;
2059 }
2060
2061 rcu_read_unlock();
2062
Kalle Valob9ada652013-10-16 15:44:46 +03002063 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2064 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002065 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002066 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002067 return;
2068 }
2069
Michal Kazior90046f52014-02-14 14:45:51 +01002070 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2071 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002072 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002073 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002074 return;
2075 }
2076
Michal Kazior139e1702015-02-15 16:50:42 +02002077 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2078 if (ret) {
2079 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2080 arvif->vdev_id, bss_conf->bssid, ret);
2081 return;
2082 }
2083
Michal Kazior7aa7a722014-08-25 12:09:38 +02002084 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002085 "mac vdev %d up (associated) bssid %pM aid %d\n",
2086 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2087
Michal Kazior077efc82014-10-21 10:10:29 +03002088 WARN_ON(arvif->is_up);
2089
Michal Kaziorc930f742014-01-23 11:38:25 +01002090 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002091 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002092
2093 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2094 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002095 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002097 return;
2098 }
2099
2100 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002101
2102 /* Workaround: Some firmware revisions (tested with qca6174
2103 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2104 * poked with peer param command.
2105 */
2106 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2107 WMI_PEER_DUMMY_VAR, 1);
2108 if (ret) {
2109 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2110 arvif->bssid, arvif->vdev_id, ret);
2111 return;
2112 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002113}
2114
Kalle Valo5e3dd152013-06-12 20:52:10 +03002115static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2116 struct ieee80211_vif *vif)
2117{
2118 struct ath10k *ar = hw->priv;
2119 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002120 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002121 int ret;
2122
Michal Kazior548db542013-07-05 16:15:15 +03002123 lockdep_assert_held(&ar->conf_mutex);
2124
Michal Kazior077efc82014-10-21 10:10:29 +03002125 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2126 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002127
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002129 if (ret)
2130 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2131 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002133 arvif->def_wep_key_idx = -1;
2134
Michal Kazior139e1702015-02-15 16:50:42 +02002135 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2136 if (ret) {
2137 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2138 arvif->vdev_id, ret);
2139 return;
2140 }
2141
Michal Kaziorc930f742014-01-23 11:38:25 +01002142 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002143}
2144
Michal Kazior590922a2014-10-21 10:10:29 +03002145static int ath10k_station_assoc(struct ath10k *ar,
2146 struct ieee80211_vif *vif,
2147 struct ieee80211_sta *sta,
2148 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149{
Michal Kazior590922a2014-10-21 10:10:29 +03002150 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002151 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002152 int ret = 0;
2153
Michal Kazior548db542013-07-05 16:15:15 +03002154 lockdep_assert_held(&ar->conf_mutex);
2155
Michal Kazior590922a2014-10-21 10:10:29 +03002156 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002158 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002159 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002160 return ret;
2161 }
2162
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002163 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002164 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2165 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002166 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002167 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002168 return ret;
2169 }
2170
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002171 /* Re-assoc is run only to update supported rates for given station. It
2172 * doesn't make much sense to reconfigure the peer completely.
2173 */
2174 if (!reassoc) {
2175 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2176 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002177 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002178 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002179 arvif->vdev_id, ret);
2180 return ret;
2181 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002182
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002183 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2184 if (ret) {
2185 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2186 sta->addr, arvif->vdev_id, ret);
2187 return ret;
2188 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002190 if (!sta->wme) {
2191 arvif->num_legacy_stations++;
2192 ret = ath10k_recalc_rtscts_prot(arvif);
2193 if (ret) {
2194 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2195 arvif->vdev_id, ret);
2196 return ret;
2197 }
2198 }
2199
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002200 /* Plumb cached keys only for static WEP */
2201 if (arvif->def_wep_key_idx != -1) {
2202 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2203 if (ret) {
2204 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2205 arvif->vdev_id, ret);
2206 return ret;
2207 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208 }
2209 }
2210
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 return ret;
2212}
2213
Michal Kazior590922a2014-10-21 10:10:29 +03002214static int ath10k_station_disassoc(struct ath10k *ar,
2215 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 struct ieee80211_sta *sta)
2217{
Michal Kazior590922a2014-10-21 10:10:29 +03002218 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002219 int ret = 0;
2220
2221 lockdep_assert_held(&ar->conf_mutex);
2222
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002223 if (!sta->wme) {
2224 arvif->num_legacy_stations--;
2225 ret = ath10k_recalc_rtscts_prot(arvif);
2226 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002227 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002228 arvif->vdev_id, ret);
2229 return ret;
2230 }
2231 }
2232
Kalle Valo5e3dd152013-06-12 20:52:10 +03002233 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2234 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002235 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002236 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002237 return ret;
2238 }
2239
2240 return ret;
2241}
2242
2243/**************/
2244/* Regulatory */
2245/**************/
2246
2247static int ath10k_update_channel_list(struct ath10k *ar)
2248{
2249 struct ieee80211_hw *hw = ar->hw;
2250 struct ieee80211_supported_band **bands;
2251 enum ieee80211_band band;
2252 struct ieee80211_channel *channel;
2253 struct wmi_scan_chan_list_arg arg = {0};
2254 struct wmi_channel_arg *ch;
2255 bool passive;
2256 int len;
2257 int ret;
2258 int i;
2259
Michal Kazior548db542013-07-05 16:15:15 +03002260 lockdep_assert_held(&ar->conf_mutex);
2261
Kalle Valo5e3dd152013-06-12 20:52:10 +03002262 bands = hw->wiphy->bands;
2263 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2264 if (!bands[band])
2265 continue;
2266
2267 for (i = 0; i < bands[band]->n_channels; i++) {
2268 if (bands[band]->channels[i].flags &
2269 IEEE80211_CHAN_DISABLED)
2270 continue;
2271
2272 arg.n_channels++;
2273 }
2274 }
2275
2276 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2277 arg.channels = kzalloc(len, GFP_KERNEL);
2278 if (!arg.channels)
2279 return -ENOMEM;
2280
2281 ch = arg.channels;
2282 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2283 if (!bands[band])
2284 continue;
2285
2286 for (i = 0; i < bands[band]->n_channels; i++) {
2287 channel = &bands[band]->channels[i];
2288
2289 if (channel->flags & IEEE80211_CHAN_DISABLED)
2290 continue;
2291
2292 ch->allow_ht = true;
2293
2294 /* FIXME: when should we really allow VHT? */
2295 ch->allow_vht = true;
2296
2297 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002298 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299
2300 ch->ht40plus =
2301 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2302
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002303 ch->chan_radar =
2304 !!(channel->flags & IEEE80211_CHAN_RADAR);
2305
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002306 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002307 ch->passive = passive;
2308
2309 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002310 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002311 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002312 ch->max_power = channel->max_power * 2;
2313 ch->max_reg_power = channel->max_reg_power * 2;
2314 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002315 ch->reg_class_id = 0; /* FIXME */
2316
2317 /* FIXME: why use only legacy modes, why not any
2318 * HT/VHT modes? Would that even make any
2319 * difference? */
2320 if (channel->band == IEEE80211_BAND_2GHZ)
2321 ch->mode = MODE_11G;
2322 else
2323 ch->mode = MODE_11A;
2324
2325 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2326 continue;
2327
Michal Kazior7aa7a722014-08-25 12:09:38 +02002328 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002329 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2330 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 ch->freq, ch->max_power, ch->max_reg_power,
2332 ch->max_antenna_gain, ch->mode);
2333
2334 ch++;
2335 }
2336 }
2337
2338 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2339 kfree(arg.channels);
2340
2341 return ret;
2342}
2343
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002344static enum wmi_dfs_region
2345ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2346{
2347 switch (dfs_region) {
2348 case NL80211_DFS_UNSET:
2349 return WMI_UNINIT_DFS_DOMAIN;
2350 case NL80211_DFS_FCC:
2351 return WMI_FCC_DFS_DOMAIN;
2352 case NL80211_DFS_ETSI:
2353 return WMI_ETSI_DFS_DOMAIN;
2354 case NL80211_DFS_JP:
2355 return WMI_MKK4_DFS_DOMAIN;
2356 }
2357 return WMI_UNINIT_DFS_DOMAIN;
2358}
2359
Michal Kaziorf7843d72013-07-16 09:38:52 +02002360static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002361{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002364 enum wmi_dfs_region wmi_dfs_reg;
2365 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366
Michal Kaziorf7843d72013-07-16 09:38:52 +02002367 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368
2369 ret = ath10k_update_channel_list(ar);
2370 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002371 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002372
2373 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002374
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002375 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2376 nl_dfs_reg = ar->dfs_detector->region;
2377 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2378 } else {
2379 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2380 }
2381
Kalle Valo5e3dd152013-06-12 20:52:10 +03002382 /* Target allows setting up per-band regdomain but ath_common provides
2383 * a combined one only */
2384 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002385 regpair->reg_domain,
2386 regpair->reg_domain, /* 2ghz */
2387 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002388 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002389 regpair->reg_5ghz_ctl,
2390 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002391 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002392 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002393}
Michal Kazior548db542013-07-05 16:15:15 +03002394
Michal Kaziorf7843d72013-07-16 09:38:52 +02002395static void ath10k_reg_notifier(struct wiphy *wiphy,
2396 struct regulatory_request *request)
2397{
2398 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2399 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002400 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002401
2402 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2403
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002404 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002405 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002406 request->dfs_region);
2407 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2408 request->dfs_region);
2409 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002410 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002411 request->dfs_region);
2412 }
2413
Michal Kaziorf7843d72013-07-16 09:38:52 +02002414 mutex_lock(&ar->conf_mutex);
2415 if (ar->state == ATH10K_STATE_ON)
2416 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002417 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418}
2419
2420/***************/
2421/* TX handlers */
2422/***************/
2423
Michal Kazior42c3aa62013-10-02 11:03:38 +02002424static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2425{
2426 if (ieee80211_is_mgmt(hdr->frame_control))
2427 return HTT_DATA_TX_EXT_TID_MGMT;
2428
2429 if (!ieee80211_is_data_qos(hdr->frame_control))
2430 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2431
2432 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2433 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2434
2435 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2436}
2437
Michal Kazior2b37c292014-09-02 11:00:22 +03002438static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002439{
Michal Kazior2b37c292014-09-02 11:00:22 +03002440 if (vif)
2441 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002442
Michal Kazior1bbc0972014-04-08 09:45:47 +03002443 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002444 return ar->monitor_vdev_id;
2445
Michal Kazior7aa7a722014-08-25 12:09:38 +02002446 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002447 return 0;
2448}
2449
Michal Kazior4b604552014-07-21 21:03:09 +03002450/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2451 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002452 */
Michal Kazior4b604552014-07-21 21:03:09 +03002453static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002454{
2455 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002456 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457 u8 *qos_ctl;
2458
2459 if (!ieee80211_is_data_qos(hdr->frame_control))
2460 return;
2461
2462 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002463 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2464 skb->data, (void *)qos_ctl - (void *)skb->data);
2465 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002466
2467 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2468 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2469 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2470 * it is safe to downgrade to NullFunc.
2471 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002472 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002473 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2474 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2475 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2476 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002477}
2478
Michal Kazior4b604552014-07-21 21:03:09 +03002479static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2480 struct ieee80211_vif *vif,
2481 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002482{
2483 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2485
2486 /* This is case only for P2P_GO */
2487 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2488 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2489 return;
2490
2491 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2492 spin_lock_bh(&ar->data_lock);
2493 if (arvif->u.ap.noa_data)
2494 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2495 GFP_ATOMIC))
2496 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2497 arvif->u.ap.noa_data,
2498 arvif->u.ap.noa_len);
2499 spin_unlock_bh(&ar->data_lock);
2500 }
2501}
2502
Michal Kazior8d6d3622014-11-24 14:58:31 +01002503static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2504{
2505 /* FIXME: Not really sure since when the behaviour changed. At some
2506 * point new firmware stopped requiring creation of peer entries for
2507 * offchannel tx (and actually creating them causes issues with wmi-htc
2508 * tx credit replenishment and reliability). Assuming it's at least 3.4
2509 * because that's when the `freq` was introduced to TX_FRM HTT command.
2510 */
2511 return !(ar->htt.target_version_major >= 3 &&
2512 ar->htt.target_version_minor >= 4);
2513}
2514
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2516{
2517 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002518 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002519
Michal Kazior961d4c32013-08-09 10:13:34 +02002520 if (ar->htt.target_version_major >= 3) {
2521 /* Since HTT 3.0 there is no separate mgmt tx command */
2522 ret = ath10k_htt_tx(&ar->htt, skb);
2523 goto exit;
2524 }
2525
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002526 if (ieee80211_is_mgmt(hdr->frame_control)) {
2527 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2528 ar->fw_features)) {
2529 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2530 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002531 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002532 ret = -EBUSY;
2533 goto exit;
2534 }
2535
2536 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2537 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2538 } else {
2539 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2540 }
2541 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2542 ar->fw_features) &&
2543 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002544 /* FW does not report tx status properly for NullFunc frames
2545 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002546 * those frames when it detects link/beacon loss and depends
2547 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002548 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002549 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002550 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002551 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552
Michal Kazior961d4c32013-08-09 10:13:34 +02002553exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002555 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2556 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002557 ieee80211_free_txskb(ar->hw, skb);
2558 }
2559}
2560
2561void ath10k_offchan_tx_purge(struct ath10k *ar)
2562{
2563 struct sk_buff *skb;
2564
2565 for (;;) {
2566 skb = skb_dequeue(&ar->offchan_tx_queue);
2567 if (!skb)
2568 break;
2569
2570 ieee80211_free_txskb(ar->hw, skb);
2571 }
2572}
2573
2574void ath10k_offchan_tx_work(struct work_struct *work)
2575{
2576 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2577 struct ath10k_peer *peer;
2578 struct ieee80211_hdr *hdr;
2579 struct sk_buff *skb;
2580 const u8 *peer_addr;
2581 int vdev_id;
2582 int ret;
2583
2584 /* FW requirement: We must create a peer before FW will send out
2585 * an offchannel frame. Otherwise the frame will be stuck and
2586 * never transmitted. We delete the peer upon tx completion.
2587 * It is unlikely that a peer for offchannel tx will already be
2588 * present. However it may be in some rare cases so account for that.
2589 * Otherwise we might remove a legitimate peer and break stuff. */
2590
2591 for (;;) {
2592 skb = skb_dequeue(&ar->offchan_tx_queue);
2593 if (!skb)
2594 break;
2595
2596 mutex_lock(&ar->conf_mutex);
2597
Michal Kazior7aa7a722014-08-25 12:09:38 +02002598 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 skb);
2600
2601 hdr = (struct ieee80211_hdr *)skb->data;
2602 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002603 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002604
2605 spin_lock_bh(&ar->data_lock);
2606 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2607 spin_unlock_bh(&ar->data_lock);
2608
2609 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002610 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002611 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002612 peer_addr, vdev_id);
2613
2614 if (!peer) {
2615 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2616 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002617 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618 peer_addr, vdev_id, ret);
2619 }
2620
2621 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002622 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002623 ar->offchan_tx_skb = skb;
2624 spin_unlock_bh(&ar->data_lock);
2625
2626 ath10k_tx_htt(ar, skb);
2627
2628 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2629 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002630 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002631 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002632 skb);
2633
2634 if (!peer) {
2635 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2636 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002637 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002638 peer_addr, vdev_id, ret);
2639 }
2640
2641 mutex_unlock(&ar->conf_mutex);
2642 }
2643}
2644
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002645void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2646{
2647 struct sk_buff *skb;
2648
2649 for (;;) {
2650 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2651 if (!skb)
2652 break;
2653
2654 ieee80211_free_txskb(ar->hw, skb);
2655 }
2656}
2657
2658void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2659{
2660 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2661 struct sk_buff *skb;
2662 int ret;
2663
2664 for (;;) {
2665 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2666 if (!skb)
2667 break;
2668
2669 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002671 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002672 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002673 ieee80211_free_txskb(ar->hw, skb);
2674 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002675 }
2676}
2677
Kalle Valo5e3dd152013-06-12 20:52:10 +03002678/************/
2679/* Scanning */
2680/************/
2681
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002682void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002684 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002685
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002686 switch (ar->scan.state) {
2687 case ATH10K_SCAN_IDLE:
2688 break;
2689 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002690 if (ar->scan.is_roc)
2691 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002692 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002693 case ATH10K_SCAN_ABORTING:
2694 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002695 ieee80211_scan_completed(ar->hw,
2696 (ar->scan.state ==
2697 ATH10K_SCAN_ABORTING));
2698 /* fall through */
2699 case ATH10K_SCAN_STARTING:
2700 ar->scan.state = ATH10K_SCAN_IDLE;
2701 ar->scan_channel = NULL;
2702 ath10k_offchan_tx_purge(ar);
2703 cancel_delayed_work(&ar->scan.timeout);
2704 complete_all(&ar->scan.completed);
2705 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002707}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002709void ath10k_scan_finish(struct ath10k *ar)
2710{
2711 spin_lock_bh(&ar->data_lock);
2712 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002713 spin_unlock_bh(&ar->data_lock);
2714}
2715
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002716static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717{
2718 struct wmi_stop_scan_arg arg = {
2719 .req_id = 1, /* FIXME */
2720 .req_type = WMI_SCAN_STOP_ONE,
2721 .u.scan_id = ATH10K_SCAN_ID,
2722 };
2723 int ret;
2724
2725 lockdep_assert_held(&ar->conf_mutex);
2726
Kalle Valo5e3dd152013-06-12 20:52:10 +03002727 ret = ath10k_wmi_stop_scan(ar, &arg);
2728 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002729 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002730 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731 }
2732
Kalle Valo5e3dd152013-06-12 20:52:10 +03002733 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002734 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002735 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002736 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002737 } else if (ret > 0) {
2738 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002739 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002740
2741out:
2742 /* Scan state should be updated upon scan completion but in case
2743 * firmware fails to deliver the event (for whatever reason) it is
2744 * desired to clean up scan state anyway. Firmware may have just
2745 * dropped the scan completion event delivery due to transport pipe
2746 * being overflown with data and/or it can recover on its own before
2747 * next scan request is submitted.
2748 */
2749 spin_lock_bh(&ar->data_lock);
2750 if (ar->scan.state != ATH10K_SCAN_IDLE)
2751 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002752 spin_unlock_bh(&ar->data_lock);
2753
2754 return ret;
2755}
2756
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002757static void ath10k_scan_abort(struct ath10k *ar)
2758{
2759 int ret;
2760
2761 lockdep_assert_held(&ar->conf_mutex);
2762
2763 spin_lock_bh(&ar->data_lock);
2764
2765 switch (ar->scan.state) {
2766 case ATH10K_SCAN_IDLE:
2767 /* This can happen if timeout worker kicked in and called
2768 * abortion while scan completion was being processed.
2769 */
2770 break;
2771 case ATH10K_SCAN_STARTING:
2772 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002773 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002774 ath10k_scan_state_str(ar->scan.state),
2775 ar->scan.state);
2776 break;
2777 case ATH10K_SCAN_RUNNING:
2778 ar->scan.state = ATH10K_SCAN_ABORTING;
2779 spin_unlock_bh(&ar->data_lock);
2780
2781 ret = ath10k_scan_stop(ar);
2782 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002783 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002784
2785 spin_lock_bh(&ar->data_lock);
2786 break;
2787 }
2788
2789 spin_unlock_bh(&ar->data_lock);
2790}
2791
2792void ath10k_scan_timeout_work(struct work_struct *work)
2793{
2794 struct ath10k *ar = container_of(work, struct ath10k,
2795 scan.timeout.work);
2796
2797 mutex_lock(&ar->conf_mutex);
2798 ath10k_scan_abort(ar);
2799 mutex_unlock(&ar->conf_mutex);
2800}
2801
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802static int ath10k_start_scan(struct ath10k *ar,
2803 const struct wmi_start_scan_arg *arg)
2804{
2805 int ret;
2806
2807 lockdep_assert_held(&ar->conf_mutex);
2808
2809 ret = ath10k_wmi_start_scan(ar, arg);
2810 if (ret)
2811 return ret;
2812
Kalle Valo5e3dd152013-06-12 20:52:10 +03002813 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2814 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002815 ret = ath10k_scan_stop(ar);
2816 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002817 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002818
2819 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 }
2821
Ben Greear2f9eec02015-02-15 16:50:38 +02002822 /* If we failed to start the scan, return error code at
2823 * this point. This is probably due to some issue in the
2824 * firmware, but no need to wedge the driver due to that...
2825 */
2826 spin_lock_bh(&ar->data_lock);
2827 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2828 spin_unlock_bh(&ar->data_lock);
2829 return -EINVAL;
2830 }
2831 spin_unlock_bh(&ar->data_lock);
2832
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002833 /* Add a 200ms margin to account for event/command processing */
2834 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2835 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002836 return 0;
2837}
2838
2839/**********************/
2840/* mac80211 callbacks */
2841/**********************/
2842
2843static void ath10k_tx(struct ieee80211_hw *hw,
2844 struct ieee80211_tx_control *control,
2845 struct sk_buff *skb)
2846{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002847 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002848 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2849 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002850 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002851
2852 /* We should disable CCK RATE due to P2P */
2853 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002854 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002855
Michal Kazior4b604552014-07-21 21:03:09 +03002856 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2857 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002858 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002860 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002861 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2862 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002863 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2864 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002865 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866
Kalle Valo5e3dd152013-06-12 20:52:10 +03002867 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2868 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002869 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002870 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002871 spin_unlock_bh(&ar->data_lock);
2872
Michal Kazior8d6d3622014-11-24 14:58:31 +01002873 if (ath10k_mac_need_offchan_tx_work(ar)) {
2874 ATH10K_SKB_CB(skb)->htt.freq = 0;
2875 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002876
Michal Kazior8d6d3622014-11-24 14:58:31 +01002877 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2878 skb);
2879
2880 skb_queue_tail(&ar->offchan_tx_queue, skb);
2881 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2882 return;
2883 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002884 }
2885
2886 ath10k_tx_htt(ar, skb);
2887}
2888
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002889/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002890void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002891{
2892 /* make sure rcu-protected mac80211 tx path itself is drained */
2893 synchronize_net();
2894
2895 ath10k_offchan_tx_purge(ar);
2896 ath10k_mgmt_over_wmi_tx_purge(ar);
2897
2898 cancel_work_sync(&ar->offchan_tx_work);
2899 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2900}
2901
Michal Kazioraffd3212013-07-16 09:54:35 +02002902void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002903{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002904 struct ath10k_vif *arvif;
2905
Michal Kazior818bdd12013-07-16 09:38:57 +02002906 lockdep_assert_held(&ar->conf_mutex);
2907
Michal Kazior19337472014-08-28 12:58:16 +02002908 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2909 ar->filter_flags = 0;
2910 ar->monitor = false;
2911
2912 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002913 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002914
2915 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002916
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002917 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002918 ath10k_peer_cleanup_all(ar);
2919 ath10k_core_stop(ar);
2920 ath10k_hif_power_down(ar);
2921
2922 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002923 list_for_each_entry(arvif, &ar->arvifs, list)
2924 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002925 spin_unlock_bh(&ar->data_lock);
2926}
2927
Ben Greear46acf7bb2014-05-16 17:15:38 +03002928static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2929{
2930 struct ath10k *ar = hw->priv;
2931
2932 mutex_lock(&ar->conf_mutex);
2933
2934 if (ar->cfg_tx_chainmask) {
2935 *tx_ant = ar->cfg_tx_chainmask;
2936 *rx_ant = ar->cfg_rx_chainmask;
2937 } else {
2938 *tx_ant = ar->supp_tx_chainmask;
2939 *rx_ant = ar->supp_rx_chainmask;
2940 }
2941
2942 mutex_unlock(&ar->conf_mutex);
2943
2944 return 0;
2945}
2946
Ben Greear5572a952014-11-24 16:22:10 +02002947static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2948{
2949 /* It is not clear that allowing gaps in chainmask
2950 * is helpful. Probably it will not do what user
2951 * is hoping for, so warn in that case.
2952 */
2953 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2954 return;
2955
2956 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2957 dbg, cm);
2958}
2959
Ben Greear46acf7bb2014-05-16 17:15:38 +03002960static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2961{
2962 int ret;
2963
2964 lockdep_assert_held(&ar->conf_mutex);
2965
Ben Greear5572a952014-11-24 16:22:10 +02002966 ath10k_check_chain_mask(ar, tx_ant, "tx");
2967 ath10k_check_chain_mask(ar, rx_ant, "rx");
2968
Ben Greear46acf7bb2014-05-16 17:15:38 +03002969 ar->cfg_tx_chainmask = tx_ant;
2970 ar->cfg_rx_chainmask = rx_ant;
2971
2972 if ((ar->state != ATH10K_STATE_ON) &&
2973 (ar->state != ATH10K_STATE_RESTARTED))
2974 return 0;
2975
2976 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2977 tx_ant);
2978 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002979 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002980 ret, tx_ant);
2981 return ret;
2982 }
2983
2984 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2985 rx_ant);
2986 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002987 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002988 ret, rx_ant);
2989 return ret;
2990 }
2991
2992 return 0;
2993}
2994
2995static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2996{
2997 struct ath10k *ar = hw->priv;
2998 int ret;
2999
3000 mutex_lock(&ar->conf_mutex);
3001 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3002 mutex_unlock(&ar->conf_mutex);
3003 return ret;
3004}
3005
Kalle Valo5e3dd152013-06-12 20:52:10 +03003006static int ath10k_start(struct ieee80211_hw *hw)
3007{
3008 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003009 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003010
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003011 /*
3012 * This makes sense only when restarting hw. It is harmless to call
3013 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3014 * commands will be submitted while restarting.
3015 */
3016 ath10k_drain_tx(ar);
3017
Michal Kazior548db542013-07-05 16:15:15 +03003018 mutex_lock(&ar->conf_mutex);
3019
Michal Kaziorc5058f52014-05-26 12:46:03 +03003020 switch (ar->state) {
3021 case ATH10K_STATE_OFF:
3022 ar->state = ATH10K_STATE_ON;
3023 break;
3024 case ATH10K_STATE_RESTARTING:
3025 ath10k_halt(ar);
3026 ar->state = ATH10K_STATE_RESTARTED;
3027 break;
3028 case ATH10K_STATE_ON:
3029 case ATH10K_STATE_RESTARTED:
3030 case ATH10K_STATE_WEDGED:
3031 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003032 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003033 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003034 case ATH10K_STATE_UTF:
3035 ret = -EBUSY;
3036 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003037 }
3038
3039 ret = ath10k_hif_power_up(ar);
3040 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003041 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003042 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003043 }
3044
Kalle Valo43d2a302014-09-10 18:23:30 +03003045 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003046 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003047 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003048 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003049 }
3050
Bartosz Markowski226a3392013-09-26 17:47:16 +02003051 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003052 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003053 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003054 goto err_core_stop;
3055 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003056
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003057 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003059 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003060 goto err_core_stop;
3061 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003062
Ben Greear46acf7bb2014-05-16 17:15:38 +03003063 if (ar->cfg_tx_chainmask)
3064 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3065 ar->cfg_rx_chainmask);
3066
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003067 /*
3068 * By default FW set ARP frames ac to voice (6). In that case ARP
3069 * exchange is not working properly for UAPSD enabled AP. ARP requests
3070 * which arrives with access category 0 are processed by network stack
3071 * and send back with access category 0, but FW changes access category
3072 * to 6. Set ARP frames access category to best effort (0) solves
3073 * this problem.
3074 */
3075
3076 ret = ath10k_wmi_pdev_set_param(ar,
3077 ar->wmi.pdev_param->arp_ac_override, 0);
3078 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003079 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003080 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003081 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003082 }
3083
Michal Kaziord6500972014-04-08 09:56:09 +03003084 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003085 ath10k_regd_update(ar);
3086
Simon Wunderlich855aed12014-08-02 09:12:54 +03003087 ath10k_spectral_start(ar);
3088
Michal Kaziorae254432014-05-26 12:46:02 +03003089 mutex_unlock(&ar->conf_mutex);
3090 return 0;
3091
3092err_core_stop:
3093 ath10k_core_stop(ar);
3094
3095err_power_down:
3096 ath10k_hif_power_down(ar);
3097
3098err_off:
3099 ar->state = ATH10K_STATE_OFF;
3100
3101err:
Michal Kazior548db542013-07-05 16:15:15 +03003102 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003103 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003104}
3105
3106static void ath10k_stop(struct ieee80211_hw *hw)
3107{
3108 struct ath10k *ar = hw->priv;
3109
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003110 ath10k_drain_tx(ar);
3111
Michal Kazior548db542013-07-05 16:15:15 +03003112 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003113 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003114 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003115 ar->state = ATH10K_STATE_OFF;
3116 }
Michal Kazior548db542013-07-05 16:15:15 +03003117 mutex_unlock(&ar->conf_mutex);
3118
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003119 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003120 cancel_work_sync(&ar->restart_work);
3121}
3122
Michal Kaziorad088bf2013-10-16 15:44:46 +03003123static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003124{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003125 struct ath10k_vif *arvif;
3126 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003127
3128 lockdep_assert_held(&ar->conf_mutex);
3129
Michal Kaziorad088bf2013-10-16 15:44:46 +03003130 list_for_each_entry(arvif, &ar->arvifs, list) {
3131 ret = ath10k_mac_vif_setup_ps(arvif);
3132 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003133 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003134 break;
3135 }
3136 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003137
Michal Kaziorad088bf2013-10-16 15:44:46 +03003138 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139}
3140
Michal Kaziorc930f742014-01-23 11:38:25 +01003141static const char *chandef_get_width(enum nl80211_chan_width width)
3142{
3143 switch (width) {
3144 case NL80211_CHAN_WIDTH_20_NOHT:
3145 return "20 (noht)";
3146 case NL80211_CHAN_WIDTH_20:
3147 return "20";
3148 case NL80211_CHAN_WIDTH_40:
3149 return "40";
3150 case NL80211_CHAN_WIDTH_80:
3151 return "80";
3152 case NL80211_CHAN_WIDTH_80P80:
3153 return "80+80";
3154 case NL80211_CHAN_WIDTH_160:
3155 return "160";
3156 case NL80211_CHAN_WIDTH_5:
3157 return "5";
3158 case NL80211_CHAN_WIDTH_10:
3159 return "10";
3160 }
3161 return "?";
3162}
3163
3164static void ath10k_config_chan(struct ath10k *ar)
3165{
3166 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003167 int ret;
3168
3169 lockdep_assert_held(&ar->conf_mutex);
3170
Michal Kazior7aa7a722014-08-25 12:09:38 +02003171 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003172 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3173 ar->chandef.chan->center_freq,
3174 ar->chandef.center_freq1,
3175 ar->chandef.center_freq2,
3176 chandef_get_width(ar->chandef.width));
3177
3178 /* First stop monitor interface. Some FW versions crash if there's a
3179 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003180 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003181 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003182
3183 list_for_each_entry(arvif, &ar->arvifs, list) {
3184 if (!arvif->is_started)
3185 continue;
3186
Michal Kaziordc55e302014-07-29 12:53:36 +03003187 if (!arvif->is_up)
3188 continue;
3189
Michal Kaziorc930f742014-01-23 11:38:25 +01003190 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3191 continue;
3192
Michal Kaziordc55e302014-07-29 12:53:36 +03003193 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003194 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003195 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003196 arvif->vdev_id, ret);
3197 continue;
3198 }
3199 }
3200
Michal Kaziordc55e302014-07-29 12:53:36 +03003201 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003202
3203 list_for_each_entry(arvif, &ar->arvifs, list) {
3204 if (!arvif->is_started)
3205 continue;
3206
3207 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3208 continue;
3209
Michal Kazior81a9a172015-03-05 16:02:17 +02003210 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3211 if (ret)
3212 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3213 ret);
3214
3215 ret = ath10k_mac_setup_prb_tmpl(arvif);
3216 if (ret)
3217 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3218 ret);
3219
Michal Kaziordc55e302014-07-29 12:53:36 +03003220 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003221 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003222 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003223 arvif->vdev_id, ret);
3224 continue;
3225 }
3226
3227 if (!arvif->is_up)
3228 continue;
3229
3230 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3231 arvif->bssid);
3232 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003233 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003234 arvif->vdev_id, ret);
3235 continue;
3236 }
3237 }
3238
Michal Kazior19337472014-08-28 12:58:16 +02003239 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003240}
3241
Michal Kazior7d9d5582014-10-21 10:40:15 +03003242static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3243{
3244 int ret;
3245 u32 param;
3246
3247 lockdep_assert_held(&ar->conf_mutex);
3248
3249 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3250
3251 param = ar->wmi.pdev_param->txpower_limit2g;
3252 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3253 if (ret) {
3254 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3255 txpower, ret);
3256 return ret;
3257 }
3258
3259 param = ar->wmi.pdev_param->txpower_limit5g;
3260 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3261 if (ret) {
3262 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3263 txpower, ret);
3264 return ret;
3265 }
3266
3267 return 0;
3268}
3269
3270static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3271{
3272 struct ath10k_vif *arvif;
3273 int ret, txpower = -1;
3274
3275 lockdep_assert_held(&ar->conf_mutex);
3276
3277 list_for_each_entry(arvif, &ar->arvifs, list) {
3278 WARN_ON(arvif->txpower < 0);
3279
3280 if (txpower == -1)
3281 txpower = arvif->txpower;
3282 else
3283 txpower = min(txpower, arvif->txpower);
3284 }
3285
3286 if (WARN_ON(txpower == -1))
3287 return -EINVAL;
3288
3289 ret = ath10k_mac_txpower_setup(ar, txpower);
3290 if (ret) {
3291 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3292 txpower, ret);
3293 return ret;
3294 }
3295
3296 return 0;
3297}
3298
Kalle Valo5e3dd152013-06-12 20:52:10 +03003299static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3300{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003301 struct ath10k *ar = hw->priv;
3302 struct ieee80211_conf *conf = &hw->conf;
3303 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003304
3305 mutex_lock(&ar->conf_mutex);
3306
3307 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003308 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003309 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003310 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003311 conf->chandef.chan->flags,
3312 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003313
Kalle Valo5e3dd152013-06-12 20:52:10 +03003314 spin_lock_bh(&ar->data_lock);
3315 ar->rx_channel = conf->chandef.chan;
3316 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003317
Michal Kaziord6500972014-04-08 09:56:09 +03003318 ar->radar_enabled = conf->radar_enabled;
3319 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003320
3321 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3322 ar->chandef = conf->chandef;
3323 ath10k_config_chan(ar);
3324 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325 }
3326
Michal Kazioraffd3212013-07-16 09:54:35 +02003327 if (changed & IEEE80211_CONF_CHANGE_PS)
3328 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003329
3330 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003331 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3332 ret = ath10k_monitor_recalc(ar);
3333 if (ret)
3334 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003335 }
3336
3337 mutex_unlock(&ar->conf_mutex);
3338 return ret;
3339}
3340
Ben Greear5572a952014-11-24 16:22:10 +02003341static u32 get_nss_from_chainmask(u16 chain_mask)
3342{
3343 if ((chain_mask & 0x15) == 0x15)
3344 return 4;
3345 else if ((chain_mask & 0x7) == 0x7)
3346 return 3;
3347 else if ((chain_mask & 0x3) == 0x3)
3348 return 2;
3349 return 1;
3350}
3351
Kalle Valo5e3dd152013-06-12 20:52:10 +03003352/*
3353 * TODO:
3354 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3355 * because we will send mgmt frames without CCK. This requirement
3356 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3357 * in the TX packet.
3358 */
3359static int ath10k_add_interface(struct ieee80211_hw *hw,
3360 struct ieee80211_vif *vif)
3361{
3362 struct ath10k *ar = hw->priv;
3363 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3364 enum wmi_sta_powersave_param param;
3365 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003366 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003367 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003368 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369
Johannes Berg848955c2014-11-11 12:48:42 +01003370 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3371
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372 mutex_lock(&ar->conf_mutex);
3373
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003374 memset(arvif, 0, sizeof(*arvif));
3375
Kalle Valo5e3dd152013-06-12 20:52:10 +03003376 arvif->ar = ar;
3377 arvif->vif = vif;
3378
Ben Greeare63b33f2013-10-22 14:54:14 -07003379 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003380 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003381
Ben Greeara9aefb32014-08-12 11:02:19 +03003382 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003383 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003384 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003385 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003386 }
Ben Greear16c11172014-09-23 14:17:16 -07003387 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003388
Ben Greear16c11172014-09-23 14:17:16 -07003389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3390 bit, ar->free_vdev_map);
3391
3392 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003393 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003394
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003396 case NL80211_IFTYPE_P2P_DEVICE:
3397 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3398 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3399 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 case NL80211_IFTYPE_UNSPECIFIED:
3401 case NL80211_IFTYPE_STATION:
3402 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3403 if (vif->p2p)
3404 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3405 break;
3406 case NL80211_IFTYPE_ADHOC:
3407 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3408 break;
3409 case NL80211_IFTYPE_AP:
3410 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3411
3412 if (vif->p2p)
3413 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3414 break;
3415 case NL80211_IFTYPE_MONITOR:
3416 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3417 break;
3418 default:
3419 WARN_ON(1);
3420 break;
3421 }
3422
Michal Kazior64badcb2014-09-18 11:18:02 +03003423 /* Some firmware revisions don't wait for beacon tx completion before
3424 * sending another SWBA event. This could lead to hardware using old
3425 * (freed) beacon data in some cases, e.g. tx credit starvation
3426 * combined with missed TBTT. This is very very rare.
3427 *
3428 * On non-IOMMU-enabled hosts this could be a possible security issue
3429 * because hw could beacon some random data on the air. On
3430 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3431 * device would crash.
3432 *
3433 * Since there are no beacon tx completions (implicit nor explicit)
3434 * propagated to host the only workaround for this is to allocate a
3435 * DMA-coherent buffer for a lifetime of a vif and use it for all
3436 * beacon tx commands. Worst case for this approach is some beacons may
3437 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3438 */
3439 if (vif->type == NL80211_IFTYPE_ADHOC ||
3440 vif->type == NL80211_IFTYPE_AP) {
3441 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3442 IEEE80211_MAX_FRAME_LEN,
3443 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303444 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003445 if (!arvif->beacon_buf) {
3446 ret = -ENOMEM;
3447 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3448 ret);
3449 goto err;
3450 }
3451 }
3452
3453 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3454 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3455 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456
3457 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3458 arvif->vdev_subtype, vif->addr);
3459 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003460 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003461 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003462 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003463 }
3464
Ben Greear16c11172014-09-23 14:17:16 -07003465 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003466 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003467
Michal Kazior46725b152015-01-28 09:57:49 +02003468 /* It makes no sense to have firmware do keepalives. mac80211 already
3469 * takes care of this with idle connection polling.
3470 */
3471 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003472 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003473 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003474 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003475 goto err_vdev_delete;
3476 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003477
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003478 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003480 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3481 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003483 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003484 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003485 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003486 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003487 goto err_vdev_delete;
3488 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003489
Ben Greear5572a952014-11-24 16:22:10 +02003490 if (ar->cfg_tx_chainmask) {
3491 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3492
3493 vdev_param = ar->wmi.vdev_param->nss;
3494 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3495 nss);
3496 if (ret) {
3497 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3498 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3499 ret);
3500 goto err_vdev_delete;
3501 }
3502 }
3503
Kalle Valo5e3dd152013-06-12 20:52:10 +03003504 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3505 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003507 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003508 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003509 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003511
Kalle Valo5a13e762014-01-20 11:01:46 +02003512 ret = ath10k_mac_set_kickout(arvif);
3513 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003514 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003515 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003516 goto err_peer_delete;
3517 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 }
3519
3520 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3521 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3522 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3523 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3524 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003526 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003527 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003528 goto err_peer_delete;
3529 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003530
Michal Kazior9f9b5742014-12-12 12:41:36 +01003531 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003532 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003533 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003534 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003535 goto err_peer_delete;
3536 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003537
Michal Kazior9f9b5742014-12-12 12:41:36 +01003538 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003539 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003540 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003541 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003542 goto err_peer_delete;
3543 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544 }
3545
Michal Kazior424121c2013-07-22 14:13:31 +02003546 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003547 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003548 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003549 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003550 goto err_peer_delete;
3551 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003552
Michal Kazior424121c2013-07-22 14:13:31 +02003553 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003554 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003555 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003556 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003557 goto err_peer_delete;
3558 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003559
Michal Kazior7d9d5582014-10-21 10:40:15 +03003560 arvif->txpower = vif->bss_conf.txpower;
3561 ret = ath10k_mac_txpower_recalc(ar);
3562 if (ret) {
3563 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3564 goto err_peer_delete;
3565 }
3566
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003568 return 0;
3569
3570err_peer_delete:
3571 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3572 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3573
3574err_vdev_delete:
3575 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003576 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003577 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003578
3579err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003580 if (arvif->beacon_buf) {
3581 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3582 arvif->beacon_buf, arvif->beacon_paddr);
3583 arvif->beacon_buf = NULL;
3584 }
3585
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003586 mutex_unlock(&ar->conf_mutex);
3587
Kalle Valo5e3dd152013-06-12 20:52:10 +03003588 return ret;
3589}
3590
3591static void ath10k_remove_interface(struct ieee80211_hw *hw,
3592 struct ieee80211_vif *vif)
3593{
3594 struct ath10k *ar = hw->priv;
3595 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3596 int ret;
3597
Michal Kazior81a9a172015-03-05 16:02:17 +02003598 cancel_work_sync(&arvif->ap_csa_work);
3599
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303600 mutex_lock(&ar->conf_mutex);
3601
Michal Kaziored543882013-09-13 14:16:56 +02003602 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003603 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003604 spin_unlock_bh(&ar->data_lock);
3605
Simon Wunderlich855aed12014-08-02 09:12:54 +03003606 ret = ath10k_spectral_vif_stop(arvif);
3607 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003608 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003609 arvif->vdev_id, ret);
3610
Ben Greear16c11172014-09-23 14:17:16 -07003611 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003612 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003613
3614 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003615 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3616 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003618 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003619 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620
3621 kfree(arvif->u.ap.noa_data);
3622 }
3623
Michal Kazior7aa7a722014-08-25 12:09:38 +02003624 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003625 arvif->vdev_id);
3626
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3628 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003629 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003630 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003631
Michal Kazior2c512052015-02-15 16:50:40 +02003632 /* Some firmware revisions don't notify host about self-peer removal
3633 * until after associated vdev is deleted.
3634 */
3635 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3636 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3637 vif->addr);
3638 if (ret)
3639 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3640 arvif->vdev_id, ret);
3641
3642 spin_lock_bh(&ar->data_lock);
3643 ar->num_peers--;
3644 spin_unlock_bh(&ar->data_lock);
3645 }
3646
Kalle Valo5e3dd152013-06-12 20:52:10 +03003647 ath10k_peer_cleanup(ar, arvif->vdev_id);
3648
3649 mutex_unlock(&ar->conf_mutex);
3650}
3651
3652/*
3653 * FIXME: Has to be verified.
3654 */
3655#define SUPPORTED_FILTERS \
3656 (FIF_PROMISC_IN_BSS | \
3657 FIF_ALLMULTI | \
3658 FIF_CONTROL | \
3659 FIF_PSPOLL | \
3660 FIF_OTHER_BSS | \
3661 FIF_BCN_PRBRESP_PROMISC | \
3662 FIF_PROBE_REQ | \
3663 FIF_FCSFAIL)
3664
3665static void ath10k_configure_filter(struct ieee80211_hw *hw,
3666 unsigned int changed_flags,
3667 unsigned int *total_flags,
3668 u64 multicast)
3669{
3670 struct ath10k *ar = hw->priv;
3671 int ret;
3672
3673 mutex_lock(&ar->conf_mutex);
3674
3675 changed_flags &= SUPPORTED_FILTERS;
3676 *total_flags &= SUPPORTED_FILTERS;
3677 ar->filter_flags = *total_flags;
3678
Michal Kazior19337472014-08-28 12:58:16 +02003679 ret = ath10k_monitor_recalc(ar);
3680 if (ret)
3681 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003682
3683 mutex_unlock(&ar->conf_mutex);
3684}
3685
3686static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3687 struct ieee80211_vif *vif,
3688 struct ieee80211_bss_conf *info,
3689 u32 changed)
3690{
3691 struct ath10k *ar = hw->priv;
3692 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3693 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003694 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003695
3696 mutex_lock(&ar->conf_mutex);
3697
3698 if (changed & BSS_CHANGED_IBSS)
3699 ath10k_control_ibss(arvif, info, vif->addr);
3700
3701 if (changed & BSS_CHANGED_BEACON_INT) {
3702 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003703 vdev_param = ar->wmi.vdev_param->beacon_interval;
3704 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003705 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003706 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003707 "mac vdev %d beacon_interval %d\n",
3708 arvif->vdev_id, arvif->beacon_interval);
3709
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003711 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003712 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003713 }
3714
3715 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003716 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003717 "vdev %d set beacon tx mode to staggered\n",
3718 arvif->vdev_id);
3719
Bartosz Markowski226a3392013-09-26 17:47:16 +02003720 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3721 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722 WMI_BEACON_STAGGERED_MODE);
3723 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003724 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003725 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003726
3727 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3728 if (ret)
3729 ath10k_warn(ar, "failed to update beacon template: %d\n",
3730 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 }
3732
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003733 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3734 ret = ath10k_mac_setup_prb_tmpl(arvif);
3735 if (ret)
3736 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3737 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003738 }
3739
Michal Kaziorba2479f2015-01-24 12:14:51 +02003740 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003741 arvif->dtim_period = info->dtim_period;
3742
Michal Kazior7aa7a722014-08-25 12:09:38 +02003743 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003744 "mac vdev %d dtim_period %d\n",
3745 arvif->vdev_id, arvif->dtim_period);
3746
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003747 vdev_param = ar->wmi.vdev_param->dtim_period;
3748 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003749 arvif->dtim_period);
3750 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003751 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003752 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003753 }
3754
3755 if (changed & BSS_CHANGED_SSID &&
3756 vif->type == NL80211_IFTYPE_AP) {
3757 arvif->u.ap.ssid_len = info->ssid_len;
3758 if (info->ssid_len)
3759 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3760 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3761 }
3762
Michal Kazior077efc82014-10-21 10:10:29 +03003763 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3764 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003765
3766 if (changed & BSS_CHANGED_BEACON_ENABLED)
3767 ath10k_control_beaconing(arvif, info);
3768
3769 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003770 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003771 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003772 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003773
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003774 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003775 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003776 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003777 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003778
3779 vdev_param = ar->wmi.vdev_param->protection_mode;
3780 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3781 info->use_cts_prot ? 1 : 0);
3782 if (ret)
3783 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3784 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003785 }
3786
3787 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788 if (info->use_short_slot)
3789 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3790
3791 else
3792 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3793
Michal Kazior7aa7a722014-08-25 12:09:38 +02003794 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003795 arvif->vdev_id, slottime);
3796
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003797 vdev_param = ar->wmi.vdev_param->slot_time;
3798 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003799 slottime);
3800 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003801 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003802 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003803 }
3804
3805 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003806 if (info->use_short_preamble)
3807 preamble = WMI_VDEV_PREAMBLE_SHORT;
3808 else
3809 preamble = WMI_VDEV_PREAMBLE_LONG;
3810
Michal Kazior7aa7a722014-08-25 12:09:38 +02003811 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003812 "mac vdev %d preamble %dn",
3813 arvif->vdev_id, preamble);
3814
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003815 vdev_param = ar->wmi.vdev_param->preamble;
3816 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003817 preamble);
3818 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003819 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003820 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821 }
3822
3823 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003824 if (info->assoc) {
3825 /* Workaround: Make sure monitor vdev is not running
3826 * when associating to prevent some firmware revisions
3827 * (e.g. 10.1 and 10.2) from crashing.
3828 */
3829 if (ar->monitor_started)
3830 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003831 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003832 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003833 } else {
3834 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003835 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003836 }
3837
Michal Kazior7d9d5582014-10-21 10:40:15 +03003838 if (changed & BSS_CHANGED_TXPOWER) {
3839 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3840 arvif->vdev_id, info->txpower);
3841
3842 arvif->txpower = info->txpower;
3843 ret = ath10k_mac_txpower_recalc(ar);
3844 if (ret)
3845 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3846 }
3847
Michal Kaziorbf14e652014-12-12 12:41:38 +01003848 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003849 arvif->ps = vif->bss_conf.ps;
3850
3851 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003852 if (ret)
3853 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3854 arvif->vdev_id, ret);
3855 }
3856
Kalle Valo5e3dd152013-06-12 20:52:10 +03003857 mutex_unlock(&ar->conf_mutex);
3858}
3859
3860static int ath10k_hw_scan(struct ieee80211_hw *hw,
3861 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003862 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003863{
3864 struct ath10k *ar = hw->priv;
3865 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003866 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003867 struct wmi_start_scan_arg arg;
3868 int ret = 0;
3869 int i;
3870
3871 mutex_lock(&ar->conf_mutex);
3872
3873 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003874 switch (ar->scan.state) {
3875 case ATH10K_SCAN_IDLE:
3876 reinit_completion(&ar->scan.started);
3877 reinit_completion(&ar->scan.completed);
3878 ar->scan.state = ATH10K_SCAN_STARTING;
3879 ar->scan.is_roc = false;
3880 ar->scan.vdev_id = arvif->vdev_id;
3881 ret = 0;
3882 break;
3883 case ATH10K_SCAN_STARTING:
3884 case ATH10K_SCAN_RUNNING:
3885 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003886 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003887 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003889 spin_unlock_bh(&ar->data_lock);
3890
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003891 if (ret)
3892 goto exit;
3893
Kalle Valo5e3dd152013-06-12 20:52:10 +03003894 memset(&arg, 0, sizeof(arg));
3895 ath10k_wmi_start_scan_init(ar, &arg);
3896 arg.vdev_id = arvif->vdev_id;
3897 arg.scan_id = ATH10K_SCAN_ID;
3898
3899 if (!req->no_cck)
3900 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3901
3902 if (req->ie_len) {
3903 arg.ie_len = req->ie_len;
3904 memcpy(arg.ie, req->ie, arg.ie_len);
3905 }
3906
3907 if (req->n_ssids) {
3908 arg.n_ssids = req->n_ssids;
3909 for (i = 0; i < arg.n_ssids; i++) {
3910 arg.ssids[i].len = req->ssids[i].ssid_len;
3911 arg.ssids[i].ssid = req->ssids[i].ssid;
3912 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003913 } else {
3914 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915 }
3916
3917 if (req->n_channels) {
3918 arg.n_channels = req->n_channels;
3919 for (i = 0; i < arg.n_channels; i++)
3920 arg.channels[i] = req->channels[i]->center_freq;
3921 }
3922
3923 ret = ath10k_start_scan(ar, &arg);
3924 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003925 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003926 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003927 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003928 spin_unlock_bh(&ar->data_lock);
3929 }
3930
3931exit:
3932 mutex_unlock(&ar->conf_mutex);
3933 return ret;
3934}
3935
3936static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3937 struct ieee80211_vif *vif)
3938{
3939 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003940
3941 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003942 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003943 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003944
3945 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003946}
3947
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003948static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3949 struct ath10k_vif *arvif,
3950 enum set_key_cmd cmd,
3951 struct ieee80211_key_conf *key)
3952{
3953 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3954 int ret;
3955
3956 /* 10.1 firmware branch requires default key index to be set to group
3957 * key index after installing it. Otherwise FW/HW Txes corrupted
3958 * frames with multi-vif APs. This is not required for main firmware
3959 * branch (e.g. 636).
3960 *
3961 * FIXME: This has been tested only in AP. It remains unknown if this
3962 * is required for multi-vif STA interfaces on 10.1 */
3963
3964 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3965 return;
3966
3967 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3968 return;
3969
3970 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3971 return;
3972
3973 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3974 return;
3975
3976 if (cmd != SET_KEY)
3977 return;
3978
3979 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3980 key->keyidx);
3981 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003982 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003983 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003984}
3985
Kalle Valo5e3dd152013-06-12 20:52:10 +03003986static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3987 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3988 struct ieee80211_key_conf *key)
3989{
3990 struct ath10k *ar = hw->priv;
3991 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3992 struct ath10k_peer *peer;
3993 const u8 *peer_addr;
3994 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3995 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3996 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01003997 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003998
3999 if (key->keyidx > WMI_MAX_KEY_INDEX)
4000 return -ENOSPC;
4001
4002 mutex_lock(&ar->conf_mutex);
4003
4004 if (sta)
4005 peer_addr = sta->addr;
4006 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4007 peer_addr = vif->bss_conf.bssid;
4008 else
4009 peer_addr = vif->addr;
4010
4011 key->hw_key_idx = key->keyidx;
4012
4013 /* the peer should not disappear in mid-way (unless FW goes awry) since
4014 * we already hold conf_mutex. we just make sure its there now. */
4015 spin_lock_bh(&ar->data_lock);
4016 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4017 spin_unlock_bh(&ar->data_lock);
4018
4019 if (!peer) {
4020 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004021 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022 peer_addr);
4023 ret = -EOPNOTSUPP;
4024 goto exit;
4025 } else {
4026 /* if the peer doesn't exist there is no key to disable
4027 * anymore */
4028 goto exit;
4029 }
4030 }
4031
4032 if (is_wep) {
4033 if (cmd == SET_KEY)
4034 arvif->wep_keys[key->keyidx] = key;
4035 else
4036 arvif->wep_keys[key->keyidx] = NULL;
4037
4038 if (cmd == DISABLE_KEY)
4039 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004040
Michal Kaziorad325cb2015-02-18 14:02:27 +01004041 /* When WEP keys are uploaded it's possible that there are
4042 * stations associated already (e.g. when merging) without any
4043 * keys. Static WEP needs an explicit per-peer key upload.
4044 */
4045 if (vif->type == NL80211_IFTYPE_ADHOC &&
4046 cmd == SET_KEY)
4047 ath10k_mac_vif_update_wep_key(arvif, key);
4048
Michal Kazior370e5672015-02-18 14:02:26 +01004049 /* 802.1x never sets the def_wep_key_idx so each set_key()
4050 * call changes default tx key.
4051 *
4052 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4053 * after first set_key().
4054 */
4055 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4056 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004057 }
4058
Michal Kazior370e5672015-02-18 14:02:26 +01004059 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4060 flags |= WMI_KEY_PAIRWISE;
4061 else
4062 flags |= WMI_KEY_GROUP;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004063
Michal Kazior370e5672015-02-18 14:02:26 +01004064 /* mac80211 uploads static WEP keys as groupwise while fw/hw requires
4065 * pairwise keys for non-self peers, i.e. BSSID in STA mode and
4066 * associated stations in AP/IBSS.
4067 *
4068 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys work
4069 * fine when mapped directly from mac80211.
4070 *
4071 * Note: When installing first static WEP groupwise key (which should
4072 * be pairwise) def_wep_key_idx isn't known yet (it's equal to -1).
4073 * Since .set_default_unicast_key is called only for static WEP it's
4074 * used to re-upload the key as pairwise.
4075 */
4076 if (arvif->def_wep_key_idx >= 0 &&
4077 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4078 flags &= ~WMI_KEY_GROUP;
4079 flags |= WMI_KEY_PAIRWISE;
4080 }
4081
4082 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004084 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004085 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004086 goto exit;
4087 }
4088
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004089 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4090
Kalle Valo5e3dd152013-06-12 20:52:10 +03004091 spin_lock_bh(&ar->data_lock);
4092 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4093 if (peer && cmd == SET_KEY)
4094 peer->keys[key->keyidx] = key;
4095 else if (peer && cmd == DISABLE_KEY)
4096 peer->keys[key->keyidx] = NULL;
4097 else if (peer == NULL)
4098 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004099 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100 spin_unlock_bh(&ar->data_lock);
4101
4102exit:
4103 mutex_unlock(&ar->conf_mutex);
4104 return ret;
4105}
4106
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004107static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4108 struct ieee80211_vif *vif,
4109 int keyidx)
4110{
4111 struct ath10k *ar = hw->priv;
4112 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4113 int ret;
4114
4115 mutex_lock(&arvif->ar->conf_mutex);
4116
4117 if (arvif->ar->state != ATH10K_STATE_ON)
4118 goto unlock;
4119
4120 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4121 arvif->vdev_id, keyidx);
4122
4123 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4124 arvif->vdev_id,
4125 arvif->ar->wmi.vdev_param->def_keyid,
4126 keyidx);
4127
4128 if (ret) {
4129 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4130 arvif->vdev_id,
4131 ret);
4132 goto unlock;
4133 }
4134
4135 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004136
4137 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4138 if (ret) {
4139 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4140 arvif->vdev_id, ret);
4141 goto unlock;
4142 }
4143
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004144unlock:
4145 mutex_unlock(&arvif->ar->conf_mutex);
4146}
4147
Michal Kazior9797feb2014-02-14 14:49:48 +01004148static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4149{
4150 struct ath10k *ar;
4151 struct ath10k_vif *arvif;
4152 struct ath10k_sta *arsta;
4153 struct ieee80211_sta *sta;
4154 u32 changed, bw, nss, smps;
4155 int err;
4156
4157 arsta = container_of(wk, struct ath10k_sta, update_wk);
4158 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4159 arvif = arsta->arvif;
4160 ar = arvif->ar;
4161
4162 spin_lock_bh(&ar->data_lock);
4163
4164 changed = arsta->changed;
4165 arsta->changed = 0;
4166
4167 bw = arsta->bw;
4168 nss = arsta->nss;
4169 smps = arsta->smps;
4170
4171 spin_unlock_bh(&ar->data_lock);
4172
4173 mutex_lock(&ar->conf_mutex);
4174
4175 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004177 sta->addr, bw);
4178
4179 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4180 WMI_PEER_CHAN_WIDTH, bw);
4181 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004182 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004183 sta->addr, bw, err);
4184 }
4185
4186 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004187 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004188 sta->addr, nss);
4189
4190 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4191 WMI_PEER_NSS, nss);
4192 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004193 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004194 sta->addr, nss, err);
4195 }
4196
4197 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004199 sta->addr, smps);
4200
4201 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4202 WMI_PEER_SMPS_STATE, smps);
4203 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004204 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004205 sta->addr, smps, err);
4206 }
4207
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004208 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4209 changed & IEEE80211_RC_NSS_CHANGED) {
4210 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004211 sta->addr);
4212
Michal Kazior590922a2014-10-21 10:10:29 +03004213 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004214 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004215 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004216 sta->addr);
4217 }
4218
Michal Kazior9797feb2014-02-14 14:49:48 +01004219 mutex_unlock(&ar->conf_mutex);
4220}
4221
Michal Kaziorcfd10612014-11-25 15:16:05 +01004222static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4223{
4224 struct ath10k *ar = arvif->ar;
4225
4226 lockdep_assert_held(&ar->conf_mutex);
4227
4228 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4229 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4230 return 0;
4231
4232 if (ar->num_stations >= ar->max_num_stations)
4233 return -ENOBUFS;
4234
4235 ar->num_stations++;
4236
4237 return 0;
4238}
4239
4240static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4241{
4242 struct ath10k *ar = arvif->ar;
4243
4244 lockdep_assert_held(&ar->conf_mutex);
4245
4246 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4247 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4248 return;
4249
4250 ar->num_stations--;
4251}
4252
Kalle Valo5e3dd152013-06-12 20:52:10 +03004253static int ath10k_sta_state(struct ieee80211_hw *hw,
4254 struct ieee80211_vif *vif,
4255 struct ieee80211_sta *sta,
4256 enum ieee80211_sta_state old_state,
4257 enum ieee80211_sta_state new_state)
4258{
4259 struct ath10k *ar = hw->priv;
4260 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004261 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004262 int ret = 0;
4263
Michal Kazior76f90022014-02-25 09:29:57 +02004264 if (old_state == IEEE80211_STA_NOTEXIST &&
4265 new_state == IEEE80211_STA_NONE) {
4266 memset(arsta, 0, sizeof(*arsta));
4267 arsta->arvif = arvif;
4268 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4269 }
4270
Michal Kazior9797feb2014-02-14 14:49:48 +01004271 /* cancel must be done outside the mutex to avoid deadlock */
4272 if ((old_state == IEEE80211_STA_NONE &&
4273 new_state == IEEE80211_STA_NOTEXIST))
4274 cancel_work_sync(&arsta->update_wk);
4275
Kalle Valo5e3dd152013-06-12 20:52:10 +03004276 mutex_lock(&ar->conf_mutex);
4277
4278 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004279 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004280 /*
4281 * New station addition.
4282 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004283 ath10k_dbg(ar, ATH10K_DBG_MAC,
4284 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4285 arvif->vdev_id, sta->addr,
4286 ar->num_stations + 1, ar->max_num_stations,
4287 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004288
Michal Kaziorcfd10612014-11-25 15:16:05 +01004289 ret = ath10k_mac_inc_num_stations(arvif);
4290 if (ret) {
4291 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4292 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004293 goto exit;
4294 }
4295
Kalle Valo5e3dd152013-06-12 20:52:10 +03004296 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004297 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004298 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 -08004299 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004300 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004301 goto exit;
4302 }
Michal Kazior077efc82014-10-21 10:10:29 +03004303
4304 if (vif->type == NL80211_IFTYPE_STATION) {
4305 WARN_ON(arvif->is_started);
4306
4307 ret = ath10k_vdev_start(arvif);
4308 if (ret) {
4309 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4310 arvif->vdev_id, ret);
4311 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4312 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004313 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004314 goto exit;
4315 }
4316
4317 arvif->is_started = true;
4318 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004319 } else if ((old_state == IEEE80211_STA_NONE &&
4320 new_state == IEEE80211_STA_NOTEXIST)) {
4321 /*
4322 * Existing station deletion.
4323 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004324 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004325 "mac vdev %d peer delete %pM (sta gone)\n",
4326 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004327
4328 if (vif->type == NL80211_IFTYPE_STATION) {
4329 WARN_ON(!arvif->is_started);
4330
4331 ret = ath10k_vdev_stop(arvif);
4332 if (ret)
4333 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4334 arvif->vdev_id, ret);
4335
4336 arvif->is_started = false;
4337 }
4338
Kalle Valo5e3dd152013-06-12 20:52:10 +03004339 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4340 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004341 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004342 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004343
Michal Kaziorcfd10612014-11-25 15:16:05 +01004344 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004345 } else if (old_state == IEEE80211_STA_AUTH &&
4346 new_state == IEEE80211_STA_ASSOC &&
4347 (vif->type == NL80211_IFTYPE_AP ||
4348 vif->type == NL80211_IFTYPE_ADHOC)) {
4349 /*
4350 * New association.
4351 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004352 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004353 sta->addr);
4354
Michal Kazior590922a2014-10-21 10:10:29 +03004355 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004356 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004357 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004358 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004359 } else if (old_state == IEEE80211_STA_ASSOC &&
4360 new_state == IEEE80211_STA_AUTH &&
4361 (vif->type == NL80211_IFTYPE_AP ||
4362 vif->type == NL80211_IFTYPE_ADHOC)) {
4363 /*
4364 * Disassociation.
4365 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004366 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004367 sta->addr);
4368
Michal Kazior590922a2014-10-21 10:10:29 +03004369 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004370 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004371 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004372 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004374exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004375 mutex_unlock(&ar->conf_mutex);
4376 return ret;
4377}
4378
4379static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004380 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004381{
4382 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004383 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4384 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004385 u32 value = 0;
4386 int ret = 0;
4387
Michal Kazior548db542013-07-05 16:15:15 +03004388 lockdep_assert_held(&ar->conf_mutex);
4389
Kalle Valo5e3dd152013-06-12 20:52:10 +03004390 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4391 return 0;
4392
4393 switch (ac) {
4394 case IEEE80211_AC_VO:
4395 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4396 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004397 prio = 7;
4398 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004399 break;
4400 case IEEE80211_AC_VI:
4401 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4402 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004403 prio = 5;
4404 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004405 break;
4406 case IEEE80211_AC_BE:
4407 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4408 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004409 prio = 2;
4410 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004411 break;
4412 case IEEE80211_AC_BK:
4413 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4414 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004415 prio = 0;
4416 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004417 break;
4418 }
4419
4420 if (enable)
4421 arvif->u.sta.uapsd |= value;
4422 else
4423 arvif->u.sta.uapsd &= ~value;
4424
4425 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4426 WMI_STA_PS_PARAM_UAPSD,
4427 arvif->u.sta.uapsd);
4428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004429 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004430 goto exit;
4431 }
4432
4433 if (arvif->u.sta.uapsd)
4434 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4435 else
4436 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4437
4438 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4439 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4440 value);
4441 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004442 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004443
Michal Kazior9f9b5742014-12-12 12:41:36 +01004444 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4445 if (ret) {
4446 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4447 arvif->vdev_id, ret);
4448 return ret;
4449 }
4450
4451 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4452 if (ret) {
4453 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4454 arvif->vdev_id, ret);
4455 return ret;
4456 }
4457
Michal Kaziorb0e56152015-01-24 12:14:52 +02004458 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4459 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4460 /* Only userspace can make an educated decision when to send
4461 * trigger frame. The following effectively disables u-UAPSD
4462 * autotrigger in firmware (which is enabled by default
4463 * provided the autotrigger service is available).
4464 */
4465
4466 arg.wmm_ac = acc;
4467 arg.user_priority = prio;
4468 arg.service_interval = 0;
4469 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4470 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4471
4472 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4473 arvif->bssid, &arg, 1);
4474 if (ret) {
4475 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4476 ret);
4477 return ret;
4478 }
4479 }
4480
Kalle Valo5e3dd152013-06-12 20:52:10 +03004481exit:
4482 return ret;
4483}
4484
4485static int ath10k_conf_tx(struct ieee80211_hw *hw,
4486 struct ieee80211_vif *vif, u16 ac,
4487 const struct ieee80211_tx_queue_params *params)
4488{
4489 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004490 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004491 struct wmi_wmm_params_arg *p = NULL;
4492 int ret;
4493
4494 mutex_lock(&ar->conf_mutex);
4495
4496 switch (ac) {
4497 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004498 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004499 break;
4500 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004501 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004502 break;
4503 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004504 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004505 break;
4506 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004507 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004508 break;
4509 }
4510
4511 if (WARN_ON(!p)) {
4512 ret = -EINVAL;
4513 goto exit;
4514 }
4515
4516 p->cwmin = params->cw_min;
4517 p->cwmax = params->cw_max;
4518 p->aifs = params->aifs;
4519
4520 /*
4521 * The channel time duration programmed in the HW is in absolute
4522 * microseconds, while mac80211 gives the txop in units of
4523 * 32 microseconds.
4524 */
4525 p->txop = params->txop * 32;
4526
Michal Kazior7fc979a2015-01-28 09:57:28 +02004527 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4528 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4529 &arvif->wmm_params);
4530 if (ret) {
4531 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4532 arvif->vdev_id, ret);
4533 goto exit;
4534 }
4535 } else {
4536 /* This won't work well with multi-interface cases but it's
4537 * better than nothing.
4538 */
4539 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4540 if (ret) {
4541 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4542 goto exit;
4543 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004544 }
4545
4546 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4547 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004548 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004549
4550exit:
4551 mutex_unlock(&ar->conf_mutex);
4552 return ret;
4553}
4554
4555#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4556
4557static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4558 struct ieee80211_vif *vif,
4559 struct ieee80211_channel *chan,
4560 int duration,
4561 enum ieee80211_roc_type type)
4562{
4563 struct ath10k *ar = hw->priv;
4564 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4565 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004566 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004567
4568 mutex_lock(&ar->conf_mutex);
4569
4570 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004571 switch (ar->scan.state) {
4572 case ATH10K_SCAN_IDLE:
4573 reinit_completion(&ar->scan.started);
4574 reinit_completion(&ar->scan.completed);
4575 reinit_completion(&ar->scan.on_channel);
4576 ar->scan.state = ATH10K_SCAN_STARTING;
4577 ar->scan.is_roc = true;
4578 ar->scan.vdev_id = arvif->vdev_id;
4579 ar->scan.roc_freq = chan->center_freq;
4580 ret = 0;
4581 break;
4582 case ATH10K_SCAN_STARTING:
4583 case ATH10K_SCAN_RUNNING:
4584 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004585 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004586 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004587 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004588 spin_unlock_bh(&ar->data_lock);
4589
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004590 if (ret)
4591 goto exit;
4592
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004593 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4594
Kalle Valo5e3dd152013-06-12 20:52:10 +03004595 memset(&arg, 0, sizeof(arg));
4596 ath10k_wmi_start_scan_init(ar, &arg);
4597 arg.vdev_id = arvif->vdev_id;
4598 arg.scan_id = ATH10K_SCAN_ID;
4599 arg.n_channels = 1;
4600 arg.channels[0] = chan->center_freq;
4601 arg.dwell_time_active = duration;
4602 arg.dwell_time_passive = duration;
4603 arg.max_scan_time = 2 * duration;
4604 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4605 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4606
4607 ret = ath10k_start_scan(ar, &arg);
4608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004609 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004610 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004611 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004612 spin_unlock_bh(&ar->data_lock);
4613 goto exit;
4614 }
4615
4616 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4617 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004618 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004619
4620 ret = ath10k_scan_stop(ar);
4621 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004622 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004623
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624 ret = -ETIMEDOUT;
4625 goto exit;
4626 }
4627
4628 ret = 0;
4629exit:
4630 mutex_unlock(&ar->conf_mutex);
4631 return ret;
4632}
4633
4634static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4635{
4636 struct ath10k *ar = hw->priv;
4637
4638 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004639 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004640 mutex_unlock(&ar->conf_mutex);
4641
Michal Kazior4eb2e162014-10-28 10:23:09 +01004642 cancel_delayed_work_sync(&ar->scan.timeout);
4643
Kalle Valo5e3dd152013-06-12 20:52:10 +03004644 return 0;
4645}
4646
4647/*
4648 * Both RTS and Fragmentation threshold are interface-specific
4649 * in ath10k, but device-specific in mac80211.
4650 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004651
4652static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4653{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004654 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004655 struct ath10k_vif *arvif;
4656 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004657
Michal Kaziorad088bf2013-10-16 15:44:46 +03004658 mutex_lock(&ar->conf_mutex);
4659 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004660 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004661 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004662
Michal Kaziorad088bf2013-10-16 15:44:46 +03004663 ret = ath10k_mac_set_rts(arvif, value);
4664 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004665 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004666 arvif->vdev_id, ret);
4667 break;
4668 }
4669 }
4670 mutex_unlock(&ar->conf_mutex);
4671
4672 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673}
4674
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004675static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4676 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004677{
4678 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004679 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004680 int ret;
4681
4682 /* mac80211 doesn't care if we really xmit queued frames or not
4683 * we'll collect those frames either way if we stop/delete vdevs */
4684 if (drop)
4685 return;
4686
Michal Kazior548db542013-07-05 16:15:15 +03004687 mutex_lock(&ar->conf_mutex);
4688
Michal Kazioraffd3212013-07-16 09:54:35 +02004689 if (ar->state == ATH10K_STATE_WEDGED)
4690 goto skip;
4691
Michal Kazioredb82362013-07-05 16:15:14 +03004692 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004693 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004694
Michal Kazioredb82362013-07-05 16:15:14 +03004695 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004696 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004697 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004698
Michal Kazior7962b0d2014-10-28 10:34:38 +01004699 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4700 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4701 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004702
4703 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004705
4706 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004707 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004708 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004709
Michal Kazioraffd3212013-07-16 09:54:35 +02004710skip:
Michal Kazior548db542013-07-05 16:15:15 +03004711 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004712}
4713
4714/* TODO: Implement this function properly
4715 * For now it is needed to reply to Probe Requests in IBSS mode.
4716 * Propably we need this information from FW.
4717 */
4718static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4719{
4720 return 1;
4721}
4722
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004723#ifdef CONFIG_PM
4724static int ath10k_suspend(struct ieee80211_hw *hw,
4725 struct cfg80211_wowlan *wowlan)
4726{
4727 struct ath10k *ar = hw->priv;
4728 int ret;
4729
Marek Puzyniak9042e172014-02-10 17:14:23 +01004730 mutex_lock(&ar->conf_mutex);
4731
Marek Puzyniak00f54822014-02-10 17:14:24 +01004732 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004733 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004734 if (ret == -ETIMEDOUT)
4735 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004736 ret = 1;
4737 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004738 }
4739
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004740 ret = ath10k_hif_suspend(ar);
4741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004742 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004743 goto resume;
4744 }
4745
Marek Puzyniak9042e172014-02-10 17:14:23 +01004746 ret = 0;
4747 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004748resume:
4749 ret = ath10k_wmi_pdev_resume_target(ar);
4750 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004751 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004752
4753 ret = 1;
4754exit:
4755 mutex_unlock(&ar->conf_mutex);
4756 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004757}
4758
4759static int ath10k_resume(struct ieee80211_hw *hw)
4760{
4761 struct ath10k *ar = hw->priv;
4762 int ret;
4763
Marek Puzyniak9042e172014-02-10 17:14:23 +01004764 mutex_lock(&ar->conf_mutex);
4765
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004766 ret = ath10k_hif_resume(ar);
4767 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004768 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004769 ret = 1;
4770 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004771 }
4772
4773 ret = ath10k_wmi_pdev_resume_target(ar);
4774 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004775 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004776 ret = 1;
4777 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004778 }
4779
Marek Puzyniak9042e172014-02-10 17:14:23 +01004780 ret = 0;
4781exit:
4782 mutex_unlock(&ar->conf_mutex);
4783 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004784}
4785#endif
4786
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004787static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4788 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004789{
4790 struct ath10k *ar = hw->priv;
4791
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004792 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4793 return;
4794
Michal Kazioraffd3212013-07-16 09:54:35 +02004795 mutex_lock(&ar->conf_mutex);
4796
4797 /* If device failed to restart it will be in a different state, e.g.
4798 * ATH10K_STATE_WEDGED */
4799 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004800 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004801 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004802 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004803 }
4804
4805 mutex_unlock(&ar->conf_mutex);
4806}
4807
Michal Kazior2e1dea42013-07-31 10:32:40 +02004808static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4809 struct survey_info *survey)
4810{
4811 struct ath10k *ar = hw->priv;
4812 struct ieee80211_supported_band *sband;
4813 struct survey_info *ar_survey = &ar->survey[idx];
4814 int ret = 0;
4815
4816 mutex_lock(&ar->conf_mutex);
4817
4818 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4819 if (sband && idx >= sband->n_channels) {
4820 idx -= sband->n_channels;
4821 sband = NULL;
4822 }
4823
4824 if (!sband)
4825 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4826
4827 if (!sband || idx >= sband->n_channels) {
4828 ret = -ENOENT;
4829 goto exit;
4830 }
4831
4832 spin_lock_bh(&ar->data_lock);
4833 memcpy(survey, ar_survey, sizeof(*survey));
4834 spin_unlock_bh(&ar->data_lock);
4835
4836 survey->channel = &sband->channels[idx];
4837
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004838 if (ar->rx_channel == survey->channel)
4839 survey->filled |= SURVEY_INFO_IN_USE;
4840
Michal Kazior2e1dea42013-07-31 10:32:40 +02004841exit:
4842 mutex_unlock(&ar->conf_mutex);
4843 return ret;
4844}
4845
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004846/* Helper table for legacy fixed_rate/bitrate_mask */
4847static const u8 cck_ofdm_rate[] = {
4848 /* CCK */
4849 3, /* 1Mbps */
4850 2, /* 2Mbps */
4851 1, /* 5.5Mbps */
4852 0, /* 11Mbps */
4853 /* OFDM */
4854 3, /* 6Mbps */
4855 7, /* 9Mbps */
4856 2, /* 12Mbps */
4857 6, /* 18Mbps */
4858 1, /* 24Mbps */
4859 5, /* 36Mbps */
4860 0, /* 48Mbps */
4861 4, /* 54Mbps */
4862};
4863
4864/* Check if only one bit set */
4865static int ath10k_check_single_mask(u32 mask)
4866{
4867 int bit;
4868
4869 bit = ffs(mask);
4870 if (!bit)
4871 return 0;
4872
4873 mask &= ~BIT(bit - 1);
4874 if (mask)
4875 return 2;
4876
4877 return 1;
4878}
4879
4880static bool
4881ath10k_default_bitrate_mask(struct ath10k *ar,
4882 enum ieee80211_band band,
4883 const struct cfg80211_bitrate_mask *mask)
4884{
4885 u32 legacy = 0x00ff;
4886 u8 ht = 0xff, i;
4887 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004888 u16 nrf = ar->num_rf_chains;
4889
4890 if (ar->cfg_tx_chainmask)
4891 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004892
4893 switch (band) {
4894 case IEEE80211_BAND_2GHZ:
4895 legacy = 0x00fff;
4896 vht = 0;
4897 break;
4898 case IEEE80211_BAND_5GHZ:
4899 break;
4900 default:
4901 return false;
4902 }
4903
4904 if (mask->control[band].legacy != legacy)
4905 return false;
4906
Ben Greearb116ea12014-11-24 16:22:10 +02004907 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004908 if (mask->control[band].ht_mcs[i] != ht)
4909 return false;
4910
Ben Greearb116ea12014-11-24 16:22:10 +02004911 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004912 if (mask->control[band].vht_mcs[i] != vht)
4913 return false;
4914
4915 return true;
4916}
4917
4918static bool
4919ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4920 enum ieee80211_band band,
4921 u8 *fixed_nss)
4922{
4923 int ht_nss = 0, vht_nss = 0, i;
4924
4925 /* check legacy */
4926 if (ath10k_check_single_mask(mask->control[band].legacy))
4927 return false;
4928
4929 /* check HT */
4930 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4931 if (mask->control[band].ht_mcs[i] == 0xff)
4932 continue;
4933 else if (mask->control[band].ht_mcs[i] == 0x00)
4934 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004935
4936 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004937 }
4938
4939 ht_nss = i;
4940
4941 /* check VHT */
4942 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4943 if (mask->control[band].vht_mcs[i] == 0x03ff)
4944 continue;
4945 else if (mask->control[band].vht_mcs[i] == 0x0000)
4946 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004947
4948 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004949 }
4950
4951 vht_nss = i;
4952
4953 if (ht_nss > 0 && vht_nss > 0)
4954 return false;
4955
4956 if (ht_nss)
4957 *fixed_nss = ht_nss;
4958 else if (vht_nss)
4959 *fixed_nss = vht_nss;
4960 else
4961 return false;
4962
4963 return true;
4964}
4965
4966static bool
4967ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4968 enum ieee80211_band band,
4969 enum wmi_rate_preamble *preamble)
4970{
4971 int legacy = 0, ht = 0, vht = 0, i;
4972
4973 *preamble = WMI_RATE_PREAMBLE_OFDM;
4974
4975 /* check legacy */
4976 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4977 if (legacy > 1)
4978 return false;
4979
4980 /* check HT */
4981 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4982 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4983 if (ht > 1)
4984 return false;
4985
4986 /* check VHT */
4987 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4988 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4989 if (vht > 1)
4990 return false;
4991
4992 /* Currently we support only one fixed_rate */
4993 if ((legacy + ht + vht) != 1)
4994 return false;
4995
4996 if (ht)
4997 *preamble = WMI_RATE_PREAMBLE_HT;
4998 else if (vht)
4999 *preamble = WMI_RATE_PREAMBLE_VHT;
5000
5001 return true;
5002}
5003
5004static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005005ath10k_bitrate_mask_rate(struct ath10k *ar,
5006 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005007 enum ieee80211_band band,
5008 u8 *fixed_rate,
5009 u8 *fixed_nss)
5010{
5011 u8 rate = 0, pream = 0, nss = 0, i;
5012 enum wmi_rate_preamble preamble;
5013
5014 /* Check if single rate correct */
5015 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5016 return false;
5017
5018 pream = preamble;
5019
5020 switch (preamble) {
5021 case WMI_RATE_PREAMBLE_CCK:
5022 case WMI_RATE_PREAMBLE_OFDM:
5023 i = ffs(mask->control[band].legacy) - 1;
5024
5025 if (band == IEEE80211_BAND_2GHZ && i < 4)
5026 pream = WMI_RATE_PREAMBLE_CCK;
5027
5028 if (band == IEEE80211_BAND_5GHZ)
5029 i += 4;
5030
5031 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5032 return false;
5033
5034 rate = cck_ofdm_rate[i];
5035 break;
5036 case WMI_RATE_PREAMBLE_HT:
5037 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5038 if (mask->control[band].ht_mcs[i])
5039 break;
5040
5041 if (i == IEEE80211_HT_MCS_MASK_LEN)
5042 return false;
5043
5044 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5045 nss = i;
5046 break;
5047 case WMI_RATE_PREAMBLE_VHT:
5048 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5049 if (mask->control[band].vht_mcs[i])
5050 break;
5051
5052 if (i == NL80211_VHT_NSS_MAX)
5053 return false;
5054
5055 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5056 nss = i;
5057 break;
5058 }
5059
5060 *fixed_nss = nss + 1;
5061 nss <<= 4;
5062 pream <<= 6;
5063
Michal Kazior7aa7a722014-08-25 12:09:38 +02005064 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 +01005065 pream, nss, rate);
5066
5067 *fixed_rate = pream | nss | rate;
5068
5069 return true;
5070}
5071
Michal Kazior7aa7a722014-08-25 12:09:38 +02005072static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5073 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005074 enum ieee80211_band band,
5075 u8 *fixed_rate,
5076 u8 *fixed_nss)
5077{
5078 /* First check full NSS mask, if we can simply limit NSS */
5079 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5080 return true;
5081
5082 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005083 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005084}
5085
5086static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5087 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005088 u8 fixed_nss,
5089 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005090{
5091 struct ath10k *ar = arvif->ar;
5092 u32 vdev_param;
5093 int ret = 0;
5094
5095 mutex_lock(&ar->conf_mutex);
5096
5097 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005098 arvif->fixed_nss == fixed_nss &&
5099 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005100 goto exit;
5101
5102 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005103 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005104
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005105 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005106 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005107
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005108 vdev_param = ar->wmi.vdev_param->fixed_rate;
5109 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5110 vdev_param, fixed_rate);
5111 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005112 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005113 fixed_rate, ret);
5114 ret = -EINVAL;
5115 goto exit;
5116 }
5117
5118 arvif->fixed_rate = fixed_rate;
5119
5120 vdev_param = ar->wmi.vdev_param->nss;
5121 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5122 vdev_param, fixed_nss);
5123
5124 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005125 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005126 fixed_nss, ret);
5127 ret = -EINVAL;
5128 goto exit;
5129 }
5130
5131 arvif->fixed_nss = fixed_nss;
5132
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005133 vdev_param = ar->wmi.vdev_param->sgi;
5134 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5135 force_sgi);
5136
5137 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005138 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005139 force_sgi, ret);
5140 ret = -EINVAL;
5141 goto exit;
5142 }
5143
5144 arvif->force_sgi = force_sgi;
5145
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005146exit:
5147 mutex_unlock(&ar->conf_mutex);
5148 return ret;
5149}
5150
5151static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5152 struct ieee80211_vif *vif,
5153 const struct cfg80211_bitrate_mask *mask)
5154{
5155 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5156 struct ath10k *ar = arvif->ar;
5157 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5158 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5159 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005160 u8 force_sgi;
5161
Ben Greearb116ea12014-11-24 16:22:10 +02005162 if (ar->cfg_tx_chainmask)
5163 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5164
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005165 force_sgi = mask->control[band].gi;
5166 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5167 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005168
5169 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005170 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005171 &fixed_rate,
5172 &fixed_nss))
5173 return -EINVAL;
5174 }
5175
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005176 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005177 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005178 return -EINVAL;
5179 }
5180
5181 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5182 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005183}
5184
Michal Kazior9797feb2014-02-14 14:49:48 +01005185static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5186 struct ieee80211_vif *vif,
5187 struct ieee80211_sta *sta,
5188 u32 changed)
5189{
5190 struct ath10k *ar = hw->priv;
5191 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5192 u32 bw, smps;
5193
5194 spin_lock_bh(&ar->data_lock);
5195
Michal Kazior7aa7a722014-08-25 12:09:38 +02005196 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005197 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5198 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5199 sta->smps_mode);
5200
5201 if (changed & IEEE80211_RC_BW_CHANGED) {
5202 bw = WMI_PEER_CHWIDTH_20MHZ;
5203
5204 switch (sta->bandwidth) {
5205 case IEEE80211_STA_RX_BW_20:
5206 bw = WMI_PEER_CHWIDTH_20MHZ;
5207 break;
5208 case IEEE80211_STA_RX_BW_40:
5209 bw = WMI_PEER_CHWIDTH_40MHZ;
5210 break;
5211 case IEEE80211_STA_RX_BW_80:
5212 bw = WMI_PEER_CHWIDTH_80MHZ;
5213 break;
5214 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005215 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005216 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005217 bw = WMI_PEER_CHWIDTH_20MHZ;
5218 break;
5219 }
5220
5221 arsta->bw = bw;
5222 }
5223
5224 if (changed & IEEE80211_RC_NSS_CHANGED)
5225 arsta->nss = sta->rx_nss;
5226
5227 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5228 smps = WMI_PEER_SMPS_PS_NONE;
5229
5230 switch (sta->smps_mode) {
5231 case IEEE80211_SMPS_AUTOMATIC:
5232 case IEEE80211_SMPS_OFF:
5233 smps = WMI_PEER_SMPS_PS_NONE;
5234 break;
5235 case IEEE80211_SMPS_STATIC:
5236 smps = WMI_PEER_SMPS_STATIC;
5237 break;
5238 case IEEE80211_SMPS_DYNAMIC:
5239 smps = WMI_PEER_SMPS_DYNAMIC;
5240 break;
5241 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005242 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005243 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005244 smps = WMI_PEER_SMPS_PS_NONE;
5245 break;
5246 }
5247
5248 arsta->smps = smps;
5249 }
5250
Michal Kazior9797feb2014-02-14 14:49:48 +01005251 arsta->changed |= changed;
5252
5253 spin_unlock_bh(&ar->data_lock);
5254
5255 ieee80211_queue_work(hw, &arsta->update_wk);
5256}
5257
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005258static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5259{
5260 /*
5261 * FIXME: Return 0 for time being. Need to figure out whether FW
5262 * has the API to fetch 64-bit local TSF
5263 */
5264
5265 return 0;
5266}
5267
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005268static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5269 struct ieee80211_vif *vif,
5270 enum ieee80211_ampdu_mlme_action action,
5271 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5272 u8 buf_size)
5273{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005274 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005275 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5276
Michal Kazior7aa7a722014-08-25 12:09:38 +02005277 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 +02005278 arvif->vdev_id, sta->addr, tid, action);
5279
5280 switch (action) {
5281 case IEEE80211_AMPDU_RX_START:
5282 case IEEE80211_AMPDU_RX_STOP:
5283 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5284 * creation/removal. Do we need to verify this?
5285 */
5286 return 0;
5287 case IEEE80211_AMPDU_TX_START:
5288 case IEEE80211_AMPDU_TX_STOP_CONT:
5289 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5290 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5291 case IEEE80211_AMPDU_TX_OPERATIONAL:
5292 /* Firmware offloads Tx aggregation entirely so deny mac80211
5293 * Tx aggregation requests.
5294 */
5295 return -EOPNOTSUPP;
5296 }
5297
5298 return -EINVAL;
5299}
5300
Kalle Valo5e3dd152013-06-12 20:52:10 +03005301static const struct ieee80211_ops ath10k_ops = {
5302 .tx = ath10k_tx,
5303 .start = ath10k_start,
5304 .stop = ath10k_stop,
5305 .config = ath10k_config,
5306 .add_interface = ath10k_add_interface,
5307 .remove_interface = ath10k_remove_interface,
5308 .configure_filter = ath10k_configure_filter,
5309 .bss_info_changed = ath10k_bss_info_changed,
5310 .hw_scan = ath10k_hw_scan,
5311 .cancel_hw_scan = ath10k_cancel_hw_scan,
5312 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005313 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314 .sta_state = ath10k_sta_state,
5315 .conf_tx = ath10k_conf_tx,
5316 .remain_on_channel = ath10k_remain_on_channel,
5317 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5318 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005319 .flush = ath10k_flush,
5320 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03005321 .set_antenna = ath10k_set_antenna,
5322 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005323 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005324 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005325 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005326 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005327 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005328 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005329 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5330 .get_et_stats = ath10k_debug_get_et_stats,
5331 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005332
5333 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5334
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005335#ifdef CONFIG_PM
5336 .suspend = ath10k_suspend,
5337 .resume = ath10k_resume,
5338#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005339#ifdef CONFIG_MAC80211_DEBUGFS
5340 .sta_add_debugfs = ath10k_sta_add_debugfs,
5341#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005342};
5343
5344#define RATETAB_ENT(_rate, _rateid, _flags) { \
5345 .bitrate = (_rate), \
5346 .flags = (_flags), \
5347 .hw_value = (_rateid), \
5348}
5349
5350#define CHAN2G(_channel, _freq, _flags) { \
5351 .band = IEEE80211_BAND_2GHZ, \
5352 .hw_value = (_channel), \
5353 .center_freq = (_freq), \
5354 .flags = (_flags), \
5355 .max_antenna_gain = 0, \
5356 .max_power = 30, \
5357}
5358
5359#define CHAN5G(_channel, _freq, _flags) { \
5360 .band = IEEE80211_BAND_5GHZ, \
5361 .hw_value = (_channel), \
5362 .center_freq = (_freq), \
5363 .flags = (_flags), \
5364 .max_antenna_gain = 0, \
5365 .max_power = 30, \
5366}
5367
5368static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5369 CHAN2G(1, 2412, 0),
5370 CHAN2G(2, 2417, 0),
5371 CHAN2G(3, 2422, 0),
5372 CHAN2G(4, 2427, 0),
5373 CHAN2G(5, 2432, 0),
5374 CHAN2G(6, 2437, 0),
5375 CHAN2G(7, 2442, 0),
5376 CHAN2G(8, 2447, 0),
5377 CHAN2G(9, 2452, 0),
5378 CHAN2G(10, 2457, 0),
5379 CHAN2G(11, 2462, 0),
5380 CHAN2G(12, 2467, 0),
5381 CHAN2G(13, 2472, 0),
5382 CHAN2G(14, 2484, 0),
5383};
5384
5385static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005386 CHAN5G(36, 5180, 0),
5387 CHAN5G(40, 5200, 0),
5388 CHAN5G(44, 5220, 0),
5389 CHAN5G(48, 5240, 0),
5390 CHAN5G(52, 5260, 0),
5391 CHAN5G(56, 5280, 0),
5392 CHAN5G(60, 5300, 0),
5393 CHAN5G(64, 5320, 0),
5394 CHAN5G(100, 5500, 0),
5395 CHAN5G(104, 5520, 0),
5396 CHAN5G(108, 5540, 0),
5397 CHAN5G(112, 5560, 0),
5398 CHAN5G(116, 5580, 0),
5399 CHAN5G(120, 5600, 0),
5400 CHAN5G(124, 5620, 0),
5401 CHAN5G(128, 5640, 0),
5402 CHAN5G(132, 5660, 0),
5403 CHAN5G(136, 5680, 0),
5404 CHAN5G(140, 5700, 0),
5405 CHAN5G(149, 5745, 0),
5406 CHAN5G(153, 5765, 0),
5407 CHAN5G(157, 5785, 0),
5408 CHAN5G(161, 5805, 0),
5409 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005410};
5411
Michal Kazior91b12082014-12-12 12:41:35 +01005412/* Note: Be careful if you re-order these. There is code which depends on this
5413 * ordering.
5414 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005415static struct ieee80211_rate ath10k_rates[] = {
5416 /* CCK */
5417 RATETAB_ENT(10, 0x82, 0),
5418 RATETAB_ENT(20, 0x84, 0),
5419 RATETAB_ENT(55, 0x8b, 0),
5420 RATETAB_ENT(110, 0x96, 0),
5421 /* OFDM */
5422 RATETAB_ENT(60, 0x0c, 0),
5423 RATETAB_ENT(90, 0x12, 0),
5424 RATETAB_ENT(120, 0x18, 0),
5425 RATETAB_ENT(180, 0x24, 0),
5426 RATETAB_ENT(240, 0x30, 0),
5427 RATETAB_ENT(360, 0x48, 0),
5428 RATETAB_ENT(480, 0x60, 0),
5429 RATETAB_ENT(540, 0x6c, 0),
5430};
5431
5432#define ath10k_a_rates (ath10k_rates + 4)
5433#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5434#define ath10k_g_rates (ath10k_rates + 0)
5435#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5436
Michal Kaziore7b54192014-08-07 11:03:27 +02005437struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438{
5439 struct ieee80211_hw *hw;
5440 struct ath10k *ar;
5441
Michal Kaziore7b54192014-08-07 11:03:27 +02005442 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005443 if (!hw)
5444 return NULL;
5445
5446 ar = hw->priv;
5447 ar->hw = hw;
5448
5449 return ar;
5450}
5451
5452void ath10k_mac_destroy(struct ath10k *ar)
5453{
5454 ieee80211_free_hw(ar->hw);
5455}
5456
5457static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5458 {
5459 .max = 8,
5460 .types = BIT(NL80211_IFTYPE_STATION)
5461 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005462 },
5463 {
5464 .max = 3,
5465 .types = BIT(NL80211_IFTYPE_P2P_GO)
5466 },
5467 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005468 .max = 1,
5469 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5470 },
5471 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005472 .max = 7,
5473 .types = BIT(NL80211_IFTYPE_AP)
5474 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005475};
5476
Bartosz Markowskif2595092013-12-10 16:20:39 +01005477static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005478 {
5479 .max = 8,
5480 .types = BIT(NL80211_IFTYPE_AP)
5481 },
5482};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005483
5484static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5485 {
5486 .limits = ath10k_if_limits,
5487 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5488 .max_interfaces = 8,
5489 .num_different_channels = 1,
5490 .beacon_int_infra_match = true,
5491 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005492};
5493
5494static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005495 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005496 .limits = ath10k_10x_if_limits,
5497 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005498 .max_interfaces = 8,
5499 .num_different_channels = 1,
5500 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005501#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005502 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5503 BIT(NL80211_CHAN_WIDTH_20) |
5504 BIT(NL80211_CHAN_WIDTH_40) |
5505 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005506#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005507 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005508};
5509
5510static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5511{
5512 struct ieee80211_sta_vht_cap vht_cap = {0};
5513 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005514 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005515 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005516
5517 vht_cap.vht_supported = 1;
5518 vht_cap.cap = ar->vht_cap_info;
5519
Michal Kaziorbc657a362015-02-26 11:11:22 +01005520 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5521 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5522 val = ar->num_rf_chains - 1;
5523 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5524 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5525
5526 vht_cap.cap |= val;
5527 }
5528
5529 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5530 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5531 val = ar->num_rf_chains - 1;
5532 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5533 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5534
5535 vht_cap.cap |= val;
5536 }
5537
Michal Kazior8865bee42013-07-24 12:36:46 +02005538 mcs_map = 0;
5539 for (i = 0; i < 8; i++) {
5540 if (i < ar->num_rf_chains)
5541 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5542 else
5543 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5544 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005545
5546 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5547 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5548
5549 return vht_cap;
5550}
5551
5552static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5553{
5554 int i;
5555 struct ieee80211_sta_ht_cap ht_cap = {0};
5556
5557 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5558 return ht_cap;
5559
5560 ht_cap.ht_supported = 1;
5561 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5562 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5563 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5564 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5565 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5566
5567 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5568 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5569
5570 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5571 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5572
5573 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5574 u32 smps;
5575
5576 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5577 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5578
5579 ht_cap.cap |= smps;
5580 }
5581
5582 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5583 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5584
5585 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5586 u32 stbc;
5587
5588 stbc = ar->ht_cap_info;
5589 stbc &= WMI_HT_CAP_RX_STBC;
5590 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5591 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5592 stbc &= IEEE80211_HT_CAP_RX_STBC;
5593
5594 ht_cap.cap |= stbc;
5595 }
5596
5597 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5598 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5599
5600 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5601 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5602
5603 /* max AMSDU is implicitly taken from vht_cap_info */
5604 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5605 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5606
Michal Kazior8865bee42013-07-24 12:36:46 +02005607 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005608 ht_cap.mcs.rx_mask[i] = 0xFF;
5609
5610 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5611
5612 return ht_cap;
5613}
5614
Kalle Valo5e3dd152013-06-12 20:52:10 +03005615static void ath10k_get_arvif_iter(void *data, u8 *mac,
5616 struct ieee80211_vif *vif)
5617{
5618 struct ath10k_vif_iter *arvif_iter = data;
5619 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5620
5621 if (arvif->vdev_id == arvif_iter->vdev_id)
5622 arvif_iter->arvif = arvif;
5623}
5624
5625struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5626{
5627 struct ath10k_vif_iter arvif_iter;
5628 u32 flags;
5629
5630 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5631 arvif_iter.vdev_id = vdev_id;
5632
5633 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5634 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5635 flags,
5636 ath10k_get_arvif_iter,
5637 &arvif_iter);
5638 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005639 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005640 return NULL;
5641 }
5642
5643 return arvif_iter.arvif;
5644}
5645
5646int ath10k_mac_register(struct ath10k *ar)
5647{
Johannes Berg3cb10942015-01-22 21:38:45 +01005648 static const u32 cipher_suites[] = {
5649 WLAN_CIPHER_SUITE_WEP40,
5650 WLAN_CIPHER_SUITE_WEP104,
5651 WLAN_CIPHER_SUITE_TKIP,
5652 WLAN_CIPHER_SUITE_CCMP,
5653 WLAN_CIPHER_SUITE_AES_CMAC,
5654 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005655 struct ieee80211_supported_band *band;
5656 struct ieee80211_sta_vht_cap vht_cap;
5657 struct ieee80211_sta_ht_cap ht_cap;
5658 void *channels;
5659 int ret;
5660
5661 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5662
5663 SET_IEEE80211_DEV(ar->hw, ar->dev);
5664
5665 ht_cap = ath10k_get_ht_cap(ar);
5666 vht_cap = ath10k_create_vht_cap(ar);
5667
5668 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5669 channels = kmemdup(ath10k_2ghz_channels,
5670 sizeof(ath10k_2ghz_channels),
5671 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005672 if (!channels) {
5673 ret = -ENOMEM;
5674 goto err_free;
5675 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005676
5677 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5678 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5679 band->channels = channels;
5680 band->n_bitrates = ath10k_g_rates_size;
5681 band->bitrates = ath10k_g_rates;
5682 band->ht_cap = ht_cap;
5683
Yanbo Lid68bb122015-01-23 08:18:20 +08005684 /* Enable the VHT support at 2.4 GHz */
5685 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005686
5687 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5688 }
5689
5690 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5691 channels = kmemdup(ath10k_5ghz_channels,
5692 sizeof(ath10k_5ghz_channels),
5693 GFP_KERNEL);
5694 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005695 ret = -ENOMEM;
5696 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005697 }
5698
5699 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5700 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5701 band->channels = channels;
5702 band->n_bitrates = ath10k_a_rates_size;
5703 band->bitrates = ath10k_a_rates;
5704 band->ht_cap = ht_cap;
5705 band->vht_cap = vht_cap;
5706 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5707 }
5708
5709 ar->hw->wiphy->interface_modes =
5710 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005711 BIT(NL80211_IFTYPE_AP);
5712
Ben Greear46acf7bb2014-05-16 17:15:38 +03005713 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5714 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5715
Bartosz Markowskid3541812013-12-10 16:20:40 +01005716 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5717 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005718 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005719 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5720 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005721
5722 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5723 IEEE80211_HW_SUPPORTS_PS |
5724 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005725 IEEE80211_HW_MFP_CAPABLE |
5726 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5727 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005728 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005729 IEEE80211_HW_SPECTRUM_MGMT |
5730 IEEE80211_HW_SW_CRYPTO_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005731
Eliad Peller0d8614b2014-09-10 14:07:36 +03005732 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5733
Kalle Valo5e3dd152013-06-12 20:52:10 +03005734 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005735 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005736
5737 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5738 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5739 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5740 }
5741
5742 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5743 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5744
5745 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005746 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005747
Kalle Valo5e3dd152013-06-12 20:52:10 +03005748 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5749
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005750 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5751 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5752
5753 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5754 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5755 * correct Probe Responses. This is more of a hack advert..
5756 */
5757 ar->hw->wiphy->probe_resp_offload |=
5758 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5759 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5760 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5761 }
5762
Kalle Valo5e3dd152013-06-12 20:52:10 +03005763 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005764 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005765 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5766
5767 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005768 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5769
Kalle Valo5e3dd152013-06-12 20:52:10 +03005770 /*
5771 * on LL hardware queues are managed entirely by the FW
5772 * so we only advertise to mac we can do the queues thing
5773 */
5774 ar->hw->queues = 4;
5775
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005776 switch (ar->wmi.op_version) {
5777 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5778 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005779 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5780 ar->hw->wiphy->n_iface_combinations =
5781 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005782 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005783 break;
5784 case ATH10K_FW_WMI_OP_VERSION_10_1:
5785 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005786 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005787 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5788 ar->hw->wiphy->n_iface_combinations =
5789 ARRAY_SIZE(ath10k_10x_if_comb);
5790 break;
5791 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5792 case ATH10K_FW_WMI_OP_VERSION_MAX:
5793 WARN_ON(1);
5794 ret = -EINVAL;
5795 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005796 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005797
Michal Kazior7c199992013-07-31 10:47:57 +02005798 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5799
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005800 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5801 /* Init ath dfs pattern detector */
5802 ar->ath_common.debug_mask = ATH_DBG_DFS;
5803 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5804 NL80211_DFS_UNSET);
5805
5806 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005807 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005808 }
5809
Kalle Valo5e3dd152013-06-12 20:52:10 +03005810 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5811 ath10k_reg_notifier);
5812 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005813 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005814 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005815 }
5816
Johannes Berg3cb10942015-01-22 21:38:45 +01005817 ar->hw->wiphy->cipher_suites = cipher_suites;
5818 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5819
Kalle Valo5e3dd152013-06-12 20:52:10 +03005820 ret = ieee80211_register_hw(ar->hw);
5821 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005822 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005823 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005824 }
5825
5826 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5827 ret = regulatory_hint(ar->hw->wiphy,
5828 ar->ath_common.regulatory.alpha2);
5829 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005830 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005831 }
5832
5833 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005834
5835err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005836 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005837err_free:
5838 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5839 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5840
Kalle Valo5e3dd152013-06-12 20:52:10 +03005841 return ret;
5842}
5843
5844void ath10k_mac_unregister(struct ath10k *ar)
5845{
5846 ieee80211_unregister_hw(ar->hw);
5847
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005848 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5849 ar->dfs_detector->exit(ar->dfs_detector);
5850
Kalle Valo5e3dd152013-06-12 20:52:10 +03005851 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5852 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5853
5854 SET_IEEE80211_DEV(ar->hw, NULL);
5855}