blob: f364b845d99128ddd970f888133567e3cf1e052e [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"
Kalle Valo5e3dd152013-06-12 20:52:10 +030030
31/**********/
32/* Crypto */
33/**********/
34
35static int ath10k_send_key(struct ath10k_vif *arvif,
36 struct ieee80211_key_conf *key,
37 enum set_key_cmd cmd,
38 const u8 *macaddr)
39{
Michal Kazior7aa7a722014-08-25 12:09:38 +020040 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030041 struct wmi_vdev_install_key_arg arg = {
42 .vdev_id = arvif->vdev_id,
43 .key_idx = key->keyidx,
44 .key_len = key->keylen,
45 .key_data = key->key,
46 .macaddr = macaddr,
47 };
48
Michal Kazior548db542013-07-05 16:15:15 +030049 lockdep_assert_held(&arvif->ar->conf_mutex);
50
Kalle Valo5e3dd152013-06-12 20:52:10 +030051 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
52 arg.key_flags = WMI_KEY_PAIRWISE;
53 else
54 arg.key_flags = WMI_KEY_GROUP;
55
56 switch (key->cipher) {
57 case WLAN_CIPHER_SUITE_CCMP:
58 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030059 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
60 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
61 else
62 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030063 break;
64 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030065 arg.key_cipher = WMI_CIPHER_TKIP;
66 arg.key_txmic_len = 8;
67 arg.key_rxmic_len = 8;
68 break;
69 case WLAN_CIPHER_SUITE_WEP40:
70 case WLAN_CIPHER_SUITE_WEP104:
71 arg.key_cipher = WMI_CIPHER_WEP;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
75 arg.key_flags = WMI_KEY_PAIRWISE;
76 break;
77 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020078 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030079 return -EOPNOTSUPP;
80 }
81
82 if (cmd == DISABLE_KEY) {
83 arg.key_cipher = WMI_CIPHER_NONE;
84 arg.key_data = NULL;
85 }
86
87 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
88}
89
90static int ath10k_install_key(struct ath10k_vif *arvif,
91 struct ieee80211_key_conf *key,
92 enum set_key_cmd cmd,
93 const u8 *macaddr)
94{
95 struct ath10k *ar = arvif->ar;
96 int ret;
97
Michal Kazior548db542013-07-05 16:15:15 +030098 lockdep_assert_held(&ar->conf_mutex);
99
Wolfram Sang16735d02013-11-14 14:32:02 -0800100 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300101
102 ret = ath10k_send_key(arvif, key, cmd, macaddr);
103 if (ret)
104 return ret;
105
106 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
107 if (ret == 0)
108 return -ETIMEDOUT;
109
110 return 0;
111}
112
113static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
114 const u8 *addr)
115{
116 struct ath10k *ar = arvif->ar;
117 struct ath10k_peer *peer;
118 int ret;
119 int i;
120
121 lockdep_assert_held(&ar->conf_mutex);
122
123 spin_lock_bh(&ar->data_lock);
124 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
125 spin_unlock_bh(&ar->data_lock);
126
127 if (!peer)
128 return -ENOENT;
129
130 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
131 if (arvif->wep_keys[i] == NULL)
132 continue;
133
134 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
135 addr);
136 if (ret)
137 return ret;
138
Sujith Manoharanae167132014-11-25 11:46:59 +0530139 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300140 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530141 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300142 }
143
144 return 0;
145}
146
147static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
148 const u8 *addr)
149{
150 struct ath10k *ar = arvif->ar;
151 struct ath10k_peer *peer;
152 int first_errno = 0;
153 int ret;
154 int i;
155
156 lockdep_assert_held(&ar->conf_mutex);
157
158 spin_lock_bh(&ar->data_lock);
159 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
160 spin_unlock_bh(&ar->data_lock);
161
162 if (!peer)
163 return -ENOENT;
164
165 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
166 if (peer->keys[i] == NULL)
167 continue;
168
169 ret = ath10k_install_key(arvif, peer->keys[i],
170 DISABLE_KEY, addr);
171 if (ret && first_errno == 0)
172 first_errno = ret;
173
174 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200175 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300176 i, ret);
177
Sujith Manoharanae167132014-11-25 11:46:59 +0530178 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300179 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530180 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300181 }
182
183 return first_errno;
184}
185
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530186bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
187 u8 keyidx)
188{
189 struct ath10k_peer *peer;
190 int i;
191
192 lockdep_assert_held(&ar->data_lock);
193
194 /* We don't know which vdev this peer belongs to,
195 * since WMI doesn't give us that information.
196 *
197 * FIXME: multi-bss needs to be handled.
198 */
199 peer = ath10k_peer_find(ar, 0, addr);
200 if (!peer)
201 return false;
202
203 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
204 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
205 return true;
206 }
207
208 return false;
209}
210
Kalle Valo5e3dd152013-06-12 20:52:10 +0300211static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
212 struct ieee80211_key_conf *key)
213{
214 struct ath10k *ar = arvif->ar;
215 struct ath10k_peer *peer;
216 u8 addr[ETH_ALEN];
217 int first_errno = 0;
218 int ret;
219 int i;
220
221 lockdep_assert_held(&ar->conf_mutex);
222
223 for (;;) {
224 /* since ath10k_install_key we can't hold data_lock all the
225 * time, so we try to remove the keys incrementally */
226 spin_lock_bh(&ar->data_lock);
227 i = 0;
228 list_for_each_entry(peer, &ar->peers, list) {
229 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
230 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300231 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232 peer->keys[i] = NULL;
233 break;
234 }
235 }
236
237 if (i < ARRAY_SIZE(peer->keys))
238 break;
239 }
240 spin_unlock_bh(&ar->data_lock);
241
242 if (i == ARRAY_SIZE(peer->keys))
243 break;
244
245 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
246 if (ret && first_errno == 0)
247 first_errno = ret;
248
249 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200250 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200251 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300252 }
253
254 return first_errno;
255}
256
Kalle Valo5e3dd152013-06-12 20:52:10 +0300257/*********************/
258/* General utilities */
259/*********************/
260
261static inline enum wmi_phy_mode
262chan_to_phymode(const struct cfg80211_chan_def *chandef)
263{
264 enum wmi_phy_mode phymode = MODE_UNKNOWN;
265
266 switch (chandef->chan->band) {
267 case IEEE80211_BAND_2GHZ:
268 switch (chandef->width) {
269 case NL80211_CHAN_WIDTH_20_NOHT:
270 phymode = MODE_11G;
271 break;
272 case NL80211_CHAN_WIDTH_20:
273 phymode = MODE_11NG_HT20;
274 break;
275 case NL80211_CHAN_WIDTH_40:
276 phymode = MODE_11NG_HT40;
277 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400278 case NL80211_CHAN_WIDTH_5:
279 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300280 case NL80211_CHAN_WIDTH_80:
281 case NL80211_CHAN_WIDTH_80P80:
282 case NL80211_CHAN_WIDTH_160:
283 phymode = MODE_UNKNOWN;
284 break;
285 }
286 break;
287 case IEEE80211_BAND_5GHZ:
288 switch (chandef->width) {
289 case NL80211_CHAN_WIDTH_20_NOHT:
290 phymode = MODE_11A;
291 break;
292 case NL80211_CHAN_WIDTH_20:
293 phymode = MODE_11NA_HT20;
294 break;
295 case NL80211_CHAN_WIDTH_40:
296 phymode = MODE_11NA_HT40;
297 break;
298 case NL80211_CHAN_WIDTH_80:
299 phymode = MODE_11AC_VHT80;
300 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400301 case NL80211_CHAN_WIDTH_5:
302 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300303 case NL80211_CHAN_WIDTH_80P80:
304 case NL80211_CHAN_WIDTH_160:
305 phymode = MODE_UNKNOWN;
306 break;
307 }
308 break;
309 default:
310 break;
311 }
312
313 WARN_ON(phymode == MODE_UNKNOWN);
314 return phymode;
315}
316
317static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
318{
319/*
320 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
321 * 0 for no restriction
322 * 1 for 1/4 us
323 * 2 for 1/2 us
324 * 3 for 1 us
325 * 4 for 2 us
326 * 5 for 4 us
327 * 6 for 8 us
328 * 7 for 16 us
329 */
330 switch (mpdudensity) {
331 case 0:
332 return 0;
333 case 1:
334 case 2:
335 case 3:
336 /* Our lower layer calculations limit our precision to
337 1 microsecond */
338 return 1;
339 case 4:
340 return 2;
341 case 5:
342 return 4;
343 case 6:
344 return 8;
345 case 7:
346 return 16;
347 default:
348 return 0;
349 }
350}
351
352static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
353{
354 int ret;
355
356 lockdep_assert_held(&ar->conf_mutex);
357
358 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800359 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200360 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200361 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300362 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800363 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300364
365 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800366 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200367 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200368 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300369 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800370 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100371 spin_lock_bh(&ar->data_lock);
372 ar->num_peers++;
373 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300374
375 return 0;
376}
377
Kalle Valo5a13e762014-01-20 11:01:46 +0200378static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
379{
380 struct ath10k *ar = arvif->ar;
381 u32 param;
382 int ret;
383
384 param = ar->wmi.pdev_param->sta_kickout_th;
385 ret = ath10k_wmi_pdev_set_param(ar, param,
386 ATH10K_KICKOUT_THRESHOLD);
387 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200388 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200389 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200390 return ret;
391 }
392
393 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
394 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
395 ATH10K_KEEPALIVE_MIN_IDLE);
396 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200397 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200398 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200399 return ret;
400 }
401
402 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
403 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
404 ATH10K_KEEPALIVE_MAX_IDLE);
405 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200406 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200407 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200408 return ret;
409 }
410
411 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
412 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
413 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
414 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200415 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200416 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200417 return ret;
418 }
419
420 return 0;
421}
422
Michal Kazior424121c2013-07-22 14:13:31 +0200423static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
424{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200425 struct ath10k *ar = arvif->ar;
426 u32 vdev_param;
427
Michal Kazior424121c2013-07-22 14:13:31 +0200428 if (value != 0xFFFFFFFF)
429 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
430 ATH10K_RTS_MAX);
431
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200432 vdev_param = ar->wmi.vdev_param->rts_threshold;
433 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200434}
435
436static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
437{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200438 struct ath10k *ar = arvif->ar;
439 u32 vdev_param;
440
Michal Kazior424121c2013-07-22 14:13:31 +0200441 if (value != 0xFFFFFFFF)
442 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
443 ATH10K_FRAGMT_THRESHOLD_MIN,
444 ATH10K_FRAGMT_THRESHOLD_MAX);
445
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200446 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
447 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200448}
449
Kalle Valo5e3dd152013-06-12 20:52:10 +0300450static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
451{
452 int ret;
453
454 lockdep_assert_held(&ar->conf_mutex);
455
456 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
457 if (ret)
458 return ret;
459
460 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
461 if (ret)
462 return ret;
463
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100464 spin_lock_bh(&ar->data_lock);
465 ar->num_peers--;
466 spin_unlock_bh(&ar->data_lock);
467
Kalle Valo5e3dd152013-06-12 20:52:10 +0300468 return 0;
469}
470
471static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
472{
473 struct ath10k_peer *peer, *tmp;
474
475 lockdep_assert_held(&ar->conf_mutex);
476
477 spin_lock_bh(&ar->data_lock);
478 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
479 if (peer->vdev_id != vdev_id)
480 continue;
481
Michal Kazior7aa7a722014-08-25 12:09:38 +0200482 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300483 peer->addr, vdev_id);
484
485 list_del(&peer->list);
486 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100487 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300488 }
489 spin_unlock_bh(&ar->data_lock);
490}
491
Michal Kaziora96d7742013-07-16 09:38:56 +0200492static void ath10k_peer_cleanup_all(struct ath10k *ar)
493{
494 struct ath10k_peer *peer, *tmp;
495
496 lockdep_assert_held(&ar->conf_mutex);
497
498 spin_lock_bh(&ar->data_lock);
499 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
500 list_del(&peer->list);
501 kfree(peer);
502 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100503 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200504 spin_unlock_bh(&ar->data_lock);
505}
506
Kalle Valo5e3dd152013-06-12 20:52:10 +0300507/************************/
508/* Interface management */
509/************************/
510
Michal Kazior64badcb2014-09-18 11:18:02 +0300511void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
512{
513 struct ath10k *ar = arvif->ar;
514
515 lockdep_assert_held(&ar->data_lock);
516
517 if (!arvif->beacon)
518 return;
519
520 if (!arvif->beacon_buf)
521 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
522 arvif->beacon->len, DMA_TO_DEVICE);
523
524 dev_kfree_skb_any(arvif->beacon);
525
526 arvif->beacon = NULL;
527 arvif->beacon_sent = false;
528}
529
530static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
531{
532 struct ath10k *ar = arvif->ar;
533
534 lockdep_assert_held(&ar->data_lock);
535
536 ath10k_mac_vif_beacon_free(arvif);
537
538 if (arvif->beacon_buf) {
539 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
540 arvif->beacon_buf, arvif->beacon_paddr);
541 arvif->beacon_buf = NULL;
542 }
543}
544
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
546{
547 int ret;
548
Michal Kazior548db542013-07-05 16:15:15 +0300549 lockdep_assert_held(&ar->conf_mutex);
550
Michal Kazior7962b0d2014-10-28 10:34:38 +0100551 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
552 return -ESHUTDOWN;
553
Kalle Valo5e3dd152013-06-12 20:52:10 +0300554 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
555 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
556 if (ret == 0)
557 return -ETIMEDOUT;
558
559 return 0;
560}
561
Michal Kazior1bbc0972014-04-08 09:45:47 +0300562static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563{
Michal Kaziorc930f742014-01-23 11:38:25 +0100564 struct cfg80211_chan_def *chandef = &ar->chandef;
565 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300566 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300567 int ret = 0;
568
569 lockdep_assert_held(&ar->conf_mutex);
570
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571 arg.vdev_id = vdev_id;
572 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100573 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300574
575 /* TODO setup this dynamically, what in case we
576 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100577 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200578 arg.channel.chan_radar =
579 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580
Michal Kazior89c5c842013-10-23 04:02:13 -0700581 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700582 arg.channel.max_power = channel->max_power * 2;
583 arg.channel.max_reg_power = channel->max_reg_power * 2;
584 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585
Michal Kazior7962b0d2014-10-28 10:34:38 +0100586 reinit_completion(&ar->vdev_setup_done);
587
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588 ret = ath10k_wmi_vdev_start(ar, &arg);
589 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200590 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200591 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592 return ret;
593 }
594
595 ret = ath10k_vdev_setup_sync(ar);
596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200597 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200598 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599 return ret;
600 }
601
602 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200604 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200605 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 goto vdev_stop;
607 }
608
609 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300610
Michal Kazior7aa7a722014-08-25 12:09:38 +0200611 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300612 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return 0;
614
615vdev_stop:
616 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
617 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620
621 return ret;
622}
623
Michal Kazior1bbc0972014-04-08 09:45:47 +0300624static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300625{
626 int ret = 0;
627
628 lockdep_assert_held(&ar->conf_mutex);
629
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200630 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200632 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200633 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634
Michal Kazior7962b0d2014-10-28 10:34:38 +0100635 reinit_completion(&ar->vdev_setup_done);
636
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
638 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200639 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200640 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300641
642 ret = ath10k_vdev_setup_sync(ar);
643 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200644 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200645 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300646
Michal Kazior7aa7a722014-08-25 12:09:38 +0200647 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300648 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 return ret;
650}
651
Michal Kazior1bbc0972014-04-08 09:45:47 +0300652static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300653{
654 int bit, ret = 0;
655
656 lockdep_assert_held(&ar->conf_mutex);
657
Ben Greeara9aefb32014-08-12 11:02:19 +0300658 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200659 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660 return -ENOMEM;
661 }
662
Ben Greear16c11172014-09-23 14:17:16 -0700663 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300664
Ben Greear16c11172014-09-23 14:17:16 -0700665 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666
667 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
668 WMI_VDEV_TYPE_MONITOR,
669 0, ar->mac_addr);
670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200671 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200672 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300673 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 }
675
Ben Greear16c11172014-09-23 14:17:16 -0700676 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300678 ar->monitor_vdev_id);
679
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300681}
682
Michal Kazior1bbc0972014-04-08 09:45:47 +0300683static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300684{
685 int ret = 0;
686
687 lockdep_assert_held(&ar->conf_mutex);
688
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
690 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200691 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200692 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300693 return ret;
694 }
695
Ben Greear16c11172014-09-23 14:17:16 -0700696 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697
Michal Kazior7aa7a722014-08-25 12:09:38 +0200698 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300699 ar->monitor_vdev_id);
700 return ret;
701}
702
Michal Kazior1bbc0972014-04-08 09:45:47 +0300703static int ath10k_monitor_start(struct ath10k *ar)
704{
705 int ret;
706
707 lockdep_assert_held(&ar->conf_mutex);
708
Michal Kazior1bbc0972014-04-08 09:45:47 +0300709 ret = ath10k_monitor_vdev_create(ar);
710 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200711 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300712 return ret;
713 }
714
715 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
716 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200717 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300718 ath10k_monitor_vdev_delete(ar);
719 return ret;
720 }
721
722 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300724
725 return 0;
726}
727
Michal Kazior19337472014-08-28 12:58:16 +0200728static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300729{
730 int ret;
731
732 lockdep_assert_held(&ar->conf_mutex);
733
Michal Kazior1bbc0972014-04-08 09:45:47 +0300734 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200735 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200736 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200737 return ret;
738 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300739
740 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200742 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200743 return ret;
744 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300745
746 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200748
749 return 0;
750}
751
752static int ath10k_monitor_recalc(struct ath10k *ar)
753{
754 bool should_start;
755
756 lockdep_assert_held(&ar->conf_mutex);
757
758 should_start = ar->monitor ||
759 ar->filter_flags & FIF_PROMISC_IN_BSS ||
760 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
761
762 ath10k_dbg(ar, ATH10K_DBG_MAC,
763 "mac monitor recalc started? %d should? %d\n",
764 ar->monitor_started, should_start);
765
766 if (should_start == ar->monitor_started)
767 return 0;
768
769 if (should_start)
770 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300771
772 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300773}
774
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200775static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
776{
777 struct ath10k *ar = arvif->ar;
778 u32 vdev_param, rts_cts = 0;
779
780 lockdep_assert_held(&ar->conf_mutex);
781
782 vdev_param = ar->wmi.vdev_param->enable_rtscts;
783
784 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
785 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
786
787 if (arvif->num_legacy_stations > 0)
788 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
789 WMI_RTSCTS_PROFILE);
790
791 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
792 rts_cts);
793}
794
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200795static int ath10k_start_cac(struct ath10k *ar)
796{
797 int ret;
798
799 lockdep_assert_held(&ar->conf_mutex);
800
801 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
802
Michal Kazior19337472014-08-28 12:58:16 +0200803 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200804 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200805 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200806 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
807 return ret;
808 }
809
Michal Kazior7aa7a722014-08-25 12:09:38 +0200810 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200811 ar->monitor_vdev_id);
812
813 return 0;
814}
815
816static int ath10k_stop_cac(struct ath10k *ar)
817{
818 lockdep_assert_held(&ar->conf_mutex);
819
820 /* CAC is not running - do nothing */
821 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
822 return 0;
823
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200824 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300825 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200826
Michal Kazior7aa7a722014-08-25 12:09:38 +0200827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200828
829 return 0;
830}
831
Michal Kaziord6500972014-04-08 09:56:09 +0300832static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200833{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200834 int ret;
835
836 lockdep_assert_held(&ar->conf_mutex);
837
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 ath10k_stop_cac(ar);
839
Michal Kaziord6500972014-04-08 09:56:09 +0300840 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200841 return;
842
Michal Kaziord6500972014-04-08 09:56:09 +0300843 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200844 return;
845
846 ret = ath10k_start_cac(ar);
847 if (ret) {
848 /*
849 * Not possible to start CAC on current channel so starting
850 * radiation is not allowed, make this channel DFS_UNAVAILABLE
851 * by indicating that radar was detected.
852 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200853 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200854 ieee80211_radar_detected(ar->hw);
855 }
856}
857
Michal Kaziordc55e302014-07-29 12:53:36 +0300858static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300859{
860 struct ath10k *ar = arvif->ar;
861 struct cfg80211_chan_def *chandef = &ar->chandef;
862 struct wmi_vdev_start_request_arg arg = {};
863 int ret = 0;
864
865 lockdep_assert_held(&ar->conf_mutex);
866
867 reinit_completion(&ar->vdev_setup_done);
868
869 arg.vdev_id = arvif->vdev_id;
870 arg.dtim_period = arvif->dtim_period;
871 arg.bcn_intval = arvif->beacon_interval;
872
873 arg.channel.freq = chandef->chan->center_freq;
874 arg.channel.band_center_freq1 = chandef->center_freq1;
875 arg.channel.mode = chan_to_phymode(chandef);
876
877 arg.channel.min_power = 0;
878 arg.channel.max_power = chandef->chan->max_power * 2;
879 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
880 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
881
882 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
883 arg.ssid = arvif->u.ap.ssid;
884 arg.ssid_len = arvif->u.ap.ssid_len;
885 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
886
887 /* For now allow DFS for AP mode */
888 arg.channel.chan_radar =
889 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
890 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
891 arg.ssid = arvif->vif->bss_conf.ssid;
892 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
893 }
894
Michal Kazior7aa7a722014-08-25 12:09:38 +0200895 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300896 "mac vdev %d start center_freq %d phymode %s\n",
897 arg.vdev_id, arg.channel.freq,
898 ath10k_wmi_phymode_str(arg.channel.mode));
899
Michal Kaziordc55e302014-07-29 12:53:36 +0300900 if (restart)
901 ret = ath10k_wmi_vdev_restart(ar, &arg);
902 else
903 ret = ath10k_wmi_vdev_start(ar, &arg);
904
Michal Kazior72654fa2014-04-08 09:56:09 +0300905 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200906 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300907 arg.vdev_id, ret);
908 return ret;
909 }
910
911 ret = ath10k_vdev_setup_sync(ar);
912 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200913 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300914 arg.vdev_id, ret);
915 return ret;
916 }
917
Michal Kaziord6500972014-04-08 09:56:09 +0300918 ar->num_started_vdevs++;
919 ath10k_recalc_radar_detection(ar);
920
Michal Kazior72654fa2014-04-08 09:56:09 +0300921 return ret;
922}
923
Michal Kaziordc55e302014-07-29 12:53:36 +0300924static int ath10k_vdev_start(struct ath10k_vif *arvif)
925{
926 return ath10k_vdev_start_restart(arvif, false);
927}
928
929static int ath10k_vdev_restart(struct ath10k_vif *arvif)
930{
931 return ath10k_vdev_start_restart(arvif, true);
932}
933
Michal Kazior72654fa2014-04-08 09:56:09 +0300934static int ath10k_vdev_stop(struct ath10k_vif *arvif)
935{
936 struct ath10k *ar = arvif->ar;
937 int ret;
938
939 lockdep_assert_held(&ar->conf_mutex);
940
941 reinit_completion(&ar->vdev_setup_done);
942
943 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
944 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200945 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300946 arvif->vdev_id, ret);
947 return ret;
948 }
949
950 ret = ath10k_vdev_setup_sync(ar);
951 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200952 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300953 arvif->vdev_id, ret);
954 return ret;
955 }
956
Michal Kaziord6500972014-04-08 09:56:09 +0300957 WARN_ON(ar->num_started_vdevs == 0);
958
959 if (ar->num_started_vdevs != 0) {
960 ar->num_started_vdevs--;
961 ath10k_recalc_radar_detection(ar);
962 }
963
Michal Kazior72654fa2014-04-08 09:56:09 +0300964 return ret;
965}
966
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +0300968 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300969{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200970 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 int ret = 0;
972
Michal Kazior548db542013-07-05 16:15:15 +0300973 lockdep_assert_held(&arvif->ar->conf_mutex);
974
Kalle Valo5e3dd152013-06-12 20:52:10 +0300975 if (!info->enable_beacon) {
976 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100977
978 arvif->is_started = false;
979 arvif->is_up = false;
980
Michal Kazior748afc42014-01-23 12:48:21 +0100981 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +0300982 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +0100983 spin_unlock_bh(&arvif->ar->data_lock);
984
Kalle Valo5e3dd152013-06-12 20:52:10 +0300985 return;
986 }
987
988 arvif->tx_seq_no = 0x1000;
989
990 ret = ath10k_vdev_start(arvif);
991 if (ret)
992 return;
993
Michal Kaziorc930f742014-01-23 11:38:25 +0100994 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +0300995 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +0100996
997 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
998 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001000 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001001 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001002 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001003 return;
1004 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001005
1006 arvif->is_started = true;
1007 arvif->is_up = true;
1008
Michal Kazior7aa7a722014-08-25 12:09:38 +02001009 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001010}
1011
1012static void ath10k_control_ibss(struct ath10k_vif *arvif,
1013 struct ieee80211_bss_conf *info,
1014 const u8 self_peer[ETH_ALEN])
1015{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001016 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001017 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018 int ret = 0;
1019
Michal Kazior548db542013-07-05 16:15:15 +03001020 lockdep_assert_held(&arvif->ar->conf_mutex);
1021
Kalle Valo5e3dd152013-06-12 20:52:10 +03001022 if (!info->ibss_joined) {
1023 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1024 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001025 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001026 self_peer, arvif->vdev_id, ret);
1027
Michal Kaziorc930f742014-01-23 11:38:25 +01001028 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001029 return;
1030
Michal Kaziorc930f742014-01-23 11:38:25 +01001031 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001032
1033 return;
1034 }
1035
1036 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1037 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001038 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001039 self_peer, arvif->vdev_id, ret);
1040 return;
1041 }
1042
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001043 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1044 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001045 ATH10K_DEFAULT_ATIM);
1046 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001047 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001048 arvif->vdev_id, ret);
1049}
1050
1051/*
1052 * Review this when mac80211 gains per-interface powersave support.
1053 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001054static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001055{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001056 struct ath10k *ar = arvif->ar;
1057 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001058 enum wmi_sta_powersave_param param;
1059 enum wmi_sta_ps_mode psmode;
1060 int ret;
1061
Michal Kazior548db542013-07-05 16:15:15 +03001062 lockdep_assert_held(&arvif->ar->conf_mutex);
1063
Michal Kaziorad088bf2013-10-16 15:44:46 +03001064 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1065 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001066
1067 if (conf->flags & IEEE80211_CONF_PS) {
1068 psmode = WMI_STA_PS_MODE_ENABLED;
1069 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1070
Michal Kaziorad088bf2013-10-16 15:44:46 +03001071 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001072 conf->dynamic_ps_timeout);
1073 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001074 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001075 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001076 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001077 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001078 } else {
1079 psmode = WMI_STA_PS_MODE_DISABLED;
1080 }
1081
Michal Kazior7aa7a722014-08-25 12:09:38 +02001082 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001083 arvif->vdev_id, psmode ? "enable" : "disable");
1084
Michal Kaziorad088bf2013-10-16 15:44:46 +03001085 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1086 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001087 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001088 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001089 return ret;
1090 }
1091
1092 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001093}
1094
1095/**********************/
1096/* Station management */
1097/**********************/
1098
Michal Kazior590922a2014-10-21 10:10:29 +03001099static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1100 struct ieee80211_vif *vif)
1101{
1102 /* Some firmware revisions have unstable STA powersave when listen
1103 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1104 * generate NullFunc frames properly even if buffered frames have been
1105 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1106 * buffered frames. Often pinging the device from AP would simply fail.
1107 *
1108 * As a workaround set it to 1.
1109 */
1110 if (vif->type == NL80211_IFTYPE_STATION)
1111 return 1;
1112
1113 return ar->hw->conf.listen_interval;
1114}
1115
Kalle Valo5e3dd152013-06-12 20:52:10 +03001116static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001117 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001119 struct wmi_peer_assoc_complete_arg *arg)
1120{
Michal Kazior590922a2014-10-21 10:10:29 +03001121 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1122
Michal Kazior548db542013-07-05 16:15:15 +03001123 lockdep_assert_held(&ar->conf_mutex);
1124
Kalle Valob25f32c2014-09-14 12:50:49 +03001125 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001126 arg->vdev_id = arvif->vdev_id;
1127 arg->peer_aid = sta->aid;
1128 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001129 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001130 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001131 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001132}
1133
1134static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001135 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 struct wmi_peer_assoc_complete_arg *arg)
1137{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001138 struct ieee80211_bss_conf *info = &vif->bss_conf;
1139 struct cfg80211_bss *bss;
1140 const u8 *rsnie = NULL;
1141 const u8 *wpaie = NULL;
1142
Michal Kazior548db542013-07-05 16:15:15 +03001143 lockdep_assert_held(&ar->conf_mutex);
1144
Kalle Valo5e3dd152013-06-12 20:52:10 +03001145 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1146 info->bssid, NULL, 0, 0, 0);
1147 if (bss) {
1148 const struct cfg80211_bss_ies *ies;
1149
1150 rcu_read_lock();
1151 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1152
1153 ies = rcu_dereference(bss->ies);
1154
1155 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001156 WLAN_OUI_TYPE_MICROSOFT_WPA,
1157 ies->data,
1158 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001159 rcu_read_unlock();
1160 cfg80211_put_bss(ar->hw->wiphy, bss);
1161 }
1162
1163 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1164 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001165 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001166 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1167 }
1168
1169 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001170 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001171 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1172 }
1173}
1174
1175static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1176 struct ieee80211_sta *sta,
1177 struct wmi_peer_assoc_complete_arg *arg)
1178{
1179 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1180 const struct ieee80211_supported_band *sband;
1181 const struct ieee80211_rate *rates;
1182 u32 ratemask;
1183 int i;
1184
Michal Kazior548db542013-07-05 16:15:15 +03001185 lockdep_assert_held(&ar->conf_mutex);
1186
Kalle Valo5e3dd152013-06-12 20:52:10 +03001187 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1188 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1189 rates = sband->bitrates;
1190
1191 rateset->num_rates = 0;
1192
1193 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1194 if (!(ratemask & 1))
1195 continue;
1196
1197 rateset->rates[rateset->num_rates] = rates->hw_value;
1198 rateset->num_rates++;
1199 }
1200}
1201
1202static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1203 struct ieee80211_sta *sta,
1204 struct wmi_peer_assoc_complete_arg *arg)
1205{
1206 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001207 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001208 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001209
Michal Kazior548db542013-07-05 16:15:15 +03001210 lockdep_assert_held(&ar->conf_mutex);
1211
Kalle Valo5e3dd152013-06-12 20:52:10 +03001212 if (!ht_cap->ht_supported)
1213 return;
1214
1215 arg->peer_flags |= WMI_PEER_HT;
1216 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1217 ht_cap->ampdu_factor)) - 1;
1218
1219 arg->peer_mpdu_density =
1220 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1221
1222 arg->peer_ht_caps = ht_cap->cap;
1223 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1224
1225 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1226 arg->peer_flags |= WMI_PEER_LDPC;
1227
1228 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1229 arg->peer_flags |= WMI_PEER_40MHZ;
1230 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1231 }
1232
1233 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1234 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1235
1236 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1237 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1238
1239 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1240 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1241 arg->peer_flags |= WMI_PEER_STBC;
1242 }
1243
1244 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001245 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1246 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1247 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1248 arg->peer_rate_caps |= stbc;
1249 arg->peer_flags |= WMI_PEER_STBC;
1250 }
1251
Kalle Valo5e3dd152013-06-12 20:52:10 +03001252 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1253 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1254 else if (ht_cap->mcs.rx_mask[1])
1255 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1256
1257 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1258 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1259 arg->peer_ht_rates.rates[n++] = i;
1260
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001261 /*
1262 * This is a workaround for HT-enabled STAs which break the spec
1263 * and have no HT capabilities RX mask (no HT RX MCS map).
1264 *
1265 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1266 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1267 *
1268 * Firmware asserts if such situation occurs.
1269 */
1270 if (n == 0) {
1271 arg->peer_ht_rates.num_rates = 8;
1272 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1273 arg->peer_ht_rates.rates[i] = i;
1274 } else {
1275 arg->peer_ht_rates.num_rates = n;
1276 arg->peer_num_spatial_streams = sta->rx_nss;
1277 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001278
Michal Kazior7aa7a722014-08-25 12:09:38 +02001279 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001280 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 arg->peer_ht_rates.num_rates,
1282 arg->peer_num_spatial_streams);
1283}
1284
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001285static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1286 struct ath10k_vif *arvif,
1287 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288{
1289 u32 uapsd = 0;
1290 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001291 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001292
Michal Kazior548db542013-07-05 16:15:15 +03001293 lockdep_assert_held(&ar->conf_mutex);
1294
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001296 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297 sta->uapsd_queues, sta->max_sp);
1298
Kalle Valo5e3dd152013-06-12 20:52:10 +03001299 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1300 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1301 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1302 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1303 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1304 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1305 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1306 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1307 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1308 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1309 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1310 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1311
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1313 max_sp = sta->max_sp;
1314
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001315 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1316 sta->addr,
1317 WMI_AP_PS_PEER_PARAM_UAPSD,
1318 uapsd);
1319 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001320 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001321 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001322 return ret;
1323 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001324
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001325 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1326 sta->addr,
1327 WMI_AP_PS_PEER_PARAM_MAX_SP,
1328 max_sp);
1329 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001330 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001331 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001332 return ret;
1333 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001334
1335 /* TODO setup this based on STA listen interval and
1336 beacon interval. Currently we don't know
1337 sta->listen_interval - mac80211 patch required.
1338 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001339 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001340 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1341 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001342 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001343 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001344 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001345 return ret;
1346 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001348
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001349 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001350}
1351
1352static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1353 struct ieee80211_sta *sta,
1354 struct wmi_peer_assoc_complete_arg *arg)
1355{
1356 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001357 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001358
1359 if (!vht_cap->vht_supported)
1360 return;
1361
1362 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001363 arg->peer_vht_caps = vht_cap->cap;
1364
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001365 ampdu_factor = (vht_cap->cap &
1366 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1367 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1368
1369 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1370 * zero in VHT IE. Using it would result in degraded throughput.
1371 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1372 * it if VHT max_mpdu is smaller. */
1373 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1374 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1375 ampdu_factor)) - 1);
1376
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1378 arg->peer_flags |= WMI_PEER_80MHZ;
1379
1380 arg->peer_vht_rates.rx_max_rate =
1381 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1382 arg->peer_vht_rates.rx_mcs_set =
1383 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1384 arg->peer_vht_rates.tx_max_rate =
1385 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1386 arg->peer_vht_rates.tx_mcs_set =
1387 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1388
Michal Kazior7aa7a722014-08-25 12:09:38 +02001389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001390 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391}
1392
1393static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001394 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001395 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001396 struct wmi_peer_assoc_complete_arg *arg)
1397{
Michal Kazior590922a2014-10-21 10:10:29 +03001398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1399
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400 switch (arvif->vdev_type) {
1401 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001402 if (sta->wme)
1403 arg->peer_flags |= WMI_PEER_QOS;
1404
1405 if (sta->wme && sta->uapsd_queues) {
1406 arg->peer_flags |= WMI_PEER_APSD;
1407 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1408 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 break;
1410 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001411 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001412 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 break;
1414 default:
1415 break;
1416 }
1417}
1418
1419static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001420 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001421 struct ieee80211_sta *sta,
1422 struct wmi_peer_assoc_complete_arg *arg)
1423{
1424 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1425
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426 switch (ar->hw->conf.chandef.chan->band) {
1427 case IEEE80211_BAND_2GHZ:
1428 if (sta->ht_cap.ht_supported) {
1429 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1430 phymode = MODE_11NG_HT40;
1431 else
1432 phymode = MODE_11NG_HT20;
1433 } else {
1434 phymode = MODE_11G;
1435 }
1436
1437 break;
1438 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001439 /*
1440 * Check VHT first.
1441 */
1442 if (sta->vht_cap.vht_supported) {
1443 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1444 phymode = MODE_11AC_VHT80;
1445 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1446 phymode = MODE_11AC_VHT40;
1447 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1448 phymode = MODE_11AC_VHT20;
1449 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001450 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1451 phymode = MODE_11NA_HT40;
1452 else
1453 phymode = MODE_11NA_HT20;
1454 } else {
1455 phymode = MODE_11A;
1456 }
1457
1458 break;
1459 default:
1460 break;
1461 }
1462
Michal Kazior7aa7a722014-08-25 12:09:38 +02001463 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001464 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001465
Kalle Valo5e3dd152013-06-12 20:52:10 +03001466 arg->peer_phymode = phymode;
1467 WARN_ON(phymode == MODE_UNKNOWN);
1468}
1469
Kalle Valob9ada652013-10-16 15:44:46 +03001470static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001471 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001472 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001473 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474{
Michal Kazior548db542013-07-05 16:15:15 +03001475 lockdep_assert_held(&ar->conf_mutex);
1476
Kalle Valob9ada652013-10-16 15:44:46 +03001477 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478
Michal Kazior590922a2014-10-21 10:10:29 +03001479 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1480 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001481 ath10k_peer_assoc_h_rates(ar, sta, arg);
1482 ath10k_peer_assoc_h_ht(ar, sta, arg);
1483 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001484 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1485 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001486
Kalle Valob9ada652013-10-16 15:44:46 +03001487 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001488}
1489
Michal Kazior90046f52014-02-14 14:45:51 +01001490static const u32 ath10k_smps_map[] = {
1491 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1492 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1493 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1494 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1495};
1496
1497static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1498 const u8 *addr,
1499 const struct ieee80211_sta_ht_cap *ht_cap)
1500{
1501 int smps;
1502
1503 if (!ht_cap->ht_supported)
1504 return 0;
1505
1506 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1507 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1508
1509 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1510 return -EINVAL;
1511
1512 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1513 WMI_PEER_SMPS_STATE,
1514 ath10k_smps_map[smps]);
1515}
1516
Kalle Valo5e3dd152013-06-12 20:52:10 +03001517/* can be called only in mac80211 callbacks due to `key_count` usage */
1518static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1519 struct ieee80211_vif *vif,
1520 struct ieee80211_bss_conf *bss_conf)
1521{
1522 struct ath10k *ar = hw->priv;
1523 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001524 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001525 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001526 struct ieee80211_sta *ap_sta;
1527 int ret;
1528
Michal Kazior548db542013-07-05 16:15:15 +03001529 lockdep_assert_held(&ar->conf_mutex);
1530
Michal Kazior077efc82014-10-21 10:10:29 +03001531 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1532 arvif->vdev_id, arvif->bssid, arvif->aid);
1533
Kalle Valo5e3dd152013-06-12 20:52:10 +03001534 rcu_read_lock();
1535
1536 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1537 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001538 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001539 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001540 rcu_read_unlock();
1541 return;
1542 }
1543
Michal Kazior90046f52014-02-14 14:45:51 +01001544 /* ap_sta must be accessed only within rcu section which must be left
1545 * before calling ath10k_setup_peer_smps() which might sleep. */
1546 ht_cap = ap_sta->ht_cap;
1547
Michal Kazior590922a2014-10-21 10:10:29 +03001548 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001549 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001550 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001551 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 rcu_read_unlock();
1553 return;
1554 }
1555
1556 rcu_read_unlock();
1557
Kalle Valob9ada652013-10-16 15:44:46 +03001558 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1559 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001560 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001561 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001562 return;
1563 }
1564
Michal Kazior90046f52014-02-14 14:45:51 +01001565 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1566 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001567 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001568 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001569 return;
1570 }
1571
Michal Kazior7aa7a722014-08-25 12:09:38 +02001572 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001573 "mac vdev %d up (associated) bssid %pM aid %d\n",
1574 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1575
Michal Kazior077efc82014-10-21 10:10:29 +03001576 WARN_ON(arvif->is_up);
1577
Michal Kaziorc930f742014-01-23 11:38:25 +01001578 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001579 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001580
1581 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001583 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001585 return;
1586 }
1587
1588 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001589}
1590
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1592 struct ieee80211_vif *vif)
1593{
1594 struct ath10k *ar = hw->priv;
1595 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1596 int ret;
1597
Michal Kazior548db542013-07-05 16:15:15 +03001598 lockdep_assert_held(&ar->conf_mutex);
1599
Michal Kazior077efc82014-10-21 10:10:29 +03001600 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1601 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001602
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001604 if (ret)
1605 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1606 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001608 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001609 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001610}
1611
Michal Kazior590922a2014-10-21 10:10:29 +03001612static int ath10k_station_assoc(struct ath10k *ar,
1613 struct ieee80211_vif *vif,
1614 struct ieee80211_sta *sta,
1615 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616{
Michal Kazior590922a2014-10-21 10:10:29 +03001617 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001618 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619 int ret = 0;
1620
Michal Kazior548db542013-07-05 16:15:15 +03001621 lockdep_assert_held(&ar->conf_mutex);
1622
Michal Kazior590922a2014-10-21 10:10:29 +03001623 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001625 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001626 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001627 return ret;
1628 }
1629
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001630 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001631 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1632 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001633 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001634 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 return ret;
1636 }
1637
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001638 /* Re-assoc is run only to update supported rates for given station. It
1639 * doesn't make much sense to reconfigure the peer completely.
1640 */
1641 if (!reassoc) {
1642 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1643 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001644 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001645 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001646 arvif->vdev_id, ret);
1647 return ret;
1648 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001649
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001650 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1651 if (ret) {
1652 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1653 sta->addr, arvif->vdev_id, ret);
1654 return ret;
1655 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001656
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001657 if (!sta->wme) {
1658 arvif->num_legacy_stations++;
1659 ret = ath10k_recalc_rtscts_prot(arvif);
1660 if (ret) {
1661 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1662 arvif->vdev_id, ret);
1663 return ret;
1664 }
1665 }
1666
1667 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1668 if (ret) {
1669 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001670 arvif->vdev_id, ret);
1671 return ret;
1672 }
1673 }
1674
Kalle Valo5e3dd152013-06-12 20:52:10 +03001675 return ret;
1676}
1677
Michal Kazior590922a2014-10-21 10:10:29 +03001678static int ath10k_station_disassoc(struct ath10k *ar,
1679 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001680 struct ieee80211_sta *sta)
1681{
Michal Kazior590922a2014-10-21 10:10:29 +03001682 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683 int ret = 0;
1684
1685 lockdep_assert_held(&ar->conf_mutex);
1686
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001687 if (!sta->wme) {
1688 arvif->num_legacy_stations--;
1689 ret = ath10k_recalc_rtscts_prot(arvif);
1690 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001691 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001692 arvif->vdev_id, ret);
1693 return ret;
1694 }
1695 }
1696
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1698 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001699 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001700 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701 return ret;
1702 }
1703
1704 return ret;
1705}
1706
1707/**************/
1708/* Regulatory */
1709/**************/
1710
1711static int ath10k_update_channel_list(struct ath10k *ar)
1712{
1713 struct ieee80211_hw *hw = ar->hw;
1714 struct ieee80211_supported_band **bands;
1715 enum ieee80211_band band;
1716 struct ieee80211_channel *channel;
1717 struct wmi_scan_chan_list_arg arg = {0};
1718 struct wmi_channel_arg *ch;
1719 bool passive;
1720 int len;
1721 int ret;
1722 int i;
1723
Michal Kazior548db542013-07-05 16:15:15 +03001724 lockdep_assert_held(&ar->conf_mutex);
1725
Kalle Valo5e3dd152013-06-12 20:52:10 +03001726 bands = hw->wiphy->bands;
1727 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1728 if (!bands[band])
1729 continue;
1730
1731 for (i = 0; i < bands[band]->n_channels; i++) {
1732 if (bands[band]->channels[i].flags &
1733 IEEE80211_CHAN_DISABLED)
1734 continue;
1735
1736 arg.n_channels++;
1737 }
1738 }
1739
1740 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1741 arg.channels = kzalloc(len, GFP_KERNEL);
1742 if (!arg.channels)
1743 return -ENOMEM;
1744
1745 ch = arg.channels;
1746 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1747 if (!bands[band])
1748 continue;
1749
1750 for (i = 0; i < bands[band]->n_channels; i++) {
1751 channel = &bands[band]->channels[i];
1752
1753 if (channel->flags & IEEE80211_CHAN_DISABLED)
1754 continue;
1755
1756 ch->allow_ht = true;
1757
1758 /* FIXME: when should we really allow VHT? */
1759 ch->allow_vht = true;
1760
1761 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001762 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763
1764 ch->ht40plus =
1765 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1766
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001767 ch->chan_radar =
1768 !!(channel->flags & IEEE80211_CHAN_RADAR);
1769
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001770 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001771 ch->passive = passive;
1772
1773 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001774 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001775 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001776 ch->max_power = channel->max_power * 2;
1777 ch->max_reg_power = channel->max_reg_power * 2;
1778 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001779 ch->reg_class_id = 0; /* FIXME */
1780
1781 /* FIXME: why use only legacy modes, why not any
1782 * HT/VHT modes? Would that even make any
1783 * difference? */
1784 if (channel->band == IEEE80211_BAND_2GHZ)
1785 ch->mode = MODE_11G;
1786 else
1787 ch->mode = MODE_11A;
1788
1789 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1790 continue;
1791
Michal Kazior7aa7a722014-08-25 12:09:38 +02001792 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001793 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1794 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001795 ch->freq, ch->max_power, ch->max_reg_power,
1796 ch->max_antenna_gain, ch->mode);
1797
1798 ch++;
1799 }
1800 }
1801
1802 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1803 kfree(arg.channels);
1804
1805 return ret;
1806}
1807
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001808static enum wmi_dfs_region
1809ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1810{
1811 switch (dfs_region) {
1812 case NL80211_DFS_UNSET:
1813 return WMI_UNINIT_DFS_DOMAIN;
1814 case NL80211_DFS_FCC:
1815 return WMI_FCC_DFS_DOMAIN;
1816 case NL80211_DFS_ETSI:
1817 return WMI_ETSI_DFS_DOMAIN;
1818 case NL80211_DFS_JP:
1819 return WMI_MKK4_DFS_DOMAIN;
1820 }
1821 return WMI_UNINIT_DFS_DOMAIN;
1822}
1823
Michal Kaziorf7843d72013-07-16 09:38:52 +02001824static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001825{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001826 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001827 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001828 enum wmi_dfs_region wmi_dfs_reg;
1829 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830
Michal Kaziorf7843d72013-07-16 09:38:52 +02001831 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001832
1833 ret = ath10k_update_channel_list(ar);
1834 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001835 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836
1837 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001838
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001839 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1840 nl_dfs_reg = ar->dfs_detector->region;
1841 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1842 } else {
1843 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1844 }
1845
Kalle Valo5e3dd152013-06-12 20:52:10 +03001846 /* Target allows setting up per-band regdomain but ath_common provides
1847 * a combined one only */
1848 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001849 regpair->reg_domain,
1850 regpair->reg_domain, /* 2ghz */
1851 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001852 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001853 regpair->reg_5ghz_ctl,
1854 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001856 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001857}
Michal Kazior548db542013-07-05 16:15:15 +03001858
Michal Kaziorf7843d72013-07-16 09:38:52 +02001859static void ath10k_reg_notifier(struct wiphy *wiphy,
1860 struct regulatory_request *request)
1861{
1862 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1863 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001864 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001865
1866 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1867
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001868 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001869 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001870 request->dfs_region);
1871 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1872 request->dfs_region);
1873 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001874 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001875 request->dfs_region);
1876 }
1877
Michal Kaziorf7843d72013-07-16 09:38:52 +02001878 mutex_lock(&ar->conf_mutex);
1879 if (ar->state == ATH10K_STATE_ON)
1880 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001881 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001882}
1883
1884/***************/
1885/* TX handlers */
1886/***************/
1887
Michal Kazior42c3aa62013-10-02 11:03:38 +02001888static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1889{
1890 if (ieee80211_is_mgmt(hdr->frame_control))
1891 return HTT_DATA_TX_EXT_TID_MGMT;
1892
1893 if (!ieee80211_is_data_qos(hdr->frame_control))
1894 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1895
1896 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1897 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1898
1899 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1900}
1901
Michal Kazior2b37c292014-09-02 11:00:22 +03001902static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001903{
Michal Kazior2b37c292014-09-02 11:00:22 +03001904 if (vif)
1905 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001906
Michal Kazior1bbc0972014-04-08 09:45:47 +03001907 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001908 return ar->monitor_vdev_id;
1909
Michal Kazior7aa7a722014-08-25 12:09:38 +02001910 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001911 return 0;
1912}
1913
Michal Kazior4b604552014-07-21 21:03:09 +03001914/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1915 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916 */
Michal Kazior4b604552014-07-21 21:03:09 +03001917static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001918{
1919 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001920 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001921 u8 *qos_ctl;
1922
1923 if (!ieee80211_is_data_qos(hdr->frame_control))
1924 return;
1925
1926 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001927 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1928 skb->data, (void *)qos_ctl - (void *)skb->data);
1929 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001930
1931 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1932 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1933 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1934 * it is safe to downgrade to NullFunc.
1935 */
1936 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1937 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1938 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1939 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940}
1941
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001942static void ath10k_tx_wep_key_work(struct work_struct *work)
1943{
1944 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1945 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001946 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001947 int ret, keyidx = arvif->def_wep_key_newidx;
1948
Michal Kazior911e6c02014-05-26 12:46:03 +03001949 mutex_lock(&arvif->ar->conf_mutex);
1950
1951 if (arvif->ar->state != ATH10K_STATE_ON)
1952 goto unlock;
1953
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001954 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001955 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001956
Michal Kazior7aa7a722014-08-25 12:09:38 +02001957 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001958 arvif->vdev_id, keyidx);
1959
1960 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1961 arvif->vdev_id,
1962 arvif->ar->wmi.vdev_param->def_keyid,
1963 keyidx);
1964 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001965 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001966 arvif->vdev_id,
1967 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001968 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001969 }
1970
1971 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001972
1973unlock:
1974 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001975}
1976
Michal Kazior4b604552014-07-21 21:03:09 +03001977static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1978 struct ieee80211_key_conf *key,
1979 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1982 struct ath10k *ar = arvif->ar;
1983 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984
Kalle Valo5e3dd152013-06-12 20:52:10 +03001985 if (!ieee80211_has_protected(hdr->frame_control))
1986 return;
1987
1988 if (!key)
1989 return;
1990
1991 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1992 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1993 return;
1994
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001995 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001996 return;
1997
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001998 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1999 * queueing frames until key index is updated is not an option because
2000 * sk_buff may need more processing to be done, e.g. offchannel */
2001 arvif->def_wep_key_newidx = key->keyidx;
2002 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002003}
2004
Michal Kazior4b604552014-07-21 21:03:09 +03002005static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2006 struct ieee80211_vif *vif,
2007 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008{
2009 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002010 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2011
2012 /* This is case only for P2P_GO */
2013 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2014 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2015 return;
2016
2017 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2018 spin_lock_bh(&ar->data_lock);
2019 if (arvif->u.ap.noa_data)
2020 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2021 GFP_ATOMIC))
2022 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2023 arvif->u.ap.noa_data,
2024 arvif->u.ap.noa_len);
2025 spin_unlock_bh(&ar->data_lock);
2026 }
2027}
2028
Michal Kazior8d6d3622014-11-24 14:58:31 +01002029static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2030{
2031 /* FIXME: Not really sure since when the behaviour changed. At some
2032 * point new firmware stopped requiring creation of peer entries for
2033 * offchannel tx (and actually creating them causes issues with wmi-htc
2034 * tx credit replenishment and reliability). Assuming it's at least 3.4
2035 * because that's when the `freq` was introduced to TX_FRM HTT command.
2036 */
2037 return !(ar->htt.target_version_major >= 3 &&
2038 ar->htt.target_version_minor >= 4);
2039}
2040
Kalle Valo5e3dd152013-06-12 20:52:10 +03002041static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2042{
2043 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002044 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045
Michal Kazior961d4c32013-08-09 10:13:34 +02002046 if (ar->htt.target_version_major >= 3) {
2047 /* Since HTT 3.0 there is no separate mgmt tx command */
2048 ret = ath10k_htt_tx(&ar->htt, skb);
2049 goto exit;
2050 }
2051
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002052 if (ieee80211_is_mgmt(hdr->frame_control)) {
2053 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2054 ar->fw_features)) {
2055 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2056 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002057 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002058 ret = -EBUSY;
2059 goto exit;
2060 }
2061
2062 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2063 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2064 } else {
2065 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2066 }
2067 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2068 ar->fw_features) &&
2069 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002070 /* FW does not report tx status properly for NullFunc frames
2071 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002072 * those frames when it detects link/beacon loss and depends
2073 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002074 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002075 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002076 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002077 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002078
Michal Kazior961d4c32013-08-09 10:13:34 +02002079exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002081 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2082 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083 ieee80211_free_txskb(ar->hw, skb);
2084 }
2085}
2086
2087void ath10k_offchan_tx_purge(struct ath10k *ar)
2088{
2089 struct sk_buff *skb;
2090
2091 for (;;) {
2092 skb = skb_dequeue(&ar->offchan_tx_queue);
2093 if (!skb)
2094 break;
2095
2096 ieee80211_free_txskb(ar->hw, skb);
2097 }
2098}
2099
2100void ath10k_offchan_tx_work(struct work_struct *work)
2101{
2102 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2103 struct ath10k_peer *peer;
2104 struct ieee80211_hdr *hdr;
2105 struct sk_buff *skb;
2106 const u8 *peer_addr;
2107 int vdev_id;
2108 int ret;
2109
2110 /* FW requirement: We must create a peer before FW will send out
2111 * an offchannel frame. Otherwise the frame will be stuck and
2112 * never transmitted. We delete the peer upon tx completion.
2113 * It is unlikely that a peer for offchannel tx will already be
2114 * present. However it may be in some rare cases so account for that.
2115 * Otherwise we might remove a legitimate peer and break stuff. */
2116
2117 for (;;) {
2118 skb = skb_dequeue(&ar->offchan_tx_queue);
2119 if (!skb)
2120 break;
2121
2122 mutex_lock(&ar->conf_mutex);
2123
Michal Kazior7aa7a722014-08-25 12:09:38 +02002124 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002125 skb);
2126
2127 hdr = (struct ieee80211_hdr *)skb->data;
2128 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002129 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130
2131 spin_lock_bh(&ar->data_lock);
2132 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2133 spin_unlock_bh(&ar->data_lock);
2134
2135 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002136 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002137 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002138 peer_addr, vdev_id);
2139
2140 if (!peer) {
2141 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2142 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002143 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002144 peer_addr, vdev_id, ret);
2145 }
2146
2147 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002148 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149 ar->offchan_tx_skb = skb;
2150 spin_unlock_bh(&ar->data_lock);
2151
2152 ath10k_tx_htt(ar, skb);
2153
2154 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2155 3 * HZ);
2156 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002157 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002158 skb);
2159
2160 if (!peer) {
2161 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2162 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002163 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002164 peer_addr, vdev_id, ret);
2165 }
2166
2167 mutex_unlock(&ar->conf_mutex);
2168 }
2169}
2170
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002171void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2172{
2173 struct sk_buff *skb;
2174
2175 for (;;) {
2176 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2177 if (!skb)
2178 break;
2179
2180 ieee80211_free_txskb(ar->hw, skb);
2181 }
2182}
2183
2184void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2185{
2186 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2187 struct sk_buff *skb;
2188 int ret;
2189
2190 for (;;) {
2191 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2192 if (!skb)
2193 break;
2194
2195 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002196 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002197 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002198 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002199 ieee80211_free_txskb(ar->hw, skb);
2200 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002201 }
2202}
2203
Kalle Valo5e3dd152013-06-12 20:52:10 +03002204/************/
2205/* Scanning */
2206/************/
2207
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002208void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002210 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002212 switch (ar->scan.state) {
2213 case ATH10K_SCAN_IDLE:
2214 break;
2215 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002216 if (ar->scan.is_roc)
2217 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior7305d3e2014-11-24 14:58:33 +01002218 case ATH10K_SCAN_ABORTING:
2219 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002220 ieee80211_scan_completed(ar->hw,
2221 (ar->scan.state ==
2222 ATH10K_SCAN_ABORTING));
2223 /* fall through */
2224 case ATH10K_SCAN_STARTING:
2225 ar->scan.state = ATH10K_SCAN_IDLE;
2226 ar->scan_channel = NULL;
2227 ath10k_offchan_tx_purge(ar);
2228 cancel_delayed_work(&ar->scan.timeout);
2229 complete_all(&ar->scan.completed);
2230 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002232}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002233
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002234void ath10k_scan_finish(struct ath10k *ar)
2235{
2236 spin_lock_bh(&ar->data_lock);
2237 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238 spin_unlock_bh(&ar->data_lock);
2239}
2240
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002241static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242{
2243 struct wmi_stop_scan_arg arg = {
2244 .req_id = 1, /* FIXME */
2245 .req_type = WMI_SCAN_STOP_ONE,
2246 .u.scan_id = ATH10K_SCAN_ID,
2247 };
2248 int ret;
2249
2250 lockdep_assert_held(&ar->conf_mutex);
2251
Kalle Valo5e3dd152013-06-12 20:52:10 +03002252 ret = ath10k_wmi_stop_scan(ar, &arg);
2253 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002254 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002255 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002256 }
2257
Kalle Valo5e3dd152013-06-12 20:52:10 +03002258 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002259 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002260 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002262 } else if (ret > 0) {
2263 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002264 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002265
2266out:
2267 /* Scan state should be updated upon scan completion but in case
2268 * firmware fails to deliver the event (for whatever reason) it is
2269 * desired to clean up scan state anyway. Firmware may have just
2270 * dropped the scan completion event delivery due to transport pipe
2271 * being overflown with data and/or it can recover on its own before
2272 * next scan request is submitted.
2273 */
2274 spin_lock_bh(&ar->data_lock);
2275 if (ar->scan.state != ATH10K_SCAN_IDLE)
2276 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002277 spin_unlock_bh(&ar->data_lock);
2278
2279 return ret;
2280}
2281
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002282static void ath10k_scan_abort(struct ath10k *ar)
2283{
2284 int ret;
2285
2286 lockdep_assert_held(&ar->conf_mutex);
2287
2288 spin_lock_bh(&ar->data_lock);
2289
2290 switch (ar->scan.state) {
2291 case ATH10K_SCAN_IDLE:
2292 /* This can happen if timeout worker kicked in and called
2293 * abortion while scan completion was being processed.
2294 */
2295 break;
2296 case ATH10K_SCAN_STARTING:
2297 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002298 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002299 ath10k_scan_state_str(ar->scan.state),
2300 ar->scan.state);
2301 break;
2302 case ATH10K_SCAN_RUNNING:
2303 ar->scan.state = ATH10K_SCAN_ABORTING;
2304 spin_unlock_bh(&ar->data_lock);
2305
2306 ret = ath10k_scan_stop(ar);
2307 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002308 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002309
2310 spin_lock_bh(&ar->data_lock);
2311 break;
2312 }
2313
2314 spin_unlock_bh(&ar->data_lock);
2315}
2316
2317void ath10k_scan_timeout_work(struct work_struct *work)
2318{
2319 struct ath10k *ar = container_of(work, struct ath10k,
2320 scan.timeout.work);
2321
2322 mutex_lock(&ar->conf_mutex);
2323 ath10k_scan_abort(ar);
2324 mutex_unlock(&ar->conf_mutex);
2325}
2326
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327static int ath10k_start_scan(struct ath10k *ar,
2328 const struct wmi_start_scan_arg *arg)
2329{
2330 int ret;
2331
2332 lockdep_assert_held(&ar->conf_mutex);
2333
2334 ret = ath10k_wmi_start_scan(ar, arg);
2335 if (ret)
2336 return ret;
2337
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2339 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002340 ret = ath10k_scan_stop(ar);
2341 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002342 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002343
2344 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002345 }
2346
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002347 /* Add a 200ms margin to account for event/command processing */
2348 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2349 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350 return 0;
2351}
2352
2353/**********************/
2354/* mac80211 callbacks */
2355/**********************/
2356
2357static void ath10k_tx(struct ieee80211_hw *hw,
2358 struct ieee80211_tx_control *control,
2359 struct sk_buff *skb)
2360{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002361 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002362 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2363 struct ieee80211_vif *vif = info->control.vif;
2364 struct ieee80211_key_conf *key = info->control.hw_key;
2365 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366
2367 /* We should disable CCK RATE due to P2P */
2368 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002369 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370
Michal Kazior4b604552014-07-21 21:03:09 +03002371 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2372 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002373 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002374
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002375 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002376 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2377 ath10k_tx_h_nwifi(hw, skb);
2378 ath10k_tx_h_update_wep_key(vif, key, skb);
2379 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2380 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002381 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002382
Kalle Valo5e3dd152013-06-12 20:52:10 +03002383 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2384 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002385 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002386 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002387 spin_unlock_bh(&ar->data_lock);
2388
Michal Kazior8d6d3622014-11-24 14:58:31 +01002389 if (ath10k_mac_need_offchan_tx_work(ar)) {
2390 ATH10K_SKB_CB(skb)->htt.freq = 0;
2391 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002392
Michal Kazior8d6d3622014-11-24 14:58:31 +01002393 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2394 skb);
2395
2396 skb_queue_tail(&ar->offchan_tx_queue, skb);
2397 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2398 return;
2399 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002400 }
2401
2402 ath10k_tx_htt(ar, skb);
2403}
2404
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002405/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002406void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002407{
2408 /* make sure rcu-protected mac80211 tx path itself is drained */
2409 synchronize_net();
2410
2411 ath10k_offchan_tx_purge(ar);
2412 ath10k_mgmt_over_wmi_tx_purge(ar);
2413
2414 cancel_work_sync(&ar->offchan_tx_work);
2415 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2416}
2417
Michal Kazioraffd3212013-07-16 09:54:35 +02002418void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002419{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002420 struct ath10k_vif *arvif;
2421
Michal Kazior818bdd12013-07-16 09:38:57 +02002422 lockdep_assert_held(&ar->conf_mutex);
2423
Michal Kazior19337472014-08-28 12:58:16 +02002424 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2425 ar->filter_flags = 0;
2426 ar->monitor = false;
2427
2428 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002429 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002430
2431 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002432
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002433 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002434 ath10k_peer_cleanup_all(ar);
2435 ath10k_core_stop(ar);
2436 ath10k_hif_power_down(ar);
2437
2438 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002439 list_for_each_entry(arvif, &ar->arvifs, list)
2440 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002441 spin_unlock_bh(&ar->data_lock);
2442}
2443
Ben Greear46acf7b2014-05-16 17:15:38 +03002444static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2445{
2446 struct ath10k *ar = hw->priv;
2447
2448 mutex_lock(&ar->conf_mutex);
2449
2450 if (ar->cfg_tx_chainmask) {
2451 *tx_ant = ar->cfg_tx_chainmask;
2452 *rx_ant = ar->cfg_rx_chainmask;
2453 } else {
2454 *tx_ant = ar->supp_tx_chainmask;
2455 *rx_ant = ar->supp_rx_chainmask;
2456 }
2457
2458 mutex_unlock(&ar->conf_mutex);
2459
2460 return 0;
2461}
2462
Ben Greear5572a952014-11-24 16:22:10 +02002463static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2464{
2465 /* It is not clear that allowing gaps in chainmask
2466 * is helpful. Probably it will not do what user
2467 * is hoping for, so warn in that case.
2468 */
2469 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2470 return;
2471
2472 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2473 dbg, cm);
2474}
2475
Ben Greear46acf7b2014-05-16 17:15:38 +03002476static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2477{
2478 int ret;
2479
2480 lockdep_assert_held(&ar->conf_mutex);
2481
Ben Greear5572a952014-11-24 16:22:10 +02002482 ath10k_check_chain_mask(ar, tx_ant, "tx");
2483 ath10k_check_chain_mask(ar, rx_ant, "rx");
2484
Ben Greear46acf7b2014-05-16 17:15:38 +03002485 ar->cfg_tx_chainmask = tx_ant;
2486 ar->cfg_rx_chainmask = rx_ant;
2487
2488 if ((ar->state != ATH10K_STATE_ON) &&
2489 (ar->state != ATH10K_STATE_RESTARTED))
2490 return 0;
2491
2492 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2493 tx_ant);
2494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002496 ret, tx_ant);
2497 return ret;
2498 }
2499
2500 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2501 rx_ant);
2502 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002503 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002504 ret, rx_ant);
2505 return ret;
2506 }
2507
2508 return 0;
2509}
2510
2511static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2512{
2513 struct ath10k *ar = hw->priv;
2514 int ret;
2515
2516 mutex_lock(&ar->conf_mutex);
2517 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2518 mutex_unlock(&ar->conf_mutex);
2519 return ret;
2520}
2521
Kalle Valo5e3dd152013-06-12 20:52:10 +03002522static int ath10k_start(struct ieee80211_hw *hw)
2523{
2524 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002525 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002526
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002527 /*
2528 * This makes sense only when restarting hw. It is harmless to call
2529 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2530 * commands will be submitted while restarting.
2531 */
2532 ath10k_drain_tx(ar);
2533
Michal Kazior548db542013-07-05 16:15:15 +03002534 mutex_lock(&ar->conf_mutex);
2535
Michal Kaziorc5058f52014-05-26 12:46:03 +03002536 switch (ar->state) {
2537 case ATH10K_STATE_OFF:
2538 ar->state = ATH10K_STATE_ON;
2539 break;
2540 case ATH10K_STATE_RESTARTING:
2541 ath10k_halt(ar);
2542 ar->state = ATH10K_STATE_RESTARTED;
2543 break;
2544 case ATH10K_STATE_ON:
2545 case ATH10K_STATE_RESTARTED:
2546 case ATH10K_STATE_WEDGED:
2547 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002548 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002549 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002550 case ATH10K_STATE_UTF:
2551 ret = -EBUSY;
2552 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002553 }
2554
2555 ret = ath10k_hif_power_up(ar);
2556 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002557 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002558 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002559 }
2560
Kalle Valo43d2a302014-09-10 18:23:30 +03002561 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002562 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002563 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002564 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002565 }
2566
Bartosz Markowski226a3392013-09-26 17:47:16 +02002567 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002568 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002569 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002570 goto err_core_stop;
2571 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002573 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002574 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002575 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002576 goto err_core_stop;
2577 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002578
Ben Greear46acf7b2014-05-16 17:15:38 +03002579 if (ar->cfg_tx_chainmask)
2580 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2581 ar->cfg_rx_chainmask);
2582
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002583 /*
2584 * By default FW set ARP frames ac to voice (6). In that case ARP
2585 * exchange is not working properly for UAPSD enabled AP. ARP requests
2586 * which arrives with access category 0 are processed by network stack
2587 * and send back with access category 0, but FW changes access category
2588 * to 6. Set ARP frames access category to best effort (0) solves
2589 * this problem.
2590 */
2591
2592 ret = ath10k_wmi_pdev_set_param(ar,
2593 ar->wmi.pdev_param->arp_ac_override, 0);
2594 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002595 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002596 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002597 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002598 }
2599
Michal Kaziord6500972014-04-08 09:56:09 +03002600 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002601 ath10k_regd_update(ar);
2602
Simon Wunderlich855aed12014-08-02 09:12:54 +03002603 ath10k_spectral_start(ar);
2604
Michal Kaziorae254432014-05-26 12:46:02 +03002605 mutex_unlock(&ar->conf_mutex);
2606 return 0;
2607
2608err_core_stop:
2609 ath10k_core_stop(ar);
2610
2611err_power_down:
2612 ath10k_hif_power_down(ar);
2613
2614err_off:
2615 ar->state = ATH10K_STATE_OFF;
2616
2617err:
Michal Kazior548db542013-07-05 16:15:15 +03002618 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002619 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002620}
2621
2622static void ath10k_stop(struct ieee80211_hw *hw)
2623{
2624 struct ath10k *ar = hw->priv;
2625
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002626 ath10k_drain_tx(ar);
2627
Michal Kazior548db542013-07-05 16:15:15 +03002628 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002629 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002630 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002631 ar->state = ATH10K_STATE_OFF;
2632 }
Michal Kazior548db542013-07-05 16:15:15 +03002633 mutex_unlock(&ar->conf_mutex);
2634
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002635 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002636 cancel_work_sync(&ar->restart_work);
2637}
2638
Michal Kaziorad088bf2013-10-16 15:44:46 +03002639static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002640{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002641 struct ath10k_vif *arvif;
2642 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002643
2644 lockdep_assert_held(&ar->conf_mutex);
2645
Michal Kaziorad088bf2013-10-16 15:44:46 +03002646 list_for_each_entry(arvif, &ar->arvifs, list) {
2647 ret = ath10k_mac_vif_setup_ps(arvif);
2648 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002649 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002650 break;
2651 }
2652 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002653
Michal Kaziorad088bf2013-10-16 15:44:46 +03002654 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655}
2656
Michal Kaziorc930f742014-01-23 11:38:25 +01002657static const char *chandef_get_width(enum nl80211_chan_width width)
2658{
2659 switch (width) {
2660 case NL80211_CHAN_WIDTH_20_NOHT:
2661 return "20 (noht)";
2662 case NL80211_CHAN_WIDTH_20:
2663 return "20";
2664 case NL80211_CHAN_WIDTH_40:
2665 return "40";
2666 case NL80211_CHAN_WIDTH_80:
2667 return "80";
2668 case NL80211_CHAN_WIDTH_80P80:
2669 return "80+80";
2670 case NL80211_CHAN_WIDTH_160:
2671 return "160";
2672 case NL80211_CHAN_WIDTH_5:
2673 return "5";
2674 case NL80211_CHAN_WIDTH_10:
2675 return "10";
2676 }
2677 return "?";
2678}
2679
2680static void ath10k_config_chan(struct ath10k *ar)
2681{
2682 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002683 int ret;
2684
2685 lockdep_assert_held(&ar->conf_mutex);
2686
Michal Kazior7aa7a722014-08-25 12:09:38 +02002687 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002688 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2689 ar->chandef.chan->center_freq,
2690 ar->chandef.center_freq1,
2691 ar->chandef.center_freq2,
2692 chandef_get_width(ar->chandef.width));
2693
2694 /* First stop monitor interface. Some FW versions crash if there's a
2695 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002696 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002697 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002698
2699 list_for_each_entry(arvif, &ar->arvifs, list) {
2700 if (!arvif->is_started)
2701 continue;
2702
Michal Kaziordc55e302014-07-29 12:53:36 +03002703 if (!arvif->is_up)
2704 continue;
2705
Michal Kaziorc930f742014-01-23 11:38:25 +01002706 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2707 continue;
2708
Michal Kaziordc55e302014-07-29 12:53:36 +03002709 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002710 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002711 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002712 arvif->vdev_id, ret);
2713 continue;
2714 }
2715 }
2716
Michal Kaziordc55e302014-07-29 12:53:36 +03002717 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002718
2719 list_for_each_entry(arvif, &ar->arvifs, list) {
2720 if (!arvif->is_started)
2721 continue;
2722
2723 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2724 continue;
2725
Michal Kaziordc55e302014-07-29 12:53:36 +03002726 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002727 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002728 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002729 arvif->vdev_id, ret);
2730 continue;
2731 }
2732
2733 if (!arvif->is_up)
2734 continue;
2735
2736 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2737 arvif->bssid);
2738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002739 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002740 arvif->vdev_id, ret);
2741 continue;
2742 }
2743 }
2744
Michal Kazior19337472014-08-28 12:58:16 +02002745 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002746}
2747
Michal Kazior7d9d5582014-10-21 10:40:15 +03002748static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2749{
2750 int ret;
2751 u32 param;
2752
2753 lockdep_assert_held(&ar->conf_mutex);
2754
2755 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2756
2757 param = ar->wmi.pdev_param->txpower_limit2g;
2758 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2759 if (ret) {
2760 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2761 txpower, ret);
2762 return ret;
2763 }
2764
2765 param = ar->wmi.pdev_param->txpower_limit5g;
2766 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2767 if (ret) {
2768 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2769 txpower, ret);
2770 return ret;
2771 }
2772
2773 return 0;
2774}
2775
2776static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2777{
2778 struct ath10k_vif *arvif;
2779 int ret, txpower = -1;
2780
2781 lockdep_assert_held(&ar->conf_mutex);
2782
2783 list_for_each_entry(arvif, &ar->arvifs, list) {
2784 WARN_ON(arvif->txpower < 0);
2785
2786 if (txpower == -1)
2787 txpower = arvif->txpower;
2788 else
2789 txpower = min(txpower, arvif->txpower);
2790 }
2791
2792 if (WARN_ON(txpower == -1))
2793 return -EINVAL;
2794
2795 ret = ath10k_mac_txpower_setup(ar, txpower);
2796 if (ret) {
2797 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2798 txpower, ret);
2799 return ret;
2800 }
2801
2802 return 0;
2803}
2804
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2806{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 struct ath10k *ar = hw->priv;
2808 struct ieee80211_conf *conf = &hw->conf;
2809 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002810
2811 mutex_lock(&ar->conf_mutex);
2812
2813 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002814 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002815 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002816 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002817 conf->chandef.chan->flags,
2818 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002819
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 spin_lock_bh(&ar->data_lock);
2821 ar->rx_channel = conf->chandef.chan;
2822 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002823
Michal Kaziord6500972014-04-08 09:56:09 +03002824 ar->radar_enabled = conf->radar_enabled;
2825 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002826
2827 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2828 ar->chandef = conf->chandef;
2829 ath10k_config_chan(ar);
2830 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002831 }
2832
Michal Kazioraffd3212013-07-16 09:54:35 +02002833 if (changed & IEEE80211_CONF_CHANGE_PS)
2834 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835
2836 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002837 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2838 ret = ath10k_monitor_recalc(ar);
2839 if (ret)
2840 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002841 }
2842
2843 mutex_unlock(&ar->conf_mutex);
2844 return ret;
2845}
2846
Ben Greear5572a952014-11-24 16:22:10 +02002847static u32 get_nss_from_chainmask(u16 chain_mask)
2848{
2849 if ((chain_mask & 0x15) == 0x15)
2850 return 4;
2851 else if ((chain_mask & 0x7) == 0x7)
2852 return 3;
2853 else if ((chain_mask & 0x3) == 0x3)
2854 return 2;
2855 return 1;
2856}
2857
Kalle Valo5e3dd152013-06-12 20:52:10 +03002858/*
2859 * TODO:
2860 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2861 * because we will send mgmt frames without CCK. This requirement
2862 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2863 * in the TX packet.
2864 */
2865static int ath10k_add_interface(struct ieee80211_hw *hw,
2866 struct ieee80211_vif *vif)
2867{
2868 struct ath10k *ar = hw->priv;
2869 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2870 enum wmi_sta_powersave_param param;
2871 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002872 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002874 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002875
2876 mutex_lock(&ar->conf_mutex);
2877
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002878 memset(arvif, 0, sizeof(*arvif));
2879
Kalle Valo5e3dd152013-06-12 20:52:10 +03002880 arvif->ar = ar;
2881 arvif->vif = vif;
2882
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002883 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002884 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002885
Ben Greeara9aefb32014-08-12 11:02:19 +03002886 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002887 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002888 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002889 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002890 }
Ben Greear16c11172014-09-23 14:17:16 -07002891 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002892
Ben Greear16c11172014-09-23 14:17:16 -07002893 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2894 bit, ar->free_vdev_map);
2895
2896 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002897 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002898
2899 if (ar->p2p)
2900 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2901
2902 switch (vif->type) {
2903 case NL80211_IFTYPE_UNSPECIFIED:
2904 case NL80211_IFTYPE_STATION:
2905 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2906 if (vif->p2p)
2907 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2908 break;
2909 case NL80211_IFTYPE_ADHOC:
2910 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2911 break;
2912 case NL80211_IFTYPE_AP:
2913 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2914
2915 if (vif->p2p)
2916 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2917 break;
2918 case NL80211_IFTYPE_MONITOR:
2919 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2920 break;
2921 default:
2922 WARN_ON(1);
2923 break;
2924 }
2925
Michal Kazior64badcb2014-09-18 11:18:02 +03002926 /* Some firmware revisions don't wait for beacon tx completion before
2927 * sending another SWBA event. This could lead to hardware using old
2928 * (freed) beacon data in some cases, e.g. tx credit starvation
2929 * combined with missed TBTT. This is very very rare.
2930 *
2931 * On non-IOMMU-enabled hosts this could be a possible security issue
2932 * because hw could beacon some random data on the air. On
2933 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2934 * device would crash.
2935 *
2936 * Since there are no beacon tx completions (implicit nor explicit)
2937 * propagated to host the only workaround for this is to allocate a
2938 * DMA-coherent buffer for a lifetime of a vif and use it for all
2939 * beacon tx commands. Worst case for this approach is some beacons may
2940 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2941 */
2942 if (vif->type == NL80211_IFTYPE_ADHOC ||
2943 vif->type == NL80211_IFTYPE_AP) {
2944 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2945 IEEE80211_MAX_FRAME_LEN,
2946 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05302947 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03002948 if (!arvif->beacon_buf) {
2949 ret = -ENOMEM;
2950 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2951 ret);
2952 goto err;
2953 }
2954 }
2955
2956 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2957 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2958 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002959
2960 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2961 arvif->vdev_subtype, vif->addr);
2962 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002963 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002964 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002965 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002966 }
2967
Ben Greear16c11172014-09-23 14:17:16 -07002968 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002969 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002970
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002971 vdev_param = ar->wmi.vdev_param->def_keyid;
2972 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002973 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002974 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002975 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002976 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002977 goto err_vdev_delete;
2978 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002979
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002980 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2981 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002982 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002983 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002984 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002985 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002986 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002987 goto err_vdev_delete;
2988 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002989
Ben Greear5572a952014-11-24 16:22:10 +02002990 if (ar->cfg_tx_chainmask) {
2991 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
2992
2993 vdev_param = ar->wmi.vdev_param->nss;
2994 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2995 nss);
2996 if (ret) {
2997 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
2998 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
2999 ret);
3000 goto err_vdev_delete;
3001 }
3002 }
3003
Kalle Valo5e3dd152013-06-12 20:52:10 +03003004 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3005 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3006 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003007 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003008 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003009 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003010 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003011
Kalle Valo5a13e762014-01-20 11:01:46 +02003012 ret = ath10k_mac_set_kickout(arvif);
3013 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003014 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003015 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003016 goto err_peer_delete;
3017 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003018 }
3019
3020 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3021 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3022 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3023 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3024 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003025 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003026 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003027 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003028 goto err_peer_delete;
3029 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003030
3031 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
3032 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
3033 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3034 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003035 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003036 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003037 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003038 goto err_peer_delete;
3039 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003040
3041 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
3042 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
3043 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3044 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003045 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003046 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003047 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003048 goto err_peer_delete;
3049 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003050 }
3051
Michal Kazior424121c2013-07-22 14:13:31 +02003052 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003053 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003054 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003055 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003056 goto err_peer_delete;
3057 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003058
Michal Kazior424121c2013-07-22 14:13:31 +02003059 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003060 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003061 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003062 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003063 goto err_peer_delete;
3064 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003065
Michal Kazior7d9d5582014-10-21 10:40:15 +03003066 arvif->txpower = vif->bss_conf.txpower;
3067 ret = ath10k_mac_txpower_recalc(ar);
3068 if (ret) {
3069 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3070 goto err_peer_delete;
3071 }
3072
Kalle Valo5e3dd152013-06-12 20:52:10 +03003073 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003074 return 0;
3075
3076err_peer_delete:
3077 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3078 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3079
3080err_vdev_delete:
3081 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003082 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003083 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003084
3085err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003086 if (arvif->beacon_buf) {
3087 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3088 arvif->beacon_buf, arvif->beacon_paddr);
3089 arvif->beacon_buf = NULL;
3090 }
3091
Michal Kazior9dad14a2013-10-16 15:44:45 +03003092 mutex_unlock(&ar->conf_mutex);
3093
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094 return ret;
3095}
3096
3097static void ath10k_remove_interface(struct ieee80211_hw *hw,
3098 struct ieee80211_vif *vif)
3099{
3100 struct ath10k *ar = hw->priv;
3101 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3102 int ret;
3103
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003104 cancel_work_sync(&arvif->wep_key_work);
3105
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303106 mutex_lock(&ar->conf_mutex);
3107
Michal Kaziored543882013-09-13 14:16:56 +02003108 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003109 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003110 spin_unlock_bh(&ar->data_lock);
3111
Simon Wunderlich855aed12014-08-02 09:12:54 +03003112 ret = ath10k_spectral_vif_stop(arvif);
3113 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003114 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003115 arvif->vdev_id, ret);
3116
Ben Greear16c11172014-09-23 14:17:16 -07003117 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003118 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003119
3120 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3121 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3122 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003123 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003124 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003125
3126 kfree(arvif->u.ap.noa_data);
3127 }
3128
Michal Kazior7aa7a722014-08-25 12:09:38 +02003129 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003130 arvif->vdev_id);
3131
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3133 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003134 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003135 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003136
Kalle Valo5e3dd152013-06-12 20:52:10 +03003137 ath10k_peer_cleanup(ar, arvif->vdev_id);
3138
3139 mutex_unlock(&ar->conf_mutex);
3140}
3141
3142/*
3143 * FIXME: Has to be verified.
3144 */
3145#define SUPPORTED_FILTERS \
3146 (FIF_PROMISC_IN_BSS | \
3147 FIF_ALLMULTI | \
3148 FIF_CONTROL | \
3149 FIF_PSPOLL | \
3150 FIF_OTHER_BSS | \
3151 FIF_BCN_PRBRESP_PROMISC | \
3152 FIF_PROBE_REQ | \
3153 FIF_FCSFAIL)
3154
3155static void ath10k_configure_filter(struct ieee80211_hw *hw,
3156 unsigned int changed_flags,
3157 unsigned int *total_flags,
3158 u64 multicast)
3159{
3160 struct ath10k *ar = hw->priv;
3161 int ret;
3162
3163 mutex_lock(&ar->conf_mutex);
3164
3165 changed_flags &= SUPPORTED_FILTERS;
3166 *total_flags &= SUPPORTED_FILTERS;
3167 ar->filter_flags = *total_flags;
3168
Michal Kazior19337472014-08-28 12:58:16 +02003169 ret = ath10k_monitor_recalc(ar);
3170 if (ret)
3171 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003172
3173 mutex_unlock(&ar->conf_mutex);
3174}
3175
3176static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3177 struct ieee80211_vif *vif,
3178 struct ieee80211_bss_conf *info,
3179 u32 changed)
3180{
3181 struct ath10k *ar = hw->priv;
3182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3183 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003184 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003185
3186 mutex_lock(&ar->conf_mutex);
3187
3188 if (changed & BSS_CHANGED_IBSS)
3189 ath10k_control_ibss(arvif, info, vif->addr);
3190
3191 if (changed & BSS_CHANGED_BEACON_INT) {
3192 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003193 vdev_param = ar->wmi.vdev_param->beacon_interval;
3194 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003195 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003196 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003197 "mac vdev %d beacon_interval %d\n",
3198 arvif->vdev_id, arvif->beacon_interval);
3199
Kalle Valo5e3dd152013-06-12 20:52:10 +03003200 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003201 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003202 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003203 }
3204
3205 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003206 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003207 "vdev %d set beacon tx mode to staggered\n",
3208 arvif->vdev_id);
3209
Bartosz Markowski226a3392013-09-26 17:47:16 +02003210 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3211 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212 WMI_BEACON_STAGGERED_MODE);
3213 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003214 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003215 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 }
3217
John W. Linvilleb70727e2013-06-13 13:34:29 -04003218 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219 arvif->dtim_period = info->dtim_period;
3220
Michal Kazior7aa7a722014-08-25 12:09:38 +02003221 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003222 "mac vdev %d dtim_period %d\n",
3223 arvif->vdev_id, arvif->dtim_period);
3224
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003225 vdev_param = ar->wmi.vdev_param->dtim_period;
3226 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003227 arvif->dtim_period);
3228 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003229 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003230 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003231 }
3232
3233 if (changed & BSS_CHANGED_SSID &&
3234 vif->type == NL80211_IFTYPE_AP) {
3235 arvif->u.ap.ssid_len = info->ssid_len;
3236 if (info->ssid_len)
3237 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3238 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3239 }
3240
Michal Kazior077efc82014-10-21 10:10:29 +03003241 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3242 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003243
3244 if (changed & BSS_CHANGED_BEACON_ENABLED)
3245 ath10k_control_beaconing(arvif, info);
3246
3247 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003248 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003249 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003250 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003251
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003252 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003253 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003254 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003255 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003256 }
3257
3258 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259 if (info->use_short_slot)
3260 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3261
3262 else
3263 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3264
Michal Kazior7aa7a722014-08-25 12:09:38 +02003265 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003266 arvif->vdev_id, slottime);
3267
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003268 vdev_param = ar->wmi.vdev_param->slot_time;
3269 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003270 slottime);
3271 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003272 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003273 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003274 }
3275
3276 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003277 if (info->use_short_preamble)
3278 preamble = WMI_VDEV_PREAMBLE_SHORT;
3279 else
3280 preamble = WMI_VDEV_PREAMBLE_LONG;
3281
Michal Kazior7aa7a722014-08-25 12:09:38 +02003282 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003283 "mac vdev %d preamble %dn",
3284 arvif->vdev_id, preamble);
3285
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003286 vdev_param = ar->wmi.vdev_param->preamble;
3287 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288 preamble);
3289 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003290 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003291 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003292 }
3293
3294 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003295 if (info->assoc) {
3296 /* Workaround: Make sure monitor vdev is not running
3297 * when associating to prevent some firmware revisions
3298 * (e.g. 10.1 and 10.2) from crashing.
3299 */
3300 if (ar->monitor_started)
3301 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003302 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003303 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003304 } else {
3305 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003306 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003307 }
3308
Michal Kazior7d9d5582014-10-21 10:40:15 +03003309 if (changed & BSS_CHANGED_TXPOWER) {
3310 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3311 arvif->vdev_id, info->txpower);
3312
3313 arvif->txpower = info->txpower;
3314 ret = ath10k_mac_txpower_recalc(ar);
3315 if (ret)
3316 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3317 }
3318
Kalle Valo5e3dd152013-06-12 20:52:10 +03003319 mutex_unlock(&ar->conf_mutex);
3320}
3321
3322static int ath10k_hw_scan(struct ieee80211_hw *hw,
3323 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003324 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325{
3326 struct ath10k *ar = hw->priv;
3327 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003328 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003329 struct wmi_start_scan_arg arg;
3330 int ret = 0;
3331 int i;
3332
3333 mutex_lock(&ar->conf_mutex);
3334
3335 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003336 switch (ar->scan.state) {
3337 case ATH10K_SCAN_IDLE:
3338 reinit_completion(&ar->scan.started);
3339 reinit_completion(&ar->scan.completed);
3340 ar->scan.state = ATH10K_SCAN_STARTING;
3341 ar->scan.is_roc = false;
3342 ar->scan.vdev_id = arvif->vdev_id;
3343 ret = 0;
3344 break;
3345 case ATH10K_SCAN_STARTING:
3346 case ATH10K_SCAN_RUNNING:
3347 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003348 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003349 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003350 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003351 spin_unlock_bh(&ar->data_lock);
3352
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003353 if (ret)
3354 goto exit;
3355
Kalle Valo5e3dd152013-06-12 20:52:10 +03003356 memset(&arg, 0, sizeof(arg));
3357 ath10k_wmi_start_scan_init(ar, &arg);
3358 arg.vdev_id = arvif->vdev_id;
3359 arg.scan_id = ATH10K_SCAN_ID;
3360
3361 if (!req->no_cck)
3362 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3363
3364 if (req->ie_len) {
3365 arg.ie_len = req->ie_len;
3366 memcpy(arg.ie, req->ie, arg.ie_len);
3367 }
3368
3369 if (req->n_ssids) {
3370 arg.n_ssids = req->n_ssids;
3371 for (i = 0; i < arg.n_ssids; i++) {
3372 arg.ssids[i].len = req->ssids[i].ssid_len;
3373 arg.ssids[i].ssid = req->ssids[i].ssid;
3374 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003375 } else {
3376 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003377 }
3378
3379 if (req->n_channels) {
3380 arg.n_channels = req->n_channels;
3381 for (i = 0; i < arg.n_channels; i++)
3382 arg.channels[i] = req->channels[i]->center_freq;
3383 }
3384
3385 ret = ath10k_start_scan(ar, &arg);
3386 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003387 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003388 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003389 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003390 spin_unlock_bh(&ar->data_lock);
3391 }
3392
3393exit:
3394 mutex_unlock(&ar->conf_mutex);
3395 return ret;
3396}
3397
3398static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3399 struct ieee80211_vif *vif)
3400{
3401 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003402
3403 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003404 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003406
3407 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408}
3409
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003410static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3411 struct ath10k_vif *arvif,
3412 enum set_key_cmd cmd,
3413 struct ieee80211_key_conf *key)
3414{
3415 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3416 int ret;
3417
3418 /* 10.1 firmware branch requires default key index to be set to group
3419 * key index after installing it. Otherwise FW/HW Txes corrupted
3420 * frames with multi-vif APs. This is not required for main firmware
3421 * branch (e.g. 636).
3422 *
3423 * FIXME: This has been tested only in AP. It remains unknown if this
3424 * is required for multi-vif STA interfaces on 10.1 */
3425
3426 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3427 return;
3428
3429 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3430 return;
3431
3432 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3433 return;
3434
3435 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3436 return;
3437
3438 if (cmd != SET_KEY)
3439 return;
3440
3441 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3442 key->keyidx);
3443 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003444 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003445 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003446}
3447
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3449 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3450 struct ieee80211_key_conf *key)
3451{
3452 struct ath10k *ar = hw->priv;
3453 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3454 struct ath10k_peer *peer;
3455 const u8 *peer_addr;
3456 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3457 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3458 int ret = 0;
3459
3460 if (key->keyidx > WMI_MAX_KEY_INDEX)
3461 return -ENOSPC;
3462
3463 mutex_lock(&ar->conf_mutex);
3464
3465 if (sta)
3466 peer_addr = sta->addr;
3467 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3468 peer_addr = vif->bss_conf.bssid;
3469 else
3470 peer_addr = vif->addr;
3471
3472 key->hw_key_idx = key->keyidx;
3473
3474 /* the peer should not disappear in mid-way (unless FW goes awry) since
3475 * we already hold conf_mutex. we just make sure its there now. */
3476 spin_lock_bh(&ar->data_lock);
3477 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3478 spin_unlock_bh(&ar->data_lock);
3479
3480 if (!peer) {
3481 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003482 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003483 peer_addr);
3484 ret = -EOPNOTSUPP;
3485 goto exit;
3486 } else {
3487 /* if the peer doesn't exist there is no key to disable
3488 * anymore */
3489 goto exit;
3490 }
3491 }
3492
3493 if (is_wep) {
3494 if (cmd == SET_KEY)
3495 arvif->wep_keys[key->keyidx] = key;
3496 else
3497 arvif->wep_keys[key->keyidx] = NULL;
3498
3499 if (cmd == DISABLE_KEY)
3500 ath10k_clear_vdev_key(arvif, key);
3501 }
3502
3503 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3504 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003505 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003506 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003507 goto exit;
3508 }
3509
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003510 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3511
Kalle Valo5e3dd152013-06-12 20:52:10 +03003512 spin_lock_bh(&ar->data_lock);
3513 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3514 if (peer && cmd == SET_KEY)
3515 peer->keys[key->keyidx] = key;
3516 else if (peer && cmd == DISABLE_KEY)
3517 peer->keys[key->keyidx] = NULL;
3518 else if (peer == NULL)
3519 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003520 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003521 spin_unlock_bh(&ar->data_lock);
3522
3523exit:
3524 mutex_unlock(&ar->conf_mutex);
3525 return ret;
3526}
3527
Michal Kazior9797feb2014-02-14 14:49:48 +01003528static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3529{
3530 struct ath10k *ar;
3531 struct ath10k_vif *arvif;
3532 struct ath10k_sta *arsta;
3533 struct ieee80211_sta *sta;
3534 u32 changed, bw, nss, smps;
3535 int err;
3536
3537 arsta = container_of(wk, struct ath10k_sta, update_wk);
3538 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3539 arvif = arsta->arvif;
3540 ar = arvif->ar;
3541
3542 spin_lock_bh(&ar->data_lock);
3543
3544 changed = arsta->changed;
3545 arsta->changed = 0;
3546
3547 bw = arsta->bw;
3548 nss = arsta->nss;
3549 smps = arsta->smps;
3550
3551 spin_unlock_bh(&ar->data_lock);
3552
3553 mutex_lock(&ar->conf_mutex);
3554
3555 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003556 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003557 sta->addr, bw);
3558
3559 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3560 WMI_PEER_CHAN_WIDTH, bw);
3561 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003562 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003563 sta->addr, bw, err);
3564 }
3565
3566 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003567 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003568 sta->addr, nss);
3569
3570 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3571 WMI_PEER_NSS, nss);
3572 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003573 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003574 sta->addr, nss, err);
3575 }
3576
3577 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003578 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003579 sta->addr, smps);
3580
3581 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3582 WMI_PEER_SMPS_STATE, smps);
3583 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003584 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003585 sta->addr, smps, err);
3586 }
3587
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003588 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003589 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003590 sta->addr);
3591
Michal Kazior590922a2014-10-21 10:10:29 +03003592 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003593 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003594 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003595 sta->addr);
3596 }
3597
Michal Kazior9797feb2014-02-14 14:49:48 +01003598 mutex_unlock(&ar->conf_mutex);
3599}
3600
Kalle Valo5e3dd152013-06-12 20:52:10 +03003601static int ath10k_sta_state(struct ieee80211_hw *hw,
3602 struct ieee80211_vif *vif,
3603 struct ieee80211_sta *sta,
3604 enum ieee80211_sta_state old_state,
3605 enum ieee80211_sta_state new_state)
3606{
3607 struct ath10k *ar = hw->priv;
3608 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003609 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003610 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003611 int ret = 0;
3612
Michal Kazior76f90022014-02-25 09:29:57 +02003613 if (old_state == IEEE80211_STA_NOTEXIST &&
3614 new_state == IEEE80211_STA_NONE) {
3615 memset(arsta, 0, sizeof(*arsta));
3616 arsta->arvif = arvif;
3617 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3618 }
3619
Michal Kazior9797feb2014-02-14 14:49:48 +01003620 /* cancel must be done outside the mutex to avoid deadlock */
3621 if ((old_state == IEEE80211_STA_NONE &&
3622 new_state == IEEE80211_STA_NOTEXIST))
3623 cancel_work_sync(&arsta->update_wk);
3624
Kalle Valo5e3dd152013-06-12 20:52:10 +03003625 mutex_lock(&ar->conf_mutex);
3626
3627 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003628 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003629 /*
3630 * New station addition.
3631 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003632 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3633 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3634 else
3635 max_num_peers = TARGET_NUM_PEERS;
3636
3637 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003638 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003639 ar->num_peers, max_num_peers);
3640 ret = -ENOBUFS;
3641 goto exit;
3642 }
3643
Michal Kazior7aa7a722014-08-25 12:09:38 +02003644 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003645 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3646 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003647
Kalle Valo5e3dd152013-06-12 20:52:10 +03003648 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003649 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003650 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 -08003651 sta->addr, arvif->vdev_id, ret);
Michal Kaziora52c0282014-11-25 15:16:03 +01003652 goto exit;
3653 }
Michal Kazior077efc82014-10-21 10:10:29 +03003654
3655 if (vif->type == NL80211_IFTYPE_STATION) {
3656 WARN_ON(arvif->is_started);
3657
3658 ret = ath10k_vdev_start(arvif);
3659 if (ret) {
3660 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3661 arvif->vdev_id, ret);
3662 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3663 sta->addr));
3664 goto exit;
3665 }
3666
3667 arvif->is_started = true;
3668 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669 } else if ((old_state == IEEE80211_STA_NONE &&
3670 new_state == IEEE80211_STA_NOTEXIST)) {
3671 /*
3672 * Existing station deletion.
3673 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003674 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003675 "mac vdev %d peer delete %pM (sta gone)\n",
3676 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003677
3678 if (vif->type == NL80211_IFTYPE_STATION) {
3679 WARN_ON(!arvif->is_started);
3680
3681 ret = ath10k_vdev_stop(arvif);
3682 if (ret)
3683 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3684 arvif->vdev_id, ret);
3685
3686 arvif->is_started = false;
3687 }
3688
Kalle Valo5e3dd152013-06-12 20:52:10 +03003689 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3690 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003691 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003692 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003693
Kalle Valo5e3dd152013-06-12 20:52:10 +03003694 } else if (old_state == IEEE80211_STA_AUTH &&
3695 new_state == IEEE80211_STA_ASSOC &&
3696 (vif->type == NL80211_IFTYPE_AP ||
3697 vif->type == NL80211_IFTYPE_ADHOC)) {
3698 /*
3699 * New association.
3700 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003701 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003702 sta->addr);
3703
Michal Kazior590922a2014-10-21 10:10:29 +03003704 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003705 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003706 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003707 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003708 } else if (old_state == IEEE80211_STA_ASSOC &&
3709 new_state == IEEE80211_STA_AUTH &&
3710 (vif->type == NL80211_IFTYPE_AP ||
3711 vif->type == NL80211_IFTYPE_ADHOC)) {
3712 /*
3713 * Disassociation.
3714 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003715 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003716 sta->addr);
3717
Michal Kazior590922a2014-10-21 10:10:29 +03003718 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003720 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003721 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003723exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003724 mutex_unlock(&ar->conf_mutex);
3725 return ret;
3726}
3727
3728static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003729 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003730{
3731 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3732 u32 value = 0;
3733 int ret = 0;
3734
Michal Kazior548db542013-07-05 16:15:15 +03003735 lockdep_assert_held(&ar->conf_mutex);
3736
Kalle Valo5e3dd152013-06-12 20:52:10 +03003737 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3738 return 0;
3739
3740 switch (ac) {
3741 case IEEE80211_AC_VO:
3742 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3743 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3744 break;
3745 case IEEE80211_AC_VI:
3746 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3747 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3748 break;
3749 case IEEE80211_AC_BE:
3750 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3751 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3752 break;
3753 case IEEE80211_AC_BK:
3754 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3755 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3756 break;
3757 }
3758
3759 if (enable)
3760 arvif->u.sta.uapsd |= value;
3761 else
3762 arvif->u.sta.uapsd &= ~value;
3763
3764 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3765 WMI_STA_PS_PARAM_UAPSD,
3766 arvif->u.sta.uapsd);
3767 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003768 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003769 goto exit;
3770 }
3771
3772 if (arvif->u.sta.uapsd)
3773 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3774 else
3775 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3776
3777 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3778 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3779 value);
3780 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003781 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003782
3783exit:
3784 return ret;
3785}
3786
3787static int ath10k_conf_tx(struct ieee80211_hw *hw,
3788 struct ieee80211_vif *vif, u16 ac,
3789 const struct ieee80211_tx_queue_params *params)
3790{
3791 struct ath10k *ar = hw->priv;
3792 struct wmi_wmm_params_arg *p = NULL;
3793 int ret;
3794
3795 mutex_lock(&ar->conf_mutex);
3796
3797 switch (ac) {
3798 case IEEE80211_AC_VO:
3799 p = &ar->wmm_params.ac_vo;
3800 break;
3801 case IEEE80211_AC_VI:
3802 p = &ar->wmm_params.ac_vi;
3803 break;
3804 case IEEE80211_AC_BE:
3805 p = &ar->wmm_params.ac_be;
3806 break;
3807 case IEEE80211_AC_BK:
3808 p = &ar->wmm_params.ac_bk;
3809 break;
3810 }
3811
3812 if (WARN_ON(!p)) {
3813 ret = -EINVAL;
3814 goto exit;
3815 }
3816
3817 p->cwmin = params->cw_min;
3818 p->cwmax = params->cw_max;
3819 p->aifs = params->aifs;
3820
3821 /*
3822 * The channel time duration programmed in the HW is in absolute
3823 * microseconds, while mac80211 gives the txop in units of
3824 * 32 microseconds.
3825 */
3826 p->txop = params->txop * 32;
3827
3828 /* FIXME: FW accepts wmm params per hw, not per vif */
3829 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3830 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003831 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003832 goto exit;
3833 }
3834
3835 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3836 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003837 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003838
3839exit:
3840 mutex_unlock(&ar->conf_mutex);
3841 return ret;
3842}
3843
3844#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3845
3846static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3847 struct ieee80211_vif *vif,
3848 struct ieee80211_channel *chan,
3849 int duration,
3850 enum ieee80211_roc_type type)
3851{
3852 struct ath10k *ar = hw->priv;
3853 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3854 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003855 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003856
3857 mutex_lock(&ar->conf_mutex);
3858
3859 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003860 switch (ar->scan.state) {
3861 case ATH10K_SCAN_IDLE:
3862 reinit_completion(&ar->scan.started);
3863 reinit_completion(&ar->scan.completed);
3864 reinit_completion(&ar->scan.on_channel);
3865 ar->scan.state = ATH10K_SCAN_STARTING;
3866 ar->scan.is_roc = true;
3867 ar->scan.vdev_id = arvif->vdev_id;
3868 ar->scan.roc_freq = chan->center_freq;
3869 ret = 0;
3870 break;
3871 case ATH10K_SCAN_STARTING:
3872 case ATH10K_SCAN_RUNNING:
3873 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003874 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003875 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003876 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003877 spin_unlock_bh(&ar->data_lock);
3878
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003879 if (ret)
3880 goto exit;
3881
Michal Kaziordcca0bd2014-11-24 14:58:32 +01003882 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
3883
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884 memset(&arg, 0, sizeof(arg));
3885 ath10k_wmi_start_scan_init(ar, &arg);
3886 arg.vdev_id = arvif->vdev_id;
3887 arg.scan_id = ATH10K_SCAN_ID;
3888 arg.n_channels = 1;
3889 arg.channels[0] = chan->center_freq;
3890 arg.dwell_time_active = duration;
3891 arg.dwell_time_passive = duration;
3892 arg.max_scan_time = 2 * duration;
3893 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3894 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3895
3896 ret = ath10k_start_scan(ar, &arg);
3897 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003898 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003899 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003900 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003901 spin_unlock_bh(&ar->data_lock);
3902 goto exit;
3903 }
3904
3905 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3906 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003907 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003908
3909 ret = ath10k_scan_stop(ar);
3910 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003911 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003912
Kalle Valo5e3dd152013-06-12 20:52:10 +03003913 ret = -ETIMEDOUT;
3914 goto exit;
3915 }
3916
3917 ret = 0;
3918exit:
3919 mutex_unlock(&ar->conf_mutex);
3920 return ret;
3921}
3922
3923static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3924{
3925 struct ath10k *ar = hw->priv;
3926
3927 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003928 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003929 mutex_unlock(&ar->conf_mutex);
3930
Michal Kazior4eb2e162014-10-28 10:23:09 +01003931 cancel_delayed_work_sync(&ar->scan.timeout);
3932
Kalle Valo5e3dd152013-06-12 20:52:10 +03003933 return 0;
3934}
3935
3936/*
3937 * Both RTS and Fragmentation threshold are interface-specific
3938 * in ath10k, but device-specific in mac80211.
3939 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003940
3941static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3942{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003943 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003944 struct ath10k_vif *arvif;
3945 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003946
Michal Kaziorad088bf2013-10-16 15:44:46 +03003947 mutex_lock(&ar->conf_mutex);
3948 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003950 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003951
Michal Kaziorad088bf2013-10-16 15:44:46 +03003952 ret = ath10k_mac_set_rts(arvif, value);
3953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003954 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003955 arvif->vdev_id, ret);
3956 break;
3957 }
3958 }
3959 mutex_unlock(&ar->conf_mutex);
3960
3961 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962}
3963
3964static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3965{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003966 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003967 struct ath10k_vif *arvif;
3968 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003969
Kalle Valo5e3dd152013-06-12 20:52:10 +03003970 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003971 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003972 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003973 arvif->vdev_id, value);
3974
Michal Kazior56a0dee2014-10-23 17:04:29 +03003975 ret = ath10k_mac_set_frag(arvif, value);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003976 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003977 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003978 arvif->vdev_id, ret);
3979 break;
3980 }
3981 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003982 mutex_unlock(&ar->conf_mutex);
3983
Michal Kaziorad088bf2013-10-16 15:44:46 +03003984 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003985}
3986
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003987static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3988 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003989{
3990 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003991 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003992 int ret;
3993
3994 /* mac80211 doesn't care if we really xmit queued frames or not
3995 * we'll collect those frames either way if we stop/delete vdevs */
3996 if (drop)
3997 return;
3998
Michal Kazior548db542013-07-05 16:15:15 +03003999 mutex_lock(&ar->conf_mutex);
4000
Michal Kazioraffd3212013-07-16 09:54:35 +02004001 if (ar->state == ATH10K_STATE_WEDGED)
4002 goto skip;
4003
Michal Kazioredb82362013-07-05 16:15:14 +03004004 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004005 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004006
Michal Kazioredb82362013-07-05 16:15:14 +03004007 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004008 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004009 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004010
Michal Kazior7962b0d2014-10-28 10:34:38 +01004011 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4012 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4013 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004014
4015 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004016 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004017
4018 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004019 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004020 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004021
Michal Kazioraffd3212013-07-16 09:54:35 +02004022skip:
Michal Kazior548db542013-07-05 16:15:15 +03004023 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004024}
4025
4026/* TODO: Implement this function properly
4027 * For now it is needed to reply to Probe Requests in IBSS mode.
4028 * Propably we need this information from FW.
4029 */
4030static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4031{
4032 return 1;
4033}
4034
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004035#ifdef CONFIG_PM
4036static int ath10k_suspend(struct ieee80211_hw *hw,
4037 struct cfg80211_wowlan *wowlan)
4038{
4039 struct ath10k *ar = hw->priv;
4040 int ret;
4041
Marek Puzyniak9042e172014-02-10 17:14:23 +01004042 mutex_lock(&ar->conf_mutex);
4043
Marek Puzyniak00f54822014-02-10 17:14:24 +01004044 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004045 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004046 if (ret == -ETIMEDOUT)
4047 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004048 ret = 1;
4049 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004050 }
4051
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004052 ret = ath10k_hif_suspend(ar);
4053 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004054 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004055 goto resume;
4056 }
4057
Marek Puzyniak9042e172014-02-10 17:14:23 +01004058 ret = 0;
4059 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004060resume:
4061 ret = ath10k_wmi_pdev_resume_target(ar);
4062 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004063 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004064
4065 ret = 1;
4066exit:
4067 mutex_unlock(&ar->conf_mutex);
4068 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004069}
4070
4071static int ath10k_resume(struct ieee80211_hw *hw)
4072{
4073 struct ath10k *ar = hw->priv;
4074 int ret;
4075
Marek Puzyniak9042e172014-02-10 17:14:23 +01004076 mutex_lock(&ar->conf_mutex);
4077
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004078 ret = ath10k_hif_resume(ar);
4079 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004080 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004081 ret = 1;
4082 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004083 }
4084
4085 ret = ath10k_wmi_pdev_resume_target(ar);
4086 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004087 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004088 ret = 1;
4089 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004090 }
4091
Marek Puzyniak9042e172014-02-10 17:14:23 +01004092 ret = 0;
4093exit:
4094 mutex_unlock(&ar->conf_mutex);
4095 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004096}
4097#endif
4098
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004099static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4100 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004101{
4102 struct ath10k *ar = hw->priv;
4103
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004104 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4105 return;
4106
Michal Kazioraffd3212013-07-16 09:54:35 +02004107 mutex_lock(&ar->conf_mutex);
4108
4109 /* If device failed to restart it will be in a different state, e.g.
4110 * ATH10K_STATE_WEDGED */
4111 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004112 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004113 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004114 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004115 }
4116
4117 mutex_unlock(&ar->conf_mutex);
4118}
4119
Michal Kazior2e1dea42013-07-31 10:32:40 +02004120static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4121 struct survey_info *survey)
4122{
4123 struct ath10k *ar = hw->priv;
4124 struct ieee80211_supported_band *sband;
4125 struct survey_info *ar_survey = &ar->survey[idx];
4126 int ret = 0;
4127
4128 mutex_lock(&ar->conf_mutex);
4129
4130 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4131 if (sband && idx >= sband->n_channels) {
4132 idx -= sband->n_channels;
4133 sband = NULL;
4134 }
4135
4136 if (!sband)
4137 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4138
4139 if (!sband || idx >= sband->n_channels) {
4140 ret = -ENOENT;
4141 goto exit;
4142 }
4143
4144 spin_lock_bh(&ar->data_lock);
4145 memcpy(survey, ar_survey, sizeof(*survey));
4146 spin_unlock_bh(&ar->data_lock);
4147
4148 survey->channel = &sband->channels[idx];
4149
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004150 if (ar->rx_channel == survey->channel)
4151 survey->filled |= SURVEY_INFO_IN_USE;
4152
Michal Kazior2e1dea42013-07-31 10:32:40 +02004153exit:
4154 mutex_unlock(&ar->conf_mutex);
4155 return ret;
4156}
4157
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004158/* Helper table for legacy fixed_rate/bitrate_mask */
4159static const u8 cck_ofdm_rate[] = {
4160 /* CCK */
4161 3, /* 1Mbps */
4162 2, /* 2Mbps */
4163 1, /* 5.5Mbps */
4164 0, /* 11Mbps */
4165 /* OFDM */
4166 3, /* 6Mbps */
4167 7, /* 9Mbps */
4168 2, /* 12Mbps */
4169 6, /* 18Mbps */
4170 1, /* 24Mbps */
4171 5, /* 36Mbps */
4172 0, /* 48Mbps */
4173 4, /* 54Mbps */
4174};
4175
4176/* Check if only one bit set */
4177static int ath10k_check_single_mask(u32 mask)
4178{
4179 int bit;
4180
4181 bit = ffs(mask);
4182 if (!bit)
4183 return 0;
4184
4185 mask &= ~BIT(bit - 1);
4186 if (mask)
4187 return 2;
4188
4189 return 1;
4190}
4191
4192static bool
4193ath10k_default_bitrate_mask(struct ath10k *ar,
4194 enum ieee80211_band band,
4195 const struct cfg80211_bitrate_mask *mask)
4196{
4197 u32 legacy = 0x00ff;
4198 u8 ht = 0xff, i;
4199 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004200 u16 nrf = ar->num_rf_chains;
4201
4202 if (ar->cfg_tx_chainmask)
4203 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004204
4205 switch (band) {
4206 case IEEE80211_BAND_2GHZ:
4207 legacy = 0x00fff;
4208 vht = 0;
4209 break;
4210 case IEEE80211_BAND_5GHZ:
4211 break;
4212 default:
4213 return false;
4214 }
4215
4216 if (mask->control[band].legacy != legacy)
4217 return false;
4218
Ben Greearb116ea12014-11-24 16:22:10 +02004219 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004220 if (mask->control[band].ht_mcs[i] != ht)
4221 return false;
4222
Ben Greearb116ea12014-11-24 16:22:10 +02004223 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004224 if (mask->control[band].vht_mcs[i] != vht)
4225 return false;
4226
4227 return true;
4228}
4229
4230static bool
4231ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4232 enum ieee80211_band band,
4233 u8 *fixed_nss)
4234{
4235 int ht_nss = 0, vht_nss = 0, i;
4236
4237 /* check legacy */
4238 if (ath10k_check_single_mask(mask->control[band].legacy))
4239 return false;
4240
4241 /* check HT */
4242 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4243 if (mask->control[band].ht_mcs[i] == 0xff)
4244 continue;
4245 else if (mask->control[band].ht_mcs[i] == 0x00)
4246 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004247
4248 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004249 }
4250
4251 ht_nss = i;
4252
4253 /* check VHT */
4254 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4255 if (mask->control[band].vht_mcs[i] == 0x03ff)
4256 continue;
4257 else if (mask->control[band].vht_mcs[i] == 0x0000)
4258 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004259
4260 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004261 }
4262
4263 vht_nss = i;
4264
4265 if (ht_nss > 0 && vht_nss > 0)
4266 return false;
4267
4268 if (ht_nss)
4269 *fixed_nss = ht_nss;
4270 else if (vht_nss)
4271 *fixed_nss = vht_nss;
4272 else
4273 return false;
4274
4275 return true;
4276}
4277
4278static bool
4279ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4280 enum ieee80211_band band,
4281 enum wmi_rate_preamble *preamble)
4282{
4283 int legacy = 0, ht = 0, vht = 0, i;
4284
4285 *preamble = WMI_RATE_PREAMBLE_OFDM;
4286
4287 /* check legacy */
4288 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4289 if (legacy > 1)
4290 return false;
4291
4292 /* check HT */
4293 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4294 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4295 if (ht > 1)
4296 return false;
4297
4298 /* check VHT */
4299 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4300 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4301 if (vht > 1)
4302 return false;
4303
4304 /* Currently we support only one fixed_rate */
4305 if ((legacy + ht + vht) != 1)
4306 return false;
4307
4308 if (ht)
4309 *preamble = WMI_RATE_PREAMBLE_HT;
4310 else if (vht)
4311 *preamble = WMI_RATE_PREAMBLE_VHT;
4312
4313 return true;
4314}
4315
4316static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004317ath10k_bitrate_mask_rate(struct ath10k *ar,
4318 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004319 enum ieee80211_band band,
4320 u8 *fixed_rate,
4321 u8 *fixed_nss)
4322{
4323 u8 rate = 0, pream = 0, nss = 0, i;
4324 enum wmi_rate_preamble preamble;
4325
4326 /* Check if single rate correct */
4327 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4328 return false;
4329
4330 pream = preamble;
4331
4332 switch (preamble) {
4333 case WMI_RATE_PREAMBLE_CCK:
4334 case WMI_RATE_PREAMBLE_OFDM:
4335 i = ffs(mask->control[band].legacy) - 1;
4336
4337 if (band == IEEE80211_BAND_2GHZ && i < 4)
4338 pream = WMI_RATE_PREAMBLE_CCK;
4339
4340 if (band == IEEE80211_BAND_5GHZ)
4341 i += 4;
4342
4343 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4344 return false;
4345
4346 rate = cck_ofdm_rate[i];
4347 break;
4348 case WMI_RATE_PREAMBLE_HT:
4349 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4350 if (mask->control[band].ht_mcs[i])
4351 break;
4352
4353 if (i == IEEE80211_HT_MCS_MASK_LEN)
4354 return false;
4355
4356 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4357 nss = i;
4358 break;
4359 case WMI_RATE_PREAMBLE_VHT:
4360 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4361 if (mask->control[band].vht_mcs[i])
4362 break;
4363
4364 if (i == NL80211_VHT_NSS_MAX)
4365 return false;
4366
4367 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4368 nss = i;
4369 break;
4370 }
4371
4372 *fixed_nss = nss + 1;
4373 nss <<= 4;
4374 pream <<= 6;
4375
Michal Kazior7aa7a722014-08-25 12:09:38 +02004376 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 +01004377 pream, nss, rate);
4378
4379 *fixed_rate = pream | nss | rate;
4380
4381 return true;
4382}
4383
Michal Kazior7aa7a722014-08-25 12:09:38 +02004384static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4385 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004386 enum ieee80211_band band,
4387 u8 *fixed_rate,
4388 u8 *fixed_nss)
4389{
4390 /* First check full NSS mask, if we can simply limit NSS */
4391 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4392 return true;
4393
4394 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004395 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004396}
4397
4398static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4399 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004400 u8 fixed_nss,
4401 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004402{
4403 struct ath10k *ar = arvif->ar;
4404 u32 vdev_param;
4405 int ret = 0;
4406
4407 mutex_lock(&ar->conf_mutex);
4408
4409 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004410 arvif->fixed_nss == fixed_nss &&
4411 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004412 goto exit;
4413
4414 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004415 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004416
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004417 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004418 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004419
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004420 vdev_param = ar->wmi.vdev_param->fixed_rate;
4421 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4422 vdev_param, fixed_rate);
4423 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004424 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004425 fixed_rate, ret);
4426 ret = -EINVAL;
4427 goto exit;
4428 }
4429
4430 arvif->fixed_rate = fixed_rate;
4431
4432 vdev_param = ar->wmi.vdev_param->nss;
4433 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4434 vdev_param, fixed_nss);
4435
4436 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004437 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004438 fixed_nss, ret);
4439 ret = -EINVAL;
4440 goto exit;
4441 }
4442
4443 arvif->fixed_nss = fixed_nss;
4444
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004445 vdev_param = ar->wmi.vdev_param->sgi;
4446 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4447 force_sgi);
4448
4449 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004450 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004451 force_sgi, ret);
4452 ret = -EINVAL;
4453 goto exit;
4454 }
4455
4456 arvif->force_sgi = force_sgi;
4457
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004458exit:
4459 mutex_unlock(&ar->conf_mutex);
4460 return ret;
4461}
4462
4463static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4464 struct ieee80211_vif *vif,
4465 const struct cfg80211_bitrate_mask *mask)
4466{
4467 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4468 struct ath10k *ar = arvif->ar;
4469 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4470 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4471 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004472 u8 force_sgi;
4473
Ben Greearb116ea12014-11-24 16:22:10 +02004474 if (ar->cfg_tx_chainmask)
4475 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4476
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004477 force_sgi = mask->control[band].gi;
4478 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4479 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004480
4481 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004482 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004483 &fixed_rate,
4484 &fixed_nss))
4485 return -EINVAL;
4486 }
4487
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004488 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004489 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004490 return -EINVAL;
4491 }
4492
4493 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4494 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004495}
4496
Michal Kazior9797feb2014-02-14 14:49:48 +01004497static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4498 struct ieee80211_vif *vif,
4499 struct ieee80211_sta *sta,
4500 u32 changed)
4501{
4502 struct ath10k *ar = hw->priv;
4503 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4504 u32 bw, smps;
4505
4506 spin_lock_bh(&ar->data_lock);
4507
Michal Kazior7aa7a722014-08-25 12:09:38 +02004508 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004509 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4510 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4511 sta->smps_mode);
4512
4513 if (changed & IEEE80211_RC_BW_CHANGED) {
4514 bw = WMI_PEER_CHWIDTH_20MHZ;
4515
4516 switch (sta->bandwidth) {
4517 case IEEE80211_STA_RX_BW_20:
4518 bw = WMI_PEER_CHWIDTH_20MHZ;
4519 break;
4520 case IEEE80211_STA_RX_BW_40:
4521 bw = WMI_PEER_CHWIDTH_40MHZ;
4522 break;
4523 case IEEE80211_STA_RX_BW_80:
4524 bw = WMI_PEER_CHWIDTH_80MHZ;
4525 break;
4526 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004527 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004528 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004529 bw = WMI_PEER_CHWIDTH_20MHZ;
4530 break;
4531 }
4532
4533 arsta->bw = bw;
4534 }
4535
4536 if (changed & IEEE80211_RC_NSS_CHANGED)
4537 arsta->nss = sta->rx_nss;
4538
4539 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4540 smps = WMI_PEER_SMPS_PS_NONE;
4541
4542 switch (sta->smps_mode) {
4543 case IEEE80211_SMPS_AUTOMATIC:
4544 case IEEE80211_SMPS_OFF:
4545 smps = WMI_PEER_SMPS_PS_NONE;
4546 break;
4547 case IEEE80211_SMPS_STATIC:
4548 smps = WMI_PEER_SMPS_STATIC;
4549 break;
4550 case IEEE80211_SMPS_DYNAMIC:
4551 smps = WMI_PEER_SMPS_DYNAMIC;
4552 break;
4553 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004554 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004555 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004556 smps = WMI_PEER_SMPS_PS_NONE;
4557 break;
4558 }
4559
4560 arsta->smps = smps;
4561 }
4562
Michal Kazior9797feb2014-02-14 14:49:48 +01004563 arsta->changed |= changed;
4564
4565 spin_unlock_bh(&ar->data_lock);
4566
4567 ieee80211_queue_work(hw, &arsta->update_wk);
4568}
4569
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004570static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4571{
4572 /*
4573 * FIXME: Return 0 for time being. Need to figure out whether FW
4574 * has the API to fetch 64-bit local TSF
4575 */
4576
4577 return 0;
4578}
4579
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004580static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4581 struct ieee80211_vif *vif,
4582 enum ieee80211_ampdu_mlme_action action,
4583 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4584 u8 buf_size)
4585{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004586 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004587 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4588
Michal Kazior7aa7a722014-08-25 12:09:38 +02004589 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 +02004590 arvif->vdev_id, sta->addr, tid, action);
4591
4592 switch (action) {
4593 case IEEE80211_AMPDU_RX_START:
4594 case IEEE80211_AMPDU_RX_STOP:
4595 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4596 * creation/removal. Do we need to verify this?
4597 */
4598 return 0;
4599 case IEEE80211_AMPDU_TX_START:
4600 case IEEE80211_AMPDU_TX_STOP_CONT:
4601 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4602 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4603 case IEEE80211_AMPDU_TX_OPERATIONAL:
4604 /* Firmware offloads Tx aggregation entirely so deny mac80211
4605 * Tx aggregation requests.
4606 */
4607 return -EOPNOTSUPP;
4608 }
4609
4610 return -EINVAL;
4611}
4612
Kalle Valo5e3dd152013-06-12 20:52:10 +03004613static const struct ieee80211_ops ath10k_ops = {
4614 .tx = ath10k_tx,
4615 .start = ath10k_start,
4616 .stop = ath10k_stop,
4617 .config = ath10k_config,
4618 .add_interface = ath10k_add_interface,
4619 .remove_interface = ath10k_remove_interface,
4620 .configure_filter = ath10k_configure_filter,
4621 .bss_info_changed = ath10k_bss_info_changed,
4622 .hw_scan = ath10k_hw_scan,
4623 .cancel_hw_scan = ath10k_cancel_hw_scan,
4624 .set_key = ath10k_set_key,
4625 .sta_state = ath10k_sta_state,
4626 .conf_tx = ath10k_conf_tx,
4627 .remain_on_channel = ath10k_remain_on_channel,
4628 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4629 .set_rts_threshold = ath10k_set_rts_threshold,
4630 .set_frag_threshold = ath10k_set_frag_threshold,
4631 .flush = ath10k_flush,
4632 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004633 .set_antenna = ath10k_set_antenna,
4634 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004635 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004636 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004637 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004638 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004639 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004640 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004641 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4642 .get_et_stats = ath10k_debug_get_et_stats,
4643 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004644
4645 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4646
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004647#ifdef CONFIG_PM
4648 .suspend = ath10k_suspend,
4649 .resume = ath10k_resume,
4650#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004651};
4652
4653#define RATETAB_ENT(_rate, _rateid, _flags) { \
4654 .bitrate = (_rate), \
4655 .flags = (_flags), \
4656 .hw_value = (_rateid), \
4657}
4658
4659#define CHAN2G(_channel, _freq, _flags) { \
4660 .band = IEEE80211_BAND_2GHZ, \
4661 .hw_value = (_channel), \
4662 .center_freq = (_freq), \
4663 .flags = (_flags), \
4664 .max_antenna_gain = 0, \
4665 .max_power = 30, \
4666}
4667
4668#define CHAN5G(_channel, _freq, _flags) { \
4669 .band = IEEE80211_BAND_5GHZ, \
4670 .hw_value = (_channel), \
4671 .center_freq = (_freq), \
4672 .flags = (_flags), \
4673 .max_antenna_gain = 0, \
4674 .max_power = 30, \
4675}
4676
4677static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4678 CHAN2G(1, 2412, 0),
4679 CHAN2G(2, 2417, 0),
4680 CHAN2G(3, 2422, 0),
4681 CHAN2G(4, 2427, 0),
4682 CHAN2G(5, 2432, 0),
4683 CHAN2G(6, 2437, 0),
4684 CHAN2G(7, 2442, 0),
4685 CHAN2G(8, 2447, 0),
4686 CHAN2G(9, 2452, 0),
4687 CHAN2G(10, 2457, 0),
4688 CHAN2G(11, 2462, 0),
4689 CHAN2G(12, 2467, 0),
4690 CHAN2G(13, 2472, 0),
4691 CHAN2G(14, 2484, 0),
4692};
4693
4694static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004695 CHAN5G(36, 5180, 0),
4696 CHAN5G(40, 5200, 0),
4697 CHAN5G(44, 5220, 0),
4698 CHAN5G(48, 5240, 0),
4699 CHAN5G(52, 5260, 0),
4700 CHAN5G(56, 5280, 0),
4701 CHAN5G(60, 5300, 0),
4702 CHAN5G(64, 5320, 0),
4703 CHAN5G(100, 5500, 0),
4704 CHAN5G(104, 5520, 0),
4705 CHAN5G(108, 5540, 0),
4706 CHAN5G(112, 5560, 0),
4707 CHAN5G(116, 5580, 0),
4708 CHAN5G(120, 5600, 0),
4709 CHAN5G(124, 5620, 0),
4710 CHAN5G(128, 5640, 0),
4711 CHAN5G(132, 5660, 0),
4712 CHAN5G(136, 5680, 0),
4713 CHAN5G(140, 5700, 0),
4714 CHAN5G(149, 5745, 0),
4715 CHAN5G(153, 5765, 0),
4716 CHAN5G(157, 5785, 0),
4717 CHAN5G(161, 5805, 0),
4718 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004719};
4720
4721static struct ieee80211_rate ath10k_rates[] = {
4722 /* CCK */
4723 RATETAB_ENT(10, 0x82, 0),
4724 RATETAB_ENT(20, 0x84, 0),
4725 RATETAB_ENT(55, 0x8b, 0),
4726 RATETAB_ENT(110, 0x96, 0),
4727 /* OFDM */
4728 RATETAB_ENT(60, 0x0c, 0),
4729 RATETAB_ENT(90, 0x12, 0),
4730 RATETAB_ENT(120, 0x18, 0),
4731 RATETAB_ENT(180, 0x24, 0),
4732 RATETAB_ENT(240, 0x30, 0),
4733 RATETAB_ENT(360, 0x48, 0),
4734 RATETAB_ENT(480, 0x60, 0),
4735 RATETAB_ENT(540, 0x6c, 0),
4736};
4737
4738#define ath10k_a_rates (ath10k_rates + 4)
4739#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4740#define ath10k_g_rates (ath10k_rates + 0)
4741#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4742
Michal Kaziore7b54192014-08-07 11:03:27 +02004743struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004744{
4745 struct ieee80211_hw *hw;
4746 struct ath10k *ar;
4747
Michal Kaziore7b54192014-08-07 11:03:27 +02004748 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004749 if (!hw)
4750 return NULL;
4751
4752 ar = hw->priv;
4753 ar->hw = hw;
4754
4755 return ar;
4756}
4757
4758void ath10k_mac_destroy(struct ath10k *ar)
4759{
4760 ieee80211_free_hw(ar->hw);
4761}
4762
4763static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4764 {
4765 .max = 8,
4766 .types = BIT(NL80211_IFTYPE_STATION)
4767 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004768 },
4769 {
4770 .max = 3,
4771 .types = BIT(NL80211_IFTYPE_P2P_GO)
4772 },
4773 {
4774 .max = 7,
4775 .types = BIT(NL80211_IFTYPE_AP)
4776 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004777};
4778
Bartosz Markowskif2595092013-12-10 16:20:39 +01004779static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004780 {
4781 .max = 8,
4782 .types = BIT(NL80211_IFTYPE_AP)
4783 },
4784};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004785
4786static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4787 {
4788 .limits = ath10k_if_limits,
4789 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4790 .max_interfaces = 8,
4791 .num_different_channels = 1,
4792 .beacon_int_infra_match = true,
4793 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004794};
4795
4796static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004797 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004798 .limits = ath10k_10x_if_limits,
4799 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004800 .max_interfaces = 8,
4801 .num_different_channels = 1,
4802 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004803#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004804 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4805 BIT(NL80211_CHAN_WIDTH_20) |
4806 BIT(NL80211_CHAN_WIDTH_40) |
4807 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004808#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004809 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004810};
4811
4812static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4813{
4814 struct ieee80211_sta_vht_cap vht_cap = {0};
4815 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004816 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004817
4818 vht_cap.vht_supported = 1;
4819 vht_cap.cap = ar->vht_cap_info;
4820
Michal Kazior8865bee42013-07-24 12:36:46 +02004821 mcs_map = 0;
4822 for (i = 0; i < 8; i++) {
4823 if (i < ar->num_rf_chains)
4824 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4825 else
4826 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4827 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004828
4829 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4830 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4831
4832 return vht_cap;
4833}
4834
4835static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4836{
4837 int i;
4838 struct ieee80211_sta_ht_cap ht_cap = {0};
4839
4840 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4841 return ht_cap;
4842
4843 ht_cap.ht_supported = 1;
4844 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4845 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4846 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4847 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4848 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4849
4850 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4851 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4852
4853 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4854 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4855
4856 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4857 u32 smps;
4858
4859 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4860 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4861
4862 ht_cap.cap |= smps;
4863 }
4864
4865 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4866 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4867
4868 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4869 u32 stbc;
4870
4871 stbc = ar->ht_cap_info;
4872 stbc &= WMI_HT_CAP_RX_STBC;
4873 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4874 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4875 stbc &= IEEE80211_HT_CAP_RX_STBC;
4876
4877 ht_cap.cap |= stbc;
4878 }
4879
4880 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4881 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4882
4883 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4884 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4885
4886 /* max AMSDU is implicitly taken from vht_cap_info */
4887 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4888 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4889
Michal Kazior8865bee42013-07-24 12:36:46 +02004890 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004891 ht_cap.mcs.rx_mask[i] = 0xFF;
4892
4893 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4894
4895 return ht_cap;
4896}
4897
Kalle Valo5e3dd152013-06-12 20:52:10 +03004898static void ath10k_get_arvif_iter(void *data, u8 *mac,
4899 struct ieee80211_vif *vif)
4900{
4901 struct ath10k_vif_iter *arvif_iter = data;
4902 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4903
4904 if (arvif->vdev_id == arvif_iter->vdev_id)
4905 arvif_iter->arvif = arvif;
4906}
4907
4908struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4909{
4910 struct ath10k_vif_iter arvif_iter;
4911 u32 flags;
4912
4913 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4914 arvif_iter.vdev_id = vdev_id;
4915
4916 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4917 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4918 flags,
4919 ath10k_get_arvif_iter,
4920 &arvif_iter);
4921 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004922 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004923 return NULL;
4924 }
4925
4926 return arvif_iter.arvif;
4927}
4928
4929int ath10k_mac_register(struct ath10k *ar)
4930{
4931 struct ieee80211_supported_band *band;
4932 struct ieee80211_sta_vht_cap vht_cap;
4933 struct ieee80211_sta_ht_cap ht_cap;
4934 void *channels;
4935 int ret;
4936
4937 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4938
4939 SET_IEEE80211_DEV(ar->hw, ar->dev);
4940
4941 ht_cap = ath10k_get_ht_cap(ar);
4942 vht_cap = ath10k_create_vht_cap(ar);
4943
4944 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4945 channels = kmemdup(ath10k_2ghz_channels,
4946 sizeof(ath10k_2ghz_channels),
4947 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004948 if (!channels) {
4949 ret = -ENOMEM;
4950 goto err_free;
4951 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004952
4953 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4954 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4955 band->channels = channels;
4956 band->n_bitrates = ath10k_g_rates_size;
4957 band->bitrates = ath10k_g_rates;
4958 band->ht_cap = ht_cap;
4959
4960 /* vht is not supported in 2.4 GHz */
4961
4962 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4963 }
4964
4965 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4966 channels = kmemdup(ath10k_5ghz_channels,
4967 sizeof(ath10k_5ghz_channels),
4968 GFP_KERNEL);
4969 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004970 ret = -ENOMEM;
4971 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004972 }
4973
4974 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4975 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4976 band->channels = channels;
4977 band->n_bitrates = ath10k_a_rates_size;
4978 band->bitrates = ath10k_a_rates;
4979 band->ht_cap = ht_cap;
4980 band->vht_cap = vht_cap;
4981 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4982 }
4983
4984 ar->hw->wiphy->interface_modes =
4985 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004986 BIT(NL80211_IFTYPE_AP);
4987
Ben Greear46acf7b2014-05-16 17:15:38 +03004988 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4989 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4990
Bartosz Markowskid3541812013-12-10 16:20:40 +01004991 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4992 ar->hw->wiphy->interface_modes |=
4993 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4994 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004995
4996 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4997 IEEE80211_HW_SUPPORTS_PS |
4998 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4999 IEEE80211_HW_SUPPORTS_UAPSD |
5000 IEEE80211_HW_MFP_CAPABLE |
5001 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5002 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005003 IEEE80211_HW_AP_LINK_PS |
5004 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005005
Eliad Peller0d8614b2014-09-10 14:07:36 +03005006 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5007
Kalle Valo5e3dd152013-06-12 20:52:10 +03005008 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005009 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005010
5011 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5012 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5013 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5014 }
5015
5016 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5017 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5018
5019 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005020 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005021
Kalle Valo5e3dd152013-06-12 20:52:10 +03005022 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5023
5024 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005025 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005026 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5027
5028 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005029 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5030
Kalle Valo5e3dd152013-06-12 20:52:10 +03005031 /*
5032 * on LL hardware queues are managed entirely by the FW
5033 * so we only advertise to mac we can do the queues thing
5034 */
5035 ar->hw->queues = 4;
5036
Bartosz Markowskif2595092013-12-10 16:20:39 +01005037 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
5038 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5039 ar->hw->wiphy->n_iface_combinations =
5040 ARRAY_SIZE(ath10k_10x_if_comb);
5041 } else {
5042 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5043 ar->hw->wiphy->n_iface_combinations =
5044 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005045
5046 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01005047 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005048
Michal Kazior7c199992013-07-31 10:47:57 +02005049 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5050
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005051 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5052 /* Init ath dfs pattern detector */
5053 ar->ath_common.debug_mask = ATH_DBG_DFS;
5054 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5055 NL80211_DFS_UNSET);
5056
5057 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005058 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005059 }
5060
Kalle Valo5e3dd152013-06-12 20:52:10 +03005061 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5062 ath10k_reg_notifier);
5063 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005064 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005065 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005066 }
5067
5068 ret = ieee80211_register_hw(ar->hw);
5069 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005070 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005071 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005072 }
5073
5074 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5075 ret = regulatory_hint(ar->hw->wiphy,
5076 ar->ath_common.regulatory.alpha2);
5077 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005078 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005079 }
5080
5081 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005082
5083err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005084 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005085err_free:
5086 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5087 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5088
Kalle Valo5e3dd152013-06-12 20:52:10 +03005089 return ret;
5090}
5091
5092void ath10k_mac_unregister(struct ath10k *ar)
5093{
5094 ieee80211_unregister_hw(ar->hw);
5095
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005096 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5097 ar->dfs_detector->exit(ar->dfs_detector);
5098
Kalle Valo5e3dd152013-06-12 20:52:10 +03005099 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5100 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5101
5102 SET_IEEE80211_DEV(ar->hw, NULL);
5103}