blob: 341f3c8d8bf2f340b775bfbf1d7cdb264818b29a [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
2538 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2539 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2540 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2541 * it is safe to downgrade to NullFunc.
2542 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002543 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002544 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2545 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2546 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2547 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002548}
2549
Michal Kazior4b604552014-07-21 21:03:09 +03002550static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2551 struct ieee80211_vif *vif,
2552 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002553{
2554 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2556
2557 /* This is case only for P2P_GO */
2558 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2559 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2560 return;
2561
2562 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2563 spin_lock_bh(&ar->data_lock);
2564 if (arvif->u.ap.noa_data)
2565 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2566 GFP_ATOMIC))
2567 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2568 arvif->u.ap.noa_data,
2569 arvif->u.ap.noa_len);
2570 spin_unlock_bh(&ar->data_lock);
2571 }
2572}
2573
Michal Kazior8d6d3622014-11-24 14:58:31 +01002574static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2575{
2576 /* FIXME: Not really sure since when the behaviour changed. At some
2577 * point new firmware stopped requiring creation of peer entries for
2578 * offchannel tx (and actually creating them causes issues with wmi-htc
2579 * tx credit replenishment and reliability). Assuming it's at least 3.4
2580 * because that's when the `freq` was introduced to TX_FRM HTT command.
2581 */
2582 return !(ar->htt.target_version_major >= 3 &&
2583 ar->htt.target_version_minor >= 4);
2584}
2585
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2587{
2588 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002589 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590
Michal Kazior961d4c32013-08-09 10:13:34 +02002591 if (ar->htt.target_version_major >= 3) {
2592 /* Since HTT 3.0 there is no separate mgmt tx command */
2593 ret = ath10k_htt_tx(&ar->htt, skb);
2594 goto exit;
2595 }
2596
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002597 if (ieee80211_is_mgmt(hdr->frame_control)) {
2598 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2599 ar->fw_features)) {
2600 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2601 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002602 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002603 ret = -EBUSY;
2604 goto exit;
2605 }
2606
2607 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2608 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2609 } else {
2610 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2611 }
2612 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2613 ar->fw_features) &&
2614 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002615 /* FW does not report tx status properly for NullFunc frames
2616 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002617 * those frames when it detects link/beacon loss and depends
2618 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002619 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002620 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002621 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002622 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002623
Michal Kazior961d4c32013-08-09 10:13:34 +02002624exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002625 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002626 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2627 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002628 ieee80211_free_txskb(ar->hw, skb);
2629 }
2630}
2631
2632void ath10k_offchan_tx_purge(struct ath10k *ar)
2633{
2634 struct sk_buff *skb;
2635
2636 for (;;) {
2637 skb = skb_dequeue(&ar->offchan_tx_queue);
2638 if (!skb)
2639 break;
2640
2641 ieee80211_free_txskb(ar->hw, skb);
2642 }
2643}
2644
2645void ath10k_offchan_tx_work(struct work_struct *work)
2646{
2647 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2648 struct ath10k_peer *peer;
2649 struct ieee80211_hdr *hdr;
2650 struct sk_buff *skb;
2651 const u8 *peer_addr;
2652 int vdev_id;
2653 int ret;
2654
2655 /* FW requirement: We must create a peer before FW will send out
2656 * an offchannel frame. Otherwise the frame will be stuck and
2657 * never transmitted. We delete the peer upon tx completion.
2658 * It is unlikely that a peer for offchannel tx will already be
2659 * present. However it may be in some rare cases so account for that.
2660 * Otherwise we might remove a legitimate peer and break stuff. */
2661
2662 for (;;) {
2663 skb = skb_dequeue(&ar->offchan_tx_queue);
2664 if (!skb)
2665 break;
2666
2667 mutex_lock(&ar->conf_mutex);
2668
Michal Kazior7aa7a722014-08-25 12:09:38 +02002669 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002670 skb);
2671
2672 hdr = (struct ieee80211_hdr *)skb->data;
2673 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002674 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002675
2676 spin_lock_bh(&ar->data_lock);
2677 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2678 spin_unlock_bh(&ar->data_lock);
2679
2680 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002681 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002682 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683 peer_addr, vdev_id);
2684
2685 if (!peer) {
2686 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2687 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002688 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002689 peer_addr, vdev_id, ret);
2690 }
2691
2692 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002693 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002694 ar->offchan_tx_skb = skb;
2695 spin_unlock_bh(&ar->data_lock);
2696
2697 ath10k_tx_htt(ar, skb);
2698
2699 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2700 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002701 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002702 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002703 skb);
2704
2705 if (!peer) {
2706 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2707 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002708 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002709 peer_addr, vdev_id, ret);
2710 }
2711
2712 mutex_unlock(&ar->conf_mutex);
2713 }
2714}
2715
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002716void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2717{
2718 struct sk_buff *skb;
2719
2720 for (;;) {
2721 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2722 if (!skb)
2723 break;
2724
2725 ieee80211_free_txskb(ar->hw, skb);
2726 }
2727}
2728
2729void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2730{
2731 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2732 struct sk_buff *skb;
2733 int ret;
2734
2735 for (;;) {
2736 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2737 if (!skb)
2738 break;
2739
2740 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002742 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002743 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002744 ieee80211_free_txskb(ar->hw, skb);
2745 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002746 }
2747}
2748
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749/************/
2750/* Scanning */
2751/************/
2752
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002753void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002755 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002756
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002757 switch (ar->scan.state) {
2758 case ATH10K_SCAN_IDLE:
2759 break;
2760 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002761 if (ar->scan.is_roc)
2762 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002763 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002764 case ATH10K_SCAN_ABORTING:
2765 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002766 ieee80211_scan_completed(ar->hw,
2767 (ar->scan.state ==
2768 ATH10K_SCAN_ABORTING));
2769 /* fall through */
2770 case ATH10K_SCAN_STARTING:
2771 ar->scan.state = ATH10K_SCAN_IDLE;
2772 ar->scan_channel = NULL;
2773 ath10k_offchan_tx_purge(ar);
2774 cancel_delayed_work(&ar->scan.timeout);
2775 complete_all(&ar->scan.completed);
2776 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002777 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002778}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002780void ath10k_scan_finish(struct ath10k *ar)
2781{
2782 spin_lock_bh(&ar->data_lock);
2783 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002784 spin_unlock_bh(&ar->data_lock);
2785}
2786
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002787static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002788{
2789 struct wmi_stop_scan_arg arg = {
2790 .req_id = 1, /* FIXME */
2791 .req_type = WMI_SCAN_STOP_ONE,
2792 .u.scan_id = ATH10K_SCAN_ID,
2793 };
2794 int ret;
2795
2796 lockdep_assert_held(&ar->conf_mutex);
2797
Kalle Valo5e3dd152013-06-12 20:52:10 +03002798 ret = ath10k_wmi_stop_scan(ar, &arg);
2799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002800 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002801 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802 }
2803
Kalle Valo5e3dd152013-06-12 20:52:10 +03002804 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002805 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002806 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002808 } else if (ret > 0) {
2809 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002810 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002811
2812out:
2813 /* Scan state should be updated upon scan completion but in case
2814 * firmware fails to deliver the event (for whatever reason) it is
2815 * desired to clean up scan state anyway. Firmware may have just
2816 * dropped the scan completion event delivery due to transport pipe
2817 * being overflown with data and/or it can recover on its own before
2818 * next scan request is submitted.
2819 */
2820 spin_lock_bh(&ar->data_lock);
2821 if (ar->scan.state != ATH10K_SCAN_IDLE)
2822 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002823 spin_unlock_bh(&ar->data_lock);
2824
2825 return ret;
2826}
2827
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002828static void ath10k_scan_abort(struct ath10k *ar)
2829{
2830 int ret;
2831
2832 lockdep_assert_held(&ar->conf_mutex);
2833
2834 spin_lock_bh(&ar->data_lock);
2835
2836 switch (ar->scan.state) {
2837 case ATH10K_SCAN_IDLE:
2838 /* This can happen if timeout worker kicked in and called
2839 * abortion while scan completion was being processed.
2840 */
2841 break;
2842 case ATH10K_SCAN_STARTING:
2843 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002844 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002845 ath10k_scan_state_str(ar->scan.state),
2846 ar->scan.state);
2847 break;
2848 case ATH10K_SCAN_RUNNING:
2849 ar->scan.state = ATH10K_SCAN_ABORTING;
2850 spin_unlock_bh(&ar->data_lock);
2851
2852 ret = ath10k_scan_stop(ar);
2853 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002854 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002855
2856 spin_lock_bh(&ar->data_lock);
2857 break;
2858 }
2859
2860 spin_unlock_bh(&ar->data_lock);
2861}
2862
2863void ath10k_scan_timeout_work(struct work_struct *work)
2864{
2865 struct ath10k *ar = container_of(work, struct ath10k,
2866 scan.timeout.work);
2867
2868 mutex_lock(&ar->conf_mutex);
2869 ath10k_scan_abort(ar);
2870 mutex_unlock(&ar->conf_mutex);
2871}
2872
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873static int ath10k_start_scan(struct ath10k *ar,
2874 const struct wmi_start_scan_arg *arg)
2875{
2876 int ret;
2877
2878 lockdep_assert_held(&ar->conf_mutex);
2879
2880 ret = ath10k_wmi_start_scan(ar, arg);
2881 if (ret)
2882 return ret;
2883
Kalle Valo5e3dd152013-06-12 20:52:10 +03002884 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2885 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002886 ret = ath10k_scan_stop(ar);
2887 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002888 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002889
2890 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002891 }
2892
Ben Greear2f9eec02015-02-15 16:50:38 +02002893 /* If we failed to start the scan, return error code at
2894 * this point. This is probably due to some issue in the
2895 * firmware, but no need to wedge the driver due to that...
2896 */
2897 spin_lock_bh(&ar->data_lock);
2898 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2899 spin_unlock_bh(&ar->data_lock);
2900 return -EINVAL;
2901 }
2902 spin_unlock_bh(&ar->data_lock);
2903
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002904 /* Add a 200ms margin to account for event/command processing */
2905 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2906 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907 return 0;
2908}
2909
2910/**********************/
2911/* mac80211 callbacks */
2912/**********************/
2913
2914static void ath10k_tx(struct ieee80211_hw *hw,
2915 struct ieee80211_tx_control *control,
2916 struct sk_buff *skb)
2917{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002919 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2920 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002921 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002922
2923 /* We should disable CCK RATE due to P2P */
2924 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002925 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002926
Michal Kazior4b604552014-07-21 21:03:09 +03002927 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2928 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002929 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002931 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002932 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2933 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002934 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2935 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002936 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002937
Kalle Valo5e3dd152013-06-12 20:52:10 +03002938 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2939 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002940 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002941 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942 spin_unlock_bh(&ar->data_lock);
2943
Michal Kazior8d6d3622014-11-24 14:58:31 +01002944 if (ath10k_mac_need_offchan_tx_work(ar)) {
2945 ATH10K_SKB_CB(skb)->htt.freq = 0;
2946 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002947
Michal Kazior8d6d3622014-11-24 14:58:31 +01002948 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2949 skb);
2950
2951 skb_queue_tail(&ar->offchan_tx_queue, skb);
2952 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2953 return;
2954 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955 }
2956
2957 ath10k_tx_htt(ar, skb);
2958}
2959
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002960/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002961void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002962{
2963 /* make sure rcu-protected mac80211 tx path itself is drained */
2964 synchronize_net();
2965
2966 ath10k_offchan_tx_purge(ar);
2967 ath10k_mgmt_over_wmi_tx_purge(ar);
2968
2969 cancel_work_sync(&ar->offchan_tx_work);
2970 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2971}
2972
Michal Kazioraffd3212013-07-16 09:54:35 +02002973void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002974{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002975 struct ath10k_vif *arvif;
2976
Michal Kazior818bdd12013-07-16 09:38:57 +02002977 lockdep_assert_held(&ar->conf_mutex);
2978
Michal Kazior19337472014-08-28 12:58:16 +02002979 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2980 ar->filter_flags = 0;
2981 ar->monitor = false;
2982
2983 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002984 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002985
2986 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002987
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002988 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002989 ath10k_peer_cleanup_all(ar);
2990 ath10k_core_stop(ar);
2991 ath10k_hif_power_down(ar);
2992
2993 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002994 list_for_each_entry(arvif, &ar->arvifs, list)
2995 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002996 spin_unlock_bh(&ar->data_lock);
2997}
2998
Ben Greear46acf7b2014-05-16 17:15:38 +03002999static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3000{
3001 struct ath10k *ar = hw->priv;
3002
3003 mutex_lock(&ar->conf_mutex);
3004
3005 if (ar->cfg_tx_chainmask) {
3006 *tx_ant = ar->cfg_tx_chainmask;
3007 *rx_ant = ar->cfg_rx_chainmask;
3008 } else {
3009 *tx_ant = ar->supp_tx_chainmask;
3010 *rx_ant = ar->supp_rx_chainmask;
3011 }
3012
3013 mutex_unlock(&ar->conf_mutex);
3014
3015 return 0;
3016}
3017
Ben Greear5572a952014-11-24 16:22:10 +02003018static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3019{
3020 /* It is not clear that allowing gaps in chainmask
3021 * is helpful. Probably it will not do what user
3022 * is hoping for, so warn in that case.
3023 */
3024 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3025 return;
3026
3027 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3028 dbg, cm);
3029}
3030
Ben Greear46acf7b2014-05-16 17:15:38 +03003031static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3032{
3033 int ret;
3034
3035 lockdep_assert_held(&ar->conf_mutex);
3036
Ben Greear5572a952014-11-24 16:22:10 +02003037 ath10k_check_chain_mask(ar, tx_ant, "tx");
3038 ath10k_check_chain_mask(ar, rx_ant, "rx");
3039
Ben Greear46acf7b2014-05-16 17:15:38 +03003040 ar->cfg_tx_chainmask = tx_ant;
3041 ar->cfg_rx_chainmask = rx_ant;
3042
3043 if ((ar->state != ATH10K_STATE_ON) &&
3044 (ar->state != ATH10K_STATE_RESTARTED))
3045 return 0;
3046
3047 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3048 tx_ant);
3049 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003050 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003051 ret, tx_ant);
3052 return ret;
3053 }
3054
3055 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3056 rx_ant);
3057 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003059 ret, rx_ant);
3060 return ret;
3061 }
3062
3063 return 0;
3064}
3065
3066static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3067{
3068 struct ath10k *ar = hw->priv;
3069 int ret;
3070
3071 mutex_lock(&ar->conf_mutex);
3072 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3073 mutex_unlock(&ar->conf_mutex);
3074 return ret;
3075}
3076
Kalle Valo5e3dd152013-06-12 20:52:10 +03003077static int ath10k_start(struct ieee80211_hw *hw)
3078{
3079 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003080 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003082 /*
3083 * This makes sense only when restarting hw. It is harmless to call
3084 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3085 * commands will be submitted while restarting.
3086 */
3087 ath10k_drain_tx(ar);
3088
Michal Kazior548db542013-07-05 16:15:15 +03003089 mutex_lock(&ar->conf_mutex);
3090
Michal Kaziorc5058f52014-05-26 12:46:03 +03003091 switch (ar->state) {
3092 case ATH10K_STATE_OFF:
3093 ar->state = ATH10K_STATE_ON;
3094 break;
3095 case ATH10K_STATE_RESTARTING:
3096 ath10k_halt(ar);
3097 ar->state = ATH10K_STATE_RESTARTED;
3098 break;
3099 case ATH10K_STATE_ON:
3100 case ATH10K_STATE_RESTARTED:
3101 case ATH10K_STATE_WEDGED:
3102 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003103 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003104 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003105 case ATH10K_STATE_UTF:
3106 ret = -EBUSY;
3107 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003108 }
3109
3110 ret = ath10k_hif_power_up(ar);
3111 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003112 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003113 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003114 }
3115
Kalle Valo43d2a302014-09-10 18:23:30 +03003116 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003117 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003118 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003119 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003120 }
3121
Bartosz Markowski226a3392013-09-26 17:47:16 +02003122 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003123 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003124 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003125 goto err_core_stop;
3126 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003127
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003128 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003129 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003130 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003131 goto err_core_stop;
3132 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003133
Ben Greear46acf7b2014-05-16 17:15:38 +03003134 if (ar->cfg_tx_chainmask)
3135 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3136 ar->cfg_rx_chainmask);
3137
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003138 /*
3139 * By default FW set ARP frames ac to voice (6). In that case ARP
3140 * exchange is not working properly for UAPSD enabled AP. ARP requests
3141 * which arrives with access category 0 are processed by network stack
3142 * and send back with access category 0, but FW changes access category
3143 * to 6. Set ARP frames access category to best effort (0) solves
3144 * this problem.
3145 */
3146
3147 ret = ath10k_wmi_pdev_set_param(ar,
3148 ar->wmi.pdev_param->arp_ac_override, 0);
3149 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003150 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003151 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003152 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003153 }
3154
Michal Kaziord6500972014-04-08 09:56:09 +03003155 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003156 ath10k_regd_update(ar);
3157
Simon Wunderlich855aed12014-08-02 09:12:54 +03003158 ath10k_spectral_start(ar);
3159
Michal Kaziorae254432014-05-26 12:46:02 +03003160 mutex_unlock(&ar->conf_mutex);
3161 return 0;
3162
3163err_core_stop:
3164 ath10k_core_stop(ar);
3165
3166err_power_down:
3167 ath10k_hif_power_down(ar);
3168
3169err_off:
3170 ar->state = ATH10K_STATE_OFF;
3171
3172err:
Michal Kazior548db542013-07-05 16:15:15 +03003173 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003174 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003175}
3176
3177static void ath10k_stop(struct ieee80211_hw *hw)
3178{
3179 struct ath10k *ar = hw->priv;
3180
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003181 ath10k_drain_tx(ar);
3182
Michal Kazior548db542013-07-05 16:15:15 +03003183 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003184 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003185 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003186 ar->state = ATH10K_STATE_OFF;
3187 }
Michal Kazior548db542013-07-05 16:15:15 +03003188 mutex_unlock(&ar->conf_mutex);
3189
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003190 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003191 cancel_work_sync(&ar->restart_work);
3192}
3193
Michal Kaziorad088bf2013-10-16 15:44:46 +03003194static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003195{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003196 struct ath10k_vif *arvif;
3197 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003198
3199 lockdep_assert_held(&ar->conf_mutex);
3200
Michal Kaziorad088bf2013-10-16 15:44:46 +03003201 list_for_each_entry(arvif, &ar->arvifs, list) {
3202 ret = ath10k_mac_vif_setup_ps(arvif);
3203 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003204 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003205 break;
3206 }
3207 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003208
Michal Kaziorad088bf2013-10-16 15:44:46 +03003209 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210}
3211
Michal Kaziorc930f742014-01-23 11:38:25 +01003212static const char *chandef_get_width(enum nl80211_chan_width width)
3213{
3214 switch (width) {
3215 case NL80211_CHAN_WIDTH_20_NOHT:
3216 return "20 (noht)";
3217 case NL80211_CHAN_WIDTH_20:
3218 return "20";
3219 case NL80211_CHAN_WIDTH_40:
3220 return "40";
3221 case NL80211_CHAN_WIDTH_80:
3222 return "80";
3223 case NL80211_CHAN_WIDTH_80P80:
3224 return "80+80";
3225 case NL80211_CHAN_WIDTH_160:
3226 return "160";
3227 case NL80211_CHAN_WIDTH_5:
3228 return "5";
3229 case NL80211_CHAN_WIDTH_10:
3230 return "10";
3231 }
3232 return "?";
3233}
3234
3235static void ath10k_config_chan(struct ath10k *ar)
3236{
3237 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003238 int ret;
3239
3240 lockdep_assert_held(&ar->conf_mutex);
3241
Michal Kazior7aa7a722014-08-25 12:09:38 +02003242 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003243 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3244 ar->chandef.chan->center_freq,
3245 ar->chandef.center_freq1,
3246 ar->chandef.center_freq2,
3247 chandef_get_width(ar->chandef.width));
3248
3249 /* First stop monitor interface. Some FW versions crash if there's a
3250 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003251 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003252 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003253
3254 list_for_each_entry(arvif, &ar->arvifs, list) {
3255 if (!arvif->is_started)
3256 continue;
3257
Michal Kaziordc55e302014-07-29 12:53:36 +03003258 if (!arvif->is_up)
3259 continue;
3260
Michal Kaziorc930f742014-01-23 11:38:25 +01003261 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3262 continue;
3263
Michal Kaziordc55e302014-07-29 12:53:36 +03003264 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003265 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003266 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003267 arvif->vdev_id, ret);
3268 continue;
3269 }
3270 }
3271
Michal Kaziordc55e302014-07-29 12:53:36 +03003272 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003273
3274 list_for_each_entry(arvif, &ar->arvifs, list) {
3275 if (!arvif->is_started)
3276 continue;
3277
3278 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3279 continue;
3280
Michal Kazior81a9a172015-03-05 16:02:17 +02003281 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3282 if (ret)
3283 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3284 ret);
3285
3286 ret = ath10k_mac_setup_prb_tmpl(arvif);
3287 if (ret)
3288 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3289 ret);
3290
Michal Kaziordc55e302014-07-29 12:53:36 +03003291 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003292 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003293 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003294 arvif->vdev_id, ret);
3295 continue;
3296 }
3297
3298 if (!arvif->is_up)
3299 continue;
3300
3301 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3302 arvif->bssid);
3303 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003304 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003305 arvif->vdev_id, ret);
3306 continue;
3307 }
3308 }
3309
Michal Kazior19337472014-08-28 12:58:16 +02003310 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003311}
3312
Michal Kazior7d9d5582014-10-21 10:40:15 +03003313static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3314{
3315 int ret;
3316 u32 param;
3317
3318 lockdep_assert_held(&ar->conf_mutex);
3319
3320 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3321
3322 param = ar->wmi.pdev_param->txpower_limit2g;
3323 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3324 if (ret) {
3325 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3326 txpower, ret);
3327 return ret;
3328 }
3329
3330 param = ar->wmi.pdev_param->txpower_limit5g;
3331 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3332 if (ret) {
3333 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3334 txpower, ret);
3335 return ret;
3336 }
3337
3338 return 0;
3339}
3340
3341static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3342{
3343 struct ath10k_vif *arvif;
3344 int ret, txpower = -1;
3345
3346 lockdep_assert_held(&ar->conf_mutex);
3347
3348 list_for_each_entry(arvif, &ar->arvifs, list) {
3349 WARN_ON(arvif->txpower < 0);
3350
3351 if (txpower == -1)
3352 txpower = arvif->txpower;
3353 else
3354 txpower = min(txpower, arvif->txpower);
3355 }
3356
3357 if (WARN_ON(txpower == -1))
3358 return -EINVAL;
3359
3360 ret = ath10k_mac_txpower_setup(ar, txpower);
3361 if (ret) {
3362 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3363 txpower, ret);
3364 return ret;
3365 }
3366
3367 return 0;
3368}
3369
Kalle Valo5e3dd152013-06-12 20:52:10 +03003370static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3371{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372 struct ath10k *ar = hw->priv;
3373 struct ieee80211_conf *conf = &hw->conf;
3374 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003375
3376 mutex_lock(&ar->conf_mutex);
3377
3378 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003379 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003380 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003381 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003382 conf->chandef.chan->flags,
3383 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003384
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 spin_lock_bh(&ar->data_lock);
3386 ar->rx_channel = conf->chandef.chan;
3387 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003388
Michal Kaziord6500972014-04-08 09:56:09 +03003389 ar->radar_enabled = conf->radar_enabled;
3390 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003391
3392 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3393 ar->chandef = conf->chandef;
3394 ath10k_config_chan(ar);
3395 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396 }
3397
Michal Kazioraffd3212013-07-16 09:54:35 +02003398 if (changed & IEEE80211_CONF_CHANGE_PS)
3399 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400
3401 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003402 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3403 ret = ath10k_monitor_recalc(ar);
3404 if (ret)
3405 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003406 }
3407
3408 mutex_unlock(&ar->conf_mutex);
3409 return ret;
3410}
3411
Ben Greear5572a952014-11-24 16:22:10 +02003412static u32 get_nss_from_chainmask(u16 chain_mask)
3413{
3414 if ((chain_mask & 0x15) == 0x15)
3415 return 4;
3416 else if ((chain_mask & 0x7) == 0x7)
3417 return 3;
3418 else if ((chain_mask & 0x3) == 0x3)
3419 return 2;
3420 return 1;
3421}
3422
Kalle Valo5e3dd152013-06-12 20:52:10 +03003423/*
3424 * TODO:
3425 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3426 * because we will send mgmt frames without CCK. This requirement
3427 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3428 * in the TX packet.
3429 */
3430static int ath10k_add_interface(struct ieee80211_hw *hw,
3431 struct ieee80211_vif *vif)
3432{
3433 struct ath10k *ar = hw->priv;
3434 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3435 enum wmi_sta_powersave_param param;
3436 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003437 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003438 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003439 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003440
Johannes Berg848955c2014-11-11 12:48:42 +01003441 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3442
Kalle Valo5e3dd152013-06-12 20:52:10 +03003443 mutex_lock(&ar->conf_mutex);
3444
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003445 memset(arvif, 0, sizeof(*arvif));
3446
Kalle Valo5e3dd152013-06-12 20:52:10 +03003447 arvif->ar = ar;
3448 arvif->vif = vif;
3449
Ben Greeare63b33f2013-10-22 14:54:14 -07003450 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003451 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003452 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3453 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003454
Ben Greeara9aefb32014-08-12 11:02:19 +03003455 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003456 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003457 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003458 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003459 }
Ben Greear16c11172014-09-23 14:17:16 -07003460 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003461
Ben Greear16c11172014-09-23 14:17:16 -07003462 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3463 bit, ar->free_vdev_map);
3464
3465 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467
Kalle Valo5e3dd152013-06-12 20:52:10 +03003468 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003469 case NL80211_IFTYPE_P2P_DEVICE:
3470 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3471 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3472 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473 case NL80211_IFTYPE_UNSPECIFIED:
3474 case NL80211_IFTYPE_STATION:
3475 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3476 if (vif->p2p)
3477 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3478 break;
3479 case NL80211_IFTYPE_ADHOC:
3480 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3481 break;
3482 case NL80211_IFTYPE_AP:
3483 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3484
3485 if (vif->p2p)
3486 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3487 break;
3488 case NL80211_IFTYPE_MONITOR:
3489 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3490 break;
3491 default:
3492 WARN_ON(1);
3493 break;
3494 }
3495
Michal Kazior64badcb2014-09-18 11:18:02 +03003496 /* Some firmware revisions don't wait for beacon tx completion before
3497 * sending another SWBA event. This could lead to hardware using old
3498 * (freed) beacon data in some cases, e.g. tx credit starvation
3499 * combined with missed TBTT. This is very very rare.
3500 *
3501 * On non-IOMMU-enabled hosts this could be a possible security issue
3502 * because hw could beacon some random data on the air. On
3503 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3504 * device would crash.
3505 *
3506 * Since there are no beacon tx completions (implicit nor explicit)
3507 * propagated to host the only workaround for this is to allocate a
3508 * DMA-coherent buffer for a lifetime of a vif and use it for all
3509 * beacon tx commands. Worst case for this approach is some beacons may
3510 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3511 */
3512 if (vif->type == NL80211_IFTYPE_ADHOC ||
3513 vif->type == NL80211_IFTYPE_AP) {
3514 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3515 IEEE80211_MAX_FRAME_LEN,
3516 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303517 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003518 if (!arvif->beacon_buf) {
3519 ret = -ENOMEM;
3520 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3521 ret);
3522 goto err;
3523 }
3524 }
3525
3526 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3527 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3528 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003529
3530 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3531 arvif->vdev_subtype, vif->addr);
3532 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003533 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003534 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003535 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536 }
3537
Ben Greear16c11172014-09-23 14:17:16 -07003538 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003539 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003540
Michal Kazior46725b152015-01-28 09:57:49 +02003541 /* It makes no sense to have firmware do keepalives. mac80211 already
3542 * takes care of this with idle connection polling.
3543 */
3544 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003545 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003546 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003547 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003548 goto err_vdev_delete;
3549 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003550
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003551 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003552
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003553 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3554 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003555 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003556 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003557 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003558 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003559 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003560 goto err_vdev_delete;
3561 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562
Ben Greear5572a952014-11-24 16:22:10 +02003563 if (ar->cfg_tx_chainmask) {
3564 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3565
3566 vdev_param = ar->wmi.vdev_param->nss;
3567 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3568 nss);
3569 if (ret) {
3570 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3571 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3572 ret);
3573 goto err_vdev_delete;
3574 }
3575 }
3576
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3578 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3579 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003580 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003581 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003582 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003583 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003584
Kalle Valo5a13e762014-01-20 11:01:46 +02003585 ret = ath10k_mac_set_kickout(arvif);
3586 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003587 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003588 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003589 goto err_peer_delete;
3590 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003591 }
3592
3593 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3594 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3595 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3596 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3597 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003598 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003599 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003600 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003601 goto err_peer_delete;
3602 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003603
Michal Kazior9f9b5742014-12-12 12:41:36 +01003604 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003605 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003606 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003607 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003608 goto err_peer_delete;
3609 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003610
Michal Kazior9f9b5742014-12-12 12:41:36 +01003611 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003612 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003613 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003614 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003615 goto err_peer_delete;
3616 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617 }
3618
Michal Kazior424121c2013-07-22 14:13:31 +02003619 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003620 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003621 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003622 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003623 goto err_peer_delete;
3624 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003625
Michal Kazior424121c2013-07-22 14:13:31 +02003626 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003627 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003628 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003629 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003630 goto err_peer_delete;
3631 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003632
Michal Kazior7d9d5582014-10-21 10:40:15 +03003633 arvif->txpower = vif->bss_conf.txpower;
3634 ret = ath10k_mac_txpower_recalc(ar);
3635 if (ret) {
3636 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3637 goto err_peer_delete;
3638 }
3639
Kalle Valo5e3dd152013-06-12 20:52:10 +03003640 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003641 return 0;
3642
3643err_peer_delete:
3644 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3645 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3646
3647err_vdev_delete:
3648 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003649 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003650 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003651
3652err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003653 if (arvif->beacon_buf) {
3654 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3655 arvif->beacon_buf, arvif->beacon_paddr);
3656 arvif->beacon_buf = NULL;
3657 }
3658
Michal Kazior9dad14a2013-10-16 15:44:45 +03003659 mutex_unlock(&ar->conf_mutex);
3660
Kalle Valo5e3dd152013-06-12 20:52:10 +03003661 return ret;
3662}
3663
3664static void ath10k_remove_interface(struct ieee80211_hw *hw,
3665 struct ieee80211_vif *vif)
3666{
3667 struct ath10k *ar = hw->priv;
3668 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3669 int ret;
3670
Michal Kazior81a9a172015-03-05 16:02:17 +02003671 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003672 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003673
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303674 mutex_lock(&ar->conf_mutex);
3675
Michal Kaziored543882013-09-13 14:16:56 +02003676 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003677 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003678 spin_unlock_bh(&ar->data_lock);
3679
Simon Wunderlich855aed12014-08-02 09:12:54 +03003680 ret = ath10k_spectral_vif_stop(arvif);
3681 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003682 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003683 arvif->vdev_id, ret);
3684
Ben Greear16c11172014-09-23 14:17:16 -07003685 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003686 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003687
3688 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003689 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3690 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003691 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003692 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003693 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003694
3695 kfree(arvif->u.ap.noa_data);
3696 }
3697
Michal Kazior7aa7a722014-08-25 12:09:38 +02003698 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003699 arvif->vdev_id);
3700
Kalle Valo5e3dd152013-06-12 20:52:10 +03003701 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3702 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003703 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003704 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003705
Michal Kazior2c512052015-02-15 16:50:40 +02003706 /* Some firmware revisions don't notify host about self-peer removal
3707 * until after associated vdev is deleted.
3708 */
3709 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3710 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3711 vif->addr);
3712 if (ret)
3713 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3714 arvif->vdev_id, ret);
3715
3716 spin_lock_bh(&ar->data_lock);
3717 ar->num_peers--;
3718 spin_unlock_bh(&ar->data_lock);
3719 }
3720
Kalle Valo5e3dd152013-06-12 20:52:10 +03003721 ath10k_peer_cleanup(ar, arvif->vdev_id);
3722
3723 mutex_unlock(&ar->conf_mutex);
3724}
3725
3726/*
3727 * FIXME: Has to be verified.
3728 */
3729#define SUPPORTED_FILTERS \
3730 (FIF_PROMISC_IN_BSS | \
3731 FIF_ALLMULTI | \
3732 FIF_CONTROL | \
3733 FIF_PSPOLL | \
3734 FIF_OTHER_BSS | \
3735 FIF_BCN_PRBRESP_PROMISC | \
3736 FIF_PROBE_REQ | \
3737 FIF_FCSFAIL)
3738
3739static void ath10k_configure_filter(struct ieee80211_hw *hw,
3740 unsigned int changed_flags,
3741 unsigned int *total_flags,
3742 u64 multicast)
3743{
3744 struct ath10k *ar = hw->priv;
3745 int ret;
3746
3747 mutex_lock(&ar->conf_mutex);
3748
3749 changed_flags &= SUPPORTED_FILTERS;
3750 *total_flags &= SUPPORTED_FILTERS;
3751 ar->filter_flags = *total_flags;
3752
Michal Kazior19337472014-08-28 12:58:16 +02003753 ret = ath10k_monitor_recalc(ar);
3754 if (ret)
3755 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003756
3757 mutex_unlock(&ar->conf_mutex);
3758}
3759
3760static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3761 struct ieee80211_vif *vif,
3762 struct ieee80211_bss_conf *info,
3763 u32 changed)
3764{
3765 struct ath10k *ar = hw->priv;
3766 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3767 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003768 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003769
3770 mutex_lock(&ar->conf_mutex);
3771
3772 if (changed & BSS_CHANGED_IBSS)
3773 ath10k_control_ibss(arvif, info, vif->addr);
3774
3775 if (changed & BSS_CHANGED_BEACON_INT) {
3776 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003777 vdev_param = ar->wmi.vdev_param->beacon_interval;
3778 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003780 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003781 "mac vdev %d beacon_interval %d\n",
3782 arvif->vdev_id, arvif->beacon_interval);
3783
Kalle Valo5e3dd152013-06-12 20:52:10 +03003784 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003785 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003786 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003787 }
3788
3789 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003790 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003791 "vdev %d set beacon tx mode to staggered\n",
3792 arvif->vdev_id);
3793
Bartosz Markowski226a3392013-09-26 17:47:16 +02003794 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3795 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003796 WMI_BEACON_STAGGERED_MODE);
3797 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003798 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003799 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003800
3801 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3802 if (ret)
3803 ath10k_warn(ar, "failed to update beacon template: %d\n",
3804 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805 }
3806
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003807 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3808 ret = ath10k_mac_setup_prb_tmpl(arvif);
3809 if (ret)
3810 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3811 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003812 }
3813
Michal Kaziorba2479f2015-01-24 12:14:51 +02003814 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815 arvif->dtim_period = info->dtim_period;
3816
Michal Kazior7aa7a722014-08-25 12:09:38 +02003817 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003818 "mac vdev %d dtim_period %d\n",
3819 arvif->vdev_id, arvif->dtim_period);
3820
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003821 vdev_param = ar->wmi.vdev_param->dtim_period;
3822 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003823 arvif->dtim_period);
3824 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003825 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003826 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827 }
3828
3829 if (changed & BSS_CHANGED_SSID &&
3830 vif->type == NL80211_IFTYPE_AP) {
3831 arvif->u.ap.ssid_len = info->ssid_len;
3832 if (info->ssid_len)
3833 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3834 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3835 }
3836
Michal Kazior077efc82014-10-21 10:10:29 +03003837 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3838 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003839
3840 if (changed & BSS_CHANGED_BEACON_ENABLED)
3841 ath10k_control_beaconing(arvif, info);
3842
3843 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003844 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003845 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003846 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003847
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003848 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003850 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003851 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003852
3853 vdev_param = ar->wmi.vdev_param->protection_mode;
3854 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3855 info->use_cts_prot ? 1 : 0);
3856 if (ret)
3857 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3858 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003859 }
3860
3861 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003862 if (info->use_short_slot)
3863 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3864
3865 else
3866 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3867
Michal Kazior7aa7a722014-08-25 12:09:38 +02003868 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003869 arvif->vdev_id, slottime);
3870
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003871 vdev_param = ar->wmi.vdev_param->slot_time;
3872 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003873 slottime);
3874 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003875 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003876 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003877 }
3878
3879 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003880 if (info->use_short_preamble)
3881 preamble = WMI_VDEV_PREAMBLE_SHORT;
3882 else
3883 preamble = WMI_VDEV_PREAMBLE_LONG;
3884
Michal Kazior7aa7a722014-08-25 12:09:38 +02003885 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003886 "mac vdev %d preamble %dn",
3887 arvif->vdev_id, preamble);
3888
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003889 vdev_param = ar->wmi.vdev_param->preamble;
3890 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003891 preamble);
3892 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003893 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003894 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895 }
3896
3897 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003898 if (info->assoc) {
3899 /* Workaround: Make sure monitor vdev is not running
3900 * when associating to prevent some firmware revisions
3901 * (e.g. 10.1 and 10.2) from crashing.
3902 */
3903 if (ar->monitor_started)
3904 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003905 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003906 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003907 } else {
3908 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003909 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003910 }
3911
Michal Kazior7d9d5582014-10-21 10:40:15 +03003912 if (changed & BSS_CHANGED_TXPOWER) {
3913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3914 arvif->vdev_id, info->txpower);
3915
3916 arvif->txpower = info->txpower;
3917 ret = ath10k_mac_txpower_recalc(ar);
3918 if (ret)
3919 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3920 }
3921
Michal Kaziorbf14e652014-12-12 12:41:38 +01003922 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003923 arvif->ps = vif->bss_conf.ps;
3924
3925 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003926 if (ret)
3927 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3928 arvif->vdev_id, ret);
3929 }
3930
Kalle Valo5e3dd152013-06-12 20:52:10 +03003931 mutex_unlock(&ar->conf_mutex);
3932}
3933
3934static int ath10k_hw_scan(struct ieee80211_hw *hw,
3935 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003936 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003937{
3938 struct ath10k *ar = hw->priv;
3939 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003940 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003941 struct wmi_start_scan_arg arg;
3942 int ret = 0;
3943 int i;
3944
3945 mutex_lock(&ar->conf_mutex);
3946
3947 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003948 switch (ar->scan.state) {
3949 case ATH10K_SCAN_IDLE:
3950 reinit_completion(&ar->scan.started);
3951 reinit_completion(&ar->scan.completed);
3952 ar->scan.state = ATH10K_SCAN_STARTING;
3953 ar->scan.is_roc = false;
3954 ar->scan.vdev_id = arvif->vdev_id;
3955 ret = 0;
3956 break;
3957 case ATH10K_SCAN_STARTING:
3958 case ATH10K_SCAN_RUNNING:
3959 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003960 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003961 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963 spin_unlock_bh(&ar->data_lock);
3964
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003965 if (ret)
3966 goto exit;
3967
Kalle Valo5e3dd152013-06-12 20:52:10 +03003968 memset(&arg, 0, sizeof(arg));
3969 ath10k_wmi_start_scan_init(ar, &arg);
3970 arg.vdev_id = arvif->vdev_id;
3971 arg.scan_id = ATH10K_SCAN_ID;
3972
3973 if (!req->no_cck)
3974 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3975
3976 if (req->ie_len) {
3977 arg.ie_len = req->ie_len;
3978 memcpy(arg.ie, req->ie, arg.ie_len);
3979 }
3980
3981 if (req->n_ssids) {
3982 arg.n_ssids = req->n_ssids;
3983 for (i = 0; i < arg.n_ssids; i++) {
3984 arg.ssids[i].len = req->ssids[i].ssid_len;
3985 arg.ssids[i].ssid = req->ssids[i].ssid;
3986 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003987 } else {
3988 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003989 }
3990
3991 if (req->n_channels) {
3992 arg.n_channels = req->n_channels;
3993 for (i = 0; i < arg.n_channels; i++)
3994 arg.channels[i] = req->channels[i]->center_freq;
3995 }
3996
3997 ret = ath10k_start_scan(ar, &arg);
3998 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003999 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004000 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004001 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004002 spin_unlock_bh(&ar->data_lock);
4003 }
4004
4005exit:
4006 mutex_unlock(&ar->conf_mutex);
4007 return ret;
4008}
4009
4010static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4011 struct ieee80211_vif *vif)
4012{
4013 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014
4015 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004016 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004018
4019 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004020}
4021
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004022static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4023 struct ath10k_vif *arvif,
4024 enum set_key_cmd cmd,
4025 struct ieee80211_key_conf *key)
4026{
4027 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4028 int ret;
4029
4030 /* 10.1 firmware branch requires default key index to be set to group
4031 * key index after installing it. Otherwise FW/HW Txes corrupted
4032 * frames with multi-vif APs. This is not required for main firmware
4033 * branch (e.g. 636).
4034 *
4035 * FIXME: This has been tested only in AP. It remains unknown if this
4036 * is required for multi-vif STA interfaces on 10.1 */
4037
4038 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4039 return;
4040
4041 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4042 return;
4043
4044 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4045 return;
4046
4047 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4048 return;
4049
4050 if (cmd != SET_KEY)
4051 return;
4052
4053 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4054 key->keyidx);
4055 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004056 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004057 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004058}
4059
Kalle Valo5e3dd152013-06-12 20:52:10 +03004060static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4061 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4062 struct ieee80211_key_conf *key)
4063{
4064 struct ath10k *ar = hw->priv;
4065 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4066 struct ath10k_peer *peer;
4067 const u8 *peer_addr;
4068 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4069 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4070 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004071 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004072
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004073 /* this one needs to be done in software */
4074 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4075 return 1;
4076
Kalle Valo5e3dd152013-06-12 20:52:10 +03004077 if (key->keyidx > WMI_MAX_KEY_INDEX)
4078 return -ENOSPC;
4079
4080 mutex_lock(&ar->conf_mutex);
4081
4082 if (sta)
4083 peer_addr = sta->addr;
4084 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4085 peer_addr = vif->bss_conf.bssid;
4086 else
4087 peer_addr = vif->addr;
4088
4089 key->hw_key_idx = key->keyidx;
4090
4091 /* the peer should not disappear in mid-way (unless FW goes awry) since
4092 * we already hold conf_mutex. we just make sure its there now. */
4093 spin_lock_bh(&ar->data_lock);
4094 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4095 spin_unlock_bh(&ar->data_lock);
4096
4097 if (!peer) {
4098 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004099 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100 peer_addr);
4101 ret = -EOPNOTSUPP;
4102 goto exit;
4103 } else {
4104 /* if the peer doesn't exist there is no key to disable
4105 * anymore */
4106 goto exit;
4107 }
4108 }
4109
Michal Kazior7cc45732015-03-09 14:24:17 +01004110 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4111 flags |= WMI_KEY_PAIRWISE;
4112 else
4113 flags |= WMI_KEY_GROUP;
4114
Kalle Valo5e3dd152013-06-12 20:52:10 +03004115 if (is_wep) {
4116 if (cmd == SET_KEY)
4117 arvif->wep_keys[key->keyidx] = key;
4118 else
4119 arvif->wep_keys[key->keyidx] = NULL;
4120
4121 if (cmd == DISABLE_KEY)
4122 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004123
Michal Kaziorad325cb2015-02-18 14:02:27 +01004124 /* When WEP keys are uploaded it's possible that there are
4125 * stations associated already (e.g. when merging) without any
4126 * keys. Static WEP needs an explicit per-peer key upload.
4127 */
4128 if (vif->type == NL80211_IFTYPE_ADHOC &&
4129 cmd == SET_KEY)
4130 ath10k_mac_vif_update_wep_key(arvif, key);
4131
Michal Kazior370e5672015-02-18 14:02:26 +01004132 /* 802.1x never sets the def_wep_key_idx so each set_key()
4133 * call changes default tx key.
4134 *
4135 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4136 * after first set_key().
4137 */
4138 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4139 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004140
Michal Kazior7cc45732015-03-09 14:24:17 +01004141 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4142 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4143 * mode and associated stations in AP/IBSS.
4144 *
4145 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4146 * work fine when mapped directly from mac80211.
4147 *
4148 * Note: When installing first static WEP groupwise key (which
4149 * should be pairwise) def_wep_key_idx isn't known yet (it's
4150 * equal to -1). Since .set_default_unicast_key is called only
4151 * for static WEP it's used to re-upload the key as pairwise.
4152 */
4153 if (arvif->def_wep_key_idx >= 0 &&
4154 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4155 flags &= ~WMI_KEY_GROUP;
4156 flags |= WMI_KEY_PAIRWISE;
4157 }
Michal Kazior370e5672015-02-18 14:02:26 +01004158 }
4159
4160 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004162 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004163 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004164 goto exit;
4165 }
4166
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004167 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4168
Kalle Valo5e3dd152013-06-12 20:52:10 +03004169 spin_lock_bh(&ar->data_lock);
4170 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4171 if (peer && cmd == SET_KEY)
4172 peer->keys[key->keyidx] = key;
4173 else if (peer && cmd == DISABLE_KEY)
4174 peer->keys[key->keyidx] = NULL;
4175 else if (peer == NULL)
4176 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004177 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178 spin_unlock_bh(&ar->data_lock);
4179
4180exit:
4181 mutex_unlock(&ar->conf_mutex);
4182 return ret;
4183}
4184
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004185static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4186 struct ieee80211_vif *vif,
4187 int keyidx)
4188{
4189 struct ath10k *ar = hw->priv;
4190 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4191 int ret;
4192
4193 mutex_lock(&arvif->ar->conf_mutex);
4194
4195 if (arvif->ar->state != ATH10K_STATE_ON)
4196 goto unlock;
4197
4198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4199 arvif->vdev_id, keyidx);
4200
4201 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4202 arvif->vdev_id,
4203 arvif->ar->wmi.vdev_param->def_keyid,
4204 keyidx);
4205
4206 if (ret) {
4207 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4208 arvif->vdev_id,
4209 ret);
4210 goto unlock;
4211 }
4212
4213 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004214
4215 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4216 if (ret) {
4217 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4218 arvif->vdev_id, ret);
4219 goto unlock;
4220 }
4221
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004222unlock:
4223 mutex_unlock(&arvif->ar->conf_mutex);
4224}
4225
Michal Kazior9797feb2014-02-14 14:49:48 +01004226static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4227{
4228 struct ath10k *ar;
4229 struct ath10k_vif *arvif;
4230 struct ath10k_sta *arsta;
4231 struct ieee80211_sta *sta;
4232 u32 changed, bw, nss, smps;
4233 int err;
4234
4235 arsta = container_of(wk, struct ath10k_sta, update_wk);
4236 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4237 arvif = arsta->arvif;
4238 ar = arvif->ar;
4239
4240 spin_lock_bh(&ar->data_lock);
4241
4242 changed = arsta->changed;
4243 arsta->changed = 0;
4244
4245 bw = arsta->bw;
4246 nss = arsta->nss;
4247 smps = arsta->smps;
4248
4249 spin_unlock_bh(&ar->data_lock);
4250
4251 mutex_lock(&ar->conf_mutex);
4252
4253 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004254 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004255 sta->addr, bw);
4256
4257 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4258 WMI_PEER_CHAN_WIDTH, bw);
4259 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004260 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004261 sta->addr, bw, err);
4262 }
4263
4264 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004265 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004266 sta->addr, nss);
4267
4268 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4269 WMI_PEER_NSS, nss);
4270 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004271 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004272 sta->addr, nss, err);
4273 }
4274
4275 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004276 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004277 sta->addr, smps);
4278
4279 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4280 WMI_PEER_SMPS_STATE, smps);
4281 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004282 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004283 sta->addr, smps, err);
4284 }
4285
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004286 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4287 changed & IEEE80211_RC_NSS_CHANGED) {
4288 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004289 sta->addr);
4290
Michal Kazior590922a2014-10-21 10:10:29 +03004291 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004292 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004293 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004294 sta->addr);
4295 }
4296
Michal Kazior9797feb2014-02-14 14:49:48 +01004297 mutex_unlock(&ar->conf_mutex);
4298}
4299
Michal Kaziorcfd10612014-11-25 15:16:05 +01004300static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4301{
4302 struct ath10k *ar = arvif->ar;
4303
4304 lockdep_assert_held(&ar->conf_mutex);
4305
4306 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4307 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4308 return 0;
4309
4310 if (ar->num_stations >= ar->max_num_stations)
4311 return -ENOBUFS;
4312
4313 ar->num_stations++;
4314
4315 return 0;
4316}
4317
4318static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4319{
4320 struct ath10k *ar = arvif->ar;
4321
4322 lockdep_assert_held(&ar->conf_mutex);
4323
4324 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4325 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4326 return;
4327
4328 ar->num_stations--;
4329}
4330
Kalle Valo5e3dd152013-06-12 20:52:10 +03004331static int ath10k_sta_state(struct ieee80211_hw *hw,
4332 struct ieee80211_vif *vif,
4333 struct ieee80211_sta *sta,
4334 enum ieee80211_sta_state old_state,
4335 enum ieee80211_sta_state new_state)
4336{
4337 struct ath10k *ar = hw->priv;
4338 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004339 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004340 int ret = 0;
4341
Michal Kazior76f90022014-02-25 09:29:57 +02004342 if (old_state == IEEE80211_STA_NOTEXIST &&
4343 new_state == IEEE80211_STA_NONE) {
4344 memset(arsta, 0, sizeof(*arsta));
4345 arsta->arvif = arvif;
4346 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4347 }
4348
Michal Kazior9797feb2014-02-14 14:49:48 +01004349 /* cancel must be done outside the mutex to avoid deadlock */
4350 if ((old_state == IEEE80211_STA_NONE &&
4351 new_state == IEEE80211_STA_NOTEXIST))
4352 cancel_work_sync(&arsta->update_wk);
4353
Kalle Valo5e3dd152013-06-12 20:52:10 +03004354 mutex_lock(&ar->conf_mutex);
4355
4356 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004357 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004358 /*
4359 * New station addition.
4360 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004361 ath10k_dbg(ar, ATH10K_DBG_MAC,
4362 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4363 arvif->vdev_id, sta->addr,
4364 ar->num_stations + 1, ar->max_num_stations,
4365 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004366
Michal Kaziorcfd10612014-11-25 15:16:05 +01004367 ret = ath10k_mac_inc_num_stations(arvif);
4368 if (ret) {
4369 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4370 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004371 goto exit;
4372 }
4373
Kalle Valo5e3dd152013-06-12 20:52:10 +03004374 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004375 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004376 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 -08004377 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004378 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004379 goto exit;
4380 }
Michal Kazior077efc82014-10-21 10:10:29 +03004381
4382 if (vif->type == NL80211_IFTYPE_STATION) {
4383 WARN_ON(arvif->is_started);
4384
4385 ret = ath10k_vdev_start(arvif);
4386 if (ret) {
4387 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4388 arvif->vdev_id, ret);
4389 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4390 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004391 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004392 goto exit;
4393 }
4394
4395 arvif->is_started = true;
4396 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004397 } else if ((old_state == IEEE80211_STA_NONE &&
4398 new_state == IEEE80211_STA_NOTEXIST)) {
4399 /*
4400 * Existing station deletion.
4401 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004402 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004403 "mac vdev %d peer delete %pM (sta gone)\n",
4404 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004405
4406 if (vif->type == NL80211_IFTYPE_STATION) {
4407 WARN_ON(!arvif->is_started);
4408
4409 ret = ath10k_vdev_stop(arvif);
4410 if (ret)
4411 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4412 arvif->vdev_id, ret);
4413
4414 arvif->is_started = false;
4415 }
4416
Kalle Valo5e3dd152013-06-12 20:52:10 +03004417 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4418 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004419 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004420 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004421
Michal Kaziorcfd10612014-11-25 15:16:05 +01004422 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004423 } else if (old_state == IEEE80211_STA_AUTH &&
4424 new_state == IEEE80211_STA_ASSOC &&
4425 (vif->type == NL80211_IFTYPE_AP ||
4426 vif->type == NL80211_IFTYPE_ADHOC)) {
4427 /*
4428 * New association.
4429 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004430 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004431 sta->addr);
4432
Michal Kazior590922a2014-10-21 10:10:29 +03004433 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004434 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004435 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004436 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004437 } else if (old_state == IEEE80211_STA_ASSOC &&
4438 new_state == IEEE80211_STA_AUTH &&
4439 (vif->type == NL80211_IFTYPE_AP ||
4440 vif->type == NL80211_IFTYPE_ADHOC)) {
4441 /*
4442 * Disassociation.
4443 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004444 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004445 sta->addr);
4446
Michal Kazior590922a2014-10-21 10:10:29 +03004447 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004448 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004449 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004450 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004451 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004452exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004453 mutex_unlock(&ar->conf_mutex);
4454 return ret;
4455}
4456
4457static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004458 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004459{
4460 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004461 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4462 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463 u32 value = 0;
4464 int ret = 0;
4465
Michal Kazior548db542013-07-05 16:15:15 +03004466 lockdep_assert_held(&ar->conf_mutex);
4467
Kalle Valo5e3dd152013-06-12 20:52:10 +03004468 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4469 return 0;
4470
4471 switch (ac) {
4472 case IEEE80211_AC_VO:
4473 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4474 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004475 prio = 7;
4476 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004477 break;
4478 case IEEE80211_AC_VI:
4479 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4480 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004481 prio = 5;
4482 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004483 break;
4484 case IEEE80211_AC_BE:
4485 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4486 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004487 prio = 2;
4488 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004489 break;
4490 case IEEE80211_AC_BK:
4491 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4492 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004493 prio = 0;
4494 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004495 break;
4496 }
4497
4498 if (enable)
4499 arvif->u.sta.uapsd |= value;
4500 else
4501 arvif->u.sta.uapsd &= ~value;
4502
4503 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4504 WMI_STA_PS_PARAM_UAPSD,
4505 arvif->u.sta.uapsd);
4506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004507 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004508 goto exit;
4509 }
4510
4511 if (arvif->u.sta.uapsd)
4512 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4513 else
4514 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4515
4516 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4517 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4518 value);
4519 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004520 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004521
Michal Kazior9f9b5742014-12-12 12:41:36 +01004522 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4523 if (ret) {
4524 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4525 arvif->vdev_id, ret);
4526 return ret;
4527 }
4528
4529 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4530 if (ret) {
4531 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4532 arvif->vdev_id, ret);
4533 return ret;
4534 }
4535
Michal Kaziorb0e56152015-01-24 12:14:52 +02004536 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4537 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4538 /* Only userspace can make an educated decision when to send
4539 * trigger frame. The following effectively disables u-UAPSD
4540 * autotrigger in firmware (which is enabled by default
4541 * provided the autotrigger service is available).
4542 */
4543
4544 arg.wmm_ac = acc;
4545 arg.user_priority = prio;
4546 arg.service_interval = 0;
4547 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4548 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4549
4550 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4551 arvif->bssid, &arg, 1);
4552 if (ret) {
4553 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4554 ret);
4555 return ret;
4556 }
4557 }
4558
Kalle Valo5e3dd152013-06-12 20:52:10 +03004559exit:
4560 return ret;
4561}
4562
4563static int ath10k_conf_tx(struct ieee80211_hw *hw,
4564 struct ieee80211_vif *vif, u16 ac,
4565 const struct ieee80211_tx_queue_params *params)
4566{
4567 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004568 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004569 struct wmi_wmm_params_arg *p = NULL;
4570 int ret;
4571
4572 mutex_lock(&ar->conf_mutex);
4573
4574 switch (ac) {
4575 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004576 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004577 break;
4578 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004579 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004580 break;
4581 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004582 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583 break;
4584 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004585 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004586 break;
4587 }
4588
4589 if (WARN_ON(!p)) {
4590 ret = -EINVAL;
4591 goto exit;
4592 }
4593
4594 p->cwmin = params->cw_min;
4595 p->cwmax = params->cw_max;
4596 p->aifs = params->aifs;
4597
4598 /*
4599 * The channel time duration programmed in the HW is in absolute
4600 * microseconds, while mac80211 gives the txop in units of
4601 * 32 microseconds.
4602 */
4603 p->txop = params->txop * 32;
4604
Michal Kazior7fc979a2015-01-28 09:57:28 +02004605 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4606 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4607 &arvif->wmm_params);
4608 if (ret) {
4609 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4610 arvif->vdev_id, ret);
4611 goto exit;
4612 }
4613 } else {
4614 /* This won't work well with multi-interface cases but it's
4615 * better than nothing.
4616 */
4617 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4618 if (ret) {
4619 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4620 goto exit;
4621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004622 }
4623
4624 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4625 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004626 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004627
4628exit:
4629 mutex_unlock(&ar->conf_mutex);
4630 return ret;
4631}
4632
4633#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4634
4635static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4636 struct ieee80211_vif *vif,
4637 struct ieee80211_channel *chan,
4638 int duration,
4639 enum ieee80211_roc_type type)
4640{
4641 struct ath10k *ar = hw->priv;
4642 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4643 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004644 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004645
4646 mutex_lock(&ar->conf_mutex);
4647
4648 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004649 switch (ar->scan.state) {
4650 case ATH10K_SCAN_IDLE:
4651 reinit_completion(&ar->scan.started);
4652 reinit_completion(&ar->scan.completed);
4653 reinit_completion(&ar->scan.on_channel);
4654 ar->scan.state = ATH10K_SCAN_STARTING;
4655 ar->scan.is_roc = true;
4656 ar->scan.vdev_id = arvif->vdev_id;
4657 ar->scan.roc_freq = chan->center_freq;
4658 ret = 0;
4659 break;
4660 case ATH10K_SCAN_STARTING:
4661 case ATH10K_SCAN_RUNNING:
4662 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004663 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004664 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004665 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004666 spin_unlock_bh(&ar->data_lock);
4667
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004668 if (ret)
4669 goto exit;
4670
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004671 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4672
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673 memset(&arg, 0, sizeof(arg));
4674 ath10k_wmi_start_scan_init(ar, &arg);
4675 arg.vdev_id = arvif->vdev_id;
4676 arg.scan_id = ATH10K_SCAN_ID;
4677 arg.n_channels = 1;
4678 arg.channels[0] = chan->center_freq;
4679 arg.dwell_time_active = duration;
4680 arg.dwell_time_passive = duration;
4681 arg.max_scan_time = 2 * duration;
4682 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4683 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4684
4685 ret = ath10k_start_scan(ar, &arg);
4686 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004687 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004688 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004689 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004690 spin_unlock_bh(&ar->data_lock);
4691 goto exit;
4692 }
4693
4694 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4695 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004696 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004697
4698 ret = ath10k_scan_stop(ar);
4699 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004700 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004701
Kalle Valo5e3dd152013-06-12 20:52:10 +03004702 ret = -ETIMEDOUT;
4703 goto exit;
4704 }
4705
4706 ret = 0;
4707exit:
4708 mutex_unlock(&ar->conf_mutex);
4709 return ret;
4710}
4711
4712static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4713{
4714 struct ath10k *ar = hw->priv;
4715
4716 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004717 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004718 mutex_unlock(&ar->conf_mutex);
4719
Michal Kazior4eb2e162014-10-28 10:23:09 +01004720 cancel_delayed_work_sync(&ar->scan.timeout);
4721
Kalle Valo5e3dd152013-06-12 20:52:10 +03004722 return 0;
4723}
4724
4725/*
4726 * Both RTS and Fragmentation threshold are interface-specific
4727 * in ath10k, but device-specific in mac80211.
4728 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004729
4730static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4731{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004733 struct ath10k_vif *arvif;
4734 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004735
Michal Kaziorad088bf2013-10-16 15:44:46 +03004736 mutex_lock(&ar->conf_mutex);
4737 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004738 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004739 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004740
Michal Kaziorad088bf2013-10-16 15:44:46 +03004741 ret = ath10k_mac_set_rts(arvif, value);
4742 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004743 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004744 arvif->vdev_id, ret);
4745 break;
4746 }
4747 }
4748 mutex_unlock(&ar->conf_mutex);
4749
4750 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004751}
4752
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004753static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4754 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004755{
4756 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004757 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004758 int ret;
4759
4760 /* mac80211 doesn't care if we really xmit queued frames or not
4761 * we'll collect those frames either way if we stop/delete vdevs */
4762 if (drop)
4763 return;
4764
Michal Kazior548db542013-07-05 16:15:15 +03004765 mutex_lock(&ar->conf_mutex);
4766
Michal Kazioraffd3212013-07-16 09:54:35 +02004767 if (ar->state == ATH10K_STATE_WEDGED)
4768 goto skip;
4769
Michal Kazioredb82362013-07-05 16:15:14 +03004770 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004772
Michal Kazioredb82362013-07-05 16:15:14 +03004773 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004774 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004775 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004776
Michal Kazior7962b0d2014-10-28 10:34:38 +01004777 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4778 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4779 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004780
4781 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004782 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004783
4784 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004785 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004786 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004787
Michal Kazioraffd3212013-07-16 09:54:35 +02004788skip:
Michal Kazior548db542013-07-05 16:15:15 +03004789 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004790}
4791
4792/* TODO: Implement this function properly
4793 * For now it is needed to reply to Probe Requests in IBSS mode.
4794 * Propably we need this information from FW.
4795 */
4796static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4797{
4798 return 1;
4799}
4800
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004801#ifdef CONFIG_PM
4802static int ath10k_suspend(struct ieee80211_hw *hw,
4803 struct cfg80211_wowlan *wowlan)
4804{
4805 struct ath10k *ar = hw->priv;
4806 int ret;
4807
Marek Puzyniak9042e172014-02-10 17:14:23 +01004808 mutex_lock(&ar->conf_mutex);
4809
Marek Puzyniak00f54822014-02-10 17:14:24 +01004810 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004811 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004812 if (ret == -ETIMEDOUT)
4813 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004814 ret = 1;
4815 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004816 }
4817
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004818 ret = ath10k_hif_suspend(ar);
4819 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004820 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004821 goto resume;
4822 }
4823
Marek Puzyniak9042e172014-02-10 17:14:23 +01004824 ret = 0;
4825 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004826resume:
4827 ret = ath10k_wmi_pdev_resume_target(ar);
4828 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004829 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004830
4831 ret = 1;
4832exit:
4833 mutex_unlock(&ar->conf_mutex);
4834 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004835}
4836
4837static int ath10k_resume(struct ieee80211_hw *hw)
4838{
4839 struct ath10k *ar = hw->priv;
4840 int ret;
4841
Marek Puzyniak9042e172014-02-10 17:14:23 +01004842 mutex_lock(&ar->conf_mutex);
4843
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004844 ret = ath10k_hif_resume(ar);
4845 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004846 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004847 ret = 1;
4848 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004849 }
4850
4851 ret = ath10k_wmi_pdev_resume_target(ar);
4852 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004853 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004854 ret = 1;
4855 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004856 }
4857
Marek Puzyniak9042e172014-02-10 17:14:23 +01004858 ret = 0;
4859exit:
4860 mutex_unlock(&ar->conf_mutex);
4861 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004862}
4863#endif
4864
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004865static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4866 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004867{
4868 struct ath10k *ar = hw->priv;
4869
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004870 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4871 return;
4872
Michal Kazioraffd3212013-07-16 09:54:35 +02004873 mutex_lock(&ar->conf_mutex);
4874
4875 /* If device failed to restart it will be in a different state, e.g.
4876 * ATH10K_STATE_WEDGED */
4877 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004878 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004879 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004880 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004881 }
4882
4883 mutex_unlock(&ar->conf_mutex);
4884}
4885
Michal Kazior2e1dea42013-07-31 10:32:40 +02004886static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4887 struct survey_info *survey)
4888{
4889 struct ath10k *ar = hw->priv;
4890 struct ieee80211_supported_band *sband;
4891 struct survey_info *ar_survey = &ar->survey[idx];
4892 int ret = 0;
4893
4894 mutex_lock(&ar->conf_mutex);
4895
4896 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4897 if (sband && idx >= sband->n_channels) {
4898 idx -= sband->n_channels;
4899 sband = NULL;
4900 }
4901
4902 if (!sband)
4903 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4904
4905 if (!sband || idx >= sband->n_channels) {
4906 ret = -ENOENT;
4907 goto exit;
4908 }
4909
4910 spin_lock_bh(&ar->data_lock);
4911 memcpy(survey, ar_survey, sizeof(*survey));
4912 spin_unlock_bh(&ar->data_lock);
4913
4914 survey->channel = &sband->channels[idx];
4915
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004916 if (ar->rx_channel == survey->channel)
4917 survey->filled |= SURVEY_INFO_IN_USE;
4918
Michal Kazior2e1dea42013-07-31 10:32:40 +02004919exit:
4920 mutex_unlock(&ar->conf_mutex);
4921 return ret;
4922}
4923
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004924/* Helper table for legacy fixed_rate/bitrate_mask */
4925static const u8 cck_ofdm_rate[] = {
4926 /* CCK */
4927 3, /* 1Mbps */
4928 2, /* 2Mbps */
4929 1, /* 5.5Mbps */
4930 0, /* 11Mbps */
4931 /* OFDM */
4932 3, /* 6Mbps */
4933 7, /* 9Mbps */
4934 2, /* 12Mbps */
4935 6, /* 18Mbps */
4936 1, /* 24Mbps */
4937 5, /* 36Mbps */
4938 0, /* 48Mbps */
4939 4, /* 54Mbps */
4940};
4941
4942/* Check if only one bit set */
4943static int ath10k_check_single_mask(u32 mask)
4944{
4945 int bit;
4946
4947 bit = ffs(mask);
4948 if (!bit)
4949 return 0;
4950
4951 mask &= ~BIT(bit - 1);
4952 if (mask)
4953 return 2;
4954
4955 return 1;
4956}
4957
4958static bool
4959ath10k_default_bitrate_mask(struct ath10k *ar,
4960 enum ieee80211_band band,
4961 const struct cfg80211_bitrate_mask *mask)
4962{
4963 u32 legacy = 0x00ff;
4964 u8 ht = 0xff, i;
4965 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004966 u16 nrf = ar->num_rf_chains;
4967
4968 if (ar->cfg_tx_chainmask)
4969 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004970
4971 switch (band) {
4972 case IEEE80211_BAND_2GHZ:
4973 legacy = 0x00fff;
4974 vht = 0;
4975 break;
4976 case IEEE80211_BAND_5GHZ:
4977 break;
4978 default:
4979 return false;
4980 }
4981
4982 if (mask->control[band].legacy != legacy)
4983 return false;
4984
Ben Greearb116ea12014-11-24 16:22:10 +02004985 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004986 if (mask->control[band].ht_mcs[i] != ht)
4987 return false;
4988
Ben Greearb116ea12014-11-24 16:22:10 +02004989 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004990 if (mask->control[band].vht_mcs[i] != vht)
4991 return false;
4992
4993 return true;
4994}
4995
4996static bool
4997ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4998 enum ieee80211_band band,
4999 u8 *fixed_nss)
5000{
5001 int ht_nss = 0, vht_nss = 0, i;
5002
5003 /* check legacy */
5004 if (ath10k_check_single_mask(mask->control[band].legacy))
5005 return false;
5006
5007 /* check HT */
5008 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5009 if (mask->control[band].ht_mcs[i] == 0xff)
5010 continue;
5011 else if (mask->control[band].ht_mcs[i] == 0x00)
5012 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005013
5014 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005015 }
5016
5017 ht_nss = i;
5018
5019 /* check VHT */
5020 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5021 if (mask->control[band].vht_mcs[i] == 0x03ff)
5022 continue;
5023 else if (mask->control[band].vht_mcs[i] == 0x0000)
5024 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005025
5026 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005027 }
5028
5029 vht_nss = i;
5030
5031 if (ht_nss > 0 && vht_nss > 0)
5032 return false;
5033
5034 if (ht_nss)
5035 *fixed_nss = ht_nss;
5036 else if (vht_nss)
5037 *fixed_nss = vht_nss;
5038 else
5039 return false;
5040
5041 return true;
5042}
5043
5044static bool
5045ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5046 enum ieee80211_band band,
5047 enum wmi_rate_preamble *preamble)
5048{
5049 int legacy = 0, ht = 0, vht = 0, i;
5050
5051 *preamble = WMI_RATE_PREAMBLE_OFDM;
5052
5053 /* check legacy */
5054 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5055 if (legacy > 1)
5056 return false;
5057
5058 /* check HT */
5059 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5060 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5061 if (ht > 1)
5062 return false;
5063
5064 /* check VHT */
5065 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5066 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5067 if (vht > 1)
5068 return false;
5069
5070 /* Currently we support only one fixed_rate */
5071 if ((legacy + ht + vht) != 1)
5072 return false;
5073
5074 if (ht)
5075 *preamble = WMI_RATE_PREAMBLE_HT;
5076 else if (vht)
5077 *preamble = WMI_RATE_PREAMBLE_VHT;
5078
5079 return true;
5080}
5081
5082static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005083ath10k_bitrate_mask_rate(struct ath10k *ar,
5084 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005085 enum ieee80211_band band,
5086 u8 *fixed_rate,
5087 u8 *fixed_nss)
5088{
5089 u8 rate = 0, pream = 0, nss = 0, i;
5090 enum wmi_rate_preamble preamble;
5091
5092 /* Check if single rate correct */
5093 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5094 return false;
5095
5096 pream = preamble;
5097
5098 switch (preamble) {
5099 case WMI_RATE_PREAMBLE_CCK:
5100 case WMI_RATE_PREAMBLE_OFDM:
5101 i = ffs(mask->control[band].legacy) - 1;
5102
5103 if (band == IEEE80211_BAND_2GHZ && i < 4)
5104 pream = WMI_RATE_PREAMBLE_CCK;
5105
5106 if (band == IEEE80211_BAND_5GHZ)
5107 i += 4;
5108
5109 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5110 return false;
5111
5112 rate = cck_ofdm_rate[i];
5113 break;
5114 case WMI_RATE_PREAMBLE_HT:
5115 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5116 if (mask->control[band].ht_mcs[i])
5117 break;
5118
5119 if (i == IEEE80211_HT_MCS_MASK_LEN)
5120 return false;
5121
5122 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5123 nss = i;
5124 break;
5125 case WMI_RATE_PREAMBLE_VHT:
5126 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5127 if (mask->control[band].vht_mcs[i])
5128 break;
5129
5130 if (i == NL80211_VHT_NSS_MAX)
5131 return false;
5132
5133 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5134 nss = i;
5135 break;
5136 }
5137
5138 *fixed_nss = nss + 1;
5139 nss <<= 4;
5140 pream <<= 6;
5141
Michal Kazior7aa7a722014-08-25 12:09:38 +02005142 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 +01005143 pream, nss, rate);
5144
5145 *fixed_rate = pream | nss | rate;
5146
5147 return true;
5148}
5149
Michal Kazior7aa7a722014-08-25 12:09:38 +02005150static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5151 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005152 enum ieee80211_band band,
5153 u8 *fixed_rate,
5154 u8 *fixed_nss)
5155{
5156 /* First check full NSS mask, if we can simply limit NSS */
5157 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5158 return true;
5159
5160 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005161 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005162}
5163
5164static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5165 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005166 u8 fixed_nss,
5167 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005168{
5169 struct ath10k *ar = arvif->ar;
5170 u32 vdev_param;
5171 int ret = 0;
5172
5173 mutex_lock(&ar->conf_mutex);
5174
5175 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005176 arvif->fixed_nss == fixed_nss &&
5177 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005178 goto exit;
5179
5180 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005181 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005182
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005183 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005184 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005185
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005186 vdev_param = ar->wmi.vdev_param->fixed_rate;
5187 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5188 vdev_param, fixed_rate);
5189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005190 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005191 fixed_rate, ret);
5192 ret = -EINVAL;
5193 goto exit;
5194 }
5195
5196 arvif->fixed_rate = fixed_rate;
5197
5198 vdev_param = ar->wmi.vdev_param->nss;
5199 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5200 vdev_param, fixed_nss);
5201
5202 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005203 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005204 fixed_nss, ret);
5205 ret = -EINVAL;
5206 goto exit;
5207 }
5208
5209 arvif->fixed_nss = fixed_nss;
5210
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005211 vdev_param = ar->wmi.vdev_param->sgi;
5212 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5213 force_sgi);
5214
5215 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005216 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005217 force_sgi, ret);
5218 ret = -EINVAL;
5219 goto exit;
5220 }
5221
5222 arvif->force_sgi = force_sgi;
5223
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005224exit:
5225 mutex_unlock(&ar->conf_mutex);
5226 return ret;
5227}
5228
5229static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5230 struct ieee80211_vif *vif,
5231 const struct cfg80211_bitrate_mask *mask)
5232{
5233 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5234 struct ath10k *ar = arvif->ar;
5235 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5236 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5237 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005238 u8 force_sgi;
5239
Ben Greearb116ea12014-11-24 16:22:10 +02005240 if (ar->cfg_tx_chainmask)
5241 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5242
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005243 force_sgi = mask->control[band].gi;
5244 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5245 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005246
5247 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005248 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005249 &fixed_rate,
5250 &fixed_nss))
5251 return -EINVAL;
5252 }
5253
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005254 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005255 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005256 return -EINVAL;
5257 }
5258
5259 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5260 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005261}
5262
Michal Kazior9797feb2014-02-14 14:49:48 +01005263static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5264 struct ieee80211_vif *vif,
5265 struct ieee80211_sta *sta,
5266 u32 changed)
5267{
5268 struct ath10k *ar = hw->priv;
5269 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5270 u32 bw, smps;
5271
5272 spin_lock_bh(&ar->data_lock);
5273
Michal Kazior7aa7a722014-08-25 12:09:38 +02005274 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005275 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5276 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5277 sta->smps_mode);
5278
5279 if (changed & IEEE80211_RC_BW_CHANGED) {
5280 bw = WMI_PEER_CHWIDTH_20MHZ;
5281
5282 switch (sta->bandwidth) {
5283 case IEEE80211_STA_RX_BW_20:
5284 bw = WMI_PEER_CHWIDTH_20MHZ;
5285 break;
5286 case IEEE80211_STA_RX_BW_40:
5287 bw = WMI_PEER_CHWIDTH_40MHZ;
5288 break;
5289 case IEEE80211_STA_RX_BW_80:
5290 bw = WMI_PEER_CHWIDTH_80MHZ;
5291 break;
5292 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005293 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005294 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005295 bw = WMI_PEER_CHWIDTH_20MHZ;
5296 break;
5297 }
5298
5299 arsta->bw = bw;
5300 }
5301
5302 if (changed & IEEE80211_RC_NSS_CHANGED)
5303 arsta->nss = sta->rx_nss;
5304
5305 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5306 smps = WMI_PEER_SMPS_PS_NONE;
5307
5308 switch (sta->smps_mode) {
5309 case IEEE80211_SMPS_AUTOMATIC:
5310 case IEEE80211_SMPS_OFF:
5311 smps = WMI_PEER_SMPS_PS_NONE;
5312 break;
5313 case IEEE80211_SMPS_STATIC:
5314 smps = WMI_PEER_SMPS_STATIC;
5315 break;
5316 case IEEE80211_SMPS_DYNAMIC:
5317 smps = WMI_PEER_SMPS_DYNAMIC;
5318 break;
5319 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005320 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005321 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005322 smps = WMI_PEER_SMPS_PS_NONE;
5323 break;
5324 }
5325
5326 arsta->smps = smps;
5327 }
5328
Michal Kazior9797feb2014-02-14 14:49:48 +01005329 arsta->changed |= changed;
5330
5331 spin_unlock_bh(&ar->data_lock);
5332
5333 ieee80211_queue_work(hw, &arsta->update_wk);
5334}
5335
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005336static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5337{
5338 /*
5339 * FIXME: Return 0 for time being. Need to figure out whether FW
5340 * has the API to fetch 64-bit local TSF
5341 */
5342
5343 return 0;
5344}
5345
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005346static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5347 struct ieee80211_vif *vif,
5348 enum ieee80211_ampdu_mlme_action action,
5349 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5350 u8 buf_size)
5351{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005352 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005353 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5354
Michal Kazior7aa7a722014-08-25 12:09:38 +02005355 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 +02005356 arvif->vdev_id, sta->addr, tid, action);
5357
5358 switch (action) {
5359 case IEEE80211_AMPDU_RX_START:
5360 case IEEE80211_AMPDU_RX_STOP:
5361 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5362 * creation/removal. Do we need to verify this?
5363 */
5364 return 0;
5365 case IEEE80211_AMPDU_TX_START:
5366 case IEEE80211_AMPDU_TX_STOP_CONT:
5367 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5368 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5369 case IEEE80211_AMPDU_TX_OPERATIONAL:
5370 /* Firmware offloads Tx aggregation entirely so deny mac80211
5371 * Tx aggregation requests.
5372 */
5373 return -EOPNOTSUPP;
5374 }
5375
5376 return -EINVAL;
5377}
5378
Kalle Valo5e3dd152013-06-12 20:52:10 +03005379static const struct ieee80211_ops ath10k_ops = {
5380 .tx = ath10k_tx,
5381 .start = ath10k_start,
5382 .stop = ath10k_stop,
5383 .config = ath10k_config,
5384 .add_interface = ath10k_add_interface,
5385 .remove_interface = ath10k_remove_interface,
5386 .configure_filter = ath10k_configure_filter,
5387 .bss_info_changed = ath10k_bss_info_changed,
5388 .hw_scan = ath10k_hw_scan,
5389 .cancel_hw_scan = ath10k_cancel_hw_scan,
5390 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005391 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005392 .sta_state = ath10k_sta_state,
5393 .conf_tx = ath10k_conf_tx,
5394 .remain_on_channel = ath10k_remain_on_channel,
5395 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5396 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005397 .flush = ath10k_flush,
5398 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005399 .set_antenna = ath10k_set_antenna,
5400 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005401 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005402 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005403 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005404 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005405 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005406 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005407 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5408 .get_et_stats = ath10k_debug_get_et_stats,
5409 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005410
5411 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5412
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005413#ifdef CONFIG_PM
5414 .suspend = ath10k_suspend,
5415 .resume = ath10k_resume,
5416#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005417#ifdef CONFIG_MAC80211_DEBUGFS
5418 .sta_add_debugfs = ath10k_sta_add_debugfs,
5419#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005420};
5421
5422#define RATETAB_ENT(_rate, _rateid, _flags) { \
5423 .bitrate = (_rate), \
5424 .flags = (_flags), \
5425 .hw_value = (_rateid), \
5426}
5427
5428#define CHAN2G(_channel, _freq, _flags) { \
5429 .band = IEEE80211_BAND_2GHZ, \
5430 .hw_value = (_channel), \
5431 .center_freq = (_freq), \
5432 .flags = (_flags), \
5433 .max_antenna_gain = 0, \
5434 .max_power = 30, \
5435}
5436
5437#define CHAN5G(_channel, _freq, _flags) { \
5438 .band = IEEE80211_BAND_5GHZ, \
5439 .hw_value = (_channel), \
5440 .center_freq = (_freq), \
5441 .flags = (_flags), \
5442 .max_antenna_gain = 0, \
5443 .max_power = 30, \
5444}
5445
5446static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5447 CHAN2G(1, 2412, 0),
5448 CHAN2G(2, 2417, 0),
5449 CHAN2G(3, 2422, 0),
5450 CHAN2G(4, 2427, 0),
5451 CHAN2G(5, 2432, 0),
5452 CHAN2G(6, 2437, 0),
5453 CHAN2G(7, 2442, 0),
5454 CHAN2G(8, 2447, 0),
5455 CHAN2G(9, 2452, 0),
5456 CHAN2G(10, 2457, 0),
5457 CHAN2G(11, 2462, 0),
5458 CHAN2G(12, 2467, 0),
5459 CHAN2G(13, 2472, 0),
5460 CHAN2G(14, 2484, 0),
5461};
5462
5463static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005464 CHAN5G(36, 5180, 0),
5465 CHAN5G(40, 5200, 0),
5466 CHAN5G(44, 5220, 0),
5467 CHAN5G(48, 5240, 0),
5468 CHAN5G(52, 5260, 0),
5469 CHAN5G(56, 5280, 0),
5470 CHAN5G(60, 5300, 0),
5471 CHAN5G(64, 5320, 0),
5472 CHAN5G(100, 5500, 0),
5473 CHAN5G(104, 5520, 0),
5474 CHAN5G(108, 5540, 0),
5475 CHAN5G(112, 5560, 0),
5476 CHAN5G(116, 5580, 0),
5477 CHAN5G(120, 5600, 0),
5478 CHAN5G(124, 5620, 0),
5479 CHAN5G(128, 5640, 0),
5480 CHAN5G(132, 5660, 0),
5481 CHAN5G(136, 5680, 0),
5482 CHAN5G(140, 5700, 0),
5483 CHAN5G(149, 5745, 0),
5484 CHAN5G(153, 5765, 0),
5485 CHAN5G(157, 5785, 0),
5486 CHAN5G(161, 5805, 0),
5487 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005488};
5489
Michal Kazior91b12082014-12-12 12:41:35 +01005490/* Note: Be careful if you re-order these. There is code which depends on this
5491 * ordering.
5492 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005493static struct ieee80211_rate ath10k_rates[] = {
5494 /* CCK */
5495 RATETAB_ENT(10, 0x82, 0),
5496 RATETAB_ENT(20, 0x84, 0),
5497 RATETAB_ENT(55, 0x8b, 0),
5498 RATETAB_ENT(110, 0x96, 0),
5499 /* OFDM */
5500 RATETAB_ENT(60, 0x0c, 0),
5501 RATETAB_ENT(90, 0x12, 0),
5502 RATETAB_ENT(120, 0x18, 0),
5503 RATETAB_ENT(180, 0x24, 0),
5504 RATETAB_ENT(240, 0x30, 0),
5505 RATETAB_ENT(360, 0x48, 0),
5506 RATETAB_ENT(480, 0x60, 0),
5507 RATETAB_ENT(540, 0x6c, 0),
5508};
5509
5510#define ath10k_a_rates (ath10k_rates + 4)
5511#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5512#define ath10k_g_rates (ath10k_rates + 0)
5513#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5514
Michal Kaziore7b54192014-08-07 11:03:27 +02005515struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005516{
5517 struct ieee80211_hw *hw;
5518 struct ath10k *ar;
5519
Michal Kaziore7b54192014-08-07 11:03:27 +02005520 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005521 if (!hw)
5522 return NULL;
5523
5524 ar = hw->priv;
5525 ar->hw = hw;
5526
5527 return ar;
5528}
5529
5530void ath10k_mac_destroy(struct ath10k *ar)
5531{
5532 ieee80211_free_hw(ar->hw);
5533}
5534
5535static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5536 {
5537 .max = 8,
5538 .types = BIT(NL80211_IFTYPE_STATION)
5539 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005540 },
5541 {
5542 .max = 3,
5543 .types = BIT(NL80211_IFTYPE_P2P_GO)
5544 },
5545 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005546 .max = 1,
5547 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5548 },
5549 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005550 .max = 7,
5551 .types = BIT(NL80211_IFTYPE_AP)
5552 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005553};
5554
Bartosz Markowskif2595092013-12-10 16:20:39 +01005555static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005556 {
5557 .max = 8,
5558 .types = BIT(NL80211_IFTYPE_AP)
5559 },
5560};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005561
5562static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5563 {
5564 .limits = ath10k_if_limits,
5565 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5566 .max_interfaces = 8,
5567 .num_different_channels = 1,
5568 .beacon_int_infra_match = true,
5569 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005570};
5571
5572static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005573 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005574 .limits = ath10k_10x_if_limits,
5575 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005576 .max_interfaces = 8,
5577 .num_different_channels = 1,
5578 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005579#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005580 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5581 BIT(NL80211_CHAN_WIDTH_20) |
5582 BIT(NL80211_CHAN_WIDTH_40) |
5583 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005584#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005585 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005586};
5587
5588static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5589{
5590 struct ieee80211_sta_vht_cap vht_cap = {0};
5591 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005592 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005593 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005594
5595 vht_cap.vht_supported = 1;
5596 vht_cap.cap = ar->vht_cap_info;
5597
Michal Kaziorbc657a362015-02-26 11:11:22 +01005598 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5599 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5600 val = ar->num_rf_chains - 1;
5601 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5602 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5603
5604 vht_cap.cap |= val;
5605 }
5606
5607 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5608 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5609 val = ar->num_rf_chains - 1;
5610 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5611 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5612
5613 vht_cap.cap |= val;
5614 }
5615
Michal Kazior8865bee42013-07-24 12:36:46 +02005616 mcs_map = 0;
5617 for (i = 0; i < 8; i++) {
5618 if (i < ar->num_rf_chains)
5619 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5620 else
5621 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5622 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005623
5624 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5625 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5626
5627 return vht_cap;
5628}
5629
5630static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5631{
5632 int i;
5633 struct ieee80211_sta_ht_cap ht_cap = {0};
5634
5635 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5636 return ht_cap;
5637
5638 ht_cap.ht_supported = 1;
5639 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5640 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5641 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5642 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5643 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5644
5645 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5646 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5647
5648 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5649 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5650
5651 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5652 u32 smps;
5653
5654 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5655 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5656
5657 ht_cap.cap |= smps;
5658 }
5659
5660 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5661 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5662
5663 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5664 u32 stbc;
5665
5666 stbc = ar->ht_cap_info;
5667 stbc &= WMI_HT_CAP_RX_STBC;
5668 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5669 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5670 stbc &= IEEE80211_HT_CAP_RX_STBC;
5671
5672 ht_cap.cap |= stbc;
5673 }
5674
5675 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5676 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5677
5678 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5679 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5680
5681 /* max AMSDU is implicitly taken from vht_cap_info */
5682 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5683 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5684
Michal Kazior8865bee42013-07-24 12:36:46 +02005685 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005686 ht_cap.mcs.rx_mask[i] = 0xFF;
5687
5688 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5689
5690 return ht_cap;
5691}
5692
Kalle Valo5e3dd152013-06-12 20:52:10 +03005693static void ath10k_get_arvif_iter(void *data, u8 *mac,
5694 struct ieee80211_vif *vif)
5695{
5696 struct ath10k_vif_iter *arvif_iter = data;
5697 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5698
5699 if (arvif->vdev_id == arvif_iter->vdev_id)
5700 arvif_iter->arvif = arvif;
5701}
5702
5703struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5704{
5705 struct ath10k_vif_iter arvif_iter;
5706 u32 flags;
5707
5708 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5709 arvif_iter.vdev_id = vdev_id;
5710
5711 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5712 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5713 flags,
5714 ath10k_get_arvif_iter,
5715 &arvif_iter);
5716 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005717 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005718 return NULL;
5719 }
5720
5721 return arvif_iter.arvif;
5722}
5723
5724int ath10k_mac_register(struct ath10k *ar)
5725{
Johannes Berg3cb10942015-01-22 21:38:45 +01005726 static const u32 cipher_suites[] = {
5727 WLAN_CIPHER_SUITE_WEP40,
5728 WLAN_CIPHER_SUITE_WEP104,
5729 WLAN_CIPHER_SUITE_TKIP,
5730 WLAN_CIPHER_SUITE_CCMP,
5731 WLAN_CIPHER_SUITE_AES_CMAC,
5732 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005733 struct ieee80211_supported_band *band;
5734 struct ieee80211_sta_vht_cap vht_cap;
5735 struct ieee80211_sta_ht_cap ht_cap;
5736 void *channels;
5737 int ret;
5738
5739 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5740
5741 SET_IEEE80211_DEV(ar->hw, ar->dev);
5742
5743 ht_cap = ath10k_get_ht_cap(ar);
5744 vht_cap = ath10k_create_vht_cap(ar);
5745
5746 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5747 channels = kmemdup(ath10k_2ghz_channels,
5748 sizeof(ath10k_2ghz_channels),
5749 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005750 if (!channels) {
5751 ret = -ENOMEM;
5752 goto err_free;
5753 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005754
5755 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5756 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5757 band->channels = channels;
5758 band->n_bitrates = ath10k_g_rates_size;
5759 band->bitrates = ath10k_g_rates;
5760 band->ht_cap = ht_cap;
5761
Yanbo Lid68bb122015-01-23 08:18:20 +08005762 /* Enable the VHT support at 2.4 GHz */
5763 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005764
5765 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5766 }
5767
5768 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5769 channels = kmemdup(ath10k_5ghz_channels,
5770 sizeof(ath10k_5ghz_channels),
5771 GFP_KERNEL);
5772 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005773 ret = -ENOMEM;
5774 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005775 }
5776
5777 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5778 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5779 band->channels = channels;
5780 band->n_bitrates = ath10k_a_rates_size;
5781 band->bitrates = ath10k_a_rates;
5782 band->ht_cap = ht_cap;
5783 band->vht_cap = vht_cap;
5784 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5785 }
5786
5787 ar->hw->wiphy->interface_modes =
5788 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005789 BIT(NL80211_IFTYPE_AP);
5790
Ben Greear46acf7b2014-05-16 17:15:38 +03005791 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5792 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5793
Bartosz Markowskid3541812013-12-10 16:20:40 +01005794 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5795 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005796 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005797 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5798 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005799
5800 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5801 IEEE80211_HW_SUPPORTS_PS |
5802 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005803 IEEE80211_HW_MFP_CAPABLE |
5804 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5805 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005806 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005807 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005808 IEEE80211_HW_SW_CRYPTO_CONTROL |
5809 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005810
Eliad Peller0d8614b2014-09-10 14:07:36 +03005811 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5812
Kalle Valo5e3dd152013-06-12 20:52:10 +03005813 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005814 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005815
5816 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5817 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5818 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5819 }
5820
5821 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5822 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5823
5824 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005825 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005826
Kalle Valo5e3dd152013-06-12 20:52:10 +03005827 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5828
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005829 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5830 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5831
5832 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5833 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5834 * correct Probe Responses. This is more of a hack advert..
5835 */
5836 ar->hw->wiphy->probe_resp_offload |=
5837 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5838 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5839 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5840 }
5841
Kalle Valo5e3dd152013-06-12 20:52:10 +03005842 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005843 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005844 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5845
5846 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005847 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5848
Kalle Valo5e3dd152013-06-12 20:52:10 +03005849 /*
5850 * on LL hardware queues are managed entirely by the FW
5851 * so we only advertise to mac we can do the queues thing
5852 */
5853 ar->hw->queues = 4;
5854
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005855 switch (ar->wmi.op_version) {
5856 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5857 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005858 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5859 ar->hw->wiphy->n_iface_combinations =
5860 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005861 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005862 break;
5863 case ATH10K_FW_WMI_OP_VERSION_10_1:
5864 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005865 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005866 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5867 ar->hw->wiphy->n_iface_combinations =
5868 ARRAY_SIZE(ath10k_10x_if_comb);
5869 break;
5870 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5871 case ATH10K_FW_WMI_OP_VERSION_MAX:
5872 WARN_ON(1);
5873 ret = -EINVAL;
5874 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005875 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005876
Michal Kazior7c199992013-07-31 10:47:57 +02005877 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5878
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005879 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5880 /* Init ath dfs pattern detector */
5881 ar->ath_common.debug_mask = ATH_DBG_DFS;
5882 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5883 NL80211_DFS_UNSET);
5884
5885 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005886 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005887 }
5888
Kalle Valo5e3dd152013-06-12 20:52:10 +03005889 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5890 ath10k_reg_notifier);
5891 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005892 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005893 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005894 }
5895
Johannes Berg3cb10942015-01-22 21:38:45 +01005896 ar->hw->wiphy->cipher_suites = cipher_suites;
5897 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5898
Kalle Valo5e3dd152013-06-12 20:52:10 +03005899 ret = ieee80211_register_hw(ar->hw);
5900 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005901 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005902 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005903 }
5904
5905 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5906 ret = regulatory_hint(ar->hw->wiphy,
5907 ar->ath_common.regulatory.alpha2);
5908 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005909 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005910 }
5911
5912 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005913
5914err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005915 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005916err_free:
5917 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5918 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5919
Kalle Valo5e3dd152013-06-12 20:52:10 +03005920 return ret;
5921}
5922
5923void ath10k_mac_unregister(struct ath10k *ar)
5924{
5925 ieee80211_unregister_hw(ar->hw);
5926
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005927 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5928 ar->dfs_detector->exit(ar->dfs_detector);
5929
Kalle Valo5e3dd152013-06-12 20:52:10 +03005930 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5931 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5932
5933 SET_IEEE80211_DEV(ar->hw, NULL);
5934}