blob: c6c09c1d421ef80612fe8004f1ccae6c37cbb442 [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
139 peer->keys[i] = arvif->wep_keys[i];
140 }
141
142 return 0;
143}
144
145static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
146 const u8 *addr)
147{
148 struct ath10k *ar = arvif->ar;
149 struct ath10k_peer *peer;
150 int first_errno = 0;
151 int ret;
152 int i;
153
154 lockdep_assert_held(&ar->conf_mutex);
155
156 spin_lock_bh(&ar->data_lock);
157 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
158 spin_unlock_bh(&ar->data_lock);
159
160 if (!peer)
161 return -ENOENT;
162
163 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
164 if (peer->keys[i] == NULL)
165 continue;
166
167 ret = ath10k_install_key(arvif, peer->keys[i],
168 DISABLE_KEY, addr);
169 if (ret && first_errno == 0)
170 first_errno = ret;
171
172 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200173 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174 i, ret);
175
176 peer->keys[i] = NULL;
177 }
178
179 return first_errno;
180}
181
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530182bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
183 u8 keyidx)
184{
185 struct ath10k_peer *peer;
186 int i;
187
188 lockdep_assert_held(&ar->data_lock);
189
190 /* We don't know which vdev this peer belongs to,
191 * since WMI doesn't give us that information.
192 *
193 * FIXME: multi-bss needs to be handled.
194 */
195 peer = ath10k_peer_find(ar, 0, addr);
196 if (!peer)
197 return false;
198
199 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
200 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
201 return true;
202 }
203
204 return false;
205}
206
Kalle Valo5e3dd152013-06-12 20:52:10 +0300207static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
208 struct ieee80211_key_conf *key)
209{
210 struct ath10k *ar = arvif->ar;
211 struct ath10k_peer *peer;
212 u8 addr[ETH_ALEN];
213 int first_errno = 0;
214 int ret;
215 int i;
216
217 lockdep_assert_held(&ar->conf_mutex);
218
219 for (;;) {
220 /* since ath10k_install_key we can't hold data_lock all the
221 * time, so we try to remove the keys incrementally */
222 spin_lock_bh(&ar->data_lock);
223 i = 0;
224 list_for_each_entry(peer, &ar->peers, list) {
225 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
226 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300227 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228 peer->keys[i] = NULL;
229 break;
230 }
231 }
232
233 if (i < ARRAY_SIZE(peer->keys))
234 break;
235 }
236 spin_unlock_bh(&ar->data_lock);
237
238 if (i == ARRAY_SIZE(peer->keys))
239 break;
240
241 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
242 if (ret && first_errno == 0)
243 first_errno = ret;
244
245 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200246 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200247 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300248 }
249
250 return first_errno;
251}
252
Kalle Valo5e3dd152013-06-12 20:52:10 +0300253/*********************/
254/* General utilities */
255/*********************/
256
257static inline enum wmi_phy_mode
258chan_to_phymode(const struct cfg80211_chan_def *chandef)
259{
260 enum wmi_phy_mode phymode = MODE_UNKNOWN;
261
262 switch (chandef->chan->band) {
263 case IEEE80211_BAND_2GHZ:
264 switch (chandef->width) {
265 case NL80211_CHAN_WIDTH_20_NOHT:
266 phymode = MODE_11G;
267 break;
268 case NL80211_CHAN_WIDTH_20:
269 phymode = MODE_11NG_HT20;
270 break;
271 case NL80211_CHAN_WIDTH_40:
272 phymode = MODE_11NG_HT40;
273 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400274 case NL80211_CHAN_WIDTH_5:
275 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300276 case NL80211_CHAN_WIDTH_80:
277 case NL80211_CHAN_WIDTH_80P80:
278 case NL80211_CHAN_WIDTH_160:
279 phymode = MODE_UNKNOWN;
280 break;
281 }
282 break;
283 case IEEE80211_BAND_5GHZ:
284 switch (chandef->width) {
285 case NL80211_CHAN_WIDTH_20_NOHT:
286 phymode = MODE_11A;
287 break;
288 case NL80211_CHAN_WIDTH_20:
289 phymode = MODE_11NA_HT20;
290 break;
291 case NL80211_CHAN_WIDTH_40:
292 phymode = MODE_11NA_HT40;
293 break;
294 case NL80211_CHAN_WIDTH_80:
295 phymode = MODE_11AC_VHT80;
296 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400297 case NL80211_CHAN_WIDTH_5:
298 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300299 case NL80211_CHAN_WIDTH_80P80:
300 case NL80211_CHAN_WIDTH_160:
301 phymode = MODE_UNKNOWN;
302 break;
303 }
304 break;
305 default:
306 break;
307 }
308
309 WARN_ON(phymode == MODE_UNKNOWN);
310 return phymode;
311}
312
313static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
314{
315/*
316 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
317 * 0 for no restriction
318 * 1 for 1/4 us
319 * 2 for 1/2 us
320 * 3 for 1 us
321 * 4 for 2 us
322 * 5 for 4 us
323 * 6 for 8 us
324 * 7 for 16 us
325 */
326 switch (mpdudensity) {
327 case 0:
328 return 0;
329 case 1:
330 case 2:
331 case 3:
332 /* Our lower layer calculations limit our precision to
333 1 microsecond */
334 return 1;
335 case 4:
336 return 2;
337 case 5:
338 return 4;
339 case 6:
340 return 8;
341 case 7:
342 return 16;
343 default:
344 return 0;
345 }
346}
347
348static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
349{
350 int ret;
351
352 lockdep_assert_held(&ar->conf_mutex);
353
354 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800355 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200356 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200357 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300358 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800359 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300360
361 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800362 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200363 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200364 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300365 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800366 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100367 spin_lock_bh(&ar->data_lock);
368 ar->num_peers++;
369 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300370
371 return 0;
372}
373
Kalle Valo5a13e762014-01-20 11:01:46 +0200374static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
375{
376 struct ath10k *ar = arvif->ar;
377 u32 param;
378 int ret;
379
380 param = ar->wmi.pdev_param->sta_kickout_th;
381 ret = ath10k_wmi_pdev_set_param(ar, param,
382 ATH10K_KICKOUT_THRESHOLD);
383 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200384 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200385 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200386 return ret;
387 }
388
389 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
390 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
391 ATH10K_KEEPALIVE_MIN_IDLE);
392 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200393 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200394 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200395 return ret;
396 }
397
398 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
399 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
400 ATH10K_KEEPALIVE_MAX_IDLE);
401 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200402 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200403 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200404 return ret;
405 }
406
407 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
408 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
409 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200411 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200412 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200413 return ret;
414 }
415
416 return 0;
417}
418
Michal Kazior424121c2013-07-22 14:13:31 +0200419static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
420{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200421 struct ath10k *ar = arvif->ar;
422 u32 vdev_param;
423
Michal Kazior424121c2013-07-22 14:13:31 +0200424 if (value != 0xFFFFFFFF)
425 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
426 ATH10K_RTS_MAX);
427
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200428 vdev_param = ar->wmi.vdev_param->rts_threshold;
429 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200430}
431
432static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
433{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200434 struct ath10k *ar = arvif->ar;
435 u32 vdev_param;
436
Michal Kazior424121c2013-07-22 14:13:31 +0200437 if (value != 0xFFFFFFFF)
438 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
439 ATH10K_FRAGMT_THRESHOLD_MIN,
440 ATH10K_FRAGMT_THRESHOLD_MAX);
441
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200442 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
443 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200444}
445
Kalle Valo5e3dd152013-06-12 20:52:10 +0300446static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
447{
448 int ret;
449
450 lockdep_assert_held(&ar->conf_mutex);
451
452 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
453 if (ret)
454 return ret;
455
456 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
457 if (ret)
458 return ret;
459
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100460 spin_lock_bh(&ar->data_lock);
461 ar->num_peers--;
462 spin_unlock_bh(&ar->data_lock);
463
Kalle Valo5e3dd152013-06-12 20:52:10 +0300464 return 0;
465}
466
467static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
468{
469 struct ath10k_peer *peer, *tmp;
470
471 lockdep_assert_held(&ar->conf_mutex);
472
473 spin_lock_bh(&ar->data_lock);
474 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
475 if (peer->vdev_id != vdev_id)
476 continue;
477
Michal Kazior7aa7a722014-08-25 12:09:38 +0200478 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300479 peer->addr, vdev_id);
480
481 list_del(&peer->list);
482 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100483 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300484 }
485 spin_unlock_bh(&ar->data_lock);
486}
487
Michal Kaziora96d7742013-07-16 09:38:56 +0200488static void ath10k_peer_cleanup_all(struct ath10k *ar)
489{
490 struct ath10k_peer *peer, *tmp;
491
492 lockdep_assert_held(&ar->conf_mutex);
493
494 spin_lock_bh(&ar->data_lock);
495 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
496 list_del(&peer->list);
497 kfree(peer);
498 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100499 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200500 spin_unlock_bh(&ar->data_lock);
501}
502
Kalle Valo5e3dd152013-06-12 20:52:10 +0300503/************************/
504/* Interface management */
505/************************/
506
Michal Kazior64badcb2014-09-18 11:18:02 +0300507void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
508{
509 struct ath10k *ar = arvif->ar;
510
511 lockdep_assert_held(&ar->data_lock);
512
513 if (!arvif->beacon)
514 return;
515
516 if (!arvif->beacon_buf)
517 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
518 arvif->beacon->len, DMA_TO_DEVICE);
519
520 dev_kfree_skb_any(arvif->beacon);
521
522 arvif->beacon = NULL;
523 arvif->beacon_sent = false;
524}
525
526static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
527{
528 struct ath10k *ar = arvif->ar;
529
530 lockdep_assert_held(&ar->data_lock);
531
532 ath10k_mac_vif_beacon_free(arvif);
533
534 if (arvif->beacon_buf) {
535 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
536 arvif->beacon_buf, arvif->beacon_paddr);
537 arvif->beacon_buf = NULL;
538 }
539}
540
Kalle Valo5e3dd152013-06-12 20:52:10 +0300541static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
542{
543 int ret;
544
Michal Kazior548db542013-07-05 16:15:15 +0300545 lockdep_assert_held(&ar->conf_mutex);
546
Michal Kazior7962b0d2014-10-28 10:34:38 +0100547 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
548 return -ESHUTDOWN;
549
Kalle Valo5e3dd152013-06-12 20:52:10 +0300550 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
551 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
552 if (ret == 0)
553 return -ETIMEDOUT;
554
555 return 0;
556}
557
Michal Kazior1bbc0972014-04-08 09:45:47 +0300558static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559{
Michal Kaziorc930f742014-01-23 11:38:25 +0100560 struct cfg80211_chan_def *chandef = &ar->chandef;
561 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300562 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563 int ret = 0;
564
565 lockdep_assert_held(&ar->conf_mutex);
566
Kalle Valo5e3dd152013-06-12 20:52:10 +0300567 arg.vdev_id = vdev_id;
568 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100569 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570
571 /* TODO setup this dynamically, what in case we
572 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100573 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200574 arg.channel.chan_radar =
575 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300576
Michal Kazior89c5c842013-10-23 04:02:13 -0700577 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700578 arg.channel.max_power = channel->max_power * 2;
579 arg.channel.max_reg_power = channel->max_reg_power * 2;
580 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581
Michal Kazior7962b0d2014-10-28 10:34:38 +0100582 reinit_completion(&ar->vdev_setup_done);
583
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584 ret = ath10k_wmi_vdev_start(ar, &arg);
585 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200586 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200587 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588 return ret;
589 }
590
591 ret = ath10k_vdev_setup_sync(ar);
592 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200593 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200594 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595 return ret;
596 }
597
598 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200600 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200601 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 goto vdev_stop;
603 }
604
605 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606
Michal Kazior7aa7a722014-08-25 12:09:38 +0200607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300608 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609 return 0;
610
611vdev_stop:
612 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
613 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200614 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200615 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616
617 return ret;
618}
619
Michal Kazior1bbc0972014-04-08 09:45:47 +0300620static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300621{
622 int ret = 0;
623
624 lockdep_assert_held(&ar->conf_mutex);
625
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200626 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
627 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200628 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200629 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300630
Michal Kazior7962b0d2014-10-28 10:34:38 +0100631 reinit_completion(&ar->vdev_setup_done);
632
Kalle Valo5e3dd152013-06-12 20:52:10 +0300633 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
634 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200635 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200636 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637
638 ret = ath10k_vdev_setup_sync(ar);
639 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200640 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200641 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300642
Michal Kazior7aa7a722014-08-25 12:09:38 +0200643 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300644 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645 return ret;
646}
647
Michal Kazior1bbc0972014-04-08 09:45:47 +0300648static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649{
650 int bit, ret = 0;
651
652 lockdep_assert_held(&ar->conf_mutex);
653
Ben Greeara9aefb32014-08-12 11:02:19 +0300654 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200655 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300656 return -ENOMEM;
657 }
658
Ben Greear16c11172014-09-23 14:17:16 -0700659 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300660
Ben Greear16c11172014-09-23 14:17:16 -0700661 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300662
663 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
664 WMI_VDEV_TYPE_MONITOR,
665 0, ar->mac_addr);
666 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200667 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200668 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300669 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670 }
671
Ben Greear16c11172014-09-23 14:17:16 -0700672 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200673 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 ar->monitor_vdev_id);
675
Kalle Valo5e3dd152013-06-12 20:52:10 +0300676 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300677}
678
Michal Kazior1bbc0972014-04-08 09:45:47 +0300679static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680{
681 int ret = 0;
682
683 lockdep_assert_held(&ar->conf_mutex);
684
Kalle Valo5e3dd152013-06-12 20:52:10 +0300685 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
686 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200687 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200688 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689 return ret;
690 }
691
Ben Greear16c11172014-09-23 14:17:16 -0700692 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300693
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695 ar->monitor_vdev_id);
696 return ret;
697}
698
Michal Kazior1bbc0972014-04-08 09:45:47 +0300699static int ath10k_monitor_start(struct ath10k *ar)
700{
701 int ret;
702
703 lockdep_assert_held(&ar->conf_mutex);
704
Michal Kazior1bbc0972014-04-08 09:45:47 +0300705 ret = ath10k_monitor_vdev_create(ar);
706 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200707 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300708 return ret;
709 }
710
711 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
712 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200713 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300714 ath10k_monitor_vdev_delete(ar);
715 return ret;
716 }
717
718 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200719 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300720
721 return 0;
722}
723
Michal Kazior19337472014-08-28 12:58:16 +0200724static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300725{
726 int ret;
727
728 lockdep_assert_held(&ar->conf_mutex);
729
Michal Kazior1bbc0972014-04-08 09:45:47 +0300730 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200731 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200732 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200733 return ret;
734 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300735
736 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200737 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200738 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200739 return ret;
740 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300741
742 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200743 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200744
745 return 0;
746}
747
748static int ath10k_monitor_recalc(struct ath10k *ar)
749{
750 bool should_start;
751
752 lockdep_assert_held(&ar->conf_mutex);
753
754 should_start = ar->monitor ||
755 ar->filter_flags & FIF_PROMISC_IN_BSS ||
756 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
757
758 ath10k_dbg(ar, ATH10K_DBG_MAC,
759 "mac monitor recalc started? %d should? %d\n",
760 ar->monitor_started, should_start);
761
762 if (should_start == ar->monitor_started)
763 return 0;
764
765 if (should_start)
766 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300767
768 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300769}
770
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200771static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
772{
773 struct ath10k *ar = arvif->ar;
774 u32 vdev_param, rts_cts = 0;
775
776 lockdep_assert_held(&ar->conf_mutex);
777
778 vdev_param = ar->wmi.vdev_param->enable_rtscts;
779
780 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
781 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
782
783 if (arvif->num_legacy_stations > 0)
784 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
785 WMI_RTSCTS_PROFILE);
786
787 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
788 rts_cts);
789}
790
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200791static int ath10k_start_cac(struct ath10k *ar)
792{
793 int ret;
794
795 lockdep_assert_held(&ar->conf_mutex);
796
797 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
798
Michal Kazior19337472014-08-28 12:58:16 +0200799 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200800 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200801 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200802 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
803 return ret;
804 }
805
Michal Kazior7aa7a722014-08-25 12:09:38 +0200806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200807 ar->monitor_vdev_id);
808
809 return 0;
810}
811
812static int ath10k_stop_cac(struct ath10k *ar)
813{
814 lockdep_assert_held(&ar->conf_mutex);
815
816 /* CAC is not running - do nothing */
817 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
818 return 0;
819
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200820 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300821 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200822
Michal Kazior7aa7a722014-08-25 12:09:38 +0200823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200824
825 return 0;
826}
827
Michal Kaziord6500972014-04-08 09:56:09 +0300828static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200829{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200830 int ret;
831
832 lockdep_assert_held(&ar->conf_mutex);
833
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200834 ath10k_stop_cac(ar);
835
Michal Kaziord6500972014-04-08 09:56:09 +0300836 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200837 return;
838
Michal Kaziord6500972014-04-08 09:56:09 +0300839 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200840 return;
841
842 ret = ath10k_start_cac(ar);
843 if (ret) {
844 /*
845 * Not possible to start CAC on current channel so starting
846 * radiation is not allowed, make this channel DFS_UNAVAILABLE
847 * by indicating that radar was detected.
848 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200849 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200850 ieee80211_radar_detected(ar->hw);
851 }
852}
853
Michal Kaziordc55e302014-07-29 12:53:36 +0300854static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300855{
856 struct ath10k *ar = arvif->ar;
857 struct cfg80211_chan_def *chandef = &ar->chandef;
858 struct wmi_vdev_start_request_arg arg = {};
859 int ret = 0;
860
861 lockdep_assert_held(&ar->conf_mutex);
862
863 reinit_completion(&ar->vdev_setup_done);
864
865 arg.vdev_id = arvif->vdev_id;
866 arg.dtim_period = arvif->dtim_period;
867 arg.bcn_intval = arvif->beacon_interval;
868
869 arg.channel.freq = chandef->chan->center_freq;
870 arg.channel.band_center_freq1 = chandef->center_freq1;
871 arg.channel.mode = chan_to_phymode(chandef);
872
873 arg.channel.min_power = 0;
874 arg.channel.max_power = chandef->chan->max_power * 2;
875 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
876 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
877
878 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
879 arg.ssid = arvif->u.ap.ssid;
880 arg.ssid_len = arvif->u.ap.ssid_len;
881 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
882
883 /* For now allow DFS for AP mode */
884 arg.channel.chan_radar =
885 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
886 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
887 arg.ssid = arvif->vif->bss_conf.ssid;
888 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
889 }
890
Michal Kazior7aa7a722014-08-25 12:09:38 +0200891 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300892 "mac vdev %d start center_freq %d phymode %s\n",
893 arg.vdev_id, arg.channel.freq,
894 ath10k_wmi_phymode_str(arg.channel.mode));
895
Michal Kaziordc55e302014-07-29 12:53:36 +0300896 if (restart)
897 ret = ath10k_wmi_vdev_restart(ar, &arg);
898 else
899 ret = ath10k_wmi_vdev_start(ar, &arg);
900
Michal Kazior72654fa2014-04-08 09:56:09 +0300901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200902 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300903 arg.vdev_id, ret);
904 return ret;
905 }
906
907 ret = ath10k_vdev_setup_sync(ar);
908 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 arg.vdev_id, ret);
911 return ret;
912 }
913
Michal Kaziord6500972014-04-08 09:56:09 +0300914 ar->num_started_vdevs++;
915 ath10k_recalc_radar_detection(ar);
916
Michal Kazior72654fa2014-04-08 09:56:09 +0300917 return ret;
918}
919
Michal Kaziordc55e302014-07-29 12:53:36 +0300920static int ath10k_vdev_start(struct ath10k_vif *arvif)
921{
922 return ath10k_vdev_start_restart(arvif, false);
923}
924
925static int ath10k_vdev_restart(struct ath10k_vif *arvif)
926{
927 return ath10k_vdev_start_restart(arvif, true);
928}
929
Michal Kazior72654fa2014-04-08 09:56:09 +0300930static int ath10k_vdev_stop(struct ath10k_vif *arvif)
931{
932 struct ath10k *ar = arvif->ar;
933 int ret;
934
935 lockdep_assert_held(&ar->conf_mutex);
936
937 reinit_completion(&ar->vdev_setup_done);
938
939 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
940 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200941 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300942 arvif->vdev_id, ret);
943 return ret;
944 }
945
946 ret = ath10k_vdev_setup_sync(ar);
947 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200948 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300949 arvif->vdev_id, ret);
950 return ret;
951 }
952
Michal Kaziord6500972014-04-08 09:56:09 +0300953 WARN_ON(ar->num_started_vdevs == 0);
954
955 if (ar->num_started_vdevs != 0) {
956 ar->num_started_vdevs--;
957 ath10k_recalc_radar_detection(ar);
958 }
959
Michal Kazior72654fa2014-04-08 09:56:09 +0300960 return ret;
961}
962
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +0300964 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300965{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200966 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967 int ret = 0;
968
Michal Kazior548db542013-07-05 16:15:15 +0300969 lockdep_assert_held(&arvif->ar->conf_mutex);
970
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 if (!info->enable_beacon) {
972 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100973
974 arvif->is_started = false;
975 arvif->is_up = false;
976
Michal Kazior748afc42014-01-23 12:48:21 +0100977 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +0300978 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +0100979 spin_unlock_bh(&arvif->ar->data_lock);
980
Kalle Valo5e3dd152013-06-12 20:52:10 +0300981 return;
982 }
983
984 arvif->tx_seq_no = 0x1000;
985
986 ret = ath10k_vdev_start(arvif);
987 if (ret)
988 return;
989
Michal Kaziorc930f742014-01-23 11:38:25 +0100990 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +0300991 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +0100992
993 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
994 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300995 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200996 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200997 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100998 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300999 return;
1000 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001001
1002 arvif->is_started = true;
1003 arvif->is_up = true;
1004
Michal Kazior7aa7a722014-08-25 12:09:38 +02001005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001006}
1007
1008static void ath10k_control_ibss(struct ath10k_vif *arvif,
1009 struct ieee80211_bss_conf *info,
1010 const u8 self_peer[ETH_ALEN])
1011{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001012 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001013 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001014 int ret = 0;
1015
Michal Kazior548db542013-07-05 16:15:15 +03001016 lockdep_assert_held(&arvif->ar->conf_mutex);
1017
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018 if (!info->ibss_joined) {
1019 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1020 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001021 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001022 self_peer, arvif->vdev_id, ret);
1023
Michal Kaziorc930f742014-01-23 11:38:25 +01001024 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001025 return;
1026
Michal Kaziorc930f742014-01-23 11:38:25 +01001027 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001028
1029 return;
1030 }
1031
1032 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1033 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001034 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001035 self_peer, arvif->vdev_id, ret);
1036 return;
1037 }
1038
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001039 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1040 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001041 ATH10K_DEFAULT_ATIM);
1042 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001043 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001044 arvif->vdev_id, ret);
1045}
1046
1047/*
1048 * Review this when mac80211 gains per-interface powersave support.
1049 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001050static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001051{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001052 struct ath10k *ar = arvif->ar;
1053 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001054 enum wmi_sta_powersave_param param;
1055 enum wmi_sta_ps_mode psmode;
1056 int ret;
1057
Michal Kazior548db542013-07-05 16:15:15 +03001058 lockdep_assert_held(&arvif->ar->conf_mutex);
1059
Michal Kaziorad088bf2013-10-16 15:44:46 +03001060 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1061 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001062
1063 if (conf->flags & IEEE80211_CONF_PS) {
1064 psmode = WMI_STA_PS_MODE_ENABLED;
1065 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1066
Michal Kaziorad088bf2013-10-16 15:44:46 +03001067 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001068 conf->dynamic_ps_timeout);
1069 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001070 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001071 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001072 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001073 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001074 } else {
1075 psmode = WMI_STA_PS_MODE_DISABLED;
1076 }
1077
Michal Kazior7aa7a722014-08-25 12:09:38 +02001078 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001079 arvif->vdev_id, psmode ? "enable" : "disable");
1080
Michal Kaziorad088bf2013-10-16 15:44:46 +03001081 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1082 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001083 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001084 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001085 return ret;
1086 }
1087
1088 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001089}
1090
1091/**********************/
1092/* Station management */
1093/**********************/
1094
Michal Kazior590922a2014-10-21 10:10:29 +03001095static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1096 struct ieee80211_vif *vif)
1097{
1098 /* Some firmware revisions have unstable STA powersave when listen
1099 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1100 * generate NullFunc frames properly even if buffered frames have been
1101 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1102 * buffered frames. Often pinging the device from AP would simply fail.
1103 *
1104 * As a workaround set it to 1.
1105 */
1106 if (vif->type == NL80211_IFTYPE_STATION)
1107 return 1;
1108
1109 return ar->hw->conf.listen_interval;
1110}
1111
Kalle Valo5e3dd152013-06-12 20:52:10 +03001112static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001113 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001114 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001115 struct wmi_peer_assoc_complete_arg *arg)
1116{
Michal Kazior590922a2014-10-21 10:10:29 +03001117 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1118
Michal Kazior548db542013-07-05 16:15:15 +03001119 lockdep_assert_held(&ar->conf_mutex);
1120
Kalle Valob25f32c2014-09-14 12:50:49 +03001121 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 arg->vdev_id = arvif->vdev_id;
1123 arg->peer_aid = sta->aid;
1124 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001125 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001126 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001127 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001128}
1129
1130static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001131 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001132 struct wmi_peer_assoc_complete_arg *arg)
1133{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001134 struct ieee80211_bss_conf *info = &vif->bss_conf;
1135 struct cfg80211_bss *bss;
1136 const u8 *rsnie = NULL;
1137 const u8 *wpaie = NULL;
1138
Michal Kazior548db542013-07-05 16:15:15 +03001139 lockdep_assert_held(&ar->conf_mutex);
1140
Kalle Valo5e3dd152013-06-12 20:52:10 +03001141 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1142 info->bssid, NULL, 0, 0, 0);
1143 if (bss) {
1144 const struct cfg80211_bss_ies *ies;
1145
1146 rcu_read_lock();
1147 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1148
1149 ies = rcu_dereference(bss->ies);
1150
1151 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001152 WLAN_OUI_TYPE_MICROSOFT_WPA,
1153 ies->data,
1154 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001155 rcu_read_unlock();
1156 cfg80211_put_bss(ar->hw->wiphy, bss);
1157 }
1158
1159 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1160 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001161 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1163 }
1164
1165 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001166 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001167 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1168 }
1169}
1170
1171static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1172 struct ieee80211_sta *sta,
1173 struct wmi_peer_assoc_complete_arg *arg)
1174{
1175 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1176 const struct ieee80211_supported_band *sband;
1177 const struct ieee80211_rate *rates;
1178 u32 ratemask;
1179 int i;
1180
Michal Kazior548db542013-07-05 16:15:15 +03001181 lockdep_assert_held(&ar->conf_mutex);
1182
Kalle Valo5e3dd152013-06-12 20:52:10 +03001183 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1184 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1185 rates = sband->bitrates;
1186
1187 rateset->num_rates = 0;
1188
1189 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1190 if (!(ratemask & 1))
1191 continue;
1192
1193 rateset->rates[rateset->num_rates] = rates->hw_value;
1194 rateset->num_rates++;
1195 }
1196}
1197
1198static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1199 struct ieee80211_sta *sta,
1200 struct wmi_peer_assoc_complete_arg *arg)
1201{
1202 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001203 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001204 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001205
Michal Kazior548db542013-07-05 16:15:15 +03001206 lockdep_assert_held(&ar->conf_mutex);
1207
Kalle Valo5e3dd152013-06-12 20:52:10 +03001208 if (!ht_cap->ht_supported)
1209 return;
1210
1211 arg->peer_flags |= WMI_PEER_HT;
1212 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1213 ht_cap->ampdu_factor)) - 1;
1214
1215 arg->peer_mpdu_density =
1216 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1217
1218 arg->peer_ht_caps = ht_cap->cap;
1219 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1220
1221 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1222 arg->peer_flags |= WMI_PEER_LDPC;
1223
1224 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1225 arg->peer_flags |= WMI_PEER_40MHZ;
1226 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1227 }
1228
1229 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1230 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1231
1232 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1233 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1234
1235 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1236 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1237 arg->peer_flags |= WMI_PEER_STBC;
1238 }
1239
1240 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001241 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1242 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1243 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1244 arg->peer_rate_caps |= stbc;
1245 arg->peer_flags |= WMI_PEER_STBC;
1246 }
1247
Kalle Valo5e3dd152013-06-12 20:52:10 +03001248 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1249 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1250 else if (ht_cap->mcs.rx_mask[1])
1251 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1252
1253 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1254 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1255 arg->peer_ht_rates.rates[n++] = i;
1256
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001257 /*
1258 * This is a workaround for HT-enabled STAs which break the spec
1259 * and have no HT capabilities RX mask (no HT RX MCS map).
1260 *
1261 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1262 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1263 *
1264 * Firmware asserts if such situation occurs.
1265 */
1266 if (n == 0) {
1267 arg->peer_ht_rates.num_rates = 8;
1268 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1269 arg->peer_ht_rates.rates[i] = i;
1270 } else {
1271 arg->peer_ht_rates.num_rates = n;
1272 arg->peer_num_spatial_streams = sta->rx_nss;
1273 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001274
Michal Kazior7aa7a722014-08-25 12:09:38 +02001275 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001276 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277 arg->peer_ht_rates.num_rates,
1278 arg->peer_num_spatial_streams);
1279}
1280
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001281static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1282 struct ath10k_vif *arvif,
1283 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001284{
1285 u32 uapsd = 0;
1286 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001287 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288
Michal Kazior548db542013-07-05 16:15:15 +03001289 lockdep_assert_held(&ar->conf_mutex);
1290
Kalle Valo5e3dd152013-06-12 20:52:10 +03001291 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001292 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001293 sta->uapsd_queues, sta->max_sp);
1294
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1296 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1297 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1298 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1299 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1300 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1301 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1302 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1303 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1304 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1305 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1306 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1307
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1309 max_sp = sta->max_sp;
1310
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001311 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1312 sta->addr,
1313 WMI_AP_PS_PEER_PARAM_UAPSD,
1314 uapsd);
1315 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001316 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001317 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001318 return ret;
1319 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001320
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001321 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1322 sta->addr,
1323 WMI_AP_PS_PEER_PARAM_MAX_SP,
1324 max_sp);
1325 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001326 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001327 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001328 return ret;
1329 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001330
1331 /* TODO setup this based on STA listen interval and
1332 beacon interval. Currently we don't know
1333 sta->listen_interval - mac80211 patch required.
1334 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001335 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001336 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1337 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001338 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001339 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001340 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001341 return ret;
1342 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001343 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001345 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346}
1347
1348static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1349 struct ieee80211_sta *sta,
1350 struct wmi_peer_assoc_complete_arg *arg)
1351{
1352 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001353 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001354
1355 if (!vht_cap->vht_supported)
1356 return;
1357
1358 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 arg->peer_vht_caps = vht_cap->cap;
1360
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001361 ampdu_factor = (vht_cap->cap &
1362 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1363 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1364
1365 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1366 * zero in VHT IE. Using it would result in degraded throughput.
1367 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1368 * it if VHT max_mpdu is smaller. */
1369 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1370 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1371 ampdu_factor)) - 1);
1372
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1374 arg->peer_flags |= WMI_PEER_80MHZ;
1375
1376 arg->peer_vht_rates.rx_max_rate =
1377 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1378 arg->peer_vht_rates.rx_mcs_set =
1379 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1380 arg->peer_vht_rates.tx_max_rate =
1381 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1382 arg->peer_vht_rates.tx_mcs_set =
1383 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1384
Michal Kazior7aa7a722014-08-25 12:09:38 +02001385 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001386 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001387}
1388
1389static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001390 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001392 struct wmi_peer_assoc_complete_arg *arg)
1393{
Michal Kazior590922a2014-10-21 10:10:29 +03001394 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1395
Kalle Valo5e3dd152013-06-12 20:52:10 +03001396 switch (arvif->vdev_type) {
1397 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001398 if (sta->wme)
1399 arg->peer_flags |= WMI_PEER_QOS;
1400
1401 if (sta->wme && sta->uapsd_queues) {
1402 arg->peer_flags |= WMI_PEER_APSD;
1403 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1404 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001405 break;
1406 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001407 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001408 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 break;
1410 default:
1411 break;
1412 }
1413}
1414
1415static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001416 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417 struct ieee80211_sta *sta,
1418 struct wmi_peer_assoc_complete_arg *arg)
1419{
1420 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1421
Kalle Valo5e3dd152013-06-12 20:52:10 +03001422 switch (ar->hw->conf.chandef.chan->band) {
1423 case IEEE80211_BAND_2GHZ:
1424 if (sta->ht_cap.ht_supported) {
1425 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1426 phymode = MODE_11NG_HT40;
1427 else
1428 phymode = MODE_11NG_HT20;
1429 } else {
1430 phymode = MODE_11G;
1431 }
1432
1433 break;
1434 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001435 /*
1436 * Check VHT first.
1437 */
1438 if (sta->vht_cap.vht_supported) {
1439 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1440 phymode = MODE_11AC_VHT80;
1441 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1442 phymode = MODE_11AC_VHT40;
1443 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1444 phymode = MODE_11AC_VHT20;
1445 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001446 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1447 phymode = MODE_11NA_HT40;
1448 else
1449 phymode = MODE_11NA_HT20;
1450 } else {
1451 phymode = MODE_11A;
1452 }
1453
1454 break;
1455 default:
1456 break;
1457 }
1458
Michal Kazior7aa7a722014-08-25 12:09:38 +02001459 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001460 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001461
Kalle Valo5e3dd152013-06-12 20:52:10 +03001462 arg->peer_phymode = phymode;
1463 WARN_ON(phymode == MODE_UNKNOWN);
1464}
1465
Kalle Valob9ada652013-10-16 15:44:46 +03001466static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001467 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001468 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001469 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001470{
Michal Kazior548db542013-07-05 16:15:15 +03001471 lockdep_assert_held(&ar->conf_mutex);
1472
Kalle Valob9ada652013-10-16 15:44:46 +03001473 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474
Michal Kazior590922a2014-10-21 10:10:29 +03001475 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1476 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001477 ath10k_peer_assoc_h_rates(ar, sta, arg);
1478 ath10k_peer_assoc_h_ht(ar, sta, arg);
1479 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001480 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1481 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001482
Kalle Valob9ada652013-10-16 15:44:46 +03001483 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001484}
1485
Michal Kazior90046f52014-02-14 14:45:51 +01001486static const u32 ath10k_smps_map[] = {
1487 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1488 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1489 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1490 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1491};
1492
1493static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1494 const u8 *addr,
1495 const struct ieee80211_sta_ht_cap *ht_cap)
1496{
1497 int smps;
1498
1499 if (!ht_cap->ht_supported)
1500 return 0;
1501
1502 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1503 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1504
1505 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1506 return -EINVAL;
1507
1508 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1509 WMI_PEER_SMPS_STATE,
1510 ath10k_smps_map[smps]);
1511}
1512
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513/* can be called only in mac80211 callbacks due to `key_count` usage */
1514static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1515 struct ieee80211_vif *vif,
1516 struct ieee80211_bss_conf *bss_conf)
1517{
1518 struct ath10k *ar = hw->priv;
1519 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001520 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001521 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001522 struct ieee80211_sta *ap_sta;
1523 int ret;
1524
Michal Kazior548db542013-07-05 16:15:15 +03001525 lockdep_assert_held(&ar->conf_mutex);
1526
Michal Kazior077efc82014-10-21 10:10:29 +03001527 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1528 arvif->vdev_id, arvif->bssid, arvif->aid);
1529
Kalle Valo5e3dd152013-06-12 20:52:10 +03001530 rcu_read_lock();
1531
1532 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1533 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001534 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001535 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001536 rcu_read_unlock();
1537 return;
1538 }
1539
Michal Kazior90046f52014-02-14 14:45:51 +01001540 /* ap_sta must be accessed only within rcu section which must be left
1541 * before calling ath10k_setup_peer_smps() which might sleep. */
1542 ht_cap = ap_sta->ht_cap;
1543
Michal Kazior590922a2014-10-21 10:10:29 +03001544 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001545 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001546 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001547 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 rcu_read_unlock();
1549 return;
1550 }
1551
1552 rcu_read_unlock();
1553
Kalle Valob9ada652013-10-16 15:44:46 +03001554 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1555 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001557 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001558 return;
1559 }
1560
Michal Kazior90046f52014-02-14 14:45:51 +01001561 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1562 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001563 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001564 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001565 return;
1566 }
1567
Michal Kazior7aa7a722014-08-25 12:09:38 +02001568 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001569 "mac vdev %d up (associated) bssid %pM aid %d\n",
1570 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1571
Michal Kazior077efc82014-10-21 10:10:29 +03001572 WARN_ON(arvif->is_up);
1573
Michal Kaziorc930f742014-01-23 11:38:25 +01001574 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001575 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001576
1577 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1578 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001579 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001580 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001581 return;
1582 }
1583
1584 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001585}
1586
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1588 struct ieee80211_vif *vif)
1589{
1590 struct ath10k *ar = hw->priv;
1591 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1592 int ret;
1593
Michal Kazior548db542013-07-05 16:15:15 +03001594 lockdep_assert_held(&ar->conf_mutex);
1595
Michal Kazior077efc82014-10-21 10:10:29 +03001596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1597 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001598
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001600 if (ret)
1601 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1602 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001604 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001605 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606}
1607
Michal Kazior590922a2014-10-21 10:10:29 +03001608static int ath10k_station_assoc(struct ath10k *ar,
1609 struct ieee80211_vif *vif,
1610 struct ieee80211_sta *sta,
1611 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612{
Michal Kazior590922a2014-10-21 10:10:29 +03001613 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001614 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 int ret = 0;
1616
Michal Kazior548db542013-07-05 16:15:15 +03001617 lockdep_assert_held(&ar->conf_mutex);
1618
Michal Kazior590922a2014-10-21 10:10:29 +03001619 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001620 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001621 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001622 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001623 return ret;
1624 }
1625
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001626 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001627 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1628 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001629 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001630 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 return ret;
1632 }
1633
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001634 /* Re-assoc is run only to update supported rates for given station. It
1635 * doesn't make much sense to reconfigure the peer completely.
1636 */
1637 if (!reassoc) {
1638 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1639 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001640 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001641 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001642 arvif->vdev_id, ret);
1643 return ret;
1644 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001645
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001646 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1647 if (ret) {
1648 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1649 sta->addr, arvif->vdev_id, ret);
1650 return ret;
1651 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001652
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001653 if (!sta->wme) {
1654 arvif->num_legacy_stations++;
1655 ret = ath10k_recalc_rtscts_prot(arvif);
1656 if (ret) {
1657 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1658 arvif->vdev_id, ret);
1659 return ret;
1660 }
1661 }
1662
1663 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1664 if (ret) {
1665 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666 arvif->vdev_id, ret);
1667 return ret;
1668 }
1669 }
1670
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 return ret;
1672}
1673
Michal Kazior590922a2014-10-21 10:10:29 +03001674static int ath10k_station_disassoc(struct ath10k *ar,
1675 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001676 struct ieee80211_sta *sta)
1677{
Michal Kazior590922a2014-10-21 10:10:29 +03001678 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 int ret = 0;
1680
1681 lockdep_assert_held(&ar->conf_mutex);
1682
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001683 if (!sta->wme) {
1684 arvif->num_legacy_stations--;
1685 ret = ath10k_recalc_rtscts_prot(arvif);
1686 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001687 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001688 arvif->vdev_id, ret);
1689 return ret;
1690 }
1691 }
1692
Kalle Valo5e3dd152013-06-12 20:52:10 +03001693 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1694 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001695 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001696 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 return ret;
1698 }
1699
1700 return ret;
1701}
1702
1703/**************/
1704/* Regulatory */
1705/**************/
1706
1707static int ath10k_update_channel_list(struct ath10k *ar)
1708{
1709 struct ieee80211_hw *hw = ar->hw;
1710 struct ieee80211_supported_band **bands;
1711 enum ieee80211_band band;
1712 struct ieee80211_channel *channel;
1713 struct wmi_scan_chan_list_arg arg = {0};
1714 struct wmi_channel_arg *ch;
1715 bool passive;
1716 int len;
1717 int ret;
1718 int i;
1719
Michal Kazior548db542013-07-05 16:15:15 +03001720 lockdep_assert_held(&ar->conf_mutex);
1721
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722 bands = hw->wiphy->bands;
1723 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1724 if (!bands[band])
1725 continue;
1726
1727 for (i = 0; i < bands[band]->n_channels; i++) {
1728 if (bands[band]->channels[i].flags &
1729 IEEE80211_CHAN_DISABLED)
1730 continue;
1731
1732 arg.n_channels++;
1733 }
1734 }
1735
1736 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1737 arg.channels = kzalloc(len, GFP_KERNEL);
1738 if (!arg.channels)
1739 return -ENOMEM;
1740
1741 ch = arg.channels;
1742 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1743 if (!bands[band])
1744 continue;
1745
1746 for (i = 0; i < bands[band]->n_channels; i++) {
1747 channel = &bands[band]->channels[i];
1748
1749 if (channel->flags & IEEE80211_CHAN_DISABLED)
1750 continue;
1751
1752 ch->allow_ht = true;
1753
1754 /* FIXME: when should we really allow VHT? */
1755 ch->allow_vht = true;
1756
1757 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001758 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759
1760 ch->ht40plus =
1761 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1762
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001763 ch->chan_radar =
1764 !!(channel->flags & IEEE80211_CHAN_RADAR);
1765
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001766 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767 ch->passive = passive;
1768
1769 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001770 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001771 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001772 ch->max_power = channel->max_power * 2;
1773 ch->max_reg_power = channel->max_reg_power * 2;
1774 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001775 ch->reg_class_id = 0; /* FIXME */
1776
1777 /* FIXME: why use only legacy modes, why not any
1778 * HT/VHT modes? Would that even make any
1779 * difference? */
1780 if (channel->band == IEEE80211_BAND_2GHZ)
1781 ch->mode = MODE_11G;
1782 else
1783 ch->mode = MODE_11A;
1784
1785 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1786 continue;
1787
Michal Kazior7aa7a722014-08-25 12:09:38 +02001788 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001789 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1790 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791 ch->freq, ch->max_power, ch->max_reg_power,
1792 ch->max_antenna_gain, ch->mode);
1793
1794 ch++;
1795 }
1796 }
1797
1798 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1799 kfree(arg.channels);
1800
1801 return ret;
1802}
1803
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001804static enum wmi_dfs_region
1805ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1806{
1807 switch (dfs_region) {
1808 case NL80211_DFS_UNSET:
1809 return WMI_UNINIT_DFS_DOMAIN;
1810 case NL80211_DFS_FCC:
1811 return WMI_FCC_DFS_DOMAIN;
1812 case NL80211_DFS_ETSI:
1813 return WMI_ETSI_DFS_DOMAIN;
1814 case NL80211_DFS_JP:
1815 return WMI_MKK4_DFS_DOMAIN;
1816 }
1817 return WMI_UNINIT_DFS_DOMAIN;
1818}
1819
Michal Kaziorf7843d72013-07-16 09:38:52 +02001820static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001821{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001822 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001823 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001824 enum wmi_dfs_region wmi_dfs_reg;
1825 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001826
Michal Kaziorf7843d72013-07-16 09:38:52 +02001827 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001828
1829 ret = ath10k_update_channel_list(ar);
1830 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001831 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001832
1833 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001834
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001835 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1836 nl_dfs_reg = ar->dfs_detector->region;
1837 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1838 } else {
1839 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1840 }
1841
Kalle Valo5e3dd152013-06-12 20:52:10 +03001842 /* Target allows setting up per-band regdomain but ath_common provides
1843 * a combined one only */
1844 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001845 regpair->reg_domain,
1846 regpair->reg_domain, /* 2ghz */
1847 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001849 regpair->reg_5ghz_ctl,
1850 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001852 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001853}
Michal Kazior548db542013-07-05 16:15:15 +03001854
Michal Kaziorf7843d72013-07-16 09:38:52 +02001855static void ath10k_reg_notifier(struct wiphy *wiphy,
1856 struct regulatory_request *request)
1857{
1858 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1859 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001860 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001861
1862 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1863
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001864 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001865 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001866 request->dfs_region);
1867 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1868 request->dfs_region);
1869 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001870 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001871 request->dfs_region);
1872 }
1873
Michal Kaziorf7843d72013-07-16 09:38:52 +02001874 mutex_lock(&ar->conf_mutex);
1875 if (ar->state == ATH10K_STATE_ON)
1876 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001877 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878}
1879
1880/***************/
1881/* TX handlers */
1882/***************/
1883
Michal Kazior42c3aa62013-10-02 11:03:38 +02001884static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1885{
1886 if (ieee80211_is_mgmt(hdr->frame_control))
1887 return HTT_DATA_TX_EXT_TID_MGMT;
1888
1889 if (!ieee80211_is_data_qos(hdr->frame_control))
1890 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1891
1892 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1893 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1894
1895 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1896}
1897
Michal Kazior2b37c292014-09-02 11:00:22 +03001898static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001899{
Michal Kazior2b37c292014-09-02 11:00:22 +03001900 if (vif)
1901 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001902
Michal Kazior1bbc0972014-04-08 09:45:47 +03001903 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001904 return ar->monitor_vdev_id;
1905
Michal Kazior7aa7a722014-08-25 12:09:38 +02001906 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001907 return 0;
1908}
1909
Michal Kazior4b604552014-07-21 21:03:09 +03001910/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1911 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001912 */
Michal Kazior4b604552014-07-21 21:03:09 +03001913static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001914{
1915 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001916 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001917 u8 *qos_ctl;
1918
1919 if (!ieee80211_is_data_qos(hdr->frame_control))
1920 return;
1921
1922 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001923 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1924 skb->data, (void *)qos_ctl - (void *)skb->data);
1925 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001926
1927 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1928 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1929 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1930 * it is safe to downgrade to NullFunc.
1931 */
1932 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1933 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1934 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1935 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001936}
1937
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001938static void ath10k_tx_wep_key_work(struct work_struct *work)
1939{
1940 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1941 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001942 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001943 int ret, keyidx = arvif->def_wep_key_newidx;
1944
Michal Kazior911e6c02014-05-26 12:46:03 +03001945 mutex_lock(&arvif->ar->conf_mutex);
1946
1947 if (arvif->ar->state != ATH10K_STATE_ON)
1948 goto unlock;
1949
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001950 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001951 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001952
Michal Kazior7aa7a722014-08-25 12:09:38 +02001953 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001954 arvif->vdev_id, keyidx);
1955
1956 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1957 arvif->vdev_id,
1958 arvif->ar->wmi.vdev_param->def_keyid,
1959 keyidx);
1960 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001961 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001962 arvif->vdev_id,
1963 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001964 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001965 }
1966
1967 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001968
1969unlock:
1970 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001971}
1972
Michal Kazior4b604552014-07-21 21:03:09 +03001973static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1974 struct ieee80211_key_conf *key,
1975 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001977 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1978 struct ath10k *ar = arvif->ar;
1979 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981 if (!ieee80211_has_protected(hdr->frame_control))
1982 return;
1983
1984 if (!key)
1985 return;
1986
1987 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1988 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1989 return;
1990
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001991 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992 return;
1993
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001994 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1995 * queueing frames until key index is updated is not an option because
1996 * sk_buff may need more processing to be done, e.g. offchannel */
1997 arvif->def_wep_key_newidx = key->keyidx;
1998 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999}
2000
Michal Kazior4b604552014-07-21 21:03:09 +03002001static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2002 struct ieee80211_vif *vif,
2003 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004{
2005 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2007
2008 /* This is case only for P2P_GO */
2009 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2010 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2011 return;
2012
2013 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2014 spin_lock_bh(&ar->data_lock);
2015 if (arvif->u.ap.noa_data)
2016 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2017 GFP_ATOMIC))
2018 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2019 arvif->u.ap.noa_data,
2020 arvif->u.ap.noa_len);
2021 spin_unlock_bh(&ar->data_lock);
2022 }
2023}
2024
Michal Kazior8d6d3622014-11-24 14:58:31 +01002025static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2026{
2027 /* FIXME: Not really sure since when the behaviour changed. At some
2028 * point new firmware stopped requiring creation of peer entries for
2029 * offchannel tx (and actually creating them causes issues with wmi-htc
2030 * tx credit replenishment and reliability). Assuming it's at least 3.4
2031 * because that's when the `freq` was introduced to TX_FRM HTT command.
2032 */
2033 return !(ar->htt.target_version_major >= 3 &&
2034 ar->htt.target_version_minor >= 4);
2035}
2036
Kalle Valo5e3dd152013-06-12 20:52:10 +03002037static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2038{
2039 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002040 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002041
Michal Kazior961d4c32013-08-09 10:13:34 +02002042 if (ar->htt.target_version_major >= 3) {
2043 /* Since HTT 3.0 there is no separate mgmt tx command */
2044 ret = ath10k_htt_tx(&ar->htt, skb);
2045 goto exit;
2046 }
2047
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002048 if (ieee80211_is_mgmt(hdr->frame_control)) {
2049 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2050 ar->fw_features)) {
2051 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2052 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002053 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002054 ret = -EBUSY;
2055 goto exit;
2056 }
2057
2058 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2059 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2060 } else {
2061 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2062 }
2063 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2064 ar->fw_features) &&
2065 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002066 /* FW does not report tx status properly for NullFunc frames
2067 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002068 * those frames when it detects link/beacon loss and depends
2069 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002070 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002071 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002072 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002073 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074
Michal Kazior961d4c32013-08-09 10:13:34 +02002075exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002076 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002077 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2078 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079 ieee80211_free_txskb(ar->hw, skb);
2080 }
2081}
2082
2083void ath10k_offchan_tx_purge(struct ath10k *ar)
2084{
2085 struct sk_buff *skb;
2086
2087 for (;;) {
2088 skb = skb_dequeue(&ar->offchan_tx_queue);
2089 if (!skb)
2090 break;
2091
2092 ieee80211_free_txskb(ar->hw, skb);
2093 }
2094}
2095
2096void ath10k_offchan_tx_work(struct work_struct *work)
2097{
2098 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2099 struct ath10k_peer *peer;
2100 struct ieee80211_hdr *hdr;
2101 struct sk_buff *skb;
2102 const u8 *peer_addr;
2103 int vdev_id;
2104 int ret;
2105
2106 /* FW requirement: We must create a peer before FW will send out
2107 * an offchannel frame. Otherwise the frame will be stuck and
2108 * never transmitted. We delete the peer upon tx completion.
2109 * It is unlikely that a peer for offchannel tx will already be
2110 * present. However it may be in some rare cases so account for that.
2111 * Otherwise we might remove a legitimate peer and break stuff. */
2112
2113 for (;;) {
2114 skb = skb_dequeue(&ar->offchan_tx_queue);
2115 if (!skb)
2116 break;
2117
2118 mutex_lock(&ar->conf_mutex);
2119
Michal Kazior7aa7a722014-08-25 12:09:38 +02002120 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002121 skb);
2122
2123 hdr = (struct ieee80211_hdr *)skb->data;
2124 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002125 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126
2127 spin_lock_bh(&ar->data_lock);
2128 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2129 spin_unlock_bh(&ar->data_lock);
2130
2131 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002132 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002133 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002134 peer_addr, vdev_id);
2135
2136 if (!peer) {
2137 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2138 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002139 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002140 peer_addr, vdev_id, ret);
2141 }
2142
2143 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002144 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002145 ar->offchan_tx_skb = skb;
2146 spin_unlock_bh(&ar->data_lock);
2147
2148 ath10k_tx_htt(ar, skb);
2149
2150 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2151 3 * HZ);
2152 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002153 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002154 skb);
2155
2156 if (!peer) {
2157 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2158 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002159 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002160 peer_addr, vdev_id, ret);
2161 }
2162
2163 mutex_unlock(&ar->conf_mutex);
2164 }
2165}
2166
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002167void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2168{
2169 struct sk_buff *skb;
2170
2171 for (;;) {
2172 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2173 if (!skb)
2174 break;
2175
2176 ieee80211_free_txskb(ar->hw, skb);
2177 }
2178}
2179
2180void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2181{
2182 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2183 struct sk_buff *skb;
2184 int ret;
2185
2186 for (;;) {
2187 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2188 if (!skb)
2189 break;
2190
2191 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002192 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002193 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002194 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002195 ieee80211_free_txskb(ar->hw, skb);
2196 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002197 }
2198}
2199
Kalle Valo5e3dd152013-06-12 20:52:10 +03002200/************/
2201/* Scanning */
2202/************/
2203
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002204void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002206 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002207
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002208 switch (ar->scan.state) {
2209 case ATH10K_SCAN_IDLE:
2210 break;
2211 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002212 if (ar->scan.is_roc)
2213 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior7305d3e2014-11-24 14:58:33 +01002214 case ATH10K_SCAN_ABORTING:
2215 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002216 ieee80211_scan_completed(ar->hw,
2217 (ar->scan.state ==
2218 ATH10K_SCAN_ABORTING));
2219 /* fall through */
2220 case ATH10K_SCAN_STARTING:
2221 ar->scan.state = ATH10K_SCAN_IDLE;
2222 ar->scan_channel = NULL;
2223 ath10k_offchan_tx_purge(ar);
2224 cancel_delayed_work(&ar->scan.timeout);
2225 complete_all(&ar->scan.completed);
2226 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002227 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002228}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002229
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002230void ath10k_scan_finish(struct ath10k *ar)
2231{
2232 spin_lock_bh(&ar->data_lock);
2233 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002234 spin_unlock_bh(&ar->data_lock);
2235}
2236
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002237static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238{
2239 struct wmi_stop_scan_arg arg = {
2240 .req_id = 1, /* FIXME */
2241 .req_type = WMI_SCAN_STOP_ONE,
2242 .u.scan_id = ATH10K_SCAN_ID,
2243 };
2244 int ret;
2245
2246 lockdep_assert_held(&ar->conf_mutex);
2247
Kalle Valo5e3dd152013-06-12 20:52:10 +03002248 ret = ath10k_wmi_stop_scan(ar, &arg);
2249 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002250 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002251 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002252 }
2253
Kalle Valo5e3dd152013-06-12 20:52:10 +03002254 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002255 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002256 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002257 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002258 } else if (ret > 0) {
2259 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002260 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002261
2262out:
2263 /* Scan state should be updated upon scan completion but in case
2264 * firmware fails to deliver the event (for whatever reason) it is
2265 * desired to clean up scan state anyway. Firmware may have just
2266 * dropped the scan completion event delivery due to transport pipe
2267 * being overflown with data and/or it can recover on its own before
2268 * next scan request is submitted.
2269 */
2270 spin_lock_bh(&ar->data_lock);
2271 if (ar->scan.state != ATH10K_SCAN_IDLE)
2272 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002273 spin_unlock_bh(&ar->data_lock);
2274
2275 return ret;
2276}
2277
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002278static void ath10k_scan_abort(struct ath10k *ar)
2279{
2280 int ret;
2281
2282 lockdep_assert_held(&ar->conf_mutex);
2283
2284 spin_lock_bh(&ar->data_lock);
2285
2286 switch (ar->scan.state) {
2287 case ATH10K_SCAN_IDLE:
2288 /* This can happen if timeout worker kicked in and called
2289 * abortion while scan completion was being processed.
2290 */
2291 break;
2292 case ATH10K_SCAN_STARTING:
2293 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002294 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002295 ath10k_scan_state_str(ar->scan.state),
2296 ar->scan.state);
2297 break;
2298 case ATH10K_SCAN_RUNNING:
2299 ar->scan.state = ATH10K_SCAN_ABORTING;
2300 spin_unlock_bh(&ar->data_lock);
2301
2302 ret = ath10k_scan_stop(ar);
2303 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002304 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002305
2306 spin_lock_bh(&ar->data_lock);
2307 break;
2308 }
2309
2310 spin_unlock_bh(&ar->data_lock);
2311}
2312
2313void ath10k_scan_timeout_work(struct work_struct *work)
2314{
2315 struct ath10k *ar = container_of(work, struct ath10k,
2316 scan.timeout.work);
2317
2318 mutex_lock(&ar->conf_mutex);
2319 ath10k_scan_abort(ar);
2320 mutex_unlock(&ar->conf_mutex);
2321}
2322
Kalle Valo5e3dd152013-06-12 20:52:10 +03002323static int ath10k_start_scan(struct ath10k *ar,
2324 const struct wmi_start_scan_arg *arg)
2325{
2326 int ret;
2327
2328 lockdep_assert_held(&ar->conf_mutex);
2329
2330 ret = ath10k_wmi_start_scan(ar, arg);
2331 if (ret)
2332 return ret;
2333
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2335 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002336 ret = ath10k_scan_stop(ar);
2337 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002338 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002339
2340 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341 }
2342
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002343 /* Add a 200ms margin to account for event/command processing */
2344 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2345 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 return 0;
2347}
2348
2349/**********************/
2350/* mac80211 callbacks */
2351/**********************/
2352
2353static void ath10k_tx(struct ieee80211_hw *hw,
2354 struct ieee80211_tx_control *control,
2355 struct sk_buff *skb)
2356{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002358 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2359 struct ieee80211_vif *vif = info->control.vif;
2360 struct ieee80211_key_conf *key = info->control.hw_key;
2361 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362
2363 /* We should disable CCK RATE due to P2P */
2364 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002365 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366
Michal Kazior4b604552014-07-21 21:03:09 +03002367 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2368 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002369 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002371 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002372 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2373 ath10k_tx_h_nwifi(hw, skb);
2374 ath10k_tx_h_update_wep_key(vif, key, skb);
2375 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2376 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002377 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378
Kalle Valo5e3dd152013-06-12 20:52:10 +03002379 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2380 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002381 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002382 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002383 spin_unlock_bh(&ar->data_lock);
2384
Michal Kazior8d6d3622014-11-24 14:58:31 +01002385 if (ath10k_mac_need_offchan_tx_work(ar)) {
2386 ATH10K_SKB_CB(skb)->htt.freq = 0;
2387 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002388
Michal Kazior8d6d3622014-11-24 14:58:31 +01002389 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2390 skb);
2391
2392 skb_queue_tail(&ar->offchan_tx_queue, skb);
2393 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2394 return;
2395 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002396 }
2397
2398 ath10k_tx_htt(ar, skb);
2399}
2400
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002401/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002402void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002403{
2404 /* make sure rcu-protected mac80211 tx path itself is drained */
2405 synchronize_net();
2406
2407 ath10k_offchan_tx_purge(ar);
2408 ath10k_mgmt_over_wmi_tx_purge(ar);
2409
2410 cancel_work_sync(&ar->offchan_tx_work);
2411 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2412}
2413
Michal Kazioraffd3212013-07-16 09:54:35 +02002414void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002415{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002416 struct ath10k_vif *arvif;
2417
Michal Kazior818bdd12013-07-16 09:38:57 +02002418 lockdep_assert_held(&ar->conf_mutex);
2419
Michal Kazior19337472014-08-28 12:58:16 +02002420 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2421 ar->filter_flags = 0;
2422 ar->monitor = false;
2423
2424 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002425 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002426
2427 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002428
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002429 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002430 ath10k_peer_cleanup_all(ar);
2431 ath10k_core_stop(ar);
2432 ath10k_hif_power_down(ar);
2433
2434 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002435 list_for_each_entry(arvif, &ar->arvifs, list)
2436 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002437 spin_unlock_bh(&ar->data_lock);
2438}
2439
Ben Greear46acf7b2014-05-16 17:15:38 +03002440static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2441{
2442 struct ath10k *ar = hw->priv;
2443
2444 mutex_lock(&ar->conf_mutex);
2445
2446 if (ar->cfg_tx_chainmask) {
2447 *tx_ant = ar->cfg_tx_chainmask;
2448 *rx_ant = ar->cfg_rx_chainmask;
2449 } else {
2450 *tx_ant = ar->supp_tx_chainmask;
2451 *rx_ant = ar->supp_rx_chainmask;
2452 }
2453
2454 mutex_unlock(&ar->conf_mutex);
2455
2456 return 0;
2457}
2458
Ben Greear5572a952014-11-24 16:22:10 +02002459static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2460{
2461 /* It is not clear that allowing gaps in chainmask
2462 * is helpful. Probably it will not do what user
2463 * is hoping for, so warn in that case.
2464 */
2465 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2466 return;
2467
2468 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2469 dbg, cm);
2470}
2471
Ben Greear46acf7b2014-05-16 17:15:38 +03002472static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2473{
2474 int ret;
2475
2476 lockdep_assert_held(&ar->conf_mutex);
2477
Ben Greear5572a952014-11-24 16:22:10 +02002478 ath10k_check_chain_mask(ar, tx_ant, "tx");
2479 ath10k_check_chain_mask(ar, rx_ant, "rx");
2480
Ben Greear46acf7b2014-05-16 17:15:38 +03002481 ar->cfg_tx_chainmask = tx_ant;
2482 ar->cfg_rx_chainmask = rx_ant;
2483
2484 if ((ar->state != ATH10K_STATE_ON) &&
2485 (ar->state != ATH10K_STATE_RESTARTED))
2486 return 0;
2487
2488 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2489 tx_ant);
2490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002491 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002492 ret, tx_ant);
2493 return ret;
2494 }
2495
2496 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2497 rx_ant);
2498 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002499 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002500 ret, rx_ant);
2501 return ret;
2502 }
2503
2504 return 0;
2505}
2506
2507static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2508{
2509 struct ath10k *ar = hw->priv;
2510 int ret;
2511
2512 mutex_lock(&ar->conf_mutex);
2513 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2514 mutex_unlock(&ar->conf_mutex);
2515 return ret;
2516}
2517
Kalle Valo5e3dd152013-06-12 20:52:10 +03002518static int ath10k_start(struct ieee80211_hw *hw)
2519{
2520 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002521 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002522
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002523 /*
2524 * This makes sense only when restarting hw. It is harmless to call
2525 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2526 * commands will be submitted while restarting.
2527 */
2528 ath10k_drain_tx(ar);
2529
Michal Kazior548db542013-07-05 16:15:15 +03002530 mutex_lock(&ar->conf_mutex);
2531
Michal Kaziorc5058f52014-05-26 12:46:03 +03002532 switch (ar->state) {
2533 case ATH10K_STATE_OFF:
2534 ar->state = ATH10K_STATE_ON;
2535 break;
2536 case ATH10K_STATE_RESTARTING:
2537 ath10k_halt(ar);
2538 ar->state = ATH10K_STATE_RESTARTED;
2539 break;
2540 case ATH10K_STATE_ON:
2541 case ATH10K_STATE_RESTARTED:
2542 case ATH10K_STATE_WEDGED:
2543 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002544 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002545 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002546 case ATH10K_STATE_UTF:
2547 ret = -EBUSY;
2548 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002549 }
2550
2551 ret = ath10k_hif_power_up(ar);
2552 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002553 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002554 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002555 }
2556
Kalle Valo43d2a302014-09-10 18:23:30 +03002557 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002558 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002559 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002560 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002561 }
2562
Bartosz Markowski226a3392013-09-26 17:47:16 +02002563 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002564 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002565 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002566 goto err_core_stop;
2567 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002569 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002570 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002571 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002572 goto err_core_stop;
2573 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574
Ben Greear46acf7b2014-05-16 17:15:38 +03002575 if (ar->cfg_tx_chainmask)
2576 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2577 ar->cfg_rx_chainmask);
2578
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002579 /*
2580 * By default FW set ARP frames ac to voice (6). In that case ARP
2581 * exchange is not working properly for UAPSD enabled AP. ARP requests
2582 * which arrives with access category 0 are processed by network stack
2583 * and send back with access category 0, but FW changes access category
2584 * to 6. Set ARP frames access category to best effort (0) solves
2585 * this problem.
2586 */
2587
2588 ret = ath10k_wmi_pdev_set_param(ar,
2589 ar->wmi.pdev_param->arp_ac_override, 0);
2590 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002591 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002592 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002593 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002594 }
2595
Michal Kaziord6500972014-04-08 09:56:09 +03002596 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002597 ath10k_regd_update(ar);
2598
Simon Wunderlich855aed12014-08-02 09:12:54 +03002599 ath10k_spectral_start(ar);
2600
Michal Kaziorae254432014-05-26 12:46:02 +03002601 mutex_unlock(&ar->conf_mutex);
2602 return 0;
2603
2604err_core_stop:
2605 ath10k_core_stop(ar);
2606
2607err_power_down:
2608 ath10k_hif_power_down(ar);
2609
2610err_off:
2611 ar->state = ATH10K_STATE_OFF;
2612
2613err:
Michal Kazior548db542013-07-05 16:15:15 +03002614 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002615 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002616}
2617
2618static void ath10k_stop(struct ieee80211_hw *hw)
2619{
2620 struct ath10k *ar = hw->priv;
2621
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002622 ath10k_drain_tx(ar);
2623
Michal Kazior548db542013-07-05 16:15:15 +03002624 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002625 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002626 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002627 ar->state = ATH10K_STATE_OFF;
2628 }
Michal Kazior548db542013-07-05 16:15:15 +03002629 mutex_unlock(&ar->conf_mutex);
2630
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002631 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002632 cancel_work_sync(&ar->restart_work);
2633}
2634
Michal Kaziorad088bf2013-10-16 15:44:46 +03002635static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002636{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002637 struct ath10k_vif *arvif;
2638 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002639
2640 lockdep_assert_held(&ar->conf_mutex);
2641
Michal Kaziorad088bf2013-10-16 15:44:46 +03002642 list_for_each_entry(arvif, &ar->arvifs, list) {
2643 ret = ath10k_mac_vif_setup_ps(arvif);
2644 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002645 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002646 break;
2647 }
2648 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002649
Michal Kaziorad088bf2013-10-16 15:44:46 +03002650 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002651}
2652
Michal Kaziorc930f742014-01-23 11:38:25 +01002653static const char *chandef_get_width(enum nl80211_chan_width width)
2654{
2655 switch (width) {
2656 case NL80211_CHAN_WIDTH_20_NOHT:
2657 return "20 (noht)";
2658 case NL80211_CHAN_WIDTH_20:
2659 return "20";
2660 case NL80211_CHAN_WIDTH_40:
2661 return "40";
2662 case NL80211_CHAN_WIDTH_80:
2663 return "80";
2664 case NL80211_CHAN_WIDTH_80P80:
2665 return "80+80";
2666 case NL80211_CHAN_WIDTH_160:
2667 return "160";
2668 case NL80211_CHAN_WIDTH_5:
2669 return "5";
2670 case NL80211_CHAN_WIDTH_10:
2671 return "10";
2672 }
2673 return "?";
2674}
2675
2676static void ath10k_config_chan(struct ath10k *ar)
2677{
2678 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002679 int ret;
2680
2681 lockdep_assert_held(&ar->conf_mutex);
2682
Michal Kazior7aa7a722014-08-25 12:09:38 +02002683 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002684 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2685 ar->chandef.chan->center_freq,
2686 ar->chandef.center_freq1,
2687 ar->chandef.center_freq2,
2688 chandef_get_width(ar->chandef.width));
2689
2690 /* First stop monitor interface. Some FW versions crash if there's a
2691 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002692 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002693 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002694
2695 list_for_each_entry(arvif, &ar->arvifs, list) {
2696 if (!arvif->is_started)
2697 continue;
2698
Michal Kaziordc55e302014-07-29 12:53:36 +03002699 if (!arvif->is_up)
2700 continue;
2701
Michal Kaziorc930f742014-01-23 11:38:25 +01002702 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2703 continue;
2704
Michal Kaziordc55e302014-07-29 12:53:36 +03002705 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002706 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002707 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002708 arvif->vdev_id, ret);
2709 continue;
2710 }
2711 }
2712
Michal Kaziordc55e302014-07-29 12:53:36 +03002713 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002714
2715 list_for_each_entry(arvif, &ar->arvifs, list) {
2716 if (!arvif->is_started)
2717 continue;
2718
2719 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2720 continue;
2721
Michal Kaziordc55e302014-07-29 12:53:36 +03002722 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002723 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002724 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002725 arvif->vdev_id, ret);
2726 continue;
2727 }
2728
2729 if (!arvif->is_up)
2730 continue;
2731
2732 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2733 arvif->bssid);
2734 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002735 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002736 arvif->vdev_id, ret);
2737 continue;
2738 }
2739 }
2740
Michal Kazior19337472014-08-28 12:58:16 +02002741 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002742}
2743
Michal Kazior7d9d5582014-10-21 10:40:15 +03002744static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2745{
2746 int ret;
2747 u32 param;
2748
2749 lockdep_assert_held(&ar->conf_mutex);
2750
2751 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2752
2753 param = ar->wmi.pdev_param->txpower_limit2g;
2754 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2755 if (ret) {
2756 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2757 txpower, ret);
2758 return ret;
2759 }
2760
2761 param = ar->wmi.pdev_param->txpower_limit5g;
2762 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2763 if (ret) {
2764 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2765 txpower, ret);
2766 return ret;
2767 }
2768
2769 return 0;
2770}
2771
2772static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2773{
2774 struct ath10k_vif *arvif;
2775 int ret, txpower = -1;
2776
2777 lockdep_assert_held(&ar->conf_mutex);
2778
2779 list_for_each_entry(arvif, &ar->arvifs, list) {
2780 WARN_ON(arvif->txpower < 0);
2781
2782 if (txpower == -1)
2783 txpower = arvif->txpower;
2784 else
2785 txpower = min(txpower, arvif->txpower);
2786 }
2787
2788 if (WARN_ON(txpower == -1))
2789 return -EINVAL;
2790
2791 ret = ath10k_mac_txpower_setup(ar, txpower);
2792 if (ret) {
2793 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2794 txpower, ret);
2795 return ret;
2796 }
2797
2798 return 0;
2799}
2800
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2802{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803 struct ath10k *ar = hw->priv;
2804 struct ieee80211_conf *conf = &hw->conf;
2805 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002806
2807 mutex_lock(&ar->conf_mutex);
2808
2809 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002810 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002811 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002812 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002813 conf->chandef.chan->flags,
2814 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002815
Kalle Valo5e3dd152013-06-12 20:52:10 +03002816 spin_lock_bh(&ar->data_lock);
2817 ar->rx_channel = conf->chandef.chan;
2818 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002819
Michal Kaziord6500972014-04-08 09:56:09 +03002820 ar->radar_enabled = conf->radar_enabled;
2821 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002822
2823 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2824 ar->chandef = conf->chandef;
2825 ath10k_config_chan(ar);
2826 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002827 }
2828
Michal Kazioraffd3212013-07-16 09:54:35 +02002829 if (changed & IEEE80211_CONF_CHANGE_PS)
2830 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002831
2832 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002833 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2834 ret = ath10k_monitor_recalc(ar);
2835 if (ret)
2836 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002837 }
2838
2839 mutex_unlock(&ar->conf_mutex);
2840 return ret;
2841}
2842
Ben Greear5572a952014-11-24 16:22:10 +02002843static u32 get_nss_from_chainmask(u16 chain_mask)
2844{
2845 if ((chain_mask & 0x15) == 0x15)
2846 return 4;
2847 else if ((chain_mask & 0x7) == 0x7)
2848 return 3;
2849 else if ((chain_mask & 0x3) == 0x3)
2850 return 2;
2851 return 1;
2852}
2853
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854/*
2855 * TODO:
2856 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2857 * because we will send mgmt frames without CCK. This requirement
2858 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2859 * in the TX packet.
2860 */
2861static int ath10k_add_interface(struct ieee80211_hw *hw,
2862 struct ieee80211_vif *vif)
2863{
2864 struct ath10k *ar = hw->priv;
2865 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2866 enum wmi_sta_powersave_param param;
2867 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002868 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002870 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002871
2872 mutex_lock(&ar->conf_mutex);
2873
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002874 memset(arvif, 0, sizeof(*arvif));
2875
Kalle Valo5e3dd152013-06-12 20:52:10 +03002876 arvif->ar = ar;
2877 arvif->vif = vif;
2878
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002879 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002880 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002881
Ben Greeara9aefb32014-08-12 11:02:19 +03002882 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002883 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002884 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002885 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002886 }
Ben Greear16c11172014-09-23 14:17:16 -07002887 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002888
Ben Greear16c11172014-09-23 14:17:16 -07002889 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2890 bit, ar->free_vdev_map);
2891
2892 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002894
2895 if (ar->p2p)
2896 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2897
2898 switch (vif->type) {
2899 case NL80211_IFTYPE_UNSPECIFIED:
2900 case NL80211_IFTYPE_STATION:
2901 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2902 if (vif->p2p)
2903 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2904 break;
2905 case NL80211_IFTYPE_ADHOC:
2906 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2907 break;
2908 case NL80211_IFTYPE_AP:
2909 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2910
2911 if (vif->p2p)
2912 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2913 break;
2914 case NL80211_IFTYPE_MONITOR:
2915 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2916 break;
2917 default:
2918 WARN_ON(1);
2919 break;
2920 }
2921
Michal Kazior64badcb2014-09-18 11:18:02 +03002922 /* Some firmware revisions don't wait for beacon tx completion before
2923 * sending another SWBA event. This could lead to hardware using old
2924 * (freed) beacon data in some cases, e.g. tx credit starvation
2925 * combined with missed TBTT. This is very very rare.
2926 *
2927 * On non-IOMMU-enabled hosts this could be a possible security issue
2928 * because hw could beacon some random data on the air. On
2929 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2930 * device would crash.
2931 *
2932 * Since there are no beacon tx completions (implicit nor explicit)
2933 * propagated to host the only workaround for this is to allocate a
2934 * DMA-coherent buffer for a lifetime of a vif and use it for all
2935 * beacon tx commands. Worst case for this approach is some beacons may
2936 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2937 */
2938 if (vif->type == NL80211_IFTYPE_ADHOC ||
2939 vif->type == NL80211_IFTYPE_AP) {
2940 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2941 IEEE80211_MAX_FRAME_LEN,
2942 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05302943 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03002944 if (!arvif->beacon_buf) {
2945 ret = -ENOMEM;
2946 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2947 ret);
2948 goto err;
2949 }
2950 }
2951
2952 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2953 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2954 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955
2956 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2957 arvif->vdev_subtype, vif->addr);
2958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002959 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002960 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002961 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002962 }
2963
Ben Greear16c11172014-09-23 14:17:16 -07002964 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002965 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002966
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002967 vdev_param = ar->wmi.vdev_param->def_keyid;
2968 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002969 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002971 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002972 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002973 goto err_vdev_delete;
2974 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002975
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002976 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2977 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002978 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002979 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002980 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002981 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002982 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002983 goto err_vdev_delete;
2984 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002985
Ben Greear5572a952014-11-24 16:22:10 +02002986 if (ar->cfg_tx_chainmask) {
2987 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
2988
2989 vdev_param = ar->wmi.vdev_param->nss;
2990 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2991 nss);
2992 if (ret) {
2993 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
2994 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
2995 ret);
2996 goto err_vdev_delete;
2997 }
2998 }
2999
Kalle Valo5e3dd152013-06-12 20:52:10 +03003000 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3001 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3002 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003003 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003004 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003005 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003006 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003007
Kalle Valo5a13e762014-01-20 11:01:46 +02003008 ret = ath10k_mac_set_kickout(arvif);
3009 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003010 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003011 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003012 goto err_peer_delete;
3013 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003014 }
3015
3016 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3017 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3018 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3019 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3020 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003021 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003022 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003023 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003024 goto err_peer_delete;
3025 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003026
3027 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
3028 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
3029 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3030 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003031 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003032 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003033 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003034 goto err_peer_delete;
3035 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036
3037 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
3038 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
3039 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3040 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003041 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003042 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003043 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003044 goto err_peer_delete;
3045 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003046 }
3047
Michal Kazior424121c2013-07-22 14:13:31 +02003048 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003049 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003050 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003051 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003052 goto err_peer_delete;
3053 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003054
Michal Kazior424121c2013-07-22 14:13:31 +02003055 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003056 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003057 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003058 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003059 goto err_peer_delete;
3060 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003061
Michal Kazior7d9d5582014-10-21 10:40:15 +03003062 arvif->txpower = vif->bss_conf.txpower;
3063 ret = ath10k_mac_txpower_recalc(ar);
3064 if (ret) {
3065 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3066 goto err_peer_delete;
3067 }
3068
Kalle Valo5e3dd152013-06-12 20:52:10 +03003069 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003070 return 0;
3071
3072err_peer_delete:
3073 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3074 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3075
3076err_vdev_delete:
3077 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003078 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003079 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003080
3081err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003082 if (arvif->beacon_buf) {
3083 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3084 arvif->beacon_buf, arvif->beacon_paddr);
3085 arvif->beacon_buf = NULL;
3086 }
3087
Michal Kazior9dad14a2013-10-16 15:44:45 +03003088 mutex_unlock(&ar->conf_mutex);
3089
Kalle Valo5e3dd152013-06-12 20:52:10 +03003090 return ret;
3091}
3092
3093static void ath10k_remove_interface(struct ieee80211_hw *hw,
3094 struct ieee80211_vif *vif)
3095{
3096 struct ath10k *ar = hw->priv;
3097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3098 int ret;
3099
3100 mutex_lock(&ar->conf_mutex);
3101
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003102 cancel_work_sync(&arvif->wep_key_work);
3103
Michal Kaziored543882013-09-13 14:16:56 +02003104 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003105 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003106 spin_unlock_bh(&ar->data_lock);
3107
Simon Wunderlich855aed12014-08-02 09:12:54 +03003108 ret = ath10k_spectral_vif_stop(arvif);
3109 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003110 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003111 arvif->vdev_id, ret);
3112
Ben Greear16c11172014-09-23 14:17:16 -07003113 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003114 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115
3116 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3117 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3118 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003119 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003120 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003121
3122 kfree(arvif->u.ap.noa_data);
3123 }
3124
Michal Kazior7aa7a722014-08-25 12:09:38 +02003125 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003126 arvif->vdev_id);
3127
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3129 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003130 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003131 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132
Kalle Valo5e3dd152013-06-12 20:52:10 +03003133 ath10k_peer_cleanup(ar, arvif->vdev_id);
3134
3135 mutex_unlock(&ar->conf_mutex);
3136}
3137
3138/*
3139 * FIXME: Has to be verified.
3140 */
3141#define SUPPORTED_FILTERS \
3142 (FIF_PROMISC_IN_BSS | \
3143 FIF_ALLMULTI | \
3144 FIF_CONTROL | \
3145 FIF_PSPOLL | \
3146 FIF_OTHER_BSS | \
3147 FIF_BCN_PRBRESP_PROMISC | \
3148 FIF_PROBE_REQ | \
3149 FIF_FCSFAIL)
3150
3151static void ath10k_configure_filter(struct ieee80211_hw *hw,
3152 unsigned int changed_flags,
3153 unsigned int *total_flags,
3154 u64 multicast)
3155{
3156 struct ath10k *ar = hw->priv;
3157 int ret;
3158
3159 mutex_lock(&ar->conf_mutex);
3160
3161 changed_flags &= SUPPORTED_FILTERS;
3162 *total_flags &= SUPPORTED_FILTERS;
3163 ar->filter_flags = *total_flags;
3164
Michal Kazior19337472014-08-28 12:58:16 +02003165 ret = ath10k_monitor_recalc(ar);
3166 if (ret)
3167 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168
3169 mutex_unlock(&ar->conf_mutex);
3170}
3171
3172static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3173 struct ieee80211_vif *vif,
3174 struct ieee80211_bss_conf *info,
3175 u32 changed)
3176{
3177 struct ath10k *ar = hw->priv;
3178 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3179 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003180 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181
3182 mutex_lock(&ar->conf_mutex);
3183
3184 if (changed & BSS_CHANGED_IBSS)
3185 ath10k_control_ibss(arvif, info, vif->addr);
3186
3187 if (changed & BSS_CHANGED_BEACON_INT) {
3188 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003189 vdev_param = ar->wmi.vdev_param->beacon_interval;
3190 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003191 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003192 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003193 "mac vdev %d beacon_interval %d\n",
3194 arvif->vdev_id, arvif->beacon_interval);
3195
Kalle Valo5e3dd152013-06-12 20:52:10 +03003196 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003197 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003198 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003199 }
3200
3201 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003202 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003203 "vdev %d set beacon tx mode to staggered\n",
3204 arvif->vdev_id);
3205
Bartosz Markowski226a3392013-09-26 17:47:16 +02003206 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3207 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 WMI_BEACON_STAGGERED_MODE);
3209 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003210 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003211 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212 }
3213
John W. Linvilleb70727e2013-06-13 13:34:29 -04003214 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003215 arvif->dtim_period = info->dtim_period;
3216
Michal Kazior7aa7a722014-08-25 12:09:38 +02003217 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003218 "mac vdev %d dtim_period %d\n",
3219 arvif->vdev_id, arvif->dtim_period);
3220
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003221 vdev_param = ar->wmi.vdev_param->dtim_period;
3222 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003223 arvif->dtim_period);
3224 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003225 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003226 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003227 }
3228
3229 if (changed & BSS_CHANGED_SSID &&
3230 vif->type == NL80211_IFTYPE_AP) {
3231 arvif->u.ap.ssid_len = info->ssid_len;
3232 if (info->ssid_len)
3233 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3234 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3235 }
3236
Michal Kazior077efc82014-10-21 10:10:29 +03003237 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3238 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003239
3240 if (changed & BSS_CHANGED_BEACON_ENABLED)
3241 ath10k_control_beaconing(arvif, info);
3242
3243 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003244 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003245 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003246 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003247
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003248 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003249 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003250 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003251 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003252 }
3253
3254 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003255 if (info->use_short_slot)
3256 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3257
3258 else
3259 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3260
Michal Kazior7aa7a722014-08-25 12:09:38 +02003261 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003262 arvif->vdev_id, slottime);
3263
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003264 vdev_param = ar->wmi.vdev_param->slot_time;
3265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003266 slottime);
3267 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003268 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003269 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003270 }
3271
3272 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273 if (info->use_short_preamble)
3274 preamble = WMI_VDEV_PREAMBLE_SHORT;
3275 else
3276 preamble = WMI_VDEV_PREAMBLE_LONG;
3277
Michal Kazior7aa7a722014-08-25 12:09:38 +02003278 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003279 "mac vdev %d preamble %dn",
3280 arvif->vdev_id, preamble);
3281
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003282 vdev_param = ar->wmi.vdev_param->preamble;
3283 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003284 preamble);
3285 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003286 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003287 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288 }
3289
3290 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003291 if (info->assoc) {
3292 /* Workaround: Make sure monitor vdev is not running
3293 * when associating to prevent some firmware revisions
3294 * (e.g. 10.1 and 10.2) from crashing.
3295 */
3296 if (ar->monitor_started)
3297 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003298 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003299 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003300 } else {
3301 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003302 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003303 }
3304
Michal Kazior7d9d5582014-10-21 10:40:15 +03003305 if (changed & BSS_CHANGED_TXPOWER) {
3306 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3307 arvif->vdev_id, info->txpower);
3308
3309 arvif->txpower = info->txpower;
3310 ret = ath10k_mac_txpower_recalc(ar);
3311 if (ret)
3312 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3313 }
3314
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315 mutex_unlock(&ar->conf_mutex);
3316}
3317
3318static int ath10k_hw_scan(struct ieee80211_hw *hw,
3319 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003320 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321{
3322 struct ath10k *ar = hw->priv;
3323 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003324 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325 struct wmi_start_scan_arg arg;
3326 int ret = 0;
3327 int i;
3328
3329 mutex_lock(&ar->conf_mutex);
3330
3331 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003332 switch (ar->scan.state) {
3333 case ATH10K_SCAN_IDLE:
3334 reinit_completion(&ar->scan.started);
3335 reinit_completion(&ar->scan.completed);
3336 ar->scan.state = ATH10K_SCAN_STARTING;
3337 ar->scan.is_roc = false;
3338 ar->scan.vdev_id = arvif->vdev_id;
3339 ret = 0;
3340 break;
3341 case ATH10K_SCAN_STARTING:
3342 case ATH10K_SCAN_RUNNING:
3343 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003344 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003345 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003346 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003347 spin_unlock_bh(&ar->data_lock);
3348
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003349 if (ret)
3350 goto exit;
3351
Kalle Valo5e3dd152013-06-12 20:52:10 +03003352 memset(&arg, 0, sizeof(arg));
3353 ath10k_wmi_start_scan_init(ar, &arg);
3354 arg.vdev_id = arvif->vdev_id;
3355 arg.scan_id = ATH10K_SCAN_ID;
3356
3357 if (!req->no_cck)
3358 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3359
3360 if (req->ie_len) {
3361 arg.ie_len = req->ie_len;
3362 memcpy(arg.ie, req->ie, arg.ie_len);
3363 }
3364
3365 if (req->n_ssids) {
3366 arg.n_ssids = req->n_ssids;
3367 for (i = 0; i < arg.n_ssids; i++) {
3368 arg.ssids[i].len = req->ssids[i].ssid_len;
3369 arg.ssids[i].ssid = req->ssids[i].ssid;
3370 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003371 } else {
3372 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003373 }
3374
3375 if (req->n_channels) {
3376 arg.n_channels = req->n_channels;
3377 for (i = 0; i < arg.n_channels; i++)
3378 arg.channels[i] = req->channels[i]->center_freq;
3379 }
3380
3381 ret = ath10k_start_scan(ar, &arg);
3382 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003383 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003384 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003385 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003386 spin_unlock_bh(&ar->data_lock);
3387 }
3388
3389exit:
3390 mutex_unlock(&ar->conf_mutex);
3391 return ret;
3392}
3393
3394static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3395 struct ieee80211_vif *vif)
3396{
3397 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398
3399 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003400 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003402
3403 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003404}
3405
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003406static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3407 struct ath10k_vif *arvif,
3408 enum set_key_cmd cmd,
3409 struct ieee80211_key_conf *key)
3410{
3411 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3412 int ret;
3413
3414 /* 10.1 firmware branch requires default key index to be set to group
3415 * key index after installing it. Otherwise FW/HW Txes corrupted
3416 * frames with multi-vif APs. This is not required for main firmware
3417 * branch (e.g. 636).
3418 *
3419 * FIXME: This has been tested only in AP. It remains unknown if this
3420 * is required for multi-vif STA interfaces on 10.1 */
3421
3422 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3423 return;
3424
3425 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3426 return;
3427
3428 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3429 return;
3430
3431 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3432 return;
3433
3434 if (cmd != SET_KEY)
3435 return;
3436
3437 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3438 key->keyidx);
3439 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003440 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003441 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003442}
3443
Kalle Valo5e3dd152013-06-12 20:52:10 +03003444static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3445 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3446 struct ieee80211_key_conf *key)
3447{
3448 struct ath10k *ar = hw->priv;
3449 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3450 struct ath10k_peer *peer;
3451 const u8 *peer_addr;
3452 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3453 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3454 int ret = 0;
3455
3456 if (key->keyidx > WMI_MAX_KEY_INDEX)
3457 return -ENOSPC;
3458
3459 mutex_lock(&ar->conf_mutex);
3460
3461 if (sta)
3462 peer_addr = sta->addr;
3463 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3464 peer_addr = vif->bss_conf.bssid;
3465 else
3466 peer_addr = vif->addr;
3467
3468 key->hw_key_idx = key->keyidx;
3469
3470 /* the peer should not disappear in mid-way (unless FW goes awry) since
3471 * we already hold conf_mutex. we just make sure its there now. */
3472 spin_lock_bh(&ar->data_lock);
3473 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3474 spin_unlock_bh(&ar->data_lock);
3475
3476 if (!peer) {
3477 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003478 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479 peer_addr);
3480 ret = -EOPNOTSUPP;
3481 goto exit;
3482 } else {
3483 /* if the peer doesn't exist there is no key to disable
3484 * anymore */
3485 goto exit;
3486 }
3487 }
3488
3489 if (is_wep) {
3490 if (cmd == SET_KEY)
3491 arvif->wep_keys[key->keyidx] = key;
3492 else
3493 arvif->wep_keys[key->keyidx] = NULL;
3494
3495 if (cmd == DISABLE_KEY)
3496 ath10k_clear_vdev_key(arvif, key);
3497 }
3498
3499 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3500 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003501 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003502 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503 goto exit;
3504 }
3505
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003506 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3507
Kalle Valo5e3dd152013-06-12 20:52:10 +03003508 spin_lock_bh(&ar->data_lock);
3509 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3510 if (peer && cmd == SET_KEY)
3511 peer->keys[key->keyidx] = key;
3512 else if (peer && cmd == DISABLE_KEY)
3513 peer->keys[key->keyidx] = NULL;
3514 else if (peer == NULL)
3515 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003516 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517 spin_unlock_bh(&ar->data_lock);
3518
3519exit:
3520 mutex_unlock(&ar->conf_mutex);
3521 return ret;
3522}
3523
Michal Kazior9797feb2014-02-14 14:49:48 +01003524static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3525{
3526 struct ath10k *ar;
3527 struct ath10k_vif *arvif;
3528 struct ath10k_sta *arsta;
3529 struct ieee80211_sta *sta;
3530 u32 changed, bw, nss, smps;
3531 int err;
3532
3533 arsta = container_of(wk, struct ath10k_sta, update_wk);
3534 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3535 arvif = arsta->arvif;
3536 ar = arvif->ar;
3537
3538 spin_lock_bh(&ar->data_lock);
3539
3540 changed = arsta->changed;
3541 arsta->changed = 0;
3542
3543 bw = arsta->bw;
3544 nss = arsta->nss;
3545 smps = arsta->smps;
3546
3547 spin_unlock_bh(&ar->data_lock);
3548
3549 mutex_lock(&ar->conf_mutex);
3550
3551 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003552 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003553 sta->addr, bw);
3554
3555 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3556 WMI_PEER_CHAN_WIDTH, bw);
3557 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003558 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003559 sta->addr, bw, err);
3560 }
3561
3562 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003563 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003564 sta->addr, nss);
3565
3566 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3567 WMI_PEER_NSS, nss);
3568 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003569 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003570 sta->addr, nss, err);
3571 }
3572
3573 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003574 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003575 sta->addr, smps);
3576
3577 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3578 WMI_PEER_SMPS_STATE, smps);
3579 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003580 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003581 sta->addr, smps, err);
3582 }
3583
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003584 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003585 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003586 sta->addr);
3587
Michal Kazior590922a2014-10-21 10:10:29 +03003588 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003589 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003590 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003591 sta->addr);
3592 }
3593
Michal Kazior9797feb2014-02-14 14:49:48 +01003594 mutex_unlock(&ar->conf_mutex);
3595}
3596
Kalle Valo5e3dd152013-06-12 20:52:10 +03003597static int ath10k_sta_state(struct ieee80211_hw *hw,
3598 struct ieee80211_vif *vif,
3599 struct ieee80211_sta *sta,
3600 enum ieee80211_sta_state old_state,
3601 enum ieee80211_sta_state new_state)
3602{
3603 struct ath10k *ar = hw->priv;
3604 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003605 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003606 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003607 int ret = 0;
3608
Michal Kazior76f90022014-02-25 09:29:57 +02003609 if (old_state == IEEE80211_STA_NOTEXIST &&
3610 new_state == IEEE80211_STA_NONE) {
3611 memset(arsta, 0, sizeof(*arsta));
3612 arsta->arvif = arvif;
3613 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3614 }
3615
Michal Kazior9797feb2014-02-14 14:49:48 +01003616 /* cancel must be done outside the mutex to avoid deadlock */
3617 if ((old_state == IEEE80211_STA_NONE &&
3618 new_state == IEEE80211_STA_NOTEXIST))
3619 cancel_work_sync(&arsta->update_wk);
3620
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621 mutex_lock(&ar->conf_mutex);
3622
3623 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003624 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003625 /*
3626 * New station addition.
3627 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003628 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3629 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3630 else
3631 max_num_peers = TARGET_NUM_PEERS;
3632
3633 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003634 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003635 ar->num_peers, max_num_peers);
3636 ret = -ENOBUFS;
3637 goto exit;
3638 }
3639
Michal Kazior7aa7a722014-08-25 12:09:38 +02003640 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003641 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3642 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003643
Kalle Valo5e3dd152013-06-12 20:52:10 +03003644 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3645 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003646 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 -08003647 sta->addr, arvif->vdev_id, ret);
Michal Kazior077efc82014-10-21 10:10:29 +03003648
3649 if (vif->type == NL80211_IFTYPE_STATION) {
3650 WARN_ON(arvif->is_started);
3651
3652 ret = ath10k_vdev_start(arvif);
3653 if (ret) {
3654 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3655 arvif->vdev_id, ret);
3656 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3657 sta->addr));
3658 goto exit;
3659 }
3660
3661 arvif->is_started = true;
3662 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003663 } else if ((old_state == IEEE80211_STA_NONE &&
3664 new_state == IEEE80211_STA_NOTEXIST)) {
3665 /*
3666 * Existing station deletion.
3667 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003668 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003669 "mac vdev %d peer delete %pM (sta gone)\n",
3670 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003671
3672 if (vif->type == NL80211_IFTYPE_STATION) {
3673 WARN_ON(!arvif->is_started);
3674
3675 ret = ath10k_vdev_stop(arvif);
3676 if (ret)
3677 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3678 arvif->vdev_id, ret);
3679
3680 arvif->is_started = false;
3681 }
3682
Kalle Valo5e3dd152013-06-12 20:52:10 +03003683 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3684 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003685 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003686 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003687
Kalle Valo5e3dd152013-06-12 20:52:10 +03003688 } else if (old_state == IEEE80211_STA_AUTH &&
3689 new_state == IEEE80211_STA_ASSOC &&
3690 (vif->type == NL80211_IFTYPE_AP ||
3691 vif->type == NL80211_IFTYPE_ADHOC)) {
3692 /*
3693 * New association.
3694 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003695 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003696 sta->addr);
3697
Michal Kazior590922a2014-10-21 10:10:29 +03003698 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003699 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003700 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003701 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003702 } else if (old_state == IEEE80211_STA_ASSOC &&
3703 new_state == IEEE80211_STA_AUTH &&
3704 (vif->type == NL80211_IFTYPE_AP ||
3705 vif->type == NL80211_IFTYPE_ADHOC)) {
3706 /*
3707 * Disassociation.
3708 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003709 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003710 sta->addr);
3711
Michal Kazior590922a2014-10-21 10:10:29 +03003712 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003713 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003714 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003715 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003716 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003717exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003718 mutex_unlock(&ar->conf_mutex);
3719 return ret;
3720}
3721
3722static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003723 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003724{
3725 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3726 u32 value = 0;
3727 int ret = 0;
3728
Michal Kazior548db542013-07-05 16:15:15 +03003729 lockdep_assert_held(&ar->conf_mutex);
3730
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3732 return 0;
3733
3734 switch (ac) {
3735 case IEEE80211_AC_VO:
3736 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3737 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3738 break;
3739 case IEEE80211_AC_VI:
3740 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3741 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3742 break;
3743 case IEEE80211_AC_BE:
3744 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3745 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3746 break;
3747 case IEEE80211_AC_BK:
3748 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3749 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3750 break;
3751 }
3752
3753 if (enable)
3754 arvif->u.sta.uapsd |= value;
3755 else
3756 arvif->u.sta.uapsd &= ~value;
3757
3758 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3759 WMI_STA_PS_PARAM_UAPSD,
3760 arvif->u.sta.uapsd);
3761 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003762 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003763 goto exit;
3764 }
3765
3766 if (arvif->u.sta.uapsd)
3767 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3768 else
3769 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3770
3771 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3772 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3773 value);
3774 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003775 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003776
3777exit:
3778 return ret;
3779}
3780
3781static int ath10k_conf_tx(struct ieee80211_hw *hw,
3782 struct ieee80211_vif *vif, u16 ac,
3783 const struct ieee80211_tx_queue_params *params)
3784{
3785 struct ath10k *ar = hw->priv;
3786 struct wmi_wmm_params_arg *p = NULL;
3787 int ret;
3788
3789 mutex_lock(&ar->conf_mutex);
3790
3791 switch (ac) {
3792 case IEEE80211_AC_VO:
3793 p = &ar->wmm_params.ac_vo;
3794 break;
3795 case IEEE80211_AC_VI:
3796 p = &ar->wmm_params.ac_vi;
3797 break;
3798 case IEEE80211_AC_BE:
3799 p = &ar->wmm_params.ac_be;
3800 break;
3801 case IEEE80211_AC_BK:
3802 p = &ar->wmm_params.ac_bk;
3803 break;
3804 }
3805
3806 if (WARN_ON(!p)) {
3807 ret = -EINVAL;
3808 goto exit;
3809 }
3810
3811 p->cwmin = params->cw_min;
3812 p->cwmax = params->cw_max;
3813 p->aifs = params->aifs;
3814
3815 /*
3816 * The channel time duration programmed in the HW is in absolute
3817 * microseconds, while mac80211 gives the txop in units of
3818 * 32 microseconds.
3819 */
3820 p->txop = params->txop * 32;
3821
3822 /* FIXME: FW accepts wmm params per hw, not per vif */
3823 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3824 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003825 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003826 goto exit;
3827 }
3828
3829 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3830 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003831 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003832
3833exit:
3834 mutex_unlock(&ar->conf_mutex);
3835 return ret;
3836}
3837
3838#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3839
3840static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3841 struct ieee80211_vif *vif,
3842 struct ieee80211_channel *chan,
3843 int duration,
3844 enum ieee80211_roc_type type)
3845{
3846 struct ath10k *ar = hw->priv;
3847 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3848 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003849 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003850
3851 mutex_lock(&ar->conf_mutex);
3852
3853 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003854 switch (ar->scan.state) {
3855 case ATH10K_SCAN_IDLE:
3856 reinit_completion(&ar->scan.started);
3857 reinit_completion(&ar->scan.completed);
3858 reinit_completion(&ar->scan.on_channel);
3859 ar->scan.state = ATH10K_SCAN_STARTING;
3860 ar->scan.is_roc = true;
3861 ar->scan.vdev_id = arvif->vdev_id;
3862 ar->scan.roc_freq = chan->center_freq;
3863 ret = 0;
3864 break;
3865 case ATH10K_SCAN_STARTING:
3866 case ATH10K_SCAN_RUNNING:
3867 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003868 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003869 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003870 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003871 spin_unlock_bh(&ar->data_lock);
3872
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003873 if (ret)
3874 goto exit;
3875
Michal Kaziordcca0bd2014-11-24 14:58:32 +01003876 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
3877
Kalle Valo5e3dd152013-06-12 20:52:10 +03003878 memset(&arg, 0, sizeof(arg));
3879 ath10k_wmi_start_scan_init(ar, &arg);
3880 arg.vdev_id = arvif->vdev_id;
3881 arg.scan_id = ATH10K_SCAN_ID;
3882 arg.n_channels = 1;
3883 arg.channels[0] = chan->center_freq;
3884 arg.dwell_time_active = duration;
3885 arg.dwell_time_passive = duration;
3886 arg.max_scan_time = 2 * duration;
3887 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3888 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3889
3890 ret = ath10k_start_scan(ar, &arg);
3891 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003892 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003894 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895 spin_unlock_bh(&ar->data_lock);
3896 goto exit;
3897 }
3898
3899 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3900 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003901 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003902
3903 ret = ath10k_scan_stop(ar);
3904 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003905 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003906
Kalle Valo5e3dd152013-06-12 20:52:10 +03003907 ret = -ETIMEDOUT;
3908 goto exit;
3909 }
3910
3911 ret = 0;
3912exit:
3913 mutex_unlock(&ar->conf_mutex);
3914 return ret;
3915}
3916
3917static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3918{
3919 struct ath10k *ar = hw->priv;
3920
3921 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003922 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003923 mutex_unlock(&ar->conf_mutex);
3924
Michal Kazior4eb2e162014-10-28 10:23:09 +01003925 cancel_delayed_work_sync(&ar->scan.timeout);
3926
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927 return 0;
3928}
3929
3930/*
3931 * Both RTS and Fragmentation threshold are interface-specific
3932 * in ath10k, but device-specific in mac80211.
3933 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003934
3935static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3936{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003937 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003938 struct ath10k_vif *arvif;
3939 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003940
Michal Kaziorad088bf2013-10-16 15:44:46 +03003941 mutex_lock(&ar->conf_mutex);
3942 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003943 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003944 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003945
Michal Kaziorad088bf2013-10-16 15:44:46 +03003946 ret = ath10k_mac_set_rts(arvif, value);
3947 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003948 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003949 arvif->vdev_id, ret);
3950 break;
3951 }
3952 }
3953 mutex_unlock(&ar->conf_mutex);
3954
3955 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003956}
3957
3958static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3959{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003960 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003961 struct ath10k_vif *arvif;
3962 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963
Kalle Valo5e3dd152013-06-12 20:52:10 +03003964 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003965 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003966 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003967 arvif->vdev_id, value);
3968
Michal Kazior56a0dee2014-10-23 17:04:29 +03003969 ret = ath10k_mac_set_frag(arvif, value);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003971 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003972 arvif->vdev_id, ret);
3973 break;
3974 }
3975 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003976 mutex_unlock(&ar->conf_mutex);
3977
Michal Kaziorad088bf2013-10-16 15:44:46 +03003978 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003979}
3980
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003981static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3982 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003983{
3984 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003985 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003986 int ret;
3987
3988 /* mac80211 doesn't care if we really xmit queued frames or not
3989 * we'll collect those frames either way if we stop/delete vdevs */
3990 if (drop)
3991 return;
3992
Michal Kazior548db542013-07-05 16:15:15 +03003993 mutex_lock(&ar->conf_mutex);
3994
Michal Kazioraffd3212013-07-16 09:54:35 +02003995 if (ar->state == ATH10K_STATE_WEDGED)
3996 goto skip;
3997
Michal Kazioredb82362013-07-05 16:15:14 +03003998 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004000
Michal Kazioredb82362013-07-05 16:15:14 +03004001 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004002 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004003 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004004
Michal Kazior7962b0d2014-10-28 10:34:38 +01004005 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4006 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4007 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004008
4009 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004011
4012 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004013 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004014 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004015
Michal Kazioraffd3212013-07-16 09:54:35 +02004016skip:
Michal Kazior548db542013-07-05 16:15:15 +03004017 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004018}
4019
4020/* TODO: Implement this function properly
4021 * For now it is needed to reply to Probe Requests in IBSS mode.
4022 * Propably we need this information from FW.
4023 */
4024static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4025{
4026 return 1;
4027}
4028
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004029#ifdef CONFIG_PM
4030static int ath10k_suspend(struct ieee80211_hw *hw,
4031 struct cfg80211_wowlan *wowlan)
4032{
4033 struct ath10k *ar = hw->priv;
4034 int ret;
4035
Marek Puzyniak9042e172014-02-10 17:14:23 +01004036 mutex_lock(&ar->conf_mutex);
4037
Marek Puzyniak00f54822014-02-10 17:14:24 +01004038 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004039 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004040 if (ret == -ETIMEDOUT)
4041 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004042 ret = 1;
4043 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004044 }
4045
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004046 ret = ath10k_hif_suspend(ar);
4047 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004048 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004049 goto resume;
4050 }
4051
Marek Puzyniak9042e172014-02-10 17:14:23 +01004052 ret = 0;
4053 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004054resume:
4055 ret = ath10k_wmi_pdev_resume_target(ar);
4056 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004057 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004058
4059 ret = 1;
4060exit:
4061 mutex_unlock(&ar->conf_mutex);
4062 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004063}
4064
4065static int ath10k_resume(struct ieee80211_hw *hw)
4066{
4067 struct ath10k *ar = hw->priv;
4068 int ret;
4069
Marek Puzyniak9042e172014-02-10 17:14:23 +01004070 mutex_lock(&ar->conf_mutex);
4071
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004072 ret = ath10k_hif_resume(ar);
4073 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004074 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004075 ret = 1;
4076 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004077 }
4078
4079 ret = ath10k_wmi_pdev_resume_target(ar);
4080 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004081 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004082 ret = 1;
4083 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004084 }
4085
Marek Puzyniak9042e172014-02-10 17:14:23 +01004086 ret = 0;
4087exit:
4088 mutex_unlock(&ar->conf_mutex);
4089 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004090}
4091#endif
4092
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004093static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4094 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004095{
4096 struct ath10k *ar = hw->priv;
4097
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004098 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4099 return;
4100
Michal Kazioraffd3212013-07-16 09:54:35 +02004101 mutex_lock(&ar->conf_mutex);
4102
4103 /* If device failed to restart it will be in a different state, e.g.
4104 * ATH10K_STATE_WEDGED */
4105 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004106 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004107 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004108 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004109 }
4110
4111 mutex_unlock(&ar->conf_mutex);
4112}
4113
Michal Kazior2e1dea42013-07-31 10:32:40 +02004114static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4115 struct survey_info *survey)
4116{
4117 struct ath10k *ar = hw->priv;
4118 struct ieee80211_supported_band *sband;
4119 struct survey_info *ar_survey = &ar->survey[idx];
4120 int ret = 0;
4121
4122 mutex_lock(&ar->conf_mutex);
4123
4124 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4125 if (sband && idx >= sband->n_channels) {
4126 idx -= sband->n_channels;
4127 sband = NULL;
4128 }
4129
4130 if (!sband)
4131 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4132
4133 if (!sband || idx >= sband->n_channels) {
4134 ret = -ENOENT;
4135 goto exit;
4136 }
4137
4138 spin_lock_bh(&ar->data_lock);
4139 memcpy(survey, ar_survey, sizeof(*survey));
4140 spin_unlock_bh(&ar->data_lock);
4141
4142 survey->channel = &sband->channels[idx];
4143
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004144 if (ar->rx_channel == survey->channel)
4145 survey->filled |= SURVEY_INFO_IN_USE;
4146
Michal Kazior2e1dea42013-07-31 10:32:40 +02004147exit:
4148 mutex_unlock(&ar->conf_mutex);
4149 return ret;
4150}
4151
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004152/* Helper table for legacy fixed_rate/bitrate_mask */
4153static const u8 cck_ofdm_rate[] = {
4154 /* CCK */
4155 3, /* 1Mbps */
4156 2, /* 2Mbps */
4157 1, /* 5.5Mbps */
4158 0, /* 11Mbps */
4159 /* OFDM */
4160 3, /* 6Mbps */
4161 7, /* 9Mbps */
4162 2, /* 12Mbps */
4163 6, /* 18Mbps */
4164 1, /* 24Mbps */
4165 5, /* 36Mbps */
4166 0, /* 48Mbps */
4167 4, /* 54Mbps */
4168};
4169
4170/* Check if only one bit set */
4171static int ath10k_check_single_mask(u32 mask)
4172{
4173 int bit;
4174
4175 bit = ffs(mask);
4176 if (!bit)
4177 return 0;
4178
4179 mask &= ~BIT(bit - 1);
4180 if (mask)
4181 return 2;
4182
4183 return 1;
4184}
4185
4186static bool
4187ath10k_default_bitrate_mask(struct ath10k *ar,
4188 enum ieee80211_band band,
4189 const struct cfg80211_bitrate_mask *mask)
4190{
4191 u32 legacy = 0x00ff;
4192 u8 ht = 0xff, i;
4193 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004194 u16 nrf = ar->num_rf_chains;
4195
4196 if (ar->cfg_tx_chainmask)
4197 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004198
4199 switch (band) {
4200 case IEEE80211_BAND_2GHZ:
4201 legacy = 0x00fff;
4202 vht = 0;
4203 break;
4204 case IEEE80211_BAND_5GHZ:
4205 break;
4206 default:
4207 return false;
4208 }
4209
4210 if (mask->control[band].legacy != legacy)
4211 return false;
4212
Ben Greearb116ea12014-11-24 16:22:10 +02004213 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004214 if (mask->control[band].ht_mcs[i] != ht)
4215 return false;
4216
Ben Greearb116ea12014-11-24 16:22:10 +02004217 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004218 if (mask->control[band].vht_mcs[i] != vht)
4219 return false;
4220
4221 return true;
4222}
4223
4224static bool
4225ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4226 enum ieee80211_band band,
4227 u8 *fixed_nss)
4228{
4229 int ht_nss = 0, vht_nss = 0, i;
4230
4231 /* check legacy */
4232 if (ath10k_check_single_mask(mask->control[band].legacy))
4233 return false;
4234
4235 /* check HT */
4236 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4237 if (mask->control[band].ht_mcs[i] == 0xff)
4238 continue;
4239 else if (mask->control[band].ht_mcs[i] == 0x00)
4240 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004241
4242 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004243 }
4244
4245 ht_nss = i;
4246
4247 /* check VHT */
4248 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4249 if (mask->control[band].vht_mcs[i] == 0x03ff)
4250 continue;
4251 else if (mask->control[band].vht_mcs[i] == 0x0000)
4252 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004253
4254 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004255 }
4256
4257 vht_nss = i;
4258
4259 if (ht_nss > 0 && vht_nss > 0)
4260 return false;
4261
4262 if (ht_nss)
4263 *fixed_nss = ht_nss;
4264 else if (vht_nss)
4265 *fixed_nss = vht_nss;
4266 else
4267 return false;
4268
4269 return true;
4270}
4271
4272static bool
4273ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4274 enum ieee80211_band band,
4275 enum wmi_rate_preamble *preamble)
4276{
4277 int legacy = 0, ht = 0, vht = 0, i;
4278
4279 *preamble = WMI_RATE_PREAMBLE_OFDM;
4280
4281 /* check legacy */
4282 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4283 if (legacy > 1)
4284 return false;
4285
4286 /* check HT */
4287 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4288 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4289 if (ht > 1)
4290 return false;
4291
4292 /* check VHT */
4293 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4294 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4295 if (vht > 1)
4296 return false;
4297
4298 /* Currently we support only one fixed_rate */
4299 if ((legacy + ht + vht) != 1)
4300 return false;
4301
4302 if (ht)
4303 *preamble = WMI_RATE_PREAMBLE_HT;
4304 else if (vht)
4305 *preamble = WMI_RATE_PREAMBLE_VHT;
4306
4307 return true;
4308}
4309
4310static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004311ath10k_bitrate_mask_rate(struct ath10k *ar,
4312 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004313 enum ieee80211_band band,
4314 u8 *fixed_rate,
4315 u8 *fixed_nss)
4316{
4317 u8 rate = 0, pream = 0, nss = 0, i;
4318 enum wmi_rate_preamble preamble;
4319
4320 /* Check if single rate correct */
4321 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4322 return false;
4323
4324 pream = preamble;
4325
4326 switch (preamble) {
4327 case WMI_RATE_PREAMBLE_CCK:
4328 case WMI_RATE_PREAMBLE_OFDM:
4329 i = ffs(mask->control[band].legacy) - 1;
4330
4331 if (band == IEEE80211_BAND_2GHZ && i < 4)
4332 pream = WMI_RATE_PREAMBLE_CCK;
4333
4334 if (band == IEEE80211_BAND_5GHZ)
4335 i += 4;
4336
4337 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4338 return false;
4339
4340 rate = cck_ofdm_rate[i];
4341 break;
4342 case WMI_RATE_PREAMBLE_HT:
4343 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4344 if (mask->control[band].ht_mcs[i])
4345 break;
4346
4347 if (i == IEEE80211_HT_MCS_MASK_LEN)
4348 return false;
4349
4350 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4351 nss = i;
4352 break;
4353 case WMI_RATE_PREAMBLE_VHT:
4354 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4355 if (mask->control[band].vht_mcs[i])
4356 break;
4357
4358 if (i == NL80211_VHT_NSS_MAX)
4359 return false;
4360
4361 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4362 nss = i;
4363 break;
4364 }
4365
4366 *fixed_nss = nss + 1;
4367 nss <<= 4;
4368 pream <<= 6;
4369
Michal Kazior7aa7a722014-08-25 12:09:38 +02004370 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 +01004371 pream, nss, rate);
4372
4373 *fixed_rate = pream | nss | rate;
4374
4375 return true;
4376}
4377
Michal Kazior7aa7a722014-08-25 12:09:38 +02004378static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4379 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004380 enum ieee80211_band band,
4381 u8 *fixed_rate,
4382 u8 *fixed_nss)
4383{
4384 /* First check full NSS mask, if we can simply limit NSS */
4385 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4386 return true;
4387
4388 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004389 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004390}
4391
4392static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4393 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004394 u8 fixed_nss,
4395 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004396{
4397 struct ath10k *ar = arvif->ar;
4398 u32 vdev_param;
4399 int ret = 0;
4400
4401 mutex_lock(&ar->conf_mutex);
4402
4403 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004404 arvif->fixed_nss == fixed_nss &&
4405 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004406 goto exit;
4407
4408 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004409 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004410
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004411 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004412 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004413
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004414 vdev_param = ar->wmi.vdev_param->fixed_rate;
4415 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4416 vdev_param, fixed_rate);
4417 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004418 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004419 fixed_rate, ret);
4420 ret = -EINVAL;
4421 goto exit;
4422 }
4423
4424 arvif->fixed_rate = fixed_rate;
4425
4426 vdev_param = ar->wmi.vdev_param->nss;
4427 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4428 vdev_param, fixed_nss);
4429
4430 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004431 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004432 fixed_nss, ret);
4433 ret = -EINVAL;
4434 goto exit;
4435 }
4436
4437 arvif->fixed_nss = fixed_nss;
4438
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004439 vdev_param = ar->wmi.vdev_param->sgi;
4440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4441 force_sgi);
4442
4443 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004444 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004445 force_sgi, ret);
4446 ret = -EINVAL;
4447 goto exit;
4448 }
4449
4450 arvif->force_sgi = force_sgi;
4451
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004452exit:
4453 mutex_unlock(&ar->conf_mutex);
4454 return ret;
4455}
4456
4457static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4458 struct ieee80211_vif *vif,
4459 const struct cfg80211_bitrate_mask *mask)
4460{
4461 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4462 struct ath10k *ar = arvif->ar;
4463 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4464 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4465 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004466 u8 force_sgi;
4467
Ben Greearb116ea12014-11-24 16:22:10 +02004468 if (ar->cfg_tx_chainmask)
4469 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4470
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004471 force_sgi = mask->control[band].gi;
4472 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4473 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004474
4475 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004476 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004477 &fixed_rate,
4478 &fixed_nss))
4479 return -EINVAL;
4480 }
4481
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004482 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004483 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004484 return -EINVAL;
4485 }
4486
4487 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4488 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004489}
4490
Michal Kazior9797feb2014-02-14 14:49:48 +01004491static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4492 struct ieee80211_vif *vif,
4493 struct ieee80211_sta *sta,
4494 u32 changed)
4495{
4496 struct ath10k *ar = hw->priv;
4497 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4498 u32 bw, smps;
4499
4500 spin_lock_bh(&ar->data_lock);
4501
Michal Kazior7aa7a722014-08-25 12:09:38 +02004502 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004503 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4504 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4505 sta->smps_mode);
4506
4507 if (changed & IEEE80211_RC_BW_CHANGED) {
4508 bw = WMI_PEER_CHWIDTH_20MHZ;
4509
4510 switch (sta->bandwidth) {
4511 case IEEE80211_STA_RX_BW_20:
4512 bw = WMI_PEER_CHWIDTH_20MHZ;
4513 break;
4514 case IEEE80211_STA_RX_BW_40:
4515 bw = WMI_PEER_CHWIDTH_40MHZ;
4516 break;
4517 case IEEE80211_STA_RX_BW_80:
4518 bw = WMI_PEER_CHWIDTH_80MHZ;
4519 break;
4520 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004521 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004522 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004523 bw = WMI_PEER_CHWIDTH_20MHZ;
4524 break;
4525 }
4526
4527 arsta->bw = bw;
4528 }
4529
4530 if (changed & IEEE80211_RC_NSS_CHANGED)
4531 arsta->nss = sta->rx_nss;
4532
4533 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4534 smps = WMI_PEER_SMPS_PS_NONE;
4535
4536 switch (sta->smps_mode) {
4537 case IEEE80211_SMPS_AUTOMATIC:
4538 case IEEE80211_SMPS_OFF:
4539 smps = WMI_PEER_SMPS_PS_NONE;
4540 break;
4541 case IEEE80211_SMPS_STATIC:
4542 smps = WMI_PEER_SMPS_STATIC;
4543 break;
4544 case IEEE80211_SMPS_DYNAMIC:
4545 smps = WMI_PEER_SMPS_DYNAMIC;
4546 break;
4547 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004548 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004549 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004550 smps = WMI_PEER_SMPS_PS_NONE;
4551 break;
4552 }
4553
4554 arsta->smps = smps;
4555 }
4556
Michal Kazior9797feb2014-02-14 14:49:48 +01004557 arsta->changed |= changed;
4558
4559 spin_unlock_bh(&ar->data_lock);
4560
4561 ieee80211_queue_work(hw, &arsta->update_wk);
4562}
4563
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004564static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4565{
4566 /*
4567 * FIXME: Return 0 for time being. Need to figure out whether FW
4568 * has the API to fetch 64-bit local TSF
4569 */
4570
4571 return 0;
4572}
4573
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004574static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4575 struct ieee80211_vif *vif,
4576 enum ieee80211_ampdu_mlme_action action,
4577 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4578 u8 buf_size)
4579{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004580 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004581 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4582
Michal Kazior7aa7a722014-08-25 12:09:38 +02004583 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 +02004584 arvif->vdev_id, sta->addr, tid, action);
4585
4586 switch (action) {
4587 case IEEE80211_AMPDU_RX_START:
4588 case IEEE80211_AMPDU_RX_STOP:
4589 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4590 * creation/removal. Do we need to verify this?
4591 */
4592 return 0;
4593 case IEEE80211_AMPDU_TX_START:
4594 case IEEE80211_AMPDU_TX_STOP_CONT:
4595 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4596 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4597 case IEEE80211_AMPDU_TX_OPERATIONAL:
4598 /* Firmware offloads Tx aggregation entirely so deny mac80211
4599 * Tx aggregation requests.
4600 */
4601 return -EOPNOTSUPP;
4602 }
4603
4604 return -EINVAL;
4605}
4606
Kalle Valo5e3dd152013-06-12 20:52:10 +03004607static const struct ieee80211_ops ath10k_ops = {
4608 .tx = ath10k_tx,
4609 .start = ath10k_start,
4610 .stop = ath10k_stop,
4611 .config = ath10k_config,
4612 .add_interface = ath10k_add_interface,
4613 .remove_interface = ath10k_remove_interface,
4614 .configure_filter = ath10k_configure_filter,
4615 .bss_info_changed = ath10k_bss_info_changed,
4616 .hw_scan = ath10k_hw_scan,
4617 .cancel_hw_scan = ath10k_cancel_hw_scan,
4618 .set_key = ath10k_set_key,
4619 .sta_state = ath10k_sta_state,
4620 .conf_tx = ath10k_conf_tx,
4621 .remain_on_channel = ath10k_remain_on_channel,
4622 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4623 .set_rts_threshold = ath10k_set_rts_threshold,
4624 .set_frag_threshold = ath10k_set_frag_threshold,
4625 .flush = ath10k_flush,
4626 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004627 .set_antenna = ath10k_set_antenna,
4628 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004629 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004630 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004631 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004632 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004633 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004634 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004635 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4636 .get_et_stats = ath10k_debug_get_et_stats,
4637 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004638
4639 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4640
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004641#ifdef CONFIG_PM
4642 .suspend = ath10k_suspend,
4643 .resume = ath10k_resume,
4644#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004645};
4646
4647#define RATETAB_ENT(_rate, _rateid, _flags) { \
4648 .bitrate = (_rate), \
4649 .flags = (_flags), \
4650 .hw_value = (_rateid), \
4651}
4652
4653#define CHAN2G(_channel, _freq, _flags) { \
4654 .band = IEEE80211_BAND_2GHZ, \
4655 .hw_value = (_channel), \
4656 .center_freq = (_freq), \
4657 .flags = (_flags), \
4658 .max_antenna_gain = 0, \
4659 .max_power = 30, \
4660}
4661
4662#define CHAN5G(_channel, _freq, _flags) { \
4663 .band = IEEE80211_BAND_5GHZ, \
4664 .hw_value = (_channel), \
4665 .center_freq = (_freq), \
4666 .flags = (_flags), \
4667 .max_antenna_gain = 0, \
4668 .max_power = 30, \
4669}
4670
4671static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4672 CHAN2G(1, 2412, 0),
4673 CHAN2G(2, 2417, 0),
4674 CHAN2G(3, 2422, 0),
4675 CHAN2G(4, 2427, 0),
4676 CHAN2G(5, 2432, 0),
4677 CHAN2G(6, 2437, 0),
4678 CHAN2G(7, 2442, 0),
4679 CHAN2G(8, 2447, 0),
4680 CHAN2G(9, 2452, 0),
4681 CHAN2G(10, 2457, 0),
4682 CHAN2G(11, 2462, 0),
4683 CHAN2G(12, 2467, 0),
4684 CHAN2G(13, 2472, 0),
4685 CHAN2G(14, 2484, 0),
4686};
4687
4688static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004689 CHAN5G(36, 5180, 0),
4690 CHAN5G(40, 5200, 0),
4691 CHAN5G(44, 5220, 0),
4692 CHAN5G(48, 5240, 0),
4693 CHAN5G(52, 5260, 0),
4694 CHAN5G(56, 5280, 0),
4695 CHAN5G(60, 5300, 0),
4696 CHAN5G(64, 5320, 0),
4697 CHAN5G(100, 5500, 0),
4698 CHAN5G(104, 5520, 0),
4699 CHAN5G(108, 5540, 0),
4700 CHAN5G(112, 5560, 0),
4701 CHAN5G(116, 5580, 0),
4702 CHAN5G(120, 5600, 0),
4703 CHAN5G(124, 5620, 0),
4704 CHAN5G(128, 5640, 0),
4705 CHAN5G(132, 5660, 0),
4706 CHAN5G(136, 5680, 0),
4707 CHAN5G(140, 5700, 0),
4708 CHAN5G(149, 5745, 0),
4709 CHAN5G(153, 5765, 0),
4710 CHAN5G(157, 5785, 0),
4711 CHAN5G(161, 5805, 0),
4712 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004713};
4714
4715static struct ieee80211_rate ath10k_rates[] = {
4716 /* CCK */
4717 RATETAB_ENT(10, 0x82, 0),
4718 RATETAB_ENT(20, 0x84, 0),
4719 RATETAB_ENT(55, 0x8b, 0),
4720 RATETAB_ENT(110, 0x96, 0),
4721 /* OFDM */
4722 RATETAB_ENT(60, 0x0c, 0),
4723 RATETAB_ENT(90, 0x12, 0),
4724 RATETAB_ENT(120, 0x18, 0),
4725 RATETAB_ENT(180, 0x24, 0),
4726 RATETAB_ENT(240, 0x30, 0),
4727 RATETAB_ENT(360, 0x48, 0),
4728 RATETAB_ENT(480, 0x60, 0),
4729 RATETAB_ENT(540, 0x6c, 0),
4730};
4731
4732#define ath10k_a_rates (ath10k_rates + 4)
4733#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4734#define ath10k_g_rates (ath10k_rates + 0)
4735#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4736
Michal Kaziore7b54192014-08-07 11:03:27 +02004737struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004738{
4739 struct ieee80211_hw *hw;
4740 struct ath10k *ar;
4741
Michal Kaziore7b54192014-08-07 11:03:27 +02004742 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004743 if (!hw)
4744 return NULL;
4745
4746 ar = hw->priv;
4747 ar->hw = hw;
4748
4749 return ar;
4750}
4751
4752void ath10k_mac_destroy(struct ath10k *ar)
4753{
4754 ieee80211_free_hw(ar->hw);
4755}
4756
4757static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4758 {
4759 .max = 8,
4760 .types = BIT(NL80211_IFTYPE_STATION)
4761 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004762 },
4763 {
4764 .max = 3,
4765 .types = BIT(NL80211_IFTYPE_P2P_GO)
4766 },
4767 {
4768 .max = 7,
4769 .types = BIT(NL80211_IFTYPE_AP)
4770 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771};
4772
Bartosz Markowskif2595092013-12-10 16:20:39 +01004773static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004774 {
4775 .max = 8,
4776 .types = BIT(NL80211_IFTYPE_AP)
4777 },
4778};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004779
4780static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4781 {
4782 .limits = ath10k_if_limits,
4783 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4784 .max_interfaces = 8,
4785 .num_different_channels = 1,
4786 .beacon_int_infra_match = true,
4787 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004788};
4789
4790static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004791 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004792 .limits = ath10k_10x_if_limits,
4793 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004794 .max_interfaces = 8,
4795 .num_different_channels = 1,
4796 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004797#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004798 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4799 BIT(NL80211_CHAN_WIDTH_20) |
4800 BIT(NL80211_CHAN_WIDTH_40) |
4801 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004802#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004803 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004804};
4805
4806static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4807{
4808 struct ieee80211_sta_vht_cap vht_cap = {0};
4809 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004810 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004811
4812 vht_cap.vht_supported = 1;
4813 vht_cap.cap = ar->vht_cap_info;
4814
Michal Kazior8865bee42013-07-24 12:36:46 +02004815 mcs_map = 0;
4816 for (i = 0; i < 8; i++) {
4817 if (i < ar->num_rf_chains)
4818 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4819 else
4820 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4821 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004822
4823 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4824 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4825
4826 return vht_cap;
4827}
4828
4829static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4830{
4831 int i;
4832 struct ieee80211_sta_ht_cap ht_cap = {0};
4833
4834 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4835 return ht_cap;
4836
4837 ht_cap.ht_supported = 1;
4838 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4839 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4840 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4841 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4842 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4843
4844 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4845 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4846
4847 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4848 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4849
4850 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4851 u32 smps;
4852
4853 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4854 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4855
4856 ht_cap.cap |= smps;
4857 }
4858
4859 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4860 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4861
4862 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4863 u32 stbc;
4864
4865 stbc = ar->ht_cap_info;
4866 stbc &= WMI_HT_CAP_RX_STBC;
4867 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4868 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4869 stbc &= IEEE80211_HT_CAP_RX_STBC;
4870
4871 ht_cap.cap |= stbc;
4872 }
4873
4874 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4875 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4876
4877 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4878 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4879
4880 /* max AMSDU is implicitly taken from vht_cap_info */
4881 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4882 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4883
Michal Kazior8865bee42013-07-24 12:36:46 +02004884 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004885 ht_cap.mcs.rx_mask[i] = 0xFF;
4886
4887 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4888
4889 return ht_cap;
4890}
4891
Kalle Valo5e3dd152013-06-12 20:52:10 +03004892static void ath10k_get_arvif_iter(void *data, u8 *mac,
4893 struct ieee80211_vif *vif)
4894{
4895 struct ath10k_vif_iter *arvif_iter = data;
4896 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4897
4898 if (arvif->vdev_id == arvif_iter->vdev_id)
4899 arvif_iter->arvif = arvif;
4900}
4901
4902struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4903{
4904 struct ath10k_vif_iter arvif_iter;
4905 u32 flags;
4906
4907 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4908 arvif_iter.vdev_id = vdev_id;
4909
4910 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4911 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4912 flags,
4913 ath10k_get_arvif_iter,
4914 &arvif_iter);
4915 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004916 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004917 return NULL;
4918 }
4919
4920 return arvif_iter.arvif;
4921}
4922
4923int ath10k_mac_register(struct ath10k *ar)
4924{
4925 struct ieee80211_supported_band *band;
4926 struct ieee80211_sta_vht_cap vht_cap;
4927 struct ieee80211_sta_ht_cap ht_cap;
4928 void *channels;
4929 int ret;
4930
4931 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4932
4933 SET_IEEE80211_DEV(ar->hw, ar->dev);
4934
4935 ht_cap = ath10k_get_ht_cap(ar);
4936 vht_cap = ath10k_create_vht_cap(ar);
4937
4938 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4939 channels = kmemdup(ath10k_2ghz_channels,
4940 sizeof(ath10k_2ghz_channels),
4941 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004942 if (!channels) {
4943 ret = -ENOMEM;
4944 goto err_free;
4945 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004946
4947 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4948 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4949 band->channels = channels;
4950 band->n_bitrates = ath10k_g_rates_size;
4951 band->bitrates = ath10k_g_rates;
4952 band->ht_cap = ht_cap;
4953
4954 /* vht is not supported in 2.4 GHz */
4955
4956 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4957 }
4958
4959 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4960 channels = kmemdup(ath10k_5ghz_channels,
4961 sizeof(ath10k_5ghz_channels),
4962 GFP_KERNEL);
4963 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004964 ret = -ENOMEM;
4965 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004966 }
4967
4968 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4969 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4970 band->channels = channels;
4971 band->n_bitrates = ath10k_a_rates_size;
4972 band->bitrates = ath10k_a_rates;
4973 band->ht_cap = ht_cap;
4974 band->vht_cap = vht_cap;
4975 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4976 }
4977
4978 ar->hw->wiphy->interface_modes =
4979 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004980 BIT(NL80211_IFTYPE_AP);
4981
Ben Greear46acf7b2014-05-16 17:15:38 +03004982 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4983 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4984
Bartosz Markowskid3541812013-12-10 16:20:40 +01004985 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4986 ar->hw->wiphy->interface_modes |=
4987 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4988 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004989
4990 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4991 IEEE80211_HW_SUPPORTS_PS |
4992 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4993 IEEE80211_HW_SUPPORTS_UAPSD |
4994 IEEE80211_HW_MFP_CAPABLE |
4995 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4996 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004997 IEEE80211_HW_AP_LINK_PS |
4998 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004999
Eliad Peller0d8614b2014-09-10 14:07:36 +03005000 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5001
Kalle Valo5e3dd152013-06-12 20:52:10 +03005002 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005003 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005004
5005 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5006 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5007 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5008 }
5009
5010 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5011 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5012
5013 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005014 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005015
Kalle Valo5e3dd152013-06-12 20:52:10 +03005016 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5017
5018 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005019 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005020 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5021
5022 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005023 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5024
Kalle Valo5e3dd152013-06-12 20:52:10 +03005025 /*
5026 * on LL hardware queues are managed entirely by the FW
5027 * so we only advertise to mac we can do the queues thing
5028 */
5029 ar->hw->queues = 4;
5030
Bartosz Markowskif2595092013-12-10 16:20:39 +01005031 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
5032 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5033 ar->hw->wiphy->n_iface_combinations =
5034 ARRAY_SIZE(ath10k_10x_if_comb);
5035 } else {
5036 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5037 ar->hw->wiphy->n_iface_combinations =
5038 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005039
5040 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01005041 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005042
Michal Kazior7c199992013-07-31 10:47:57 +02005043 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5044
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005045 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5046 /* Init ath dfs pattern detector */
5047 ar->ath_common.debug_mask = ATH_DBG_DFS;
5048 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5049 NL80211_DFS_UNSET);
5050
5051 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005052 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005053 }
5054
Kalle Valo5e3dd152013-06-12 20:52:10 +03005055 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5056 ath10k_reg_notifier);
5057 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005058 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005059 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005060 }
5061
5062 ret = ieee80211_register_hw(ar->hw);
5063 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005064 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005065 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005066 }
5067
5068 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5069 ret = regulatory_hint(ar->hw->wiphy,
5070 ar->ath_common.regulatory.alpha2);
5071 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005072 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005073 }
5074
5075 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005076
5077err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005078 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005079err_free:
5080 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5081 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5082
Kalle Valo5e3dd152013-06-12 20:52:10 +03005083 return ret;
5084}
5085
5086void ath10k_mac_unregister(struct ath10k *ar)
5087{
5088 ieee80211_unregister_hw(ar->hw);
5089
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005090 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5091 ar->dfs_detector->exit(ar->dfs_detector);
5092
Kalle Valo5e3dd152013-06-12 20:52:10 +03005093 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5094 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5095
5096 SET_IEEE80211_DEV(ar->hw, NULL);
5097}