blob: 76a9bedf8ae202b943ca0470b49b9eef9e1ac8f2 [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
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200884 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200885
886 if (arvif->num_legacy_stations > 0)
887 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
888 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +0200889 else
890 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
891 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200892
893 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
894 rts_cts);
895}
896
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200897static int ath10k_start_cac(struct ath10k *ar)
898{
899 int ret;
900
901 lockdep_assert_held(&ar->conf_mutex);
902
903 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
904
Michal Kazior19337472014-08-28 12:58:16 +0200905 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200906 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200907 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200908 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
909 return ret;
910 }
911
Michal Kazior7aa7a722014-08-25 12:09:38 +0200912 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200913 ar->monitor_vdev_id);
914
915 return 0;
916}
917
918static int ath10k_stop_cac(struct ath10k *ar)
919{
920 lockdep_assert_held(&ar->conf_mutex);
921
922 /* CAC is not running - do nothing */
923 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
924 return 0;
925
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200926 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300927 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200928
Michal Kazior7aa7a722014-08-25 12:09:38 +0200929 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200930
931 return 0;
932}
933
Michal Kaziord6500972014-04-08 09:56:09 +0300934static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200935{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200936 int ret;
937
938 lockdep_assert_held(&ar->conf_mutex);
939
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200940 ath10k_stop_cac(ar);
941
Michal Kaziord6500972014-04-08 09:56:09 +0300942 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200943 return;
944
Michal Kaziord6500972014-04-08 09:56:09 +0300945 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200946 return;
947
948 ret = ath10k_start_cac(ar);
949 if (ret) {
950 /*
951 * Not possible to start CAC on current channel so starting
952 * radiation is not allowed, make this channel DFS_UNAVAILABLE
953 * by indicating that radar was detected.
954 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200955 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200956 ieee80211_radar_detected(ar->hw);
957 }
958}
959
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530960static int ath10k_vdev_stop(struct ath10k_vif *arvif)
961{
962 struct ath10k *ar = arvif->ar;
963 int ret;
964
965 lockdep_assert_held(&ar->conf_mutex);
966
967 reinit_completion(&ar->vdev_setup_done);
968
969 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
970 if (ret) {
971 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
972 arvif->vdev_id, ret);
973 return ret;
974 }
975
976 ret = ath10k_vdev_setup_sync(ar);
977 if (ret) {
978 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
979 arvif->vdev_id, ret);
980 return ret;
981 }
982
983 WARN_ON(ar->num_started_vdevs == 0);
984
985 if (ar->num_started_vdevs != 0) {
986 ar->num_started_vdevs--;
987 ath10k_recalc_radar_detection(ar);
988 }
989
990 return ret;
991}
992
Michal Kaziordc55e302014-07-29 12:53:36 +0300993static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300994{
995 struct ath10k *ar = arvif->ar;
996 struct cfg80211_chan_def *chandef = &ar->chandef;
997 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530998 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +0300999
1000 lockdep_assert_held(&ar->conf_mutex);
1001
1002 reinit_completion(&ar->vdev_setup_done);
1003
1004 arg.vdev_id = arvif->vdev_id;
1005 arg.dtim_period = arvif->dtim_period;
1006 arg.bcn_intval = arvif->beacon_interval;
1007
1008 arg.channel.freq = chandef->chan->center_freq;
1009 arg.channel.band_center_freq1 = chandef->center_freq1;
1010 arg.channel.mode = chan_to_phymode(chandef);
1011
1012 arg.channel.min_power = 0;
1013 arg.channel.max_power = chandef->chan->max_power * 2;
1014 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1015 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1016
1017 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1018 arg.ssid = arvif->u.ap.ssid;
1019 arg.ssid_len = arvif->u.ap.ssid_len;
1020 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1021
1022 /* For now allow DFS for AP mode */
1023 arg.channel.chan_radar =
1024 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1025 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1026 arg.ssid = arvif->vif->bss_conf.ssid;
1027 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1028 }
1029
Michal Kazior7aa7a722014-08-25 12:09:38 +02001030 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001031 "mac vdev %d start center_freq %d phymode %s\n",
1032 arg.vdev_id, arg.channel.freq,
1033 ath10k_wmi_phymode_str(arg.channel.mode));
1034
Michal Kaziordc55e302014-07-29 12:53:36 +03001035 if (restart)
1036 ret = ath10k_wmi_vdev_restart(ar, &arg);
1037 else
1038 ret = ath10k_wmi_vdev_start(ar, &arg);
1039
Michal Kazior72654fa2014-04-08 09:56:09 +03001040 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001041 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001042 arg.vdev_id, ret);
1043 return ret;
1044 }
1045
1046 ret = ath10k_vdev_setup_sync(ar);
1047 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001048 ath10k_warn(ar,
1049 "failed to synchronize setup for vdev %i restart %d: %d\n",
1050 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001051 return ret;
1052 }
1053
Michal Kaziord6500972014-04-08 09:56:09 +03001054 ar->num_started_vdevs++;
1055 ath10k_recalc_radar_detection(ar);
1056
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301057 ret = ath10k_monitor_recalc(ar);
1058 if (ret) {
1059 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1060 arg.vdev_id, restart, ret);
1061 ret2 = ath10k_vdev_stop(arvif);
1062 if (ret2)
1063 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1064 arg.vdev_id, restart, ret2);
1065 }
1066
Michal Kazior72654fa2014-04-08 09:56:09 +03001067 return ret;
1068}
1069
Michal Kaziordc55e302014-07-29 12:53:36 +03001070static int ath10k_vdev_start(struct ath10k_vif *arvif)
1071{
1072 return ath10k_vdev_start_restart(arvif, false);
1073}
1074
1075static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1076{
1077 return ath10k_vdev_start_restart(arvif, true);
1078}
1079
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001080static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1081 struct sk_buff *bcn)
1082{
1083 struct ath10k *ar = arvif->ar;
1084 struct ieee80211_mgmt *mgmt;
1085 const u8 *p2p_ie;
1086 int ret;
1087
1088 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1089 return 0;
1090
1091 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1092 return 0;
1093
1094 mgmt = (void *)bcn->data;
1095 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1096 mgmt->u.beacon.variable,
1097 bcn->len - (mgmt->u.beacon.variable -
1098 bcn->data));
1099 if (!p2p_ie)
1100 return -ENOENT;
1101
1102 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1103 if (ret) {
1104 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1105 arvif->vdev_id, ret);
1106 return ret;
1107 }
1108
1109 return 0;
1110}
1111
1112static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1113 u8 oui_type, size_t ie_offset)
1114{
1115 size_t len;
1116 const u8 *next;
1117 const u8 *end;
1118 u8 *ie;
1119
1120 if (WARN_ON(skb->len < ie_offset))
1121 return -EINVAL;
1122
1123 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1124 skb->data + ie_offset,
1125 skb->len - ie_offset);
1126 if (!ie)
1127 return -ENOENT;
1128
1129 len = ie[1] + 2;
1130 end = skb->data + skb->len;
1131 next = ie + len;
1132
1133 if (WARN_ON(next > end))
1134 return -EINVAL;
1135
1136 memmove(ie, next, end - next);
1137 skb_trim(skb, skb->len - len);
1138
1139 return 0;
1140}
1141
1142static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1143{
1144 struct ath10k *ar = arvif->ar;
1145 struct ieee80211_hw *hw = ar->hw;
1146 struct ieee80211_vif *vif = arvif->vif;
1147 struct ieee80211_mutable_offsets offs = {};
1148 struct sk_buff *bcn;
1149 int ret;
1150
1151 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1152 return 0;
1153
Michal Kazior81a9a172015-03-05 16:02:17 +02001154 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1155 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1156 return 0;
1157
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001158 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1159 if (!bcn) {
1160 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1161 return -EPERM;
1162 }
1163
1164 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1165 if (ret) {
1166 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1167 kfree_skb(bcn);
1168 return ret;
1169 }
1170
1171 /* P2P IE is inserted by firmware automatically (as configured above)
1172 * so remove it from the base beacon template to avoid duplicate P2P
1173 * IEs in beacon frames.
1174 */
1175 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1176 offsetof(struct ieee80211_mgmt,
1177 u.beacon.variable));
1178
1179 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1180 0, NULL, 0);
1181 kfree_skb(bcn);
1182
1183 if (ret) {
1184 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1185 ret);
1186 return ret;
1187 }
1188
1189 return 0;
1190}
1191
1192static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1193{
1194 struct ath10k *ar = arvif->ar;
1195 struct ieee80211_hw *hw = ar->hw;
1196 struct ieee80211_vif *vif = arvif->vif;
1197 struct sk_buff *prb;
1198 int ret;
1199
1200 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1201 return 0;
1202
Michal Kazior81a9a172015-03-05 16:02:17 +02001203 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1204 return 0;
1205
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001206 prb = ieee80211_proberesp_get(hw, vif);
1207 if (!prb) {
1208 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1209 return -EPERM;
1210 }
1211
1212 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1213 kfree_skb(prb);
1214
1215 if (ret) {
1216 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1217 ret);
1218 return ret;
1219 }
1220
1221 return 0;
1222}
1223
Kalle Valo5e3dd152013-06-12 20:52:10 +03001224static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001225 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001227 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228 int ret = 0;
1229
Michal Kazior548db542013-07-05 16:15:15 +03001230 lockdep_assert_held(&arvif->ar->conf_mutex);
1231
Kalle Valo5e3dd152013-06-12 20:52:10 +03001232 if (!info->enable_beacon) {
1233 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001234
1235 arvif->is_started = false;
1236 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001237
1238 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001239 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001240 spin_unlock_bh(&arvif->ar->data_lock);
1241
Kalle Valo5e3dd152013-06-12 20:52:10 +03001242 return;
1243 }
1244
1245 arvif->tx_seq_no = 0x1000;
1246
1247 ret = ath10k_vdev_start(arvif);
1248 if (ret)
1249 return;
1250
Michal Kaziorc930f742014-01-23 11:38:25 +01001251 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001252 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001253
1254 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1255 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001256 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001257 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001258 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001259 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001260 return;
1261 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001262
1263 arvif->is_started = true;
1264 arvif->is_up = true;
1265
Michal Kazior7aa7a722014-08-25 12:09:38 +02001266 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267}
1268
1269static void ath10k_control_ibss(struct ath10k_vif *arvif,
1270 struct ieee80211_bss_conf *info,
1271 const u8 self_peer[ETH_ALEN])
1272{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001273 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001274 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001275 int ret = 0;
1276
Michal Kazior548db542013-07-05 16:15:15 +03001277 lockdep_assert_held(&arvif->ar->conf_mutex);
1278
Kalle Valo5e3dd152013-06-12 20:52:10 +03001279 if (!info->ibss_joined) {
1280 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1281 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001282 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283 self_peer, arvif->vdev_id, ret);
1284
Michal Kaziorc930f742014-01-23 11:38:25 +01001285 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286 return;
1287
Michal Kaziorc930f742014-01-23 11:38:25 +01001288 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001289
1290 return;
1291 }
1292
1293 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001295 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001296 self_peer, arvif->vdev_id, ret);
1297 return;
1298 }
1299
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001300 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1301 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302 ATH10K_DEFAULT_ATIM);
1303 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001304 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305 arvif->vdev_id, ret);
1306}
1307
Michal Kazior9f9b5742014-12-12 12:41:36 +01001308static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1309{
1310 struct ath10k *ar = arvif->ar;
1311 u32 param;
1312 u32 value;
1313 int ret;
1314
1315 lockdep_assert_held(&arvif->ar->conf_mutex);
1316
1317 if (arvif->u.sta.uapsd)
1318 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1319 else
1320 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1321
1322 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1323 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1324 if (ret) {
1325 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1326 value, arvif->vdev_id, ret);
1327 return ret;
1328 }
1329
1330 return 0;
1331}
1332
1333static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1334{
1335 struct ath10k *ar = arvif->ar;
1336 u32 param;
1337 u32 value;
1338 int ret;
1339
1340 lockdep_assert_held(&arvif->ar->conf_mutex);
1341
1342 if (arvif->u.sta.uapsd)
1343 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1344 else
1345 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1346
1347 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1348 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1349 param, value);
1350 if (ret) {
1351 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1352 value, arvif->vdev_id, ret);
1353 return ret;
1354 }
1355
1356 return 0;
1357}
1358
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001359static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1360{
1361 struct ath10k_vif *arvif;
1362 int num = 0;
1363
1364 lockdep_assert_held(&ar->conf_mutex);
1365
1366 list_for_each_entry(arvif, &ar->arvifs, list)
1367 if (arvif->ps)
1368 num++;
1369
1370 return num;
1371}
1372
Michal Kaziorad088bf2013-10-16 15:44:46 +03001373static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001374{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001375 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001376 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001377 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001378 enum wmi_sta_powersave_param param;
1379 enum wmi_sta_ps_mode psmode;
1380 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001381 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001382 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383
Michal Kazior548db542013-07-05 16:15:15 +03001384 lockdep_assert_held(&arvif->ar->conf_mutex);
1385
Michal Kaziorad088bf2013-10-16 15:44:46 +03001386 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1387 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001388
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001389 enable_ps = arvif->ps;
1390
1391 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1392 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1393 ar->fw_features)) {
1394 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1395 arvif->vdev_id);
1396 enable_ps = false;
1397 }
1398
1399 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400 psmode = WMI_STA_PS_MODE_ENABLED;
1401 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1402
Michal Kazior526549a2014-12-12 12:41:37 +01001403 ps_timeout = conf->dynamic_ps_timeout;
1404 if (ps_timeout == 0) {
1405 /* Firmware doesn't like 0 */
1406 ps_timeout = ieee80211_tu_to_usec(
1407 vif->bss_conf.beacon_int) / 1000;
1408 }
1409
Michal Kaziorad088bf2013-10-16 15:44:46 +03001410 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001411 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001413 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001414 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001415 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001416 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417 } else {
1418 psmode = WMI_STA_PS_MODE_DISABLED;
1419 }
1420
Michal Kazior7aa7a722014-08-25 12:09:38 +02001421 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001422 arvif->vdev_id, psmode ? "enable" : "disable");
1423
Michal Kaziorad088bf2013-10-16 15:44:46 +03001424 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1425 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001426 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001427 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001428 return ret;
1429 }
1430
1431 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001432}
1433
Michal Kazior46725b152015-01-28 09:57:49 +02001434static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1435{
1436 struct ath10k *ar = arvif->ar;
1437 struct wmi_sta_keepalive_arg arg = {};
1438 int ret;
1439
1440 lockdep_assert_held(&arvif->ar->conf_mutex);
1441
1442 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1443 return 0;
1444
1445 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1446 return 0;
1447
1448 /* Some firmware revisions have a bug and ignore the `enabled` field.
1449 * Instead use the interval to disable the keepalive.
1450 */
1451 arg.vdev_id = arvif->vdev_id;
1452 arg.enabled = 1;
1453 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1454 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1455
1456 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1457 if (ret) {
1458 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1459 arvif->vdev_id, ret);
1460 return ret;
1461 }
1462
1463 return 0;
1464}
1465
Michal Kazior81a9a172015-03-05 16:02:17 +02001466static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1467{
1468 struct ath10k *ar = arvif->ar;
1469 struct ieee80211_vif *vif = arvif->vif;
1470 int ret;
1471
Michal Kazior8513d952015-03-09 14:19:24 +01001472 lockdep_assert_held(&arvif->ar->conf_mutex);
1473
1474 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1475 return;
1476
Michal Kazior81a9a172015-03-05 16:02:17 +02001477 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1478 return;
1479
1480 if (!vif->csa_active)
1481 return;
1482
1483 if (!arvif->is_up)
1484 return;
1485
1486 if (!ieee80211_csa_is_complete(vif)) {
1487 ieee80211_csa_update_counter(vif);
1488
1489 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1490 if (ret)
1491 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1492 ret);
1493
1494 ret = ath10k_mac_setup_prb_tmpl(arvif);
1495 if (ret)
1496 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1497 ret);
1498 } else {
1499 ieee80211_csa_finish(vif);
1500 }
1501}
1502
1503static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1504{
1505 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1506 ap_csa_work);
1507 struct ath10k *ar = arvif->ar;
1508
1509 mutex_lock(&ar->conf_mutex);
1510 ath10k_mac_vif_ap_csa_count_down(arvif);
1511 mutex_unlock(&ar->conf_mutex);
1512}
1513
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001514static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1515 struct ieee80211_vif *vif)
1516{
1517 struct sk_buff *skb = data;
1518 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1519 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1520
1521 if (vif->type != NL80211_IFTYPE_STATION)
1522 return;
1523
1524 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1525 return;
1526
1527 cancel_delayed_work(&arvif->connection_loss_work);
1528}
1529
1530void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1531{
1532 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1533 IEEE80211_IFACE_ITER_NORMAL,
1534 ath10k_mac_handle_beacon_iter,
1535 skb);
1536}
1537
1538static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1539 struct ieee80211_vif *vif)
1540{
1541 u32 *vdev_id = data;
1542 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1543 struct ath10k *ar = arvif->ar;
1544 struct ieee80211_hw *hw = ar->hw;
1545
1546 if (arvif->vdev_id != *vdev_id)
1547 return;
1548
1549 if (!arvif->is_up)
1550 return;
1551
1552 ieee80211_beacon_loss(vif);
1553
1554 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1555 * (done by mac80211) succeeds but beacons do not resume then it
1556 * doesn't make sense to continue operation. Queue connection loss work
1557 * which can be cancelled when beacon is received.
1558 */
1559 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1560 ATH10K_CONNECTION_LOSS_HZ);
1561}
1562
1563void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1564{
1565 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1566 IEEE80211_IFACE_ITER_NORMAL,
1567 ath10k_mac_handle_beacon_miss_iter,
1568 &vdev_id);
1569}
1570
1571static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1572{
1573 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1574 connection_loss_work.work);
1575 struct ieee80211_vif *vif = arvif->vif;
1576
1577 if (!arvif->is_up)
1578 return;
1579
1580 ieee80211_connection_loss(vif);
1581}
1582
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583/**********************/
1584/* Station management */
1585/**********************/
1586
Michal Kazior590922a2014-10-21 10:10:29 +03001587static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1588 struct ieee80211_vif *vif)
1589{
1590 /* Some firmware revisions have unstable STA powersave when listen
1591 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1592 * generate NullFunc frames properly even if buffered frames have been
1593 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1594 * buffered frames. Often pinging the device from AP would simply fail.
1595 *
1596 * As a workaround set it to 1.
1597 */
1598 if (vif->type == NL80211_IFTYPE_STATION)
1599 return 1;
1600
1601 return ar->hw->conf.listen_interval;
1602}
1603
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001605 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 struct wmi_peer_assoc_complete_arg *arg)
1608{
Michal Kazior590922a2014-10-21 10:10:29 +03001609 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1610
Michal Kazior548db542013-07-05 16:15:15 +03001611 lockdep_assert_held(&ar->conf_mutex);
1612
Kalle Valob25f32c2014-09-14 12:50:49 +03001613 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001614 arg->vdev_id = arvif->vdev_id;
1615 arg->peer_aid = sta->aid;
1616 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001617 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001619 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001620}
1621
1622static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001623 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 struct wmi_peer_assoc_complete_arg *arg)
1625{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626 struct ieee80211_bss_conf *info = &vif->bss_conf;
1627 struct cfg80211_bss *bss;
1628 const u8 *rsnie = NULL;
1629 const u8 *wpaie = NULL;
1630
Michal Kazior548db542013-07-05 16:15:15 +03001631 lockdep_assert_held(&ar->conf_mutex);
1632
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1634 info->bssid, NULL, 0, 0, 0);
1635 if (bss) {
1636 const struct cfg80211_bss_ies *ies;
1637
1638 rcu_read_lock();
1639 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1640
1641 ies = rcu_dereference(bss->ies);
1642
1643 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001644 WLAN_OUI_TYPE_MICROSOFT_WPA,
1645 ies->data,
1646 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 rcu_read_unlock();
1648 cfg80211_put_bss(ar->hw->wiphy, bss);
1649 }
1650
1651 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1652 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001653 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001654 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1655 }
1656
1657 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001658 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001659 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1660 }
1661}
1662
1663static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1664 struct ieee80211_sta *sta,
1665 struct wmi_peer_assoc_complete_arg *arg)
1666{
1667 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1668 const struct ieee80211_supported_band *sband;
1669 const struct ieee80211_rate *rates;
1670 u32 ratemask;
1671 int i;
1672
Michal Kazior548db542013-07-05 16:15:15 +03001673 lockdep_assert_held(&ar->conf_mutex);
1674
Kalle Valo5e3dd152013-06-12 20:52:10 +03001675 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1676 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1677 rates = sband->bitrates;
1678
1679 rateset->num_rates = 0;
1680
1681 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1682 if (!(ratemask & 1))
1683 continue;
1684
1685 rateset->rates[rateset->num_rates] = rates->hw_value;
1686 rateset->num_rates++;
1687 }
1688}
1689
1690static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1691 struct ieee80211_sta *sta,
1692 struct wmi_peer_assoc_complete_arg *arg)
1693{
1694 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001696 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697
Michal Kazior548db542013-07-05 16:15:15 +03001698 lockdep_assert_held(&ar->conf_mutex);
1699
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700 if (!ht_cap->ht_supported)
1701 return;
1702
1703 arg->peer_flags |= WMI_PEER_HT;
1704 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1705 ht_cap->ampdu_factor)) - 1;
1706
1707 arg->peer_mpdu_density =
1708 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1709
1710 arg->peer_ht_caps = ht_cap->cap;
1711 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1712
1713 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1714 arg->peer_flags |= WMI_PEER_LDPC;
1715
1716 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1717 arg->peer_flags |= WMI_PEER_40MHZ;
1718 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1719 }
1720
1721 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1722 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1723
1724 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1725 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1726
1727 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1728 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1729 arg->peer_flags |= WMI_PEER_STBC;
1730 }
1731
1732 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1734 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1735 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1736 arg->peer_rate_caps |= stbc;
1737 arg->peer_flags |= WMI_PEER_STBC;
1738 }
1739
Kalle Valo5e3dd152013-06-12 20:52:10 +03001740 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1741 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1742 else if (ht_cap->mcs.rx_mask[1])
1743 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1744
1745 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1746 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1747 arg->peer_ht_rates.rates[n++] = i;
1748
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001749 /*
1750 * This is a workaround for HT-enabled STAs which break the spec
1751 * and have no HT capabilities RX mask (no HT RX MCS map).
1752 *
1753 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1754 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1755 *
1756 * Firmware asserts if such situation occurs.
1757 */
1758 if (n == 0) {
1759 arg->peer_ht_rates.num_rates = 8;
1760 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1761 arg->peer_ht_rates.rates[i] = i;
1762 } else {
1763 arg->peer_ht_rates.num_rates = n;
1764 arg->peer_num_spatial_streams = sta->rx_nss;
1765 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766
Michal Kazior7aa7a722014-08-25 12:09:38 +02001767 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001768 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001769 arg->peer_ht_rates.num_rates,
1770 arg->peer_num_spatial_streams);
1771}
1772
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001773static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1774 struct ath10k_vif *arvif,
1775 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776{
1777 u32 uapsd = 0;
1778 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001779 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001780
Michal Kazior548db542013-07-05 16:15:15 +03001781 lockdep_assert_held(&ar->conf_mutex);
1782
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001784 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 sta->uapsd_queues, sta->max_sp);
1786
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1788 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1789 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1790 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1791 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1792 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1793 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1794 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1795 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1796 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1797 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1798 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1799
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1801 max_sp = sta->max_sp;
1802
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001803 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1804 sta->addr,
1805 WMI_AP_PS_PEER_PARAM_UAPSD,
1806 uapsd);
1807 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001808 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001809 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001810 return ret;
1811 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001812
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001813 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1814 sta->addr,
1815 WMI_AP_PS_PEER_PARAM_MAX_SP,
1816 max_sp);
1817 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001818 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001819 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001820 return ret;
1821 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001822
1823 /* TODO setup this based on STA listen interval and
1824 beacon interval. Currently we don't know
1825 sta->listen_interval - mac80211 patch required.
1826 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001827 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001828 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1829 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001830 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001831 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001832 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001833 return ret;
1834 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001837 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001838}
1839
1840static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1841 struct ieee80211_sta *sta,
1842 struct wmi_peer_assoc_complete_arg *arg)
1843{
1844 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001845 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001846
1847 if (!vht_cap->vht_supported)
1848 return;
1849
1850 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001851
1852 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1853 arg->peer_flags |= WMI_PEER_VHT_2G;
1854
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855 arg->peer_vht_caps = vht_cap->cap;
1856
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001857 ampdu_factor = (vht_cap->cap &
1858 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1859 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1860
1861 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1862 * zero in VHT IE. Using it would result in degraded throughput.
1863 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1864 * it if VHT max_mpdu is smaller. */
1865 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1866 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1867 ampdu_factor)) - 1);
1868
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1870 arg->peer_flags |= WMI_PEER_80MHZ;
1871
1872 arg->peer_vht_rates.rx_max_rate =
1873 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1874 arg->peer_vht_rates.rx_mcs_set =
1875 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1876 arg->peer_vht_rates.tx_max_rate =
1877 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1878 arg->peer_vht_rates.tx_mcs_set =
1879 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1880
Michal Kazior7aa7a722014-08-25 12:09:38 +02001881 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001882 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001883}
1884
1885static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001886 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001887 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001888 struct wmi_peer_assoc_complete_arg *arg)
1889{
Michal Kazior590922a2014-10-21 10:10:29 +03001890 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1891
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892 switch (arvif->vdev_type) {
1893 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001894 if (sta->wme)
1895 arg->peer_flags |= WMI_PEER_QOS;
1896
1897 if (sta->wme && sta->uapsd_queues) {
1898 arg->peer_flags |= WMI_PEER_APSD;
1899 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1900 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001901 break;
1902 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001903 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001904 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001906 case WMI_VDEV_TYPE_IBSS:
1907 if (sta->wme)
1908 arg->peer_flags |= WMI_PEER_QOS;
1909 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001910 default:
1911 break;
1912 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001913
1914 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1915 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916}
1917
Michal Kazior91b12082014-12-12 12:41:35 +01001918static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1919{
1920 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1921 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1922}
1923
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001925 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926 struct ieee80211_sta *sta,
1927 struct wmi_peer_assoc_complete_arg *arg)
1928{
1929 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1930
Kalle Valo5e3dd152013-06-12 20:52:10 +03001931 switch (ar->hw->conf.chandef.chan->band) {
1932 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001933 if (sta->vht_cap.vht_supported) {
1934 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1935 phymode = MODE_11AC_VHT40;
1936 else
1937 phymode = MODE_11AC_VHT20;
1938 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1940 phymode = MODE_11NG_HT40;
1941 else
1942 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001943 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001945 } else {
1946 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001947 }
1948
1949 break;
1950 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001951 /*
1952 * Check VHT first.
1953 */
1954 if (sta->vht_cap.vht_supported) {
1955 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1956 phymode = MODE_11AC_VHT80;
1957 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1958 phymode = MODE_11AC_VHT40;
1959 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1960 phymode = MODE_11AC_VHT20;
1961 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1963 phymode = MODE_11NA_HT40;
1964 else
1965 phymode = MODE_11NA_HT20;
1966 } else {
1967 phymode = MODE_11A;
1968 }
1969
1970 break;
1971 default:
1972 break;
1973 }
1974
Michal Kazior7aa7a722014-08-25 12:09:38 +02001975 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001976 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001977
Kalle Valo5e3dd152013-06-12 20:52:10 +03001978 arg->peer_phymode = phymode;
1979 WARN_ON(phymode == MODE_UNKNOWN);
1980}
1981
Kalle Valob9ada652013-10-16 15:44:46 +03001982static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001983 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001984 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001985 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001986{
Michal Kazior548db542013-07-05 16:15:15 +03001987 lockdep_assert_held(&ar->conf_mutex);
1988
Kalle Valob9ada652013-10-16 15:44:46 +03001989 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990
Michal Kazior590922a2014-10-21 10:10:29 +03001991 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1992 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001993 ath10k_peer_assoc_h_rates(ar, sta, arg);
1994 ath10k_peer_assoc_h_ht(ar, sta, arg);
1995 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001996 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1997 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998
Kalle Valob9ada652013-10-16 15:44:46 +03001999 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002000}
2001
Michal Kazior90046f52014-02-14 14:45:51 +01002002static const u32 ath10k_smps_map[] = {
2003 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2004 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2005 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2006 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2007};
2008
2009static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2010 const u8 *addr,
2011 const struct ieee80211_sta_ht_cap *ht_cap)
2012{
2013 int smps;
2014
2015 if (!ht_cap->ht_supported)
2016 return 0;
2017
2018 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2019 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2020
2021 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2022 return -EINVAL;
2023
2024 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2025 WMI_PEER_SMPS_STATE,
2026 ath10k_smps_map[smps]);
2027}
2028
Michal Kazior139e1702015-02-15 16:50:42 +02002029static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2030 struct ieee80211_vif *vif,
2031 struct ieee80211_sta_vht_cap vht_cap)
2032{
2033 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2034 int ret;
2035 u32 param;
2036 u32 value;
2037
2038 if (!(ar->vht_cap_info &
2039 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2040 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2041 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2042 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2043 return 0;
2044
2045 param = ar->wmi.vdev_param->txbf;
2046 value = 0;
2047
2048 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2049 return 0;
2050
2051 /* The following logic is correct. If a remote STA advertises support
2052 * for being a beamformer then we should enable us being a beamformee.
2053 */
2054
2055 if (ar->vht_cap_info &
2056 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2057 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2058 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2059 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2060
2061 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2062 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2063 }
2064
2065 if (ar->vht_cap_info &
2066 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2067 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2068 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2069 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2070
2071 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2072 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2073 }
2074
2075 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2076 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2077
2078 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2079 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2080
2081 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2082 if (ret) {
2083 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2084 value, ret);
2085 return ret;
2086 }
2087
2088 return 0;
2089}
2090
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091/* can be called only in mac80211 callbacks due to `key_count` usage */
2092static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2093 struct ieee80211_vif *vif,
2094 struct ieee80211_bss_conf *bss_conf)
2095{
2096 struct ath10k *ar = hw->priv;
2097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002098 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002099 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002100 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101 struct ieee80211_sta *ap_sta;
2102 int ret;
2103
Michal Kazior548db542013-07-05 16:15:15 +03002104 lockdep_assert_held(&ar->conf_mutex);
2105
Michal Kazior077efc82014-10-21 10:10:29 +03002106 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2107 arvif->vdev_id, arvif->bssid, arvif->aid);
2108
Kalle Valo5e3dd152013-06-12 20:52:10 +03002109 rcu_read_lock();
2110
2111 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2112 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002113 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002114 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002115 rcu_read_unlock();
2116 return;
2117 }
2118
Michal Kazior90046f52014-02-14 14:45:51 +01002119 /* ap_sta must be accessed only within rcu section which must be left
2120 * before calling ath10k_setup_peer_smps() which might sleep. */
2121 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002122 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002123
Michal Kazior590922a2014-10-21 10:10:29 +03002124 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002125 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002126 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002127 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128 rcu_read_unlock();
2129 return;
2130 }
2131
2132 rcu_read_unlock();
2133
Kalle Valob9ada652013-10-16 15:44:46 +03002134 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2135 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002136 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002137 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002138 return;
2139 }
2140
Michal Kazior90046f52014-02-14 14:45:51 +01002141 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2142 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002143 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002144 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002145 return;
2146 }
2147
Michal Kazior139e1702015-02-15 16:50:42 +02002148 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2149 if (ret) {
2150 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2151 arvif->vdev_id, bss_conf->bssid, ret);
2152 return;
2153 }
2154
Michal Kazior7aa7a722014-08-25 12:09:38 +02002155 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002156 "mac vdev %d up (associated) bssid %pM aid %d\n",
2157 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2158
Michal Kazior077efc82014-10-21 10:10:29 +03002159 WARN_ON(arvif->is_up);
2160
Michal Kaziorc930f742014-01-23 11:38:25 +01002161 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002162 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002163
2164 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2165 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002166 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002167 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002168 return;
2169 }
2170
2171 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002172
2173 /* Workaround: Some firmware revisions (tested with qca6174
2174 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2175 * poked with peer param command.
2176 */
2177 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2178 WMI_PEER_DUMMY_VAR, 1);
2179 if (ret) {
2180 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2181 arvif->bssid, arvif->vdev_id, ret);
2182 return;
2183 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184}
2185
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2187 struct ieee80211_vif *vif)
2188{
2189 struct ath10k *ar = hw->priv;
2190 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002191 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 int ret;
2193
Michal Kazior548db542013-07-05 16:15:15 +03002194 lockdep_assert_held(&ar->conf_mutex);
2195
Michal Kazior077efc82014-10-21 10:10:29 +03002196 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2197 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002198
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002200 if (ret)
2201 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2202 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002204 arvif->def_wep_key_idx = -1;
2205
Michal Kazior139e1702015-02-15 16:50:42 +02002206 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2207 if (ret) {
2208 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2209 arvif->vdev_id, ret);
2210 return;
2211 }
2212
Michal Kaziorc930f742014-01-23 11:38:25 +01002213 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002214
2215 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216}
2217
Michal Kazior590922a2014-10-21 10:10:29 +03002218static int ath10k_station_assoc(struct ath10k *ar,
2219 struct ieee80211_vif *vif,
2220 struct ieee80211_sta *sta,
2221 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222{
Michal Kazior590922a2014-10-21 10:10:29 +03002223 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002224 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002225 int ret = 0;
2226
Michal Kazior548db542013-07-05 16:15:15 +03002227 lockdep_assert_held(&ar->conf_mutex);
2228
Michal Kazior590922a2014-10-21 10:10:29 +03002229 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002230 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002231 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002232 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002233 return ret;
2234 }
2235
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002236 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002237 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2238 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002239 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002240 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002241 return ret;
2242 }
2243
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002244 /* Re-assoc is run only to update supported rates for given station. It
2245 * doesn't make much sense to reconfigure the peer completely.
2246 */
2247 if (!reassoc) {
2248 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2249 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002250 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002251 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002252 arvif->vdev_id, ret);
2253 return ret;
2254 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002255
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002256 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2257 if (ret) {
2258 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2259 sta->addr, arvif->vdev_id, ret);
2260 return ret;
2261 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002262
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002263 if (!sta->wme) {
2264 arvif->num_legacy_stations++;
2265 ret = ath10k_recalc_rtscts_prot(arvif);
2266 if (ret) {
2267 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2268 arvif->vdev_id, ret);
2269 return ret;
2270 }
2271 }
2272
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002273 /* Plumb cached keys only for static WEP */
2274 if (arvif->def_wep_key_idx != -1) {
2275 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2276 if (ret) {
2277 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2278 arvif->vdev_id, ret);
2279 return ret;
2280 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 }
2282 }
2283
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284 return ret;
2285}
2286
Michal Kazior590922a2014-10-21 10:10:29 +03002287static int ath10k_station_disassoc(struct ath10k *ar,
2288 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289 struct ieee80211_sta *sta)
2290{
Michal Kazior590922a2014-10-21 10:10:29 +03002291 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292 int ret = 0;
2293
2294 lockdep_assert_held(&ar->conf_mutex);
2295
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002296 if (!sta->wme) {
2297 arvif->num_legacy_stations--;
2298 ret = ath10k_recalc_rtscts_prot(arvif);
2299 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002300 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002301 arvif->vdev_id, ret);
2302 return ret;
2303 }
2304 }
2305
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2307 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002308 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002309 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002310 return ret;
2311 }
2312
2313 return ret;
2314}
2315
2316/**************/
2317/* Regulatory */
2318/**************/
2319
2320static int ath10k_update_channel_list(struct ath10k *ar)
2321{
2322 struct ieee80211_hw *hw = ar->hw;
2323 struct ieee80211_supported_band **bands;
2324 enum ieee80211_band band;
2325 struct ieee80211_channel *channel;
2326 struct wmi_scan_chan_list_arg arg = {0};
2327 struct wmi_channel_arg *ch;
2328 bool passive;
2329 int len;
2330 int ret;
2331 int i;
2332
Michal Kazior548db542013-07-05 16:15:15 +03002333 lockdep_assert_held(&ar->conf_mutex);
2334
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335 bands = hw->wiphy->bands;
2336 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2337 if (!bands[band])
2338 continue;
2339
2340 for (i = 0; i < bands[band]->n_channels; i++) {
2341 if (bands[band]->channels[i].flags &
2342 IEEE80211_CHAN_DISABLED)
2343 continue;
2344
2345 arg.n_channels++;
2346 }
2347 }
2348
2349 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2350 arg.channels = kzalloc(len, GFP_KERNEL);
2351 if (!arg.channels)
2352 return -ENOMEM;
2353
2354 ch = arg.channels;
2355 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2356 if (!bands[band])
2357 continue;
2358
2359 for (i = 0; i < bands[band]->n_channels; i++) {
2360 channel = &bands[band]->channels[i];
2361
2362 if (channel->flags & IEEE80211_CHAN_DISABLED)
2363 continue;
2364
2365 ch->allow_ht = true;
2366
2367 /* FIXME: when should we really allow VHT? */
2368 ch->allow_vht = true;
2369
2370 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002371 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002372
2373 ch->ht40plus =
2374 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2375
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002376 ch->chan_radar =
2377 !!(channel->flags & IEEE80211_CHAN_RADAR);
2378
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002379 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002380 ch->passive = passive;
2381
2382 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002383 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002384 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002385 ch->max_power = channel->max_power * 2;
2386 ch->max_reg_power = channel->max_reg_power * 2;
2387 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002388 ch->reg_class_id = 0; /* FIXME */
2389
2390 /* FIXME: why use only legacy modes, why not any
2391 * HT/VHT modes? Would that even make any
2392 * difference? */
2393 if (channel->band == IEEE80211_BAND_2GHZ)
2394 ch->mode = MODE_11G;
2395 else
2396 ch->mode = MODE_11A;
2397
2398 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2399 continue;
2400
Michal Kazior7aa7a722014-08-25 12:09:38 +02002401 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002402 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2403 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002404 ch->freq, ch->max_power, ch->max_reg_power,
2405 ch->max_antenna_gain, ch->mode);
2406
2407 ch++;
2408 }
2409 }
2410
2411 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2412 kfree(arg.channels);
2413
2414 return ret;
2415}
2416
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002417static enum wmi_dfs_region
2418ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2419{
2420 switch (dfs_region) {
2421 case NL80211_DFS_UNSET:
2422 return WMI_UNINIT_DFS_DOMAIN;
2423 case NL80211_DFS_FCC:
2424 return WMI_FCC_DFS_DOMAIN;
2425 case NL80211_DFS_ETSI:
2426 return WMI_ETSI_DFS_DOMAIN;
2427 case NL80211_DFS_JP:
2428 return WMI_MKK4_DFS_DOMAIN;
2429 }
2430 return WMI_UNINIT_DFS_DOMAIN;
2431}
2432
Michal Kaziorf7843d72013-07-16 09:38:52 +02002433static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002434{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002435 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002436 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002437 enum wmi_dfs_region wmi_dfs_reg;
2438 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002439
Michal Kaziorf7843d72013-07-16 09:38:52 +02002440 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002441
2442 ret = ath10k_update_channel_list(ar);
2443 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002444 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445
2446 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002447
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002448 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2449 nl_dfs_reg = ar->dfs_detector->region;
2450 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2451 } else {
2452 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2453 }
2454
Kalle Valo5e3dd152013-06-12 20:52:10 +03002455 /* Target allows setting up per-band regdomain but ath_common provides
2456 * a combined one only */
2457 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002458 regpair->reg_domain,
2459 regpair->reg_domain, /* 2ghz */
2460 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002462 regpair->reg_5ghz_ctl,
2463 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002465 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002466}
Michal Kazior548db542013-07-05 16:15:15 +03002467
Michal Kaziorf7843d72013-07-16 09:38:52 +02002468static void ath10k_reg_notifier(struct wiphy *wiphy,
2469 struct regulatory_request *request)
2470{
2471 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2472 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002473 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002474
2475 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2476
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002477 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002478 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002479 request->dfs_region);
2480 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2481 request->dfs_region);
2482 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002483 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002484 request->dfs_region);
2485 }
2486
Michal Kaziorf7843d72013-07-16 09:38:52 +02002487 mutex_lock(&ar->conf_mutex);
2488 if (ar->state == ATH10K_STATE_ON)
2489 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002490 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491}
2492
2493/***************/
2494/* TX handlers */
2495/***************/
2496
Michal Kazior42c3aa62013-10-02 11:03:38 +02002497static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2498{
2499 if (ieee80211_is_mgmt(hdr->frame_control))
2500 return HTT_DATA_TX_EXT_TID_MGMT;
2501
2502 if (!ieee80211_is_data_qos(hdr->frame_control))
2503 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2504
2505 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2506 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2507
2508 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2509}
2510
Michal Kazior2b37c292014-09-02 11:00:22 +03002511static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002512{
Michal Kazior2b37c292014-09-02 11:00:22 +03002513 if (vif)
2514 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002515
Michal Kazior1bbc0972014-04-08 09:45:47 +03002516 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002517 return ar->monitor_vdev_id;
2518
Michal Kazior7aa7a722014-08-25 12:09:38 +02002519 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002520 return 0;
2521}
2522
Michal Kazior4b604552014-07-21 21:03:09 +03002523/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2524 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525 */
Michal Kazior4b604552014-07-21 21:03:09 +03002526static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527{
2528 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002529 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002530 u8 *qos_ctl;
2531
2532 if (!ieee80211_is_data_qos(hdr->frame_control))
2533 return;
2534
2535 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002536 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2537 skb->data, (void *)qos_ctl - (void *)skb->data);
2538 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002539
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002540 /* Some firmware revisions don't handle sending QoS NullFunc well.
2541 * These frames are mainly used for CQM purposes so it doesn't really
2542 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002543 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002544 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002545 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002546 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002547
2548 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002549}
2550
Michal Kazior4b604552014-07-21 21:03:09 +03002551static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2552 struct ieee80211_vif *vif,
2553 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554{
2555 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002556 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2557
2558 /* This is case only for P2P_GO */
2559 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2560 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2561 return;
2562
2563 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2564 spin_lock_bh(&ar->data_lock);
2565 if (arvif->u.ap.noa_data)
2566 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2567 GFP_ATOMIC))
2568 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2569 arvif->u.ap.noa_data,
2570 arvif->u.ap.noa_len);
2571 spin_unlock_bh(&ar->data_lock);
2572 }
2573}
2574
Michal Kazior8d6d3622014-11-24 14:58:31 +01002575static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2576{
2577 /* FIXME: Not really sure since when the behaviour changed. At some
2578 * point new firmware stopped requiring creation of peer entries for
2579 * offchannel tx (and actually creating them causes issues with wmi-htc
2580 * tx credit replenishment and reliability). Assuming it's at least 3.4
2581 * because that's when the `freq` was introduced to TX_FRM HTT command.
2582 */
2583 return !(ar->htt.target_version_major >= 3 &&
2584 ar->htt.target_version_minor >= 4);
2585}
2586
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2588{
2589 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002590 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002591
Michal Kazior961d4c32013-08-09 10:13:34 +02002592 if (ar->htt.target_version_major >= 3) {
2593 /* Since HTT 3.0 there is no separate mgmt tx command */
2594 ret = ath10k_htt_tx(&ar->htt, skb);
2595 goto exit;
2596 }
2597
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002598 if (ieee80211_is_mgmt(hdr->frame_control)) {
2599 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2600 ar->fw_features)) {
2601 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2602 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002603 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002604 ret = -EBUSY;
2605 goto exit;
2606 }
2607
2608 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2609 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2610 } else {
2611 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2612 }
2613 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2614 ar->fw_features) &&
2615 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002616 /* FW does not report tx status properly for NullFunc frames
2617 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002618 * those frames when it detects link/beacon loss and depends
2619 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002620 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002621 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002622 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002623 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624
Michal Kazior961d4c32013-08-09 10:13:34 +02002625exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002627 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2628 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002629 ieee80211_free_txskb(ar->hw, skb);
2630 }
2631}
2632
2633void ath10k_offchan_tx_purge(struct ath10k *ar)
2634{
2635 struct sk_buff *skb;
2636
2637 for (;;) {
2638 skb = skb_dequeue(&ar->offchan_tx_queue);
2639 if (!skb)
2640 break;
2641
2642 ieee80211_free_txskb(ar->hw, skb);
2643 }
2644}
2645
2646void ath10k_offchan_tx_work(struct work_struct *work)
2647{
2648 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2649 struct ath10k_peer *peer;
2650 struct ieee80211_hdr *hdr;
2651 struct sk_buff *skb;
2652 const u8 *peer_addr;
2653 int vdev_id;
2654 int ret;
2655
2656 /* FW requirement: We must create a peer before FW will send out
2657 * an offchannel frame. Otherwise the frame will be stuck and
2658 * never transmitted. We delete the peer upon tx completion.
2659 * It is unlikely that a peer for offchannel tx will already be
2660 * present. However it may be in some rare cases so account for that.
2661 * Otherwise we might remove a legitimate peer and break stuff. */
2662
2663 for (;;) {
2664 skb = skb_dequeue(&ar->offchan_tx_queue);
2665 if (!skb)
2666 break;
2667
2668 mutex_lock(&ar->conf_mutex);
2669
Michal Kazior7aa7a722014-08-25 12:09:38 +02002670 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002671 skb);
2672
2673 hdr = (struct ieee80211_hdr *)skb->data;
2674 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002675 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002676
2677 spin_lock_bh(&ar->data_lock);
2678 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2679 spin_unlock_bh(&ar->data_lock);
2680
2681 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002682 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002683 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002684 peer_addr, vdev_id);
2685
2686 if (!peer) {
2687 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2688 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002689 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690 peer_addr, vdev_id, ret);
2691 }
2692
2693 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002694 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 ar->offchan_tx_skb = skb;
2696 spin_unlock_bh(&ar->data_lock);
2697
2698 ath10k_tx_htt(ar, skb);
2699
2700 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2701 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002702 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002703 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704 skb);
2705
2706 if (!peer) {
2707 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2708 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002710 peer_addr, vdev_id, ret);
2711 }
2712
2713 mutex_unlock(&ar->conf_mutex);
2714 }
2715}
2716
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002717void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2718{
2719 struct sk_buff *skb;
2720
2721 for (;;) {
2722 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2723 if (!skb)
2724 break;
2725
2726 ieee80211_free_txskb(ar->hw, skb);
2727 }
2728}
2729
2730void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2731{
2732 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2733 struct sk_buff *skb;
2734 int ret;
2735
2736 for (;;) {
2737 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2738 if (!skb)
2739 break;
2740
2741 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002742 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002743 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002744 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002745 ieee80211_free_txskb(ar->hw, skb);
2746 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002747 }
2748}
2749
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750/************/
2751/* Scanning */
2752/************/
2753
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002754void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002755{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002756 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002758 switch (ar->scan.state) {
2759 case ATH10K_SCAN_IDLE:
2760 break;
2761 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002762 if (ar->scan.is_roc)
2763 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002764 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002765 case ATH10K_SCAN_ABORTING:
2766 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002767 ieee80211_scan_completed(ar->hw,
2768 (ar->scan.state ==
2769 ATH10K_SCAN_ABORTING));
2770 /* fall through */
2771 case ATH10K_SCAN_STARTING:
2772 ar->scan.state = ATH10K_SCAN_IDLE;
2773 ar->scan_channel = NULL;
2774 ath10k_offchan_tx_purge(ar);
2775 cancel_delayed_work(&ar->scan.timeout);
2776 complete_all(&ar->scan.completed);
2777 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002779}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002780
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002781void ath10k_scan_finish(struct ath10k *ar)
2782{
2783 spin_lock_bh(&ar->data_lock);
2784 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002785 spin_unlock_bh(&ar->data_lock);
2786}
2787
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002788static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002789{
2790 struct wmi_stop_scan_arg arg = {
2791 .req_id = 1, /* FIXME */
2792 .req_type = WMI_SCAN_STOP_ONE,
2793 .u.scan_id = ATH10K_SCAN_ID,
2794 };
2795 int ret;
2796
2797 lockdep_assert_held(&ar->conf_mutex);
2798
Kalle Valo5e3dd152013-06-12 20:52:10 +03002799 ret = ath10k_wmi_stop_scan(ar, &arg);
2800 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002801 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002802 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803 }
2804
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002806 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002807 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002808 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002809 } else if (ret > 0) {
2810 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002811 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002812
2813out:
2814 /* Scan state should be updated upon scan completion but in case
2815 * firmware fails to deliver the event (for whatever reason) it is
2816 * desired to clean up scan state anyway. Firmware may have just
2817 * dropped the scan completion event delivery due to transport pipe
2818 * being overflown with data and/or it can recover on its own before
2819 * next scan request is submitted.
2820 */
2821 spin_lock_bh(&ar->data_lock);
2822 if (ar->scan.state != ATH10K_SCAN_IDLE)
2823 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824 spin_unlock_bh(&ar->data_lock);
2825
2826 return ret;
2827}
2828
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002829static void ath10k_scan_abort(struct ath10k *ar)
2830{
2831 int ret;
2832
2833 lockdep_assert_held(&ar->conf_mutex);
2834
2835 spin_lock_bh(&ar->data_lock);
2836
2837 switch (ar->scan.state) {
2838 case ATH10K_SCAN_IDLE:
2839 /* This can happen if timeout worker kicked in and called
2840 * abortion while scan completion was being processed.
2841 */
2842 break;
2843 case ATH10K_SCAN_STARTING:
2844 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002845 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002846 ath10k_scan_state_str(ar->scan.state),
2847 ar->scan.state);
2848 break;
2849 case ATH10K_SCAN_RUNNING:
2850 ar->scan.state = ATH10K_SCAN_ABORTING;
2851 spin_unlock_bh(&ar->data_lock);
2852
2853 ret = ath10k_scan_stop(ar);
2854 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002855 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002856
2857 spin_lock_bh(&ar->data_lock);
2858 break;
2859 }
2860
2861 spin_unlock_bh(&ar->data_lock);
2862}
2863
2864void ath10k_scan_timeout_work(struct work_struct *work)
2865{
2866 struct ath10k *ar = container_of(work, struct ath10k,
2867 scan.timeout.work);
2868
2869 mutex_lock(&ar->conf_mutex);
2870 ath10k_scan_abort(ar);
2871 mutex_unlock(&ar->conf_mutex);
2872}
2873
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874static int ath10k_start_scan(struct ath10k *ar,
2875 const struct wmi_start_scan_arg *arg)
2876{
2877 int ret;
2878
2879 lockdep_assert_held(&ar->conf_mutex);
2880
2881 ret = ath10k_wmi_start_scan(ar, arg);
2882 if (ret)
2883 return ret;
2884
Kalle Valo5e3dd152013-06-12 20:52:10 +03002885 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2886 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002887 ret = ath10k_scan_stop(ar);
2888 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002889 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002890
2891 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002892 }
2893
Ben Greear2f9eec02015-02-15 16:50:38 +02002894 /* If we failed to start the scan, return error code at
2895 * this point. This is probably due to some issue in the
2896 * firmware, but no need to wedge the driver due to that...
2897 */
2898 spin_lock_bh(&ar->data_lock);
2899 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2900 spin_unlock_bh(&ar->data_lock);
2901 return -EINVAL;
2902 }
2903 spin_unlock_bh(&ar->data_lock);
2904
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002905 /* Add a 200ms margin to account for event/command processing */
2906 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2907 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002908 return 0;
2909}
2910
2911/**********************/
2912/* mac80211 callbacks */
2913/**********************/
2914
2915static void ath10k_tx(struct ieee80211_hw *hw,
2916 struct ieee80211_tx_control *control,
2917 struct sk_buff *skb)
2918{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002920 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2921 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002922 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002923
2924 /* We should disable CCK RATE due to P2P */
2925 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002926 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002927
Michal Kazior4b604552014-07-21 21:03:09 +03002928 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2929 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002930 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002931
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002932 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002933 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2934 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002935 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2936 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002937 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002938
Kalle Valo5e3dd152013-06-12 20:52:10 +03002939 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2940 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002941 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002942 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002943 spin_unlock_bh(&ar->data_lock);
2944
Michal Kazior8d6d3622014-11-24 14:58:31 +01002945 if (ath10k_mac_need_offchan_tx_work(ar)) {
2946 ATH10K_SKB_CB(skb)->htt.freq = 0;
2947 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002948
Michal Kazior8d6d3622014-11-24 14:58:31 +01002949 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2950 skb);
2951
2952 skb_queue_tail(&ar->offchan_tx_queue, skb);
2953 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2954 return;
2955 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002956 }
2957
2958 ath10k_tx_htt(ar, skb);
2959}
2960
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002961/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002962void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002963{
2964 /* make sure rcu-protected mac80211 tx path itself is drained */
2965 synchronize_net();
2966
2967 ath10k_offchan_tx_purge(ar);
2968 ath10k_mgmt_over_wmi_tx_purge(ar);
2969
2970 cancel_work_sync(&ar->offchan_tx_work);
2971 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2972}
2973
Michal Kazioraffd3212013-07-16 09:54:35 +02002974void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002975{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002976 struct ath10k_vif *arvif;
2977
Michal Kazior818bdd12013-07-16 09:38:57 +02002978 lockdep_assert_held(&ar->conf_mutex);
2979
Michal Kazior19337472014-08-28 12:58:16 +02002980 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2981 ar->filter_flags = 0;
2982 ar->monitor = false;
2983
2984 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002985 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002986
2987 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002988
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002989 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002990 ath10k_peer_cleanup_all(ar);
2991 ath10k_core_stop(ar);
2992 ath10k_hif_power_down(ar);
2993
2994 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002995 list_for_each_entry(arvif, &ar->arvifs, list)
2996 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002997 spin_unlock_bh(&ar->data_lock);
2998}
2999
Ben Greear46acf7b2014-05-16 17:15:38 +03003000static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3001{
3002 struct ath10k *ar = hw->priv;
3003
3004 mutex_lock(&ar->conf_mutex);
3005
3006 if (ar->cfg_tx_chainmask) {
3007 *tx_ant = ar->cfg_tx_chainmask;
3008 *rx_ant = ar->cfg_rx_chainmask;
3009 } else {
3010 *tx_ant = ar->supp_tx_chainmask;
3011 *rx_ant = ar->supp_rx_chainmask;
3012 }
3013
3014 mutex_unlock(&ar->conf_mutex);
3015
3016 return 0;
3017}
3018
Ben Greear5572a952014-11-24 16:22:10 +02003019static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3020{
3021 /* It is not clear that allowing gaps in chainmask
3022 * is helpful. Probably it will not do what user
3023 * is hoping for, so warn in that case.
3024 */
3025 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3026 return;
3027
3028 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3029 dbg, cm);
3030}
3031
Ben Greear46acf7b2014-05-16 17:15:38 +03003032static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3033{
3034 int ret;
3035
3036 lockdep_assert_held(&ar->conf_mutex);
3037
Ben Greear5572a952014-11-24 16:22:10 +02003038 ath10k_check_chain_mask(ar, tx_ant, "tx");
3039 ath10k_check_chain_mask(ar, rx_ant, "rx");
3040
Ben Greear46acf7b2014-05-16 17:15:38 +03003041 ar->cfg_tx_chainmask = tx_ant;
3042 ar->cfg_rx_chainmask = rx_ant;
3043
3044 if ((ar->state != ATH10K_STATE_ON) &&
3045 (ar->state != ATH10K_STATE_RESTARTED))
3046 return 0;
3047
3048 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3049 tx_ant);
3050 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003051 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003052 ret, tx_ant);
3053 return ret;
3054 }
3055
3056 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3057 rx_ant);
3058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003059 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003060 ret, rx_ant);
3061 return ret;
3062 }
3063
3064 return 0;
3065}
3066
3067static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3068{
3069 struct ath10k *ar = hw->priv;
3070 int ret;
3071
3072 mutex_lock(&ar->conf_mutex);
3073 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3074 mutex_unlock(&ar->conf_mutex);
3075 return ret;
3076}
3077
Kalle Valo5e3dd152013-06-12 20:52:10 +03003078static int ath10k_start(struct ieee80211_hw *hw)
3079{
3080 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003081 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003082
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003083 /*
3084 * This makes sense only when restarting hw. It is harmless to call
3085 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3086 * commands will be submitted while restarting.
3087 */
3088 ath10k_drain_tx(ar);
3089
Michal Kazior548db542013-07-05 16:15:15 +03003090 mutex_lock(&ar->conf_mutex);
3091
Michal Kaziorc5058f52014-05-26 12:46:03 +03003092 switch (ar->state) {
3093 case ATH10K_STATE_OFF:
3094 ar->state = ATH10K_STATE_ON;
3095 break;
3096 case ATH10K_STATE_RESTARTING:
3097 ath10k_halt(ar);
3098 ar->state = ATH10K_STATE_RESTARTED;
3099 break;
3100 case ATH10K_STATE_ON:
3101 case ATH10K_STATE_RESTARTED:
3102 case ATH10K_STATE_WEDGED:
3103 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003104 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003105 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003106 case ATH10K_STATE_UTF:
3107 ret = -EBUSY;
3108 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003109 }
3110
3111 ret = ath10k_hif_power_up(ar);
3112 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003113 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003114 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003115 }
3116
Kalle Valo43d2a302014-09-10 18:23:30 +03003117 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003118 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003119 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003120 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003121 }
3122
Bartosz Markowski226a3392013-09-26 17:47:16 +02003123 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003124 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003125 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003126 goto err_core_stop;
3127 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003129 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003130 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003131 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003132 goto err_core_stop;
3133 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003134
Ben Greear46acf7b2014-05-16 17:15:38 +03003135 if (ar->cfg_tx_chainmask)
3136 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3137 ar->cfg_rx_chainmask);
3138
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003139 /*
3140 * By default FW set ARP frames ac to voice (6). In that case ARP
3141 * exchange is not working properly for UAPSD enabled AP. ARP requests
3142 * which arrives with access category 0 are processed by network stack
3143 * and send back with access category 0, but FW changes access category
3144 * to 6. Set ARP frames access category to best effort (0) solves
3145 * this problem.
3146 */
3147
3148 ret = ath10k_wmi_pdev_set_param(ar,
3149 ar->wmi.pdev_param->arp_ac_override, 0);
3150 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003151 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003152 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003153 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003154 }
3155
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303156 ret = ath10k_wmi_pdev_set_param(ar,
3157 ar->wmi.pdev_param->ani_enable, 1);
3158 if (ret) {
3159 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3160 ret);
3161 goto err_core_stop;
3162 }
3163
Michal Kaziord6500972014-04-08 09:56:09 +03003164 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003165 ath10k_regd_update(ar);
3166
Simon Wunderlich855aed12014-08-02 09:12:54 +03003167 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303168 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003169
Michal Kaziorae254432014-05-26 12:46:02 +03003170 mutex_unlock(&ar->conf_mutex);
3171 return 0;
3172
3173err_core_stop:
3174 ath10k_core_stop(ar);
3175
3176err_power_down:
3177 ath10k_hif_power_down(ar);
3178
3179err_off:
3180 ar->state = ATH10K_STATE_OFF;
3181
3182err:
Michal Kazior548db542013-07-05 16:15:15 +03003183 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003184 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003185}
3186
3187static void ath10k_stop(struct ieee80211_hw *hw)
3188{
3189 struct ath10k *ar = hw->priv;
3190
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003191 ath10k_drain_tx(ar);
3192
Michal Kazior548db542013-07-05 16:15:15 +03003193 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003194 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003195 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003196 ar->state = ATH10K_STATE_OFF;
3197 }
Michal Kazior548db542013-07-05 16:15:15 +03003198 mutex_unlock(&ar->conf_mutex);
3199
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003200 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003201 cancel_work_sync(&ar->restart_work);
3202}
3203
Michal Kaziorad088bf2013-10-16 15:44:46 +03003204static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003205{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003206 struct ath10k_vif *arvif;
3207 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003208
3209 lockdep_assert_held(&ar->conf_mutex);
3210
Michal Kaziorad088bf2013-10-16 15:44:46 +03003211 list_for_each_entry(arvif, &ar->arvifs, list) {
3212 ret = ath10k_mac_vif_setup_ps(arvif);
3213 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003214 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003215 break;
3216 }
3217 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003218
Michal Kaziorad088bf2013-10-16 15:44:46 +03003219 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003220}
3221
Michal Kaziorc930f742014-01-23 11:38:25 +01003222static const char *chandef_get_width(enum nl80211_chan_width width)
3223{
3224 switch (width) {
3225 case NL80211_CHAN_WIDTH_20_NOHT:
3226 return "20 (noht)";
3227 case NL80211_CHAN_WIDTH_20:
3228 return "20";
3229 case NL80211_CHAN_WIDTH_40:
3230 return "40";
3231 case NL80211_CHAN_WIDTH_80:
3232 return "80";
3233 case NL80211_CHAN_WIDTH_80P80:
3234 return "80+80";
3235 case NL80211_CHAN_WIDTH_160:
3236 return "160";
3237 case NL80211_CHAN_WIDTH_5:
3238 return "5";
3239 case NL80211_CHAN_WIDTH_10:
3240 return "10";
3241 }
3242 return "?";
3243}
3244
3245static void ath10k_config_chan(struct ath10k *ar)
3246{
3247 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003248 int ret;
3249
3250 lockdep_assert_held(&ar->conf_mutex);
3251
Michal Kazior7aa7a722014-08-25 12:09:38 +02003252 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003253 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3254 ar->chandef.chan->center_freq,
3255 ar->chandef.center_freq1,
3256 ar->chandef.center_freq2,
3257 chandef_get_width(ar->chandef.width));
3258
3259 /* First stop monitor interface. Some FW versions crash if there's a
3260 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003261 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003262 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003263
3264 list_for_each_entry(arvif, &ar->arvifs, list) {
3265 if (!arvif->is_started)
3266 continue;
3267
Michal Kaziordc55e302014-07-29 12:53:36 +03003268 if (!arvif->is_up)
3269 continue;
3270
Michal Kaziorc930f742014-01-23 11:38:25 +01003271 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3272 continue;
3273
Michal Kaziordc55e302014-07-29 12:53:36 +03003274 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003275 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003276 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003277 arvif->vdev_id, ret);
3278 continue;
3279 }
3280 }
3281
Michal Kaziordc55e302014-07-29 12:53:36 +03003282 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003283
3284 list_for_each_entry(arvif, &ar->arvifs, list) {
3285 if (!arvif->is_started)
3286 continue;
3287
3288 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3289 continue;
3290
Michal Kazior81a9a172015-03-05 16:02:17 +02003291 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3292 if (ret)
3293 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3294 ret);
3295
3296 ret = ath10k_mac_setup_prb_tmpl(arvif);
3297 if (ret)
3298 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3299 ret);
3300
Michal Kaziordc55e302014-07-29 12:53:36 +03003301 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003302 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003303 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003304 arvif->vdev_id, ret);
3305 continue;
3306 }
3307
3308 if (!arvif->is_up)
3309 continue;
3310
3311 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3312 arvif->bssid);
3313 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003314 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003315 arvif->vdev_id, ret);
3316 continue;
3317 }
3318 }
3319
Michal Kazior19337472014-08-28 12:58:16 +02003320 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003321}
3322
Michal Kazior7d9d5582014-10-21 10:40:15 +03003323static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3324{
3325 int ret;
3326 u32 param;
3327
3328 lockdep_assert_held(&ar->conf_mutex);
3329
3330 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3331
3332 param = ar->wmi.pdev_param->txpower_limit2g;
3333 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3334 if (ret) {
3335 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3336 txpower, ret);
3337 return ret;
3338 }
3339
3340 param = ar->wmi.pdev_param->txpower_limit5g;
3341 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3342 if (ret) {
3343 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3344 txpower, ret);
3345 return ret;
3346 }
3347
3348 return 0;
3349}
3350
3351static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3352{
3353 struct ath10k_vif *arvif;
3354 int ret, txpower = -1;
3355
3356 lockdep_assert_held(&ar->conf_mutex);
3357
3358 list_for_each_entry(arvif, &ar->arvifs, list) {
3359 WARN_ON(arvif->txpower < 0);
3360
3361 if (txpower == -1)
3362 txpower = arvif->txpower;
3363 else
3364 txpower = min(txpower, arvif->txpower);
3365 }
3366
3367 if (WARN_ON(txpower == -1))
3368 return -EINVAL;
3369
3370 ret = ath10k_mac_txpower_setup(ar, txpower);
3371 if (ret) {
3372 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3373 txpower, ret);
3374 return ret;
3375 }
3376
3377 return 0;
3378}
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3381{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003382 struct ath10k *ar = hw->priv;
3383 struct ieee80211_conf *conf = &hw->conf;
3384 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385
3386 mutex_lock(&ar->conf_mutex);
3387
3388 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003389 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003390 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003391 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003392 conf->chandef.chan->flags,
3393 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003394
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395 spin_lock_bh(&ar->data_lock);
3396 ar->rx_channel = conf->chandef.chan;
3397 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003398
Michal Kaziord6500972014-04-08 09:56:09 +03003399 ar->radar_enabled = conf->radar_enabled;
3400 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003401
3402 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3403 ar->chandef = conf->chandef;
3404 ath10k_config_chan(ar);
3405 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003406 }
3407
Michal Kazioraffd3212013-07-16 09:54:35 +02003408 if (changed & IEEE80211_CONF_CHANGE_PS)
3409 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003410
3411 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003412 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3413 ret = ath10k_monitor_recalc(ar);
3414 if (ret)
3415 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003416 }
3417
3418 mutex_unlock(&ar->conf_mutex);
3419 return ret;
3420}
3421
Ben Greear5572a952014-11-24 16:22:10 +02003422static u32 get_nss_from_chainmask(u16 chain_mask)
3423{
3424 if ((chain_mask & 0x15) == 0x15)
3425 return 4;
3426 else if ((chain_mask & 0x7) == 0x7)
3427 return 3;
3428 else if ((chain_mask & 0x3) == 0x3)
3429 return 2;
3430 return 1;
3431}
3432
Kalle Valo5e3dd152013-06-12 20:52:10 +03003433/*
3434 * TODO:
3435 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3436 * because we will send mgmt frames without CCK. This requirement
3437 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3438 * in the TX packet.
3439 */
3440static int ath10k_add_interface(struct ieee80211_hw *hw,
3441 struct ieee80211_vif *vif)
3442{
3443 struct ath10k *ar = hw->priv;
3444 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3445 enum wmi_sta_powersave_param param;
3446 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003447 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003449 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003450
Johannes Berg848955c2014-11-11 12:48:42 +01003451 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3452
Kalle Valo5e3dd152013-06-12 20:52:10 +03003453 mutex_lock(&ar->conf_mutex);
3454
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003455 memset(arvif, 0, sizeof(*arvif));
3456
Kalle Valo5e3dd152013-06-12 20:52:10 +03003457 arvif->ar = ar;
3458 arvif->vif = vif;
3459
Ben Greeare63b33f2013-10-22 14:54:14 -07003460 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003461 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003462 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3463 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003464
Ben Greeara9aefb32014-08-12 11:02:19 +03003465 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003466 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003468 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469 }
Ben Greear16c11172014-09-23 14:17:16 -07003470 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003471
Ben Greear16c11172014-09-23 14:17:16 -07003472 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3473 bit, ar->free_vdev_map);
3474
3475 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003477
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003479 case NL80211_IFTYPE_P2P_DEVICE:
3480 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3481 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3482 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003483 case NL80211_IFTYPE_UNSPECIFIED:
3484 case NL80211_IFTYPE_STATION:
3485 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3486 if (vif->p2p)
3487 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3488 break;
3489 case NL80211_IFTYPE_ADHOC:
3490 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3491 break;
3492 case NL80211_IFTYPE_AP:
3493 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3494
3495 if (vif->p2p)
3496 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3497 break;
3498 case NL80211_IFTYPE_MONITOR:
3499 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3500 break;
3501 default:
3502 WARN_ON(1);
3503 break;
3504 }
3505
Michal Kazior64badcb2014-09-18 11:18:02 +03003506 /* Some firmware revisions don't wait for beacon tx completion before
3507 * sending another SWBA event. This could lead to hardware using old
3508 * (freed) beacon data in some cases, e.g. tx credit starvation
3509 * combined with missed TBTT. This is very very rare.
3510 *
3511 * On non-IOMMU-enabled hosts this could be a possible security issue
3512 * because hw could beacon some random data on the air. On
3513 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3514 * device would crash.
3515 *
3516 * Since there are no beacon tx completions (implicit nor explicit)
3517 * propagated to host the only workaround for this is to allocate a
3518 * DMA-coherent buffer for a lifetime of a vif and use it for all
3519 * beacon tx commands. Worst case for this approach is some beacons may
3520 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3521 */
3522 if (vif->type == NL80211_IFTYPE_ADHOC ||
3523 vif->type == NL80211_IFTYPE_AP) {
3524 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3525 IEEE80211_MAX_FRAME_LEN,
3526 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303527 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003528 if (!arvif->beacon_buf) {
3529 ret = -ENOMEM;
3530 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3531 ret);
3532 goto err;
3533 }
3534 }
3535
3536 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3537 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3538 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003539
3540 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3541 arvif->vdev_subtype, vif->addr);
3542 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003543 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003544 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003545 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 }
3547
Ben Greear16c11172014-09-23 14:17:16 -07003548 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003549 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003550
Michal Kazior46725b152015-01-28 09:57:49 +02003551 /* It makes no sense to have firmware do keepalives. mac80211 already
3552 * takes care of this with idle connection polling.
3553 */
3554 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003555 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003556 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003557 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003558 goto err_vdev_delete;
3559 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003561 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003563 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3564 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003565 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003566 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003567 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003568 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003569 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003570 goto err_vdev_delete;
3571 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003572
Ben Greear5572a952014-11-24 16:22:10 +02003573 if (ar->cfg_tx_chainmask) {
3574 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3575
3576 vdev_param = ar->wmi.vdev_param->nss;
3577 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3578 nss);
3579 if (ret) {
3580 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3581 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3582 ret);
3583 goto err_vdev_delete;
3584 }
3585 }
3586
Kalle Valo5e3dd152013-06-12 20:52:10 +03003587 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3588 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3589 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003590 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003591 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003592 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003593 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003594
Kalle Valo5a13e762014-01-20 11:01:46 +02003595 ret = ath10k_mac_set_kickout(arvif);
3596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003597 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003598 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003599 goto err_peer_delete;
3600 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003601 }
3602
3603 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3604 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3605 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3606 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3607 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003609 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003610 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003611 goto err_peer_delete;
3612 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003613
Michal Kazior9f9b5742014-12-12 12:41:36 +01003614 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003615 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003616 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003617 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003618 goto err_peer_delete;
3619 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620
Michal Kazior9f9b5742014-12-12 12:41:36 +01003621 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003622 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003623 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003624 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003625 goto err_peer_delete;
3626 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627 }
3628
Michal Kazior424121c2013-07-22 14:13:31 +02003629 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003630 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003631 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003632 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003633 goto err_peer_delete;
3634 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003635
Michal Kazior424121c2013-07-22 14:13:31 +02003636 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003637 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003638 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003639 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003640 goto err_peer_delete;
3641 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003642
Michal Kazior7d9d5582014-10-21 10:40:15 +03003643 arvif->txpower = vif->bss_conf.txpower;
3644 ret = ath10k_mac_txpower_recalc(ar);
3645 if (ret) {
3646 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3647 goto err_peer_delete;
3648 }
3649
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003651 return 0;
3652
3653err_peer_delete:
3654 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3655 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3656
3657err_vdev_delete:
3658 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003659 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003660 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003661
3662err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003663 if (arvif->beacon_buf) {
3664 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3665 arvif->beacon_buf, arvif->beacon_paddr);
3666 arvif->beacon_buf = NULL;
3667 }
3668
Michal Kazior9dad14a2013-10-16 15:44:45 +03003669 mutex_unlock(&ar->conf_mutex);
3670
Kalle Valo5e3dd152013-06-12 20:52:10 +03003671 return ret;
3672}
3673
3674static void ath10k_remove_interface(struct ieee80211_hw *hw,
3675 struct ieee80211_vif *vif)
3676{
3677 struct ath10k *ar = hw->priv;
3678 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3679 int ret;
3680
Michal Kazior81a9a172015-03-05 16:02:17 +02003681 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003682 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003683
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303684 mutex_lock(&ar->conf_mutex);
3685
Michal Kaziored543882013-09-13 14:16:56 +02003686 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003687 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003688 spin_unlock_bh(&ar->data_lock);
3689
Simon Wunderlich855aed12014-08-02 09:12:54 +03003690 ret = ath10k_spectral_vif_stop(arvif);
3691 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003692 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003693 arvif->vdev_id, ret);
3694
Ben Greear16c11172014-09-23 14:17:16 -07003695 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003696 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003697
3698 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003699 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3700 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003701 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003702 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003703 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003704
3705 kfree(arvif->u.ap.noa_data);
3706 }
3707
Michal Kazior7aa7a722014-08-25 12:09:38 +02003708 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003709 arvif->vdev_id);
3710
Kalle Valo5e3dd152013-06-12 20:52:10 +03003711 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3712 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003713 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003714 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715
Michal Kazior2c512052015-02-15 16:50:40 +02003716 /* Some firmware revisions don't notify host about self-peer removal
3717 * until after associated vdev is deleted.
3718 */
3719 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3720 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3721 vif->addr);
3722 if (ret)
3723 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3724 arvif->vdev_id, ret);
3725
3726 spin_lock_bh(&ar->data_lock);
3727 ar->num_peers--;
3728 spin_unlock_bh(&ar->data_lock);
3729 }
3730
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 ath10k_peer_cleanup(ar, arvif->vdev_id);
3732
3733 mutex_unlock(&ar->conf_mutex);
3734}
3735
3736/*
3737 * FIXME: Has to be verified.
3738 */
3739#define SUPPORTED_FILTERS \
3740 (FIF_PROMISC_IN_BSS | \
3741 FIF_ALLMULTI | \
3742 FIF_CONTROL | \
3743 FIF_PSPOLL | \
3744 FIF_OTHER_BSS | \
3745 FIF_BCN_PRBRESP_PROMISC | \
3746 FIF_PROBE_REQ | \
3747 FIF_FCSFAIL)
3748
3749static void ath10k_configure_filter(struct ieee80211_hw *hw,
3750 unsigned int changed_flags,
3751 unsigned int *total_flags,
3752 u64 multicast)
3753{
3754 struct ath10k *ar = hw->priv;
3755 int ret;
3756
3757 mutex_lock(&ar->conf_mutex);
3758
3759 changed_flags &= SUPPORTED_FILTERS;
3760 *total_flags &= SUPPORTED_FILTERS;
3761 ar->filter_flags = *total_flags;
3762
Michal Kazior19337472014-08-28 12:58:16 +02003763 ret = ath10k_monitor_recalc(ar);
3764 if (ret)
3765 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003766
3767 mutex_unlock(&ar->conf_mutex);
3768}
3769
3770static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3771 struct ieee80211_vif *vif,
3772 struct ieee80211_bss_conf *info,
3773 u32 changed)
3774{
3775 struct ath10k *ar = hw->priv;
3776 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3777 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003778 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779
3780 mutex_lock(&ar->conf_mutex);
3781
3782 if (changed & BSS_CHANGED_IBSS)
3783 ath10k_control_ibss(arvif, info, vif->addr);
3784
3785 if (changed & BSS_CHANGED_BEACON_INT) {
3786 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003787 vdev_param = ar->wmi.vdev_param->beacon_interval;
3788 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003789 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003790 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003791 "mac vdev %d beacon_interval %d\n",
3792 arvif->vdev_id, arvif->beacon_interval);
3793
Kalle Valo5e3dd152013-06-12 20:52:10 +03003794 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003795 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003796 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003797 }
3798
3799 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003800 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003801 "vdev %d set beacon tx mode to staggered\n",
3802 arvif->vdev_id);
3803
Bartosz Markowski226a3392013-09-26 17:47:16 +02003804 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3805 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003806 WMI_BEACON_STAGGERED_MODE);
3807 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003808 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003809 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003810
3811 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3812 if (ret)
3813 ath10k_warn(ar, "failed to update beacon template: %d\n",
3814 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815 }
3816
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003817 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3818 ret = ath10k_mac_setup_prb_tmpl(arvif);
3819 if (ret)
3820 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3821 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003822 }
3823
Michal Kaziorba2479f2015-01-24 12:14:51 +02003824 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003825 arvif->dtim_period = info->dtim_period;
3826
Michal Kazior7aa7a722014-08-25 12:09:38 +02003827 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003828 "mac vdev %d dtim_period %d\n",
3829 arvif->vdev_id, arvif->dtim_period);
3830
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003831 vdev_param = ar->wmi.vdev_param->dtim_period;
3832 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003833 arvif->dtim_period);
3834 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003835 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003836 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003837 }
3838
3839 if (changed & BSS_CHANGED_SSID &&
3840 vif->type == NL80211_IFTYPE_AP) {
3841 arvif->u.ap.ssid_len = info->ssid_len;
3842 if (info->ssid_len)
3843 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3844 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3845 }
3846
Michal Kazior077efc82014-10-21 10:10:29 +03003847 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3848 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849
3850 if (changed & BSS_CHANGED_BEACON_ENABLED)
3851 ath10k_control_beaconing(arvif, info);
3852
3853 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003854 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003855 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003856 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003857
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003858 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003859 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003860 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003861 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003862
3863 vdev_param = ar->wmi.vdev_param->protection_mode;
3864 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3865 info->use_cts_prot ? 1 : 0);
3866 if (ret)
3867 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3868 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869 }
3870
3871 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003872 if (info->use_short_slot)
3873 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3874
3875 else
3876 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3877
Michal Kazior7aa7a722014-08-25 12:09:38 +02003878 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003879 arvif->vdev_id, slottime);
3880
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003881 vdev_param = ar->wmi.vdev_param->slot_time;
3882 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003883 slottime);
3884 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003885 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003886 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003887 }
3888
3889 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003890 if (info->use_short_preamble)
3891 preamble = WMI_VDEV_PREAMBLE_SHORT;
3892 else
3893 preamble = WMI_VDEV_PREAMBLE_LONG;
3894
Michal Kazior7aa7a722014-08-25 12:09:38 +02003895 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003896 "mac vdev %d preamble %dn",
3897 arvif->vdev_id, preamble);
3898
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003899 vdev_param = ar->wmi.vdev_param->preamble;
3900 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003901 preamble);
3902 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003903 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003904 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003905 }
3906
3907 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003908 if (info->assoc) {
3909 /* Workaround: Make sure monitor vdev is not running
3910 * when associating to prevent some firmware revisions
3911 * (e.g. 10.1 and 10.2) from crashing.
3912 */
3913 if (ar->monitor_started)
3914 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003916 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003917 } else {
3918 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003919 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920 }
3921
Michal Kazior7d9d5582014-10-21 10:40:15 +03003922 if (changed & BSS_CHANGED_TXPOWER) {
3923 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3924 arvif->vdev_id, info->txpower);
3925
3926 arvif->txpower = info->txpower;
3927 ret = ath10k_mac_txpower_recalc(ar);
3928 if (ret)
3929 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3930 }
3931
Michal Kaziorbf14e652014-12-12 12:41:38 +01003932 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003933 arvif->ps = vif->bss_conf.ps;
3934
3935 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003936 if (ret)
3937 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3938 arvif->vdev_id, ret);
3939 }
3940
Kalle Valo5e3dd152013-06-12 20:52:10 +03003941 mutex_unlock(&ar->conf_mutex);
3942}
3943
3944static int ath10k_hw_scan(struct ieee80211_hw *hw,
3945 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003946 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003947{
3948 struct ath10k *ar = hw->priv;
3949 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003950 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003951 struct wmi_start_scan_arg arg;
3952 int ret = 0;
3953 int i;
3954
3955 mutex_lock(&ar->conf_mutex);
3956
3957 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003958 switch (ar->scan.state) {
3959 case ATH10K_SCAN_IDLE:
3960 reinit_completion(&ar->scan.started);
3961 reinit_completion(&ar->scan.completed);
3962 ar->scan.state = ATH10K_SCAN_STARTING;
3963 ar->scan.is_roc = false;
3964 ar->scan.vdev_id = arvif->vdev_id;
3965 ret = 0;
3966 break;
3967 case ATH10K_SCAN_STARTING:
3968 case ATH10K_SCAN_RUNNING:
3969 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003970 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003971 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003972 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973 spin_unlock_bh(&ar->data_lock);
3974
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003975 if (ret)
3976 goto exit;
3977
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 memset(&arg, 0, sizeof(arg));
3979 ath10k_wmi_start_scan_init(ar, &arg);
3980 arg.vdev_id = arvif->vdev_id;
3981 arg.scan_id = ATH10K_SCAN_ID;
3982
3983 if (!req->no_cck)
3984 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3985
3986 if (req->ie_len) {
3987 arg.ie_len = req->ie_len;
3988 memcpy(arg.ie, req->ie, arg.ie_len);
3989 }
3990
3991 if (req->n_ssids) {
3992 arg.n_ssids = req->n_ssids;
3993 for (i = 0; i < arg.n_ssids; i++) {
3994 arg.ssids[i].len = req->ssids[i].ssid_len;
3995 arg.ssids[i].ssid = req->ssids[i].ssid;
3996 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003997 } else {
3998 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 }
4000
4001 if (req->n_channels) {
4002 arg.n_channels = req->n_channels;
4003 for (i = 0; i < arg.n_channels; i++)
4004 arg.channels[i] = req->channels[i]->center_freq;
4005 }
4006
4007 ret = ath10k_start_scan(ar, &arg);
4008 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004009 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004011 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012 spin_unlock_bh(&ar->data_lock);
4013 }
4014
4015exit:
4016 mutex_unlock(&ar->conf_mutex);
4017 return ret;
4018}
4019
4020static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4021 struct ieee80211_vif *vif)
4022{
4023 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004024
4025 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004026 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004027 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004028
4029 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004030}
4031
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004032static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4033 struct ath10k_vif *arvif,
4034 enum set_key_cmd cmd,
4035 struct ieee80211_key_conf *key)
4036{
4037 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4038 int ret;
4039
4040 /* 10.1 firmware branch requires default key index to be set to group
4041 * key index after installing it. Otherwise FW/HW Txes corrupted
4042 * frames with multi-vif APs. This is not required for main firmware
4043 * branch (e.g. 636).
4044 *
4045 * FIXME: This has been tested only in AP. It remains unknown if this
4046 * is required for multi-vif STA interfaces on 10.1 */
4047
4048 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4049 return;
4050
4051 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4052 return;
4053
4054 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4055 return;
4056
4057 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4058 return;
4059
4060 if (cmd != SET_KEY)
4061 return;
4062
4063 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4064 key->keyidx);
4065 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004066 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004067 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004068}
4069
Kalle Valo5e3dd152013-06-12 20:52:10 +03004070static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4071 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4072 struct ieee80211_key_conf *key)
4073{
4074 struct ath10k *ar = hw->priv;
4075 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4076 struct ath10k_peer *peer;
4077 const u8 *peer_addr;
4078 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4079 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4080 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004081 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004082
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004083 /* this one needs to be done in software */
4084 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4085 return 1;
4086
Kalle Valo5e3dd152013-06-12 20:52:10 +03004087 if (key->keyidx > WMI_MAX_KEY_INDEX)
4088 return -ENOSPC;
4089
4090 mutex_lock(&ar->conf_mutex);
4091
4092 if (sta)
4093 peer_addr = sta->addr;
4094 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4095 peer_addr = vif->bss_conf.bssid;
4096 else
4097 peer_addr = vif->addr;
4098
4099 key->hw_key_idx = key->keyidx;
4100
4101 /* the peer should not disappear in mid-way (unless FW goes awry) since
4102 * we already hold conf_mutex. we just make sure its there now. */
4103 spin_lock_bh(&ar->data_lock);
4104 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4105 spin_unlock_bh(&ar->data_lock);
4106
4107 if (!peer) {
4108 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004109 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004110 peer_addr);
4111 ret = -EOPNOTSUPP;
4112 goto exit;
4113 } else {
4114 /* if the peer doesn't exist there is no key to disable
4115 * anymore */
4116 goto exit;
4117 }
4118 }
4119
Michal Kazior7cc45732015-03-09 14:24:17 +01004120 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4121 flags |= WMI_KEY_PAIRWISE;
4122 else
4123 flags |= WMI_KEY_GROUP;
4124
Kalle Valo5e3dd152013-06-12 20:52:10 +03004125 if (is_wep) {
4126 if (cmd == SET_KEY)
4127 arvif->wep_keys[key->keyidx] = key;
4128 else
4129 arvif->wep_keys[key->keyidx] = NULL;
4130
4131 if (cmd == DISABLE_KEY)
4132 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004133
Michal Kaziorad325cb2015-02-18 14:02:27 +01004134 /* When WEP keys are uploaded it's possible that there are
4135 * stations associated already (e.g. when merging) without any
4136 * keys. Static WEP needs an explicit per-peer key upload.
4137 */
4138 if (vif->type == NL80211_IFTYPE_ADHOC &&
4139 cmd == SET_KEY)
4140 ath10k_mac_vif_update_wep_key(arvif, key);
4141
Michal Kazior370e5672015-02-18 14:02:26 +01004142 /* 802.1x never sets the def_wep_key_idx so each set_key()
4143 * call changes default tx key.
4144 *
4145 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4146 * after first set_key().
4147 */
4148 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4149 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004150
Michal Kazior7cc45732015-03-09 14:24:17 +01004151 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4152 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4153 * mode and associated stations in AP/IBSS.
4154 *
4155 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4156 * work fine when mapped directly from mac80211.
4157 *
4158 * Note: When installing first static WEP groupwise key (which
4159 * should be pairwise) def_wep_key_idx isn't known yet (it's
4160 * equal to -1). Since .set_default_unicast_key is called only
4161 * for static WEP it's used to re-upload the key as pairwise.
4162 */
4163 if (arvif->def_wep_key_idx >= 0 &&
4164 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4165 flags &= ~WMI_KEY_GROUP;
4166 flags |= WMI_KEY_PAIRWISE;
4167 }
Michal Kazior370e5672015-02-18 14:02:26 +01004168 }
4169
4170 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004171 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004172 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004173 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004174 goto exit;
4175 }
4176
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004177 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4178
Kalle Valo5e3dd152013-06-12 20:52:10 +03004179 spin_lock_bh(&ar->data_lock);
4180 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4181 if (peer && cmd == SET_KEY)
4182 peer->keys[key->keyidx] = key;
4183 else if (peer && cmd == DISABLE_KEY)
4184 peer->keys[key->keyidx] = NULL;
4185 else if (peer == NULL)
4186 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004187 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004188 spin_unlock_bh(&ar->data_lock);
4189
4190exit:
4191 mutex_unlock(&ar->conf_mutex);
4192 return ret;
4193}
4194
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004195static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4196 struct ieee80211_vif *vif,
4197 int keyidx)
4198{
4199 struct ath10k *ar = hw->priv;
4200 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4201 int ret;
4202
4203 mutex_lock(&arvif->ar->conf_mutex);
4204
4205 if (arvif->ar->state != ATH10K_STATE_ON)
4206 goto unlock;
4207
4208 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4209 arvif->vdev_id, keyidx);
4210
4211 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4212 arvif->vdev_id,
4213 arvif->ar->wmi.vdev_param->def_keyid,
4214 keyidx);
4215
4216 if (ret) {
4217 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4218 arvif->vdev_id,
4219 ret);
4220 goto unlock;
4221 }
4222
4223 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004224
4225 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4226 if (ret) {
4227 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4228 arvif->vdev_id, ret);
4229 goto unlock;
4230 }
4231
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004232unlock:
4233 mutex_unlock(&arvif->ar->conf_mutex);
4234}
4235
Michal Kazior9797feb2014-02-14 14:49:48 +01004236static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4237{
4238 struct ath10k *ar;
4239 struct ath10k_vif *arvif;
4240 struct ath10k_sta *arsta;
4241 struct ieee80211_sta *sta;
4242 u32 changed, bw, nss, smps;
4243 int err;
4244
4245 arsta = container_of(wk, struct ath10k_sta, update_wk);
4246 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4247 arvif = arsta->arvif;
4248 ar = arvif->ar;
4249
4250 spin_lock_bh(&ar->data_lock);
4251
4252 changed = arsta->changed;
4253 arsta->changed = 0;
4254
4255 bw = arsta->bw;
4256 nss = arsta->nss;
4257 smps = arsta->smps;
4258
4259 spin_unlock_bh(&ar->data_lock);
4260
4261 mutex_lock(&ar->conf_mutex);
4262
4263 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004264 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004265 sta->addr, bw);
4266
4267 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4268 WMI_PEER_CHAN_WIDTH, bw);
4269 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004270 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004271 sta->addr, bw, err);
4272 }
4273
4274 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004275 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004276 sta->addr, nss);
4277
4278 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4279 WMI_PEER_NSS, nss);
4280 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004282 sta->addr, nss, err);
4283 }
4284
4285 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004286 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004287 sta->addr, smps);
4288
4289 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4290 WMI_PEER_SMPS_STATE, smps);
4291 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004292 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004293 sta->addr, smps, err);
4294 }
4295
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004296 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4297 changed & IEEE80211_RC_NSS_CHANGED) {
4298 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004299 sta->addr);
4300
Michal Kazior590922a2014-10-21 10:10:29 +03004301 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004302 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004303 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004304 sta->addr);
4305 }
4306
Michal Kazior9797feb2014-02-14 14:49:48 +01004307 mutex_unlock(&ar->conf_mutex);
4308}
4309
Michal Kaziorcfd10612014-11-25 15:16:05 +01004310static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4311{
4312 struct ath10k *ar = arvif->ar;
4313
4314 lockdep_assert_held(&ar->conf_mutex);
4315
4316 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4317 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4318 return 0;
4319
4320 if (ar->num_stations >= ar->max_num_stations)
4321 return -ENOBUFS;
4322
4323 ar->num_stations++;
4324
4325 return 0;
4326}
4327
4328static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4329{
4330 struct ath10k *ar = arvif->ar;
4331
4332 lockdep_assert_held(&ar->conf_mutex);
4333
4334 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4335 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4336 return;
4337
4338 ar->num_stations--;
4339}
4340
Kalle Valo5e3dd152013-06-12 20:52:10 +03004341static int ath10k_sta_state(struct ieee80211_hw *hw,
4342 struct ieee80211_vif *vif,
4343 struct ieee80211_sta *sta,
4344 enum ieee80211_sta_state old_state,
4345 enum ieee80211_sta_state new_state)
4346{
4347 struct ath10k *ar = hw->priv;
4348 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004349 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004350 int ret = 0;
4351
Michal Kazior76f90022014-02-25 09:29:57 +02004352 if (old_state == IEEE80211_STA_NOTEXIST &&
4353 new_state == IEEE80211_STA_NONE) {
4354 memset(arsta, 0, sizeof(*arsta));
4355 arsta->arvif = arvif;
4356 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4357 }
4358
Michal Kazior9797feb2014-02-14 14:49:48 +01004359 /* cancel must be done outside the mutex to avoid deadlock */
4360 if ((old_state == IEEE80211_STA_NONE &&
4361 new_state == IEEE80211_STA_NOTEXIST))
4362 cancel_work_sync(&arsta->update_wk);
4363
Kalle Valo5e3dd152013-06-12 20:52:10 +03004364 mutex_lock(&ar->conf_mutex);
4365
4366 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004367 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004368 /*
4369 * New station addition.
4370 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004371 ath10k_dbg(ar, ATH10K_DBG_MAC,
4372 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4373 arvif->vdev_id, sta->addr,
4374 ar->num_stations + 1, ar->max_num_stations,
4375 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004376
Michal Kaziorcfd10612014-11-25 15:16:05 +01004377 ret = ath10k_mac_inc_num_stations(arvif);
4378 if (ret) {
4379 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4380 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004381 goto exit;
4382 }
4383
Kalle Valo5e3dd152013-06-12 20:52:10 +03004384 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004386 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 -08004387 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004388 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004389 goto exit;
4390 }
Michal Kazior077efc82014-10-21 10:10:29 +03004391
4392 if (vif->type == NL80211_IFTYPE_STATION) {
4393 WARN_ON(arvif->is_started);
4394
4395 ret = ath10k_vdev_start(arvif);
4396 if (ret) {
4397 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4398 arvif->vdev_id, ret);
4399 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4400 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004401 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004402 goto exit;
4403 }
4404
4405 arvif->is_started = true;
4406 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004407 } else if ((old_state == IEEE80211_STA_NONE &&
4408 new_state == IEEE80211_STA_NOTEXIST)) {
4409 /*
4410 * Existing station deletion.
4411 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004412 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004413 "mac vdev %d peer delete %pM (sta gone)\n",
4414 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004415
4416 if (vif->type == NL80211_IFTYPE_STATION) {
4417 WARN_ON(!arvif->is_started);
4418
4419 ret = ath10k_vdev_stop(arvif);
4420 if (ret)
4421 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4422 arvif->vdev_id, ret);
4423
4424 arvif->is_started = false;
4425 }
4426
Kalle Valo5e3dd152013-06-12 20:52:10 +03004427 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4428 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004429 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004430 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004431
Michal Kaziorcfd10612014-11-25 15:16:05 +01004432 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004433 } else if (old_state == IEEE80211_STA_AUTH &&
4434 new_state == IEEE80211_STA_ASSOC &&
4435 (vif->type == NL80211_IFTYPE_AP ||
4436 vif->type == NL80211_IFTYPE_ADHOC)) {
4437 /*
4438 * New association.
4439 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004440 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004441 sta->addr);
4442
Michal Kazior590922a2014-10-21 10:10:29 +03004443 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004444 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004445 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004446 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004447 } else if (old_state == IEEE80211_STA_ASSOC &&
4448 new_state == IEEE80211_STA_AUTH &&
4449 (vif->type == NL80211_IFTYPE_AP ||
4450 vif->type == NL80211_IFTYPE_ADHOC)) {
4451 /*
4452 * Disassociation.
4453 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004454 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004455 sta->addr);
4456
Michal Kazior590922a2014-10-21 10:10:29 +03004457 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004458 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004459 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004460 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004461 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004462exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463 mutex_unlock(&ar->conf_mutex);
4464 return ret;
4465}
4466
4467static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004468 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004469{
4470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004471 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4472 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004473 u32 value = 0;
4474 int ret = 0;
4475
Michal Kazior548db542013-07-05 16:15:15 +03004476 lockdep_assert_held(&ar->conf_mutex);
4477
Kalle Valo5e3dd152013-06-12 20:52:10 +03004478 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4479 return 0;
4480
4481 switch (ac) {
4482 case IEEE80211_AC_VO:
4483 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4484 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004485 prio = 7;
4486 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004487 break;
4488 case IEEE80211_AC_VI:
4489 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4490 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004491 prio = 5;
4492 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004493 break;
4494 case IEEE80211_AC_BE:
4495 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4496 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004497 prio = 2;
4498 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004499 break;
4500 case IEEE80211_AC_BK:
4501 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4502 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004503 prio = 0;
4504 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004505 break;
4506 }
4507
4508 if (enable)
4509 arvif->u.sta.uapsd |= value;
4510 else
4511 arvif->u.sta.uapsd &= ~value;
4512
4513 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4514 WMI_STA_PS_PARAM_UAPSD,
4515 arvif->u.sta.uapsd);
4516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004517 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004518 goto exit;
4519 }
4520
4521 if (arvif->u.sta.uapsd)
4522 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4523 else
4524 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4525
4526 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4527 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4528 value);
4529 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004530 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004531
Michal Kazior9f9b5742014-12-12 12:41:36 +01004532 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4533 if (ret) {
4534 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4535 arvif->vdev_id, ret);
4536 return ret;
4537 }
4538
4539 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4540 if (ret) {
4541 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4542 arvif->vdev_id, ret);
4543 return ret;
4544 }
4545
Michal Kaziorb0e56152015-01-24 12:14:52 +02004546 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4547 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4548 /* Only userspace can make an educated decision when to send
4549 * trigger frame. The following effectively disables u-UAPSD
4550 * autotrigger in firmware (which is enabled by default
4551 * provided the autotrigger service is available).
4552 */
4553
4554 arg.wmm_ac = acc;
4555 arg.user_priority = prio;
4556 arg.service_interval = 0;
4557 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4558 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4559
4560 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4561 arvif->bssid, &arg, 1);
4562 if (ret) {
4563 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4564 ret);
4565 return ret;
4566 }
4567 }
4568
Kalle Valo5e3dd152013-06-12 20:52:10 +03004569exit:
4570 return ret;
4571}
4572
4573static int ath10k_conf_tx(struct ieee80211_hw *hw,
4574 struct ieee80211_vif *vif, u16 ac,
4575 const struct ieee80211_tx_queue_params *params)
4576{
4577 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004578 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004579 struct wmi_wmm_params_arg *p = NULL;
4580 int ret;
4581
4582 mutex_lock(&ar->conf_mutex);
4583
4584 switch (ac) {
4585 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004586 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004587 break;
4588 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004589 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004590 break;
4591 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004592 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004593 break;
4594 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004595 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004596 break;
4597 }
4598
4599 if (WARN_ON(!p)) {
4600 ret = -EINVAL;
4601 goto exit;
4602 }
4603
4604 p->cwmin = params->cw_min;
4605 p->cwmax = params->cw_max;
4606 p->aifs = params->aifs;
4607
4608 /*
4609 * The channel time duration programmed in the HW is in absolute
4610 * microseconds, while mac80211 gives the txop in units of
4611 * 32 microseconds.
4612 */
4613 p->txop = params->txop * 32;
4614
Michal Kazior7fc979a2015-01-28 09:57:28 +02004615 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4616 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4617 &arvif->wmm_params);
4618 if (ret) {
4619 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4620 arvif->vdev_id, ret);
4621 goto exit;
4622 }
4623 } else {
4624 /* This won't work well with multi-interface cases but it's
4625 * better than nothing.
4626 */
4627 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4628 if (ret) {
4629 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4630 goto exit;
4631 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004632 }
4633
4634 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4635 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004636 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004637
4638exit:
4639 mutex_unlock(&ar->conf_mutex);
4640 return ret;
4641}
4642
4643#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4644
4645static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4646 struct ieee80211_vif *vif,
4647 struct ieee80211_channel *chan,
4648 int duration,
4649 enum ieee80211_roc_type type)
4650{
4651 struct ath10k *ar = hw->priv;
4652 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4653 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004654 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004655
4656 mutex_lock(&ar->conf_mutex);
4657
4658 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004659 switch (ar->scan.state) {
4660 case ATH10K_SCAN_IDLE:
4661 reinit_completion(&ar->scan.started);
4662 reinit_completion(&ar->scan.completed);
4663 reinit_completion(&ar->scan.on_channel);
4664 ar->scan.state = ATH10K_SCAN_STARTING;
4665 ar->scan.is_roc = true;
4666 ar->scan.vdev_id = arvif->vdev_id;
4667 ar->scan.roc_freq = chan->center_freq;
4668 ret = 0;
4669 break;
4670 case ATH10K_SCAN_STARTING:
4671 case ATH10K_SCAN_RUNNING:
4672 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004674 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004675 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004676 spin_unlock_bh(&ar->data_lock);
4677
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004678 if (ret)
4679 goto exit;
4680
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004681 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4682
Kalle Valo5e3dd152013-06-12 20:52:10 +03004683 memset(&arg, 0, sizeof(arg));
4684 ath10k_wmi_start_scan_init(ar, &arg);
4685 arg.vdev_id = arvif->vdev_id;
4686 arg.scan_id = ATH10K_SCAN_ID;
4687 arg.n_channels = 1;
4688 arg.channels[0] = chan->center_freq;
4689 arg.dwell_time_active = duration;
4690 arg.dwell_time_passive = duration;
4691 arg.max_scan_time = 2 * duration;
4692 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4693 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4694
4695 ret = ath10k_start_scan(ar, &arg);
4696 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004697 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004698 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004699 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004700 spin_unlock_bh(&ar->data_lock);
4701 goto exit;
4702 }
4703
4704 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4705 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004706 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004707
4708 ret = ath10k_scan_stop(ar);
4709 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004710 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004711
Kalle Valo5e3dd152013-06-12 20:52:10 +03004712 ret = -ETIMEDOUT;
4713 goto exit;
4714 }
4715
4716 ret = 0;
4717exit:
4718 mutex_unlock(&ar->conf_mutex);
4719 return ret;
4720}
4721
4722static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4723{
4724 struct ath10k *ar = hw->priv;
4725
4726 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004727 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004728 mutex_unlock(&ar->conf_mutex);
4729
Michal Kazior4eb2e162014-10-28 10:23:09 +01004730 cancel_delayed_work_sync(&ar->scan.timeout);
4731
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732 return 0;
4733}
4734
4735/*
4736 * Both RTS and Fragmentation threshold are interface-specific
4737 * in ath10k, but device-specific in mac80211.
4738 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004739
4740static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4741{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004742 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004743 struct ath10k_vif *arvif;
4744 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004745
Michal Kaziorad088bf2013-10-16 15:44:46 +03004746 mutex_lock(&ar->conf_mutex);
4747 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004748 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004749 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004750
Michal Kaziorad088bf2013-10-16 15:44:46 +03004751 ret = ath10k_mac_set_rts(arvif, value);
4752 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004753 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004754 arvif->vdev_id, ret);
4755 break;
4756 }
4757 }
4758 mutex_unlock(&ar->conf_mutex);
4759
4760 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004761}
4762
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004763static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4764 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004765{
4766 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004767 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004768 int ret;
4769
4770 /* mac80211 doesn't care if we really xmit queued frames or not
4771 * we'll collect those frames either way if we stop/delete vdevs */
4772 if (drop)
4773 return;
4774
Michal Kazior548db542013-07-05 16:15:15 +03004775 mutex_lock(&ar->conf_mutex);
4776
Michal Kazioraffd3212013-07-16 09:54:35 +02004777 if (ar->state == ATH10K_STATE_WEDGED)
4778 goto skip;
4779
Michal Kazioredb82362013-07-05 16:15:14 +03004780 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004781 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004782
Michal Kazioredb82362013-07-05 16:15:14 +03004783 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004784 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004785 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004786
Michal Kazior7962b0d2014-10-28 10:34:38 +01004787 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4788 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4789 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004790
4791 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004793
4794 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004795 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004796 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004797
Michal Kazioraffd3212013-07-16 09:54:35 +02004798skip:
Michal Kazior548db542013-07-05 16:15:15 +03004799 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004800}
4801
4802/* TODO: Implement this function properly
4803 * For now it is needed to reply to Probe Requests in IBSS mode.
4804 * Propably we need this information from FW.
4805 */
4806static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4807{
4808 return 1;
4809}
4810
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004811#ifdef CONFIG_PM
4812static int ath10k_suspend(struct ieee80211_hw *hw,
4813 struct cfg80211_wowlan *wowlan)
4814{
4815 struct ath10k *ar = hw->priv;
4816 int ret;
4817
Marek Puzyniak9042e172014-02-10 17:14:23 +01004818 mutex_lock(&ar->conf_mutex);
4819
Marek Puzyniak00f54822014-02-10 17:14:24 +01004820 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004821 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004822 if (ret == -ETIMEDOUT)
4823 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004824 ret = 1;
4825 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004826 }
4827
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004828 ret = ath10k_hif_suspend(ar);
4829 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004830 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004831 goto resume;
4832 }
4833
Marek Puzyniak9042e172014-02-10 17:14:23 +01004834 ret = 0;
4835 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004836resume:
4837 ret = ath10k_wmi_pdev_resume_target(ar);
4838 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004839 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004840
4841 ret = 1;
4842exit:
4843 mutex_unlock(&ar->conf_mutex);
4844 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004845}
4846
4847static int ath10k_resume(struct ieee80211_hw *hw)
4848{
4849 struct ath10k *ar = hw->priv;
4850 int ret;
4851
Marek Puzyniak9042e172014-02-10 17:14:23 +01004852 mutex_lock(&ar->conf_mutex);
4853
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004854 ret = ath10k_hif_resume(ar);
4855 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004856 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004857 ret = 1;
4858 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004859 }
4860
4861 ret = ath10k_wmi_pdev_resume_target(ar);
4862 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004863 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004864 ret = 1;
4865 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004866 }
4867
Marek Puzyniak9042e172014-02-10 17:14:23 +01004868 ret = 0;
4869exit:
4870 mutex_unlock(&ar->conf_mutex);
4871 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004872}
4873#endif
4874
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004875static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4876 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004877{
4878 struct ath10k *ar = hw->priv;
4879
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004880 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4881 return;
4882
Michal Kazioraffd3212013-07-16 09:54:35 +02004883 mutex_lock(&ar->conf_mutex);
4884
4885 /* If device failed to restart it will be in a different state, e.g.
4886 * ATH10K_STATE_WEDGED */
4887 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004888 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004889 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004890 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004891 }
4892
4893 mutex_unlock(&ar->conf_mutex);
4894}
4895
Michal Kazior2e1dea42013-07-31 10:32:40 +02004896static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4897 struct survey_info *survey)
4898{
4899 struct ath10k *ar = hw->priv;
4900 struct ieee80211_supported_band *sband;
4901 struct survey_info *ar_survey = &ar->survey[idx];
4902 int ret = 0;
4903
4904 mutex_lock(&ar->conf_mutex);
4905
4906 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4907 if (sband && idx >= sband->n_channels) {
4908 idx -= sband->n_channels;
4909 sband = NULL;
4910 }
4911
4912 if (!sband)
4913 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4914
4915 if (!sband || idx >= sband->n_channels) {
4916 ret = -ENOENT;
4917 goto exit;
4918 }
4919
4920 spin_lock_bh(&ar->data_lock);
4921 memcpy(survey, ar_survey, sizeof(*survey));
4922 spin_unlock_bh(&ar->data_lock);
4923
4924 survey->channel = &sband->channels[idx];
4925
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004926 if (ar->rx_channel == survey->channel)
4927 survey->filled |= SURVEY_INFO_IN_USE;
4928
Michal Kazior2e1dea42013-07-31 10:32:40 +02004929exit:
4930 mutex_unlock(&ar->conf_mutex);
4931 return ret;
4932}
4933
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004934/* Helper table for legacy fixed_rate/bitrate_mask */
4935static const u8 cck_ofdm_rate[] = {
4936 /* CCK */
4937 3, /* 1Mbps */
4938 2, /* 2Mbps */
4939 1, /* 5.5Mbps */
4940 0, /* 11Mbps */
4941 /* OFDM */
4942 3, /* 6Mbps */
4943 7, /* 9Mbps */
4944 2, /* 12Mbps */
4945 6, /* 18Mbps */
4946 1, /* 24Mbps */
4947 5, /* 36Mbps */
4948 0, /* 48Mbps */
4949 4, /* 54Mbps */
4950};
4951
4952/* Check if only one bit set */
4953static int ath10k_check_single_mask(u32 mask)
4954{
4955 int bit;
4956
4957 bit = ffs(mask);
4958 if (!bit)
4959 return 0;
4960
4961 mask &= ~BIT(bit - 1);
4962 if (mask)
4963 return 2;
4964
4965 return 1;
4966}
4967
4968static bool
4969ath10k_default_bitrate_mask(struct ath10k *ar,
4970 enum ieee80211_band band,
4971 const struct cfg80211_bitrate_mask *mask)
4972{
4973 u32 legacy = 0x00ff;
4974 u8 ht = 0xff, i;
4975 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004976 u16 nrf = ar->num_rf_chains;
4977
4978 if (ar->cfg_tx_chainmask)
4979 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004980
4981 switch (band) {
4982 case IEEE80211_BAND_2GHZ:
4983 legacy = 0x00fff;
4984 vht = 0;
4985 break;
4986 case IEEE80211_BAND_5GHZ:
4987 break;
4988 default:
4989 return false;
4990 }
4991
4992 if (mask->control[band].legacy != legacy)
4993 return false;
4994
Ben Greearb116ea12014-11-24 16:22:10 +02004995 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004996 if (mask->control[band].ht_mcs[i] != ht)
4997 return false;
4998
Ben Greearb116ea12014-11-24 16:22:10 +02004999 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005000 if (mask->control[band].vht_mcs[i] != vht)
5001 return false;
5002
5003 return true;
5004}
5005
5006static bool
5007ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5008 enum ieee80211_band band,
5009 u8 *fixed_nss)
5010{
5011 int ht_nss = 0, vht_nss = 0, i;
5012
5013 /* check legacy */
5014 if (ath10k_check_single_mask(mask->control[band].legacy))
5015 return false;
5016
5017 /* check HT */
5018 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5019 if (mask->control[band].ht_mcs[i] == 0xff)
5020 continue;
5021 else if (mask->control[band].ht_mcs[i] == 0x00)
5022 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005023
5024 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005025 }
5026
5027 ht_nss = i;
5028
5029 /* check VHT */
5030 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5031 if (mask->control[band].vht_mcs[i] == 0x03ff)
5032 continue;
5033 else if (mask->control[band].vht_mcs[i] == 0x0000)
5034 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005035
5036 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005037 }
5038
5039 vht_nss = i;
5040
5041 if (ht_nss > 0 && vht_nss > 0)
5042 return false;
5043
5044 if (ht_nss)
5045 *fixed_nss = ht_nss;
5046 else if (vht_nss)
5047 *fixed_nss = vht_nss;
5048 else
5049 return false;
5050
5051 return true;
5052}
5053
5054static bool
5055ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5056 enum ieee80211_band band,
5057 enum wmi_rate_preamble *preamble)
5058{
5059 int legacy = 0, ht = 0, vht = 0, i;
5060
5061 *preamble = WMI_RATE_PREAMBLE_OFDM;
5062
5063 /* check legacy */
5064 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5065 if (legacy > 1)
5066 return false;
5067
5068 /* check HT */
5069 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5070 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5071 if (ht > 1)
5072 return false;
5073
5074 /* check VHT */
5075 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5076 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5077 if (vht > 1)
5078 return false;
5079
5080 /* Currently we support only one fixed_rate */
5081 if ((legacy + ht + vht) != 1)
5082 return false;
5083
5084 if (ht)
5085 *preamble = WMI_RATE_PREAMBLE_HT;
5086 else if (vht)
5087 *preamble = WMI_RATE_PREAMBLE_VHT;
5088
5089 return true;
5090}
5091
5092static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005093ath10k_bitrate_mask_rate(struct ath10k *ar,
5094 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005095 enum ieee80211_band band,
5096 u8 *fixed_rate,
5097 u8 *fixed_nss)
5098{
5099 u8 rate = 0, pream = 0, nss = 0, i;
5100 enum wmi_rate_preamble preamble;
5101
5102 /* Check if single rate correct */
5103 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5104 return false;
5105
5106 pream = preamble;
5107
5108 switch (preamble) {
5109 case WMI_RATE_PREAMBLE_CCK:
5110 case WMI_RATE_PREAMBLE_OFDM:
5111 i = ffs(mask->control[band].legacy) - 1;
5112
5113 if (band == IEEE80211_BAND_2GHZ && i < 4)
5114 pream = WMI_RATE_PREAMBLE_CCK;
5115
5116 if (band == IEEE80211_BAND_5GHZ)
5117 i += 4;
5118
5119 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5120 return false;
5121
5122 rate = cck_ofdm_rate[i];
5123 break;
5124 case WMI_RATE_PREAMBLE_HT:
5125 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5126 if (mask->control[band].ht_mcs[i])
5127 break;
5128
5129 if (i == IEEE80211_HT_MCS_MASK_LEN)
5130 return false;
5131
5132 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5133 nss = i;
5134 break;
5135 case WMI_RATE_PREAMBLE_VHT:
5136 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5137 if (mask->control[band].vht_mcs[i])
5138 break;
5139
5140 if (i == NL80211_VHT_NSS_MAX)
5141 return false;
5142
5143 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5144 nss = i;
5145 break;
5146 }
5147
5148 *fixed_nss = nss + 1;
5149 nss <<= 4;
5150 pream <<= 6;
5151
Michal Kazior7aa7a722014-08-25 12:09:38 +02005152 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 +01005153 pream, nss, rate);
5154
5155 *fixed_rate = pream | nss | rate;
5156
5157 return true;
5158}
5159
Michal Kazior7aa7a722014-08-25 12:09:38 +02005160static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5161 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005162 enum ieee80211_band band,
5163 u8 *fixed_rate,
5164 u8 *fixed_nss)
5165{
5166 /* First check full NSS mask, if we can simply limit NSS */
5167 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5168 return true;
5169
5170 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005171 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005172}
5173
5174static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5175 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005176 u8 fixed_nss,
5177 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005178{
5179 struct ath10k *ar = arvif->ar;
5180 u32 vdev_param;
5181 int ret = 0;
5182
5183 mutex_lock(&ar->conf_mutex);
5184
5185 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005186 arvif->fixed_nss == fixed_nss &&
5187 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005188 goto exit;
5189
5190 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005191 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005192
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005193 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005194 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005195
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005196 vdev_param = ar->wmi.vdev_param->fixed_rate;
5197 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5198 vdev_param, fixed_rate);
5199 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005200 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005201 fixed_rate, ret);
5202 ret = -EINVAL;
5203 goto exit;
5204 }
5205
5206 arvif->fixed_rate = fixed_rate;
5207
5208 vdev_param = ar->wmi.vdev_param->nss;
5209 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5210 vdev_param, fixed_nss);
5211
5212 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005213 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005214 fixed_nss, ret);
5215 ret = -EINVAL;
5216 goto exit;
5217 }
5218
5219 arvif->fixed_nss = fixed_nss;
5220
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005221 vdev_param = ar->wmi.vdev_param->sgi;
5222 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5223 force_sgi);
5224
5225 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005226 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005227 force_sgi, ret);
5228 ret = -EINVAL;
5229 goto exit;
5230 }
5231
5232 arvif->force_sgi = force_sgi;
5233
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005234exit:
5235 mutex_unlock(&ar->conf_mutex);
5236 return ret;
5237}
5238
5239static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5240 struct ieee80211_vif *vif,
5241 const struct cfg80211_bitrate_mask *mask)
5242{
5243 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5244 struct ath10k *ar = arvif->ar;
5245 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5246 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5247 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005248 u8 force_sgi;
5249
Ben Greearb116ea12014-11-24 16:22:10 +02005250 if (ar->cfg_tx_chainmask)
5251 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5252
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005253 force_sgi = mask->control[band].gi;
5254 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5255 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005256
5257 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005258 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005259 &fixed_rate,
5260 &fixed_nss))
5261 return -EINVAL;
5262 }
5263
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005264 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005265 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005266 return -EINVAL;
5267 }
5268
5269 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5270 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005271}
5272
Michal Kazior9797feb2014-02-14 14:49:48 +01005273static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5274 struct ieee80211_vif *vif,
5275 struct ieee80211_sta *sta,
5276 u32 changed)
5277{
5278 struct ath10k *ar = hw->priv;
5279 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5280 u32 bw, smps;
5281
5282 spin_lock_bh(&ar->data_lock);
5283
Michal Kazior7aa7a722014-08-25 12:09:38 +02005284 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005285 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5286 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5287 sta->smps_mode);
5288
5289 if (changed & IEEE80211_RC_BW_CHANGED) {
5290 bw = WMI_PEER_CHWIDTH_20MHZ;
5291
5292 switch (sta->bandwidth) {
5293 case IEEE80211_STA_RX_BW_20:
5294 bw = WMI_PEER_CHWIDTH_20MHZ;
5295 break;
5296 case IEEE80211_STA_RX_BW_40:
5297 bw = WMI_PEER_CHWIDTH_40MHZ;
5298 break;
5299 case IEEE80211_STA_RX_BW_80:
5300 bw = WMI_PEER_CHWIDTH_80MHZ;
5301 break;
5302 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005303 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005304 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005305 bw = WMI_PEER_CHWIDTH_20MHZ;
5306 break;
5307 }
5308
5309 arsta->bw = bw;
5310 }
5311
5312 if (changed & IEEE80211_RC_NSS_CHANGED)
5313 arsta->nss = sta->rx_nss;
5314
5315 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5316 smps = WMI_PEER_SMPS_PS_NONE;
5317
5318 switch (sta->smps_mode) {
5319 case IEEE80211_SMPS_AUTOMATIC:
5320 case IEEE80211_SMPS_OFF:
5321 smps = WMI_PEER_SMPS_PS_NONE;
5322 break;
5323 case IEEE80211_SMPS_STATIC:
5324 smps = WMI_PEER_SMPS_STATIC;
5325 break;
5326 case IEEE80211_SMPS_DYNAMIC:
5327 smps = WMI_PEER_SMPS_DYNAMIC;
5328 break;
5329 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005330 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005331 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005332 smps = WMI_PEER_SMPS_PS_NONE;
5333 break;
5334 }
5335
5336 arsta->smps = smps;
5337 }
5338
Michal Kazior9797feb2014-02-14 14:49:48 +01005339 arsta->changed |= changed;
5340
5341 spin_unlock_bh(&ar->data_lock);
5342
5343 ieee80211_queue_work(hw, &arsta->update_wk);
5344}
5345
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005346static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5347{
5348 /*
5349 * FIXME: Return 0 for time being. Need to figure out whether FW
5350 * has the API to fetch 64-bit local TSF
5351 */
5352
5353 return 0;
5354}
5355
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005356static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5357 struct ieee80211_vif *vif,
5358 enum ieee80211_ampdu_mlme_action action,
5359 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5360 u8 buf_size)
5361{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005362 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005363 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5364
Michal Kazior7aa7a722014-08-25 12:09:38 +02005365 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 +02005366 arvif->vdev_id, sta->addr, tid, action);
5367
5368 switch (action) {
5369 case IEEE80211_AMPDU_RX_START:
5370 case IEEE80211_AMPDU_RX_STOP:
5371 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5372 * creation/removal. Do we need to verify this?
5373 */
5374 return 0;
5375 case IEEE80211_AMPDU_TX_START:
5376 case IEEE80211_AMPDU_TX_STOP_CONT:
5377 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5378 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5379 case IEEE80211_AMPDU_TX_OPERATIONAL:
5380 /* Firmware offloads Tx aggregation entirely so deny mac80211
5381 * Tx aggregation requests.
5382 */
5383 return -EOPNOTSUPP;
5384 }
5385
5386 return -EINVAL;
5387}
5388
Kalle Valo5e3dd152013-06-12 20:52:10 +03005389static const struct ieee80211_ops ath10k_ops = {
5390 .tx = ath10k_tx,
5391 .start = ath10k_start,
5392 .stop = ath10k_stop,
5393 .config = ath10k_config,
5394 .add_interface = ath10k_add_interface,
5395 .remove_interface = ath10k_remove_interface,
5396 .configure_filter = ath10k_configure_filter,
5397 .bss_info_changed = ath10k_bss_info_changed,
5398 .hw_scan = ath10k_hw_scan,
5399 .cancel_hw_scan = ath10k_cancel_hw_scan,
5400 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005401 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005402 .sta_state = ath10k_sta_state,
5403 .conf_tx = ath10k_conf_tx,
5404 .remain_on_channel = ath10k_remain_on_channel,
5405 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5406 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005407 .flush = ath10k_flush,
5408 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005409 .set_antenna = ath10k_set_antenna,
5410 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005411 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005412 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005413 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005414 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005415 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005416 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005417 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5418 .get_et_stats = ath10k_debug_get_et_stats,
5419 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005420
5421 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5422
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005423#ifdef CONFIG_PM
5424 .suspend = ath10k_suspend,
5425 .resume = ath10k_resume,
5426#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005427#ifdef CONFIG_MAC80211_DEBUGFS
5428 .sta_add_debugfs = ath10k_sta_add_debugfs,
5429#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005430};
5431
5432#define RATETAB_ENT(_rate, _rateid, _flags) { \
5433 .bitrate = (_rate), \
5434 .flags = (_flags), \
5435 .hw_value = (_rateid), \
5436}
5437
5438#define CHAN2G(_channel, _freq, _flags) { \
5439 .band = IEEE80211_BAND_2GHZ, \
5440 .hw_value = (_channel), \
5441 .center_freq = (_freq), \
5442 .flags = (_flags), \
5443 .max_antenna_gain = 0, \
5444 .max_power = 30, \
5445}
5446
5447#define CHAN5G(_channel, _freq, _flags) { \
5448 .band = IEEE80211_BAND_5GHZ, \
5449 .hw_value = (_channel), \
5450 .center_freq = (_freq), \
5451 .flags = (_flags), \
5452 .max_antenna_gain = 0, \
5453 .max_power = 30, \
5454}
5455
5456static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5457 CHAN2G(1, 2412, 0),
5458 CHAN2G(2, 2417, 0),
5459 CHAN2G(3, 2422, 0),
5460 CHAN2G(4, 2427, 0),
5461 CHAN2G(5, 2432, 0),
5462 CHAN2G(6, 2437, 0),
5463 CHAN2G(7, 2442, 0),
5464 CHAN2G(8, 2447, 0),
5465 CHAN2G(9, 2452, 0),
5466 CHAN2G(10, 2457, 0),
5467 CHAN2G(11, 2462, 0),
5468 CHAN2G(12, 2467, 0),
5469 CHAN2G(13, 2472, 0),
5470 CHAN2G(14, 2484, 0),
5471};
5472
5473static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005474 CHAN5G(36, 5180, 0),
5475 CHAN5G(40, 5200, 0),
5476 CHAN5G(44, 5220, 0),
5477 CHAN5G(48, 5240, 0),
5478 CHAN5G(52, 5260, 0),
5479 CHAN5G(56, 5280, 0),
5480 CHAN5G(60, 5300, 0),
5481 CHAN5G(64, 5320, 0),
5482 CHAN5G(100, 5500, 0),
5483 CHAN5G(104, 5520, 0),
5484 CHAN5G(108, 5540, 0),
5485 CHAN5G(112, 5560, 0),
5486 CHAN5G(116, 5580, 0),
5487 CHAN5G(120, 5600, 0),
5488 CHAN5G(124, 5620, 0),
5489 CHAN5G(128, 5640, 0),
5490 CHAN5G(132, 5660, 0),
5491 CHAN5G(136, 5680, 0),
5492 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005493 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005494 CHAN5G(149, 5745, 0),
5495 CHAN5G(153, 5765, 0),
5496 CHAN5G(157, 5785, 0),
5497 CHAN5G(161, 5805, 0),
5498 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005499};
5500
Michal Kazior91b12082014-12-12 12:41:35 +01005501/* Note: Be careful if you re-order these. There is code which depends on this
5502 * ordering.
5503 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005504static struct ieee80211_rate ath10k_rates[] = {
5505 /* CCK */
5506 RATETAB_ENT(10, 0x82, 0),
5507 RATETAB_ENT(20, 0x84, 0),
5508 RATETAB_ENT(55, 0x8b, 0),
5509 RATETAB_ENT(110, 0x96, 0),
5510 /* OFDM */
5511 RATETAB_ENT(60, 0x0c, 0),
5512 RATETAB_ENT(90, 0x12, 0),
5513 RATETAB_ENT(120, 0x18, 0),
5514 RATETAB_ENT(180, 0x24, 0),
5515 RATETAB_ENT(240, 0x30, 0),
5516 RATETAB_ENT(360, 0x48, 0),
5517 RATETAB_ENT(480, 0x60, 0),
5518 RATETAB_ENT(540, 0x6c, 0),
5519};
5520
5521#define ath10k_a_rates (ath10k_rates + 4)
5522#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5523#define ath10k_g_rates (ath10k_rates + 0)
5524#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5525
Michal Kaziore7b54192014-08-07 11:03:27 +02005526struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005527{
5528 struct ieee80211_hw *hw;
5529 struct ath10k *ar;
5530
Michal Kaziore7b54192014-08-07 11:03:27 +02005531 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005532 if (!hw)
5533 return NULL;
5534
5535 ar = hw->priv;
5536 ar->hw = hw;
5537
5538 return ar;
5539}
5540
5541void ath10k_mac_destroy(struct ath10k *ar)
5542{
5543 ieee80211_free_hw(ar->hw);
5544}
5545
5546static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5547 {
5548 .max = 8,
5549 .types = BIT(NL80211_IFTYPE_STATION)
5550 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005551 },
5552 {
5553 .max = 3,
5554 .types = BIT(NL80211_IFTYPE_P2P_GO)
5555 },
5556 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005557 .max = 1,
5558 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5559 },
5560 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005561 .max = 7,
5562 .types = BIT(NL80211_IFTYPE_AP)
5563 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005564};
5565
Bartosz Markowskif2595092013-12-10 16:20:39 +01005566static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005567 {
5568 .max = 8,
5569 .types = BIT(NL80211_IFTYPE_AP)
5570 },
5571};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005572
5573static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5574 {
5575 .limits = ath10k_if_limits,
5576 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5577 .max_interfaces = 8,
5578 .num_different_channels = 1,
5579 .beacon_int_infra_match = true,
5580 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005581};
5582
5583static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005584 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005585 .limits = ath10k_10x_if_limits,
5586 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005587 .max_interfaces = 8,
5588 .num_different_channels = 1,
5589 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005590#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005591 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5592 BIT(NL80211_CHAN_WIDTH_20) |
5593 BIT(NL80211_CHAN_WIDTH_40) |
5594 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005595#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005596 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005597};
5598
5599static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5600{
5601 struct ieee80211_sta_vht_cap vht_cap = {0};
5602 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005603 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005604 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005605
5606 vht_cap.vht_supported = 1;
5607 vht_cap.cap = ar->vht_cap_info;
5608
Michal Kaziorbc657a362015-02-26 11:11:22 +01005609 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5610 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5611 val = ar->num_rf_chains - 1;
5612 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5613 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5614
5615 vht_cap.cap |= val;
5616 }
5617
5618 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5619 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5620 val = ar->num_rf_chains - 1;
5621 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5622 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5623
5624 vht_cap.cap |= val;
5625 }
5626
Michal Kazior8865bee42013-07-24 12:36:46 +02005627 mcs_map = 0;
5628 for (i = 0; i < 8; i++) {
5629 if (i < ar->num_rf_chains)
5630 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5631 else
5632 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5633 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005634
5635 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5636 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5637
5638 return vht_cap;
5639}
5640
5641static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5642{
5643 int i;
5644 struct ieee80211_sta_ht_cap ht_cap = {0};
5645
5646 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5647 return ht_cap;
5648
5649 ht_cap.ht_supported = 1;
5650 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5651 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5652 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5653 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5654 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5655
5656 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5657 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5658
5659 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5660 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5661
5662 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5663 u32 smps;
5664
5665 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5666 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5667
5668 ht_cap.cap |= smps;
5669 }
5670
5671 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5672 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5673
5674 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5675 u32 stbc;
5676
5677 stbc = ar->ht_cap_info;
5678 stbc &= WMI_HT_CAP_RX_STBC;
5679 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5680 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5681 stbc &= IEEE80211_HT_CAP_RX_STBC;
5682
5683 ht_cap.cap |= stbc;
5684 }
5685
5686 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5687 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5688
5689 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5690 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5691
5692 /* max AMSDU is implicitly taken from vht_cap_info */
5693 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5694 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5695
Michal Kazior8865bee42013-07-24 12:36:46 +02005696 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005697 ht_cap.mcs.rx_mask[i] = 0xFF;
5698
5699 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5700
5701 return ht_cap;
5702}
5703
Kalle Valo5e3dd152013-06-12 20:52:10 +03005704static void ath10k_get_arvif_iter(void *data, u8 *mac,
5705 struct ieee80211_vif *vif)
5706{
5707 struct ath10k_vif_iter *arvif_iter = data;
5708 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5709
5710 if (arvif->vdev_id == arvif_iter->vdev_id)
5711 arvif_iter->arvif = arvif;
5712}
5713
5714struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5715{
5716 struct ath10k_vif_iter arvif_iter;
5717 u32 flags;
5718
5719 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5720 arvif_iter.vdev_id = vdev_id;
5721
5722 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5723 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5724 flags,
5725 ath10k_get_arvif_iter,
5726 &arvif_iter);
5727 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005728 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005729 return NULL;
5730 }
5731
5732 return arvif_iter.arvif;
5733}
5734
5735int ath10k_mac_register(struct ath10k *ar)
5736{
Johannes Berg3cb10942015-01-22 21:38:45 +01005737 static const u32 cipher_suites[] = {
5738 WLAN_CIPHER_SUITE_WEP40,
5739 WLAN_CIPHER_SUITE_WEP104,
5740 WLAN_CIPHER_SUITE_TKIP,
5741 WLAN_CIPHER_SUITE_CCMP,
5742 WLAN_CIPHER_SUITE_AES_CMAC,
5743 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005744 struct ieee80211_supported_band *band;
5745 struct ieee80211_sta_vht_cap vht_cap;
5746 struct ieee80211_sta_ht_cap ht_cap;
5747 void *channels;
5748 int ret;
5749
5750 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5751
5752 SET_IEEE80211_DEV(ar->hw, ar->dev);
5753
5754 ht_cap = ath10k_get_ht_cap(ar);
5755 vht_cap = ath10k_create_vht_cap(ar);
5756
5757 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5758 channels = kmemdup(ath10k_2ghz_channels,
5759 sizeof(ath10k_2ghz_channels),
5760 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005761 if (!channels) {
5762 ret = -ENOMEM;
5763 goto err_free;
5764 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005765
5766 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5767 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5768 band->channels = channels;
5769 band->n_bitrates = ath10k_g_rates_size;
5770 band->bitrates = ath10k_g_rates;
5771 band->ht_cap = ht_cap;
5772
Yanbo Lid68bb122015-01-23 08:18:20 +08005773 /* Enable the VHT support at 2.4 GHz */
5774 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005775
5776 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5777 }
5778
5779 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5780 channels = kmemdup(ath10k_5ghz_channels,
5781 sizeof(ath10k_5ghz_channels),
5782 GFP_KERNEL);
5783 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005784 ret = -ENOMEM;
5785 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005786 }
5787
5788 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5789 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5790 band->channels = channels;
5791 band->n_bitrates = ath10k_a_rates_size;
5792 band->bitrates = ath10k_a_rates;
5793 band->ht_cap = ht_cap;
5794 band->vht_cap = vht_cap;
5795 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5796 }
5797
5798 ar->hw->wiphy->interface_modes =
5799 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005800 BIT(NL80211_IFTYPE_AP);
5801
Ben Greear46acf7b2014-05-16 17:15:38 +03005802 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5803 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5804
Bartosz Markowskid3541812013-12-10 16:20:40 +01005805 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5806 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005807 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005808 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5809 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005810
5811 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5812 IEEE80211_HW_SUPPORTS_PS |
5813 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005814 IEEE80211_HW_MFP_CAPABLE |
5815 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5816 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005817 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005818 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005819 IEEE80211_HW_SW_CRYPTO_CONTROL |
5820 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005821
Eliad Peller0d8614b2014-09-10 14:07:36 +03005822 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5823
Kalle Valo5e3dd152013-06-12 20:52:10 +03005824 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005825 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005826
5827 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5828 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5829 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5830 }
5831
5832 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5833 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5834
5835 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005836 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005837
Kalle Valo5e3dd152013-06-12 20:52:10 +03005838 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5839
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005840 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5841 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5842
5843 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5844 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5845 * correct Probe Responses. This is more of a hack advert..
5846 */
5847 ar->hw->wiphy->probe_resp_offload |=
5848 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5849 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5850 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5851 }
5852
Kalle Valo5e3dd152013-06-12 20:52:10 +03005853 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005854 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005855 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5856
5857 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005858 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5859
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005860 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5861
Kalle Valo5e3dd152013-06-12 20:52:10 +03005862 /*
5863 * on LL hardware queues are managed entirely by the FW
5864 * so we only advertise to mac we can do the queues thing
5865 */
5866 ar->hw->queues = 4;
5867
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005868 switch (ar->wmi.op_version) {
5869 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5870 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005871 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5872 ar->hw->wiphy->n_iface_combinations =
5873 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005874 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005875 break;
5876 case ATH10K_FW_WMI_OP_VERSION_10_1:
5877 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005878 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005879 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5880 ar->hw->wiphy->n_iface_combinations =
5881 ARRAY_SIZE(ath10k_10x_if_comb);
5882 break;
5883 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5884 case ATH10K_FW_WMI_OP_VERSION_MAX:
5885 WARN_ON(1);
5886 ret = -EINVAL;
5887 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005888 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005889
Michal Kazior7c199992013-07-31 10:47:57 +02005890 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5891
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005892 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5893 /* Init ath dfs pattern detector */
5894 ar->ath_common.debug_mask = ATH_DBG_DFS;
5895 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5896 NL80211_DFS_UNSET);
5897
5898 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005899 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005900 }
5901
Kalle Valo5e3dd152013-06-12 20:52:10 +03005902 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5903 ath10k_reg_notifier);
5904 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005905 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005906 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005907 }
5908
Johannes Berg3cb10942015-01-22 21:38:45 +01005909 ar->hw->wiphy->cipher_suites = cipher_suites;
5910 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5911
Kalle Valo5e3dd152013-06-12 20:52:10 +03005912 ret = ieee80211_register_hw(ar->hw);
5913 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005914 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005915 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005916 }
5917
5918 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5919 ret = regulatory_hint(ar->hw->wiphy,
5920 ar->ath_common.regulatory.alpha2);
5921 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005922 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005923 }
5924
5925 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005926
5927err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005928 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005929err_free:
5930 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5931 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5932
Kalle Valo5e3dd152013-06-12 20:52:10 +03005933 return ret;
5934}
5935
5936void ath10k_mac_unregister(struct ath10k *ar)
5937{
5938 ieee80211_unregister_hw(ar->hw);
5939
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005940 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5941 ar->dfs_detector->exit(ar->dfs_detector);
5942
Kalle Valo5e3dd152013-06-12 20:52:10 +03005943 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5944 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5945
5946 SET_IEEE80211_DEV(ar->hw, NULL);
5947}