blob: 9e4748fbcf8a3a9f9845f7c07ee801bde6b7fb98 [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
182static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
183 struct ieee80211_key_conf *key)
184{
185 struct ath10k *ar = arvif->ar;
186 struct ath10k_peer *peer;
187 u8 addr[ETH_ALEN];
188 int first_errno = 0;
189 int ret;
190 int i;
191
192 lockdep_assert_held(&ar->conf_mutex);
193
194 for (;;) {
195 /* since ath10k_install_key we can't hold data_lock all the
196 * time, so we try to remove the keys incrementally */
197 spin_lock_bh(&ar->data_lock);
198 i = 0;
199 list_for_each_entry(peer, &ar->peers, list) {
200 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
201 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300202 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300203 peer->keys[i] = NULL;
204 break;
205 }
206 }
207
208 if (i < ARRAY_SIZE(peer->keys))
209 break;
210 }
211 spin_unlock_bh(&ar->data_lock);
212
213 if (i == ARRAY_SIZE(peer->keys))
214 break;
215
216 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
217 if (ret && first_errno == 0)
218 first_errno = ret;
219
220 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200221 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200222 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300223 }
224
225 return first_errno;
226}
227
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228/*********************/
229/* General utilities */
230/*********************/
231
232static inline enum wmi_phy_mode
233chan_to_phymode(const struct cfg80211_chan_def *chandef)
234{
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
241 phymode = MODE_11G;
242 break;
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
245 break;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
248 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
255 break;
256 }
257 break;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
261 phymode = MODE_11A;
262 break;
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
265 break;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
268 break;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
271 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
277 break;
278 }
279 break;
280 default:
281 break;
282 }
283
284 WARN_ON(phymode == MODE_UNKNOWN);
285 return phymode;
286}
287
288static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
289{
290/*
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
293 * 1 for 1/4 us
294 * 2 for 1/2 us
295 * 3 for 1 us
296 * 4 for 2 us
297 * 5 for 4 us
298 * 6 for 8 us
299 * 7 for 16 us
300 */
301 switch (mpdudensity) {
302 case 0:
303 return 0;
304 case 1:
305 case 2:
306 case 3:
307 /* Our lower layer calculations limit our precision to
308 1 microsecond */
309 return 1;
310 case 4:
311 return 2;
312 case 5:
313 return 4;
314 case 6:
315 return 8;
316 case 7:
317 return 16;
318 default:
319 return 0;
320 }
321}
322
323static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
324{
325 int ret;
326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800330 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200332 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200339 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800341 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100342 spin_lock_bh(&ar->data_lock);
343 ar->num_peers++;
344 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300345
346 return 0;
347}
348
Kalle Valo5a13e762014-01-20 11:01:46 +0200349static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350{
351 struct ath10k *ar = arvif->ar;
352 u32 param;
353 int ret;
354
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
358 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200360 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200361 return ret;
362 }
363
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200370 return ret;
371 }
372
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200378 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200379 return ret;
380 }
381
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200387 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200388 return ret;
389 }
390
391 return 0;
392}
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200396 struct ath10k *ar = arvif->ar;
397 u32 vdev_param;
398
Michal Kazior424121c2013-07-22 14:13:31 +0200399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
401 ATH10K_RTS_MAX);
402
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200405}
406
407static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 struct ath10k *ar = arvif->ar;
410 u32 vdev_param;
411
Michal Kazior424121c2013-07-22 14:13:31 +0200412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
416
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
422{
423 int ret;
424
425 lockdep_assert_held(&ar->conf_mutex);
426
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
428 if (ret)
429 return ret;
430
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
432 if (ret)
433 return ret;
434
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100435 spin_lock_bh(&ar->data_lock);
436 ar->num_peers--;
437 spin_unlock_bh(&ar->data_lock);
438
Kalle Valo5e3dd152013-06-12 20:52:10 +0300439 return 0;
440}
441
442static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443{
444 struct ath10k_peer *peer, *tmp;
445
446 lockdep_assert_held(&ar->conf_mutex);
447
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
451 continue;
452
Michal Kazior7aa7a722014-08-25 12:09:38 +0200453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 peer->addr, vdev_id);
455
456 list_del(&peer->list);
457 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100458 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 }
460 spin_unlock_bh(&ar->data_lock);
461}
462
Michal Kaziora96d7742013-07-16 09:38:56 +0200463static void ath10k_peer_cleanup_all(struct ath10k *ar)
464{
465 struct ath10k_peer *peer, *tmp;
466
467 lockdep_assert_held(&ar->conf_mutex);
468
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
472 kfree(peer);
473 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200475 spin_unlock_bh(&ar->data_lock);
476}
477
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478/************************/
479/* Interface management */
480/************************/
481
Michal Kazior64badcb2014-09-18 11:18:02 +0300482void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
483{
484 struct ath10k *ar = arvif->ar;
485
486 lockdep_assert_held(&ar->data_lock);
487
488 if (!arvif->beacon)
489 return;
490
491 if (!arvif->beacon_buf)
492 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
493 arvif->beacon->len, DMA_TO_DEVICE);
494
495 dev_kfree_skb_any(arvif->beacon);
496
497 arvif->beacon = NULL;
498 arvif->beacon_sent = false;
499}
500
501static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
502{
503 struct ath10k *ar = arvif->ar;
504
505 lockdep_assert_held(&ar->data_lock);
506
507 ath10k_mac_vif_beacon_free(arvif);
508
509 if (arvif->beacon_buf) {
510 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
511 arvif->beacon_buf, arvif->beacon_paddr);
512 arvif->beacon_buf = NULL;
513 }
514}
515
Kalle Valo5e3dd152013-06-12 20:52:10 +0300516static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
517{
518 int ret;
519
Michal Kazior548db542013-07-05 16:15:15 +0300520 lockdep_assert_held(&ar->conf_mutex);
521
Michal Kazior7962b0d2014-10-28 10:34:38 +0100522 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
523 return -ESHUTDOWN;
524
Kalle Valo5e3dd152013-06-12 20:52:10 +0300525 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
526 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
527 if (ret == 0)
528 return -ETIMEDOUT;
529
530 return 0;
531}
532
Michal Kazior1bbc0972014-04-08 09:45:47 +0300533static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300534{
Michal Kaziorc930f742014-01-23 11:38:25 +0100535 struct cfg80211_chan_def *chandef = &ar->chandef;
536 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300537 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300538 int ret = 0;
539
540 lockdep_assert_held(&ar->conf_mutex);
541
Kalle Valo5e3dd152013-06-12 20:52:10 +0300542 arg.vdev_id = vdev_id;
543 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100544 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545
546 /* TODO setup this dynamically, what in case we
547 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100548 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200549 arg.channel.chan_radar =
550 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300551
Michal Kazior89c5c842013-10-23 04:02:13 -0700552 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700553 arg.channel.max_power = channel->max_power * 2;
554 arg.channel.max_reg_power = channel->max_reg_power * 2;
555 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300556
Michal Kazior7962b0d2014-10-28 10:34:38 +0100557 reinit_completion(&ar->vdev_setup_done);
558
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559 ret = ath10k_wmi_vdev_start(ar, &arg);
560 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200561 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200562 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563 return ret;
564 }
565
566 ret = ath10k_vdev_setup_sync(ar);
567 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200568 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200569 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570 return ret;
571 }
572
573 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
574 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200575 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200576 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577 goto vdev_stop;
578 }
579
580 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581
Michal Kazior7aa7a722014-08-25 12:09:38 +0200582 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300583 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584 return 0;
585
586vdev_stop:
587 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
588 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200589 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200590 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591
592 return ret;
593}
594
Michal Kazior1bbc0972014-04-08 09:45:47 +0300595static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300596{
597 int ret = 0;
598
599 lockdep_assert_held(&ar->conf_mutex);
600
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200601 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
602 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200603 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200604 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300605
Michal Kazior7962b0d2014-10-28 10:34:38 +0100606 reinit_completion(&ar->vdev_setup_done);
607
Kalle Valo5e3dd152013-06-12 20:52:10 +0300608 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
609 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200610 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200611 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300612
613 ret = ath10k_vdev_setup_sync(ar);
614 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200615 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200616 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300617
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300619 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 return ret;
621}
622
Michal Kazior1bbc0972014-04-08 09:45:47 +0300623static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624{
625 int bit, ret = 0;
626
627 lockdep_assert_held(&ar->conf_mutex);
628
Ben Greeara9aefb32014-08-12 11:02:19 +0300629 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200630 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300631 return -ENOMEM;
632 }
633
Ben Greear16c11172014-09-23 14:17:16 -0700634 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300635
Ben Greear16c11172014-09-23 14:17:16 -0700636 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637
638 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
639 WMI_VDEV_TYPE_MONITOR,
640 0, ar->mac_addr);
641 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200642 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200643 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300644 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645 }
646
Ben Greear16c11172014-09-23 14:17:16 -0700647 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200648 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 ar->monitor_vdev_id);
650
Kalle Valo5e3dd152013-06-12 20:52:10 +0300651 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300652}
653
Michal Kazior1bbc0972014-04-08 09:45:47 +0300654static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655{
656 int ret = 0;
657
658 lockdep_assert_held(&ar->conf_mutex);
659
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
661 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200662 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200663 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300664 return ret;
665 }
666
Ben Greear16c11172014-09-23 14:17:16 -0700667 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300668
Michal Kazior7aa7a722014-08-25 12:09:38 +0200669 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670 ar->monitor_vdev_id);
671 return ret;
672}
673
Michal Kazior1bbc0972014-04-08 09:45:47 +0300674static int ath10k_monitor_start(struct ath10k *ar)
675{
676 int ret;
677
678 lockdep_assert_held(&ar->conf_mutex);
679
Michal Kazior1bbc0972014-04-08 09:45:47 +0300680 ret = ath10k_monitor_vdev_create(ar);
681 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200682 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300683 return ret;
684 }
685
686 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
687 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200688 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300689 ath10k_monitor_vdev_delete(ar);
690 return ret;
691 }
692
693 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300695
696 return 0;
697}
698
Michal Kazior19337472014-08-28 12:58:16 +0200699static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300700{
701 int ret;
702
703 lockdep_assert_held(&ar->conf_mutex);
704
Michal Kazior1bbc0972014-04-08 09:45:47 +0300705 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200706 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200707 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200708 return ret;
709 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300710
711 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200712 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200713 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200714 return ret;
715 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300716
717 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200718 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200719
720 return 0;
721}
722
723static int ath10k_monitor_recalc(struct ath10k *ar)
724{
725 bool should_start;
726
727 lockdep_assert_held(&ar->conf_mutex);
728
729 should_start = ar->monitor ||
730 ar->filter_flags & FIF_PROMISC_IN_BSS ||
731 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
732
733 ath10k_dbg(ar, ATH10K_DBG_MAC,
734 "mac monitor recalc started? %d should? %d\n",
735 ar->monitor_started, should_start);
736
737 if (should_start == ar->monitor_started)
738 return 0;
739
740 if (should_start)
741 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300742
743 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300744}
745
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200746static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
747{
748 struct ath10k *ar = arvif->ar;
749 u32 vdev_param, rts_cts = 0;
750
751 lockdep_assert_held(&ar->conf_mutex);
752
753 vdev_param = ar->wmi.vdev_param->enable_rtscts;
754
755 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
756 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
757
758 if (arvif->num_legacy_stations > 0)
759 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
760 WMI_RTSCTS_PROFILE);
761
762 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
763 rts_cts);
764}
765
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200766static int ath10k_start_cac(struct ath10k *ar)
767{
768 int ret;
769
770 lockdep_assert_held(&ar->conf_mutex);
771
772 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
773
Michal Kazior19337472014-08-28 12:58:16 +0200774 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200775 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200776 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200777 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
778 return ret;
779 }
780
Michal Kazior7aa7a722014-08-25 12:09:38 +0200781 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200782 ar->monitor_vdev_id);
783
784 return 0;
785}
786
787static int ath10k_stop_cac(struct ath10k *ar)
788{
789 lockdep_assert_held(&ar->conf_mutex);
790
791 /* CAC is not running - do nothing */
792 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
793 return 0;
794
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200795 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300796 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200797
Michal Kazior7aa7a722014-08-25 12:09:38 +0200798 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200799
800 return 0;
801}
802
Michal Kaziord6500972014-04-08 09:56:09 +0300803static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200804{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200805 int ret;
806
807 lockdep_assert_held(&ar->conf_mutex);
808
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200809 ath10k_stop_cac(ar);
810
Michal Kaziord6500972014-04-08 09:56:09 +0300811 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200812 return;
813
Michal Kaziord6500972014-04-08 09:56:09 +0300814 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200815 return;
816
817 ret = ath10k_start_cac(ar);
818 if (ret) {
819 /*
820 * Not possible to start CAC on current channel so starting
821 * radiation is not allowed, make this channel DFS_UNAVAILABLE
822 * by indicating that radar was detected.
823 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200824 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200825 ieee80211_radar_detected(ar->hw);
826 }
827}
828
Michal Kaziordc55e302014-07-29 12:53:36 +0300829static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300830{
831 struct ath10k *ar = arvif->ar;
832 struct cfg80211_chan_def *chandef = &ar->chandef;
833 struct wmi_vdev_start_request_arg arg = {};
834 int ret = 0;
835
836 lockdep_assert_held(&ar->conf_mutex);
837
838 reinit_completion(&ar->vdev_setup_done);
839
840 arg.vdev_id = arvif->vdev_id;
841 arg.dtim_period = arvif->dtim_period;
842 arg.bcn_intval = arvif->beacon_interval;
843
844 arg.channel.freq = chandef->chan->center_freq;
845 arg.channel.band_center_freq1 = chandef->center_freq1;
846 arg.channel.mode = chan_to_phymode(chandef);
847
848 arg.channel.min_power = 0;
849 arg.channel.max_power = chandef->chan->max_power * 2;
850 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
851 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
852
853 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
854 arg.ssid = arvif->u.ap.ssid;
855 arg.ssid_len = arvif->u.ap.ssid_len;
856 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
857
858 /* For now allow DFS for AP mode */
859 arg.channel.chan_radar =
860 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
861 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
862 arg.ssid = arvif->vif->bss_conf.ssid;
863 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
864 }
865
Michal Kazior7aa7a722014-08-25 12:09:38 +0200866 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300867 "mac vdev %d start center_freq %d phymode %s\n",
868 arg.vdev_id, arg.channel.freq,
869 ath10k_wmi_phymode_str(arg.channel.mode));
870
Michal Kaziordc55e302014-07-29 12:53:36 +0300871 if (restart)
872 ret = ath10k_wmi_vdev_restart(ar, &arg);
873 else
874 ret = ath10k_wmi_vdev_start(ar, &arg);
875
Michal Kazior72654fa2014-04-08 09:56:09 +0300876 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200877 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300878 arg.vdev_id, ret);
879 return ret;
880 }
881
882 ret = ath10k_vdev_setup_sync(ar);
883 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200884 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300885 arg.vdev_id, ret);
886 return ret;
887 }
888
Michal Kaziord6500972014-04-08 09:56:09 +0300889 ar->num_started_vdevs++;
890 ath10k_recalc_radar_detection(ar);
891
Michal Kazior72654fa2014-04-08 09:56:09 +0300892 return ret;
893}
894
Michal Kaziordc55e302014-07-29 12:53:36 +0300895static int ath10k_vdev_start(struct ath10k_vif *arvif)
896{
897 return ath10k_vdev_start_restart(arvif, false);
898}
899
900static int ath10k_vdev_restart(struct ath10k_vif *arvif)
901{
902 return ath10k_vdev_start_restart(arvif, true);
903}
904
Michal Kazior72654fa2014-04-08 09:56:09 +0300905static int ath10k_vdev_stop(struct ath10k_vif *arvif)
906{
907 struct ath10k *ar = arvif->ar;
908 int ret;
909
910 lockdep_assert_held(&ar->conf_mutex);
911
912 reinit_completion(&ar->vdev_setup_done);
913
914 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
915 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200916 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300917 arvif->vdev_id, ret);
918 return ret;
919 }
920
921 ret = ath10k_vdev_setup_sync(ar);
922 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200923 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300924 arvif->vdev_id, ret);
925 return ret;
926 }
927
Michal Kaziord6500972014-04-08 09:56:09 +0300928 WARN_ON(ar->num_started_vdevs == 0);
929
930 if (ar->num_started_vdevs != 0) {
931 ar->num_started_vdevs--;
932 ath10k_recalc_radar_detection(ar);
933 }
934
Michal Kazior72654fa2014-04-08 09:56:09 +0300935 return ret;
936}
937
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +0300939 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300940{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200941 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942 int ret = 0;
943
Michal Kazior548db542013-07-05 16:15:15 +0300944 lockdep_assert_held(&arvif->ar->conf_mutex);
945
Kalle Valo5e3dd152013-06-12 20:52:10 +0300946 if (!info->enable_beacon) {
947 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100948
949 arvif->is_started = false;
950 arvif->is_up = false;
951
Michal Kazior748afc42014-01-23 12:48:21 +0100952 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +0300953 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +0100954 spin_unlock_bh(&arvif->ar->data_lock);
955
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956 return;
957 }
958
959 arvif->tx_seq_no = 0x1000;
960
961 ret = ath10k_vdev_start(arvif);
962 if (ret)
963 return;
964
Michal Kaziorc930f742014-01-23 11:38:25 +0100965 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +0300966 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +0100967
968 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
969 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200971 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200972 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100973 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300974 return;
975 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100976
977 arvif->is_started = true;
978 arvif->is_up = true;
979
Michal Kazior7aa7a722014-08-25 12:09:38 +0200980 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300981}
982
983static void ath10k_control_ibss(struct ath10k_vif *arvif,
984 struct ieee80211_bss_conf *info,
985 const u8 self_peer[ETH_ALEN])
986{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200987 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200988 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300989 int ret = 0;
990
Michal Kazior548db542013-07-05 16:15:15 +0300991 lockdep_assert_held(&arvif->ar->conf_mutex);
992
Kalle Valo5e3dd152013-06-12 20:52:10 +0300993 if (!info->ibss_joined) {
994 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
995 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200996 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300997 self_peer, arvif->vdev_id, ret);
998
Michal Kaziorc930f742014-01-23 11:38:25 +0100999 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001000 return;
1001
Michal Kaziorc930f742014-01-23 11:38:25 +01001002 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001003
1004 return;
1005 }
1006
1007 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1008 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001009 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001010 self_peer, arvif->vdev_id, ret);
1011 return;
1012 }
1013
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001014 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1015 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001016 ATH10K_DEFAULT_ATIM);
1017 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001018 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001019 arvif->vdev_id, ret);
1020}
1021
1022/*
1023 * Review this when mac80211 gains per-interface powersave support.
1024 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001025static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001026{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001027 struct ath10k *ar = arvif->ar;
1028 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001029 enum wmi_sta_powersave_param param;
1030 enum wmi_sta_ps_mode psmode;
1031 int ret;
1032
Michal Kazior548db542013-07-05 16:15:15 +03001033 lockdep_assert_held(&arvif->ar->conf_mutex);
1034
Michal Kaziorad088bf2013-10-16 15:44:46 +03001035 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1036 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001037
1038 if (conf->flags & IEEE80211_CONF_PS) {
1039 psmode = WMI_STA_PS_MODE_ENABLED;
1040 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1041
Michal Kaziorad088bf2013-10-16 15:44:46 +03001042 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001043 conf->dynamic_ps_timeout);
1044 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001045 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001046 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001047 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001048 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001049 } else {
1050 psmode = WMI_STA_PS_MODE_DISABLED;
1051 }
1052
Michal Kazior7aa7a722014-08-25 12:09:38 +02001053 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001054 arvif->vdev_id, psmode ? "enable" : "disable");
1055
Michal Kaziorad088bf2013-10-16 15:44:46 +03001056 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1057 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001058 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001059 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001060 return ret;
1061 }
1062
1063 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001064}
1065
1066/**********************/
1067/* Station management */
1068/**********************/
1069
Michal Kazior590922a2014-10-21 10:10:29 +03001070static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1071 struct ieee80211_vif *vif)
1072{
1073 /* Some firmware revisions have unstable STA powersave when listen
1074 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1075 * generate NullFunc frames properly even if buffered frames have been
1076 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1077 * buffered frames. Often pinging the device from AP would simply fail.
1078 *
1079 * As a workaround set it to 1.
1080 */
1081 if (vif->type == NL80211_IFTYPE_STATION)
1082 return 1;
1083
1084 return ar->hw->conf.listen_interval;
1085}
1086
Kalle Valo5e3dd152013-06-12 20:52:10 +03001087static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001088 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001089 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090 struct wmi_peer_assoc_complete_arg *arg)
1091{
Michal Kazior590922a2014-10-21 10:10:29 +03001092 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1093
Michal Kazior548db542013-07-05 16:15:15 +03001094 lockdep_assert_held(&ar->conf_mutex);
1095
Kalle Valob25f32c2014-09-14 12:50:49 +03001096 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001097 arg->vdev_id = arvif->vdev_id;
1098 arg->peer_aid = sta->aid;
1099 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001100 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001101 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001102 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001103}
1104
1105static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001106 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001107 struct wmi_peer_assoc_complete_arg *arg)
1108{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001109 struct ieee80211_bss_conf *info = &vif->bss_conf;
1110 struct cfg80211_bss *bss;
1111 const u8 *rsnie = NULL;
1112 const u8 *wpaie = NULL;
1113
Michal Kazior548db542013-07-05 16:15:15 +03001114 lockdep_assert_held(&ar->conf_mutex);
1115
Kalle Valo5e3dd152013-06-12 20:52:10 +03001116 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1117 info->bssid, NULL, 0, 0, 0);
1118 if (bss) {
1119 const struct cfg80211_bss_ies *ies;
1120
1121 rcu_read_lock();
1122 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1123
1124 ies = rcu_dereference(bss->ies);
1125
1126 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001127 WLAN_OUI_TYPE_MICROSOFT_WPA,
1128 ies->data,
1129 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001130 rcu_read_unlock();
1131 cfg80211_put_bss(ar->hw->wiphy, bss);
1132 }
1133
1134 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1135 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001136 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001137 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1138 }
1139
1140 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001141 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001142 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1143 }
1144}
1145
1146static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1147 struct ieee80211_sta *sta,
1148 struct wmi_peer_assoc_complete_arg *arg)
1149{
1150 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1151 const struct ieee80211_supported_band *sband;
1152 const struct ieee80211_rate *rates;
1153 u32 ratemask;
1154 int i;
1155
Michal Kazior548db542013-07-05 16:15:15 +03001156 lockdep_assert_held(&ar->conf_mutex);
1157
Kalle Valo5e3dd152013-06-12 20:52:10 +03001158 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1159 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1160 rates = sband->bitrates;
1161
1162 rateset->num_rates = 0;
1163
1164 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1165 if (!(ratemask & 1))
1166 continue;
1167
1168 rateset->rates[rateset->num_rates] = rates->hw_value;
1169 rateset->num_rates++;
1170 }
1171}
1172
1173static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1174 struct ieee80211_sta *sta,
1175 struct wmi_peer_assoc_complete_arg *arg)
1176{
1177 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001178 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001179 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001180
Michal Kazior548db542013-07-05 16:15:15 +03001181 lockdep_assert_held(&ar->conf_mutex);
1182
Kalle Valo5e3dd152013-06-12 20:52:10 +03001183 if (!ht_cap->ht_supported)
1184 return;
1185
1186 arg->peer_flags |= WMI_PEER_HT;
1187 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1188 ht_cap->ampdu_factor)) - 1;
1189
1190 arg->peer_mpdu_density =
1191 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1192
1193 arg->peer_ht_caps = ht_cap->cap;
1194 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1195
1196 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1197 arg->peer_flags |= WMI_PEER_LDPC;
1198
1199 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1200 arg->peer_flags |= WMI_PEER_40MHZ;
1201 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1202 }
1203
1204 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1205 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1206
1207 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1208 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1209
1210 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1211 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1212 arg->peer_flags |= WMI_PEER_STBC;
1213 }
1214
1215 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001216 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1217 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1218 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1219 arg->peer_rate_caps |= stbc;
1220 arg->peer_flags |= WMI_PEER_STBC;
1221 }
1222
Kalle Valo5e3dd152013-06-12 20:52:10 +03001223 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1224 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1225 else if (ht_cap->mcs.rx_mask[1])
1226 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1227
1228 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1229 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1230 arg->peer_ht_rates.rates[n++] = i;
1231
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001232 /*
1233 * This is a workaround for HT-enabled STAs which break the spec
1234 * and have no HT capabilities RX mask (no HT RX MCS map).
1235 *
1236 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1237 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1238 *
1239 * Firmware asserts if such situation occurs.
1240 */
1241 if (n == 0) {
1242 arg->peer_ht_rates.num_rates = 8;
1243 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1244 arg->peer_ht_rates.rates[i] = i;
1245 } else {
1246 arg->peer_ht_rates.num_rates = n;
1247 arg->peer_num_spatial_streams = sta->rx_nss;
1248 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001249
Michal Kazior7aa7a722014-08-25 12:09:38 +02001250 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001251 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001252 arg->peer_ht_rates.num_rates,
1253 arg->peer_num_spatial_streams);
1254}
1255
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001256static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1257 struct ath10k_vif *arvif,
1258 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259{
1260 u32 uapsd = 0;
1261 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001262 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263
Michal Kazior548db542013-07-05 16:15:15 +03001264 lockdep_assert_held(&ar->conf_mutex);
1265
Kalle Valo5e3dd152013-06-12 20:52:10 +03001266 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001268 sta->uapsd_queues, sta->max_sp);
1269
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1271 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1272 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1273 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1274 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1275 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1276 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1277 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1278 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1279 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1280 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1281 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1282
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1284 max_sp = sta->max_sp;
1285
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001286 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1287 sta->addr,
1288 WMI_AP_PS_PEER_PARAM_UAPSD,
1289 uapsd);
1290 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001291 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001292 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001293 return ret;
1294 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001296 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1297 sta->addr,
1298 WMI_AP_PS_PEER_PARAM_MAX_SP,
1299 max_sp);
1300 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001301 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001302 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001303 return ret;
1304 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305
1306 /* TODO setup this based on STA listen interval and
1307 beacon interval. Currently we don't know
1308 sta->listen_interval - mac80211 patch required.
1309 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001310 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001311 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1312 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001313 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001314 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001315 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001316 return ret;
1317 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001318 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001319
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001320 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001321}
1322
1323static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1324 struct ieee80211_sta *sta,
1325 struct wmi_peer_assoc_complete_arg *arg)
1326{
1327 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001328 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001329
1330 if (!vht_cap->vht_supported)
1331 return;
1332
1333 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001334 arg->peer_vht_caps = vht_cap->cap;
1335
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001336 ampdu_factor = (vht_cap->cap &
1337 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1338 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1339
1340 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1341 * zero in VHT IE. Using it would result in degraded throughput.
1342 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1343 * it if VHT max_mpdu is smaller. */
1344 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1345 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1346 ampdu_factor)) - 1);
1347
Kalle Valo5e3dd152013-06-12 20:52:10 +03001348 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1349 arg->peer_flags |= WMI_PEER_80MHZ;
1350
1351 arg->peer_vht_rates.rx_max_rate =
1352 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1353 arg->peer_vht_rates.rx_mcs_set =
1354 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1355 arg->peer_vht_rates.tx_max_rate =
1356 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1357 arg->peer_vht_rates.tx_mcs_set =
1358 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1359
Michal Kazior7aa7a722014-08-25 12:09:38 +02001360 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001361 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362}
1363
1364static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001365 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367 struct wmi_peer_assoc_complete_arg *arg)
1368{
Michal Kazior590922a2014-10-21 10:10:29 +03001369 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1370
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 switch (arvif->vdev_type) {
1372 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001373 if (sta->wme)
1374 arg->peer_flags |= WMI_PEER_QOS;
1375
1376 if (sta->wme && sta->uapsd_queues) {
1377 arg->peer_flags |= WMI_PEER_APSD;
1378 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1379 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001380 break;
1381 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001382 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001383 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 break;
1385 default:
1386 break;
1387 }
1388}
1389
1390static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001391 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001392 struct ieee80211_sta *sta,
1393 struct wmi_peer_assoc_complete_arg *arg)
1394{
1395 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1396
Kalle Valo5e3dd152013-06-12 20:52:10 +03001397 switch (ar->hw->conf.chandef.chan->band) {
1398 case IEEE80211_BAND_2GHZ:
1399 if (sta->ht_cap.ht_supported) {
1400 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1401 phymode = MODE_11NG_HT40;
1402 else
1403 phymode = MODE_11NG_HT20;
1404 } else {
1405 phymode = MODE_11G;
1406 }
1407
1408 break;
1409 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001410 /*
1411 * Check VHT first.
1412 */
1413 if (sta->vht_cap.vht_supported) {
1414 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1415 phymode = MODE_11AC_VHT80;
1416 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1417 phymode = MODE_11AC_VHT40;
1418 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1419 phymode = MODE_11AC_VHT20;
1420 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001421 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1422 phymode = MODE_11NA_HT40;
1423 else
1424 phymode = MODE_11NA_HT20;
1425 } else {
1426 phymode = MODE_11A;
1427 }
1428
1429 break;
1430 default:
1431 break;
1432 }
1433
Michal Kazior7aa7a722014-08-25 12:09:38 +02001434 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001435 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001436
Kalle Valo5e3dd152013-06-12 20:52:10 +03001437 arg->peer_phymode = phymode;
1438 WARN_ON(phymode == MODE_UNKNOWN);
1439}
1440
Kalle Valob9ada652013-10-16 15:44:46 +03001441static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001442 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001443 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001444 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001445{
Michal Kazior548db542013-07-05 16:15:15 +03001446 lockdep_assert_held(&ar->conf_mutex);
1447
Kalle Valob9ada652013-10-16 15:44:46 +03001448 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001449
Michal Kazior590922a2014-10-21 10:10:29 +03001450 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1451 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001452 ath10k_peer_assoc_h_rates(ar, sta, arg);
1453 ath10k_peer_assoc_h_ht(ar, sta, arg);
1454 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001455 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1456 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001457
Kalle Valob9ada652013-10-16 15:44:46 +03001458 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459}
1460
Michal Kazior90046f52014-02-14 14:45:51 +01001461static const u32 ath10k_smps_map[] = {
1462 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1463 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1464 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1465 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1466};
1467
1468static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1469 const u8 *addr,
1470 const struct ieee80211_sta_ht_cap *ht_cap)
1471{
1472 int smps;
1473
1474 if (!ht_cap->ht_supported)
1475 return 0;
1476
1477 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1478 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1479
1480 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1481 return -EINVAL;
1482
1483 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1484 WMI_PEER_SMPS_STATE,
1485 ath10k_smps_map[smps]);
1486}
1487
Kalle Valo5e3dd152013-06-12 20:52:10 +03001488/* can be called only in mac80211 callbacks due to `key_count` usage */
1489static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1490 struct ieee80211_vif *vif,
1491 struct ieee80211_bss_conf *bss_conf)
1492{
1493 struct ath10k *ar = hw->priv;
1494 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001495 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001496 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001497 struct ieee80211_sta *ap_sta;
1498 int ret;
1499
Michal Kazior548db542013-07-05 16:15:15 +03001500 lockdep_assert_held(&ar->conf_mutex);
1501
Michal Kazior077efc82014-10-21 10:10:29 +03001502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1503 arvif->vdev_id, arvif->bssid, arvif->aid);
1504
Kalle Valo5e3dd152013-06-12 20:52:10 +03001505 rcu_read_lock();
1506
1507 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1508 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001509 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001510 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001511 rcu_read_unlock();
1512 return;
1513 }
1514
Michal Kazior90046f52014-02-14 14:45:51 +01001515 /* ap_sta must be accessed only within rcu section which must be left
1516 * before calling ath10k_setup_peer_smps() which might sleep. */
1517 ht_cap = ap_sta->ht_cap;
1518
Michal Kazior590922a2014-10-21 10:10:29 +03001519 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001520 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001521 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001522 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001523 rcu_read_unlock();
1524 return;
1525 }
1526
1527 rcu_read_unlock();
1528
Kalle Valob9ada652013-10-16 15:44:46 +03001529 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1530 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001531 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001532 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001533 return;
1534 }
1535
Michal Kazior90046f52014-02-14 14:45:51 +01001536 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1537 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001538 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001539 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001540 return;
1541 }
1542
Michal Kazior7aa7a722014-08-25 12:09:38 +02001543 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001544 "mac vdev %d up (associated) bssid %pM aid %d\n",
1545 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1546
Michal Kazior077efc82014-10-21 10:10:29 +03001547 WARN_ON(arvif->is_up);
1548
Michal Kaziorc930f742014-01-23 11:38:25 +01001549 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001550 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001551
1552 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1553 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001554 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001556 return;
1557 }
1558
1559 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560}
1561
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1563 struct ieee80211_vif *vif)
1564{
1565 struct ath10k *ar = hw->priv;
1566 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1567 int ret;
1568
Michal Kazior548db542013-07-05 16:15:15 +03001569 lockdep_assert_held(&ar->conf_mutex);
1570
Michal Kazior077efc82014-10-21 10:10:29 +03001571 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1572 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001573
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001575 if (ret)
1576 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1577 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001578
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001579 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001580 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581}
1582
Michal Kazior590922a2014-10-21 10:10:29 +03001583static int ath10k_station_assoc(struct ath10k *ar,
1584 struct ieee80211_vif *vif,
1585 struct ieee80211_sta *sta,
1586 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587{
Michal Kazior590922a2014-10-21 10:10:29 +03001588 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001589 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590 int ret = 0;
1591
Michal Kazior548db542013-07-05 16:15:15 +03001592 lockdep_assert_held(&ar->conf_mutex);
1593
Michal Kazior590922a2014-10-21 10:10:29 +03001594 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001595 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001596 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001597 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001598 return ret;
1599 }
1600
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001601 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001602 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001604 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001605 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 return ret;
1607 }
1608
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001609 /* Re-assoc is run only to update supported rates for given station. It
1610 * doesn't make much sense to reconfigure the peer completely.
1611 */
1612 if (!reassoc) {
1613 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1614 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001615 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001616 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001617 arvif->vdev_id, ret);
1618 return ret;
1619 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001620
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001621 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1622 if (ret) {
1623 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1624 sta->addr, arvif->vdev_id, ret);
1625 return ret;
1626 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001628 if (!sta->wme) {
1629 arvif->num_legacy_stations++;
1630 ret = ath10k_recalc_rtscts_prot(arvif);
1631 if (ret) {
1632 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1633 arvif->vdev_id, ret);
1634 return ret;
1635 }
1636 }
1637
1638 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1639 if (ret) {
1640 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1641 arvif->vdev_id, ret);
1642 return ret;
1643 }
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001644 }
1645
Kalle Valo5e3dd152013-06-12 20:52:10 +03001646 return ret;
1647}
1648
Michal Kazior590922a2014-10-21 10:10:29 +03001649static int ath10k_station_disassoc(struct ath10k *ar,
1650 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001651 struct ieee80211_sta *sta)
1652{
Michal Kazior590922a2014-10-21 10:10:29 +03001653 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001654 int ret = 0;
1655
Michal Kazior548db542013-07-05 16:15:15 +03001656 lockdep_assert_held(&ar->conf_mutex);
1657
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001658 if (!sta->wme) {
1659 arvif->num_legacy_stations--;
1660 ret = ath10k_recalc_rtscts_prot(arvif);
1661 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001662 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001663 arvif->vdev_id, ret);
1664 return ret;
1665 }
1666 }
1667
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1669 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001670 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001671 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001672 return ret;
1673 }
1674
1675 return ret;
1676}
1677
1678/**************/
1679/* Regulatory */
1680/**************/
1681
1682static int ath10k_update_channel_list(struct ath10k *ar)
1683{
1684 struct ieee80211_hw *hw = ar->hw;
1685 struct ieee80211_supported_band **bands;
1686 enum ieee80211_band band;
1687 struct ieee80211_channel *channel;
1688 struct wmi_scan_chan_list_arg arg = {0};
1689 struct wmi_channel_arg *ch;
1690 bool passive;
1691 int len;
1692 int ret;
1693 int i;
1694
Michal Kazior548db542013-07-05 16:15:15 +03001695 lockdep_assert_held(&ar->conf_mutex);
1696
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 bands = hw->wiphy->bands;
1698 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1699 if (!bands[band])
1700 continue;
1701
1702 for (i = 0; i < bands[band]->n_channels; i++) {
1703 if (bands[band]->channels[i].flags &
1704 IEEE80211_CHAN_DISABLED)
1705 continue;
1706
1707 arg.n_channels++;
1708 }
1709 }
1710
1711 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1712 arg.channels = kzalloc(len, GFP_KERNEL);
1713 if (!arg.channels)
1714 return -ENOMEM;
1715
1716 ch = arg.channels;
1717 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1718 if (!bands[band])
1719 continue;
1720
1721 for (i = 0; i < bands[band]->n_channels; i++) {
1722 channel = &bands[band]->channels[i];
1723
1724 if (channel->flags & IEEE80211_CHAN_DISABLED)
1725 continue;
1726
1727 ch->allow_ht = true;
1728
1729 /* FIXME: when should we really allow VHT? */
1730 ch->allow_vht = true;
1731
1732 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001733 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001734
1735 ch->ht40plus =
1736 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1737
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001738 ch->chan_radar =
1739 !!(channel->flags & IEEE80211_CHAN_RADAR);
1740
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001741 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742 ch->passive = passive;
1743
1744 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001745 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001746 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001747 ch->max_power = channel->max_power * 2;
1748 ch->max_reg_power = channel->max_reg_power * 2;
1749 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750 ch->reg_class_id = 0; /* FIXME */
1751
1752 /* FIXME: why use only legacy modes, why not any
1753 * HT/VHT modes? Would that even make any
1754 * difference? */
1755 if (channel->band == IEEE80211_BAND_2GHZ)
1756 ch->mode = MODE_11G;
1757 else
1758 ch->mode = MODE_11A;
1759
1760 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1761 continue;
1762
Michal Kazior7aa7a722014-08-25 12:09:38 +02001763 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001764 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1765 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766 ch->freq, ch->max_power, ch->max_reg_power,
1767 ch->max_antenna_gain, ch->mode);
1768
1769 ch++;
1770 }
1771 }
1772
1773 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1774 kfree(arg.channels);
1775
1776 return ret;
1777}
1778
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001779static enum wmi_dfs_region
1780ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1781{
1782 switch (dfs_region) {
1783 case NL80211_DFS_UNSET:
1784 return WMI_UNINIT_DFS_DOMAIN;
1785 case NL80211_DFS_FCC:
1786 return WMI_FCC_DFS_DOMAIN;
1787 case NL80211_DFS_ETSI:
1788 return WMI_ETSI_DFS_DOMAIN;
1789 case NL80211_DFS_JP:
1790 return WMI_MKK4_DFS_DOMAIN;
1791 }
1792 return WMI_UNINIT_DFS_DOMAIN;
1793}
1794
Michal Kaziorf7843d72013-07-16 09:38:52 +02001795static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001796{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001797 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001799 enum wmi_dfs_region wmi_dfs_reg;
1800 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001801
Michal Kaziorf7843d72013-07-16 09:38:52 +02001802 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001803
1804 ret = ath10k_update_channel_list(ar);
1805 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001806 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001807
1808 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001809
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001810 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1811 nl_dfs_reg = ar->dfs_detector->region;
1812 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1813 } else {
1814 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1815 }
1816
Kalle Valo5e3dd152013-06-12 20:52:10 +03001817 /* Target allows setting up per-band regdomain but ath_common provides
1818 * a combined one only */
1819 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001820 regpair->reg_domain,
1821 regpair->reg_domain, /* 2ghz */
1822 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001823 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001824 regpair->reg_5ghz_ctl,
1825 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001826 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001827 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001828}
Michal Kazior548db542013-07-05 16:15:15 +03001829
Michal Kaziorf7843d72013-07-16 09:38:52 +02001830static void ath10k_reg_notifier(struct wiphy *wiphy,
1831 struct regulatory_request *request)
1832{
1833 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1834 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001835 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001836
1837 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1838
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001839 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001840 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001841 request->dfs_region);
1842 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1843 request->dfs_region);
1844 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001845 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001846 request->dfs_region);
1847 }
1848
Michal Kaziorf7843d72013-07-16 09:38:52 +02001849 mutex_lock(&ar->conf_mutex);
1850 if (ar->state == ATH10K_STATE_ON)
1851 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001852 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853}
1854
1855/***************/
1856/* TX handlers */
1857/***************/
1858
Michal Kazior42c3aa62013-10-02 11:03:38 +02001859static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1860{
1861 if (ieee80211_is_mgmt(hdr->frame_control))
1862 return HTT_DATA_TX_EXT_TID_MGMT;
1863
1864 if (!ieee80211_is_data_qos(hdr->frame_control))
1865 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1866
1867 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1868 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1869
1870 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1871}
1872
Michal Kazior2b37c292014-09-02 11:00:22 +03001873static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001874{
Michal Kazior2b37c292014-09-02 11:00:22 +03001875 if (vif)
1876 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001877
Michal Kazior1bbc0972014-04-08 09:45:47 +03001878 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001879 return ar->monitor_vdev_id;
1880
Michal Kazior7aa7a722014-08-25 12:09:38 +02001881 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001882 return 0;
1883}
1884
Michal Kazior4b604552014-07-21 21:03:09 +03001885/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1886 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001887 */
Michal Kazior4b604552014-07-21 21:03:09 +03001888static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001889{
1890 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001891 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892 u8 *qos_ctl;
1893
1894 if (!ieee80211_is_data_qos(hdr->frame_control))
1895 return;
1896
1897 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001898 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1899 skb->data, (void *)qos_ctl - (void *)skb->data);
1900 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001901
1902 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1903 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1904 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1905 * it is safe to downgrade to NullFunc.
1906 */
1907 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1908 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1909 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1910 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001911}
1912
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001913static void ath10k_tx_wep_key_work(struct work_struct *work)
1914{
1915 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1916 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001917 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001918 int ret, keyidx = arvif->def_wep_key_newidx;
1919
Michal Kazior911e6c02014-05-26 12:46:03 +03001920 mutex_lock(&arvif->ar->conf_mutex);
1921
1922 if (arvif->ar->state != ATH10K_STATE_ON)
1923 goto unlock;
1924
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001925 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001926 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001927
Michal Kazior7aa7a722014-08-25 12:09:38 +02001928 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001929 arvif->vdev_id, keyidx);
1930
1931 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1932 arvif->vdev_id,
1933 arvif->ar->wmi.vdev_param->def_keyid,
1934 keyidx);
1935 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001936 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001937 arvif->vdev_id,
1938 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001939 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001940 }
1941
1942 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001943
1944unlock:
1945 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001946}
1947
Michal Kazior4b604552014-07-21 21:03:09 +03001948static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1949 struct ieee80211_key_conf *key,
1950 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1953 struct ath10k *ar = arvif->ar;
1954 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955
Kalle Valo5e3dd152013-06-12 20:52:10 +03001956 if (!ieee80211_has_protected(hdr->frame_control))
1957 return;
1958
1959 if (!key)
1960 return;
1961
1962 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1963 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1964 return;
1965
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001966 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 return;
1968
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001969 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1970 * queueing frames until key index is updated is not an option because
1971 * sk_buff may need more processing to be done, e.g. offchannel */
1972 arvif->def_wep_key_newidx = key->keyidx;
1973 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001974}
1975
Michal Kazior4b604552014-07-21 21:03:09 +03001976static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1977 struct ieee80211_vif *vif,
1978 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001979{
1980 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1982
1983 /* This is case only for P2P_GO */
1984 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1985 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1986 return;
1987
1988 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1989 spin_lock_bh(&ar->data_lock);
1990 if (arvif->u.ap.noa_data)
1991 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1992 GFP_ATOMIC))
1993 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1994 arvif->u.ap.noa_data,
1995 arvif->u.ap.noa_len);
1996 spin_unlock_bh(&ar->data_lock);
1997 }
1998}
1999
2000static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2001{
2002 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002003 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004
Michal Kazior961d4c32013-08-09 10:13:34 +02002005 if (ar->htt.target_version_major >= 3) {
2006 /* Since HTT 3.0 there is no separate mgmt tx command */
2007 ret = ath10k_htt_tx(&ar->htt, skb);
2008 goto exit;
2009 }
2010
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002011 if (ieee80211_is_mgmt(hdr->frame_control)) {
2012 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2013 ar->fw_features)) {
2014 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2015 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002016 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002017 ret = -EBUSY;
2018 goto exit;
2019 }
2020
2021 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2022 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2023 } else {
2024 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2025 }
2026 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2027 ar->fw_features) &&
2028 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002029 /* FW does not report tx status properly for NullFunc frames
2030 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002031 * those frames when it detects link/beacon loss and depends
2032 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002033 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002034 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002035 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002036 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002037
Michal Kazior961d4c32013-08-09 10:13:34 +02002038exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002040 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2041 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002042 ieee80211_free_txskb(ar->hw, skb);
2043 }
2044}
2045
2046void ath10k_offchan_tx_purge(struct ath10k *ar)
2047{
2048 struct sk_buff *skb;
2049
2050 for (;;) {
2051 skb = skb_dequeue(&ar->offchan_tx_queue);
2052 if (!skb)
2053 break;
2054
2055 ieee80211_free_txskb(ar->hw, skb);
2056 }
2057}
2058
2059void ath10k_offchan_tx_work(struct work_struct *work)
2060{
2061 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2062 struct ath10k_peer *peer;
2063 struct ieee80211_hdr *hdr;
2064 struct sk_buff *skb;
2065 const u8 *peer_addr;
2066 int vdev_id;
2067 int ret;
2068
2069 /* FW requirement: We must create a peer before FW will send out
2070 * an offchannel frame. Otherwise the frame will be stuck and
2071 * never transmitted. We delete the peer upon tx completion.
2072 * It is unlikely that a peer for offchannel tx will already be
2073 * present. However it may be in some rare cases so account for that.
2074 * Otherwise we might remove a legitimate peer and break stuff. */
2075
2076 for (;;) {
2077 skb = skb_dequeue(&ar->offchan_tx_queue);
2078 if (!skb)
2079 break;
2080
2081 mutex_lock(&ar->conf_mutex);
2082
Michal Kazior7aa7a722014-08-25 12:09:38 +02002083 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002084 skb);
2085
2086 hdr = (struct ieee80211_hdr *)skb->data;
2087 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002088 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089
2090 spin_lock_bh(&ar->data_lock);
2091 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2092 spin_unlock_bh(&ar->data_lock);
2093
2094 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002095 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002096 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002097 peer_addr, vdev_id);
2098
2099 if (!peer) {
2100 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2101 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002102 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002103 peer_addr, vdev_id, ret);
2104 }
2105
2106 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002107 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002108 ar->offchan_tx_skb = skb;
2109 spin_unlock_bh(&ar->data_lock);
2110
2111 ath10k_tx_htt(ar, skb);
2112
2113 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2114 3 * HZ);
2115 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002116 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 skb);
2118
2119 if (!peer) {
2120 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2121 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002122 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 peer_addr, vdev_id, ret);
2124 }
2125
2126 mutex_unlock(&ar->conf_mutex);
2127 }
2128}
2129
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002130void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2131{
2132 struct sk_buff *skb;
2133
2134 for (;;) {
2135 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2136 if (!skb)
2137 break;
2138
2139 ieee80211_free_txskb(ar->hw, skb);
2140 }
2141}
2142
2143void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2144{
2145 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2146 struct sk_buff *skb;
2147 int ret;
2148
2149 for (;;) {
2150 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2151 if (!skb)
2152 break;
2153
2154 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002155 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002156 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002157 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002158 ieee80211_free_txskb(ar->hw, skb);
2159 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002160 }
2161}
2162
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163/************/
2164/* Scanning */
2165/************/
2166
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002167void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002168{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002169 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002171 switch (ar->scan.state) {
2172 case ATH10K_SCAN_IDLE:
2173 break;
2174 case ATH10K_SCAN_RUNNING:
2175 case ATH10K_SCAN_ABORTING:
2176 if (ar->scan.is_roc)
2177 ieee80211_remain_on_channel_expired(ar->hw);
2178 else
2179 ieee80211_scan_completed(ar->hw,
2180 (ar->scan.state ==
2181 ATH10K_SCAN_ABORTING));
2182 /* fall through */
2183 case ATH10K_SCAN_STARTING:
2184 ar->scan.state = ATH10K_SCAN_IDLE;
2185 ar->scan_channel = NULL;
2186 ath10k_offchan_tx_purge(ar);
2187 cancel_delayed_work(&ar->scan.timeout);
2188 complete_all(&ar->scan.completed);
2189 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002191}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002193void ath10k_scan_finish(struct ath10k *ar)
2194{
2195 spin_lock_bh(&ar->data_lock);
2196 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197 spin_unlock_bh(&ar->data_lock);
2198}
2199
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002200static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002201{
2202 struct wmi_stop_scan_arg arg = {
2203 .req_id = 1, /* FIXME */
2204 .req_type = WMI_SCAN_STOP_ONE,
2205 .u.scan_id = ATH10K_SCAN_ID,
2206 };
2207 int ret;
2208
2209 lockdep_assert_held(&ar->conf_mutex);
2210
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 ret = ath10k_wmi_stop_scan(ar, &arg);
2212 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002213 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002214 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215 }
2216
Kalle Valo5e3dd152013-06-12 20:52:10 +03002217 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002218 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002219 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002220 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002221 } else if (ret > 0) {
2222 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002224
2225out:
2226 /* Scan state should be updated upon scan completion but in case
2227 * firmware fails to deliver the event (for whatever reason) it is
2228 * desired to clean up scan state anyway. Firmware may have just
2229 * dropped the scan completion event delivery due to transport pipe
2230 * being overflown with data and/or it can recover on its own before
2231 * next scan request is submitted.
2232 */
2233 spin_lock_bh(&ar->data_lock);
2234 if (ar->scan.state != ATH10K_SCAN_IDLE)
2235 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002236 spin_unlock_bh(&ar->data_lock);
2237
2238 return ret;
2239}
2240
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002241static void ath10k_scan_abort(struct ath10k *ar)
2242{
2243 int ret;
2244
2245 lockdep_assert_held(&ar->conf_mutex);
2246
2247 spin_lock_bh(&ar->data_lock);
2248
2249 switch (ar->scan.state) {
2250 case ATH10K_SCAN_IDLE:
2251 /* This can happen if timeout worker kicked in and called
2252 * abortion while scan completion was being processed.
2253 */
2254 break;
2255 case ATH10K_SCAN_STARTING:
2256 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002257 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002258 ath10k_scan_state_str(ar->scan.state),
2259 ar->scan.state);
2260 break;
2261 case ATH10K_SCAN_RUNNING:
2262 ar->scan.state = ATH10K_SCAN_ABORTING;
2263 spin_unlock_bh(&ar->data_lock);
2264
2265 ret = ath10k_scan_stop(ar);
2266 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002267 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002268
2269 spin_lock_bh(&ar->data_lock);
2270 break;
2271 }
2272
2273 spin_unlock_bh(&ar->data_lock);
2274}
2275
2276void ath10k_scan_timeout_work(struct work_struct *work)
2277{
2278 struct ath10k *ar = container_of(work, struct ath10k,
2279 scan.timeout.work);
2280
2281 mutex_lock(&ar->conf_mutex);
2282 ath10k_scan_abort(ar);
2283 mutex_unlock(&ar->conf_mutex);
2284}
2285
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286static int ath10k_start_scan(struct ath10k *ar,
2287 const struct wmi_start_scan_arg *arg)
2288{
2289 int ret;
2290
2291 lockdep_assert_held(&ar->conf_mutex);
2292
2293 ret = ath10k_wmi_start_scan(ar, arg);
2294 if (ret)
2295 return ret;
2296
Kalle Valo5e3dd152013-06-12 20:52:10 +03002297 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2298 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002299 ret = ath10k_scan_stop(ar);
2300 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002301 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002302
2303 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304 }
2305
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002306 /* Add a 200ms margin to account for event/command processing */
2307 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2308 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002309 return 0;
2310}
2311
2312/**********************/
2313/* mac80211 callbacks */
2314/**********************/
2315
2316static void ath10k_tx(struct ieee80211_hw *hw,
2317 struct ieee80211_tx_control *control,
2318 struct sk_buff *skb)
2319{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002321 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2322 struct ieee80211_vif *vif = info->control.vif;
2323 struct ieee80211_key_conf *key = info->control.hw_key;
2324 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325
2326 /* We should disable CCK RATE due to P2P */
2327 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002328 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002329
Michal Kazior4b604552014-07-21 21:03:09 +03002330 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2331 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002332 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002334 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002335 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2336 ath10k_tx_h_nwifi(hw, skb);
2337 ath10k_tx_h_update_wep_key(vif, key, skb);
2338 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2339 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002340 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341
Kalle Valo5e3dd152013-06-12 20:52:10 +03002342 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2343 spin_lock_bh(&ar->data_lock);
2344 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002345 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 spin_unlock_bh(&ar->data_lock);
2347
Michal Kazior7aa7a722014-08-25 12:09:38 +02002348 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2349 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350
2351 skb_queue_tail(&ar->offchan_tx_queue, skb);
2352 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2353 return;
2354 }
2355
2356 ath10k_tx_htt(ar, skb);
2357}
2358
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002359/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002360void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002361{
2362 /* make sure rcu-protected mac80211 tx path itself is drained */
2363 synchronize_net();
2364
2365 ath10k_offchan_tx_purge(ar);
2366 ath10k_mgmt_over_wmi_tx_purge(ar);
2367
2368 cancel_work_sync(&ar->offchan_tx_work);
2369 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2370}
2371
Michal Kazioraffd3212013-07-16 09:54:35 +02002372void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002373{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002374 struct ath10k_vif *arvif;
2375
Michal Kazior818bdd12013-07-16 09:38:57 +02002376 lockdep_assert_held(&ar->conf_mutex);
2377
Michal Kazior19337472014-08-28 12:58:16 +02002378 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2379 ar->filter_flags = 0;
2380 ar->monitor = false;
2381
2382 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002383 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002384
2385 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002386
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002387 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002388 ath10k_peer_cleanup_all(ar);
2389 ath10k_core_stop(ar);
2390 ath10k_hif_power_down(ar);
2391
2392 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002393 list_for_each_entry(arvif, &ar->arvifs, list)
2394 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002395 spin_unlock_bh(&ar->data_lock);
2396}
2397
Ben Greear46acf7b2014-05-16 17:15:38 +03002398static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2399{
2400 struct ath10k *ar = hw->priv;
2401
2402 mutex_lock(&ar->conf_mutex);
2403
2404 if (ar->cfg_tx_chainmask) {
2405 *tx_ant = ar->cfg_tx_chainmask;
2406 *rx_ant = ar->cfg_rx_chainmask;
2407 } else {
2408 *tx_ant = ar->supp_tx_chainmask;
2409 *rx_ant = ar->supp_rx_chainmask;
2410 }
2411
2412 mutex_unlock(&ar->conf_mutex);
2413
2414 return 0;
2415}
2416
2417static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2418{
2419 int ret;
2420
2421 lockdep_assert_held(&ar->conf_mutex);
2422
2423 ar->cfg_tx_chainmask = tx_ant;
2424 ar->cfg_rx_chainmask = rx_ant;
2425
2426 if ((ar->state != ATH10K_STATE_ON) &&
2427 (ar->state != ATH10K_STATE_RESTARTED))
2428 return 0;
2429
2430 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2431 tx_ant);
2432 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002433 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002434 ret, tx_ant);
2435 return ret;
2436 }
2437
2438 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2439 rx_ant);
2440 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002441 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002442 ret, rx_ant);
2443 return ret;
2444 }
2445
2446 return 0;
2447}
2448
2449static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2450{
2451 struct ath10k *ar = hw->priv;
2452 int ret;
2453
2454 mutex_lock(&ar->conf_mutex);
2455 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2456 mutex_unlock(&ar->conf_mutex);
2457 return ret;
2458}
2459
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460static int ath10k_start(struct ieee80211_hw *hw)
2461{
2462 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002463 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002465 /*
2466 * This makes sense only when restarting hw. It is harmless to call
2467 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2468 * commands will be submitted while restarting.
2469 */
2470 ath10k_drain_tx(ar);
2471
Michal Kazior548db542013-07-05 16:15:15 +03002472 mutex_lock(&ar->conf_mutex);
2473
Michal Kaziorc5058f52014-05-26 12:46:03 +03002474 switch (ar->state) {
2475 case ATH10K_STATE_OFF:
2476 ar->state = ATH10K_STATE_ON;
2477 break;
2478 case ATH10K_STATE_RESTARTING:
2479 ath10k_halt(ar);
2480 ar->state = ATH10K_STATE_RESTARTED;
2481 break;
2482 case ATH10K_STATE_ON:
2483 case ATH10K_STATE_RESTARTED:
2484 case ATH10K_STATE_WEDGED:
2485 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002486 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002487 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002488 case ATH10K_STATE_UTF:
2489 ret = -EBUSY;
2490 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002491 }
2492
2493 ret = ath10k_hif_power_up(ar);
2494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002496 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002497 }
2498
Kalle Valo43d2a302014-09-10 18:23:30 +03002499 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002500 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002501 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002502 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002503 }
2504
Bartosz Markowski226a3392013-09-26 17:47:16 +02002505 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002507 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002508 goto err_core_stop;
2509 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002510
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002511 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002512 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002513 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002514 goto err_core_stop;
2515 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002516
Ben Greear46acf7b2014-05-16 17:15:38 +03002517 if (ar->cfg_tx_chainmask)
2518 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2519 ar->cfg_rx_chainmask);
2520
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002521 /*
2522 * By default FW set ARP frames ac to voice (6). In that case ARP
2523 * exchange is not working properly for UAPSD enabled AP. ARP requests
2524 * which arrives with access category 0 are processed by network stack
2525 * and send back with access category 0, but FW changes access category
2526 * to 6. Set ARP frames access category to best effort (0) solves
2527 * this problem.
2528 */
2529
2530 ret = ath10k_wmi_pdev_set_param(ar,
2531 ar->wmi.pdev_param->arp_ac_override, 0);
2532 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002533 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002534 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002535 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002536 }
2537
Michal Kaziord6500972014-04-08 09:56:09 +03002538 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002539 ath10k_regd_update(ar);
2540
Simon Wunderlich855aed12014-08-02 09:12:54 +03002541 ath10k_spectral_start(ar);
2542
Michal Kaziorae254432014-05-26 12:46:02 +03002543 mutex_unlock(&ar->conf_mutex);
2544 return 0;
2545
2546err_core_stop:
2547 ath10k_core_stop(ar);
2548
2549err_power_down:
2550 ath10k_hif_power_down(ar);
2551
2552err_off:
2553 ar->state = ATH10K_STATE_OFF;
2554
2555err:
Michal Kazior548db542013-07-05 16:15:15 +03002556 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002557 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558}
2559
2560static void ath10k_stop(struct ieee80211_hw *hw)
2561{
2562 struct ath10k *ar = hw->priv;
2563
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002564 ath10k_drain_tx(ar);
2565
Michal Kazior548db542013-07-05 16:15:15 +03002566 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002567 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002568 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002569 ar->state = ATH10K_STATE_OFF;
2570 }
Michal Kazior548db542013-07-05 16:15:15 +03002571 mutex_unlock(&ar->conf_mutex);
2572
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002573 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002574 cancel_work_sync(&ar->restart_work);
2575}
2576
Michal Kaziorad088bf2013-10-16 15:44:46 +03002577static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002578{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002579 struct ath10k_vif *arvif;
2580 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002581
2582 lockdep_assert_held(&ar->conf_mutex);
2583
Michal Kaziorad088bf2013-10-16 15:44:46 +03002584 list_for_each_entry(arvif, &ar->arvifs, list) {
2585 ret = ath10k_mac_vif_setup_ps(arvif);
2586 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002587 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002588 break;
2589 }
2590 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002591
Michal Kaziorad088bf2013-10-16 15:44:46 +03002592 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002593}
2594
Michal Kaziorc930f742014-01-23 11:38:25 +01002595static const char *chandef_get_width(enum nl80211_chan_width width)
2596{
2597 switch (width) {
2598 case NL80211_CHAN_WIDTH_20_NOHT:
2599 return "20 (noht)";
2600 case NL80211_CHAN_WIDTH_20:
2601 return "20";
2602 case NL80211_CHAN_WIDTH_40:
2603 return "40";
2604 case NL80211_CHAN_WIDTH_80:
2605 return "80";
2606 case NL80211_CHAN_WIDTH_80P80:
2607 return "80+80";
2608 case NL80211_CHAN_WIDTH_160:
2609 return "160";
2610 case NL80211_CHAN_WIDTH_5:
2611 return "5";
2612 case NL80211_CHAN_WIDTH_10:
2613 return "10";
2614 }
2615 return "?";
2616}
2617
2618static void ath10k_config_chan(struct ath10k *ar)
2619{
2620 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002621 int ret;
2622
2623 lockdep_assert_held(&ar->conf_mutex);
2624
Michal Kazior7aa7a722014-08-25 12:09:38 +02002625 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002626 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2627 ar->chandef.chan->center_freq,
2628 ar->chandef.center_freq1,
2629 ar->chandef.center_freq2,
2630 chandef_get_width(ar->chandef.width));
2631
2632 /* First stop monitor interface. Some FW versions crash if there's a
2633 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002634 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002635 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002636
2637 list_for_each_entry(arvif, &ar->arvifs, list) {
2638 if (!arvif->is_started)
2639 continue;
2640
Michal Kaziordc55e302014-07-29 12:53:36 +03002641 if (!arvif->is_up)
2642 continue;
2643
Michal Kaziorc930f742014-01-23 11:38:25 +01002644 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2645 continue;
2646
Michal Kaziordc55e302014-07-29 12:53:36 +03002647 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002648 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002649 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002650 arvif->vdev_id, ret);
2651 continue;
2652 }
2653 }
2654
Michal Kaziordc55e302014-07-29 12:53:36 +03002655 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002656
2657 list_for_each_entry(arvif, &ar->arvifs, list) {
2658 if (!arvif->is_started)
2659 continue;
2660
2661 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2662 continue;
2663
Michal Kaziordc55e302014-07-29 12:53:36 +03002664 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002665 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002666 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002667 arvif->vdev_id, ret);
2668 continue;
2669 }
2670
2671 if (!arvif->is_up)
2672 continue;
2673
2674 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2675 arvif->bssid);
2676 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002677 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002678 arvif->vdev_id, ret);
2679 continue;
2680 }
2681 }
2682
Michal Kazior19337472014-08-28 12:58:16 +02002683 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002684}
2685
Michal Kazior7d9d5582014-10-21 10:40:15 +03002686static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2687{
2688 int ret;
2689 u32 param;
2690
2691 lockdep_assert_held(&ar->conf_mutex);
2692
2693 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2694
2695 param = ar->wmi.pdev_param->txpower_limit2g;
2696 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2697 if (ret) {
2698 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2699 txpower, ret);
2700 return ret;
2701 }
2702
2703 param = ar->wmi.pdev_param->txpower_limit5g;
2704 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2705 if (ret) {
2706 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2707 txpower, ret);
2708 return ret;
2709 }
2710
2711 return 0;
2712}
2713
2714static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2715{
2716 struct ath10k_vif *arvif;
2717 int ret, txpower = -1;
2718
2719 lockdep_assert_held(&ar->conf_mutex);
2720
2721 list_for_each_entry(arvif, &ar->arvifs, list) {
2722 WARN_ON(arvif->txpower < 0);
2723
2724 if (txpower == -1)
2725 txpower = arvif->txpower;
2726 else
2727 txpower = min(txpower, arvif->txpower);
2728 }
2729
2730 if (WARN_ON(txpower == -1))
2731 return -EINVAL;
2732
2733 ret = ath10k_mac_txpower_setup(ar, txpower);
2734 if (ret) {
2735 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2736 txpower, ret);
2737 return ret;
2738 }
2739
2740 return 0;
2741}
2742
Kalle Valo5e3dd152013-06-12 20:52:10 +03002743static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2744{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745 struct ath10k *ar = hw->priv;
2746 struct ieee80211_conf *conf = &hw->conf;
2747 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748
2749 mutex_lock(&ar->conf_mutex);
2750
2751 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002752 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002753 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002754 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002755 conf->chandef.chan->flags,
2756 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002757
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758 spin_lock_bh(&ar->data_lock);
2759 ar->rx_channel = conf->chandef.chan;
2760 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002761
Michal Kaziord6500972014-04-08 09:56:09 +03002762 ar->radar_enabled = conf->radar_enabled;
2763 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002764
2765 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2766 ar->chandef = conf->chandef;
2767 ath10k_config_chan(ar);
2768 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002769 }
2770
Michal Kazioraffd3212013-07-16 09:54:35 +02002771 if (changed & IEEE80211_CONF_CHANGE_PS)
2772 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773
2774 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002775 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2776 ret = ath10k_monitor_recalc(ar);
2777 if (ret)
2778 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779 }
2780
2781 mutex_unlock(&ar->conf_mutex);
2782 return ret;
2783}
2784
2785/*
2786 * TODO:
2787 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2788 * because we will send mgmt frames without CCK. This requirement
2789 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2790 * in the TX packet.
2791 */
2792static int ath10k_add_interface(struct ieee80211_hw *hw,
2793 struct ieee80211_vif *vif)
2794{
2795 struct ath10k *ar = hw->priv;
2796 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2797 enum wmi_sta_powersave_param param;
2798 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002799 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002801 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802
2803 mutex_lock(&ar->conf_mutex);
2804
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002805 memset(arvif, 0, sizeof(*arvif));
2806
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 arvif->ar = ar;
2808 arvif->vif = vif;
2809
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002810 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002811 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002812
Ben Greeara9aefb32014-08-12 11:02:19 +03002813 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002814 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002816 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002817 }
Ben Greear16c11172014-09-23 14:17:16 -07002818 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002819
Ben Greear16c11172014-09-23 14:17:16 -07002820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2821 bit, ar->free_vdev_map);
2822
2823 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002825
2826 if (ar->p2p)
2827 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2828
2829 switch (vif->type) {
2830 case NL80211_IFTYPE_UNSPECIFIED:
2831 case NL80211_IFTYPE_STATION:
2832 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2833 if (vif->p2p)
2834 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2835 break;
2836 case NL80211_IFTYPE_ADHOC:
2837 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2838 break;
2839 case NL80211_IFTYPE_AP:
2840 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2841
2842 if (vif->p2p)
2843 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2844 break;
2845 case NL80211_IFTYPE_MONITOR:
2846 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2847 break;
2848 default:
2849 WARN_ON(1);
2850 break;
2851 }
2852
Michal Kazior64badcb2014-09-18 11:18:02 +03002853 /* Some firmware revisions don't wait for beacon tx completion before
2854 * sending another SWBA event. This could lead to hardware using old
2855 * (freed) beacon data in some cases, e.g. tx credit starvation
2856 * combined with missed TBTT. This is very very rare.
2857 *
2858 * On non-IOMMU-enabled hosts this could be a possible security issue
2859 * because hw could beacon some random data on the air. On
2860 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2861 * device would crash.
2862 *
2863 * Since there are no beacon tx completions (implicit nor explicit)
2864 * propagated to host the only workaround for this is to allocate a
2865 * DMA-coherent buffer for a lifetime of a vif and use it for all
2866 * beacon tx commands. Worst case for this approach is some beacons may
2867 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2868 */
2869 if (vif->type == NL80211_IFTYPE_ADHOC ||
2870 vif->type == NL80211_IFTYPE_AP) {
2871 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2872 IEEE80211_MAX_FRAME_LEN,
2873 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05302874 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03002875 if (!arvif->beacon_buf) {
2876 ret = -ENOMEM;
2877 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2878 ret);
2879 goto err;
2880 }
2881 }
2882
2883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2884 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2885 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002886
2887 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2888 arvif->vdev_subtype, vif->addr);
2889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002890 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002891 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002892 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 }
2894
Ben Greear16c11172014-09-23 14:17:16 -07002895 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002896 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002897
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002898 vdev_param = ar->wmi.vdev_param->def_keyid;
2899 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002900 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002902 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002903 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002904 goto err_vdev_delete;
2905 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002907 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2908 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002910 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002911 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002912 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002913 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002914 goto err_vdev_delete;
2915 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002916
2917 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2918 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002920 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002921 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002922 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002923 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002924
Kalle Valo5a13e762014-01-20 11:01:46 +02002925 ret = ath10k_mac_set_kickout(arvif);
2926 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002927 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002928 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002929 goto err_peer_delete;
2930 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002931 }
2932
2933 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2934 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2935 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2936 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2937 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002938 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002939 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002940 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002941 goto err_peer_delete;
2942 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002943
2944 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2945 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2946 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2947 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002948 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002949 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002950 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002951 goto err_peer_delete;
2952 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002953
2954 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2955 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2956 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2957 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002959 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002960 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002961 goto err_peer_delete;
2962 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002963 }
2964
Michal Kazior424121c2013-07-22 14:13:31 +02002965 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002966 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002967 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002968 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002969 goto err_peer_delete;
2970 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002971
Michal Kazior424121c2013-07-22 14:13:31 +02002972 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002973 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002974 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002975 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002976 goto err_peer_delete;
2977 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002978
Michal Kazior7d9d5582014-10-21 10:40:15 +03002979 arvif->txpower = vif->bss_conf.txpower;
2980 ret = ath10k_mac_txpower_recalc(ar);
2981 if (ret) {
2982 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
2983 goto err_peer_delete;
2984 }
2985
Kalle Valo5e3dd152013-06-12 20:52:10 +03002986 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002987 return 0;
2988
2989err_peer_delete:
2990 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2991 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2992
2993err_vdev_delete:
2994 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07002995 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002996 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002997
2998err:
Michal Kazior64badcb2014-09-18 11:18:02 +03002999 if (arvif->beacon_buf) {
3000 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3001 arvif->beacon_buf, arvif->beacon_paddr);
3002 arvif->beacon_buf = NULL;
3003 }
3004
Michal Kazior9dad14a2013-10-16 15:44:45 +03003005 mutex_unlock(&ar->conf_mutex);
3006
Kalle Valo5e3dd152013-06-12 20:52:10 +03003007 return ret;
3008}
3009
3010static void ath10k_remove_interface(struct ieee80211_hw *hw,
3011 struct ieee80211_vif *vif)
3012{
3013 struct ath10k *ar = hw->priv;
3014 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3015 int ret;
3016
3017 mutex_lock(&ar->conf_mutex);
3018
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003019 cancel_work_sync(&arvif->wep_key_work);
3020
Michal Kaziored543882013-09-13 14:16:56 +02003021 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003022 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003023 spin_unlock_bh(&ar->data_lock);
3024
Simon Wunderlich855aed12014-08-02 09:12:54 +03003025 ret = ath10k_spectral_vif_stop(arvif);
3026 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003027 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003028 arvif->vdev_id, ret);
3029
Ben Greear16c11172014-09-23 14:17:16 -07003030 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003031 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003032
3033 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3034 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3035 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003036 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003037 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003038
3039 kfree(arvif->u.ap.noa_data);
3040 }
3041
Michal Kazior7aa7a722014-08-25 12:09:38 +02003042 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003043 arvif->vdev_id);
3044
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3046 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003047 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003048 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003049
Kalle Valo5e3dd152013-06-12 20:52:10 +03003050 ath10k_peer_cleanup(ar, arvif->vdev_id);
3051
3052 mutex_unlock(&ar->conf_mutex);
3053}
3054
3055/*
3056 * FIXME: Has to be verified.
3057 */
3058#define SUPPORTED_FILTERS \
3059 (FIF_PROMISC_IN_BSS | \
3060 FIF_ALLMULTI | \
3061 FIF_CONTROL | \
3062 FIF_PSPOLL | \
3063 FIF_OTHER_BSS | \
3064 FIF_BCN_PRBRESP_PROMISC | \
3065 FIF_PROBE_REQ | \
3066 FIF_FCSFAIL)
3067
3068static void ath10k_configure_filter(struct ieee80211_hw *hw,
3069 unsigned int changed_flags,
3070 unsigned int *total_flags,
3071 u64 multicast)
3072{
3073 struct ath10k *ar = hw->priv;
3074 int ret;
3075
3076 mutex_lock(&ar->conf_mutex);
3077
3078 changed_flags &= SUPPORTED_FILTERS;
3079 *total_flags &= SUPPORTED_FILTERS;
3080 ar->filter_flags = *total_flags;
3081
Michal Kazior19337472014-08-28 12:58:16 +02003082 ret = ath10k_monitor_recalc(ar);
3083 if (ret)
3084 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003085
3086 mutex_unlock(&ar->conf_mutex);
3087}
3088
3089static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3090 struct ieee80211_vif *vif,
3091 struct ieee80211_bss_conf *info,
3092 u32 changed)
3093{
3094 struct ath10k *ar = hw->priv;
3095 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3096 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003097 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098
3099 mutex_lock(&ar->conf_mutex);
3100
3101 if (changed & BSS_CHANGED_IBSS)
3102 ath10k_control_ibss(arvif, info, vif->addr);
3103
3104 if (changed & BSS_CHANGED_BEACON_INT) {
3105 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003106 vdev_param = ar->wmi.vdev_param->beacon_interval;
3107 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003108 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003109 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003110 "mac vdev %d beacon_interval %d\n",
3111 arvif->vdev_id, arvif->beacon_interval);
3112
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003114 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003115 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116 }
3117
3118 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003119 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003120 "vdev %d set beacon tx mode to staggered\n",
3121 arvif->vdev_id);
3122
Bartosz Markowski226a3392013-09-26 17:47:16 +02003123 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3124 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003125 WMI_BEACON_STAGGERED_MODE);
3126 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003127 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003128 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 }
3130
John W. Linvilleb70727e2013-06-13 13:34:29 -04003131 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 arvif->dtim_period = info->dtim_period;
3133
Michal Kazior7aa7a722014-08-25 12:09:38 +02003134 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003135 "mac vdev %d dtim_period %d\n",
3136 arvif->vdev_id, arvif->dtim_period);
3137
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003138 vdev_param = ar->wmi.vdev_param->dtim_period;
3139 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003140 arvif->dtim_period);
3141 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003142 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003143 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003144 }
3145
3146 if (changed & BSS_CHANGED_SSID &&
3147 vif->type == NL80211_IFTYPE_AP) {
3148 arvif->u.ap.ssid_len = info->ssid_len;
3149 if (info->ssid_len)
3150 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3151 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3152 }
3153
Michal Kazior077efc82014-10-21 10:10:29 +03003154 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3155 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003156
3157 if (changed & BSS_CHANGED_BEACON_ENABLED)
3158 ath10k_control_beaconing(arvif, info);
3159
3160 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003161 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003162 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003163 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003164
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003165 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003166 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003167 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003168 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169 }
3170
3171 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003172 if (info->use_short_slot)
3173 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3174
3175 else
3176 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3177
Michal Kazior7aa7a722014-08-25 12:09:38 +02003178 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003179 arvif->vdev_id, slottime);
3180
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003181 vdev_param = ar->wmi.vdev_param->slot_time;
3182 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003183 slottime);
3184 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003185 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003186 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187 }
3188
3189 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 if (info->use_short_preamble)
3191 preamble = WMI_VDEV_PREAMBLE_SHORT;
3192 else
3193 preamble = WMI_VDEV_PREAMBLE_LONG;
3194
Michal Kazior7aa7a722014-08-25 12:09:38 +02003195 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003196 "mac vdev %d preamble %dn",
3197 arvif->vdev_id, preamble);
3198
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003199 vdev_param = ar->wmi.vdev_param->preamble;
3200 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003201 preamble);
3202 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003203 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003204 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003205 }
3206
3207 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003208 if (info->assoc) {
3209 /* Workaround: Make sure monitor vdev is not running
3210 * when associating to prevent some firmware revisions
3211 * (e.g. 10.1 and 10.2) from crashing.
3212 */
3213 if (ar->monitor_started)
3214 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003215 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003216 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003217 } else {
3218 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003219 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003220 }
3221
Michal Kazior7d9d5582014-10-21 10:40:15 +03003222 if (changed & BSS_CHANGED_TXPOWER) {
3223 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3224 arvif->vdev_id, info->txpower);
3225
3226 arvif->txpower = info->txpower;
3227 ret = ath10k_mac_txpower_recalc(ar);
3228 if (ret)
3229 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3230 }
3231
Kalle Valo5e3dd152013-06-12 20:52:10 +03003232 mutex_unlock(&ar->conf_mutex);
3233}
3234
3235static int ath10k_hw_scan(struct ieee80211_hw *hw,
3236 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003237 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003238{
3239 struct ath10k *ar = hw->priv;
3240 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003241 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242 struct wmi_start_scan_arg arg;
3243 int ret = 0;
3244 int i;
3245
3246 mutex_lock(&ar->conf_mutex);
3247
3248 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003249 switch (ar->scan.state) {
3250 case ATH10K_SCAN_IDLE:
3251 reinit_completion(&ar->scan.started);
3252 reinit_completion(&ar->scan.completed);
3253 ar->scan.state = ATH10K_SCAN_STARTING;
3254 ar->scan.is_roc = false;
3255 ar->scan.vdev_id = arvif->vdev_id;
3256 ret = 0;
3257 break;
3258 case ATH10K_SCAN_STARTING:
3259 case ATH10K_SCAN_RUNNING:
3260 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003261 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003262 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264 spin_unlock_bh(&ar->data_lock);
3265
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003266 if (ret)
3267 goto exit;
3268
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269 memset(&arg, 0, sizeof(arg));
3270 ath10k_wmi_start_scan_init(ar, &arg);
3271 arg.vdev_id = arvif->vdev_id;
3272 arg.scan_id = ATH10K_SCAN_ID;
3273
3274 if (!req->no_cck)
3275 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3276
3277 if (req->ie_len) {
3278 arg.ie_len = req->ie_len;
3279 memcpy(arg.ie, req->ie, arg.ie_len);
3280 }
3281
3282 if (req->n_ssids) {
3283 arg.n_ssids = req->n_ssids;
3284 for (i = 0; i < arg.n_ssids; i++) {
3285 arg.ssids[i].len = req->ssids[i].ssid_len;
3286 arg.ssids[i].ssid = req->ssids[i].ssid;
3287 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003288 } else {
3289 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003290 }
3291
3292 if (req->n_channels) {
3293 arg.n_channels = req->n_channels;
3294 for (i = 0; i < arg.n_channels; i++)
3295 arg.channels[i] = req->channels[i]->center_freq;
3296 }
3297
3298 ret = ath10k_start_scan(ar, &arg);
3299 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003300 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003301 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003302 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003303 spin_unlock_bh(&ar->data_lock);
3304 }
3305
3306exit:
3307 mutex_unlock(&ar->conf_mutex);
3308 return ret;
3309}
3310
3311static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3312 struct ieee80211_vif *vif)
3313{
3314 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315
3316 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003317 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003318 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003319
3320 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321}
3322
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003323static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3324 struct ath10k_vif *arvif,
3325 enum set_key_cmd cmd,
3326 struct ieee80211_key_conf *key)
3327{
3328 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3329 int ret;
3330
3331 /* 10.1 firmware branch requires default key index to be set to group
3332 * key index after installing it. Otherwise FW/HW Txes corrupted
3333 * frames with multi-vif APs. This is not required for main firmware
3334 * branch (e.g. 636).
3335 *
3336 * FIXME: This has been tested only in AP. It remains unknown if this
3337 * is required for multi-vif STA interfaces on 10.1 */
3338
3339 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3340 return;
3341
3342 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3343 return;
3344
3345 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3346 return;
3347
3348 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3349 return;
3350
3351 if (cmd != SET_KEY)
3352 return;
3353
3354 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3355 key->keyidx);
3356 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003357 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003358 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003359}
3360
Kalle Valo5e3dd152013-06-12 20:52:10 +03003361static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3362 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3363 struct ieee80211_key_conf *key)
3364{
3365 struct ath10k *ar = hw->priv;
3366 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3367 struct ath10k_peer *peer;
3368 const u8 *peer_addr;
3369 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3370 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3371 int ret = 0;
3372
3373 if (key->keyidx > WMI_MAX_KEY_INDEX)
3374 return -ENOSPC;
3375
3376 mutex_lock(&ar->conf_mutex);
3377
3378 if (sta)
3379 peer_addr = sta->addr;
3380 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3381 peer_addr = vif->bss_conf.bssid;
3382 else
3383 peer_addr = vif->addr;
3384
3385 key->hw_key_idx = key->keyidx;
3386
3387 /* the peer should not disappear in mid-way (unless FW goes awry) since
3388 * we already hold conf_mutex. we just make sure its there now. */
3389 spin_lock_bh(&ar->data_lock);
3390 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3391 spin_unlock_bh(&ar->data_lock);
3392
3393 if (!peer) {
3394 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003395 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396 peer_addr);
3397 ret = -EOPNOTSUPP;
3398 goto exit;
3399 } else {
3400 /* if the peer doesn't exist there is no key to disable
3401 * anymore */
3402 goto exit;
3403 }
3404 }
3405
3406 if (is_wep) {
3407 if (cmd == SET_KEY)
3408 arvif->wep_keys[key->keyidx] = key;
3409 else
3410 arvif->wep_keys[key->keyidx] = NULL;
3411
3412 if (cmd == DISABLE_KEY)
3413 ath10k_clear_vdev_key(arvif, key);
3414 }
3415
3416 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3417 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003418 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003419 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003420 goto exit;
3421 }
3422
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003423 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3424
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425 spin_lock_bh(&ar->data_lock);
3426 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3427 if (peer && cmd == SET_KEY)
3428 peer->keys[key->keyidx] = key;
3429 else if (peer && cmd == DISABLE_KEY)
3430 peer->keys[key->keyidx] = NULL;
3431 else if (peer == NULL)
3432 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003433 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003434 spin_unlock_bh(&ar->data_lock);
3435
3436exit:
3437 mutex_unlock(&ar->conf_mutex);
3438 return ret;
3439}
3440
Michal Kazior9797feb2014-02-14 14:49:48 +01003441static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3442{
3443 struct ath10k *ar;
3444 struct ath10k_vif *arvif;
3445 struct ath10k_sta *arsta;
3446 struct ieee80211_sta *sta;
3447 u32 changed, bw, nss, smps;
3448 int err;
3449
3450 arsta = container_of(wk, struct ath10k_sta, update_wk);
3451 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3452 arvif = arsta->arvif;
3453 ar = arvif->ar;
3454
3455 spin_lock_bh(&ar->data_lock);
3456
3457 changed = arsta->changed;
3458 arsta->changed = 0;
3459
3460 bw = arsta->bw;
3461 nss = arsta->nss;
3462 smps = arsta->smps;
3463
3464 spin_unlock_bh(&ar->data_lock);
3465
3466 mutex_lock(&ar->conf_mutex);
3467
3468 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003469 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003470 sta->addr, bw);
3471
3472 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3473 WMI_PEER_CHAN_WIDTH, bw);
3474 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003475 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003476 sta->addr, bw, err);
3477 }
3478
3479 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003480 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003481 sta->addr, nss);
3482
3483 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3484 WMI_PEER_NSS, nss);
3485 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003486 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003487 sta->addr, nss, err);
3488 }
3489
3490 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003491 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003492 sta->addr, smps);
3493
3494 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3495 WMI_PEER_SMPS_STATE, smps);
3496 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003497 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003498 sta->addr, smps, err);
3499 }
3500
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003501 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003503 sta->addr);
3504
Michal Kazior590922a2014-10-21 10:10:29 +03003505 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003506 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003507 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003508 sta->addr);
3509 }
3510
Michal Kazior9797feb2014-02-14 14:49:48 +01003511 mutex_unlock(&ar->conf_mutex);
3512}
3513
Kalle Valo5e3dd152013-06-12 20:52:10 +03003514static int ath10k_sta_state(struct ieee80211_hw *hw,
3515 struct ieee80211_vif *vif,
3516 struct ieee80211_sta *sta,
3517 enum ieee80211_sta_state old_state,
3518 enum ieee80211_sta_state new_state)
3519{
3520 struct ath10k *ar = hw->priv;
3521 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003522 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003523 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003524 int ret = 0;
3525
Michal Kazior76f90022014-02-25 09:29:57 +02003526 if (old_state == IEEE80211_STA_NOTEXIST &&
3527 new_state == IEEE80211_STA_NONE) {
3528 memset(arsta, 0, sizeof(*arsta));
3529 arsta->arvif = arvif;
3530 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3531 }
3532
Michal Kazior9797feb2014-02-14 14:49:48 +01003533 /* cancel must be done outside the mutex to avoid deadlock */
3534 if ((old_state == IEEE80211_STA_NONE &&
3535 new_state == IEEE80211_STA_NOTEXIST))
3536 cancel_work_sync(&arsta->update_wk);
3537
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 mutex_lock(&ar->conf_mutex);
3539
3540 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003541 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003542 /*
3543 * New station addition.
3544 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003545 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3546 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3547 else
3548 max_num_peers = TARGET_NUM_PEERS;
3549
3550 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003551 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003552 ar->num_peers, max_num_peers);
3553 ret = -ENOBUFS;
3554 goto exit;
3555 }
3556
Michal Kazior7aa7a722014-08-25 12:09:38 +02003557 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003558 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3559 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003560
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3562 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003563 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 -08003564 sta->addr, arvif->vdev_id, ret);
Michal Kazior077efc82014-10-21 10:10:29 +03003565
3566 if (vif->type == NL80211_IFTYPE_STATION) {
3567 WARN_ON(arvif->is_started);
3568
3569 ret = ath10k_vdev_start(arvif);
3570 if (ret) {
3571 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3572 arvif->vdev_id, ret);
3573 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3574 sta->addr));
3575 goto exit;
3576 }
3577
3578 arvif->is_started = true;
3579 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003580 } else if ((old_state == IEEE80211_STA_NONE &&
3581 new_state == IEEE80211_STA_NOTEXIST)) {
3582 /*
3583 * Existing station deletion.
3584 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003585 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003586 "mac vdev %d peer delete %pM (sta gone)\n",
3587 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003588
3589 if (vif->type == NL80211_IFTYPE_STATION) {
3590 WARN_ON(!arvif->is_started);
3591
3592 ret = ath10k_vdev_stop(arvif);
3593 if (ret)
3594 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3595 arvif->vdev_id, ret);
3596
3597 arvif->is_started = false;
3598 }
3599
Kalle Valo5e3dd152013-06-12 20:52:10 +03003600 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3601 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003602 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003603 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003604
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 } else if (old_state == IEEE80211_STA_AUTH &&
3606 new_state == IEEE80211_STA_ASSOC &&
3607 (vif->type == NL80211_IFTYPE_AP ||
3608 vif->type == NL80211_IFTYPE_ADHOC)) {
3609 /*
3610 * New association.
3611 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003612 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003613 sta->addr);
3614
Michal Kazior590922a2014-10-21 10:10:29 +03003615 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003616 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003617 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003618 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003619 } else if (old_state == IEEE80211_STA_ASSOC &&
3620 new_state == IEEE80211_STA_AUTH &&
3621 (vif->type == NL80211_IFTYPE_AP ||
3622 vif->type == NL80211_IFTYPE_ADHOC)) {
3623 /*
3624 * Disassociation.
3625 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003626 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003627 sta->addr);
3628
Michal Kazior590922a2014-10-21 10:10:29 +03003629 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003630 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003631 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003632 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003633 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003634exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003635 mutex_unlock(&ar->conf_mutex);
3636 return ret;
3637}
3638
3639static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003640 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003641{
3642 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3643 u32 value = 0;
3644 int ret = 0;
3645
Michal Kazior548db542013-07-05 16:15:15 +03003646 lockdep_assert_held(&ar->conf_mutex);
3647
Kalle Valo5e3dd152013-06-12 20:52:10 +03003648 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3649 return 0;
3650
3651 switch (ac) {
3652 case IEEE80211_AC_VO:
3653 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3654 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3655 break;
3656 case IEEE80211_AC_VI:
3657 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3658 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3659 break;
3660 case IEEE80211_AC_BE:
3661 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3662 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3663 break;
3664 case IEEE80211_AC_BK:
3665 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3666 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3667 break;
3668 }
3669
3670 if (enable)
3671 arvif->u.sta.uapsd |= value;
3672 else
3673 arvif->u.sta.uapsd &= ~value;
3674
3675 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3676 WMI_STA_PS_PARAM_UAPSD,
3677 arvif->u.sta.uapsd);
3678 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003679 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003680 goto exit;
3681 }
3682
3683 if (arvif->u.sta.uapsd)
3684 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3685 else
3686 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3687
3688 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3689 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3690 value);
3691 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003692 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003693
3694exit:
3695 return ret;
3696}
3697
3698static int ath10k_conf_tx(struct ieee80211_hw *hw,
3699 struct ieee80211_vif *vif, u16 ac,
3700 const struct ieee80211_tx_queue_params *params)
3701{
3702 struct ath10k *ar = hw->priv;
3703 struct wmi_wmm_params_arg *p = NULL;
3704 int ret;
3705
3706 mutex_lock(&ar->conf_mutex);
3707
3708 switch (ac) {
3709 case IEEE80211_AC_VO:
3710 p = &ar->wmm_params.ac_vo;
3711 break;
3712 case IEEE80211_AC_VI:
3713 p = &ar->wmm_params.ac_vi;
3714 break;
3715 case IEEE80211_AC_BE:
3716 p = &ar->wmm_params.ac_be;
3717 break;
3718 case IEEE80211_AC_BK:
3719 p = &ar->wmm_params.ac_bk;
3720 break;
3721 }
3722
3723 if (WARN_ON(!p)) {
3724 ret = -EINVAL;
3725 goto exit;
3726 }
3727
3728 p->cwmin = params->cw_min;
3729 p->cwmax = params->cw_max;
3730 p->aifs = params->aifs;
3731
3732 /*
3733 * The channel time duration programmed in the HW is in absolute
3734 * microseconds, while mac80211 gives the txop in units of
3735 * 32 microseconds.
3736 */
3737 p->txop = params->txop * 32;
3738
3739 /* FIXME: FW accepts wmm params per hw, not per vif */
3740 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003742 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003743 goto exit;
3744 }
3745
3746 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3747 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003748 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003749
3750exit:
3751 mutex_unlock(&ar->conf_mutex);
3752 return ret;
3753}
3754
3755#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3756
3757static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3758 struct ieee80211_vif *vif,
3759 struct ieee80211_channel *chan,
3760 int duration,
3761 enum ieee80211_roc_type type)
3762{
3763 struct ath10k *ar = hw->priv;
3764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3765 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003766 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003767
3768 mutex_lock(&ar->conf_mutex);
3769
3770 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003771 switch (ar->scan.state) {
3772 case ATH10K_SCAN_IDLE:
3773 reinit_completion(&ar->scan.started);
3774 reinit_completion(&ar->scan.completed);
3775 reinit_completion(&ar->scan.on_channel);
3776 ar->scan.state = ATH10K_SCAN_STARTING;
3777 ar->scan.is_roc = true;
3778 ar->scan.vdev_id = arvif->vdev_id;
3779 ar->scan.roc_freq = chan->center_freq;
3780 ret = 0;
3781 break;
3782 case ATH10K_SCAN_STARTING:
3783 case ATH10K_SCAN_RUNNING:
3784 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003785 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003786 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003787 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788 spin_unlock_bh(&ar->data_lock);
3789
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003790 if (ret)
3791 goto exit;
3792
Kalle Valo5e3dd152013-06-12 20:52:10 +03003793 memset(&arg, 0, sizeof(arg));
3794 ath10k_wmi_start_scan_init(ar, &arg);
3795 arg.vdev_id = arvif->vdev_id;
3796 arg.scan_id = ATH10K_SCAN_ID;
3797 arg.n_channels = 1;
3798 arg.channels[0] = chan->center_freq;
3799 arg.dwell_time_active = duration;
3800 arg.dwell_time_passive = duration;
3801 arg.max_scan_time = 2 * duration;
3802 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3803 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3804
3805 ret = ath10k_start_scan(ar, &arg);
3806 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003807 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003808 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003809 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003810 spin_unlock_bh(&ar->data_lock);
3811 goto exit;
3812 }
3813
3814 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3815 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003816 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003817
3818 ret = ath10k_scan_stop(ar);
3819 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003820 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003821
Kalle Valo5e3dd152013-06-12 20:52:10 +03003822 ret = -ETIMEDOUT;
3823 goto exit;
3824 }
3825
3826 ret = 0;
3827exit:
3828 mutex_unlock(&ar->conf_mutex);
3829 return ret;
3830}
3831
3832static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3833{
3834 struct ath10k *ar = hw->priv;
3835
3836 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003837 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003838 mutex_unlock(&ar->conf_mutex);
3839
Michal Kazior4eb2e162014-10-28 10:23:09 +01003840 cancel_delayed_work_sync(&ar->scan.timeout);
3841
Kalle Valo5e3dd152013-06-12 20:52:10 +03003842 return 0;
3843}
3844
3845/*
3846 * Both RTS and Fragmentation threshold are interface-specific
3847 * in ath10k, but device-specific in mac80211.
3848 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849
3850static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3851{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003852 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003853 struct ath10k_vif *arvif;
3854 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003855
Michal Kaziorad088bf2013-10-16 15:44:46 +03003856 mutex_lock(&ar->conf_mutex);
3857 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003858 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003859 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003860
Michal Kaziorad088bf2013-10-16 15:44:46 +03003861 ret = ath10k_mac_set_rts(arvif, value);
3862 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003863 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003864 arvif->vdev_id, ret);
3865 break;
3866 }
3867 }
3868 mutex_unlock(&ar->conf_mutex);
3869
3870 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003871}
3872
3873static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3874{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003875 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003876 struct ath10k_vif *arvif;
3877 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003878
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003880 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003881 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003882 arvif->vdev_id, value);
3883
Michal Kazior56a0dee2014-10-23 17:04:29 +03003884 ret = ath10k_mac_set_frag(arvif, value);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003886 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003887 arvif->vdev_id, ret);
3888 break;
3889 }
3890 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003891 mutex_unlock(&ar->conf_mutex);
3892
Michal Kaziorad088bf2013-10-16 15:44:46 +03003893 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003894}
3895
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003896static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3897 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003898{
3899 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003900 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003901 int ret;
3902
3903 /* mac80211 doesn't care if we really xmit queued frames or not
3904 * we'll collect those frames either way if we stop/delete vdevs */
3905 if (drop)
3906 return;
3907
Michal Kazior548db542013-07-05 16:15:15 +03003908 mutex_lock(&ar->conf_mutex);
3909
Michal Kazioraffd3212013-07-16 09:54:35 +02003910 if (ar->state == ATH10K_STATE_WEDGED)
3911 goto skip;
3912
Michal Kazioredb82362013-07-05 16:15:14 +03003913 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003914 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003915
Michal Kazioredb82362013-07-05 16:15:14 +03003916 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003917 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003918 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003919
Michal Kazior7962b0d2014-10-28 10:34:38 +01003920 skip = (ar->state == ATH10K_STATE_WEDGED) ||
3921 test_bit(ATH10K_FLAG_CRASH_FLUSH,
3922 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02003923
3924 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003925 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003926
3927 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003928 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003929 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003930
Michal Kazioraffd3212013-07-16 09:54:35 +02003931skip:
Michal Kazior548db542013-07-05 16:15:15 +03003932 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003933}
3934
3935/* TODO: Implement this function properly
3936 * For now it is needed to reply to Probe Requests in IBSS mode.
3937 * Propably we need this information from FW.
3938 */
3939static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3940{
3941 return 1;
3942}
3943
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003944#ifdef CONFIG_PM
3945static int ath10k_suspend(struct ieee80211_hw *hw,
3946 struct cfg80211_wowlan *wowlan)
3947{
3948 struct ath10k *ar = hw->priv;
3949 int ret;
3950
Marek Puzyniak9042e172014-02-10 17:14:23 +01003951 mutex_lock(&ar->conf_mutex);
3952
Marek Puzyniak00f54822014-02-10 17:14:24 +01003953 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003954 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003955 if (ret == -ETIMEDOUT)
3956 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003957 ret = 1;
3958 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003959 }
3960
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003961 ret = ath10k_hif_suspend(ar);
3962 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003963 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003964 goto resume;
3965 }
3966
Marek Puzyniak9042e172014-02-10 17:14:23 +01003967 ret = 0;
3968 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003969resume:
3970 ret = ath10k_wmi_pdev_resume_target(ar);
3971 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003972 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003973
3974 ret = 1;
3975exit:
3976 mutex_unlock(&ar->conf_mutex);
3977 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003978}
3979
3980static int ath10k_resume(struct ieee80211_hw *hw)
3981{
3982 struct ath10k *ar = hw->priv;
3983 int ret;
3984
Marek Puzyniak9042e172014-02-10 17:14:23 +01003985 mutex_lock(&ar->conf_mutex);
3986
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003987 ret = ath10k_hif_resume(ar);
3988 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003989 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003990 ret = 1;
3991 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003992 }
3993
3994 ret = ath10k_wmi_pdev_resume_target(ar);
3995 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003996 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003997 ret = 1;
3998 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003999 }
4000
Marek Puzyniak9042e172014-02-10 17:14:23 +01004001 ret = 0;
4002exit:
4003 mutex_unlock(&ar->conf_mutex);
4004 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004005}
4006#endif
4007
Michal Kazioraffd3212013-07-16 09:54:35 +02004008static void ath10k_restart_complete(struct ieee80211_hw *hw)
4009{
4010 struct ath10k *ar = hw->priv;
4011
4012 mutex_lock(&ar->conf_mutex);
4013
4014 /* If device failed to restart it will be in a different state, e.g.
4015 * ATH10K_STATE_WEDGED */
4016 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004017 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004018 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004019 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004020 }
4021
4022 mutex_unlock(&ar->conf_mutex);
4023}
4024
Michal Kazior2e1dea42013-07-31 10:32:40 +02004025static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4026 struct survey_info *survey)
4027{
4028 struct ath10k *ar = hw->priv;
4029 struct ieee80211_supported_band *sband;
4030 struct survey_info *ar_survey = &ar->survey[idx];
4031 int ret = 0;
4032
4033 mutex_lock(&ar->conf_mutex);
4034
4035 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4036 if (sband && idx >= sband->n_channels) {
4037 idx -= sband->n_channels;
4038 sband = NULL;
4039 }
4040
4041 if (!sband)
4042 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4043
4044 if (!sband || idx >= sband->n_channels) {
4045 ret = -ENOENT;
4046 goto exit;
4047 }
4048
4049 spin_lock_bh(&ar->data_lock);
4050 memcpy(survey, ar_survey, sizeof(*survey));
4051 spin_unlock_bh(&ar->data_lock);
4052
4053 survey->channel = &sband->channels[idx];
4054
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004055 if (ar->rx_channel == survey->channel)
4056 survey->filled |= SURVEY_INFO_IN_USE;
4057
Michal Kazior2e1dea42013-07-31 10:32:40 +02004058exit:
4059 mutex_unlock(&ar->conf_mutex);
4060 return ret;
4061}
4062
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004063/* Helper table for legacy fixed_rate/bitrate_mask */
4064static const u8 cck_ofdm_rate[] = {
4065 /* CCK */
4066 3, /* 1Mbps */
4067 2, /* 2Mbps */
4068 1, /* 5.5Mbps */
4069 0, /* 11Mbps */
4070 /* OFDM */
4071 3, /* 6Mbps */
4072 7, /* 9Mbps */
4073 2, /* 12Mbps */
4074 6, /* 18Mbps */
4075 1, /* 24Mbps */
4076 5, /* 36Mbps */
4077 0, /* 48Mbps */
4078 4, /* 54Mbps */
4079};
4080
4081/* Check if only one bit set */
4082static int ath10k_check_single_mask(u32 mask)
4083{
4084 int bit;
4085
4086 bit = ffs(mask);
4087 if (!bit)
4088 return 0;
4089
4090 mask &= ~BIT(bit - 1);
4091 if (mask)
4092 return 2;
4093
4094 return 1;
4095}
4096
4097static bool
4098ath10k_default_bitrate_mask(struct ath10k *ar,
4099 enum ieee80211_band band,
4100 const struct cfg80211_bitrate_mask *mask)
4101{
4102 u32 legacy = 0x00ff;
4103 u8 ht = 0xff, i;
4104 u16 vht = 0x3ff;
4105
4106 switch (band) {
4107 case IEEE80211_BAND_2GHZ:
4108 legacy = 0x00fff;
4109 vht = 0;
4110 break;
4111 case IEEE80211_BAND_5GHZ:
4112 break;
4113 default:
4114 return false;
4115 }
4116
4117 if (mask->control[band].legacy != legacy)
4118 return false;
4119
4120 for (i = 0; i < ar->num_rf_chains; i++)
4121 if (mask->control[band].ht_mcs[i] != ht)
4122 return false;
4123
4124 for (i = 0; i < ar->num_rf_chains; i++)
4125 if (mask->control[band].vht_mcs[i] != vht)
4126 return false;
4127
4128 return true;
4129}
4130
4131static bool
4132ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4133 enum ieee80211_band band,
4134 u8 *fixed_nss)
4135{
4136 int ht_nss = 0, vht_nss = 0, i;
4137
4138 /* check legacy */
4139 if (ath10k_check_single_mask(mask->control[band].legacy))
4140 return false;
4141
4142 /* check HT */
4143 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4144 if (mask->control[band].ht_mcs[i] == 0xff)
4145 continue;
4146 else if (mask->control[band].ht_mcs[i] == 0x00)
4147 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004148
4149 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004150 }
4151
4152 ht_nss = i;
4153
4154 /* check VHT */
4155 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4156 if (mask->control[band].vht_mcs[i] == 0x03ff)
4157 continue;
4158 else if (mask->control[band].vht_mcs[i] == 0x0000)
4159 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004160
4161 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004162 }
4163
4164 vht_nss = i;
4165
4166 if (ht_nss > 0 && vht_nss > 0)
4167 return false;
4168
4169 if (ht_nss)
4170 *fixed_nss = ht_nss;
4171 else if (vht_nss)
4172 *fixed_nss = vht_nss;
4173 else
4174 return false;
4175
4176 return true;
4177}
4178
4179static bool
4180ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4181 enum ieee80211_band band,
4182 enum wmi_rate_preamble *preamble)
4183{
4184 int legacy = 0, ht = 0, vht = 0, i;
4185
4186 *preamble = WMI_RATE_PREAMBLE_OFDM;
4187
4188 /* check legacy */
4189 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4190 if (legacy > 1)
4191 return false;
4192
4193 /* check HT */
4194 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4195 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4196 if (ht > 1)
4197 return false;
4198
4199 /* check VHT */
4200 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4201 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4202 if (vht > 1)
4203 return false;
4204
4205 /* Currently we support only one fixed_rate */
4206 if ((legacy + ht + vht) != 1)
4207 return false;
4208
4209 if (ht)
4210 *preamble = WMI_RATE_PREAMBLE_HT;
4211 else if (vht)
4212 *preamble = WMI_RATE_PREAMBLE_VHT;
4213
4214 return true;
4215}
4216
4217static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004218ath10k_bitrate_mask_rate(struct ath10k *ar,
4219 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004220 enum ieee80211_band band,
4221 u8 *fixed_rate,
4222 u8 *fixed_nss)
4223{
4224 u8 rate = 0, pream = 0, nss = 0, i;
4225 enum wmi_rate_preamble preamble;
4226
4227 /* Check if single rate correct */
4228 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4229 return false;
4230
4231 pream = preamble;
4232
4233 switch (preamble) {
4234 case WMI_RATE_PREAMBLE_CCK:
4235 case WMI_RATE_PREAMBLE_OFDM:
4236 i = ffs(mask->control[band].legacy) - 1;
4237
4238 if (band == IEEE80211_BAND_2GHZ && i < 4)
4239 pream = WMI_RATE_PREAMBLE_CCK;
4240
4241 if (band == IEEE80211_BAND_5GHZ)
4242 i += 4;
4243
4244 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4245 return false;
4246
4247 rate = cck_ofdm_rate[i];
4248 break;
4249 case WMI_RATE_PREAMBLE_HT:
4250 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4251 if (mask->control[band].ht_mcs[i])
4252 break;
4253
4254 if (i == IEEE80211_HT_MCS_MASK_LEN)
4255 return false;
4256
4257 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4258 nss = i;
4259 break;
4260 case WMI_RATE_PREAMBLE_VHT:
4261 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4262 if (mask->control[band].vht_mcs[i])
4263 break;
4264
4265 if (i == NL80211_VHT_NSS_MAX)
4266 return false;
4267
4268 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4269 nss = i;
4270 break;
4271 }
4272
4273 *fixed_nss = nss + 1;
4274 nss <<= 4;
4275 pream <<= 6;
4276
Michal Kazior7aa7a722014-08-25 12:09:38 +02004277 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 +01004278 pream, nss, rate);
4279
4280 *fixed_rate = pream | nss | rate;
4281
4282 return true;
4283}
4284
Michal Kazior7aa7a722014-08-25 12:09:38 +02004285static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4286 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004287 enum ieee80211_band band,
4288 u8 *fixed_rate,
4289 u8 *fixed_nss)
4290{
4291 /* First check full NSS mask, if we can simply limit NSS */
4292 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4293 return true;
4294
4295 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004296 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004297}
4298
4299static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4300 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004301 u8 fixed_nss,
4302 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004303{
4304 struct ath10k *ar = arvif->ar;
4305 u32 vdev_param;
4306 int ret = 0;
4307
4308 mutex_lock(&ar->conf_mutex);
4309
4310 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004311 arvif->fixed_nss == fixed_nss &&
4312 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004313 goto exit;
4314
4315 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004317
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004318 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004320
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004321 vdev_param = ar->wmi.vdev_param->fixed_rate;
4322 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4323 vdev_param, fixed_rate);
4324 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004325 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004326 fixed_rate, ret);
4327 ret = -EINVAL;
4328 goto exit;
4329 }
4330
4331 arvif->fixed_rate = fixed_rate;
4332
4333 vdev_param = ar->wmi.vdev_param->nss;
4334 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4335 vdev_param, fixed_nss);
4336
4337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004338 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004339 fixed_nss, ret);
4340 ret = -EINVAL;
4341 goto exit;
4342 }
4343
4344 arvif->fixed_nss = fixed_nss;
4345
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004346 vdev_param = ar->wmi.vdev_param->sgi;
4347 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4348 force_sgi);
4349
4350 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004351 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004352 force_sgi, ret);
4353 ret = -EINVAL;
4354 goto exit;
4355 }
4356
4357 arvif->force_sgi = force_sgi;
4358
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004359exit:
4360 mutex_unlock(&ar->conf_mutex);
4361 return ret;
4362}
4363
4364static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4365 struct ieee80211_vif *vif,
4366 const struct cfg80211_bitrate_mask *mask)
4367{
4368 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4369 struct ath10k *ar = arvif->ar;
4370 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4371 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4372 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004373 u8 force_sgi;
4374
4375 force_sgi = mask->control[band].gi;
4376 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4377 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004378
4379 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004380 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004381 &fixed_rate,
4382 &fixed_nss))
4383 return -EINVAL;
4384 }
4385
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004386 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004387 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004388 return -EINVAL;
4389 }
4390
4391 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4392 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004393}
4394
Michal Kazior9797feb2014-02-14 14:49:48 +01004395static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4396 struct ieee80211_vif *vif,
4397 struct ieee80211_sta *sta,
4398 u32 changed)
4399{
4400 struct ath10k *ar = hw->priv;
4401 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4402 u32 bw, smps;
4403
4404 spin_lock_bh(&ar->data_lock);
4405
Michal Kazior7aa7a722014-08-25 12:09:38 +02004406 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004407 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4408 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4409 sta->smps_mode);
4410
4411 if (changed & IEEE80211_RC_BW_CHANGED) {
4412 bw = WMI_PEER_CHWIDTH_20MHZ;
4413
4414 switch (sta->bandwidth) {
4415 case IEEE80211_STA_RX_BW_20:
4416 bw = WMI_PEER_CHWIDTH_20MHZ;
4417 break;
4418 case IEEE80211_STA_RX_BW_40:
4419 bw = WMI_PEER_CHWIDTH_40MHZ;
4420 break;
4421 case IEEE80211_STA_RX_BW_80:
4422 bw = WMI_PEER_CHWIDTH_80MHZ;
4423 break;
4424 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004425 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004426 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004427 bw = WMI_PEER_CHWIDTH_20MHZ;
4428 break;
4429 }
4430
4431 arsta->bw = bw;
4432 }
4433
4434 if (changed & IEEE80211_RC_NSS_CHANGED)
4435 arsta->nss = sta->rx_nss;
4436
4437 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4438 smps = WMI_PEER_SMPS_PS_NONE;
4439
4440 switch (sta->smps_mode) {
4441 case IEEE80211_SMPS_AUTOMATIC:
4442 case IEEE80211_SMPS_OFF:
4443 smps = WMI_PEER_SMPS_PS_NONE;
4444 break;
4445 case IEEE80211_SMPS_STATIC:
4446 smps = WMI_PEER_SMPS_STATIC;
4447 break;
4448 case IEEE80211_SMPS_DYNAMIC:
4449 smps = WMI_PEER_SMPS_DYNAMIC;
4450 break;
4451 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004452 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004453 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004454 smps = WMI_PEER_SMPS_PS_NONE;
4455 break;
4456 }
4457
4458 arsta->smps = smps;
4459 }
4460
Michal Kazior9797feb2014-02-14 14:49:48 +01004461 arsta->changed |= changed;
4462
4463 spin_unlock_bh(&ar->data_lock);
4464
4465 ieee80211_queue_work(hw, &arsta->update_wk);
4466}
4467
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004468static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4469{
4470 /*
4471 * FIXME: Return 0 for time being. Need to figure out whether FW
4472 * has the API to fetch 64-bit local TSF
4473 */
4474
4475 return 0;
4476}
4477
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004478static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4479 struct ieee80211_vif *vif,
4480 enum ieee80211_ampdu_mlme_action action,
4481 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4482 u8 buf_size)
4483{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004484 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004485 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4486
Michal Kazior7aa7a722014-08-25 12:09:38 +02004487 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 +02004488 arvif->vdev_id, sta->addr, tid, action);
4489
4490 switch (action) {
4491 case IEEE80211_AMPDU_RX_START:
4492 case IEEE80211_AMPDU_RX_STOP:
4493 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4494 * creation/removal. Do we need to verify this?
4495 */
4496 return 0;
4497 case IEEE80211_AMPDU_TX_START:
4498 case IEEE80211_AMPDU_TX_STOP_CONT:
4499 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4500 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4501 case IEEE80211_AMPDU_TX_OPERATIONAL:
4502 /* Firmware offloads Tx aggregation entirely so deny mac80211
4503 * Tx aggregation requests.
4504 */
4505 return -EOPNOTSUPP;
4506 }
4507
4508 return -EINVAL;
4509}
4510
Kalle Valo5e3dd152013-06-12 20:52:10 +03004511static const struct ieee80211_ops ath10k_ops = {
4512 .tx = ath10k_tx,
4513 .start = ath10k_start,
4514 .stop = ath10k_stop,
4515 .config = ath10k_config,
4516 .add_interface = ath10k_add_interface,
4517 .remove_interface = ath10k_remove_interface,
4518 .configure_filter = ath10k_configure_filter,
4519 .bss_info_changed = ath10k_bss_info_changed,
4520 .hw_scan = ath10k_hw_scan,
4521 .cancel_hw_scan = ath10k_cancel_hw_scan,
4522 .set_key = ath10k_set_key,
4523 .sta_state = ath10k_sta_state,
4524 .conf_tx = ath10k_conf_tx,
4525 .remain_on_channel = ath10k_remain_on_channel,
4526 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4527 .set_rts_threshold = ath10k_set_rts_threshold,
4528 .set_frag_threshold = ath10k_set_frag_threshold,
4529 .flush = ath10k_flush,
4530 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004531 .set_antenna = ath10k_set_antenna,
4532 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004533 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004534 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004535 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004536 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004537 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004538 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004539 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4540 .get_et_stats = ath10k_debug_get_et_stats,
4541 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004542
4543 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4544
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004545#ifdef CONFIG_PM
4546 .suspend = ath10k_suspend,
4547 .resume = ath10k_resume,
4548#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004549};
4550
4551#define RATETAB_ENT(_rate, _rateid, _flags) { \
4552 .bitrate = (_rate), \
4553 .flags = (_flags), \
4554 .hw_value = (_rateid), \
4555}
4556
4557#define CHAN2G(_channel, _freq, _flags) { \
4558 .band = IEEE80211_BAND_2GHZ, \
4559 .hw_value = (_channel), \
4560 .center_freq = (_freq), \
4561 .flags = (_flags), \
4562 .max_antenna_gain = 0, \
4563 .max_power = 30, \
4564}
4565
4566#define CHAN5G(_channel, _freq, _flags) { \
4567 .band = IEEE80211_BAND_5GHZ, \
4568 .hw_value = (_channel), \
4569 .center_freq = (_freq), \
4570 .flags = (_flags), \
4571 .max_antenna_gain = 0, \
4572 .max_power = 30, \
4573}
4574
4575static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4576 CHAN2G(1, 2412, 0),
4577 CHAN2G(2, 2417, 0),
4578 CHAN2G(3, 2422, 0),
4579 CHAN2G(4, 2427, 0),
4580 CHAN2G(5, 2432, 0),
4581 CHAN2G(6, 2437, 0),
4582 CHAN2G(7, 2442, 0),
4583 CHAN2G(8, 2447, 0),
4584 CHAN2G(9, 2452, 0),
4585 CHAN2G(10, 2457, 0),
4586 CHAN2G(11, 2462, 0),
4587 CHAN2G(12, 2467, 0),
4588 CHAN2G(13, 2472, 0),
4589 CHAN2G(14, 2484, 0),
4590};
4591
4592static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004593 CHAN5G(36, 5180, 0),
4594 CHAN5G(40, 5200, 0),
4595 CHAN5G(44, 5220, 0),
4596 CHAN5G(48, 5240, 0),
4597 CHAN5G(52, 5260, 0),
4598 CHAN5G(56, 5280, 0),
4599 CHAN5G(60, 5300, 0),
4600 CHAN5G(64, 5320, 0),
4601 CHAN5G(100, 5500, 0),
4602 CHAN5G(104, 5520, 0),
4603 CHAN5G(108, 5540, 0),
4604 CHAN5G(112, 5560, 0),
4605 CHAN5G(116, 5580, 0),
4606 CHAN5G(120, 5600, 0),
4607 CHAN5G(124, 5620, 0),
4608 CHAN5G(128, 5640, 0),
4609 CHAN5G(132, 5660, 0),
4610 CHAN5G(136, 5680, 0),
4611 CHAN5G(140, 5700, 0),
4612 CHAN5G(149, 5745, 0),
4613 CHAN5G(153, 5765, 0),
4614 CHAN5G(157, 5785, 0),
4615 CHAN5G(161, 5805, 0),
4616 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004617};
4618
4619static struct ieee80211_rate ath10k_rates[] = {
4620 /* CCK */
4621 RATETAB_ENT(10, 0x82, 0),
4622 RATETAB_ENT(20, 0x84, 0),
4623 RATETAB_ENT(55, 0x8b, 0),
4624 RATETAB_ENT(110, 0x96, 0),
4625 /* OFDM */
4626 RATETAB_ENT(60, 0x0c, 0),
4627 RATETAB_ENT(90, 0x12, 0),
4628 RATETAB_ENT(120, 0x18, 0),
4629 RATETAB_ENT(180, 0x24, 0),
4630 RATETAB_ENT(240, 0x30, 0),
4631 RATETAB_ENT(360, 0x48, 0),
4632 RATETAB_ENT(480, 0x60, 0),
4633 RATETAB_ENT(540, 0x6c, 0),
4634};
4635
4636#define ath10k_a_rates (ath10k_rates + 4)
4637#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4638#define ath10k_g_rates (ath10k_rates + 0)
4639#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4640
Michal Kaziore7b54192014-08-07 11:03:27 +02004641struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004642{
4643 struct ieee80211_hw *hw;
4644 struct ath10k *ar;
4645
Michal Kaziore7b54192014-08-07 11:03:27 +02004646 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004647 if (!hw)
4648 return NULL;
4649
4650 ar = hw->priv;
4651 ar->hw = hw;
4652
4653 return ar;
4654}
4655
4656void ath10k_mac_destroy(struct ath10k *ar)
4657{
4658 ieee80211_free_hw(ar->hw);
4659}
4660
4661static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4662 {
4663 .max = 8,
4664 .types = BIT(NL80211_IFTYPE_STATION)
4665 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004666 },
4667 {
4668 .max = 3,
4669 .types = BIT(NL80211_IFTYPE_P2P_GO)
4670 },
4671 {
4672 .max = 7,
4673 .types = BIT(NL80211_IFTYPE_AP)
4674 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004675};
4676
Bartosz Markowskif2595092013-12-10 16:20:39 +01004677static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004678 {
4679 .max = 8,
4680 .types = BIT(NL80211_IFTYPE_AP)
4681 },
4682};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004683
4684static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4685 {
4686 .limits = ath10k_if_limits,
4687 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4688 .max_interfaces = 8,
4689 .num_different_channels = 1,
4690 .beacon_int_infra_match = true,
4691 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004692};
4693
4694static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004695 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004696 .limits = ath10k_10x_if_limits,
4697 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004698 .max_interfaces = 8,
4699 .num_different_channels = 1,
4700 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004701#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004702 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4703 BIT(NL80211_CHAN_WIDTH_20) |
4704 BIT(NL80211_CHAN_WIDTH_40) |
4705 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004706#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004707 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004708};
4709
4710static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4711{
4712 struct ieee80211_sta_vht_cap vht_cap = {0};
4713 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004714 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004715
4716 vht_cap.vht_supported = 1;
4717 vht_cap.cap = ar->vht_cap_info;
4718
Michal Kazior8865bee42013-07-24 12:36:46 +02004719 mcs_map = 0;
4720 for (i = 0; i < 8; i++) {
4721 if (i < ar->num_rf_chains)
4722 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4723 else
4724 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4725 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004726
4727 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4728 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4729
4730 return vht_cap;
4731}
4732
4733static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4734{
4735 int i;
4736 struct ieee80211_sta_ht_cap ht_cap = {0};
4737
4738 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4739 return ht_cap;
4740
4741 ht_cap.ht_supported = 1;
4742 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4743 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4744 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4745 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4746 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4747
4748 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4749 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4750
4751 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4752 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4753
4754 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4755 u32 smps;
4756
4757 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4758 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4759
4760 ht_cap.cap |= smps;
4761 }
4762
4763 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4764 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4765
4766 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4767 u32 stbc;
4768
4769 stbc = ar->ht_cap_info;
4770 stbc &= WMI_HT_CAP_RX_STBC;
4771 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4772 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4773 stbc &= IEEE80211_HT_CAP_RX_STBC;
4774
4775 ht_cap.cap |= stbc;
4776 }
4777
4778 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4779 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4780
4781 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4782 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4783
4784 /* max AMSDU is implicitly taken from vht_cap_info */
4785 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4786 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4787
Michal Kazior8865bee42013-07-24 12:36:46 +02004788 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004789 ht_cap.mcs.rx_mask[i] = 0xFF;
4790
4791 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4792
4793 return ht_cap;
4794}
4795
Kalle Valo5e3dd152013-06-12 20:52:10 +03004796static void ath10k_get_arvif_iter(void *data, u8 *mac,
4797 struct ieee80211_vif *vif)
4798{
4799 struct ath10k_vif_iter *arvif_iter = data;
4800 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4801
4802 if (arvif->vdev_id == arvif_iter->vdev_id)
4803 arvif_iter->arvif = arvif;
4804}
4805
4806struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4807{
4808 struct ath10k_vif_iter arvif_iter;
4809 u32 flags;
4810
4811 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4812 arvif_iter.vdev_id = vdev_id;
4813
4814 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4815 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4816 flags,
4817 ath10k_get_arvif_iter,
4818 &arvif_iter);
4819 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004820 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004821 return NULL;
4822 }
4823
4824 return arvif_iter.arvif;
4825}
4826
4827int ath10k_mac_register(struct ath10k *ar)
4828{
4829 struct ieee80211_supported_band *band;
4830 struct ieee80211_sta_vht_cap vht_cap;
4831 struct ieee80211_sta_ht_cap ht_cap;
4832 void *channels;
4833 int ret;
4834
4835 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4836
4837 SET_IEEE80211_DEV(ar->hw, ar->dev);
4838
4839 ht_cap = ath10k_get_ht_cap(ar);
4840 vht_cap = ath10k_create_vht_cap(ar);
4841
4842 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4843 channels = kmemdup(ath10k_2ghz_channels,
4844 sizeof(ath10k_2ghz_channels),
4845 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004846 if (!channels) {
4847 ret = -ENOMEM;
4848 goto err_free;
4849 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004850
4851 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4852 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4853 band->channels = channels;
4854 band->n_bitrates = ath10k_g_rates_size;
4855 band->bitrates = ath10k_g_rates;
4856 band->ht_cap = ht_cap;
4857
4858 /* vht is not supported in 2.4 GHz */
4859
4860 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4861 }
4862
4863 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4864 channels = kmemdup(ath10k_5ghz_channels,
4865 sizeof(ath10k_5ghz_channels),
4866 GFP_KERNEL);
4867 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004868 ret = -ENOMEM;
4869 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004870 }
4871
4872 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4873 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4874 band->channels = channels;
4875 band->n_bitrates = ath10k_a_rates_size;
4876 band->bitrates = ath10k_a_rates;
4877 band->ht_cap = ht_cap;
4878 band->vht_cap = vht_cap;
4879 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4880 }
4881
4882 ar->hw->wiphy->interface_modes =
4883 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004884 BIT(NL80211_IFTYPE_AP);
4885
Ben Greear46acf7b2014-05-16 17:15:38 +03004886 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4887 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4888
Bartosz Markowskid3541812013-12-10 16:20:40 +01004889 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4890 ar->hw->wiphy->interface_modes |=
4891 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4892 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004893
4894 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4895 IEEE80211_HW_SUPPORTS_PS |
4896 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4897 IEEE80211_HW_SUPPORTS_UAPSD |
4898 IEEE80211_HW_MFP_CAPABLE |
4899 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4900 IEEE80211_HW_HAS_RATE_CONTROL |
4901 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004902 IEEE80211_HW_AP_LINK_PS |
4903 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004904
Michal Kazior1f8bb152013-09-18 14:43:22 +02004905 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4906 * bytes is used for padding/alignment if necessary. */
4907 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4908
Kalle Valo5e3dd152013-06-12 20:52:10 +03004909 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4910 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4911
4912 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4913 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4914 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4915 }
4916
4917 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4918 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4919
4920 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004921 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004922
Kalle Valo5e3dd152013-06-12 20:52:10 +03004923 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4924
4925 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004926 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004927 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4928
4929 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4930 /*
4931 * on LL hardware queues are managed entirely by the FW
4932 * so we only advertise to mac we can do the queues thing
4933 */
4934 ar->hw->queues = 4;
4935
Bartosz Markowskif2595092013-12-10 16:20:39 +01004936 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4937 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4938 ar->hw->wiphy->n_iface_combinations =
4939 ARRAY_SIZE(ath10k_10x_if_comb);
4940 } else {
4941 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4942 ar->hw->wiphy->n_iface_combinations =
4943 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004944
4945 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004946 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004947
Michal Kazior7c199992013-07-31 10:47:57 +02004948 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4949
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004950 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4951 /* Init ath dfs pattern detector */
4952 ar->ath_common.debug_mask = ATH_DBG_DFS;
4953 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4954 NL80211_DFS_UNSET);
4955
4956 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004957 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004958 }
4959
Kalle Valo5e3dd152013-06-12 20:52:10 +03004960 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4961 ath10k_reg_notifier);
4962 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004963 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004964 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004965 }
4966
4967 ret = ieee80211_register_hw(ar->hw);
4968 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004969 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004970 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004971 }
4972
4973 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4974 ret = regulatory_hint(ar->hw->wiphy,
4975 ar->ath_common.regulatory.alpha2);
4976 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004977 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004978 }
4979
4980 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004981
4982err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004983 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004984err_free:
4985 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4986 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4987
Kalle Valo5e3dd152013-06-12 20:52:10 +03004988 return ret;
4989}
4990
4991void ath10k_mac_unregister(struct ath10k *ar)
4992{
4993 ieee80211_unregister_hw(ar->hw);
4994
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004995 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4996 ar->dfs_detector->exit(ar->dfs_detector);
4997
Kalle Valo5e3dd152013-06-12 20:52:10 +03004998 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4999 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5000
5001 SET_IEEE80211_DEV(ar->hw, NULL);
5002}