blob: f1175a56e9d0da4ae6ab9258a39e2e05b2d46188 [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:
Bartosz Markowskid7131c02015-03-10 14:32:19 +010069 WARN_ON(1);
70 return -EINVAL;
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 ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100859 !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
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001512static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1513 struct ieee80211_vif *vif)
1514{
1515 struct sk_buff *skb = data;
1516 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1517 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1518
1519 if (vif->type != NL80211_IFTYPE_STATION)
1520 return;
1521
1522 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1523 return;
1524
1525 cancel_delayed_work(&arvif->connection_loss_work);
1526}
1527
1528void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1529{
1530 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1531 IEEE80211_IFACE_ITER_NORMAL,
1532 ath10k_mac_handle_beacon_iter,
1533 skb);
1534}
1535
1536static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1537 struct ieee80211_vif *vif)
1538{
1539 u32 *vdev_id = data;
1540 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1541 struct ath10k *ar = arvif->ar;
1542 struct ieee80211_hw *hw = ar->hw;
1543
1544 if (arvif->vdev_id != *vdev_id)
1545 return;
1546
1547 if (!arvif->is_up)
1548 return;
1549
1550 ieee80211_beacon_loss(vif);
1551
1552 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1553 * (done by mac80211) succeeds but beacons do not resume then it
1554 * doesn't make sense to continue operation. Queue connection loss work
1555 * which can be cancelled when beacon is received.
1556 */
1557 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1558 ATH10K_CONNECTION_LOSS_HZ);
1559}
1560
1561void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1562{
1563 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1564 IEEE80211_IFACE_ITER_NORMAL,
1565 ath10k_mac_handle_beacon_miss_iter,
1566 &vdev_id);
1567}
1568
1569static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1570{
1571 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1572 connection_loss_work.work);
1573 struct ieee80211_vif *vif = arvif->vif;
1574
1575 if (!arvif->is_up)
1576 return;
1577
1578 ieee80211_connection_loss(vif);
1579}
1580
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581/**********************/
1582/* Station management */
1583/**********************/
1584
Michal Kazior590922a2014-10-21 10:10:29 +03001585static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1586 struct ieee80211_vif *vif)
1587{
1588 /* Some firmware revisions have unstable STA powersave when listen
1589 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1590 * generate NullFunc frames properly even if buffered frames have been
1591 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1592 * buffered frames. Often pinging the device from AP would simply fail.
1593 *
1594 * As a workaround set it to 1.
1595 */
1596 if (vif->type == NL80211_IFTYPE_STATION)
1597 return 1;
1598
1599 return ar->hw->conf.listen_interval;
1600}
1601
Kalle Valo5e3dd152013-06-12 20:52:10 +03001602static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001603 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605 struct wmi_peer_assoc_complete_arg *arg)
1606{
Michal Kazior590922a2014-10-21 10:10:29 +03001607 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1608
Michal Kazior548db542013-07-05 16:15:15 +03001609 lockdep_assert_held(&ar->conf_mutex);
1610
Kalle Valob25f32c2014-09-14 12:50:49 +03001611 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612 arg->vdev_id = arvif->vdev_id;
1613 arg->peer_aid = sta->aid;
1614 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001615 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001617 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618}
1619
1620static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001621 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 struct wmi_peer_assoc_complete_arg *arg)
1623{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 struct ieee80211_bss_conf *info = &vif->bss_conf;
1625 struct cfg80211_bss *bss;
1626 const u8 *rsnie = NULL;
1627 const u8 *wpaie = NULL;
1628
Michal Kazior548db542013-07-05 16:15:15 +03001629 lockdep_assert_held(&ar->conf_mutex);
1630
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1632 info->bssid, NULL, 0, 0, 0);
1633 if (bss) {
1634 const struct cfg80211_bss_ies *ies;
1635
1636 rcu_read_lock();
1637 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1638
1639 ies = rcu_dereference(bss->ies);
1640
1641 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001642 WLAN_OUI_TYPE_MICROSOFT_WPA,
1643 ies->data,
1644 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001645 rcu_read_unlock();
1646 cfg80211_put_bss(ar->hw->wiphy, bss);
1647 }
1648
1649 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1650 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001651 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001652 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1653 }
1654
1655 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001656 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001657 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1658 }
1659}
1660
1661static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1662 struct ieee80211_sta *sta,
1663 struct wmi_peer_assoc_complete_arg *arg)
1664{
1665 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1666 const struct ieee80211_supported_band *sband;
1667 const struct ieee80211_rate *rates;
1668 u32 ratemask;
1669 int i;
1670
Michal Kazior548db542013-07-05 16:15:15 +03001671 lockdep_assert_held(&ar->conf_mutex);
1672
Kalle Valo5e3dd152013-06-12 20:52:10 +03001673 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1674 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1675 rates = sband->bitrates;
1676
1677 rateset->num_rates = 0;
1678
1679 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1680 if (!(ratemask & 1))
1681 continue;
1682
1683 rateset->rates[rateset->num_rates] = rates->hw_value;
1684 rateset->num_rates++;
1685 }
1686}
1687
1688static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1689 struct ieee80211_sta *sta,
1690 struct wmi_peer_assoc_complete_arg *arg)
1691{
1692 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001693 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001694 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
Michal Kazior548db542013-07-05 16:15:15 +03001696 lockdep_assert_held(&ar->conf_mutex);
1697
Kalle Valo5e3dd152013-06-12 20:52:10 +03001698 if (!ht_cap->ht_supported)
1699 return;
1700
1701 arg->peer_flags |= WMI_PEER_HT;
1702 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1703 ht_cap->ampdu_factor)) - 1;
1704
1705 arg->peer_mpdu_density =
1706 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1707
1708 arg->peer_ht_caps = ht_cap->cap;
1709 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1710
1711 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1712 arg->peer_flags |= WMI_PEER_LDPC;
1713
1714 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1715 arg->peer_flags |= WMI_PEER_40MHZ;
1716 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1717 }
1718
1719 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1720 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1721
1722 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1723 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1724
1725 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1726 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1727 arg->peer_flags |= WMI_PEER_STBC;
1728 }
1729
1730 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1732 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1733 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1734 arg->peer_rate_caps |= stbc;
1735 arg->peer_flags |= WMI_PEER_STBC;
1736 }
1737
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1739 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1740 else if (ht_cap->mcs.rx_mask[1])
1741 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1742
1743 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1744 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1745 arg->peer_ht_rates.rates[n++] = i;
1746
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001747 /*
1748 * This is a workaround for HT-enabled STAs which break the spec
1749 * and have no HT capabilities RX mask (no HT RX MCS map).
1750 *
1751 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1752 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1753 *
1754 * Firmware asserts if such situation occurs.
1755 */
1756 if (n == 0) {
1757 arg->peer_ht_rates.num_rates = 8;
1758 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1759 arg->peer_ht_rates.rates[i] = i;
1760 } else {
1761 arg->peer_ht_rates.num_rates = n;
1762 arg->peer_num_spatial_streams = sta->rx_nss;
1763 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001764
Michal Kazior7aa7a722014-08-25 12:09:38 +02001765 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001766 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767 arg->peer_ht_rates.num_rates,
1768 arg->peer_num_spatial_streams);
1769}
1770
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001771static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1772 struct ath10k_vif *arvif,
1773 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001774{
1775 u32 uapsd = 0;
1776 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001777 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778
Michal Kazior548db542013-07-05 16:15:15 +03001779 lockdep_assert_held(&ar->conf_mutex);
1780
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001782 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783 sta->uapsd_queues, sta->max_sp);
1784
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1786 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1787 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1788 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1789 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1790 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1791 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1792 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1793 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1794 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1795 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1796 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1797
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1799 max_sp = sta->max_sp;
1800
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001801 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1802 sta->addr,
1803 WMI_AP_PS_PEER_PARAM_UAPSD,
1804 uapsd);
1805 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001806 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001807 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001808 return ret;
1809 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001811 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1812 sta->addr,
1813 WMI_AP_PS_PEER_PARAM_MAX_SP,
1814 max_sp);
1815 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001816 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001817 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001818 return ret;
1819 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001820
1821 /* TODO setup this based on STA listen interval and
1822 beacon interval. Currently we don't know
1823 sta->listen_interval - mac80211 patch required.
1824 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001825 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001826 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1827 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001828 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001829 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001830 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001831 return ret;
1832 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001833 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001834
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001835 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836}
1837
1838static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1839 struct ieee80211_sta *sta,
1840 struct wmi_peer_assoc_complete_arg *arg)
1841{
1842 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001843 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001844
1845 if (!vht_cap->vht_supported)
1846 return;
1847
1848 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001849
1850 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1851 arg->peer_flags |= WMI_PEER_VHT_2G;
1852
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853 arg->peer_vht_caps = vht_cap->cap;
1854
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001855 ampdu_factor = (vht_cap->cap &
1856 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1857 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1858
1859 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1860 * zero in VHT IE. Using it would result in degraded throughput.
1861 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1862 * it if VHT max_mpdu is smaller. */
1863 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1864 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1865 ampdu_factor)) - 1);
1866
Kalle Valo5e3dd152013-06-12 20:52:10 +03001867 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1868 arg->peer_flags |= WMI_PEER_80MHZ;
1869
1870 arg->peer_vht_rates.rx_max_rate =
1871 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1872 arg->peer_vht_rates.rx_mcs_set =
1873 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1874 arg->peer_vht_rates.tx_max_rate =
1875 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1876 arg->peer_vht_rates.tx_mcs_set =
1877 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1878
Michal Kazior7aa7a722014-08-25 12:09:38 +02001879 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001880 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881}
1882
1883static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001884 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001886 struct wmi_peer_assoc_complete_arg *arg)
1887{
Michal Kazior590922a2014-10-21 10:10:29 +03001888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1889
Kalle Valo5e3dd152013-06-12 20:52:10 +03001890 switch (arvif->vdev_type) {
1891 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001892 if (sta->wme)
1893 arg->peer_flags |= WMI_PEER_QOS;
1894
1895 if (sta->wme && sta->uapsd_queues) {
1896 arg->peer_flags |= WMI_PEER_APSD;
1897 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1898 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001899 break;
1900 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001901 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001902 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001904 case WMI_VDEV_TYPE_IBSS:
1905 if (sta->wme)
1906 arg->peer_flags |= WMI_PEER_QOS;
1907 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001908 default:
1909 break;
1910 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001911
1912 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1913 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001914}
1915
Michal Kazior91b12082014-12-12 12:41:35 +01001916static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1917{
1918 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1919 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1920}
1921
Kalle Valo5e3dd152013-06-12 20:52:10 +03001922static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001923 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 struct ieee80211_sta *sta,
1925 struct wmi_peer_assoc_complete_arg *arg)
1926{
1927 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1928
Kalle Valo5e3dd152013-06-12 20:52:10 +03001929 switch (ar->hw->conf.chandef.chan->band) {
1930 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001931 if (sta->vht_cap.vht_supported) {
1932 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1933 phymode = MODE_11AC_VHT40;
1934 else
1935 phymode = MODE_11AC_VHT20;
1936 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1938 phymode = MODE_11NG_HT40;
1939 else
1940 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001941 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001943 } else {
1944 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945 }
1946
1947 break;
1948 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001949 /*
1950 * Check VHT first.
1951 */
1952 if (sta->vht_cap.vht_supported) {
1953 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1954 phymode = MODE_11AC_VHT80;
1955 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1956 phymode = MODE_11AC_VHT40;
1957 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1958 phymode = MODE_11AC_VHT20;
1959 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1961 phymode = MODE_11NA_HT40;
1962 else
1963 phymode = MODE_11NA_HT20;
1964 } else {
1965 phymode = MODE_11A;
1966 }
1967
1968 break;
1969 default:
1970 break;
1971 }
1972
Michal Kazior7aa7a722014-08-25 12:09:38 +02001973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001974 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001975
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 arg->peer_phymode = phymode;
1977 WARN_ON(phymode == MODE_UNKNOWN);
1978}
1979
Kalle Valob9ada652013-10-16 15:44:46 +03001980static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001981 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001982 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001983 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984{
Michal Kazior548db542013-07-05 16:15:15 +03001985 lockdep_assert_held(&ar->conf_mutex);
1986
Kalle Valob9ada652013-10-16 15:44:46 +03001987 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988
Michal Kazior590922a2014-10-21 10:10:29 +03001989 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1990 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001991 ath10k_peer_assoc_h_rates(ar, sta, arg);
1992 ath10k_peer_assoc_h_ht(ar, sta, arg);
1993 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001994 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1995 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001996
Kalle Valob9ada652013-10-16 15:44:46 +03001997 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998}
1999
Michal Kazior90046f52014-02-14 14:45:51 +01002000static const u32 ath10k_smps_map[] = {
2001 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2002 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2003 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2004 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2005};
2006
2007static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2008 const u8 *addr,
2009 const struct ieee80211_sta_ht_cap *ht_cap)
2010{
2011 int smps;
2012
2013 if (!ht_cap->ht_supported)
2014 return 0;
2015
2016 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2017 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2018
2019 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2020 return -EINVAL;
2021
2022 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2023 WMI_PEER_SMPS_STATE,
2024 ath10k_smps_map[smps]);
2025}
2026
Michal Kazior139e1702015-02-15 16:50:42 +02002027static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2028 struct ieee80211_vif *vif,
2029 struct ieee80211_sta_vht_cap vht_cap)
2030{
2031 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2032 int ret;
2033 u32 param;
2034 u32 value;
2035
2036 if (!(ar->vht_cap_info &
2037 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2038 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2039 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2040 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2041 return 0;
2042
2043 param = ar->wmi.vdev_param->txbf;
2044 value = 0;
2045
2046 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2047 return 0;
2048
2049 /* The following logic is correct. If a remote STA advertises support
2050 * for being a beamformer then we should enable us being a beamformee.
2051 */
2052
2053 if (ar->vht_cap_info &
2054 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2055 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2056 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2057 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2058
2059 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2060 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2061 }
2062
2063 if (ar->vht_cap_info &
2064 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2065 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2066 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2067 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2068
2069 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2070 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2071 }
2072
2073 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2074 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2075
2076 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2077 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2078
2079 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2080 if (ret) {
2081 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2082 value, ret);
2083 return ret;
2084 }
2085
2086 return 0;
2087}
2088
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089/* can be called only in mac80211 callbacks due to `key_count` usage */
2090static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2091 struct ieee80211_vif *vif,
2092 struct ieee80211_bss_conf *bss_conf)
2093{
2094 struct ath10k *ar = hw->priv;
2095 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002096 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002097 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002098 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002099 struct ieee80211_sta *ap_sta;
2100 int ret;
2101
Michal Kazior548db542013-07-05 16:15:15 +03002102 lockdep_assert_held(&ar->conf_mutex);
2103
Michal Kazior077efc82014-10-21 10:10:29 +03002104 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2105 arvif->vdev_id, arvif->bssid, arvif->aid);
2106
Kalle Valo5e3dd152013-06-12 20:52:10 +03002107 rcu_read_lock();
2108
2109 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2110 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002111 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002112 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002113 rcu_read_unlock();
2114 return;
2115 }
2116
Michal Kazior90046f52014-02-14 14:45:51 +01002117 /* ap_sta must be accessed only within rcu section which must be left
2118 * before calling ath10k_setup_peer_smps() which might sleep. */
2119 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002120 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002121
Michal Kazior590922a2014-10-21 10:10:29 +03002122 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002124 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002125 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126 rcu_read_unlock();
2127 return;
2128 }
2129
2130 rcu_read_unlock();
2131
Kalle Valob9ada652013-10-16 15:44:46 +03002132 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2133 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002134 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002135 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002136 return;
2137 }
2138
Michal Kazior90046f52014-02-14 14:45:51 +01002139 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2140 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002141 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002142 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002143 return;
2144 }
2145
Michal Kazior139e1702015-02-15 16:50:42 +02002146 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2147 if (ret) {
2148 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2149 arvif->vdev_id, bss_conf->bssid, ret);
2150 return;
2151 }
2152
Michal Kazior7aa7a722014-08-25 12:09:38 +02002153 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002154 "mac vdev %d up (associated) bssid %pM aid %d\n",
2155 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2156
Michal Kazior077efc82014-10-21 10:10:29 +03002157 WARN_ON(arvif->is_up);
2158
Michal Kaziorc930f742014-01-23 11:38:25 +01002159 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002160 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002161
2162 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2163 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002164 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002165 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002166 return;
2167 }
2168
2169 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002170
2171 /* Workaround: Some firmware revisions (tested with qca6174
2172 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2173 * poked with peer param command.
2174 */
2175 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2176 WMI_PEER_DUMMY_VAR, 1);
2177 if (ret) {
2178 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2179 arvif->bssid, arvif->vdev_id, ret);
2180 return;
2181 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182}
2183
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2185 struct ieee80211_vif *vif)
2186{
2187 struct ath10k *ar = hw->priv;
2188 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002189 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190 int ret;
2191
Michal Kazior548db542013-07-05 16:15:15 +03002192 lockdep_assert_held(&ar->conf_mutex);
2193
Michal Kazior077efc82014-10-21 10:10:29 +03002194 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2195 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002196
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002198 if (ret)
2199 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2200 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002201
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002202 arvif->def_wep_key_idx = -1;
2203
Michal Kazior139e1702015-02-15 16:50:42 +02002204 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2205 if (ret) {
2206 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2207 arvif->vdev_id, ret);
2208 return;
2209 }
2210
Michal Kaziorc930f742014-01-23 11:38:25 +01002211 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002212
2213 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214}
2215
Michal Kazior590922a2014-10-21 10:10:29 +03002216static int ath10k_station_assoc(struct ath10k *ar,
2217 struct ieee80211_vif *vif,
2218 struct ieee80211_sta *sta,
2219 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002220{
Michal Kazior590922a2014-10-21 10:10:29 +03002221 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002222 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223 int ret = 0;
2224
Michal Kazior548db542013-07-05 16:15:15 +03002225 lockdep_assert_held(&ar->conf_mutex);
2226
Michal Kazior590922a2014-10-21 10:10:29 +03002227 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002228 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002229 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002230 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002231 return ret;
2232 }
2233
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002234 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002235 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2236 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002237 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002238 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002239 return ret;
2240 }
2241
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002242 /* Re-assoc is run only to update supported rates for given station. It
2243 * doesn't make much sense to reconfigure the peer completely.
2244 */
2245 if (!reassoc) {
2246 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2247 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002248 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002249 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002250 arvif->vdev_id, ret);
2251 return ret;
2252 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002253
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002254 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2255 if (ret) {
2256 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2257 sta->addr, arvif->vdev_id, ret);
2258 return ret;
2259 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002260
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002261 if (!sta->wme) {
2262 arvif->num_legacy_stations++;
2263 ret = ath10k_recalc_rtscts_prot(arvif);
2264 if (ret) {
2265 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2266 arvif->vdev_id, ret);
2267 return ret;
2268 }
2269 }
2270
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002271 /* Plumb cached keys only for static WEP */
2272 if (arvif->def_wep_key_idx != -1) {
2273 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2274 if (ret) {
2275 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2276 arvif->vdev_id, ret);
2277 return ret;
2278 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279 }
2280 }
2281
Kalle Valo5e3dd152013-06-12 20:52:10 +03002282 return ret;
2283}
2284
Michal Kazior590922a2014-10-21 10:10:29 +03002285static int ath10k_station_disassoc(struct ath10k *ar,
2286 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287 struct ieee80211_sta *sta)
2288{
Michal Kazior590922a2014-10-21 10:10:29 +03002289 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002290 int ret = 0;
2291
2292 lockdep_assert_held(&ar->conf_mutex);
2293
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002294 if (!sta->wme) {
2295 arvif->num_legacy_stations--;
2296 ret = ath10k_recalc_rtscts_prot(arvif);
2297 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002298 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002299 arvif->vdev_id, ret);
2300 return ret;
2301 }
2302 }
2303
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2305 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002306 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002307 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 return ret;
2309 }
2310
2311 return ret;
2312}
2313
2314/**************/
2315/* Regulatory */
2316/**************/
2317
2318static int ath10k_update_channel_list(struct ath10k *ar)
2319{
2320 struct ieee80211_hw *hw = ar->hw;
2321 struct ieee80211_supported_band **bands;
2322 enum ieee80211_band band;
2323 struct ieee80211_channel *channel;
2324 struct wmi_scan_chan_list_arg arg = {0};
2325 struct wmi_channel_arg *ch;
2326 bool passive;
2327 int len;
2328 int ret;
2329 int i;
2330
Michal Kazior548db542013-07-05 16:15:15 +03002331 lockdep_assert_held(&ar->conf_mutex);
2332
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333 bands = hw->wiphy->bands;
2334 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2335 if (!bands[band])
2336 continue;
2337
2338 for (i = 0; i < bands[band]->n_channels; i++) {
2339 if (bands[band]->channels[i].flags &
2340 IEEE80211_CHAN_DISABLED)
2341 continue;
2342
2343 arg.n_channels++;
2344 }
2345 }
2346
2347 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2348 arg.channels = kzalloc(len, GFP_KERNEL);
2349 if (!arg.channels)
2350 return -ENOMEM;
2351
2352 ch = arg.channels;
2353 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2354 if (!bands[band])
2355 continue;
2356
2357 for (i = 0; i < bands[band]->n_channels; i++) {
2358 channel = &bands[band]->channels[i];
2359
2360 if (channel->flags & IEEE80211_CHAN_DISABLED)
2361 continue;
2362
2363 ch->allow_ht = true;
2364
2365 /* FIXME: when should we really allow VHT? */
2366 ch->allow_vht = true;
2367
2368 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002369 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370
2371 ch->ht40plus =
2372 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2373
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002374 ch->chan_radar =
2375 !!(channel->flags & IEEE80211_CHAN_RADAR);
2376
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002377 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378 ch->passive = passive;
2379
2380 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002381 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002382 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002383 ch->max_power = channel->max_power * 2;
2384 ch->max_reg_power = channel->max_reg_power * 2;
2385 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386 ch->reg_class_id = 0; /* FIXME */
2387
2388 /* FIXME: why use only legacy modes, why not any
2389 * HT/VHT modes? Would that even make any
2390 * difference? */
2391 if (channel->band == IEEE80211_BAND_2GHZ)
2392 ch->mode = MODE_11G;
2393 else
2394 ch->mode = MODE_11A;
2395
2396 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2397 continue;
2398
Michal Kazior7aa7a722014-08-25 12:09:38 +02002399 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002400 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2401 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002402 ch->freq, ch->max_power, ch->max_reg_power,
2403 ch->max_antenna_gain, ch->mode);
2404
2405 ch++;
2406 }
2407 }
2408
2409 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2410 kfree(arg.channels);
2411
2412 return ret;
2413}
2414
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002415static enum wmi_dfs_region
2416ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2417{
2418 switch (dfs_region) {
2419 case NL80211_DFS_UNSET:
2420 return WMI_UNINIT_DFS_DOMAIN;
2421 case NL80211_DFS_FCC:
2422 return WMI_FCC_DFS_DOMAIN;
2423 case NL80211_DFS_ETSI:
2424 return WMI_ETSI_DFS_DOMAIN;
2425 case NL80211_DFS_JP:
2426 return WMI_MKK4_DFS_DOMAIN;
2427 }
2428 return WMI_UNINIT_DFS_DOMAIN;
2429}
2430
Michal Kaziorf7843d72013-07-16 09:38:52 +02002431static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002432{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002433 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002434 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002435 enum wmi_dfs_region wmi_dfs_reg;
2436 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002437
Michal Kaziorf7843d72013-07-16 09:38:52 +02002438 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002439
2440 ret = ath10k_update_channel_list(ar);
2441 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002442 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002443
2444 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002445
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002446 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2447 nl_dfs_reg = ar->dfs_detector->region;
2448 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2449 } else {
2450 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2451 }
2452
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453 /* Target allows setting up per-band regdomain but ath_common provides
2454 * a combined one only */
2455 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002456 regpair->reg_domain,
2457 regpair->reg_domain, /* 2ghz */
2458 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002460 regpair->reg_5ghz_ctl,
2461 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002462 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002463 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002464}
Michal Kazior548db542013-07-05 16:15:15 +03002465
Michal Kaziorf7843d72013-07-16 09:38:52 +02002466static void ath10k_reg_notifier(struct wiphy *wiphy,
2467 struct regulatory_request *request)
2468{
2469 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2470 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002471 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002472
2473 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2474
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002475 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002476 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002477 request->dfs_region);
2478 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2479 request->dfs_region);
2480 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002481 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002482 request->dfs_region);
2483 }
2484
Michal Kaziorf7843d72013-07-16 09:38:52 +02002485 mutex_lock(&ar->conf_mutex);
2486 if (ar->state == ATH10K_STATE_ON)
2487 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002488 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002489}
2490
2491/***************/
2492/* TX handlers */
2493/***************/
2494
Michal Kazior42c3aa62013-10-02 11:03:38 +02002495static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2496{
2497 if (ieee80211_is_mgmt(hdr->frame_control))
2498 return HTT_DATA_TX_EXT_TID_MGMT;
2499
2500 if (!ieee80211_is_data_qos(hdr->frame_control))
2501 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2502
2503 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2504 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2505
2506 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2507}
2508
Michal Kazior2b37c292014-09-02 11:00:22 +03002509static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002510{
Michal Kazior2b37c292014-09-02 11:00:22 +03002511 if (vif)
2512 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002513
Michal Kazior1bbc0972014-04-08 09:45:47 +03002514 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002515 return ar->monitor_vdev_id;
2516
Michal Kazior7aa7a722014-08-25 12:09:38 +02002517 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002518 return 0;
2519}
2520
Michal Kazior4b604552014-07-21 21:03:09 +03002521/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2522 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523 */
Michal Kazior4b604552014-07-21 21:03:09 +03002524static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525{
2526 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002527 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528 u8 *qos_ctl;
2529
2530 if (!ieee80211_is_data_qos(hdr->frame_control))
2531 return;
2532
2533 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002534 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2535 skb->data, (void *)qos_ctl - (void *)skb->data);
2536 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002537
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002538 /* Some firmware revisions don't handle sending QoS NullFunc well.
2539 * These frames are mainly used for CQM purposes so it doesn't really
2540 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002541 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002542 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002543 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002544 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002545
2546 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002547}
2548
Michal Kazior4b604552014-07-21 21:03:09 +03002549static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2550 struct ieee80211_vif *vif,
2551 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552{
2553 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2555
2556 /* This is case only for P2P_GO */
2557 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2558 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2559 return;
2560
2561 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2562 spin_lock_bh(&ar->data_lock);
2563 if (arvif->u.ap.noa_data)
2564 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2565 GFP_ATOMIC))
2566 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2567 arvif->u.ap.noa_data,
2568 arvif->u.ap.noa_len);
2569 spin_unlock_bh(&ar->data_lock);
2570 }
2571}
2572
Michal Kazior8d6d3622014-11-24 14:58:31 +01002573static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2574{
2575 /* FIXME: Not really sure since when the behaviour changed. At some
2576 * point new firmware stopped requiring creation of peer entries for
2577 * offchannel tx (and actually creating them causes issues with wmi-htc
2578 * tx credit replenishment and reliability). Assuming it's at least 3.4
2579 * because that's when the `freq` was introduced to TX_FRM HTT command.
2580 */
2581 return !(ar->htt.target_version_major >= 3 &&
2582 ar->htt.target_version_minor >= 4);
2583}
2584
Kalle Valo5e3dd152013-06-12 20:52:10 +03002585static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2586{
2587 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002588 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002589
Michal Kazior961d4c32013-08-09 10:13:34 +02002590 if (ar->htt.target_version_major >= 3) {
2591 /* Since HTT 3.0 there is no separate mgmt tx command */
2592 ret = ath10k_htt_tx(&ar->htt, skb);
2593 goto exit;
2594 }
2595
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002596 if (ieee80211_is_mgmt(hdr->frame_control)) {
2597 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2598 ar->fw_features)) {
2599 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2600 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002601 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002602 ret = -EBUSY;
2603 goto exit;
2604 }
2605
2606 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2607 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2608 } else {
2609 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2610 }
2611 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2612 ar->fw_features) &&
2613 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002614 /* FW does not report tx status properly for NullFunc frames
2615 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002616 * those frames when it detects link/beacon loss and depends
2617 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002618 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002619 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002620 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622
Michal Kazior961d4c32013-08-09 10:13:34 +02002623exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002625 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2626 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002627 ieee80211_free_txskb(ar->hw, skb);
2628 }
2629}
2630
2631void ath10k_offchan_tx_purge(struct ath10k *ar)
2632{
2633 struct sk_buff *skb;
2634
2635 for (;;) {
2636 skb = skb_dequeue(&ar->offchan_tx_queue);
2637 if (!skb)
2638 break;
2639
2640 ieee80211_free_txskb(ar->hw, skb);
2641 }
2642}
2643
2644void ath10k_offchan_tx_work(struct work_struct *work)
2645{
2646 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2647 struct ath10k_peer *peer;
2648 struct ieee80211_hdr *hdr;
2649 struct sk_buff *skb;
2650 const u8 *peer_addr;
2651 int vdev_id;
2652 int ret;
2653
2654 /* FW requirement: We must create a peer before FW will send out
2655 * an offchannel frame. Otherwise the frame will be stuck and
2656 * never transmitted. We delete the peer upon tx completion.
2657 * It is unlikely that a peer for offchannel tx will already be
2658 * present. However it may be in some rare cases so account for that.
2659 * Otherwise we might remove a legitimate peer and break stuff. */
2660
2661 for (;;) {
2662 skb = skb_dequeue(&ar->offchan_tx_queue);
2663 if (!skb)
2664 break;
2665
2666 mutex_lock(&ar->conf_mutex);
2667
Michal Kazior7aa7a722014-08-25 12:09:38 +02002668 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669 skb);
2670
2671 hdr = (struct ieee80211_hdr *)skb->data;
2672 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002673 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674
2675 spin_lock_bh(&ar->data_lock);
2676 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2677 spin_unlock_bh(&ar->data_lock);
2678
2679 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002680 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002681 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 peer_addr, vdev_id);
2683
2684 if (!peer) {
2685 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2686 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002687 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002688 peer_addr, vdev_id, ret);
2689 }
2690
2691 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002692 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693 ar->offchan_tx_skb = skb;
2694 spin_unlock_bh(&ar->data_lock);
2695
2696 ath10k_tx_htt(ar, skb);
2697
2698 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2699 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002700 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002701 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002702 skb);
2703
2704 if (!peer) {
2705 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2706 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002707 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708 peer_addr, vdev_id, ret);
2709 }
2710
2711 mutex_unlock(&ar->conf_mutex);
2712 }
2713}
2714
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002715void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2716{
2717 struct sk_buff *skb;
2718
2719 for (;;) {
2720 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2721 if (!skb)
2722 break;
2723
2724 ieee80211_free_txskb(ar->hw, skb);
2725 }
2726}
2727
2728void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2729{
2730 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2731 struct sk_buff *skb;
2732 int ret;
2733
2734 for (;;) {
2735 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2736 if (!skb)
2737 break;
2738
2739 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002740 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002741 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002742 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002743 ieee80211_free_txskb(ar->hw, skb);
2744 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002745 }
2746}
2747
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748/************/
2749/* Scanning */
2750/************/
2751
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002752void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002753{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002754 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002755
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002756 switch (ar->scan.state) {
2757 case ATH10K_SCAN_IDLE:
2758 break;
2759 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002760 if (ar->scan.is_roc)
2761 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002762 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002763 case ATH10K_SCAN_ABORTING:
2764 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002765 ieee80211_scan_completed(ar->hw,
2766 (ar->scan.state ==
2767 ATH10K_SCAN_ABORTING));
2768 /* fall through */
2769 case ATH10K_SCAN_STARTING:
2770 ar->scan.state = ATH10K_SCAN_IDLE;
2771 ar->scan_channel = NULL;
2772 ath10k_offchan_tx_purge(ar);
2773 cancel_delayed_work(&ar->scan.timeout);
2774 complete_all(&ar->scan.completed);
2775 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002777}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002779void ath10k_scan_finish(struct ath10k *ar)
2780{
2781 spin_lock_bh(&ar->data_lock);
2782 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 spin_unlock_bh(&ar->data_lock);
2784}
2785
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002786static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002787{
2788 struct wmi_stop_scan_arg arg = {
2789 .req_id = 1, /* FIXME */
2790 .req_type = WMI_SCAN_STOP_ONE,
2791 .u.scan_id = ATH10K_SCAN_ID,
2792 };
2793 int ret;
2794
2795 lockdep_assert_held(&ar->conf_mutex);
2796
Kalle Valo5e3dd152013-06-12 20:52:10 +03002797 ret = ath10k_wmi_stop_scan(ar, &arg);
2798 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002799 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002800 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801 }
2802
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002804 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002805 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002806 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002807 } else if (ret > 0) {
2808 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002809 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002810
2811out:
2812 /* Scan state should be updated upon scan completion but in case
2813 * firmware fails to deliver the event (for whatever reason) it is
2814 * desired to clean up scan state anyway. Firmware may have just
2815 * dropped the scan completion event delivery due to transport pipe
2816 * being overflown with data and/or it can recover on its own before
2817 * next scan request is submitted.
2818 */
2819 spin_lock_bh(&ar->data_lock);
2820 if (ar->scan.state != ATH10K_SCAN_IDLE)
2821 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002822 spin_unlock_bh(&ar->data_lock);
2823
2824 return ret;
2825}
2826
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002827static void ath10k_scan_abort(struct ath10k *ar)
2828{
2829 int ret;
2830
2831 lockdep_assert_held(&ar->conf_mutex);
2832
2833 spin_lock_bh(&ar->data_lock);
2834
2835 switch (ar->scan.state) {
2836 case ATH10K_SCAN_IDLE:
2837 /* This can happen if timeout worker kicked in and called
2838 * abortion while scan completion was being processed.
2839 */
2840 break;
2841 case ATH10K_SCAN_STARTING:
2842 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002843 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002844 ath10k_scan_state_str(ar->scan.state),
2845 ar->scan.state);
2846 break;
2847 case ATH10K_SCAN_RUNNING:
2848 ar->scan.state = ATH10K_SCAN_ABORTING;
2849 spin_unlock_bh(&ar->data_lock);
2850
2851 ret = ath10k_scan_stop(ar);
2852 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002853 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002854
2855 spin_lock_bh(&ar->data_lock);
2856 break;
2857 }
2858
2859 spin_unlock_bh(&ar->data_lock);
2860}
2861
2862void ath10k_scan_timeout_work(struct work_struct *work)
2863{
2864 struct ath10k *ar = container_of(work, struct ath10k,
2865 scan.timeout.work);
2866
2867 mutex_lock(&ar->conf_mutex);
2868 ath10k_scan_abort(ar);
2869 mutex_unlock(&ar->conf_mutex);
2870}
2871
Kalle Valo5e3dd152013-06-12 20:52:10 +03002872static int ath10k_start_scan(struct ath10k *ar,
2873 const struct wmi_start_scan_arg *arg)
2874{
2875 int ret;
2876
2877 lockdep_assert_held(&ar->conf_mutex);
2878
2879 ret = ath10k_wmi_start_scan(ar, arg);
2880 if (ret)
2881 return ret;
2882
Kalle Valo5e3dd152013-06-12 20:52:10 +03002883 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2884 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002885 ret = ath10k_scan_stop(ar);
2886 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002887 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002888
2889 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002890 }
2891
Ben Greear2f9eec02015-02-15 16:50:38 +02002892 /* If we failed to start the scan, return error code at
2893 * this point. This is probably due to some issue in the
2894 * firmware, but no need to wedge the driver due to that...
2895 */
2896 spin_lock_bh(&ar->data_lock);
2897 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2898 spin_unlock_bh(&ar->data_lock);
2899 return -EINVAL;
2900 }
2901 spin_unlock_bh(&ar->data_lock);
2902
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002903 /* Add a 200ms margin to account for event/command processing */
2904 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2905 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906 return 0;
2907}
2908
2909/**********************/
2910/* mac80211 callbacks */
2911/**********************/
2912
2913static void ath10k_tx(struct ieee80211_hw *hw,
2914 struct ieee80211_tx_control *control,
2915 struct sk_buff *skb)
2916{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002917 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002918 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2919 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002920 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921
2922 /* We should disable CCK RATE due to P2P */
2923 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002924 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925
Michal Kazior4b604552014-07-21 21:03:09 +03002926 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2927 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002928 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002929
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002930 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002931 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2932 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002933 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2934 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002935 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002936
Kalle Valo5e3dd152013-06-12 20:52:10 +03002937 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2938 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002939 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002940 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002941 spin_unlock_bh(&ar->data_lock);
2942
Michal Kazior8d6d3622014-11-24 14:58:31 +01002943 if (ath10k_mac_need_offchan_tx_work(ar)) {
2944 ATH10K_SKB_CB(skb)->htt.freq = 0;
2945 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002946
Michal Kazior8d6d3622014-11-24 14:58:31 +01002947 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2948 skb);
2949
2950 skb_queue_tail(&ar->offchan_tx_queue, skb);
2951 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2952 return;
2953 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002954 }
2955
2956 ath10k_tx_htt(ar, skb);
2957}
2958
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002959/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002960void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002961{
2962 /* make sure rcu-protected mac80211 tx path itself is drained */
2963 synchronize_net();
2964
2965 ath10k_offchan_tx_purge(ar);
2966 ath10k_mgmt_over_wmi_tx_purge(ar);
2967
2968 cancel_work_sync(&ar->offchan_tx_work);
2969 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2970}
2971
Michal Kazioraffd3212013-07-16 09:54:35 +02002972void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002973{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002974 struct ath10k_vif *arvif;
2975
Michal Kazior818bdd12013-07-16 09:38:57 +02002976 lockdep_assert_held(&ar->conf_mutex);
2977
Michal Kazior19337472014-08-28 12:58:16 +02002978 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2979 ar->filter_flags = 0;
2980 ar->monitor = false;
2981
2982 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002983 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002984
2985 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002986
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002987 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002988 ath10k_peer_cleanup_all(ar);
2989 ath10k_core_stop(ar);
2990 ath10k_hif_power_down(ar);
2991
2992 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002993 list_for_each_entry(arvif, &ar->arvifs, list)
2994 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002995 spin_unlock_bh(&ar->data_lock);
2996}
2997
Ben Greear46acf7bb2014-05-16 17:15:38 +03002998static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2999{
3000 struct ath10k *ar = hw->priv;
3001
3002 mutex_lock(&ar->conf_mutex);
3003
3004 if (ar->cfg_tx_chainmask) {
3005 *tx_ant = ar->cfg_tx_chainmask;
3006 *rx_ant = ar->cfg_rx_chainmask;
3007 } else {
3008 *tx_ant = ar->supp_tx_chainmask;
3009 *rx_ant = ar->supp_rx_chainmask;
3010 }
3011
3012 mutex_unlock(&ar->conf_mutex);
3013
3014 return 0;
3015}
3016
Ben Greear5572a952014-11-24 16:22:10 +02003017static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3018{
3019 /* It is not clear that allowing gaps in chainmask
3020 * is helpful. Probably it will not do what user
3021 * is hoping for, so warn in that case.
3022 */
3023 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3024 return;
3025
3026 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3027 dbg, cm);
3028}
3029
Ben Greear46acf7bb2014-05-16 17:15:38 +03003030static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3031{
3032 int ret;
3033
3034 lockdep_assert_held(&ar->conf_mutex);
3035
Ben Greear5572a952014-11-24 16:22:10 +02003036 ath10k_check_chain_mask(ar, tx_ant, "tx");
3037 ath10k_check_chain_mask(ar, rx_ant, "rx");
3038
Ben Greear46acf7bb2014-05-16 17:15:38 +03003039 ar->cfg_tx_chainmask = tx_ant;
3040 ar->cfg_rx_chainmask = rx_ant;
3041
3042 if ((ar->state != ATH10K_STATE_ON) &&
3043 (ar->state != ATH10K_STATE_RESTARTED))
3044 return 0;
3045
3046 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3047 tx_ant);
3048 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003049 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03003050 ret, tx_ant);
3051 return ret;
3052 }
3053
3054 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3055 rx_ant);
3056 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003057 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03003058 ret, rx_ant);
3059 return ret;
3060 }
3061
3062 return 0;
3063}
3064
3065static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3066{
3067 struct ath10k *ar = hw->priv;
3068 int ret;
3069
3070 mutex_lock(&ar->conf_mutex);
3071 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3072 mutex_unlock(&ar->conf_mutex);
3073 return ret;
3074}
3075
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076static int ath10k_start(struct ieee80211_hw *hw)
3077{
3078 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003079 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003080
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003081 /*
3082 * This makes sense only when restarting hw. It is harmless to call
3083 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3084 * commands will be submitted while restarting.
3085 */
3086 ath10k_drain_tx(ar);
3087
Michal Kazior548db542013-07-05 16:15:15 +03003088 mutex_lock(&ar->conf_mutex);
3089
Michal Kaziorc5058f52014-05-26 12:46:03 +03003090 switch (ar->state) {
3091 case ATH10K_STATE_OFF:
3092 ar->state = ATH10K_STATE_ON;
3093 break;
3094 case ATH10K_STATE_RESTARTING:
3095 ath10k_halt(ar);
3096 ar->state = ATH10K_STATE_RESTARTED;
3097 break;
3098 case ATH10K_STATE_ON:
3099 case ATH10K_STATE_RESTARTED:
3100 case ATH10K_STATE_WEDGED:
3101 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003102 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003103 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003104 case ATH10K_STATE_UTF:
3105 ret = -EBUSY;
3106 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003107 }
3108
3109 ret = ath10k_hif_power_up(ar);
3110 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003111 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003112 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003113 }
3114
Kalle Valo43d2a302014-09-10 18:23:30 +03003115 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003116 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003117 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003118 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003119 }
3120
Bartosz Markowski226a3392013-09-26 17:47:16 +02003121 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003122 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003123 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003124 goto err_core_stop;
3125 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003126
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003127 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003128 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003129 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003130 goto err_core_stop;
3131 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132
Ben Greear46acf7bb2014-05-16 17:15:38 +03003133 if (ar->cfg_tx_chainmask)
3134 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3135 ar->cfg_rx_chainmask);
3136
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003137 /*
3138 * By default FW set ARP frames ac to voice (6). In that case ARP
3139 * exchange is not working properly for UAPSD enabled AP. ARP requests
3140 * which arrives with access category 0 are processed by network stack
3141 * and send back with access category 0, but FW changes access category
3142 * to 6. Set ARP frames access category to best effort (0) solves
3143 * this problem.
3144 */
3145
3146 ret = ath10k_wmi_pdev_set_param(ar,
3147 ar->wmi.pdev_param->arp_ac_override, 0);
3148 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003149 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003150 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003151 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003152 }
3153
Michal Kaziord6500972014-04-08 09:56:09 +03003154 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003155 ath10k_regd_update(ar);
3156
Simon Wunderlich855aed12014-08-02 09:12:54 +03003157 ath10k_spectral_start(ar);
3158
Michal Kaziorae254432014-05-26 12:46:02 +03003159 mutex_unlock(&ar->conf_mutex);
3160 return 0;
3161
3162err_core_stop:
3163 ath10k_core_stop(ar);
3164
3165err_power_down:
3166 ath10k_hif_power_down(ar);
3167
3168err_off:
3169 ar->state = ATH10K_STATE_OFF;
3170
3171err:
Michal Kazior548db542013-07-05 16:15:15 +03003172 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003173 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003174}
3175
3176static void ath10k_stop(struct ieee80211_hw *hw)
3177{
3178 struct ath10k *ar = hw->priv;
3179
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003180 ath10k_drain_tx(ar);
3181
Michal Kazior548db542013-07-05 16:15:15 +03003182 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003183 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003184 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003185 ar->state = ATH10K_STATE_OFF;
3186 }
Michal Kazior548db542013-07-05 16:15:15 +03003187 mutex_unlock(&ar->conf_mutex);
3188
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003189 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003190 cancel_work_sync(&ar->restart_work);
3191}
3192
Michal Kaziorad088bf2013-10-16 15:44:46 +03003193static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003194{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003195 struct ath10k_vif *arvif;
3196 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003197
3198 lockdep_assert_held(&ar->conf_mutex);
3199
Michal Kaziorad088bf2013-10-16 15:44:46 +03003200 list_for_each_entry(arvif, &ar->arvifs, list) {
3201 ret = ath10k_mac_vif_setup_ps(arvif);
3202 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003203 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003204 break;
3205 }
3206 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003207
Michal Kaziorad088bf2013-10-16 15:44:46 +03003208 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003209}
3210
Michal Kaziorc930f742014-01-23 11:38:25 +01003211static const char *chandef_get_width(enum nl80211_chan_width width)
3212{
3213 switch (width) {
3214 case NL80211_CHAN_WIDTH_20_NOHT:
3215 return "20 (noht)";
3216 case NL80211_CHAN_WIDTH_20:
3217 return "20";
3218 case NL80211_CHAN_WIDTH_40:
3219 return "40";
3220 case NL80211_CHAN_WIDTH_80:
3221 return "80";
3222 case NL80211_CHAN_WIDTH_80P80:
3223 return "80+80";
3224 case NL80211_CHAN_WIDTH_160:
3225 return "160";
3226 case NL80211_CHAN_WIDTH_5:
3227 return "5";
3228 case NL80211_CHAN_WIDTH_10:
3229 return "10";
3230 }
3231 return "?";
3232}
3233
3234static void ath10k_config_chan(struct ath10k *ar)
3235{
3236 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003237 int ret;
3238
3239 lockdep_assert_held(&ar->conf_mutex);
3240
Michal Kazior7aa7a722014-08-25 12:09:38 +02003241 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003242 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3243 ar->chandef.chan->center_freq,
3244 ar->chandef.center_freq1,
3245 ar->chandef.center_freq2,
3246 chandef_get_width(ar->chandef.width));
3247
3248 /* First stop monitor interface. Some FW versions crash if there's a
3249 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003250 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003251 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003252
3253 list_for_each_entry(arvif, &ar->arvifs, list) {
3254 if (!arvif->is_started)
3255 continue;
3256
Michal Kaziordc55e302014-07-29 12:53:36 +03003257 if (!arvif->is_up)
3258 continue;
3259
Michal Kaziorc930f742014-01-23 11:38:25 +01003260 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3261 continue;
3262
Michal Kaziordc55e302014-07-29 12:53:36 +03003263 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003264 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003265 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003266 arvif->vdev_id, ret);
3267 continue;
3268 }
3269 }
3270
Michal Kaziordc55e302014-07-29 12:53:36 +03003271 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003272
3273 list_for_each_entry(arvif, &ar->arvifs, list) {
3274 if (!arvif->is_started)
3275 continue;
3276
3277 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3278 continue;
3279
Michal Kazior81a9a172015-03-05 16:02:17 +02003280 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3281 if (ret)
3282 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3283 ret);
3284
3285 ret = ath10k_mac_setup_prb_tmpl(arvif);
3286 if (ret)
3287 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3288 ret);
3289
Michal Kaziordc55e302014-07-29 12:53:36 +03003290 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003291 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003292 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003293 arvif->vdev_id, ret);
3294 continue;
3295 }
3296
3297 if (!arvif->is_up)
3298 continue;
3299
3300 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3301 arvif->bssid);
3302 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003303 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003304 arvif->vdev_id, ret);
3305 continue;
3306 }
3307 }
3308
Michal Kazior19337472014-08-28 12:58:16 +02003309 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003310}
3311
Michal Kazior7d9d5582014-10-21 10:40:15 +03003312static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3313{
3314 int ret;
3315 u32 param;
3316
3317 lockdep_assert_held(&ar->conf_mutex);
3318
3319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3320
3321 param = ar->wmi.pdev_param->txpower_limit2g;
3322 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3323 if (ret) {
3324 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3325 txpower, ret);
3326 return ret;
3327 }
3328
3329 param = ar->wmi.pdev_param->txpower_limit5g;
3330 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3331 if (ret) {
3332 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3333 txpower, ret);
3334 return ret;
3335 }
3336
3337 return 0;
3338}
3339
3340static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3341{
3342 struct ath10k_vif *arvif;
3343 int ret, txpower = -1;
3344
3345 lockdep_assert_held(&ar->conf_mutex);
3346
3347 list_for_each_entry(arvif, &ar->arvifs, list) {
3348 WARN_ON(arvif->txpower < 0);
3349
3350 if (txpower == -1)
3351 txpower = arvif->txpower;
3352 else
3353 txpower = min(txpower, arvif->txpower);
3354 }
3355
3356 if (WARN_ON(txpower == -1))
3357 return -EINVAL;
3358
3359 ret = ath10k_mac_txpower_setup(ar, txpower);
3360 if (ret) {
3361 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3362 txpower, ret);
3363 return ret;
3364 }
3365
3366 return 0;
3367}
3368
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3370{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003371 struct ath10k *ar = hw->priv;
3372 struct ieee80211_conf *conf = &hw->conf;
3373 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003374
3375 mutex_lock(&ar->conf_mutex);
3376
3377 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003378 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003379 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003380 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003381 conf->chandef.chan->flags,
3382 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003383
Kalle Valo5e3dd152013-06-12 20:52:10 +03003384 spin_lock_bh(&ar->data_lock);
3385 ar->rx_channel = conf->chandef.chan;
3386 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003387
Michal Kaziord6500972014-04-08 09:56:09 +03003388 ar->radar_enabled = conf->radar_enabled;
3389 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003390
3391 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3392 ar->chandef = conf->chandef;
3393 ath10k_config_chan(ar);
3394 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395 }
3396
Michal Kazioraffd3212013-07-16 09:54:35 +02003397 if (changed & IEEE80211_CONF_CHANGE_PS)
3398 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003399
3400 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003401 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3402 ret = ath10k_monitor_recalc(ar);
3403 if (ret)
3404 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405 }
3406
3407 mutex_unlock(&ar->conf_mutex);
3408 return ret;
3409}
3410
Ben Greear5572a952014-11-24 16:22:10 +02003411static u32 get_nss_from_chainmask(u16 chain_mask)
3412{
3413 if ((chain_mask & 0x15) == 0x15)
3414 return 4;
3415 else if ((chain_mask & 0x7) == 0x7)
3416 return 3;
3417 else if ((chain_mask & 0x3) == 0x3)
3418 return 2;
3419 return 1;
3420}
3421
Kalle Valo5e3dd152013-06-12 20:52:10 +03003422/*
3423 * TODO:
3424 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3425 * because we will send mgmt frames without CCK. This requirement
3426 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3427 * in the TX packet.
3428 */
3429static int ath10k_add_interface(struct ieee80211_hw *hw,
3430 struct ieee80211_vif *vif)
3431{
3432 struct ath10k *ar = hw->priv;
3433 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3434 enum wmi_sta_powersave_param param;
3435 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003436 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003437 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003438 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003439
Johannes Berg848955c2014-11-11 12:48:42 +01003440 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3441
Kalle Valo5e3dd152013-06-12 20:52:10 +03003442 mutex_lock(&ar->conf_mutex);
3443
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003444 memset(arvif, 0, sizeof(*arvif));
3445
Kalle Valo5e3dd152013-06-12 20:52:10 +03003446 arvif->ar = ar;
3447 arvif->vif = vif;
3448
Ben Greeare63b33f2013-10-22 14:54:14 -07003449 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003450 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003451 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3452 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003453
Ben Greeara9aefb32014-08-12 11:02:19 +03003454 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003455 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003457 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458 }
Ben Greear16c11172014-09-23 14:17:16 -07003459 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003460
Ben Greear16c11172014-09-23 14:17:16 -07003461 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3462 bit, ar->free_vdev_map);
3463
3464 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003465 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003468 case NL80211_IFTYPE_P2P_DEVICE:
3469 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3470 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3471 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003472 case NL80211_IFTYPE_UNSPECIFIED:
3473 case NL80211_IFTYPE_STATION:
3474 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3475 if (vif->p2p)
3476 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3477 break;
3478 case NL80211_IFTYPE_ADHOC:
3479 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3480 break;
3481 case NL80211_IFTYPE_AP:
3482 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3483
3484 if (vif->p2p)
3485 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3486 break;
3487 case NL80211_IFTYPE_MONITOR:
3488 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3489 break;
3490 default:
3491 WARN_ON(1);
3492 break;
3493 }
3494
Michal Kazior64badcb2014-09-18 11:18:02 +03003495 /* Some firmware revisions don't wait for beacon tx completion before
3496 * sending another SWBA event. This could lead to hardware using old
3497 * (freed) beacon data in some cases, e.g. tx credit starvation
3498 * combined with missed TBTT. This is very very rare.
3499 *
3500 * On non-IOMMU-enabled hosts this could be a possible security issue
3501 * because hw could beacon some random data on the air. On
3502 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3503 * device would crash.
3504 *
3505 * Since there are no beacon tx completions (implicit nor explicit)
3506 * propagated to host the only workaround for this is to allocate a
3507 * DMA-coherent buffer for a lifetime of a vif and use it for all
3508 * beacon tx commands. Worst case for this approach is some beacons may
3509 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3510 */
3511 if (vif->type == NL80211_IFTYPE_ADHOC ||
3512 vif->type == NL80211_IFTYPE_AP) {
3513 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3514 IEEE80211_MAX_FRAME_LEN,
3515 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303516 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003517 if (!arvif->beacon_buf) {
3518 ret = -ENOMEM;
3519 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3520 ret);
3521 goto err;
3522 }
3523 }
3524
3525 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3526 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3527 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003528
3529 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3530 arvif->vdev_subtype, vif->addr);
3531 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003532 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003533 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003534 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003535 }
3536
Ben Greear16c11172014-09-23 14:17:16 -07003537 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003538 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003539
Michal Kazior46725b152015-01-28 09:57:49 +02003540 /* It makes no sense to have firmware do keepalives. mac80211 already
3541 * takes care of this with idle connection polling.
3542 */
3543 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003544 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003545 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003546 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003547 goto err_vdev_delete;
3548 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003549
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003550 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003551
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003552 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3553 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003554 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003555 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003556 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003557 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003558 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003559 goto err_vdev_delete;
3560 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561
Ben Greear5572a952014-11-24 16:22:10 +02003562 if (ar->cfg_tx_chainmask) {
3563 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3564
3565 vdev_param = ar->wmi.vdev_param->nss;
3566 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3567 nss);
3568 if (ret) {
3569 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3570 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3571 ret);
3572 goto err_vdev_delete;
3573 }
3574 }
3575
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3577 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3578 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003579 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003580 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003581 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003582 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003583
Kalle Valo5a13e762014-01-20 11:01:46 +02003584 ret = ath10k_mac_set_kickout(arvif);
3585 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003586 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003587 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003588 goto err_peer_delete;
3589 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003590 }
3591
3592 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3593 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3594 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3595 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3596 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003597 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003598 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003599 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003600 goto err_peer_delete;
3601 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003602
Michal Kazior9f9b5742014-12-12 12:41:36 +01003603 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003604 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003605 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003606 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003607 goto err_peer_delete;
3608 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003609
Michal Kazior9f9b5742014-12-12 12:41:36 +01003610 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003611 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003612 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003613 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003614 goto err_peer_delete;
3615 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003616 }
3617
Michal Kazior424121c2013-07-22 14:13:31 +02003618 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003619 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003620 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003621 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003622 goto err_peer_delete;
3623 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003624
Michal Kazior424121c2013-07-22 14:13:31 +02003625 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003626 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003627 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003628 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003629 goto err_peer_delete;
3630 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003631
Michal Kazior7d9d5582014-10-21 10:40:15 +03003632 arvif->txpower = vif->bss_conf.txpower;
3633 ret = ath10k_mac_txpower_recalc(ar);
3634 if (ret) {
3635 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3636 goto err_peer_delete;
3637 }
3638
Kalle Valo5e3dd152013-06-12 20:52:10 +03003639 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003640 return 0;
3641
3642err_peer_delete:
3643 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3644 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3645
3646err_vdev_delete:
3647 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003648 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003649 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003650
3651err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003652 if (arvif->beacon_buf) {
3653 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3654 arvif->beacon_buf, arvif->beacon_paddr);
3655 arvif->beacon_buf = NULL;
3656 }
3657
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003658 mutex_unlock(&ar->conf_mutex);
3659
Kalle Valo5e3dd152013-06-12 20:52:10 +03003660 return ret;
3661}
3662
3663static void ath10k_remove_interface(struct ieee80211_hw *hw,
3664 struct ieee80211_vif *vif)
3665{
3666 struct ath10k *ar = hw->priv;
3667 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3668 int ret;
3669
Michal Kazior81a9a172015-03-05 16:02:17 +02003670 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003671 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003672
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303673 mutex_lock(&ar->conf_mutex);
3674
Michal Kaziored543882013-09-13 14:16:56 +02003675 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003676 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003677 spin_unlock_bh(&ar->data_lock);
3678
Simon Wunderlich855aed12014-08-02 09:12:54 +03003679 ret = ath10k_spectral_vif_stop(arvif);
3680 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003681 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003682 arvif->vdev_id, ret);
3683
Ben Greear16c11172014-09-23 14:17:16 -07003684 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003685 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003686
3687 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003688 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3689 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003690 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003691 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003692 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003693
3694 kfree(arvif->u.ap.noa_data);
3695 }
3696
Michal Kazior7aa7a722014-08-25 12:09:38 +02003697 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003698 arvif->vdev_id);
3699
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3701 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003702 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003703 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003704
Michal Kazior2c512052015-02-15 16:50:40 +02003705 /* Some firmware revisions don't notify host about self-peer removal
3706 * until after associated vdev is deleted.
3707 */
3708 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3709 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3710 vif->addr);
3711 if (ret)
3712 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3713 arvif->vdev_id, ret);
3714
3715 spin_lock_bh(&ar->data_lock);
3716 ar->num_peers--;
3717 spin_unlock_bh(&ar->data_lock);
3718 }
3719
Kalle Valo5e3dd152013-06-12 20:52:10 +03003720 ath10k_peer_cleanup(ar, arvif->vdev_id);
3721
3722 mutex_unlock(&ar->conf_mutex);
3723}
3724
3725/*
3726 * FIXME: Has to be verified.
3727 */
3728#define SUPPORTED_FILTERS \
3729 (FIF_PROMISC_IN_BSS | \
3730 FIF_ALLMULTI | \
3731 FIF_CONTROL | \
3732 FIF_PSPOLL | \
3733 FIF_OTHER_BSS | \
3734 FIF_BCN_PRBRESP_PROMISC | \
3735 FIF_PROBE_REQ | \
3736 FIF_FCSFAIL)
3737
3738static void ath10k_configure_filter(struct ieee80211_hw *hw,
3739 unsigned int changed_flags,
3740 unsigned int *total_flags,
3741 u64 multicast)
3742{
3743 struct ath10k *ar = hw->priv;
3744 int ret;
3745
3746 mutex_lock(&ar->conf_mutex);
3747
3748 changed_flags &= SUPPORTED_FILTERS;
3749 *total_flags &= SUPPORTED_FILTERS;
3750 ar->filter_flags = *total_flags;
3751
Michal Kazior19337472014-08-28 12:58:16 +02003752 ret = ath10k_monitor_recalc(ar);
3753 if (ret)
3754 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003755
3756 mutex_unlock(&ar->conf_mutex);
3757}
3758
3759static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3760 struct ieee80211_vif *vif,
3761 struct ieee80211_bss_conf *info,
3762 u32 changed)
3763{
3764 struct ath10k *ar = hw->priv;
3765 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3766 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003767 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003768
3769 mutex_lock(&ar->conf_mutex);
3770
3771 if (changed & BSS_CHANGED_IBSS)
3772 ath10k_control_ibss(arvif, info, vif->addr);
3773
3774 if (changed & BSS_CHANGED_BEACON_INT) {
3775 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003776 vdev_param = ar->wmi.vdev_param->beacon_interval;
3777 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003778 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003779 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003780 "mac vdev %d beacon_interval %d\n",
3781 arvif->vdev_id, arvif->beacon_interval);
3782
Kalle Valo5e3dd152013-06-12 20:52:10 +03003783 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003784 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003785 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786 }
3787
3788 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003789 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003790 "vdev %d set beacon tx mode to staggered\n",
3791 arvif->vdev_id);
3792
Bartosz Markowski226a3392013-09-26 17:47:16 +02003793 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3794 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003795 WMI_BEACON_STAGGERED_MODE);
3796 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003797 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003798 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003799
3800 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3801 if (ret)
3802 ath10k_warn(ar, "failed to update beacon template: %d\n",
3803 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003804 }
3805
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003806 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3807 ret = ath10k_mac_setup_prb_tmpl(arvif);
3808 if (ret)
3809 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3810 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003811 }
3812
Michal Kaziorba2479f2015-01-24 12:14:51 +02003813 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003814 arvif->dtim_period = info->dtim_period;
3815
Michal Kazior7aa7a722014-08-25 12:09:38 +02003816 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003817 "mac vdev %d dtim_period %d\n",
3818 arvif->vdev_id, arvif->dtim_period);
3819
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003820 vdev_param = ar->wmi.vdev_param->dtim_period;
3821 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003822 arvif->dtim_period);
3823 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003824 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003825 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003826 }
3827
3828 if (changed & BSS_CHANGED_SSID &&
3829 vif->type == NL80211_IFTYPE_AP) {
3830 arvif->u.ap.ssid_len = info->ssid_len;
3831 if (info->ssid_len)
3832 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3833 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3834 }
3835
Michal Kazior077efc82014-10-21 10:10:29 +03003836 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3837 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003838
3839 if (changed & BSS_CHANGED_BEACON_ENABLED)
3840 ath10k_control_beaconing(arvif, info);
3841
3842 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003843 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003844 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003845 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003846
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003847 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003848 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003849 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003850 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003851
3852 vdev_param = ar->wmi.vdev_param->protection_mode;
3853 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3854 info->use_cts_prot ? 1 : 0);
3855 if (ret)
3856 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3857 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003858 }
3859
3860 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003861 if (info->use_short_slot)
3862 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3863
3864 else
3865 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3866
Michal Kazior7aa7a722014-08-25 12:09:38 +02003867 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003868 arvif->vdev_id, slottime);
3869
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003870 vdev_param = ar->wmi.vdev_param->slot_time;
3871 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003872 slottime);
3873 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003874 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003875 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003876 }
3877
3878 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 if (info->use_short_preamble)
3880 preamble = WMI_VDEV_PREAMBLE_SHORT;
3881 else
3882 preamble = WMI_VDEV_PREAMBLE_LONG;
3883
Michal Kazior7aa7a722014-08-25 12:09:38 +02003884 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003885 "mac vdev %d preamble %dn",
3886 arvif->vdev_id, preamble);
3887
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003888 vdev_param = ar->wmi.vdev_param->preamble;
3889 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003890 preamble);
3891 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003892 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003893 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003894 }
3895
3896 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003897 if (info->assoc) {
3898 /* Workaround: Make sure monitor vdev is not running
3899 * when associating to prevent some firmware revisions
3900 * (e.g. 10.1 and 10.2) from crashing.
3901 */
3902 if (ar->monitor_started)
3903 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003904 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003905 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003906 } else {
3907 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003908 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909 }
3910
Michal Kazior7d9d5582014-10-21 10:40:15 +03003911 if (changed & BSS_CHANGED_TXPOWER) {
3912 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3913 arvif->vdev_id, info->txpower);
3914
3915 arvif->txpower = info->txpower;
3916 ret = ath10k_mac_txpower_recalc(ar);
3917 if (ret)
3918 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3919 }
3920
Michal Kaziorbf14e652014-12-12 12:41:38 +01003921 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003922 arvif->ps = vif->bss_conf.ps;
3923
3924 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003925 if (ret)
3926 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3927 arvif->vdev_id, ret);
3928 }
3929
Kalle Valo5e3dd152013-06-12 20:52:10 +03003930 mutex_unlock(&ar->conf_mutex);
3931}
3932
3933static int ath10k_hw_scan(struct ieee80211_hw *hw,
3934 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003935 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003936{
3937 struct ath10k *ar = hw->priv;
3938 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003939 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003940 struct wmi_start_scan_arg arg;
3941 int ret = 0;
3942 int i;
3943
3944 mutex_lock(&ar->conf_mutex);
3945
3946 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003947 switch (ar->scan.state) {
3948 case ATH10K_SCAN_IDLE:
3949 reinit_completion(&ar->scan.started);
3950 reinit_completion(&ar->scan.completed);
3951 ar->scan.state = ATH10K_SCAN_STARTING;
3952 ar->scan.is_roc = false;
3953 ar->scan.vdev_id = arvif->vdev_id;
3954 ret = 0;
3955 break;
3956 case ATH10K_SCAN_STARTING:
3957 case ATH10K_SCAN_RUNNING:
3958 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003959 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003960 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003961 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 spin_unlock_bh(&ar->data_lock);
3963
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003964 if (ret)
3965 goto exit;
3966
Kalle Valo5e3dd152013-06-12 20:52:10 +03003967 memset(&arg, 0, sizeof(arg));
3968 ath10k_wmi_start_scan_init(ar, &arg);
3969 arg.vdev_id = arvif->vdev_id;
3970 arg.scan_id = ATH10K_SCAN_ID;
3971
3972 if (!req->no_cck)
3973 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3974
3975 if (req->ie_len) {
3976 arg.ie_len = req->ie_len;
3977 memcpy(arg.ie, req->ie, arg.ie_len);
3978 }
3979
3980 if (req->n_ssids) {
3981 arg.n_ssids = req->n_ssids;
3982 for (i = 0; i < arg.n_ssids; i++) {
3983 arg.ssids[i].len = req->ssids[i].ssid_len;
3984 arg.ssids[i].ssid = req->ssids[i].ssid;
3985 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003986 } else {
3987 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003988 }
3989
3990 if (req->n_channels) {
3991 arg.n_channels = req->n_channels;
3992 for (i = 0; i < arg.n_channels; i++)
3993 arg.channels[i] = req->channels[i]->center_freq;
3994 }
3995
3996 ret = ath10k_start_scan(ar, &arg);
3997 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003998 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004000 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004001 spin_unlock_bh(&ar->data_lock);
4002 }
4003
4004exit:
4005 mutex_unlock(&ar->conf_mutex);
4006 return ret;
4007}
4008
4009static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4010 struct ieee80211_vif *vif)
4011{
4012 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004013
4014 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004015 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004016 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004017
4018 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019}
4020
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004021static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4022 struct ath10k_vif *arvif,
4023 enum set_key_cmd cmd,
4024 struct ieee80211_key_conf *key)
4025{
4026 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4027 int ret;
4028
4029 /* 10.1 firmware branch requires default key index to be set to group
4030 * key index after installing it. Otherwise FW/HW Txes corrupted
4031 * frames with multi-vif APs. This is not required for main firmware
4032 * branch (e.g. 636).
4033 *
4034 * FIXME: This has been tested only in AP. It remains unknown if this
4035 * is required for multi-vif STA interfaces on 10.1 */
4036
4037 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4038 return;
4039
4040 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4041 return;
4042
4043 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4044 return;
4045
4046 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4047 return;
4048
4049 if (cmd != SET_KEY)
4050 return;
4051
4052 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4053 key->keyidx);
4054 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004055 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004056 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004057}
4058
Kalle Valo5e3dd152013-06-12 20:52:10 +03004059static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4060 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4061 struct ieee80211_key_conf *key)
4062{
4063 struct ath10k *ar = hw->priv;
4064 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4065 struct ath10k_peer *peer;
4066 const u8 *peer_addr;
4067 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4068 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4069 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004070 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004071
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004072 /* this one needs to be done in software */
4073 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4074 return 1;
4075
Kalle Valo5e3dd152013-06-12 20:52:10 +03004076 if (key->keyidx > WMI_MAX_KEY_INDEX)
4077 return -ENOSPC;
4078
4079 mutex_lock(&ar->conf_mutex);
4080
4081 if (sta)
4082 peer_addr = sta->addr;
4083 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4084 peer_addr = vif->bss_conf.bssid;
4085 else
4086 peer_addr = vif->addr;
4087
4088 key->hw_key_idx = key->keyidx;
4089
4090 /* the peer should not disappear in mid-way (unless FW goes awry) since
4091 * we already hold conf_mutex. we just make sure its there now. */
4092 spin_lock_bh(&ar->data_lock);
4093 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4094 spin_unlock_bh(&ar->data_lock);
4095
4096 if (!peer) {
4097 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004098 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004099 peer_addr);
4100 ret = -EOPNOTSUPP;
4101 goto exit;
4102 } else {
4103 /* if the peer doesn't exist there is no key to disable
4104 * anymore */
4105 goto exit;
4106 }
4107 }
4108
Michal Kazior7cc45732015-03-09 14:24:17 +01004109 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4110 flags |= WMI_KEY_PAIRWISE;
4111 else
4112 flags |= WMI_KEY_GROUP;
4113
Kalle Valo5e3dd152013-06-12 20:52:10 +03004114 if (is_wep) {
4115 if (cmd == SET_KEY)
4116 arvif->wep_keys[key->keyidx] = key;
4117 else
4118 arvif->wep_keys[key->keyidx] = NULL;
4119
4120 if (cmd == DISABLE_KEY)
4121 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004122
Michal Kaziorad325cb2015-02-18 14:02:27 +01004123 /* When WEP keys are uploaded it's possible that there are
4124 * stations associated already (e.g. when merging) without any
4125 * keys. Static WEP needs an explicit per-peer key upload.
4126 */
4127 if (vif->type == NL80211_IFTYPE_ADHOC &&
4128 cmd == SET_KEY)
4129 ath10k_mac_vif_update_wep_key(arvif, key);
4130
Michal Kazior370e5672015-02-18 14:02:26 +01004131 /* 802.1x never sets the def_wep_key_idx so each set_key()
4132 * call changes default tx key.
4133 *
4134 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4135 * after first set_key().
4136 */
4137 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4138 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139
Michal Kazior7cc45732015-03-09 14:24:17 +01004140 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4141 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4142 * mode and associated stations in AP/IBSS.
4143 *
4144 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4145 * work fine when mapped directly from mac80211.
4146 *
4147 * Note: When installing first static WEP groupwise key (which
4148 * should be pairwise) def_wep_key_idx isn't known yet (it's
4149 * equal to -1). Since .set_default_unicast_key is called only
4150 * for static WEP it's used to re-upload the key as pairwise.
4151 */
4152 if (arvif->def_wep_key_idx >= 0 &&
4153 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4154 flags &= ~WMI_KEY_GROUP;
4155 flags |= WMI_KEY_PAIRWISE;
4156 }
Michal Kazior370e5672015-02-18 14:02:26 +01004157 }
4158
4159 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004161 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004162 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004163 goto exit;
4164 }
4165
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004166 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4167
Kalle Valo5e3dd152013-06-12 20:52:10 +03004168 spin_lock_bh(&ar->data_lock);
4169 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4170 if (peer && cmd == SET_KEY)
4171 peer->keys[key->keyidx] = key;
4172 else if (peer && cmd == DISABLE_KEY)
4173 peer->keys[key->keyidx] = NULL;
4174 else if (peer == NULL)
4175 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004176 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004177 spin_unlock_bh(&ar->data_lock);
4178
4179exit:
4180 mutex_unlock(&ar->conf_mutex);
4181 return ret;
4182}
4183
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004184static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4185 struct ieee80211_vif *vif,
4186 int keyidx)
4187{
4188 struct ath10k *ar = hw->priv;
4189 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4190 int ret;
4191
4192 mutex_lock(&arvif->ar->conf_mutex);
4193
4194 if (arvif->ar->state != ATH10K_STATE_ON)
4195 goto unlock;
4196
4197 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4198 arvif->vdev_id, keyidx);
4199
4200 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4201 arvif->vdev_id,
4202 arvif->ar->wmi.vdev_param->def_keyid,
4203 keyidx);
4204
4205 if (ret) {
4206 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4207 arvif->vdev_id,
4208 ret);
4209 goto unlock;
4210 }
4211
4212 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004213
4214 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4215 if (ret) {
4216 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4217 arvif->vdev_id, ret);
4218 goto unlock;
4219 }
4220
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004221unlock:
4222 mutex_unlock(&arvif->ar->conf_mutex);
4223}
4224
Michal Kazior9797feb2014-02-14 14:49:48 +01004225static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4226{
4227 struct ath10k *ar;
4228 struct ath10k_vif *arvif;
4229 struct ath10k_sta *arsta;
4230 struct ieee80211_sta *sta;
4231 u32 changed, bw, nss, smps;
4232 int err;
4233
4234 arsta = container_of(wk, struct ath10k_sta, update_wk);
4235 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4236 arvif = arsta->arvif;
4237 ar = arvif->ar;
4238
4239 spin_lock_bh(&ar->data_lock);
4240
4241 changed = arsta->changed;
4242 arsta->changed = 0;
4243
4244 bw = arsta->bw;
4245 nss = arsta->nss;
4246 smps = arsta->smps;
4247
4248 spin_unlock_bh(&ar->data_lock);
4249
4250 mutex_lock(&ar->conf_mutex);
4251
4252 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004253 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004254 sta->addr, bw);
4255
4256 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4257 WMI_PEER_CHAN_WIDTH, bw);
4258 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004259 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004260 sta->addr, bw, err);
4261 }
4262
4263 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004264 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004265 sta->addr, nss);
4266
4267 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4268 WMI_PEER_NSS, nss);
4269 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004270 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004271 sta->addr, nss, err);
4272 }
4273
4274 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004275 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004276 sta->addr, smps);
4277
4278 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4279 WMI_PEER_SMPS_STATE, smps);
4280 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004282 sta->addr, smps, err);
4283 }
4284
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004285 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4286 changed & IEEE80211_RC_NSS_CHANGED) {
4287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004288 sta->addr);
4289
Michal Kazior590922a2014-10-21 10:10:29 +03004290 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004291 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004292 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004293 sta->addr);
4294 }
4295
Michal Kazior9797feb2014-02-14 14:49:48 +01004296 mutex_unlock(&ar->conf_mutex);
4297}
4298
Michal Kaziorcfd10612014-11-25 15:16:05 +01004299static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4300{
4301 struct ath10k *ar = arvif->ar;
4302
4303 lockdep_assert_held(&ar->conf_mutex);
4304
4305 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4306 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4307 return 0;
4308
4309 if (ar->num_stations >= ar->max_num_stations)
4310 return -ENOBUFS;
4311
4312 ar->num_stations++;
4313
4314 return 0;
4315}
4316
4317static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4318{
4319 struct ath10k *ar = arvif->ar;
4320
4321 lockdep_assert_held(&ar->conf_mutex);
4322
4323 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4324 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4325 return;
4326
4327 ar->num_stations--;
4328}
4329
Kalle Valo5e3dd152013-06-12 20:52:10 +03004330static int ath10k_sta_state(struct ieee80211_hw *hw,
4331 struct ieee80211_vif *vif,
4332 struct ieee80211_sta *sta,
4333 enum ieee80211_sta_state old_state,
4334 enum ieee80211_sta_state new_state)
4335{
4336 struct ath10k *ar = hw->priv;
4337 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004338 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004339 int ret = 0;
4340
Michal Kazior76f90022014-02-25 09:29:57 +02004341 if (old_state == IEEE80211_STA_NOTEXIST &&
4342 new_state == IEEE80211_STA_NONE) {
4343 memset(arsta, 0, sizeof(*arsta));
4344 arsta->arvif = arvif;
4345 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4346 }
4347
Michal Kazior9797feb2014-02-14 14:49:48 +01004348 /* cancel must be done outside the mutex to avoid deadlock */
4349 if ((old_state == IEEE80211_STA_NONE &&
4350 new_state == IEEE80211_STA_NOTEXIST))
4351 cancel_work_sync(&arsta->update_wk);
4352
Kalle Valo5e3dd152013-06-12 20:52:10 +03004353 mutex_lock(&ar->conf_mutex);
4354
4355 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004356 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004357 /*
4358 * New station addition.
4359 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004360 ath10k_dbg(ar, ATH10K_DBG_MAC,
4361 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4362 arvif->vdev_id, sta->addr,
4363 ar->num_stations + 1, ar->max_num_stations,
4364 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004365
Michal Kaziorcfd10612014-11-25 15:16:05 +01004366 ret = ath10k_mac_inc_num_stations(arvif);
4367 if (ret) {
4368 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4369 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004370 goto exit;
4371 }
4372
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004374 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004375 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 -08004376 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004377 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004378 goto exit;
4379 }
Michal Kazior077efc82014-10-21 10:10:29 +03004380
4381 if (vif->type == NL80211_IFTYPE_STATION) {
4382 WARN_ON(arvif->is_started);
4383
4384 ret = ath10k_vdev_start(arvif);
4385 if (ret) {
4386 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4387 arvif->vdev_id, ret);
4388 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4389 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004390 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004391 goto exit;
4392 }
4393
4394 arvif->is_started = true;
4395 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004396 } else if ((old_state == IEEE80211_STA_NONE &&
4397 new_state == IEEE80211_STA_NOTEXIST)) {
4398 /*
4399 * Existing station deletion.
4400 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004401 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004402 "mac vdev %d peer delete %pM (sta gone)\n",
4403 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004404
4405 if (vif->type == NL80211_IFTYPE_STATION) {
4406 WARN_ON(!arvif->is_started);
4407
4408 ret = ath10k_vdev_stop(arvif);
4409 if (ret)
4410 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4411 arvif->vdev_id, ret);
4412
4413 arvif->is_started = false;
4414 }
4415
Kalle Valo5e3dd152013-06-12 20:52:10 +03004416 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4417 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004418 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004419 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004420
Michal Kaziorcfd10612014-11-25 15:16:05 +01004421 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004422 } else if (old_state == IEEE80211_STA_AUTH &&
4423 new_state == IEEE80211_STA_ASSOC &&
4424 (vif->type == NL80211_IFTYPE_AP ||
4425 vif->type == NL80211_IFTYPE_ADHOC)) {
4426 /*
4427 * New association.
4428 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004429 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004430 sta->addr);
4431
Michal Kazior590922a2014-10-21 10:10:29 +03004432 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004433 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004434 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004435 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004436 } else if (old_state == IEEE80211_STA_ASSOC &&
4437 new_state == IEEE80211_STA_AUTH &&
4438 (vif->type == NL80211_IFTYPE_AP ||
4439 vif->type == NL80211_IFTYPE_ADHOC)) {
4440 /*
4441 * Disassociation.
4442 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004443 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004444 sta->addr);
4445
Michal Kazior590922a2014-10-21 10:10:29 +03004446 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004447 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004448 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004449 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004450 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004451exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004452 mutex_unlock(&ar->conf_mutex);
4453 return ret;
4454}
4455
4456static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004457 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004458{
4459 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004460 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4461 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004462 u32 value = 0;
4463 int ret = 0;
4464
Michal Kazior548db542013-07-05 16:15:15 +03004465 lockdep_assert_held(&ar->conf_mutex);
4466
Kalle Valo5e3dd152013-06-12 20:52:10 +03004467 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4468 return 0;
4469
4470 switch (ac) {
4471 case IEEE80211_AC_VO:
4472 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4473 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004474 prio = 7;
4475 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004476 break;
4477 case IEEE80211_AC_VI:
4478 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4479 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004480 prio = 5;
4481 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004482 break;
4483 case IEEE80211_AC_BE:
4484 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4485 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004486 prio = 2;
4487 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004488 break;
4489 case IEEE80211_AC_BK:
4490 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4491 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004492 prio = 0;
4493 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004494 break;
4495 }
4496
4497 if (enable)
4498 arvif->u.sta.uapsd |= value;
4499 else
4500 arvif->u.sta.uapsd &= ~value;
4501
4502 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4503 WMI_STA_PS_PARAM_UAPSD,
4504 arvif->u.sta.uapsd);
4505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004506 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004507 goto exit;
4508 }
4509
4510 if (arvif->u.sta.uapsd)
4511 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4512 else
4513 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4514
4515 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4516 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4517 value);
4518 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004519 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004520
Michal Kazior9f9b5742014-12-12 12:41:36 +01004521 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4522 if (ret) {
4523 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4524 arvif->vdev_id, ret);
4525 return ret;
4526 }
4527
4528 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4529 if (ret) {
4530 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4531 arvif->vdev_id, ret);
4532 return ret;
4533 }
4534
Michal Kaziorb0e56152015-01-24 12:14:52 +02004535 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4536 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4537 /* Only userspace can make an educated decision when to send
4538 * trigger frame. The following effectively disables u-UAPSD
4539 * autotrigger in firmware (which is enabled by default
4540 * provided the autotrigger service is available).
4541 */
4542
4543 arg.wmm_ac = acc;
4544 arg.user_priority = prio;
4545 arg.service_interval = 0;
4546 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4547 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4548
4549 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4550 arvif->bssid, &arg, 1);
4551 if (ret) {
4552 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4553 ret);
4554 return ret;
4555 }
4556 }
4557
Kalle Valo5e3dd152013-06-12 20:52:10 +03004558exit:
4559 return ret;
4560}
4561
4562static int ath10k_conf_tx(struct ieee80211_hw *hw,
4563 struct ieee80211_vif *vif, u16 ac,
4564 const struct ieee80211_tx_queue_params *params)
4565{
4566 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004567 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004568 struct wmi_wmm_params_arg *p = NULL;
4569 int ret;
4570
4571 mutex_lock(&ar->conf_mutex);
4572
4573 switch (ac) {
4574 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004575 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004576 break;
4577 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004578 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004579 break;
4580 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004581 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004582 break;
4583 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004584 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004585 break;
4586 }
4587
4588 if (WARN_ON(!p)) {
4589 ret = -EINVAL;
4590 goto exit;
4591 }
4592
4593 p->cwmin = params->cw_min;
4594 p->cwmax = params->cw_max;
4595 p->aifs = params->aifs;
4596
4597 /*
4598 * The channel time duration programmed in the HW is in absolute
4599 * microseconds, while mac80211 gives the txop in units of
4600 * 32 microseconds.
4601 */
4602 p->txop = params->txop * 32;
4603
Michal Kazior7fc979a2015-01-28 09:57:28 +02004604 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4605 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4606 &arvif->wmm_params);
4607 if (ret) {
4608 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4609 arvif->vdev_id, ret);
4610 goto exit;
4611 }
4612 } else {
4613 /* This won't work well with multi-interface cases but it's
4614 * better than nothing.
4615 */
4616 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4617 if (ret) {
4618 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4619 goto exit;
4620 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621 }
4622
4623 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4624 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004625 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004626
4627exit:
4628 mutex_unlock(&ar->conf_mutex);
4629 return ret;
4630}
4631
4632#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4633
4634static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4635 struct ieee80211_vif *vif,
4636 struct ieee80211_channel *chan,
4637 int duration,
4638 enum ieee80211_roc_type type)
4639{
4640 struct ath10k *ar = hw->priv;
4641 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4642 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004643 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004644
4645 mutex_lock(&ar->conf_mutex);
4646
4647 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004648 switch (ar->scan.state) {
4649 case ATH10K_SCAN_IDLE:
4650 reinit_completion(&ar->scan.started);
4651 reinit_completion(&ar->scan.completed);
4652 reinit_completion(&ar->scan.on_channel);
4653 ar->scan.state = ATH10K_SCAN_STARTING;
4654 ar->scan.is_roc = true;
4655 ar->scan.vdev_id = arvif->vdev_id;
4656 ar->scan.roc_freq = chan->center_freq;
4657 ret = 0;
4658 break;
4659 case ATH10K_SCAN_STARTING:
4660 case ATH10K_SCAN_RUNNING:
4661 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004662 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004663 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004664 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004665 spin_unlock_bh(&ar->data_lock);
4666
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004667 if (ret)
4668 goto exit;
4669
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004670 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4671
Kalle Valo5e3dd152013-06-12 20:52:10 +03004672 memset(&arg, 0, sizeof(arg));
4673 ath10k_wmi_start_scan_init(ar, &arg);
4674 arg.vdev_id = arvif->vdev_id;
4675 arg.scan_id = ATH10K_SCAN_ID;
4676 arg.n_channels = 1;
4677 arg.channels[0] = chan->center_freq;
4678 arg.dwell_time_active = duration;
4679 arg.dwell_time_passive = duration;
4680 arg.max_scan_time = 2 * duration;
4681 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4682 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4683
4684 ret = ath10k_start_scan(ar, &arg);
4685 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004686 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004687 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004688 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004689 spin_unlock_bh(&ar->data_lock);
4690 goto exit;
4691 }
4692
4693 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4694 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004695 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004696
4697 ret = ath10k_scan_stop(ar);
4698 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004699 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004700
Kalle Valo5e3dd152013-06-12 20:52:10 +03004701 ret = -ETIMEDOUT;
4702 goto exit;
4703 }
4704
4705 ret = 0;
4706exit:
4707 mutex_unlock(&ar->conf_mutex);
4708 return ret;
4709}
4710
4711static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4712{
4713 struct ath10k *ar = hw->priv;
4714
4715 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004716 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004717 mutex_unlock(&ar->conf_mutex);
4718
Michal Kazior4eb2e162014-10-28 10:23:09 +01004719 cancel_delayed_work_sync(&ar->scan.timeout);
4720
Kalle Valo5e3dd152013-06-12 20:52:10 +03004721 return 0;
4722}
4723
4724/*
4725 * Both RTS and Fragmentation threshold are interface-specific
4726 * in ath10k, but device-specific in mac80211.
4727 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004728
4729static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4730{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004731 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004732 struct ath10k_vif *arvif;
4733 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004734
Michal Kaziorad088bf2013-10-16 15:44:46 +03004735 mutex_lock(&ar->conf_mutex);
4736 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004738 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004739
Michal Kaziorad088bf2013-10-16 15:44:46 +03004740 ret = ath10k_mac_set_rts(arvif, value);
4741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004742 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004743 arvif->vdev_id, ret);
4744 break;
4745 }
4746 }
4747 mutex_unlock(&ar->conf_mutex);
4748
4749 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004750}
4751
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004752static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4753 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004754{
4755 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004756 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004757 int ret;
4758
4759 /* mac80211 doesn't care if we really xmit queued frames or not
4760 * we'll collect those frames either way if we stop/delete vdevs */
4761 if (drop)
4762 return;
4763
Michal Kazior548db542013-07-05 16:15:15 +03004764 mutex_lock(&ar->conf_mutex);
4765
Michal Kazioraffd3212013-07-16 09:54:35 +02004766 if (ar->state == ATH10K_STATE_WEDGED)
4767 goto skip;
4768
Michal Kazioredb82362013-07-05 16:15:14 +03004769 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004770 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004771
Michal Kazioredb82362013-07-05 16:15:14 +03004772 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004773 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004774 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004775
Michal Kazior7962b0d2014-10-28 10:34:38 +01004776 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4777 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4778 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004779
4780 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004781 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004782
4783 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004784 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004785 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004786
Michal Kazioraffd3212013-07-16 09:54:35 +02004787skip:
Michal Kazior548db542013-07-05 16:15:15 +03004788 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004789}
4790
4791/* TODO: Implement this function properly
4792 * For now it is needed to reply to Probe Requests in IBSS mode.
4793 * Propably we need this information from FW.
4794 */
4795static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4796{
4797 return 1;
4798}
4799
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004800#ifdef CONFIG_PM
4801static int ath10k_suspend(struct ieee80211_hw *hw,
4802 struct cfg80211_wowlan *wowlan)
4803{
4804 struct ath10k *ar = hw->priv;
4805 int ret;
4806
Marek Puzyniak9042e172014-02-10 17:14:23 +01004807 mutex_lock(&ar->conf_mutex);
4808
Marek Puzyniak00f54822014-02-10 17:14:24 +01004809 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004810 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004811 if (ret == -ETIMEDOUT)
4812 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004813 ret = 1;
4814 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004815 }
4816
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004817 ret = ath10k_hif_suspend(ar);
4818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004819 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004820 goto resume;
4821 }
4822
Marek Puzyniak9042e172014-02-10 17:14:23 +01004823 ret = 0;
4824 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004825resume:
4826 ret = ath10k_wmi_pdev_resume_target(ar);
4827 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004828 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004829
4830 ret = 1;
4831exit:
4832 mutex_unlock(&ar->conf_mutex);
4833 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004834}
4835
4836static int ath10k_resume(struct ieee80211_hw *hw)
4837{
4838 struct ath10k *ar = hw->priv;
4839 int ret;
4840
Marek Puzyniak9042e172014-02-10 17:14:23 +01004841 mutex_lock(&ar->conf_mutex);
4842
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004843 ret = ath10k_hif_resume(ar);
4844 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004845 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004846 ret = 1;
4847 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004848 }
4849
4850 ret = ath10k_wmi_pdev_resume_target(ar);
4851 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004852 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004853 ret = 1;
4854 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004855 }
4856
Marek Puzyniak9042e172014-02-10 17:14:23 +01004857 ret = 0;
4858exit:
4859 mutex_unlock(&ar->conf_mutex);
4860 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004861}
4862#endif
4863
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004864static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4865 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004866{
4867 struct ath10k *ar = hw->priv;
4868
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004869 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4870 return;
4871
Michal Kazioraffd3212013-07-16 09:54:35 +02004872 mutex_lock(&ar->conf_mutex);
4873
4874 /* If device failed to restart it will be in a different state, e.g.
4875 * ATH10K_STATE_WEDGED */
4876 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004877 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004878 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004879 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004880 }
4881
4882 mutex_unlock(&ar->conf_mutex);
4883}
4884
Michal Kazior2e1dea42013-07-31 10:32:40 +02004885static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4886 struct survey_info *survey)
4887{
4888 struct ath10k *ar = hw->priv;
4889 struct ieee80211_supported_band *sband;
4890 struct survey_info *ar_survey = &ar->survey[idx];
4891 int ret = 0;
4892
4893 mutex_lock(&ar->conf_mutex);
4894
4895 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4896 if (sband && idx >= sband->n_channels) {
4897 idx -= sband->n_channels;
4898 sband = NULL;
4899 }
4900
4901 if (!sband)
4902 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4903
4904 if (!sband || idx >= sband->n_channels) {
4905 ret = -ENOENT;
4906 goto exit;
4907 }
4908
4909 spin_lock_bh(&ar->data_lock);
4910 memcpy(survey, ar_survey, sizeof(*survey));
4911 spin_unlock_bh(&ar->data_lock);
4912
4913 survey->channel = &sband->channels[idx];
4914
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004915 if (ar->rx_channel == survey->channel)
4916 survey->filled |= SURVEY_INFO_IN_USE;
4917
Michal Kazior2e1dea42013-07-31 10:32:40 +02004918exit:
4919 mutex_unlock(&ar->conf_mutex);
4920 return ret;
4921}
4922
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004923/* Helper table for legacy fixed_rate/bitrate_mask */
4924static const u8 cck_ofdm_rate[] = {
4925 /* CCK */
4926 3, /* 1Mbps */
4927 2, /* 2Mbps */
4928 1, /* 5.5Mbps */
4929 0, /* 11Mbps */
4930 /* OFDM */
4931 3, /* 6Mbps */
4932 7, /* 9Mbps */
4933 2, /* 12Mbps */
4934 6, /* 18Mbps */
4935 1, /* 24Mbps */
4936 5, /* 36Mbps */
4937 0, /* 48Mbps */
4938 4, /* 54Mbps */
4939};
4940
4941/* Check if only one bit set */
4942static int ath10k_check_single_mask(u32 mask)
4943{
4944 int bit;
4945
4946 bit = ffs(mask);
4947 if (!bit)
4948 return 0;
4949
4950 mask &= ~BIT(bit - 1);
4951 if (mask)
4952 return 2;
4953
4954 return 1;
4955}
4956
4957static bool
4958ath10k_default_bitrate_mask(struct ath10k *ar,
4959 enum ieee80211_band band,
4960 const struct cfg80211_bitrate_mask *mask)
4961{
4962 u32 legacy = 0x00ff;
4963 u8 ht = 0xff, i;
4964 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004965 u16 nrf = ar->num_rf_chains;
4966
4967 if (ar->cfg_tx_chainmask)
4968 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004969
4970 switch (band) {
4971 case IEEE80211_BAND_2GHZ:
4972 legacy = 0x00fff;
4973 vht = 0;
4974 break;
4975 case IEEE80211_BAND_5GHZ:
4976 break;
4977 default:
4978 return false;
4979 }
4980
4981 if (mask->control[band].legacy != legacy)
4982 return false;
4983
Ben Greearb116ea12014-11-24 16:22:10 +02004984 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004985 if (mask->control[band].ht_mcs[i] != ht)
4986 return false;
4987
Ben Greearb116ea12014-11-24 16:22:10 +02004988 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004989 if (mask->control[band].vht_mcs[i] != vht)
4990 return false;
4991
4992 return true;
4993}
4994
4995static bool
4996ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4997 enum ieee80211_band band,
4998 u8 *fixed_nss)
4999{
5000 int ht_nss = 0, vht_nss = 0, i;
5001
5002 /* check legacy */
5003 if (ath10k_check_single_mask(mask->control[band].legacy))
5004 return false;
5005
5006 /* check HT */
5007 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5008 if (mask->control[band].ht_mcs[i] == 0xff)
5009 continue;
5010 else if (mask->control[band].ht_mcs[i] == 0x00)
5011 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005012
5013 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005014 }
5015
5016 ht_nss = i;
5017
5018 /* check VHT */
5019 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5020 if (mask->control[band].vht_mcs[i] == 0x03ff)
5021 continue;
5022 else if (mask->control[band].vht_mcs[i] == 0x0000)
5023 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005024
5025 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005026 }
5027
5028 vht_nss = i;
5029
5030 if (ht_nss > 0 && vht_nss > 0)
5031 return false;
5032
5033 if (ht_nss)
5034 *fixed_nss = ht_nss;
5035 else if (vht_nss)
5036 *fixed_nss = vht_nss;
5037 else
5038 return false;
5039
5040 return true;
5041}
5042
5043static bool
5044ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5045 enum ieee80211_band band,
5046 enum wmi_rate_preamble *preamble)
5047{
5048 int legacy = 0, ht = 0, vht = 0, i;
5049
5050 *preamble = WMI_RATE_PREAMBLE_OFDM;
5051
5052 /* check legacy */
5053 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5054 if (legacy > 1)
5055 return false;
5056
5057 /* check HT */
5058 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5059 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5060 if (ht > 1)
5061 return false;
5062
5063 /* check VHT */
5064 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5065 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5066 if (vht > 1)
5067 return false;
5068
5069 /* Currently we support only one fixed_rate */
5070 if ((legacy + ht + vht) != 1)
5071 return false;
5072
5073 if (ht)
5074 *preamble = WMI_RATE_PREAMBLE_HT;
5075 else if (vht)
5076 *preamble = WMI_RATE_PREAMBLE_VHT;
5077
5078 return true;
5079}
5080
5081static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005082ath10k_bitrate_mask_rate(struct ath10k *ar,
5083 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005084 enum ieee80211_band band,
5085 u8 *fixed_rate,
5086 u8 *fixed_nss)
5087{
5088 u8 rate = 0, pream = 0, nss = 0, i;
5089 enum wmi_rate_preamble preamble;
5090
5091 /* Check if single rate correct */
5092 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5093 return false;
5094
5095 pream = preamble;
5096
5097 switch (preamble) {
5098 case WMI_RATE_PREAMBLE_CCK:
5099 case WMI_RATE_PREAMBLE_OFDM:
5100 i = ffs(mask->control[band].legacy) - 1;
5101
5102 if (band == IEEE80211_BAND_2GHZ && i < 4)
5103 pream = WMI_RATE_PREAMBLE_CCK;
5104
5105 if (band == IEEE80211_BAND_5GHZ)
5106 i += 4;
5107
5108 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5109 return false;
5110
5111 rate = cck_ofdm_rate[i];
5112 break;
5113 case WMI_RATE_PREAMBLE_HT:
5114 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5115 if (mask->control[band].ht_mcs[i])
5116 break;
5117
5118 if (i == IEEE80211_HT_MCS_MASK_LEN)
5119 return false;
5120
5121 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5122 nss = i;
5123 break;
5124 case WMI_RATE_PREAMBLE_VHT:
5125 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5126 if (mask->control[band].vht_mcs[i])
5127 break;
5128
5129 if (i == NL80211_VHT_NSS_MAX)
5130 return false;
5131
5132 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5133 nss = i;
5134 break;
5135 }
5136
5137 *fixed_nss = nss + 1;
5138 nss <<= 4;
5139 pream <<= 6;
5140
Michal Kazior7aa7a722014-08-25 12:09:38 +02005141 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 +01005142 pream, nss, rate);
5143
5144 *fixed_rate = pream | nss | rate;
5145
5146 return true;
5147}
5148
Michal Kazior7aa7a722014-08-25 12:09:38 +02005149static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5150 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005151 enum ieee80211_band band,
5152 u8 *fixed_rate,
5153 u8 *fixed_nss)
5154{
5155 /* First check full NSS mask, if we can simply limit NSS */
5156 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5157 return true;
5158
5159 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005160 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005161}
5162
5163static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5164 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005165 u8 fixed_nss,
5166 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005167{
5168 struct ath10k *ar = arvif->ar;
5169 u32 vdev_param;
5170 int ret = 0;
5171
5172 mutex_lock(&ar->conf_mutex);
5173
5174 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005175 arvif->fixed_nss == fixed_nss &&
5176 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005177 goto exit;
5178
5179 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005180 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005181
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005182 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005183 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005184
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005185 vdev_param = ar->wmi.vdev_param->fixed_rate;
5186 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5187 vdev_param, fixed_rate);
5188 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005189 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005190 fixed_rate, ret);
5191 ret = -EINVAL;
5192 goto exit;
5193 }
5194
5195 arvif->fixed_rate = fixed_rate;
5196
5197 vdev_param = ar->wmi.vdev_param->nss;
5198 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5199 vdev_param, fixed_nss);
5200
5201 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005202 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005203 fixed_nss, ret);
5204 ret = -EINVAL;
5205 goto exit;
5206 }
5207
5208 arvif->fixed_nss = fixed_nss;
5209
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005210 vdev_param = ar->wmi.vdev_param->sgi;
5211 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5212 force_sgi);
5213
5214 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005215 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005216 force_sgi, ret);
5217 ret = -EINVAL;
5218 goto exit;
5219 }
5220
5221 arvif->force_sgi = force_sgi;
5222
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005223exit:
5224 mutex_unlock(&ar->conf_mutex);
5225 return ret;
5226}
5227
5228static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5229 struct ieee80211_vif *vif,
5230 const struct cfg80211_bitrate_mask *mask)
5231{
5232 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5233 struct ath10k *ar = arvif->ar;
5234 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5235 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5236 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005237 u8 force_sgi;
5238
Ben Greearb116ea12014-11-24 16:22:10 +02005239 if (ar->cfg_tx_chainmask)
5240 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5241
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005242 force_sgi = mask->control[band].gi;
5243 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5244 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005245
5246 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005247 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005248 &fixed_rate,
5249 &fixed_nss))
5250 return -EINVAL;
5251 }
5252
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005253 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005254 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005255 return -EINVAL;
5256 }
5257
5258 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5259 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005260}
5261
Michal Kazior9797feb2014-02-14 14:49:48 +01005262static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5263 struct ieee80211_vif *vif,
5264 struct ieee80211_sta *sta,
5265 u32 changed)
5266{
5267 struct ath10k *ar = hw->priv;
5268 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5269 u32 bw, smps;
5270
5271 spin_lock_bh(&ar->data_lock);
5272
Michal Kazior7aa7a722014-08-25 12:09:38 +02005273 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005274 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5275 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5276 sta->smps_mode);
5277
5278 if (changed & IEEE80211_RC_BW_CHANGED) {
5279 bw = WMI_PEER_CHWIDTH_20MHZ;
5280
5281 switch (sta->bandwidth) {
5282 case IEEE80211_STA_RX_BW_20:
5283 bw = WMI_PEER_CHWIDTH_20MHZ;
5284 break;
5285 case IEEE80211_STA_RX_BW_40:
5286 bw = WMI_PEER_CHWIDTH_40MHZ;
5287 break;
5288 case IEEE80211_STA_RX_BW_80:
5289 bw = WMI_PEER_CHWIDTH_80MHZ;
5290 break;
5291 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005292 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005293 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005294 bw = WMI_PEER_CHWIDTH_20MHZ;
5295 break;
5296 }
5297
5298 arsta->bw = bw;
5299 }
5300
5301 if (changed & IEEE80211_RC_NSS_CHANGED)
5302 arsta->nss = sta->rx_nss;
5303
5304 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5305 smps = WMI_PEER_SMPS_PS_NONE;
5306
5307 switch (sta->smps_mode) {
5308 case IEEE80211_SMPS_AUTOMATIC:
5309 case IEEE80211_SMPS_OFF:
5310 smps = WMI_PEER_SMPS_PS_NONE;
5311 break;
5312 case IEEE80211_SMPS_STATIC:
5313 smps = WMI_PEER_SMPS_STATIC;
5314 break;
5315 case IEEE80211_SMPS_DYNAMIC:
5316 smps = WMI_PEER_SMPS_DYNAMIC;
5317 break;
5318 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005319 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005320 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005321 smps = WMI_PEER_SMPS_PS_NONE;
5322 break;
5323 }
5324
5325 arsta->smps = smps;
5326 }
5327
Michal Kazior9797feb2014-02-14 14:49:48 +01005328 arsta->changed |= changed;
5329
5330 spin_unlock_bh(&ar->data_lock);
5331
5332 ieee80211_queue_work(hw, &arsta->update_wk);
5333}
5334
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005335static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5336{
5337 /*
5338 * FIXME: Return 0 for time being. Need to figure out whether FW
5339 * has the API to fetch 64-bit local TSF
5340 */
5341
5342 return 0;
5343}
5344
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005345static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5346 struct ieee80211_vif *vif,
5347 enum ieee80211_ampdu_mlme_action action,
5348 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5349 u8 buf_size)
5350{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005351 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005352 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5353
Michal Kazior7aa7a722014-08-25 12:09:38 +02005354 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 +02005355 arvif->vdev_id, sta->addr, tid, action);
5356
5357 switch (action) {
5358 case IEEE80211_AMPDU_RX_START:
5359 case IEEE80211_AMPDU_RX_STOP:
5360 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5361 * creation/removal. Do we need to verify this?
5362 */
5363 return 0;
5364 case IEEE80211_AMPDU_TX_START:
5365 case IEEE80211_AMPDU_TX_STOP_CONT:
5366 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5367 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5368 case IEEE80211_AMPDU_TX_OPERATIONAL:
5369 /* Firmware offloads Tx aggregation entirely so deny mac80211
5370 * Tx aggregation requests.
5371 */
5372 return -EOPNOTSUPP;
5373 }
5374
5375 return -EINVAL;
5376}
5377
Kalle Valo5e3dd152013-06-12 20:52:10 +03005378static const struct ieee80211_ops ath10k_ops = {
5379 .tx = ath10k_tx,
5380 .start = ath10k_start,
5381 .stop = ath10k_stop,
5382 .config = ath10k_config,
5383 .add_interface = ath10k_add_interface,
5384 .remove_interface = ath10k_remove_interface,
5385 .configure_filter = ath10k_configure_filter,
5386 .bss_info_changed = ath10k_bss_info_changed,
5387 .hw_scan = ath10k_hw_scan,
5388 .cancel_hw_scan = ath10k_cancel_hw_scan,
5389 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005390 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391 .sta_state = ath10k_sta_state,
5392 .conf_tx = ath10k_conf_tx,
5393 .remain_on_channel = ath10k_remain_on_channel,
5394 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5395 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005396 .flush = ath10k_flush,
5397 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03005398 .set_antenna = ath10k_set_antenna,
5399 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005400 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005401 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005402 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005403 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005404 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005405 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005406 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5407 .get_et_stats = ath10k_debug_get_et_stats,
5408 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005409
5410 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5411
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005412#ifdef CONFIG_PM
5413 .suspend = ath10k_suspend,
5414 .resume = ath10k_resume,
5415#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005416#ifdef CONFIG_MAC80211_DEBUGFS
5417 .sta_add_debugfs = ath10k_sta_add_debugfs,
5418#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005419};
5420
5421#define RATETAB_ENT(_rate, _rateid, _flags) { \
5422 .bitrate = (_rate), \
5423 .flags = (_flags), \
5424 .hw_value = (_rateid), \
5425}
5426
5427#define CHAN2G(_channel, _freq, _flags) { \
5428 .band = IEEE80211_BAND_2GHZ, \
5429 .hw_value = (_channel), \
5430 .center_freq = (_freq), \
5431 .flags = (_flags), \
5432 .max_antenna_gain = 0, \
5433 .max_power = 30, \
5434}
5435
5436#define CHAN5G(_channel, _freq, _flags) { \
5437 .band = IEEE80211_BAND_5GHZ, \
5438 .hw_value = (_channel), \
5439 .center_freq = (_freq), \
5440 .flags = (_flags), \
5441 .max_antenna_gain = 0, \
5442 .max_power = 30, \
5443}
5444
5445static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5446 CHAN2G(1, 2412, 0),
5447 CHAN2G(2, 2417, 0),
5448 CHAN2G(3, 2422, 0),
5449 CHAN2G(4, 2427, 0),
5450 CHAN2G(5, 2432, 0),
5451 CHAN2G(6, 2437, 0),
5452 CHAN2G(7, 2442, 0),
5453 CHAN2G(8, 2447, 0),
5454 CHAN2G(9, 2452, 0),
5455 CHAN2G(10, 2457, 0),
5456 CHAN2G(11, 2462, 0),
5457 CHAN2G(12, 2467, 0),
5458 CHAN2G(13, 2472, 0),
5459 CHAN2G(14, 2484, 0),
5460};
5461
5462static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005463 CHAN5G(36, 5180, 0),
5464 CHAN5G(40, 5200, 0),
5465 CHAN5G(44, 5220, 0),
5466 CHAN5G(48, 5240, 0),
5467 CHAN5G(52, 5260, 0),
5468 CHAN5G(56, 5280, 0),
5469 CHAN5G(60, 5300, 0),
5470 CHAN5G(64, 5320, 0),
5471 CHAN5G(100, 5500, 0),
5472 CHAN5G(104, 5520, 0),
5473 CHAN5G(108, 5540, 0),
5474 CHAN5G(112, 5560, 0),
5475 CHAN5G(116, 5580, 0),
5476 CHAN5G(120, 5600, 0),
5477 CHAN5G(124, 5620, 0),
5478 CHAN5G(128, 5640, 0),
5479 CHAN5G(132, 5660, 0),
5480 CHAN5G(136, 5680, 0),
5481 CHAN5G(140, 5700, 0),
5482 CHAN5G(149, 5745, 0),
5483 CHAN5G(153, 5765, 0),
5484 CHAN5G(157, 5785, 0),
5485 CHAN5G(161, 5805, 0),
5486 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005487};
5488
Michal Kazior91b12082014-12-12 12:41:35 +01005489/* Note: Be careful if you re-order these. There is code which depends on this
5490 * ordering.
5491 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005492static struct ieee80211_rate ath10k_rates[] = {
5493 /* CCK */
5494 RATETAB_ENT(10, 0x82, 0),
5495 RATETAB_ENT(20, 0x84, 0),
5496 RATETAB_ENT(55, 0x8b, 0),
5497 RATETAB_ENT(110, 0x96, 0),
5498 /* OFDM */
5499 RATETAB_ENT(60, 0x0c, 0),
5500 RATETAB_ENT(90, 0x12, 0),
5501 RATETAB_ENT(120, 0x18, 0),
5502 RATETAB_ENT(180, 0x24, 0),
5503 RATETAB_ENT(240, 0x30, 0),
5504 RATETAB_ENT(360, 0x48, 0),
5505 RATETAB_ENT(480, 0x60, 0),
5506 RATETAB_ENT(540, 0x6c, 0),
5507};
5508
5509#define ath10k_a_rates (ath10k_rates + 4)
5510#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5511#define ath10k_g_rates (ath10k_rates + 0)
5512#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5513
Michal Kaziore7b54192014-08-07 11:03:27 +02005514struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005515{
5516 struct ieee80211_hw *hw;
5517 struct ath10k *ar;
5518
Michal Kaziore7b54192014-08-07 11:03:27 +02005519 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005520 if (!hw)
5521 return NULL;
5522
5523 ar = hw->priv;
5524 ar->hw = hw;
5525
5526 return ar;
5527}
5528
5529void ath10k_mac_destroy(struct ath10k *ar)
5530{
5531 ieee80211_free_hw(ar->hw);
5532}
5533
5534static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5535 {
5536 .max = 8,
5537 .types = BIT(NL80211_IFTYPE_STATION)
5538 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005539 },
5540 {
5541 .max = 3,
5542 .types = BIT(NL80211_IFTYPE_P2P_GO)
5543 },
5544 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005545 .max = 1,
5546 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5547 },
5548 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005549 .max = 7,
5550 .types = BIT(NL80211_IFTYPE_AP)
5551 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005552};
5553
Bartosz Markowskif2595092013-12-10 16:20:39 +01005554static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005555 {
5556 .max = 8,
5557 .types = BIT(NL80211_IFTYPE_AP)
5558 },
5559};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005560
5561static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5562 {
5563 .limits = ath10k_if_limits,
5564 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5565 .max_interfaces = 8,
5566 .num_different_channels = 1,
5567 .beacon_int_infra_match = true,
5568 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005569};
5570
5571static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005572 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005573 .limits = ath10k_10x_if_limits,
5574 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005575 .max_interfaces = 8,
5576 .num_different_channels = 1,
5577 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005578#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005579 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5580 BIT(NL80211_CHAN_WIDTH_20) |
5581 BIT(NL80211_CHAN_WIDTH_40) |
5582 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005583#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005584 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005585};
5586
5587static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5588{
5589 struct ieee80211_sta_vht_cap vht_cap = {0};
5590 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005591 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005592 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005593
5594 vht_cap.vht_supported = 1;
5595 vht_cap.cap = ar->vht_cap_info;
5596
Michal Kaziorbc657a362015-02-26 11:11:22 +01005597 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5598 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5599 val = ar->num_rf_chains - 1;
5600 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5601 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5602
5603 vht_cap.cap |= val;
5604 }
5605
5606 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5607 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5608 val = ar->num_rf_chains - 1;
5609 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5610 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5611
5612 vht_cap.cap |= val;
5613 }
5614
Michal Kazior8865bee42013-07-24 12:36:46 +02005615 mcs_map = 0;
5616 for (i = 0; i < 8; i++) {
5617 if (i < ar->num_rf_chains)
5618 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5619 else
5620 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005622
5623 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5624 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5625
5626 return vht_cap;
5627}
5628
5629static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5630{
5631 int i;
5632 struct ieee80211_sta_ht_cap ht_cap = {0};
5633
5634 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5635 return ht_cap;
5636
5637 ht_cap.ht_supported = 1;
5638 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5639 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5640 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5641 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5642 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5643
5644 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5645 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5646
5647 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5648 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5649
5650 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5651 u32 smps;
5652
5653 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5654 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5655
5656 ht_cap.cap |= smps;
5657 }
5658
5659 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5660 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5661
5662 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5663 u32 stbc;
5664
5665 stbc = ar->ht_cap_info;
5666 stbc &= WMI_HT_CAP_RX_STBC;
5667 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5668 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5669 stbc &= IEEE80211_HT_CAP_RX_STBC;
5670
5671 ht_cap.cap |= stbc;
5672 }
5673
5674 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5675 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5676
5677 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5678 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5679
5680 /* max AMSDU is implicitly taken from vht_cap_info */
5681 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5682 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5683
Michal Kazior8865bee42013-07-24 12:36:46 +02005684 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005685 ht_cap.mcs.rx_mask[i] = 0xFF;
5686
5687 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5688
5689 return ht_cap;
5690}
5691
Kalle Valo5e3dd152013-06-12 20:52:10 +03005692static void ath10k_get_arvif_iter(void *data, u8 *mac,
5693 struct ieee80211_vif *vif)
5694{
5695 struct ath10k_vif_iter *arvif_iter = data;
5696 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5697
5698 if (arvif->vdev_id == arvif_iter->vdev_id)
5699 arvif_iter->arvif = arvif;
5700}
5701
5702struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5703{
5704 struct ath10k_vif_iter arvif_iter;
5705 u32 flags;
5706
5707 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5708 arvif_iter.vdev_id = vdev_id;
5709
5710 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5711 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5712 flags,
5713 ath10k_get_arvif_iter,
5714 &arvif_iter);
5715 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005716 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005717 return NULL;
5718 }
5719
5720 return arvif_iter.arvif;
5721}
5722
5723int ath10k_mac_register(struct ath10k *ar)
5724{
Johannes Berg3cb10942015-01-22 21:38:45 +01005725 static const u32 cipher_suites[] = {
5726 WLAN_CIPHER_SUITE_WEP40,
5727 WLAN_CIPHER_SUITE_WEP104,
5728 WLAN_CIPHER_SUITE_TKIP,
5729 WLAN_CIPHER_SUITE_CCMP,
5730 WLAN_CIPHER_SUITE_AES_CMAC,
5731 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005732 struct ieee80211_supported_band *band;
5733 struct ieee80211_sta_vht_cap vht_cap;
5734 struct ieee80211_sta_ht_cap ht_cap;
5735 void *channels;
5736 int ret;
5737
5738 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5739
5740 SET_IEEE80211_DEV(ar->hw, ar->dev);
5741
5742 ht_cap = ath10k_get_ht_cap(ar);
5743 vht_cap = ath10k_create_vht_cap(ar);
5744
5745 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5746 channels = kmemdup(ath10k_2ghz_channels,
5747 sizeof(ath10k_2ghz_channels),
5748 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005749 if (!channels) {
5750 ret = -ENOMEM;
5751 goto err_free;
5752 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005753
5754 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5755 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5756 band->channels = channels;
5757 band->n_bitrates = ath10k_g_rates_size;
5758 band->bitrates = ath10k_g_rates;
5759 band->ht_cap = ht_cap;
5760
Yanbo Lid68bb122015-01-23 08:18:20 +08005761 /* Enable the VHT support at 2.4 GHz */
5762 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005763
5764 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5765 }
5766
5767 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5768 channels = kmemdup(ath10k_5ghz_channels,
5769 sizeof(ath10k_5ghz_channels),
5770 GFP_KERNEL);
5771 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005772 ret = -ENOMEM;
5773 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005774 }
5775
5776 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5777 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5778 band->channels = channels;
5779 band->n_bitrates = ath10k_a_rates_size;
5780 band->bitrates = ath10k_a_rates;
5781 band->ht_cap = ht_cap;
5782 band->vht_cap = vht_cap;
5783 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5784 }
5785
5786 ar->hw->wiphy->interface_modes =
5787 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005788 BIT(NL80211_IFTYPE_AP);
5789
Ben Greear46acf7bb2014-05-16 17:15:38 +03005790 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5791 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5792
Bartosz Markowskid3541812013-12-10 16:20:40 +01005793 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5794 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005795 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005796 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5797 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005798
5799 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5800 IEEE80211_HW_SUPPORTS_PS |
5801 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005802 IEEE80211_HW_MFP_CAPABLE |
5803 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5804 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005805 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005806 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005807 IEEE80211_HW_SW_CRYPTO_CONTROL |
5808 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005809
Eliad Peller0d8614b2014-09-10 14:07:36 +03005810 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5811
Kalle Valo5e3dd152013-06-12 20:52:10 +03005812 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005813 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005814
5815 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5816 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5817 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5818 }
5819
5820 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5821 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5822
5823 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005824 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005825
Kalle Valo5e3dd152013-06-12 20:52:10 +03005826 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5827
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005828 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5829 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5830
5831 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5832 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5833 * correct Probe Responses. This is more of a hack advert..
5834 */
5835 ar->hw->wiphy->probe_resp_offload |=
5836 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5837 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5838 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5839 }
5840
Kalle Valo5e3dd152013-06-12 20:52:10 +03005841 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005842 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005843 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5844
5845 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005846 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5847
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005848 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5849
Kalle Valo5e3dd152013-06-12 20:52:10 +03005850 /*
5851 * on LL hardware queues are managed entirely by the FW
5852 * so we only advertise to mac we can do the queues thing
5853 */
5854 ar->hw->queues = 4;
5855
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005856 switch (ar->wmi.op_version) {
5857 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5858 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005859 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5860 ar->hw->wiphy->n_iface_combinations =
5861 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005862 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005863 break;
5864 case ATH10K_FW_WMI_OP_VERSION_10_1:
5865 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005866 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005867 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5868 ar->hw->wiphy->n_iface_combinations =
5869 ARRAY_SIZE(ath10k_10x_if_comb);
5870 break;
5871 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5872 case ATH10K_FW_WMI_OP_VERSION_MAX:
5873 WARN_ON(1);
5874 ret = -EINVAL;
5875 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005876 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005877
Michal Kazior7c199992013-07-31 10:47:57 +02005878 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5879
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005880 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5881 /* Init ath dfs pattern detector */
5882 ar->ath_common.debug_mask = ATH_DBG_DFS;
5883 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5884 NL80211_DFS_UNSET);
5885
5886 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005887 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005888 }
5889
Kalle Valo5e3dd152013-06-12 20:52:10 +03005890 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5891 ath10k_reg_notifier);
5892 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005893 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005894 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005895 }
5896
Johannes Berg3cb10942015-01-22 21:38:45 +01005897 ar->hw->wiphy->cipher_suites = cipher_suites;
5898 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5899
Kalle Valo5e3dd152013-06-12 20:52:10 +03005900 ret = ieee80211_register_hw(ar->hw);
5901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005902 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005903 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005904 }
5905
5906 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5907 ret = regulatory_hint(ar->hw->wiphy,
5908 ar->ath_common.regulatory.alpha2);
5909 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005910 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005911 }
5912
5913 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005914
5915err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005916 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005917err_free:
5918 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5919 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5920
Kalle Valo5e3dd152013-06-12 20:52:10 +03005921 return ret;
5922}
5923
5924void ath10k_mac_unregister(struct ath10k *ar)
5925{
5926 ieee80211_unregister_hw(ar->hw);
5927
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005928 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5929 ar->dfs_detector->exit(ar->dfs_detector);
5930
Kalle Valo5e3dd152013-06-12 20:52:10 +03005931 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5932 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5933
5934 SET_IEEE80211_DEV(ar->hw, NULL);
5935}