blob: 60e416eb23d0947771a6568003744c1fece592c1 [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
Michal Kaziord6500972014-04-08 09:56:09 +03003156 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003157 ath10k_regd_update(ar);
3158
Simon Wunderlich855aed12014-08-02 09:12:54 +03003159 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303160 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003161
Michal Kaziorae254432014-05-26 12:46:02 +03003162 mutex_unlock(&ar->conf_mutex);
3163 return 0;
3164
3165err_core_stop:
3166 ath10k_core_stop(ar);
3167
3168err_power_down:
3169 ath10k_hif_power_down(ar);
3170
3171err_off:
3172 ar->state = ATH10K_STATE_OFF;
3173
3174err:
Michal Kazior548db542013-07-05 16:15:15 +03003175 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003176 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003177}
3178
3179static void ath10k_stop(struct ieee80211_hw *hw)
3180{
3181 struct ath10k *ar = hw->priv;
3182
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003183 ath10k_drain_tx(ar);
3184
Michal Kazior548db542013-07-05 16:15:15 +03003185 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003186 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003187 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003188 ar->state = ATH10K_STATE_OFF;
3189 }
Michal Kazior548db542013-07-05 16:15:15 +03003190 mutex_unlock(&ar->conf_mutex);
3191
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003192 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003193 cancel_work_sync(&ar->restart_work);
3194}
3195
Michal Kaziorad088bf2013-10-16 15:44:46 +03003196static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003197{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003198 struct ath10k_vif *arvif;
3199 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003200
3201 lockdep_assert_held(&ar->conf_mutex);
3202
Michal Kaziorad088bf2013-10-16 15:44:46 +03003203 list_for_each_entry(arvif, &ar->arvifs, list) {
3204 ret = ath10k_mac_vif_setup_ps(arvif);
3205 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003206 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003207 break;
3208 }
3209 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003210
Michal Kaziorad088bf2013-10-16 15:44:46 +03003211 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212}
3213
Michal Kaziorc930f742014-01-23 11:38:25 +01003214static const char *chandef_get_width(enum nl80211_chan_width width)
3215{
3216 switch (width) {
3217 case NL80211_CHAN_WIDTH_20_NOHT:
3218 return "20 (noht)";
3219 case NL80211_CHAN_WIDTH_20:
3220 return "20";
3221 case NL80211_CHAN_WIDTH_40:
3222 return "40";
3223 case NL80211_CHAN_WIDTH_80:
3224 return "80";
3225 case NL80211_CHAN_WIDTH_80P80:
3226 return "80+80";
3227 case NL80211_CHAN_WIDTH_160:
3228 return "160";
3229 case NL80211_CHAN_WIDTH_5:
3230 return "5";
3231 case NL80211_CHAN_WIDTH_10:
3232 return "10";
3233 }
3234 return "?";
3235}
3236
3237static void ath10k_config_chan(struct ath10k *ar)
3238{
3239 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003240 int ret;
3241
3242 lockdep_assert_held(&ar->conf_mutex);
3243
Michal Kazior7aa7a722014-08-25 12:09:38 +02003244 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003245 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3246 ar->chandef.chan->center_freq,
3247 ar->chandef.center_freq1,
3248 ar->chandef.center_freq2,
3249 chandef_get_width(ar->chandef.width));
3250
3251 /* First stop monitor interface. Some FW versions crash if there's a
3252 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003253 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003254 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003255
3256 list_for_each_entry(arvif, &ar->arvifs, list) {
3257 if (!arvif->is_started)
3258 continue;
3259
Michal Kaziordc55e302014-07-29 12:53:36 +03003260 if (!arvif->is_up)
3261 continue;
3262
Michal Kaziorc930f742014-01-23 11:38:25 +01003263 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3264 continue;
3265
Michal Kaziordc55e302014-07-29 12:53:36 +03003266 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003267 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003268 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003269 arvif->vdev_id, ret);
3270 continue;
3271 }
3272 }
3273
Michal Kaziordc55e302014-07-29 12:53:36 +03003274 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003275
3276 list_for_each_entry(arvif, &ar->arvifs, list) {
3277 if (!arvif->is_started)
3278 continue;
3279
3280 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3281 continue;
3282
Michal Kazior81a9a172015-03-05 16:02:17 +02003283 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3284 if (ret)
3285 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3286 ret);
3287
3288 ret = ath10k_mac_setup_prb_tmpl(arvif);
3289 if (ret)
3290 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3291 ret);
3292
Michal Kaziordc55e302014-07-29 12:53:36 +03003293 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003295 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003296 arvif->vdev_id, ret);
3297 continue;
3298 }
3299
3300 if (!arvif->is_up)
3301 continue;
3302
3303 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3304 arvif->bssid);
3305 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003306 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003307 arvif->vdev_id, ret);
3308 continue;
3309 }
3310 }
3311
Michal Kazior19337472014-08-28 12:58:16 +02003312 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003313}
3314
Michal Kazior7d9d5582014-10-21 10:40:15 +03003315static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3316{
3317 int ret;
3318 u32 param;
3319
3320 lockdep_assert_held(&ar->conf_mutex);
3321
3322 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3323
3324 param = ar->wmi.pdev_param->txpower_limit2g;
3325 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3326 if (ret) {
3327 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3328 txpower, ret);
3329 return ret;
3330 }
3331
3332 param = ar->wmi.pdev_param->txpower_limit5g;
3333 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3334 if (ret) {
3335 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3336 txpower, ret);
3337 return ret;
3338 }
3339
3340 return 0;
3341}
3342
3343static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3344{
3345 struct ath10k_vif *arvif;
3346 int ret, txpower = -1;
3347
3348 lockdep_assert_held(&ar->conf_mutex);
3349
3350 list_for_each_entry(arvif, &ar->arvifs, list) {
3351 WARN_ON(arvif->txpower < 0);
3352
3353 if (txpower == -1)
3354 txpower = arvif->txpower;
3355 else
3356 txpower = min(txpower, arvif->txpower);
3357 }
3358
3359 if (WARN_ON(txpower == -1))
3360 return -EINVAL;
3361
3362 ret = ath10k_mac_txpower_setup(ar, txpower);
3363 if (ret) {
3364 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3365 txpower, ret);
3366 return ret;
3367 }
3368
3369 return 0;
3370}
3371
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3373{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003374 struct ath10k *ar = hw->priv;
3375 struct ieee80211_conf *conf = &hw->conf;
3376 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003377
3378 mutex_lock(&ar->conf_mutex);
3379
3380 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003381 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003382 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003383 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003384 conf->chandef.chan->flags,
3385 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003386
Kalle Valo5e3dd152013-06-12 20:52:10 +03003387 spin_lock_bh(&ar->data_lock);
3388 ar->rx_channel = conf->chandef.chan;
3389 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003390
Michal Kaziord6500972014-04-08 09:56:09 +03003391 ar->radar_enabled = conf->radar_enabled;
3392 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003393
3394 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3395 ar->chandef = conf->chandef;
3396 ath10k_config_chan(ar);
3397 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398 }
3399
Michal Kazioraffd3212013-07-16 09:54:35 +02003400 if (changed & IEEE80211_CONF_CHANGE_PS)
3401 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003402
3403 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003404 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3405 ret = ath10k_monitor_recalc(ar);
3406 if (ret)
3407 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 }
3409
3410 mutex_unlock(&ar->conf_mutex);
3411 return ret;
3412}
3413
Ben Greear5572a952014-11-24 16:22:10 +02003414static u32 get_nss_from_chainmask(u16 chain_mask)
3415{
3416 if ((chain_mask & 0x15) == 0x15)
3417 return 4;
3418 else if ((chain_mask & 0x7) == 0x7)
3419 return 3;
3420 else if ((chain_mask & 0x3) == 0x3)
3421 return 2;
3422 return 1;
3423}
3424
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425/*
3426 * TODO:
3427 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3428 * because we will send mgmt frames without CCK. This requirement
3429 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3430 * in the TX packet.
3431 */
3432static int ath10k_add_interface(struct ieee80211_hw *hw,
3433 struct ieee80211_vif *vif)
3434{
3435 struct ath10k *ar = hw->priv;
3436 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3437 enum wmi_sta_powersave_param param;
3438 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003439 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003440 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003441 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003442
Johannes Berg848955c2014-11-11 12:48:42 +01003443 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3444
Kalle Valo5e3dd152013-06-12 20:52:10 +03003445 mutex_lock(&ar->conf_mutex);
3446
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003447 memset(arvif, 0, sizeof(*arvif));
3448
Kalle Valo5e3dd152013-06-12 20:52:10 +03003449 arvif->ar = ar;
3450 arvif->vif = vif;
3451
Ben Greeare63b33f2013-10-22 14:54:14 -07003452 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003453 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003454 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3455 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003456
Ben Greeara9aefb32014-08-12 11:02:19 +03003457 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003458 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003459 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003460 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003461 }
Ben Greear16c11172014-09-23 14:17:16 -07003462 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003463
Ben Greear16c11172014-09-23 14:17:16 -07003464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3465 bit, ar->free_vdev_map);
3466
3467 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003468 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469
Kalle Valo5e3dd152013-06-12 20:52:10 +03003470 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003471 case NL80211_IFTYPE_P2P_DEVICE:
3472 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3473 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3474 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475 case NL80211_IFTYPE_UNSPECIFIED:
3476 case NL80211_IFTYPE_STATION:
3477 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3478 if (vif->p2p)
3479 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3480 break;
3481 case NL80211_IFTYPE_ADHOC:
3482 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3483 break;
3484 case NL80211_IFTYPE_AP:
3485 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3486
3487 if (vif->p2p)
3488 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3489 break;
3490 case NL80211_IFTYPE_MONITOR:
3491 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3492 break;
3493 default:
3494 WARN_ON(1);
3495 break;
3496 }
3497
Michal Kazior64badcb2014-09-18 11:18:02 +03003498 /* Some firmware revisions don't wait for beacon tx completion before
3499 * sending another SWBA event. This could lead to hardware using old
3500 * (freed) beacon data in some cases, e.g. tx credit starvation
3501 * combined with missed TBTT. This is very very rare.
3502 *
3503 * On non-IOMMU-enabled hosts this could be a possible security issue
3504 * because hw could beacon some random data on the air. On
3505 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3506 * device would crash.
3507 *
3508 * Since there are no beacon tx completions (implicit nor explicit)
3509 * propagated to host the only workaround for this is to allocate a
3510 * DMA-coherent buffer for a lifetime of a vif and use it for all
3511 * beacon tx commands. Worst case for this approach is some beacons may
3512 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3513 */
3514 if (vif->type == NL80211_IFTYPE_ADHOC ||
3515 vif->type == NL80211_IFTYPE_AP) {
3516 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3517 IEEE80211_MAX_FRAME_LEN,
3518 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303519 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003520 if (!arvif->beacon_buf) {
3521 ret = -ENOMEM;
3522 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3523 ret);
3524 goto err;
3525 }
3526 }
3527
3528 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3529 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3530 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003531
3532 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3533 arvif->vdev_subtype, vif->addr);
3534 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003535 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003536 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003537 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 }
3539
Ben Greear16c11172014-09-23 14:17:16 -07003540 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003541 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003542
Michal Kazior46725b152015-01-28 09:57:49 +02003543 /* It makes no sense to have firmware do keepalives. mac80211 already
3544 * takes care of this with idle connection polling.
3545 */
3546 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003547 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003548 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003549 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003550 goto err_vdev_delete;
3551 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003552
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003553 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003554
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003555 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3556 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003558 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003559 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003560 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003561 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003562 goto err_vdev_delete;
3563 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003564
Ben Greear5572a952014-11-24 16:22:10 +02003565 if (ar->cfg_tx_chainmask) {
3566 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3567
3568 vdev_param = ar->wmi.vdev_param->nss;
3569 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3570 nss);
3571 if (ret) {
3572 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3573 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3574 ret);
3575 goto err_vdev_delete;
3576 }
3577 }
3578
Kalle Valo5e3dd152013-06-12 20:52:10 +03003579 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3580 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3581 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003582 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003583 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003584 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003585 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003586
Kalle Valo5a13e762014-01-20 11:01:46 +02003587 ret = ath10k_mac_set_kickout(arvif);
3588 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003589 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003590 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003591 goto err_peer_delete;
3592 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003593 }
3594
3595 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3596 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3597 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3598 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3599 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003600 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003601 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003602 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003603 goto err_peer_delete;
3604 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605
Michal Kazior9f9b5742014-12-12 12:41:36 +01003606 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003607 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003608 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003609 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003610 goto err_peer_delete;
3611 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003612
Michal Kazior9f9b5742014-12-12 12:41:36 +01003613 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003614 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003615 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003616 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003617 goto err_peer_delete;
3618 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003619 }
3620
Michal Kazior424121c2013-07-22 14:13:31 +02003621 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003622 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003623 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003624 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003625 goto err_peer_delete;
3626 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003627
Michal Kazior424121c2013-07-22 14:13:31 +02003628 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003629 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003630 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003631 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003632 goto err_peer_delete;
3633 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003634
Michal Kazior7d9d5582014-10-21 10:40:15 +03003635 arvif->txpower = vif->bss_conf.txpower;
3636 ret = ath10k_mac_txpower_recalc(ar);
3637 if (ret) {
3638 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3639 goto err_peer_delete;
3640 }
3641
Kalle Valo5e3dd152013-06-12 20:52:10 +03003642 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003643 return 0;
3644
3645err_peer_delete:
3646 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3647 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3648
3649err_vdev_delete:
3650 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003651 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003652 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003653
3654err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003655 if (arvif->beacon_buf) {
3656 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3657 arvif->beacon_buf, arvif->beacon_paddr);
3658 arvif->beacon_buf = NULL;
3659 }
3660
Michal Kazior9dad14a2013-10-16 15:44:45 +03003661 mutex_unlock(&ar->conf_mutex);
3662
Kalle Valo5e3dd152013-06-12 20:52:10 +03003663 return ret;
3664}
3665
3666static void ath10k_remove_interface(struct ieee80211_hw *hw,
3667 struct ieee80211_vif *vif)
3668{
3669 struct ath10k *ar = hw->priv;
3670 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3671 int ret;
3672
Michal Kazior81a9a172015-03-05 16:02:17 +02003673 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003674 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003675
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303676 mutex_lock(&ar->conf_mutex);
3677
Michal Kaziored543882013-09-13 14:16:56 +02003678 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003679 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003680 spin_unlock_bh(&ar->data_lock);
3681
Simon Wunderlich855aed12014-08-02 09:12:54 +03003682 ret = ath10k_spectral_vif_stop(arvif);
3683 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003684 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003685 arvif->vdev_id, ret);
3686
Ben Greear16c11172014-09-23 14:17:16 -07003687 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003688 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003689
3690 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003691 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3692 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003693 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003694 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003695 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003696
3697 kfree(arvif->u.ap.noa_data);
3698 }
3699
Michal Kazior7aa7a722014-08-25 12:09:38 +02003700 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003701 arvif->vdev_id);
3702
Kalle Valo5e3dd152013-06-12 20:52:10 +03003703 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3704 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003705 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003706 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707
Michal Kazior2c512052015-02-15 16:50:40 +02003708 /* Some firmware revisions don't notify host about self-peer removal
3709 * until after associated vdev is deleted.
3710 */
3711 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3712 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3713 vif->addr);
3714 if (ret)
3715 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3716 arvif->vdev_id, ret);
3717
3718 spin_lock_bh(&ar->data_lock);
3719 ar->num_peers--;
3720 spin_unlock_bh(&ar->data_lock);
3721 }
3722
Kalle Valo5e3dd152013-06-12 20:52:10 +03003723 ath10k_peer_cleanup(ar, arvif->vdev_id);
3724
3725 mutex_unlock(&ar->conf_mutex);
3726}
3727
3728/*
3729 * FIXME: Has to be verified.
3730 */
3731#define SUPPORTED_FILTERS \
3732 (FIF_PROMISC_IN_BSS | \
3733 FIF_ALLMULTI | \
3734 FIF_CONTROL | \
3735 FIF_PSPOLL | \
3736 FIF_OTHER_BSS | \
3737 FIF_BCN_PRBRESP_PROMISC | \
3738 FIF_PROBE_REQ | \
3739 FIF_FCSFAIL)
3740
3741static void ath10k_configure_filter(struct ieee80211_hw *hw,
3742 unsigned int changed_flags,
3743 unsigned int *total_flags,
3744 u64 multicast)
3745{
3746 struct ath10k *ar = hw->priv;
3747 int ret;
3748
3749 mutex_lock(&ar->conf_mutex);
3750
3751 changed_flags &= SUPPORTED_FILTERS;
3752 *total_flags &= SUPPORTED_FILTERS;
3753 ar->filter_flags = *total_flags;
3754
Michal Kazior19337472014-08-28 12:58:16 +02003755 ret = ath10k_monitor_recalc(ar);
3756 if (ret)
3757 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003758
3759 mutex_unlock(&ar->conf_mutex);
3760}
3761
3762static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3763 struct ieee80211_vif *vif,
3764 struct ieee80211_bss_conf *info,
3765 u32 changed)
3766{
3767 struct ath10k *ar = hw->priv;
3768 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3769 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003770 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003771
3772 mutex_lock(&ar->conf_mutex);
3773
3774 if (changed & BSS_CHANGED_IBSS)
3775 ath10k_control_ibss(arvif, info, vif->addr);
3776
3777 if (changed & BSS_CHANGED_BEACON_INT) {
3778 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003779 vdev_param = ar->wmi.vdev_param->beacon_interval;
3780 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003781 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003782 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003783 "mac vdev %d beacon_interval %d\n",
3784 arvif->vdev_id, arvif->beacon_interval);
3785
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003787 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003788 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003789 }
3790
3791 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003792 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003793 "vdev %d set beacon tx mode to staggered\n",
3794 arvif->vdev_id);
3795
Bartosz Markowski226a3392013-09-26 17:47:16 +02003796 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3797 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003798 WMI_BEACON_STAGGERED_MODE);
3799 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003800 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003801 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003802
3803 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3804 if (ret)
3805 ath10k_warn(ar, "failed to update beacon template: %d\n",
3806 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003807 }
3808
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003809 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3810 ret = ath10k_mac_setup_prb_tmpl(arvif);
3811 if (ret)
3812 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3813 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003814 }
3815
Michal Kaziorba2479f2015-01-24 12:14:51 +02003816 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003817 arvif->dtim_period = info->dtim_period;
3818
Michal Kazior7aa7a722014-08-25 12:09:38 +02003819 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003820 "mac vdev %d dtim_period %d\n",
3821 arvif->vdev_id, arvif->dtim_period);
3822
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003823 vdev_param = ar->wmi.vdev_param->dtim_period;
3824 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003825 arvif->dtim_period);
3826 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003827 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003828 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003829 }
3830
3831 if (changed & BSS_CHANGED_SSID &&
3832 vif->type == NL80211_IFTYPE_AP) {
3833 arvif->u.ap.ssid_len = info->ssid_len;
3834 if (info->ssid_len)
3835 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3836 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3837 }
3838
Michal Kazior077efc82014-10-21 10:10:29 +03003839 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3840 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003841
3842 if (changed & BSS_CHANGED_BEACON_ENABLED)
3843 ath10k_control_beaconing(arvif, info);
3844
3845 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003846 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003847 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003848 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003849
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003850 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003851 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003852 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003853 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003854
3855 vdev_param = ar->wmi.vdev_param->protection_mode;
3856 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3857 info->use_cts_prot ? 1 : 0);
3858 if (ret)
3859 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3860 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003861 }
3862
3863 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003864 if (info->use_short_slot)
3865 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3866
3867 else
3868 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3869
Michal Kazior7aa7a722014-08-25 12:09:38 +02003870 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003871 arvif->vdev_id, slottime);
3872
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003873 vdev_param = ar->wmi.vdev_param->slot_time;
3874 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003875 slottime);
3876 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003877 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003878 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 }
3880
3881 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003882 if (info->use_short_preamble)
3883 preamble = WMI_VDEV_PREAMBLE_SHORT;
3884 else
3885 preamble = WMI_VDEV_PREAMBLE_LONG;
3886
Michal Kazior7aa7a722014-08-25 12:09:38 +02003887 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003888 "mac vdev %d preamble %dn",
3889 arvif->vdev_id, preamble);
3890
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003891 vdev_param = ar->wmi.vdev_param->preamble;
3892 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893 preamble);
3894 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003895 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003896 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003897 }
3898
3899 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003900 if (info->assoc) {
3901 /* Workaround: Make sure monitor vdev is not running
3902 * when associating to prevent some firmware revisions
3903 * (e.g. 10.1 and 10.2) from crashing.
3904 */
3905 if (ar->monitor_started)
3906 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003907 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003908 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003909 } else {
3910 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003911 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003912 }
3913
Michal Kazior7d9d5582014-10-21 10:40:15 +03003914 if (changed & BSS_CHANGED_TXPOWER) {
3915 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3916 arvif->vdev_id, info->txpower);
3917
3918 arvif->txpower = info->txpower;
3919 ret = ath10k_mac_txpower_recalc(ar);
3920 if (ret)
3921 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3922 }
3923
Michal Kaziorbf14e652014-12-12 12:41:38 +01003924 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003925 arvif->ps = vif->bss_conf.ps;
3926
3927 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003928 if (ret)
3929 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3930 arvif->vdev_id, ret);
3931 }
3932
Kalle Valo5e3dd152013-06-12 20:52:10 +03003933 mutex_unlock(&ar->conf_mutex);
3934}
3935
3936static int ath10k_hw_scan(struct ieee80211_hw *hw,
3937 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003938 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003939{
3940 struct ath10k *ar = hw->priv;
3941 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003942 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003943 struct wmi_start_scan_arg arg;
3944 int ret = 0;
3945 int i;
3946
3947 mutex_lock(&ar->conf_mutex);
3948
3949 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003950 switch (ar->scan.state) {
3951 case ATH10K_SCAN_IDLE:
3952 reinit_completion(&ar->scan.started);
3953 reinit_completion(&ar->scan.completed);
3954 ar->scan.state = ATH10K_SCAN_STARTING;
3955 ar->scan.is_roc = false;
3956 ar->scan.vdev_id = arvif->vdev_id;
3957 ret = 0;
3958 break;
3959 case ATH10K_SCAN_STARTING:
3960 case ATH10K_SCAN_RUNNING:
3961 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003963 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003964 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003965 spin_unlock_bh(&ar->data_lock);
3966
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003967 if (ret)
3968 goto exit;
3969
Kalle Valo5e3dd152013-06-12 20:52:10 +03003970 memset(&arg, 0, sizeof(arg));
3971 ath10k_wmi_start_scan_init(ar, &arg);
3972 arg.vdev_id = arvif->vdev_id;
3973 arg.scan_id = ATH10K_SCAN_ID;
3974
3975 if (!req->no_cck)
3976 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3977
3978 if (req->ie_len) {
3979 arg.ie_len = req->ie_len;
3980 memcpy(arg.ie, req->ie, arg.ie_len);
3981 }
3982
3983 if (req->n_ssids) {
3984 arg.n_ssids = req->n_ssids;
3985 for (i = 0; i < arg.n_ssids; i++) {
3986 arg.ssids[i].len = req->ssids[i].ssid_len;
3987 arg.ssids[i].ssid = req->ssids[i].ssid;
3988 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003989 } else {
3990 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003991 }
3992
3993 if (req->n_channels) {
3994 arg.n_channels = req->n_channels;
3995 for (i = 0; i < arg.n_channels; i++)
3996 arg.channels[i] = req->channels[i]->center_freq;
3997 }
3998
3999 ret = ath10k_start_scan(ar, &arg);
4000 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004001 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004002 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004003 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004004 spin_unlock_bh(&ar->data_lock);
4005 }
4006
4007exit:
4008 mutex_unlock(&ar->conf_mutex);
4009 return ret;
4010}
4011
4012static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4013 struct ieee80211_vif *vif)
4014{
4015 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004016
4017 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004018 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004020
4021 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022}
4023
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004024static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4025 struct ath10k_vif *arvif,
4026 enum set_key_cmd cmd,
4027 struct ieee80211_key_conf *key)
4028{
4029 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4030 int ret;
4031
4032 /* 10.1 firmware branch requires default key index to be set to group
4033 * key index after installing it. Otherwise FW/HW Txes corrupted
4034 * frames with multi-vif APs. This is not required for main firmware
4035 * branch (e.g. 636).
4036 *
4037 * FIXME: This has been tested only in AP. It remains unknown if this
4038 * is required for multi-vif STA interfaces on 10.1 */
4039
4040 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4041 return;
4042
4043 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4044 return;
4045
4046 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4047 return;
4048
4049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4050 return;
4051
4052 if (cmd != SET_KEY)
4053 return;
4054
4055 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4056 key->keyidx);
4057 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004058 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004059 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004060}
4061
Kalle Valo5e3dd152013-06-12 20:52:10 +03004062static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4063 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4064 struct ieee80211_key_conf *key)
4065{
4066 struct ath10k *ar = hw->priv;
4067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4068 struct ath10k_peer *peer;
4069 const u8 *peer_addr;
4070 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4071 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4072 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004073 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004074
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004075 /* this one needs to be done in software */
4076 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4077 return 1;
4078
Kalle Valo5e3dd152013-06-12 20:52:10 +03004079 if (key->keyidx > WMI_MAX_KEY_INDEX)
4080 return -ENOSPC;
4081
4082 mutex_lock(&ar->conf_mutex);
4083
4084 if (sta)
4085 peer_addr = sta->addr;
4086 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4087 peer_addr = vif->bss_conf.bssid;
4088 else
4089 peer_addr = vif->addr;
4090
4091 key->hw_key_idx = key->keyidx;
4092
4093 /* the peer should not disappear in mid-way (unless FW goes awry) since
4094 * we already hold conf_mutex. we just make sure its there now. */
4095 spin_lock_bh(&ar->data_lock);
4096 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4097 spin_unlock_bh(&ar->data_lock);
4098
4099 if (!peer) {
4100 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004101 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004102 peer_addr);
4103 ret = -EOPNOTSUPP;
4104 goto exit;
4105 } else {
4106 /* if the peer doesn't exist there is no key to disable
4107 * anymore */
4108 goto exit;
4109 }
4110 }
4111
Michal Kazior7cc45732015-03-09 14:24:17 +01004112 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4113 flags |= WMI_KEY_PAIRWISE;
4114 else
4115 flags |= WMI_KEY_GROUP;
4116
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117 if (is_wep) {
4118 if (cmd == SET_KEY)
4119 arvif->wep_keys[key->keyidx] = key;
4120 else
4121 arvif->wep_keys[key->keyidx] = NULL;
4122
4123 if (cmd == DISABLE_KEY)
4124 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004125
Michal Kaziorad325cb2015-02-18 14:02:27 +01004126 /* When WEP keys are uploaded it's possible that there are
4127 * stations associated already (e.g. when merging) without any
4128 * keys. Static WEP needs an explicit per-peer key upload.
4129 */
4130 if (vif->type == NL80211_IFTYPE_ADHOC &&
4131 cmd == SET_KEY)
4132 ath10k_mac_vif_update_wep_key(arvif, key);
4133
Michal Kazior370e5672015-02-18 14:02:26 +01004134 /* 802.1x never sets the def_wep_key_idx so each set_key()
4135 * call changes default tx key.
4136 *
4137 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4138 * after first set_key().
4139 */
4140 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4141 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142
Michal Kazior7cc45732015-03-09 14:24:17 +01004143 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4144 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4145 * mode and associated stations in AP/IBSS.
4146 *
4147 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4148 * work fine when mapped directly from mac80211.
4149 *
4150 * Note: When installing first static WEP groupwise key (which
4151 * should be pairwise) def_wep_key_idx isn't known yet (it's
4152 * equal to -1). Since .set_default_unicast_key is called only
4153 * for static WEP it's used to re-upload the key as pairwise.
4154 */
4155 if (arvif->def_wep_key_idx >= 0 &&
4156 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4157 flags &= ~WMI_KEY_GROUP;
4158 flags |= WMI_KEY_PAIRWISE;
4159 }
Michal Kazior370e5672015-02-18 14:02:26 +01004160 }
4161
4162 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004163 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004164 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004165 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004166 goto exit;
4167 }
4168
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004169 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4170
Kalle Valo5e3dd152013-06-12 20:52:10 +03004171 spin_lock_bh(&ar->data_lock);
4172 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4173 if (peer && cmd == SET_KEY)
4174 peer->keys[key->keyidx] = key;
4175 else if (peer && cmd == DISABLE_KEY)
4176 peer->keys[key->keyidx] = NULL;
4177 else if (peer == NULL)
4178 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004179 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004180 spin_unlock_bh(&ar->data_lock);
4181
4182exit:
4183 mutex_unlock(&ar->conf_mutex);
4184 return ret;
4185}
4186
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004187static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4188 struct ieee80211_vif *vif,
4189 int keyidx)
4190{
4191 struct ath10k *ar = hw->priv;
4192 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4193 int ret;
4194
4195 mutex_lock(&arvif->ar->conf_mutex);
4196
4197 if (arvif->ar->state != ATH10K_STATE_ON)
4198 goto unlock;
4199
4200 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4201 arvif->vdev_id, keyidx);
4202
4203 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4204 arvif->vdev_id,
4205 arvif->ar->wmi.vdev_param->def_keyid,
4206 keyidx);
4207
4208 if (ret) {
4209 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4210 arvif->vdev_id,
4211 ret);
4212 goto unlock;
4213 }
4214
4215 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004216
4217 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4218 if (ret) {
4219 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4220 arvif->vdev_id, ret);
4221 goto unlock;
4222 }
4223
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004224unlock:
4225 mutex_unlock(&arvif->ar->conf_mutex);
4226}
4227
Michal Kazior9797feb2014-02-14 14:49:48 +01004228static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4229{
4230 struct ath10k *ar;
4231 struct ath10k_vif *arvif;
4232 struct ath10k_sta *arsta;
4233 struct ieee80211_sta *sta;
4234 u32 changed, bw, nss, smps;
4235 int err;
4236
4237 arsta = container_of(wk, struct ath10k_sta, update_wk);
4238 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4239 arvif = arsta->arvif;
4240 ar = arvif->ar;
4241
4242 spin_lock_bh(&ar->data_lock);
4243
4244 changed = arsta->changed;
4245 arsta->changed = 0;
4246
4247 bw = arsta->bw;
4248 nss = arsta->nss;
4249 smps = arsta->smps;
4250
4251 spin_unlock_bh(&ar->data_lock);
4252
4253 mutex_lock(&ar->conf_mutex);
4254
4255 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004256 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004257 sta->addr, bw);
4258
4259 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4260 WMI_PEER_CHAN_WIDTH, bw);
4261 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004262 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004263 sta->addr, bw, err);
4264 }
4265
4266 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004268 sta->addr, nss);
4269
4270 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4271 WMI_PEER_NSS, nss);
4272 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004273 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004274 sta->addr, nss, err);
4275 }
4276
4277 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004278 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004279 sta->addr, smps);
4280
4281 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4282 WMI_PEER_SMPS_STATE, smps);
4283 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004284 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004285 sta->addr, smps, err);
4286 }
4287
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004288 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4289 changed & IEEE80211_RC_NSS_CHANGED) {
4290 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004291 sta->addr);
4292
Michal Kazior590922a2014-10-21 10:10:29 +03004293 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004294 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004295 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004296 sta->addr);
4297 }
4298
Michal Kazior9797feb2014-02-14 14:49:48 +01004299 mutex_unlock(&ar->conf_mutex);
4300}
4301
Michal Kaziorcfd10612014-11-25 15:16:05 +01004302static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4303{
4304 struct ath10k *ar = arvif->ar;
4305
4306 lockdep_assert_held(&ar->conf_mutex);
4307
4308 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4309 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4310 return 0;
4311
4312 if (ar->num_stations >= ar->max_num_stations)
4313 return -ENOBUFS;
4314
4315 ar->num_stations++;
4316
4317 return 0;
4318}
4319
4320static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4321{
4322 struct ath10k *ar = arvif->ar;
4323
4324 lockdep_assert_held(&ar->conf_mutex);
4325
4326 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4327 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4328 return;
4329
4330 ar->num_stations--;
4331}
4332
Kalle Valo5e3dd152013-06-12 20:52:10 +03004333static int ath10k_sta_state(struct ieee80211_hw *hw,
4334 struct ieee80211_vif *vif,
4335 struct ieee80211_sta *sta,
4336 enum ieee80211_sta_state old_state,
4337 enum ieee80211_sta_state new_state)
4338{
4339 struct ath10k *ar = hw->priv;
4340 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004341 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004342 int ret = 0;
4343
Michal Kazior76f90022014-02-25 09:29:57 +02004344 if (old_state == IEEE80211_STA_NOTEXIST &&
4345 new_state == IEEE80211_STA_NONE) {
4346 memset(arsta, 0, sizeof(*arsta));
4347 arsta->arvif = arvif;
4348 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4349 }
4350
Michal Kazior9797feb2014-02-14 14:49:48 +01004351 /* cancel must be done outside the mutex to avoid deadlock */
4352 if ((old_state == IEEE80211_STA_NONE &&
4353 new_state == IEEE80211_STA_NOTEXIST))
4354 cancel_work_sync(&arsta->update_wk);
4355
Kalle Valo5e3dd152013-06-12 20:52:10 +03004356 mutex_lock(&ar->conf_mutex);
4357
4358 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004359 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004360 /*
4361 * New station addition.
4362 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004363 ath10k_dbg(ar, ATH10K_DBG_MAC,
4364 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4365 arvif->vdev_id, sta->addr,
4366 ar->num_stations + 1, ar->max_num_stations,
4367 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004368
Michal Kaziorcfd10612014-11-25 15:16:05 +01004369 ret = ath10k_mac_inc_num_stations(arvif);
4370 if (ret) {
4371 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4372 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004373 goto exit;
4374 }
4375
Kalle Valo5e3dd152013-06-12 20:52:10 +03004376 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004377 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004378 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 -08004379 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004380 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004381 goto exit;
4382 }
Michal Kazior077efc82014-10-21 10:10:29 +03004383
4384 if (vif->type == NL80211_IFTYPE_STATION) {
4385 WARN_ON(arvif->is_started);
4386
4387 ret = ath10k_vdev_start(arvif);
4388 if (ret) {
4389 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4390 arvif->vdev_id, ret);
4391 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4392 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004393 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004394 goto exit;
4395 }
4396
4397 arvif->is_started = true;
4398 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004399 } else if ((old_state == IEEE80211_STA_NONE &&
4400 new_state == IEEE80211_STA_NOTEXIST)) {
4401 /*
4402 * Existing station deletion.
4403 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004404 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004405 "mac vdev %d peer delete %pM (sta gone)\n",
4406 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004407
4408 if (vif->type == NL80211_IFTYPE_STATION) {
4409 WARN_ON(!arvif->is_started);
4410
4411 ret = ath10k_vdev_stop(arvif);
4412 if (ret)
4413 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4414 arvif->vdev_id, ret);
4415
4416 arvif->is_started = false;
4417 }
4418
Kalle Valo5e3dd152013-06-12 20:52:10 +03004419 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4420 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004421 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004422 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004423
Michal Kaziorcfd10612014-11-25 15:16:05 +01004424 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004425 } else if (old_state == IEEE80211_STA_AUTH &&
4426 new_state == IEEE80211_STA_ASSOC &&
4427 (vif->type == NL80211_IFTYPE_AP ||
4428 vif->type == NL80211_IFTYPE_ADHOC)) {
4429 /*
4430 * New association.
4431 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004432 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004433 sta->addr);
4434
Michal Kazior590922a2014-10-21 10:10:29 +03004435 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004436 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004437 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004438 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004439 } else if (old_state == IEEE80211_STA_ASSOC &&
4440 new_state == IEEE80211_STA_AUTH &&
4441 (vif->type == NL80211_IFTYPE_AP ||
4442 vif->type == NL80211_IFTYPE_ADHOC)) {
4443 /*
4444 * Disassociation.
4445 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004446 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004447 sta->addr);
4448
Michal Kazior590922a2014-10-21 10:10:29 +03004449 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004450 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004451 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004452 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004453 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004454exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004455 mutex_unlock(&ar->conf_mutex);
4456 return ret;
4457}
4458
4459static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004460 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004461{
4462 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004463 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4464 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004465 u32 value = 0;
4466 int ret = 0;
4467
Michal Kazior548db542013-07-05 16:15:15 +03004468 lockdep_assert_held(&ar->conf_mutex);
4469
Kalle Valo5e3dd152013-06-12 20:52:10 +03004470 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4471 return 0;
4472
4473 switch (ac) {
4474 case IEEE80211_AC_VO:
4475 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4476 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004477 prio = 7;
4478 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004479 break;
4480 case IEEE80211_AC_VI:
4481 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4482 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004483 prio = 5;
4484 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004485 break;
4486 case IEEE80211_AC_BE:
4487 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4488 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004489 prio = 2;
4490 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004491 break;
4492 case IEEE80211_AC_BK:
4493 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4494 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004495 prio = 0;
4496 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004497 break;
4498 }
4499
4500 if (enable)
4501 arvif->u.sta.uapsd |= value;
4502 else
4503 arvif->u.sta.uapsd &= ~value;
4504
4505 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4506 WMI_STA_PS_PARAM_UAPSD,
4507 arvif->u.sta.uapsd);
4508 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004509 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 goto exit;
4511 }
4512
4513 if (arvif->u.sta.uapsd)
4514 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4515 else
4516 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4517
4518 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4519 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4520 value);
4521 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004522 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004523
Michal Kazior9f9b5742014-12-12 12:41:36 +01004524 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4525 if (ret) {
4526 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4527 arvif->vdev_id, ret);
4528 return ret;
4529 }
4530
4531 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4532 if (ret) {
4533 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4534 arvif->vdev_id, ret);
4535 return ret;
4536 }
4537
Michal Kaziorb0e56152015-01-24 12:14:52 +02004538 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4539 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4540 /* Only userspace can make an educated decision when to send
4541 * trigger frame. The following effectively disables u-UAPSD
4542 * autotrigger in firmware (which is enabled by default
4543 * provided the autotrigger service is available).
4544 */
4545
4546 arg.wmm_ac = acc;
4547 arg.user_priority = prio;
4548 arg.service_interval = 0;
4549 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4550 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4551
4552 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4553 arvif->bssid, &arg, 1);
4554 if (ret) {
4555 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4556 ret);
4557 return ret;
4558 }
4559 }
4560
Kalle Valo5e3dd152013-06-12 20:52:10 +03004561exit:
4562 return ret;
4563}
4564
4565static int ath10k_conf_tx(struct ieee80211_hw *hw,
4566 struct ieee80211_vif *vif, u16 ac,
4567 const struct ieee80211_tx_queue_params *params)
4568{
4569 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004570 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004571 struct wmi_wmm_params_arg *p = NULL;
4572 int ret;
4573
4574 mutex_lock(&ar->conf_mutex);
4575
4576 switch (ac) {
4577 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004578 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004579 break;
4580 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004581 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004582 break;
4583 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004584 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004585 break;
4586 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004587 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004588 break;
4589 }
4590
4591 if (WARN_ON(!p)) {
4592 ret = -EINVAL;
4593 goto exit;
4594 }
4595
4596 p->cwmin = params->cw_min;
4597 p->cwmax = params->cw_max;
4598 p->aifs = params->aifs;
4599
4600 /*
4601 * The channel time duration programmed in the HW is in absolute
4602 * microseconds, while mac80211 gives the txop in units of
4603 * 32 microseconds.
4604 */
4605 p->txop = params->txop * 32;
4606
Michal Kazior7fc979a2015-01-28 09:57:28 +02004607 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4608 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4609 &arvif->wmm_params);
4610 if (ret) {
4611 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4612 arvif->vdev_id, ret);
4613 goto exit;
4614 }
4615 } else {
4616 /* This won't work well with multi-interface cases but it's
4617 * better than nothing.
4618 */
4619 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4620 if (ret) {
4621 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4622 goto exit;
4623 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624 }
4625
4626 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4627 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004628 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004629
4630exit:
4631 mutex_unlock(&ar->conf_mutex);
4632 return ret;
4633}
4634
4635#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4636
4637static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4638 struct ieee80211_vif *vif,
4639 struct ieee80211_channel *chan,
4640 int duration,
4641 enum ieee80211_roc_type type)
4642{
4643 struct ath10k *ar = hw->priv;
4644 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4645 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004646 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004647
4648 mutex_lock(&ar->conf_mutex);
4649
4650 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004651 switch (ar->scan.state) {
4652 case ATH10K_SCAN_IDLE:
4653 reinit_completion(&ar->scan.started);
4654 reinit_completion(&ar->scan.completed);
4655 reinit_completion(&ar->scan.on_channel);
4656 ar->scan.state = ATH10K_SCAN_STARTING;
4657 ar->scan.is_roc = true;
4658 ar->scan.vdev_id = arvif->vdev_id;
4659 ar->scan.roc_freq = chan->center_freq;
4660 ret = 0;
4661 break;
4662 case ATH10K_SCAN_STARTING:
4663 case ATH10K_SCAN_RUNNING:
4664 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004665 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004666 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004667 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004668 spin_unlock_bh(&ar->data_lock);
4669
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004670 if (ret)
4671 goto exit;
4672
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004673 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4674
Kalle Valo5e3dd152013-06-12 20:52:10 +03004675 memset(&arg, 0, sizeof(arg));
4676 ath10k_wmi_start_scan_init(ar, &arg);
4677 arg.vdev_id = arvif->vdev_id;
4678 arg.scan_id = ATH10K_SCAN_ID;
4679 arg.n_channels = 1;
4680 arg.channels[0] = chan->center_freq;
4681 arg.dwell_time_active = duration;
4682 arg.dwell_time_passive = duration;
4683 arg.max_scan_time = 2 * duration;
4684 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4685 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4686
4687 ret = ath10k_start_scan(ar, &arg);
4688 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004689 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004690 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004691 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004692 spin_unlock_bh(&ar->data_lock);
4693 goto exit;
4694 }
4695
4696 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4697 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004698 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004699
4700 ret = ath10k_scan_stop(ar);
4701 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004702 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004703
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704 ret = -ETIMEDOUT;
4705 goto exit;
4706 }
4707
4708 ret = 0;
4709exit:
4710 mutex_unlock(&ar->conf_mutex);
4711 return ret;
4712}
4713
4714static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4715{
4716 struct ath10k *ar = hw->priv;
4717
4718 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004719 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004720 mutex_unlock(&ar->conf_mutex);
4721
Michal Kazior4eb2e162014-10-28 10:23:09 +01004722 cancel_delayed_work_sync(&ar->scan.timeout);
4723
Kalle Valo5e3dd152013-06-12 20:52:10 +03004724 return 0;
4725}
4726
4727/*
4728 * Both RTS and Fragmentation threshold are interface-specific
4729 * in ath10k, but device-specific in mac80211.
4730 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004731
4732static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4733{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004734 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004735 struct ath10k_vif *arvif;
4736 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004737
Michal Kaziorad088bf2013-10-16 15:44:46 +03004738 mutex_lock(&ar->conf_mutex);
4739 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004741 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004742
Michal Kaziorad088bf2013-10-16 15:44:46 +03004743 ret = ath10k_mac_set_rts(arvif, value);
4744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004745 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004746 arvif->vdev_id, ret);
4747 break;
4748 }
4749 }
4750 mutex_unlock(&ar->conf_mutex);
4751
4752 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004753}
4754
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004755static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4756 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004757{
4758 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004759 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004760 int ret;
4761
4762 /* mac80211 doesn't care if we really xmit queued frames or not
4763 * we'll collect those frames either way if we stop/delete vdevs */
4764 if (drop)
4765 return;
4766
Michal Kazior548db542013-07-05 16:15:15 +03004767 mutex_lock(&ar->conf_mutex);
4768
Michal Kazioraffd3212013-07-16 09:54:35 +02004769 if (ar->state == ATH10K_STATE_WEDGED)
4770 goto skip;
4771
Michal Kazioredb82362013-07-05 16:15:14 +03004772 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004773 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004774
Michal Kazioredb82362013-07-05 16:15:14 +03004775 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004776 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004777 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004778
Michal Kazior7962b0d2014-10-28 10:34:38 +01004779 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4780 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4781 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004782
4783 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004784 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004785
4786 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004787 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004788 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004789
Michal Kazioraffd3212013-07-16 09:54:35 +02004790skip:
Michal Kazior548db542013-07-05 16:15:15 +03004791 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792}
4793
4794/* TODO: Implement this function properly
4795 * For now it is needed to reply to Probe Requests in IBSS mode.
4796 * Propably we need this information from FW.
4797 */
4798static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4799{
4800 return 1;
4801}
4802
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004803#ifdef CONFIG_PM
4804static int ath10k_suspend(struct ieee80211_hw *hw,
4805 struct cfg80211_wowlan *wowlan)
4806{
4807 struct ath10k *ar = hw->priv;
4808 int ret;
4809
Marek Puzyniak9042e172014-02-10 17:14:23 +01004810 mutex_lock(&ar->conf_mutex);
4811
Marek Puzyniak00f54822014-02-10 17:14:24 +01004812 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004813 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004814 if (ret == -ETIMEDOUT)
4815 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004816 ret = 1;
4817 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004818 }
4819
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004820 ret = ath10k_hif_suspend(ar);
4821 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004822 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004823 goto resume;
4824 }
4825
Marek Puzyniak9042e172014-02-10 17:14:23 +01004826 ret = 0;
4827 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004828resume:
4829 ret = ath10k_wmi_pdev_resume_target(ar);
4830 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004831 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004832
4833 ret = 1;
4834exit:
4835 mutex_unlock(&ar->conf_mutex);
4836 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004837}
4838
4839static int ath10k_resume(struct ieee80211_hw *hw)
4840{
4841 struct ath10k *ar = hw->priv;
4842 int ret;
4843
Marek Puzyniak9042e172014-02-10 17:14:23 +01004844 mutex_lock(&ar->conf_mutex);
4845
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004846 ret = ath10k_hif_resume(ar);
4847 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004848 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004849 ret = 1;
4850 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004851 }
4852
4853 ret = ath10k_wmi_pdev_resume_target(ar);
4854 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004855 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004856 ret = 1;
4857 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004858 }
4859
Marek Puzyniak9042e172014-02-10 17:14:23 +01004860 ret = 0;
4861exit:
4862 mutex_unlock(&ar->conf_mutex);
4863 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004864}
4865#endif
4866
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004867static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4868 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004869{
4870 struct ath10k *ar = hw->priv;
4871
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004872 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4873 return;
4874
Michal Kazioraffd3212013-07-16 09:54:35 +02004875 mutex_lock(&ar->conf_mutex);
4876
4877 /* If device failed to restart it will be in a different state, e.g.
4878 * ATH10K_STATE_WEDGED */
4879 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004880 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004881 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004882 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004883 }
4884
4885 mutex_unlock(&ar->conf_mutex);
4886}
4887
Michal Kazior2e1dea42013-07-31 10:32:40 +02004888static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4889 struct survey_info *survey)
4890{
4891 struct ath10k *ar = hw->priv;
4892 struct ieee80211_supported_band *sband;
4893 struct survey_info *ar_survey = &ar->survey[idx];
4894 int ret = 0;
4895
4896 mutex_lock(&ar->conf_mutex);
4897
4898 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4899 if (sband && idx >= sband->n_channels) {
4900 idx -= sband->n_channels;
4901 sband = NULL;
4902 }
4903
4904 if (!sband)
4905 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4906
4907 if (!sband || idx >= sband->n_channels) {
4908 ret = -ENOENT;
4909 goto exit;
4910 }
4911
4912 spin_lock_bh(&ar->data_lock);
4913 memcpy(survey, ar_survey, sizeof(*survey));
4914 spin_unlock_bh(&ar->data_lock);
4915
4916 survey->channel = &sband->channels[idx];
4917
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004918 if (ar->rx_channel == survey->channel)
4919 survey->filled |= SURVEY_INFO_IN_USE;
4920
Michal Kazior2e1dea42013-07-31 10:32:40 +02004921exit:
4922 mutex_unlock(&ar->conf_mutex);
4923 return ret;
4924}
4925
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004926/* Helper table for legacy fixed_rate/bitrate_mask */
4927static const u8 cck_ofdm_rate[] = {
4928 /* CCK */
4929 3, /* 1Mbps */
4930 2, /* 2Mbps */
4931 1, /* 5.5Mbps */
4932 0, /* 11Mbps */
4933 /* OFDM */
4934 3, /* 6Mbps */
4935 7, /* 9Mbps */
4936 2, /* 12Mbps */
4937 6, /* 18Mbps */
4938 1, /* 24Mbps */
4939 5, /* 36Mbps */
4940 0, /* 48Mbps */
4941 4, /* 54Mbps */
4942};
4943
4944/* Check if only one bit set */
4945static int ath10k_check_single_mask(u32 mask)
4946{
4947 int bit;
4948
4949 bit = ffs(mask);
4950 if (!bit)
4951 return 0;
4952
4953 mask &= ~BIT(bit - 1);
4954 if (mask)
4955 return 2;
4956
4957 return 1;
4958}
4959
4960static bool
4961ath10k_default_bitrate_mask(struct ath10k *ar,
4962 enum ieee80211_band band,
4963 const struct cfg80211_bitrate_mask *mask)
4964{
4965 u32 legacy = 0x00ff;
4966 u8 ht = 0xff, i;
4967 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004968 u16 nrf = ar->num_rf_chains;
4969
4970 if (ar->cfg_tx_chainmask)
4971 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004972
4973 switch (band) {
4974 case IEEE80211_BAND_2GHZ:
4975 legacy = 0x00fff;
4976 vht = 0;
4977 break;
4978 case IEEE80211_BAND_5GHZ:
4979 break;
4980 default:
4981 return false;
4982 }
4983
4984 if (mask->control[band].legacy != legacy)
4985 return false;
4986
Ben Greearb116ea12014-11-24 16:22:10 +02004987 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004988 if (mask->control[band].ht_mcs[i] != ht)
4989 return false;
4990
Ben Greearb116ea12014-11-24 16:22:10 +02004991 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004992 if (mask->control[band].vht_mcs[i] != vht)
4993 return false;
4994
4995 return true;
4996}
4997
4998static bool
4999ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5000 enum ieee80211_band band,
5001 u8 *fixed_nss)
5002{
5003 int ht_nss = 0, vht_nss = 0, i;
5004
5005 /* check legacy */
5006 if (ath10k_check_single_mask(mask->control[band].legacy))
5007 return false;
5008
5009 /* check HT */
5010 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5011 if (mask->control[band].ht_mcs[i] == 0xff)
5012 continue;
5013 else if (mask->control[band].ht_mcs[i] == 0x00)
5014 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005015
5016 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005017 }
5018
5019 ht_nss = i;
5020
5021 /* check VHT */
5022 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5023 if (mask->control[band].vht_mcs[i] == 0x03ff)
5024 continue;
5025 else if (mask->control[band].vht_mcs[i] == 0x0000)
5026 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005027
5028 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005029 }
5030
5031 vht_nss = i;
5032
5033 if (ht_nss > 0 && vht_nss > 0)
5034 return false;
5035
5036 if (ht_nss)
5037 *fixed_nss = ht_nss;
5038 else if (vht_nss)
5039 *fixed_nss = vht_nss;
5040 else
5041 return false;
5042
5043 return true;
5044}
5045
5046static bool
5047ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5048 enum ieee80211_band band,
5049 enum wmi_rate_preamble *preamble)
5050{
5051 int legacy = 0, ht = 0, vht = 0, i;
5052
5053 *preamble = WMI_RATE_PREAMBLE_OFDM;
5054
5055 /* check legacy */
5056 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5057 if (legacy > 1)
5058 return false;
5059
5060 /* check HT */
5061 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5062 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5063 if (ht > 1)
5064 return false;
5065
5066 /* check VHT */
5067 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5068 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5069 if (vht > 1)
5070 return false;
5071
5072 /* Currently we support only one fixed_rate */
5073 if ((legacy + ht + vht) != 1)
5074 return false;
5075
5076 if (ht)
5077 *preamble = WMI_RATE_PREAMBLE_HT;
5078 else if (vht)
5079 *preamble = WMI_RATE_PREAMBLE_VHT;
5080
5081 return true;
5082}
5083
5084static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005085ath10k_bitrate_mask_rate(struct ath10k *ar,
5086 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005087 enum ieee80211_band band,
5088 u8 *fixed_rate,
5089 u8 *fixed_nss)
5090{
5091 u8 rate = 0, pream = 0, nss = 0, i;
5092 enum wmi_rate_preamble preamble;
5093
5094 /* Check if single rate correct */
5095 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5096 return false;
5097
5098 pream = preamble;
5099
5100 switch (preamble) {
5101 case WMI_RATE_PREAMBLE_CCK:
5102 case WMI_RATE_PREAMBLE_OFDM:
5103 i = ffs(mask->control[band].legacy) - 1;
5104
5105 if (band == IEEE80211_BAND_2GHZ && i < 4)
5106 pream = WMI_RATE_PREAMBLE_CCK;
5107
5108 if (band == IEEE80211_BAND_5GHZ)
5109 i += 4;
5110
5111 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5112 return false;
5113
5114 rate = cck_ofdm_rate[i];
5115 break;
5116 case WMI_RATE_PREAMBLE_HT:
5117 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5118 if (mask->control[band].ht_mcs[i])
5119 break;
5120
5121 if (i == IEEE80211_HT_MCS_MASK_LEN)
5122 return false;
5123
5124 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5125 nss = i;
5126 break;
5127 case WMI_RATE_PREAMBLE_VHT:
5128 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5129 if (mask->control[band].vht_mcs[i])
5130 break;
5131
5132 if (i == NL80211_VHT_NSS_MAX)
5133 return false;
5134
5135 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5136 nss = i;
5137 break;
5138 }
5139
5140 *fixed_nss = nss + 1;
5141 nss <<= 4;
5142 pream <<= 6;
5143
Michal Kazior7aa7a722014-08-25 12:09:38 +02005144 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 +01005145 pream, nss, rate);
5146
5147 *fixed_rate = pream | nss | rate;
5148
5149 return true;
5150}
5151
Michal Kazior7aa7a722014-08-25 12:09:38 +02005152static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5153 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005154 enum ieee80211_band band,
5155 u8 *fixed_rate,
5156 u8 *fixed_nss)
5157{
5158 /* First check full NSS mask, if we can simply limit NSS */
5159 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5160 return true;
5161
5162 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005163 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005164}
5165
5166static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5167 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005168 u8 fixed_nss,
5169 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005170{
5171 struct ath10k *ar = arvif->ar;
5172 u32 vdev_param;
5173 int ret = 0;
5174
5175 mutex_lock(&ar->conf_mutex);
5176
5177 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005178 arvif->fixed_nss == fixed_nss &&
5179 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005180 goto exit;
5181
5182 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005183 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005184
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005185 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005186 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005187
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005188 vdev_param = ar->wmi.vdev_param->fixed_rate;
5189 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5190 vdev_param, fixed_rate);
5191 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005192 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005193 fixed_rate, ret);
5194 ret = -EINVAL;
5195 goto exit;
5196 }
5197
5198 arvif->fixed_rate = fixed_rate;
5199
5200 vdev_param = ar->wmi.vdev_param->nss;
5201 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5202 vdev_param, fixed_nss);
5203
5204 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005205 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005206 fixed_nss, ret);
5207 ret = -EINVAL;
5208 goto exit;
5209 }
5210
5211 arvif->fixed_nss = fixed_nss;
5212
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005213 vdev_param = ar->wmi.vdev_param->sgi;
5214 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5215 force_sgi);
5216
5217 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005218 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005219 force_sgi, ret);
5220 ret = -EINVAL;
5221 goto exit;
5222 }
5223
5224 arvif->force_sgi = force_sgi;
5225
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005226exit:
5227 mutex_unlock(&ar->conf_mutex);
5228 return ret;
5229}
5230
5231static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5232 struct ieee80211_vif *vif,
5233 const struct cfg80211_bitrate_mask *mask)
5234{
5235 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5236 struct ath10k *ar = arvif->ar;
5237 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5238 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5239 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005240 u8 force_sgi;
5241
Ben Greearb116ea12014-11-24 16:22:10 +02005242 if (ar->cfg_tx_chainmask)
5243 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5244
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005245 force_sgi = mask->control[band].gi;
5246 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5247 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005248
5249 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005250 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005251 &fixed_rate,
5252 &fixed_nss))
5253 return -EINVAL;
5254 }
5255
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005256 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005257 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005258 return -EINVAL;
5259 }
5260
5261 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5262 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005263}
5264
Michal Kazior9797feb2014-02-14 14:49:48 +01005265static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5266 struct ieee80211_vif *vif,
5267 struct ieee80211_sta *sta,
5268 u32 changed)
5269{
5270 struct ath10k *ar = hw->priv;
5271 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5272 u32 bw, smps;
5273
5274 spin_lock_bh(&ar->data_lock);
5275
Michal Kazior7aa7a722014-08-25 12:09:38 +02005276 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005277 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5278 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5279 sta->smps_mode);
5280
5281 if (changed & IEEE80211_RC_BW_CHANGED) {
5282 bw = WMI_PEER_CHWIDTH_20MHZ;
5283
5284 switch (sta->bandwidth) {
5285 case IEEE80211_STA_RX_BW_20:
5286 bw = WMI_PEER_CHWIDTH_20MHZ;
5287 break;
5288 case IEEE80211_STA_RX_BW_40:
5289 bw = WMI_PEER_CHWIDTH_40MHZ;
5290 break;
5291 case IEEE80211_STA_RX_BW_80:
5292 bw = WMI_PEER_CHWIDTH_80MHZ;
5293 break;
5294 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005295 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005296 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005297 bw = WMI_PEER_CHWIDTH_20MHZ;
5298 break;
5299 }
5300
5301 arsta->bw = bw;
5302 }
5303
5304 if (changed & IEEE80211_RC_NSS_CHANGED)
5305 arsta->nss = sta->rx_nss;
5306
5307 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5308 smps = WMI_PEER_SMPS_PS_NONE;
5309
5310 switch (sta->smps_mode) {
5311 case IEEE80211_SMPS_AUTOMATIC:
5312 case IEEE80211_SMPS_OFF:
5313 smps = WMI_PEER_SMPS_PS_NONE;
5314 break;
5315 case IEEE80211_SMPS_STATIC:
5316 smps = WMI_PEER_SMPS_STATIC;
5317 break;
5318 case IEEE80211_SMPS_DYNAMIC:
5319 smps = WMI_PEER_SMPS_DYNAMIC;
5320 break;
5321 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005322 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005323 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005324 smps = WMI_PEER_SMPS_PS_NONE;
5325 break;
5326 }
5327
5328 arsta->smps = smps;
5329 }
5330
Michal Kazior9797feb2014-02-14 14:49:48 +01005331 arsta->changed |= changed;
5332
5333 spin_unlock_bh(&ar->data_lock);
5334
5335 ieee80211_queue_work(hw, &arsta->update_wk);
5336}
5337
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005338static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5339{
5340 /*
5341 * FIXME: Return 0 for time being. Need to figure out whether FW
5342 * has the API to fetch 64-bit local TSF
5343 */
5344
5345 return 0;
5346}
5347
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005348static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5349 struct ieee80211_vif *vif,
5350 enum ieee80211_ampdu_mlme_action action,
5351 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5352 u8 buf_size)
5353{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005354 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005355 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5356
Michal Kazior7aa7a722014-08-25 12:09:38 +02005357 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 +02005358 arvif->vdev_id, sta->addr, tid, action);
5359
5360 switch (action) {
5361 case IEEE80211_AMPDU_RX_START:
5362 case IEEE80211_AMPDU_RX_STOP:
5363 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5364 * creation/removal. Do we need to verify this?
5365 */
5366 return 0;
5367 case IEEE80211_AMPDU_TX_START:
5368 case IEEE80211_AMPDU_TX_STOP_CONT:
5369 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5370 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5371 case IEEE80211_AMPDU_TX_OPERATIONAL:
5372 /* Firmware offloads Tx aggregation entirely so deny mac80211
5373 * Tx aggregation requests.
5374 */
5375 return -EOPNOTSUPP;
5376 }
5377
5378 return -EINVAL;
5379}
5380
Kalle Valo5e3dd152013-06-12 20:52:10 +03005381static const struct ieee80211_ops ath10k_ops = {
5382 .tx = ath10k_tx,
5383 .start = ath10k_start,
5384 .stop = ath10k_stop,
5385 .config = ath10k_config,
5386 .add_interface = ath10k_add_interface,
5387 .remove_interface = ath10k_remove_interface,
5388 .configure_filter = ath10k_configure_filter,
5389 .bss_info_changed = ath10k_bss_info_changed,
5390 .hw_scan = ath10k_hw_scan,
5391 .cancel_hw_scan = ath10k_cancel_hw_scan,
5392 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005393 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005394 .sta_state = ath10k_sta_state,
5395 .conf_tx = ath10k_conf_tx,
5396 .remain_on_channel = ath10k_remain_on_channel,
5397 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5398 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005399 .flush = ath10k_flush,
5400 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005401 .set_antenna = ath10k_set_antenna,
5402 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005403 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005404 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005405 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005406 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005407 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005408 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005409 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5410 .get_et_stats = ath10k_debug_get_et_stats,
5411 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005412
5413 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5414
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005415#ifdef CONFIG_PM
5416 .suspend = ath10k_suspend,
5417 .resume = ath10k_resume,
5418#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005419#ifdef CONFIG_MAC80211_DEBUGFS
5420 .sta_add_debugfs = ath10k_sta_add_debugfs,
5421#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005422};
5423
5424#define RATETAB_ENT(_rate, _rateid, _flags) { \
5425 .bitrate = (_rate), \
5426 .flags = (_flags), \
5427 .hw_value = (_rateid), \
5428}
5429
5430#define CHAN2G(_channel, _freq, _flags) { \
5431 .band = IEEE80211_BAND_2GHZ, \
5432 .hw_value = (_channel), \
5433 .center_freq = (_freq), \
5434 .flags = (_flags), \
5435 .max_antenna_gain = 0, \
5436 .max_power = 30, \
5437}
5438
5439#define CHAN5G(_channel, _freq, _flags) { \
5440 .band = IEEE80211_BAND_5GHZ, \
5441 .hw_value = (_channel), \
5442 .center_freq = (_freq), \
5443 .flags = (_flags), \
5444 .max_antenna_gain = 0, \
5445 .max_power = 30, \
5446}
5447
5448static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5449 CHAN2G(1, 2412, 0),
5450 CHAN2G(2, 2417, 0),
5451 CHAN2G(3, 2422, 0),
5452 CHAN2G(4, 2427, 0),
5453 CHAN2G(5, 2432, 0),
5454 CHAN2G(6, 2437, 0),
5455 CHAN2G(7, 2442, 0),
5456 CHAN2G(8, 2447, 0),
5457 CHAN2G(9, 2452, 0),
5458 CHAN2G(10, 2457, 0),
5459 CHAN2G(11, 2462, 0),
5460 CHAN2G(12, 2467, 0),
5461 CHAN2G(13, 2472, 0),
5462 CHAN2G(14, 2484, 0),
5463};
5464
5465static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005466 CHAN5G(36, 5180, 0),
5467 CHAN5G(40, 5200, 0),
5468 CHAN5G(44, 5220, 0),
5469 CHAN5G(48, 5240, 0),
5470 CHAN5G(52, 5260, 0),
5471 CHAN5G(56, 5280, 0),
5472 CHAN5G(60, 5300, 0),
5473 CHAN5G(64, 5320, 0),
5474 CHAN5G(100, 5500, 0),
5475 CHAN5G(104, 5520, 0),
5476 CHAN5G(108, 5540, 0),
5477 CHAN5G(112, 5560, 0),
5478 CHAN5G(116, 5580, 0),
5479 CHAN5G(120, 5600, 0),
5480 CHAN5G(124, 5620, 0),
5481 CHAN5G(128, 5640, 0),
5482 CHAN5G(132, 5660, 0),
5483 CHAN5G(136, 5680, 0),
5484 CHAN5G(140, 5700, 0),
5485 CHAN5G(149, 5745, 0),
5486 CHAN5G(153, 5765, 0),
5487 CHAN5G(157, 5785, 0),
5488 CHAN5G(161, 5805, 0),
5489 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490};
5491
Michal Kazior91b12082014-12-12 12:41:35 +01005492/* Note: Be careful if you re-order these. There is code which depends on this
5493 * ordering.
5494 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005495static struct ieee80211_rate ath10k_rates[] = {
5496 /* CCK */
5497 RATETAB_ENT(10, 0x82, 0),
5498 RATETAB_ENT(20, 0x84, 0),
5499 RATETAB_ENT(55, 0x8b, 0),
5500 RATETAB_ENT(110, 0x96, 0),
5501 /* OFDM */
5502 RATETAB_ENT(60, 0x0c, 0),
5503 RATETAB_ENT(90, 0x12, 0),
5504 RATETAB_ENT(120, 0x18, 0),
5505 RATETAB_ENT(180, 0x24, 0),
5506 RATETAB_ENT(240, 0x30, 0),
5507 RATETAB_ENT(360, 0x48, 0),
5508 RATETAB_ENT(480, 0x60, 0),
5509 RATETAB_ENT(540, 0x6c, 0),
5510};
5511
5512#define ath10k_a_rates (ath10k_rates + 4)
5513#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5514#define ath10k_g_rates (ath10k_rates + 0)
5515#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5516
Michal Kaziore7b54192014-08-07 11:03:27 +02005517struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005518{
5519 struct ieee80211_hw *hw;
5520 struct ath10k *ar;
5521
Michal Kaziore7b54192014-08-07 11:03:27 +02005522 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005523 if (!hw)
5524 return NULL;
5525
5526 ar = hw->priv;
5527 ar->hw = hw;
5528
5529 return ar;
5530}
5531
5532void ath10k_mac_destroy(struct ath10k *ar)
5533{
5534 ieee80211_free_hw(ar->hw);
5535}
5536
5537static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5538 {
5539 .max = 8,
5540 .types = BIT(NL80211_IFTYPE_STATION)
5541 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005542 },
5543 {
5544 .max = 3,
5545 .types = BIT(NL80211_IFTYPE_P2P_GO)
5546 },
5547 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005548 .max = 1,
5549 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5550 },
5551 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005552 .max = 7,
5553 .types = BIT(NL80211_IFTYPE_AP)
5554 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005555};
5556
Bartosz Markowskif2595092013-12-10 16:20:39 +01005557static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005558 {
5559 .max = 8,
5560 .types = BIT(NL80211_IFTYPE_AP)
5561 },
5562};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005563
5564static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5565 {
5566 .limits = ath10k_if_limits,
5567 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5568 .max_interfaces = 8,
5569 .num_different_channels = 1,
5570 .beacon_int_infra_match = true,
5571 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005572};
5573
5574static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005575 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005576 .limits = ath10k_10x_if_limits,
5577 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005578 .max_interfaces = 8,
5579 .num_different_channels = 1,
5580 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005581#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005582 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5583 BIT(NL80211_CHAN_WIDTH_20) |
5584 BIT(NL80211_CHAN_WIDTH_40) |
5585 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005586#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005587 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005588};
5589
5590static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5591{
5592 struct ieee80211_sta_vht_cap vht_cap = {0};
5593 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005594 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005595 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005596
5597 vht_cap.vht_supported = 1;
5598 vht_cap.cap = ar->vht_cap_info;
5599
Michal Kaziorbc657a362015-02-26 11:11:22 +01005600 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5601 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5602 val = ar->num_rf_chains - 1;
5603 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5604 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5605
5606 vht_cap.cap |= val;
5607 }
5608
5609 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5610 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5611 val = ar->num_rf_chains - 1;
5612 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5613 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5614
5615 vht_cap.cap |= val;
5616 }
5617
Michal Kazior8865bee42013-07-24 12:36:46 +02005618 mcs_map = 0;
5619 for (i = 0; i < 8; i++) {
5620 if (i < ar->num_rf_chains)
5621 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5622 else
5623 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005625
5626 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5627 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5628
5629 return vht_cap;
5630}
5631
5632static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5633{
5634 int i;
5635 struct ieee80211_sta_ht_cap ht_cap = {0};
5636
5637 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5638 return ht_cap;
5639
5640 ht_cap.ht_supported = 1;
5641 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5642 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5643 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5644 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5645 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5646
5647 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5648 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5649
5650 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5651 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5652
5653 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5654 u32 smps;
5655
5656 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5657 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5658
5659 ht_cap.cap |= smps;
5660 }
5661
5662 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5663 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5664
5665 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5666 u32 stbc;
5667
5668 stbc = ar->ht_cap_info;
5669 stbc &= WMI_HT_CAP_RX_STBC;
5670 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5671 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5672 stbc &= IEEE80211_HT_CAP_RX_STBC;
5673
5674 ht_cap.cap |= stbc;
5675 }
5676
5677 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5678 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5679
5680 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5681 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5682
5683 /* max AMSDU is implicitly taken from vht_cap_info */
5684 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5685 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5686
Michal Kazior8865bee42013-07-24 12:36:46 +02005687 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005688 ht_cap.mcs.rx_mask[i] = 0xFF;
5689
5690 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5691
5692 return ht_cap;
5693}
5694
Kalle Valo5e3dd152013-06-12 20:52:10 +03005695static void ath10k_get_arvif_iter(void *data, u8 *mac,
5696 struct ieee80211_vif *vif)
5697{
5698 struct ath10k_vif_iter *arvif_iter = data;
5699 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5700
5701 if (arvif->vdev_id == arvif_iter->vdev_id)
5702 arvif_iter->arvif = arvif;
5703}
5704
5705struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5706{
5707 struct ath10k_vif_iter arvif_iter;
5708 u32 flags;
5709
5710 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5711 arvif_iter.vdev_id = vdev_id;
5712
5713 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5714 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5715 flags,
5716 ath10k_get_arvif_iter,
5717 &arvif_iter);
5718 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005719 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005720 return NULL;
5721 }
5722
5723 return arvif_iter.arvif;
5724}
5725
5726int ath10k_mac_register(struct ath10k *ar)
5727{
Johannes Berg3cb10942015-01-22 21:38:45 +01005728 static const u32 cipher_suites[] = {
5729 WLAN_CIPHER_SUITE_WEP40,
5730 WLAN_CIPHER_SUITE_WEP104,
5731 WLAN_CIPHER_SUITE_TKIP,
5732 WLAN_CIPHER_SUITE_CCMP,
5733 WLAN_CIPHER_SUITE_AES_CMAC,
5734 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005735 struct ieee80211_supported_band *band;
5736 struct ieee80211_sta_vht_cap vht_cap;
5737 struct ieee80211_sta_ht_cap ht_cap;
5738 void *channels;
5739 int ret;
5740
5741 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5742
5743 SET_IEEE80211_DEV(ar->hw, ar->dev);
5744
5745 ht_cap = ath10k_get_ht_cap(ar);
5746 vht_cap = ath10k_create_vht_cap(ar);
5747
5748 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5749 channels = kmemdup(ath10k_2ghz_channels,
5750 sizeof(ath10k_2ghz_channels),
5751 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005752 if (!channels) {
5753 ret = -ENOMEM;
5754 goto err_free;
5755 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005756
5757 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5758 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5759 band->channels = channels;
5760 band->n_bitrates = ath10k_g_rates_size;
5761 band->bitrates = ath10k_g_rates;
5762 band->ht_cap = ht_cap;
5763
Yanbo Lid68bb122015-01-23 08:18:20 +08005764 /* Enable the VHT support at 2.4 GHz */
5765 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005766
5767 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5768 }
5769
5770 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5771 channels = kmemdup(ath10k_5ghz_channels,
5772 sizeof(ath10k_5ghz_channels),
5773 GFP_KERNEL);
5774 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005775 ret = -ENOMEM;
5776 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005777 }
5778
5779 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5780 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5781 band->channels = channels;
5782 band->n_bitrates = ath10k_a_rates_size;
5783 band->bitrates = ath10k_a_rates;
5784 band->ht_cap = ht_cap;
5785 band->vht_cap = vht_cap;
5786 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5787 }
5788
5789 ar->hw->wiphy->interface_modes =
5790 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005791 BIT(NL80211_IFTYPE_AP);
5792
Ben Greear46acf7b2014-05-16 17:15:38 +03005793 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5794 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5795
Bartosz Markowskid3541812013-12-10 16:20:40 +01005796 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5797 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005798 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005799 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5800 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005801
5802 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5803 IEEE80211_HW_SUPPORTS_PS |
5804 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005805 IEEE80211_HW_MFP_CAPABLE |
5806 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5807 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005808 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005809 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02005810 IEEE80211_HW_SW_CRYPTO_CONTROL |
5811 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005812
Eliad Peller0d8614b2014-09-10 14:07:36 +03005813 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5814
Kalle Valo5e3dd152013-06-12 20:52:10 +03005815 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005816 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005817
5818 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5819 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5820 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5821 }
5822
5823 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5824 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5825
5826 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005827 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005828
Kalle Valo5e3dd152013-06-12 20:52:10 +03005829 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5830
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005831 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5832 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5833
5834 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5835 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5836 * correct Probe Responses. This is more of a hack advert..
5837 */
5838 ar->hw->wiphy->probe_resp_offload |=
5839 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5840 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5841 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5842 }
5843
Kalle Valo5e3dd152013-06-12 20:52:10 +03005844 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005845 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005846 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5847
5848 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005849 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5850
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01005851 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
5852
Kalle Valo5e3dd152013-06-12 20:52:10 +03005853 /*
5854 * on LL hardware queues are managed entirely by the FW
5855 * so we only advertise to mac we can do the queues thing
5856 */
5857 ar->hw->queues = 4;
5858
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005859 switch (ar->wmi.op_version) {
5860 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5861 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005862 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5863 ar->hw->wiphy->n_iface_combinations =
5864 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005865 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005866 break;
5867 case ATH10K_FW_WMI_OP_VERSION_10_1:
5868 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005869 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005870 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5871 ar->hw->wiphy->n_iface_combinations =
5872 ARRAY_SIZE(ath10k_10x_if_comb);
5873 break;
5874 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5875 case ATH10K_FW_WMI_OP_VERSION_MAX:
5876 WARN_ON(1);
5877 ret = -EINVAL;
5878 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005879 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005880
Michal Kazior7c199992013-07-31 10:47:57 +02005881 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5882
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005883 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5884 /* Init ath dfs pattern detector */
5885 ar->ath_common.debug_mask = ATH_DBG_DFS;
5886 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5887 NL80211_DFS_UNSET);
5888
5889 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005890 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005891 }
5892
Kalle Valo5e3dd152013-06-12 20:52:10 +03005893 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5894 ath10k_reg_notifier);
5895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005896 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005897 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005898 }
5899
Johannes Berg3cb10942015-01-22 21:38:45 +01005900 ar->hw->wiphy->cipher_suites = cipher_suites;
5901 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5902
Kalle Valo5e3dd152013-06-12 20:52:10 +03005903 ret = ieee80211_register_hw(ar->hw);
5904 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005905 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005906 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005907 }
5908
5909 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5910 ret = regulatory_hint(ar->hw->wiphy,
5911 ar->ath_common.regulatory.alpha2);
5912 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005913 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005914 }
5915
5916 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005917
5918err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005919 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005920err_free:
5921 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5922 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5923
Kalle Valo5e3dd152013-06-12 20:52:10 +03005924 return ret;
5925}
5926
5927void ath10k_mac_unregister(struct ath10k *ar)
5928{
5929 ieee80211_unregister_hw(ar->hw);
5930
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005931 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5932 ar->dfs_detector->exit(ar->dfs_detector);
5933
Kalle Valo5e3dd152013-06-12 20:52:10 +03005934 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5935 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5936
5937 SET_IEEE80211_DEV(ar->hw, NULL);
5938}