blob: f45eca0b7a4ee57090d89bf5e3a2792e1e3f8916 [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"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
71 break;
72 default:
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
88 const u8 *macaddr)
89{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Kalle Valo5e3dd152013-06-12 20:52:10 +030095 INIT_COMPLETION(ar->install_key_done);
96
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
98 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
128
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 addr);
131 if (ret)
132 return ret;
133
134 peer->keys[i] = arvif->wep_keys[i];
135 }
136
137 return 0;
138}
139
140static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
141 const u8 *addr)
142{
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
145 int first_errno = 0;
146 int ret;
147 int i;
148
149 lockdep_assert_held(&ar->conf_mutex);
150
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
154
155 if (!peer)
156 return -ENOENT;
157
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
160 continue;
161
162 ret = ath10k_install_key(arvif, peer->keys[i],
163 DISABLE_KEY, addr);
164 if (ret && first_errno == 0)
165 first_errno = ret;
166
167 if (ret)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
169 i, ret);
170
171 peer->keys[i] = NULL;
172 }
173
174 return first_errno;
175}
176
177static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
179{
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
182 u8 addr[ETH_ALEN];
183 int first_errno = 0;
184 int ret;
185 int i;
186
187 lockdep_assert_held(&ar->conf_mutex);
188
189 for (;;) {
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
193 i = 0;
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
199 break;
200 }
201 }
202
203 if (i < ARRAY_SIZE(peer->keys))
204 break;
205 }
206 spin_unlock_bh(&ar->data_lock);
207
208 if (i == ARRAY_SIZE(peer->keys))
209 break;
210
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
213 first_errno = ret;
214
215 if (ret)
216 ath10k_warn("could not remove key for %pM\n", addr);
217 }
218
219 return first_errno;
220}
221
222
223/*********************/
224/* General utilities */
225/*********************/
226
227static inline enum wmi_phy_mode
228chan_to_phymode(const struct cfg80211_chan_def *chandef)
229{
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
236 phymode = MODE_11G;
237 break;
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
240 break;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
243 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
250 break;
251 }
252 break;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
256 phymode = MODE_11A;
257 break;
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
260 break;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
266 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
272 break;
273 }
274 break;
275 default:
276 break;
277 }
278
279 WARN_ON(phymode == MODE_UNKNOWN);
280 return phymode;
281}
282
283static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
284{
285/*
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
288 * 1 for 1/4 us
289 * 2 for 1/2 us
290 * 3 for 1 us
291 * 4 for 2 us
292 * 5 for 4 us
293 * 6 for 8 us
294 * 7 for 16 us
295 */
296 switch (mpdudensity) {
297 case 0:
298 return 0;
299 case 1:
300 case 2:
301 case 3:
302 /* Our lower layer calculations limit our precision to
303 1 microsecond */
304 return 1;
305 case 4:
306 return 2;
307 case 5:
308 return 4;
309 case 6:
310 return 8;
311 case 7:
312 return 16;
313 default:
314 return 0;
315 }
316}
317
318static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
319{
320 int ret;
321
322 lockdep_assert_held(&ar->conf_mutex);
323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
325 if (ret)
326 return ret;
327
328 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
329 if (ret)
330 return ret;
331
332 return 0;
333}
334
Michal Kazior424121c2013-07-22 14:13:31 +0200335static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
336{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200337 struct ath10k *ar = arvif->ar;
338 u32 vdev_param;
339
Michal Kazior424121c2013-07-22 14:13:31 +0200340 if (value != 0xFFFFFFFF)
341 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
342 ATH10K_RTS_MAX);
343
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200344 vdev_param = ar->wmi.vdev_param->rts_threshold;
345 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200346}
347
348static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
349{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200350 struct ath10k *ar = arvif->ar;
351 u32 vdev_param;
352
Michal Kazior424121c2013-07-22 14:13:31 +0200353 if (value != 0xFFFFFFFF)
354 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
355 ATH10K_FRAGMT_THRESHOLD_MIN,
356 ATH10K_FRAGMT_THRESHOLD_MAX);
357
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200358 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
359 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200360}
361
Kalle Valo5e3dd152013-06-12 20:52:10 +0300362static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
363{
364 int ret;
365
366 lockdep_assert_held(&ar->conf_mutex);
367
368 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
369 if (ret)
370 return ret;
371
372 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
373 if (ret)
374 return ret;
375
376 return 0;
377}
378
379static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
380{
381 struct ath10k_peer *peer, *tmp;
382
383 lockdep_assert_held(&ar->conf_mutex);
384
385 spin_lock_bh(&ar->data_lock);
386 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
387 if (peer->vdev_id != vdev_id)
388 continue;
389
390 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
391 peer->addr, vdev_id);
392
393 list_del(&peer->list);
394 kfree(peer);
395 }
396 spin_unlock_bh(&ar->data_lock);
397}
398
Michal Kaziora96d7742013-07-16 09:38:56 +0200399static void ath10k_peer_cleanup_all(struct ath10k *ar)
400{
401 struct ath10k_peer *peer, *tmp;
402
403 lockdep_assert_held(&ar->conf_mutex);
404
405 spin_lock_bh(&ar->data_lock);
406 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
407 list_del(&peer->list);
408 kfree(peer);
409 }
410 spin_unlock_bh(&ar->data_lock);
411}
412
Kalle Valo5e3dd152013-06-12 20:52:10 +0300413/************************/
414/* Interface management */
415/************************/
416
417static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
418{
419 int ret;
420
Michal Kazior548db542013-07-05 16:15:15 +0300421 lockdep_assert_held(&ar->conf_mutex);
422
Kalle Valo5e3dd152013-06-12 20:52:10 +0300423 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
424 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
425 if (ret == 0)
426 return -ETIMEDOUT;
427
428 return 0;
429}
430
431static int ath10k_vdev_start(struct ath10k_vif *arvif)
432{
433 struct ath10k *ar = arvif->ar;
434 struct ieee80211_conf *conf = &ar->hw->conf;
435 struct ieee80211_channel *channel = conf->chandef.chan;
436 struct wmi_vdev_start_request_arg arg = {};
437 int ret = 0;
438
439 lockdep_assert_held(&ar->conf_mutex);
440
441 INIT_COMPLETION(ar->vdev_setup_done);
442
443 arg.vdev_id = arvif->vdev_id;
444 arg.dtim_period = arvif->dtim_period;
445 arg.bcn_intval = arvif->beacon_interval;
446
447 arg.channel.freq = channel->center_freq;
448
449 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
450
451 arg.channel.mode = chan_to_phymode(&conf->chandef);
452
Michal Kazior89c5c842013-10-23 04:02:13 -0700453 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700454 arg.channel.max_power = channel->max_power * 2;
455 arg.channel.max_reg_power = channel->max_reg_power * 2;
456 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300457
458 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
459 arg.ssid = arvif->u.ap.ssid;
460 arg.ssid_len = arvif->u.ap.ssid_len;
461 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
462 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
463 arg.ssid = arvif->vif->bss_conf.ssid;
464 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
465 }
466
Kalle Valo38a1d472013-09-08 17:56:14 +0300467 ath10k_dbg(ATH10K_DBG_MAC,
468 "mac vdev %d start center_freq %d phymode %s\n",
469 arg.vdev_id, arg.channel.freq,
470 ath10k_wmi_phymode_str(arg.channel.mode));
471
Kalle Valo5e3dd152013-06-12 20:52:10 +0300472 ret = ath10k_wmi_vdev_start(ar, &arg);
473 if (ret) {
474 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
475 return ret;
476 }
477
478 ret = ath10k_vdev_setup_sync(ar);
479 if (ret) {
480 ath10k_warn("vdev setup failed %d\n", ret);
481 return ret;
482 }
483
484 return ret;
485}
486
487static int ath10k_vdev_stop(struct ath10k_vif *arvif)
488{
489 struct ath10k *ar = arvif->ar;
490 int ret;
491
492 lockdep_assert_held(&ar->conf_mutex);
493
494 INIT_COMPLETION(ar->vdev_setup_done);
495
496 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
497 if (ret) {
498 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
499 return ret;
500 }
501
502 ret = ath10k_vdev_setup_sync(ar);
503 if (ret) {
504 ath10k_warn("vdev setup failed %d\n", ret);
505 return ret;
506 }
507
508 return ret;
509}
510
511static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
512{
513 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
514 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300515 int ret = 0;
516
517 lockdep_assert_held(&ar->conf_mutex);
518
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300519 if (!ar->monitor_present) {
520 ath10k_warn("mac montor stop -- monitor is not present\n");
521 return -EINVAL;
522 }
523
Kalle Valo5e3dd152013-06-12 20:52:10 +0300524 arg.vdev_id = vdev_id;
525 arg.channel.freq = channel->center_freq;
526 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
527
528 /* TODO setup this dynamically, what in case we
529 don't have any vifs? */
530 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
531
Michal Kazior89c5c842013-10-23 04:02:13 -0700532 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700533 arg.channel.max_power = channel->max_power * 2;
534 arg.channel.max_reg_power = channel->max_reg_power * 2;
535 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300536
537 ret = ath10k_wmi_vdev_start(ar, &arg);
538 if (ret) {
539 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
540 return ret;
541 }
542
543 ret = ath10k_vdev_setup_sync(ar);
544 if (ret) {
545 ath10k_warn("Monitor vdev setup failed %d\n", ret);
546 return ret;
547 }
548
549 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
550 if (ret) {
551 ath10k_warn("Monitor vdev up failed: %d\n", ret);
552 goto vdev_stop;
553 }
554
555 ar->monitor_vdev_id = vdev_id;
556 ar->monitor_enabled = true;
557
558 return 0;
559
560vdev_stop:
561 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
562 if (ret)
563 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
564
565 return ret;
566}
567
568static int ath10k_monitor_stop(struct ath10k *ar)
569{
570 int ret = 0;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300574 if (!ar->monitor_present) {
575 ath10k_warn("mac montor stop -- monitor is not present\n");
576 return -EINVAL;
577 }
578
579 if (!ar->monitor_enabled) {
580 ath10k_warn("mac montor stop -- monitor is not enabled\n");
581 return -EINVAL;
582 }
583
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200584 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
585 if (ret)
586 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300587
588 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
589 if (ret)
590 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
591
592 ret = ath10k_vdev_setup_sync(ar);
593 if (ret)
594 ath10k_warn("Monitor_down sync failed: %d\n", ret);
595
596 ar->monitor_enabled = false;
597 return ret;
598}
599
600static int ath10k_monitor_create(struct ath10k *ar)
601{
602 int bit, ret = 0;
603
604 lockdep_assert_held(&ar->conf_mutex);
605
606 if (ar->monitor_present) {
607 ath10k_warn("Monitor mode already enabled\n");
608 return 0;
609 }
610
611 bit = ffs(ar->free_vdev_map);
612 if (bit == 0) {
613 ath10k_warn("No free VDEV slots\n");
614 return -ENOMEM;
615 }
616
617 ar->monitor_vdev_id = bit - 1;
618 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
619
620 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
621 WMI_VDEV_TYPE_MONITOR,
622 0, ar->mac_addr);
623 if (ret) {
624 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
625 goto vdev_fail;
626 }
627
Kalle Valo60c3daa2013-09-08 17:56:07 +0300628 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300629 ar->monitor_vdev_id);
630
631 ar->monitor_present = true;
632 return 0;
633
634vdev_fail:
635 /*
636 * Restore the ID to the global map.
637 */
638 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
639 return ret;
640}
641
642static int ath10k_monitor_destroy(struct ath10k *ar)
643{
644 int ret = 0;
645
646 lockdep_assert_held(&ar->conf_mutex);
647
648 if (!ar->monitor_present)
649 return 0;
650
651 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
652 if (ret) {
653 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
654 return ret;
655 }
656
657 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
658 ar->monitor_present = false;
659
Kalle Valo60c3daa2013-09-08 17:56:07 +0300660 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300661 ar->monitor_vdev_id);
662 return ret;
663}
664
665static void ath10k_control_beaconing(struct ath10k_vif *arvif,
666 struct ieee80211_bss_conf *info)
667{
668 int ret = 0;
669
Michal Kazior548db542013-07-05 16:15:15 +0300670 lockdep_assert_held(&arvif->ar->conf_mutex);
671
Kalle Valo5e3dd152013-06-12 20:52:10 +0300672 if (!info->enable_beacon) {
673 ath10k_vdev_stop(arvif);
674 return;
675 }
676
677 arvif->tx_seq_no = 0x1000;
678
679 ret = ath10k_vdev_start(arvif);
680 if (ret)
681 return;
682
683 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
684 if (ret) {
685 ath10k_warn("Failed to bring up VDEV: %d\n",
686 arvif->vdev_id);
687 return;
688 }
Kalle Valo60c3daa2013-09-08 17:56:07 +0300689 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300690}
691
692static void ath10k_control_ibss(struct ath10k_vif *arvif,
693 struct ieee80211_bss_conf *info,
694 const u8 self_peer[ETH_ALEN])
695{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200696 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697 int ret = 0;
698
Michal Kazior548db542013-07-05 16:15:15 +0300699 lockdep_assert_held(&arvif->ar->conf_mutex);
700
Kalle Valo5e3dd152013-06-12 20:52:10 +0300701 if (!info->ibss_joined) {
702 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
703 if (ret)
704 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
705 self_peer, arvif->vdev_id, ret);
706
707 if (is_zero_ether_addr(arvif->u.ibss.bssid))
708 return;
709
710 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
711 arvif->u.ibss.bssid);
712 if (ret) {
713 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
714 arvif->u.ibss.bssid, arvif->vdev_id, ret);
715 return;
716 }
717
718 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
719
720 return;
721 }
722
723 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
724 if (ret) {
725 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
726 self_peer, arvif->vdev_id, ret);
727 return;
728 }
729
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200730 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
731 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300732 ATH10K_DEFAULT_ATIM);
733 if (ret)
734 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
735 arvif->vdev_id, ret);
736}
737
738/*
739 * Review this when mac80211 gains per-interface powersave support.
740 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300741static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300742{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300743 struct ath10k *ar = arvif->ar;
744 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300745 enum wmi_sta_powersave_param param;
746 enum wmi_sta_ps_mode psmode;
747 int ret;
748
Michal Kazior548db542013-07-05 16:15:15 +0300749 lockdep_assert_held(&arvif->ar->conf_mutex);
750
Michal Kaziorad088bf2013-10-16 15:44:46 +0300751 if (arvif->vif->type != NL80211_IFTYPE_STATION)
752 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300753
754 if (conf->flags & IEEE80211_CONF_PS) {
755 psmode = WMI_STA_PS_MODE_ENABLED;
756 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
757
Michal Kaziorad088bf2013-10-16 15:44:46 +0300758 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300759 conf->dynamic_ps_timeout);
760 if (ret) {
761 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
762 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300763 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300764 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300765 } else {
766 psmode = WMI_STA_PS_MODE_DISABLED;
767 }
768
Kalle Valo60c3daa2013-09-08 17:56:07 +0300769 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
770 arvif->vdev_id, psmode ? "enable" : "disable");
771
Michal Kaziorad088bf2013-10-16 15:44:46 +0300772 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
773 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300774 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
775 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300776 return ret;
777 }
778
779 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300780}
781
782/**********************/
783/* Station management */
784/**********************/
785
786static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
787 struct ath10k_vif *arvif,
788 struct ieee80211_sta *sta,
789 struct ieee80211_bss_conf *bss_conf,
790 struct wmi_peer_assoc_complete_arg *arg)
791{
Michal Kazior548db542013-07-05 16:15:15 +0300792 lockdep_assert_held(&ar->conf_mutex);
793
Kalle Valo5e3dd152013-06-12 20:52:10 +0300794 memcpy(arg->addr, sta->addr, ETH_ALEN);
795 arg->vdev_id = arvif->vdev_id;
796 arg->peer_aid = sta->aid;
797 arg->peer_flags |= WMI_PEER_AUTH;
798
799 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
800 /*
801 * Seems FW have problems with Power Save in STA
802 * mode when we setup this parameter to high (eg. 5).
803 * Often we see that FW don't send NULL (with clean P flags)
804 * frame even there is info about buffered frames in beacons.
805 * Sometimes we have to wait more than 10 seconds before FW
806 * will wakeup. Often sending one ping from AP to our device
807 * just fail (more than 50%).
808 *
809 * Seems setting this FW parameter to 1 couse FW
810 * will check every beacon and will wakup immediately
811 * after detection buffered data.
812 */
813 arg->peer_listen_intval = 1;
814 else
815 arg->peer_listen_intval = ar->hw->conf.listen_interval;
816
817 arg->peer_num_spatial_streams = 1;
818
819 /*
820 * The assoc capabilities are available only in managed mode.
821 */
822 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
823 arg->peer_caps = bss_conf->assoc_capability;
824}
825
826static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
827 struct ath10k_vif *arvif,
828 struct wmi_peer_assoc_complete_arg *arg)
829{
830 struct ieee80211_vif *vif = arvif->vif;
831 struct ieee80211_bss_conf *info = &vif->bss_conf;
832 struct cfg80211_bss *bss;
833 const u8 *rsnie = NULL;
834 const u8 *wpaie = NULL;
835
Michal Kazior548db542013-07-05 16:15:15 +0300836 lockdep_assert_held(&ar->conf_mutex);
837
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
839 info->bssid, NULL, 0, 0, 0);
840 if (bss) {
841 const struct cfg80211_bss_ies *ies;
842
843 rcu_read_lock();
844 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
845
846 ies = rcu_dereference(bss->ies);
847
848 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
849 WLAN_OUI_TYPE_MICROSOFT_WPA,
850 ies->data,
851 ies->len);
852 rcu_read_unlock();
853 cfg80211_put_bss(ar->hw->wiphy, bss);
854 }
855
856 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
857 if (rsnie || wpaie) {
858 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
859 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
860 }
861
862 if (wpaie) {
863 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
864 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
865 }
866}
867
868static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
869 struct ieee80211_sta *sta,
870 struct wmi_peer_assoc_complete_arg *arg)
871{
872 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
873 const struct ieee80211_supported_band *sband;
874 const struct ieee80211_rate *rates;
875 u32 ratemask;
876 int i;
877
Michal Kazior548db542013-07-05 16:15:15 +0300878 lockdep_assert_held(&ar->conf_mutex);
879
Kalle Valo5e3dd152013-06-12 20:52:10 +0300880 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
881 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
882 rates = sband->bitrates;
883
884 rateset->num_rates = 0;
885
886 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
887 if (!(ratemask & 1))
888 continue;
889
890 rateset->rates[rateset->num_rates] = rates->hw_value;
891 rateset->num_rates++;
892 }
893}
894
895static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
896 struct ieee80211_sta *sta,
897 struct wmi_peer_assoc_complete_arg *arg)
898{
899 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
900 int smps;
901 int i, n;
902
Michal Kazior548db542013-07-05 16:15:15 +0300903 lockdep_assert_held(&ar->conf_mutex);
904
Kalle Valo5e3dd152013-06-12 20:52:10 +0300905 if (!ht_cap->ht_supported)
906 return;
907
908 arg->peer_flags |= WMI_PEER_HT;
909 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
910 ht_cap->ampdu_factor)) - 1;
911
912 arg->peer_mpdu_density =
913 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
914
915 arg->peer_ht_caps = ht_cap->cap;
916 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
917
918 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
919 arg->peer_flags |= WMI_PEER_LDPC;
920
921 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
922 arg->peer_flags |= WMI_PEER_40MHZ;
923 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
924 }
925
926 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
927 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
928
929 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
930 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
931
932 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
933 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
934 arg->peer_flags |= WMI_PEER_STBC;
935 }
936
937 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
938 u32 stbc;
939 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
940 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
941 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
942 arg->peer_rate_caps |= stbc;
943 arg->peer_flags |= WMI_PEER_STBC;
944 }
945
946 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
947 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
948
949 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
950 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
951 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
952 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
953 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
954 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
955 }
956
957 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
958 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
959 else if (ht_cap->mcs.rx_mask[1])
960 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
961
962 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
963 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
964 arg->peer_ht_rates.rates[n++] = i;
965
966 arg->peer_ht_rates.num_rates = n;
967 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
968
Kalle Valo60c3daa2013-09-08 17:56:07 +0300969 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
970 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 arg->peer_ht_rates.num_rates,
972 arg->peer_num_spatial_streams);
973}
974
975static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
976 struct ath10k_vif *arvif,
977 struct ieee80211_sta *sta,
978 struct ieee80211_bss_conf *bss_conf,
979 struct wmi_peer_assoc_complete_arg *arg)
980{
981 u32 uapsd = 0;
982 u32 max_sp = 0;
983
Michal Kazior548db542013-07-05 16:15:15 +0300984 lockdep_assert_held(&ar->conf_mutex);
985
Kalle Valo5e3dd152013-06-12 20:52:10 +0300986 if (sta->wme)
987 arg->peer_flags |= WMI_PEER_QOS;
988
989 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +0300990 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 sta->uapsd_queues, sta->max_sp);
992
993 arg->peer_flags |= WMI_PEER_APSD;
Janusz Dziedzicc69029b2013-08-07 12:10:49 +0200994 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300995
996 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
997 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
998 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
999 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1000 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1001 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1002 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1003 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1004 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1005 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1006 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1007 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1008
1009
1010 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1011 max_sp = sta->max_sp;
1012
1013 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1014 sta->addr,
1015 WMI_AP_PS_PEER_PARAM_UAPSD,
1016 uapsd);
1017
1018 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1019 sta->addr,
1020 WMI_AP_PS_PEER_PARAM_MAX_SP,
1021 max_sp);
1022
1023 /* TODO setup this based on STA listen interval and
1024 beacon interval. Currently we don't know
1025 sta->listen_interval - mac80211 patch required.
1026 Currently use 10 seconds */
1027 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1028 sta->addr,
1029 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1030 10);
1031 }
1032}
1033
1034static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1035 struct ath10k_vif *arvif,
1036 struct ieee80211_sta *sta,
1037 struct ieee80211_bss_conf *bss_conf,
1038 struct wmi_peer_assoc_complete_arg *arg)
1039{
1040 if (bss_conf->qos)
1041 arg->peer_flags |= WMI_PEER_QOS;
1042}
1043
1044static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1045 struct ieee80211_sta *sta,
1046 struct wmi_peer_assoc_complete_arg *arg)
1047{
1048 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001049 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001050
1051 if (!vht_cap->vht_supported)
1052 return;
1053
1054 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001055 arg->peer_vht_caps = vht_cap->cap;
1056
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001057
1058 ampdu_factor = (vht_cap->cap &
1059 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1060 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1061
1062 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1063 * zero in VHT IE. Using it would result in degraded throughput.
1064 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1065 * it if VHT max_mpdu is smaller. */
1066 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1067 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1068 ampdu_factor)) - 1);
1069
Kalle Valo5e3dd152013-06-12 20:52:10 +03001070 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1071 arg->peer_flags |= WMI_PEER_80MHZ;
1072
1073 arg->peer_vht_rates.rx_max_rate =
1074 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1075 arg->peer_vht_rates.rx_mcs_set =
1076 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1077 arg->peer_vht_rates.tx_max_rate =
1078 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1079 arg->peer_vht_rates.tx_mcs_set =
1080 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1081
Kalle Valo60c3daa2013-09-08 17:56:07 +03001082 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1083 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001084}
1085
1086static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1087 struct ath10k_vif *arvif,
1088 struct ieee80211_sta *sta,
1089 struct ieee80211_bss_conf *bss_conf,
1090 struct wmi_peer_assoc_complete_arg *arg)
1091{
1092 switch (arvif->vdev_type) {
1093 case WMI_VDEV_TYPE_AP:
1094 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1095 break;
1096 case WMI_VDEV_TYPE_STA:
1097 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1098 break;
1099 default:
1100 break;
1101 }
1102}
1103
1104static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1105 struct ath10k_vif *arvif,
1106 struct ieee80211_sta *sta,
1107 struct wmi_peer_assoc_complete_arg *arg)
1108{
1109 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1110
Kalle Valo5e3dd152013-06-12 20:52:10 +03001111 switch (ar->hw->conf.chandef.chan->band) {
1112 case IEEE80211_BAND_2GHZ:
1113 if (sta->ht_cap.ht_supported) {
1114 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1115 phymode = MODE_11NG_HT40;
1116 else
1117 phymode = MODE_11NG_HT20;
1118 } else {
1119 phymode = MODE_11G;
1120 }
1121
1122 break;
1123 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001124 /*
1125 * Check VHT first.
1126 */
1127 if (sta->vht_cap.vht_supported) {
1128 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1129 phymode = MODE_11AC_VHT80;
1130 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1131 phymode = MODE_11AC_VHT40;
1132 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1133 phymode = MODE_11AC_VHT20;
1134 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001135 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1136 phymode = MODE_11NA_HT40;
1137 else
1138 phymode = MODE_11NA_HT20;
1139 } else {
1140 phymode = MODE_11A;
1141 }
1142
1143 break;
1144 default:
1145 break;
1146 }
1147
Kalle Valo38a1d472013-09-08 17:56:14 +03001148 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1149 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001150
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 arg->peer_phymode = phymode;
1152 WARN_ON(phymode == MODE_UNKNOWN);
1153}
1154
Kalle Valob9ada652013-10-16 15:44:46 +03001155static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1156 struct ath10k_vif *arvif,
1157 struct ieee80211_sta *sta,
1158 struct ieee80211_bss_conf *bss_conf,
1159 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001160{
Michal Kazior548db542013-07-05 16:15:15 +03001161 lockdep_assert_held(&ar->conf_mutex);
1162
Kalle Valob9ada652013-10-16 15:44:46 +03001163 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001164
Kalle Valob9ada652013-10-16 15:44:46 +03001165 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1166 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1167 ath10k_peer_assoc_h_rates(ar, sta, arg);
1168 ath10k_peer_assoc_h_ht(ar, sta, arg);
1169 ath10k_peer_assoc_h_vht(ar, sta, arg);
1170 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1171 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172
Kalle Valob9ada652013-10-16 15:44:46 +03001173 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174}
1175
1176/* can be called only in mac80211 callbacks due to `key_count` usage */
1177static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1178 struct ieee80211_vif *vif,
1179 struct ieee80211_bss_conf *bss_conf)
1180{
1181 struct ath10k *ar = hw->priv;
1182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001183 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001184 struct ieee80211_sta *ap_sta;
1185 int ret;
1186
Michal Kazior548db542013-07-05 16:15:15 +03001187 lockdep_assert_held(&ar->conf_mutex);
1188
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189 rcu_read_lock();
1190
1191 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1192 if (!ap_sta) {
1193 ath10k_warn("Failed to find station entry for %pM\n",
1194 bss_conf->bssid);
1195 rcu_read_unlock();
1196 return;
1197 }
1198
Kalle Valob9ada652013-10-16 15:44:46 +03001199 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1200 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001201 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001202 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1203 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001204 rcu_read_unlock();
1205 return;
1206 }
1207
1208 rcu_read_unlock();
1209
Kalle Valob9ada652013-10-16 15:44:46 +03001210 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1211 if (ret) {
1212 ath10k_warn("Peer assoc failed for %pM\n: %d",
1213 bss_conf->bssid, ret);
1214 return;
1215 }
1216
Kalle Valo60c3daa2013-09-08 17:56:07 +03001217 ath10k_dbg(ATH10K_DBG_MAC,
1218 "mac vdev %d up (associated) bssid %pM aid %d\n",
1219 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1220
Kalle Valo5e3dd152013-06-12 20:52:10 +03001221 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1222 bss_conf->bssid);
1223 if (ret)
1224 ath10k_warn("VDEV: %d up failed: ret %d\n",
1225 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226}
1227
1228/*
1229 * FIXME: flush TIDs
1230 */
1231static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1232 struct ieee80211_vif *vif)
1233{
1234 struct ath10k *ar = hw->priv;
1235 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1236 int ret;
1237
Michal Kazior548db542013-07-05 16:15:15 +03001238 lockdep_assert_held(&ar->conf_mutex);
1239
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240 /*
1241 * For some reason, calling VDEV-DOWN before VDEV-STOP
1242 * makes the FW to send frames via HTT after disassociation.
1243 * No idea why this happens, even though VDEV-DOWN is supposed
1244 * to be analogous to link down, so just stop the VDEV.
1245 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001246 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1247 arvif->vdev_id);
1248
1249 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001250 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001251
1252 /*
1253 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1254 * report beacons from previously associated network through HTT.
1255 * This in turn would spam mac80211 WARN_ON if we bring down all
1256 * interfaces as it expects there is no rx when no interface is
1257 * running.
1258 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001259 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1260
1261 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001264 arvif->def_wep_key_idx = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001265}
1266
1267static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta)
1269{
Kalle Valob9ada652013-10-16 15:44:46 +03001270 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001271 int ret = 0;
1272
Michal Kazior548db542013-07-05 16:15:15 +03001273 lockdep_assert_held(&ar->conf_mutex);
1274
Kalle Valob9ada652013-10-16 15:44:46 +03001275 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001276 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001277 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1278 sta->addr);
1279 return ret;
1280 }
1281
1282 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1283 if (ret) {
1284 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1285 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286 return ret;
1287 }
1288
1289 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1290 if (ret) {
1291 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1292 return ret;
1293 }
1294
1295 return ret;
1296}
1297
1298static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1299 struct ieee80211_sta *sta)
1300{
1301 int ret = 0;
1302
Michal Kazior548db542013-07-05 16:15:15 +03001303 lockdep_assert_held(&ar->conf_mutex);
1304
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1306 if (ret) {
1307 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1308 return ret;
1309 }
1310
1311 return ret;
1312}
1313
1314/**************/
1315/* Regulatory */
1316/**************/
1317
1318static int ath10k_update_channel_list(struct ath10k *ar)
1319{
1320 struct ieee80211_hw *hw = ar->hw;
1321 struct ieee80211_supported_band **bands;
1322 enum ieee80211_band band;
1323 struct ieee80211_channel *channel;
1324 struct wmi_scan_chan_list_arg arg = {0};
1325 struct wmi_channel_arg *ch;
1326 bool passive;
1327 int len;
1328 int ret;
1329 int i;
1330
Michal Kazior548db542013-07-05 16:15:15 +03001331 lockdep_assert_held(&ar->conf_mutex);
1332
Kalle Valo5e3dd152013-06-12 20:52:10 +03001333 bands = hw->wiphy->bands;
1334 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1335 if (!bands[band])
1336 continue;
1337
1338 for (i = 0; i < bands[band]->n_channels; i++) {
1339 if (bands[band]->channels[i].flags &
1340 IEEE80211_CHAN_DISABLED)
1341 continue;
1342
1343 arg.n_channels++;
1344 }
1345 }
1346
1347 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1348 arg.channels = kzalloc(len, GFP_KERNEL);
1349 if (!arg.channels)
1350 return -ENOMEM;
1351
1352 ch = arg.channels;
1353 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1354 if (!bands[band])
1355 continue;
1356
1357 for (i = 0; i < bands[band]->n_channels; i++) {
1358 channel = &bands[band]->channels[i];
1359
1360 if (channel->flags & IEEE80211_CHAN_DISABLED)
1361 continue;
1362
1363 ch->allow_ht = true;
1364
1365 /* FIXME: when should we really allow VHT? */
1366 ch->allow_vht = true;
1367
1368 ch->allow_ibss =
1369 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1370
1371 ch->ht40plus =
1372 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1373
1374 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1375 ch->passive = passive;
1376
1377 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001378 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001379 ch->max_power = channel->max_power * 2;
1380 ch->max_reg_power = channel->max_reg_power * 2;
1381 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001382 ch->reg_class_id = 0; /* FIXME */
1383
1384 /* FIXME: why use only legacy modes, why not any
1385 * HT/VHT modes? Would that even make any
1386 * difference? */
1387 if (channel->band == IEEE80211_BAND_2GHZ)
1388 ch->mode = MODE_11G;
1389 else
1390 ch->mode = MODE_11A;
1391
1392 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1393 continue;
1394
1395 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001396 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1397 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398 ch->freq, ch->max_power, ch->max_reg_power,
1399 ch->max_antenna_gain, ch->mode);
1400
1401 ch++;
1402 }
1403 }
1404
1405 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1406 kfree(arg.channels);
1407
1408 return ret;
1409}
1410
Michal Kaziorf7843d72013-07-16 09:38:52 +02001411static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001414 int ret;
1415
Michal Kaziorf7843d72013-07-16 09:38:52 +02001416 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417
1418 ret = ath10k_update_channel_list(ar);
1419 if (ret)
1420 ath10k_warn("could not update channel list (%d)\n", ret);
1421
1422 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001423
Kalle Valo5e3dd152013-06-12 20:52:10 +03001424 /* Target allows setting up per-band regdomain but ath_common provides
1425 * a combined one only */
1426 ret = ath10k_wmi_pdev_set_regdomain(ar,
1427 regpair->regDmnEnum,
1428 regpair->regDmnEnum, /* 2ghz */
1429 regpair->regDmnEnum, /* 5ghz */
1430 regpair->reg_2ghz_ctl,
1431 regpair->reg_5ghz_ctl);
1432 if (ret)
1433 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001434}
Michal Kazior548db542013-07-05 16:15:15 +03001435
Michal Kaziorf7843d72013-07-16 09:38:52 +02001436static void ath10k_reg_notifier(struct wiphy *wiphy,
1437 struct regulatory_request *request)
1438{
1439 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1440 struct ath10k *ar = hw->priv;
1441
1442 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1443
1444 mutex_lock(&ar->conf_mutex);
1445 if (ar->state == ATH10K_STATE_ON)
1446 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001447 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001448}
1449
1450/***************/
1451/* TX handlers */
1452/***************/
1453
Michal Kazior42c3aa62013-10-02 11:03:38 +02001454static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1455{
1456 if (ieee80211_is_mgmt(hdr->frame_control))
1457 return HTT_DATA_TX_EXT_TID_MGMT;
1458
1459 if (!ieee80211_is_data_qos(hdr->frame_control))
1460 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1461
1462 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1463 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1464
1465 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1466}
1467
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001468static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1469 struct ieee80211_tx_info *info)
1470{
1471 if (info->control.vif)
1472 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1473
1474 if (ar->monitor_enabled)
1475 return ar->monitor_vdev_id;
1476
1477 ath10k_warn("could not resolve vdev id\n");
1478 return 0;
1479}
1480
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481/*
1482 * Frames sent to the FW have to be in "Native Wifi" format.
1483 * Strip the QoS field from the 802.11 header.
1484 */
1485static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1486 struct ieee80211_tx_control *control,
1487 struct sk_buff *skb)
1488{
1489 struct ieee80211_hdr *hdr = (void *)skb->data;
1490 u8 *qos_ctl;
1491
1492 if (!ieee80211_is_data_qos(hdr->frame_control))
1493 return;
1494
1495 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001496 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1497 skb->data, (void *)qos_ctl - (void *)skb->data);
1498 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001499}
1500
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001501static void ath10k_tx_wep_key_work(struct work_struct *work)
1502{
1503 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1504 wep_key_work);
1505 int ret, keyidx = arvif->def_wep_key_newidx;
1506
1507 if (arvif->def_wep_key_idx == keyidx)
1508 return;
1509
1510 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1511 arvif->vdev_id, keyidx);
1512
1513 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1514 arvif->vdev_id,
1515 arvif->ar->wmi.vdev_param->def_keyid,
1516 keyidx);
1517 if (ret) {
1518 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1519 return;
1520 }
1521
1522 arvif->def_wep_key_idx = keyidx;
1523}
1524
Kalle Valo5e3dd152013-06-12 20:52:10 +03001525static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1526{
1527 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1528 struct ieee80211_vif *vif = info->control.vif;
1529 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1530 struct ath10k *ar = arvif->ar;
1531 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1532 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533
Kalle Valo5e3dd152013-06-12 20:52:10 +03001534 if (!ieee80211_has_protected(hdr->frame_control))
1535 return;
1536
1537 if (!key)
1538 return;
1539
1540 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1541 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1542 return;
1543
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001544 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001545 return;
1546
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001547 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1548 * queueing frames until key index is updated is not an option because
1549 * sk_buff may need more processing to be done, e.g. offchannel */
1550 arvif->def_wep_key_newidx = key->keyidx;
1551 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552}
1553
1554static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1555{
1556 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1557 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1558 struct ieee80211_vif *vif = info->control.vif;
1559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1560
1561 /* This is case only for P2P_GO */
1562 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1563 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1564 return;
1565
1566 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1567 spin_lock_bh(&ar->data_lock);
1568 if (arvif->u.ap.noa_data)
1569 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1570 GFP_ATOMIC))
1571 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1572 arvif->u.ap.noa_data,
1573 arvif->u.ap.noa_len);
1574 spin_unlock_bh(&ar->data_lock);
1575 }
1576}
1577
1578static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1579{
1580 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001581 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001582
Michal Kazior961d4c32013-08-09 10:13:34 +02001583 if (ar->htt.target_version_major >= 3) {
1584 /* Since HTT 3.0 there is no separate mgmt tx command */
1585 ret = ath10k_htt_tx(&ar->htt, skb);
1586 goto exit;
1587 }
1588
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001589 if (ieee80211_is_mgmt(hdr->frame_control)) {
1590 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1591 ar->fw_features)) {
1592 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1593 ATH10K_MAX_NUM_MGMT_PENDING) {
1594 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1595 ret = -EBUSY;
1596 goto exit;
1597 }
1598
1599 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1600 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1601 } else {
1602 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1603 }
1604 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1605 ar->fw_features) &&
1606 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 /* FW does not report tx status properly for NullFunc frames
1608 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001609 * those frames when it detects link/beacon loss and depends
1610 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001611 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001612 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001613 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001614 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615
Michal Kazior961d4c32013-08-09 10:13:34 +02001616exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617 if (ret) {
1618 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1619 ieee80211_free_txskb(ar->hw, skb);
1620 }
1621}
1622
1623void ath10k_offchan_tx_purge(struct ath10k *ar)
1624{
1625 struct sk_buff *skb;
1626
1627 for (;;) {
1628 skb = skb_dequeue(&ar->offchan_tx_queue);
1629 if (!skb)
1630 break;
1631
1632 ieee80211_free_txskb(ar->hw, skb);
1633 }
1634}
1635
1636void ath10k_offchan_tx_work(struct work_struct *work)
1637{
1638 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1639 struct ath10k_peer *peer;
1640 struct ieee80211_hdr *hdr;
1641 struct sk_buff *skb;
1642 const u8 *peer_addr;
1643 int vdev_id;
1644 int ret;
1645
1646 /* FW requirement: We must create a peer before FW will send out
1647 * an offchannel frame. Otherwise the frame will be stuck and
1648 * never transmitted. We delete the peer upon tx completion.
1649 * It is unlikely that a peer for offchannel tx will already be
1650 * present. However it may be in some rare cases so account for that.
1651 * Otherwise we might remove a legitimate peer and break stuff. */
1652
1653 for (;;) {
1654 skb = skb_dequeue(&ar->offchan_tx_queue);
1655 if (!skb)
1656 break;
1657
1658 mutex_lock(&ar->conf_mutex);
1659
Kalle Valo60c3daa2013-09-08 17:56:07 +03001660 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 skb);
1662
1663 hdr = (struct ieee80211_hdr *)skb->data;
1664 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001665 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666
1667 spin_lock_bh(&ar->data_lock);
1668 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1669 spin_unlock_bh(&ar->data_lock);
1670
1671 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001672 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001673 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1674 peer_addr, vdev_id);
1675
1676 if (!peer) {
1677 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1678 if (ret)
1679 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1680 peer_addr, vdev_id, ret);
1681 }
1682
1683 spin_lock_bh(&ar->data_lock);
1684 INIT_COMPLETION(ar->offchan_tx_completed);
1685 ar->offchan_tx_skb = skb;
1686 spin_unlock_bh(&ar->data_lock);
1687
1688 ath10k_tx_htt(ar, skb);
1689
1690 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1691 3 * HZ);
1692 if (ret <= 0)
1693 ath10k_warn("timed out waiting for offchannel skb %p\n",
1694 skb);
1695
1696 if (!peer) {
1697 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1698 if (ret)
1699 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1700 peer_addr, vdev_id, ret);
1701 }
1702
1703 mutex_unlock(&ar->conf_mutex);
1704 }
1705}
1706
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001707void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1708{
1709 struct sk_buff *skb;
1710
1711 for (;;) {
1712 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1713 if (!skb)
1714 break;
1715
1716 ieee80211_free_txskb(ar->hw, skb);
1717 }
1718}
1719
1720void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1721{
1722 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1723 struct sk_buff *skb;
1724 int ret;
1725
1726 for (;;) {
1727 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1728 if (!skb)
1729 break;
1730
1731 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001732 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001733 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001734 ieee80211_free_txskb(ar->hw, skb);
1735 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001736 }
1737}
1738
Kalle Valo5e3dd152013-06-12 20:52:10 +03001739/************/
1740/* Scanning */
1741/************/
1742
1743/*
1744 * This gets called if we dont get a heart-beat during scan.
1745 * This may indicate the FW has hung and we need to abort the
1746 * scan manually to prevent cancel_hw_scan() from deadlocking
1747 */
1748void ath10k_reset_scan(unsigned long ptr)
1749{
1750 struct ath10k *ar = (struct ath10k *)ptr;
1751
1752 spin_lock_bh(&ar->data_lock);
1753 if (!ar->scan.in_progress) {
1754 spin_unlock_bh(&ar->data_lock);
1755 return;
1756 }
1757
1758 ath10k_warn("scan timeout. resetting. fw issue?\n");
1759
1760 if (ar->scan.is_roc)
1761 ieee80211_remain_on_channel_expired(ar->hw);
1762 else
1763 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1764
1765 ar->scan.in_progress = false;
1766 complete_all(&ar->scan.completed);
1767 spin_unlock_bh(&ar->data_lock);
1768}
1769
1770static int ath10k_abort_scan(struct ath10k *ar)
1771{
1772 struct wmi_stop_scan_arg arg = {
1773 .req_id = 1, /* FIXME */
1774 .req_type = WMI_SCAN_STOP_ONE,
1775 .u.scan_id = ATH10K_SCAN_ID,
1776 };
1777 int ret;
1778
1779 lockdep_assert_held(&ar->conf_mutex);
1780
1781 del_timer_sync(&ar->scan.timeout);
1782
1783 spin_lock_bh(&ar->data_lock);
1784 if (!ar->scan.in_progress) {
1785 spin_unlock_bh(&ar->data_lock);
1786 return 0;
1787 }
1788
1789 ar->scan.aborting = true;
1790 spin_unlock_bh(&ar->data_lock);
1791
1792 ret = ath10k_wmi_stop_scan(ar, &arg);
1793 if (ret) {
1794 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03001795 spin_lock_bh(&ar->data_lock);
1796 ar->scan.in_progress = false;
1797 ath10k_offchan_tx_purge(ar);
1798 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001799 return -EIO;
1800 }
1801
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1803 if (ret == 0)
1804 ath10k_warn("timed out while waiting for scan to stop\n");
1805
1806 /* scan completion may be done right after we timeout here, so let's
1807 * check the in_progress and tell mac80211 scan is completed. if we
1808 * don't do that and FW fails to send us scan completion indication
1809 * then userspace won't be able to scan anymore */
1810 ret = 0;
1811
1812 spin_lock_bh(&ar->data_lock);
1813 if (ar->scan.in_progress) {
1814 ath10k_warn("could not stop scan. its still in progress\n");
1815 ar->scan.in_progress = false;
1816 ath10k_offchan_tx_purge(ar);
1817 ret = -ETIMEDOUT;
1818 }
1819 spin_unlock_bh(&ar->data_lock);
1820
1821 return ret;
1822}
1823
1824static int ath10k_start_scan(struct ath10k *ar,
1825 const struct wmi_start_scan_arg *arg)
1826{
1827 int ret;
1828
1829 lockdep_assert_held(&ar->conf_mutex);
1830
1831 ret = ath10k_wmi_start_scan(ar, arg);
1832 if (ret)
1833 return ret;
1834
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1836 if (ret == 0) {
1837 ath10k_abort_scan(ar);
1838 return ret;
1839 }
1840
1841 /* the scan can complete earlier, before we even
1842 * start the timer. in that case the timer handler
1843 * checks ar->scan.in_progress and bails out if its
1844 * false. Add a 200ms margin to account event/command
1845 * processing. */
1846 mod_timer(&ar->scan.timeout, jiffies +
1847 msecs_to_jiffies(arg->max_scan_time+200));
1848 return 0;
1849}
1850
1851/**********************/
1852/* mac80211 callbacks */
1853/**********************/
1854
1855static void ath10k_tx(struct ieee80211_hw *hw,
1856 struct ieee80211_tx_control *control,
1857 struct sk_buff *skb)
1858{
1859 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1860 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1861 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001862 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001863
1864 /* We should disable CCK RATE due to P2P */
1865 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1866 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1867
1868 /* we must calculate tid before we apply qos workaround
1869 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02001870 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001871 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001872
Michal Kaziorcf84bd42013-07-16 11:04:54 +02001873 /* it makes no sense to process injected frames like that */
1874 if (info->control.vif &&
1875 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1876 ath10k_tx_h_qos_workaround(hw, control, skb);
1877 ath10k_tx_h_update_wep_key(skb);
1878 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1879 ath10k_tx_h_seq_no(skb);
1880 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001882 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02001883 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884 ATH10K_SKB_CB(skb)->htt.tid = tid;
1885
1886 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1887 spin_lock_bh(&ar->data_lock);
1888 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001889 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001890 spin_unlock_bh(&ar->data_lock);
1891
1892 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1893
1894 skb_queue_tail(&ar->offchan_tx_queue, skb);
1895 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1896 return;
1897 }
1898
1899 ath10k_tx_htt(ar, skb);
1900}
1901
1902/*
1903 * Initialize various parameters with default vaules.
1904 */
Michal Kazioraffd3212013-07-16 09:54:35 +02001905void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02001906{
1907 lockdep_assert_held(&ar->conf_mutex);
1908
1909 del_timer_sync(&ar->scan.timeout);
1910 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001911 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02001912 ath10k_peer_cleanup_all(ar);
1913 ath10k_core_stop(ar);
1914 ath10k_hif_power_down(ar);
1915
1916 spin_lock_bh(&ar->data_lock);
1917 if (ar->scan.in_progress) {
1918 del_timer(&ar->scan.timeout);
1919 ar->scan.in_progress = false;
1920 ieee80211_scan_completed(ar->hw, true);
1921 }
1922 spin_unlock_bh(&ar->data_lock);
1923}
1924
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925static int ath10k_start(struct ieee80211_hw *hw)
1926{
1927 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02001928 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001929
Michal Kazior548db542013-07-05 16:15:15 +03001930 mutex_lock(&ar->conf_mutex);
1931
Michal Kazioraffd3212013-07-16 09:54:35 +02001932 if (ar->state != ATH10K_STATE_OFF &&
1933 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02001934 ret = -EINVAL;
1935 goto exit;
1936 }
1937
1938 ret = ath10k_hif_power_up(ar);
1939 if (ret) {
1940 ath10k_err("could not init hif (%d)\n", ret);
1941 ar->state = ATH10K_STATE_OFF;
1942 goto exit;
1943 }
1944
1945 ret = ath10k_core_start(ar);
1946 if (ret) {
1947 ath10k_err("could not init core (%d)\n", ret);
1948 ath10k_hif_power_down(ar);
1949 ar->state = ATH10K_STATE_OFF;
1950 goto exit;
1951 }
1952
Michal Kazioraffd3212013-07-16 09:54:35 +02001953 if (ar->state == ATH10K_STATE_OFF)
1954 ar->state = ATH10K_STATE_ON;
1955 else if (ar->state == ATH10K_STATE_RESTARTING)
1956 ar->state = ATH10K_STATE_RESTARTED;
1957
Bartosz Markowski226a3392013-09-26 17:47:16 +02001958 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001959 if (ret)
1960 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1961 ret);
1962
Bartosz Markowski226a3392013-09-26 17:47:16 +02001963 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964 if (ret)
1965 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1966 ret);
1967
Michal Kaziorf7843d72013-07-16 09:38:52 +02001968 ath10k_regd_update(ar);
1969
Michal Kazior818bdd12013-07-16 09:38:57 +02001970exit:
Michal Kazior548db542013-07-05 16:15:15 +03001971 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972 return 0;
1973}
1974
1975static void ath10k_stop(struct ieee80211_hw *hw)
1976{
1977 struct ath10k *ar = hw->priv;
1978
Michal Kazior548db542013-07-05 16:15:15 +03001979 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02001980 if (ar->state == ATH10K_STATE_ON ||
1981 ar->state == ATH10K_STATE_RESTARTED ||
1982 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02001983 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02001984
Michal Kaziorf7843d72013-07-16 09:38:52 +02001985 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03001986 mutex_unlock(&ar->conf_mutex);
1987
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001988 ath10k_mgmt_over_wmi_tx_purge(ar);
1989
Michal Kazior548db542013-07-05 16:15:15 +03001990 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001991 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02001992 cancel_work_sync(&ar->restart_work);
1993}
1994
Michal Kaziorad088bf2013-10-16 15:44:46 +03001995static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02001996{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001997 struct ath10k_vif *arvif;
1998 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02001999
2000 lockdep_assert_held(&ar->conf_mutex);
2001
Michal Kaziorad088bf2013-10-16 15:44:46 +03002002 list_for_each_entry(arvif, &ar->arvifs, list) {
2003 ret = ath10k_mac_vif_setup_ps(arvif);
2004 if (ret) {
2005 ath10k_warn("could not setup powersave (%d)\n", ret);
2006 break;
2007 }
2008 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002009
Michal Kaziorad088bf2013-10-16 15:44:46 +03002010 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011}
2012
2013static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2014{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 struct ath10k *ar = hw->priv;
2016 struct ieee80211_conf *conf = &hw->conf;
2017 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002018 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002019
2020 mutex_lock(&ar->conf_mutex);
2021
2022 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002023 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002024 conf->chandef.chan->center_freq);
2025 spin_lock_bh(&ar->data_lock);
2026 ar->rx_channel = conf->chandef.chan;
2027 spin_unlock_bh(&ar->data_lock);
2028 }
2029
Michal Kazior5474efe2013-10-23 04:02:15 -07002030 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2031 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2032 hw->conf.power_level);
2033
2034 param = ar->wmi.pdev_param->txpower_limit2g;
2035 ret = ath10k_wmi_pdev_set_param(ar, param,
2036 hw->conf.power_level * 2);
2037 if (ret)
2038 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2039 hw->conf.power_level, ret);
2040
2041 param = ar->wmi.pdev_param->txpower_limit5g;
2042 ret = ath10k_wmi_pdev_set_param(ar, param,
2043 hw->conf.power_level * 2);
2044 if (ret)
2045 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2046 hw->conf.power_level, ret);
2047 }
2048
Michal Kazioraffd3212013-07-16 09:54:35 +02002049 if (changed & IEEE80211_CONF_CHANGE_PS)
2050 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051
2052 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2053 if (conf->flags & IEEE80211_CONF_MONITOR)
2054 ret = ath10k_monitor_create(ar);
2055 else
2056 ret = ath10k_monitor_destroy(ar);
2057 }
2058
2059 mutex_unlock(&ar->conf_mutex);
2060 return ret;
2061}
2062
2063/*
2064 * TODO:
2065 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2066 * because we will send mgmt frames without CCK. This requirement
2067 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2068 * in the TX packet.
2069 */
2070static int ath10k_add_interface(struct ieee80211_hw *hw,
2071 struct ieee80211_vif *vif)
2072{
2073 struct ath10k *ar = hw->priv;
2074 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2075 enum wmi_sta_powersave_param param;
2076 int ret = 0;
Michal Kazior424121c2013-07-22 14:13:31 +02002077 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002078 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002079 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080
2081 mutex_lock(&ar->conf_mutex);
2082
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002083 memset(arvif, 0, sizeof(*arvif));
2084
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085 arvif->ar = ar;
2086 arvif->vif = vif;
2087
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002088 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002089 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002090
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2092 ath10k_warn("Only one monitor interface allowed\n");
2093 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002094 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 }
2096
2097 bit = ffs(ar->free_vdev_map);
2098 if (bit == 0) {
2099 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002100 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101 }
2102
2103 arvif->vdev_id = bit - 1;
2104 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002105
2106 if (ar->p2p)
2107 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2108
2109 switch (vif->type) {
2110 case NL80211_IFTYPE_UNSPECIFIED:
2111 case NL80211_IFTYPE_STATION:
2112 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2113 if (vif->p2p)
2114 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2115 break;
2116 case NL80211_IFTYPE_ADHOC:
2117 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2118 break;
2119 case NL80211_IFTYPE_AP:
2120 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2121
2122 if (vif->p2p)
2123 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2124 break;
2125 case NL80211_IFTYPE_MONITOR:
2126 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2127 break;
2128 default:
2129 WARN_ON(1);
2130 break;
2131 }
2132
Kalle Valo60c3daa2013-09-08 17:56:07 +03002133 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002134 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2135
2136 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2137 arvif->vdev_subtype, vif->addr);
2138 if (ret) {
2139 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002140 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002141 }
2142
Michal Kazior9dad14a2013-10-16 15:44:45 +03002143 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002144 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002145
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002146 vdev_param = ar->wmi.vdev_param->def_keyid;
2147 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002148 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002149 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002151 goto err_vdev_delete;
2152 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002154 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2155 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002157 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002158 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002160 goto err_vdev_delete;
2161 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162
2163 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2164 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2165 if (ret) {
2166 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002167 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002168 }
2169 }
2170
2171 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2172 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2173 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2174 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2175 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002176 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002177 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002178 goto err_peer_delete;
2179 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180
2181 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2182 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2183 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2184 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002185 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002187 goto err_peer_delete;
2188 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189
2190 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2191 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2192 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2193 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002194 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002195 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002196 goto err_peer_delete;
2197 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198 }
2199
Michal Kazior424121c2013-07-22 14:13:31 +02002200 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002201 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002202 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2203 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002204 goto err_peer_delete;
2205 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002206
Michal Kazior424121c2013-07-22 14:13:31 +02002207 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002208 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002209 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2210 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002211 goto err_peer_delete;
2212 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002213
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2215 ar->monitor_present = true;
2216
Kalle Valo5e3dd152013-06-12 20:52:10 +03002217 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002218 return 0;
2219
2220err_peer_delete:
2221 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2222 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2223
2224err_vdev_delete:
2225 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2226 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002227 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002228
2229err:
2230 mutex_unlock(&ar->conf_mutex);
2231
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232 return ret;
2233}
2234
2235static void ath10k_remove_interface(struct ieee80211_hw *hw,
2236 struct ieee80211_vif *vif)
2237{
2238 struct ath10k *ar = hw->priv;
2239 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2240 int ret;
2241
2242 mutex_lock(&ar->conf_mutex);
2243
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002244 cancel_work_sync(&arvif->wep_key_work);
2245
Michal Kaziored543882013-09-13 14:16:56 +02002246 spin_lock_bh(&ar->data_lock);
2247 if (arvif->beacon) {
2248 dev_kfree_skb_any(arvif->beacon);
2249 arvif->beacon = NULL;
2250 }
2251 spin_unlock_bh(&ar->data_lock);
2252
Kalle Valo5e3dd152013-06-12 20:52:10 +03002253 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002254 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002255
2256 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2257 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2258 if (ret)
2259 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2260
2261 kfree(arvif->u.ap.noa_data);
2262 }
2263
Kalle Valo60c3daa2013-09-08 17:56:07 +03002264 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2265 arvif->vdev_id);
2266
Kalle Valo5e3dd152013-06-12 20:52:10 +03002267 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2268 if (ret)
2269 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2270
2271 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2272 ar->monitor_present = false;
2273
2274 ath10k_peer_cleanup(ar, arvif->vdev_id);
2275
2276 mutex_unlock(&ar->conf_mutex);
2277}
2278
2279/*
2280 * FIXME: Has to be verified.
2281 */
2282#define SUPPORTED_FILTERS \
2283 (FIF_PROMISC_IN_BSS | \
2284 FIF_ALLMULTI | \
2285 FIF_CONTROL | \
2286 FIF_PSPOLL | \
2287 FIF_OTHER_BSS | \
2288 FIF_BCN_PRBRESP_PROMISC | \
2289 FIF_PROBE_REQ | \
2290 FIF_FCSFAIL)
2291
2292static void ath10k_configure_filter(struct ieee80211_hw *hw,
2293 unsigned int changed_flags,
2294 unsigned int *total_flags,
2295 u64 multicast)
2296{
2297 struct ath10k *ar = hw->priv;
2298 int ret;
2299
2300 mutex_lock(&ar->conf_mutex);
2301
2302 changed_flags &= SUPPORTED_FILTERS;
2303 *total_flags &= SUPPORTED_FILTERS;
2304 ar->filter_flags = *total_flags;
2305
Michal Kaziorafd09222013-10-16 16:45:41 +03002306 /* Monitor must not be started if it wasn't created first.
2307 * Promiscuous mode may be started on a non-monitor interface - in
2308 * such case the monitor vdev is not created so starting the
2309 * monitor makes no sense. Since ath10k uses no special RX filters
2310 * (only BSS filter in STA mode) there's no need for any special
2311 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002312 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002313 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002314 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2315 ar->monitor_vdev_id);
2316
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2318 if (ret)
2319 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002321 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002322 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2323 ar->monitor_vdev_id);
2324
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325 ret = ath10k_monitor_stop(ar);
2326 if (ret)
2327 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002328 }
2329
2330 mutex_unlock(&ar->conf_mutex);
2331}
2332
2333static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2334 struct ieee80211_vif *vif,
2335 struct ieee80211_bss_conf *info,
2336 u32 changed)
2337{
2338 struct ath10k *ar = hw->priv;
2339 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2340 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002341 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002342
2343 mutex_lock(&ar->conf_mutex);
2344
2345 if (changed & BSS_CHANGED_IBSS)
2346 ath10k_control_ibss(arvif, info, vif->addr);
2347
2348 if (changed & BSS_CHANGED_BEACON_INT) {
2349 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002350 vdev_param = ar->wmi.vdev_param->beacon_interval;
2351 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002352 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002353 ath10k_dbg(ATH10K_DBG_MAC,
2354 "mac vdev %d beacon_interval %d\n",
2355 arvif->vdev_id, arvif->beacon_interval);
2356
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 if (ret)
2358 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2359 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360 }
2361
2362 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002363 ath10k_dbg(ATH10K_DBG_MAC,
2364 "vdev %d set beacon tx mode to staggered\n",
2365 arvif->vdev_id);
2366
Bartosz Markowski226a3392013-09-26 17:47:16 +02002367 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2368 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002369 WMI_BEACON_STAGGERED_MODE);
2370 if (ret)
2371 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2372 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002373 }
2374
John W. Linvilleb70727e2013-06-13 13:34:29 -04002375 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376 arvif->dtim_period = info->dtim_period;
2377
Kalle Valo60c3daa2013-09-08 17:56:07 +03002378 ath10k_dbg(ATH10K_DBG_MAC,
2379 "mac vdev %d dtim_period %d\n",
2380 arvif->vdev_id, arvif->dtim_period);
2381
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002382 vdev_param = ar->wmi.vdev_param->dtim_period;
2383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002384 arvif->dtim_period);
2385 if (ret)
2386 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2387 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002388 }
2389
2390 if (changed & BSS_CHANGED_SSID &&
2391 vif->type == NL80211_IFTYPE_AP) {
2392 arvif->u.ap.ssid_len = info->ssid_len;
2393 if (info->ssid_len)
2394 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2395 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2396 }
2397
2398 if (changed & BSS_CHANGED_BSSID) {
2399 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002400 ath10k_dbg(ATH10K_DBG_MAC,
2401 "mac vdev %d create peer %pM\n",
2402 arvif->vdev_id, info->bssid);
2403
Kalle Valo5e3dd152013-06-12 20:52:10 +03002404 ret = ath10k_peer_create(ar, arvif->vdev_id,
2405 info->bssid);
2406 if (ret)
2407 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2408 info->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002409
2410 if (vif->type == NL80211_IFTYPE_STATION) {
2411 /*
2412 * this is never erased as we it for crypto key
2413 * clearing; this is FW requirement
2414 */
2415 memcpy(arvif->u.sta.bssid, info->bssid,
2416 ETH_ALEN);
2417
Kalle Valo60c3daa2013-09-08 17:56:07 +03002418 ath10k_dbg(ATH10K_DBG_MAC,
2419 "mac vdev %d start %pM\n",
2420 arvif->vdev_id, info->bssid);
2421
2422 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002423 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002424 }
2425
2426 /*
2427 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2428 * so driver need to store it. It is needed when leaving
2429 * IBSS in order to remove BSSID peer.
2430 */
2431 if (vif->type == NL80211_IFTYPE_ADHOC)
2432 memcpy(arvif->u.ibss.bssid, info->bssid,
2433 ETH_ALEN);
2434 }
2435 }
2436
2437 if (changed & BSS_CHANGED_BEACON_ENABLED)
2438 ath10k_control_beaconing(arvif, info);
2439
2440 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2441 u32 cts_prot;
2442 if (info->use_cts_prot)
2443 cts_prot = 1;
2444 else
2445 cts_prot = 0;
2446
Kalle Valo60c3daa2013-09-08 17:56:07 +03002447 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2448 arvif->vdev_id, cts_prot);
2449
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002450 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002452 cts_prot);
2453 if (ret)
2454 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2455 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456 }
2457
2458 if (changed & BSS_CHANGED_ERP_SLOT) {
2459 u32 slottime;
2460 if (info->use_short_slot)
2461 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2462
2463 else
2464 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2465
Kalle Valo60c3daa2013-09-08 17:56:07 +03002466 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2467 arvif->vdev_id, slottime);
2468
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002469 vdev_param = ar->wmi.vdev_param->slot_time;
2470 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002471 slottime);
2472 if (ret)
2473 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2474 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475 }
2476
2477 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2478 u32 preamble;
2479 if (info->use_short_preamble)
2480 preamble = WMI_VDEV_PREAMBLE_SHORT;
2481 else
2482 preamble = WMI_VDEV_PREAMBLE_LONG;
2483
Kalle Valo60c3daa2013-09-08 17:56:07 +03002484 ath10k_dbg(ATH10K_DBG_MAC,
2485 "mac vdev %d preamble %dn",
2486 arvif->vdev_id, preamble);
2487
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002488 vdev_param = ar->wmi.vdev_param->preamble;
2489 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490 preamble);
2491 if (ret)
2492 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2493 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002494 }
2495
2496 if (changed & BSS_CHANGED_ASSOC) {
2497 if (info->assoc)
2498 ath10k_bss_assoc(hw, vif, info);
2499 }
2500
2501 mutex_unlock(&ar->conf_mutex);
2502}
2503
2504static int ath10k_hw_scan(struct ieee80211_hw *hw,
2505 struct ieee80211_vif *vif,
2506 struct cfg80211_scan_request *req)
2507{
2508 struct ath10k *ar = hw->priv;
2509 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2510 struct wmi_start_scan_arg arg;
2511 int ret = 0;
2512 int i;
2513
2514 mutex_lock(&ar->conf_mutex);
2515
2516 spin_lock_bh(&ar->data_lock);
2517 if (ar->scan.in_progress) {
2518 spin_unlock_bh(&ar->data_lock);
2519 ret = -EBUSY;
2520 goto exit;
2521 }
2522
2523 INIT_COMPLETION(ar->scan.started);
2524 INIT_COMPLETION(ar->scan.completed);
2525 ar->scan.in_progress = true;
2526 ar->scan.aborting = false;
2527 ar->scan.is_roc = false;
2528 ar->scan.vdev_id = arvif->vdev_id;
2529 spin_unlock_bh(&ar->data_lock);
2530
2531 memset(&arg, 0, sizeof(arg));
2532 ath10k_wmi_start_scan_init(ar, &arg);
2533 arg.vdev_id = arvif->vdev_id;
2534 arg.scan_id = ATH10K_SCAN_ID;
2535
2536 if (!req->no_cck)
2537 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2538
2539 if (req->ie_len) {
2540 arg.ie_len = req->ie_len;
2541 memcpy(arg.ie, req->ie, arg.ie_len);
2542 }
2543
2544 if (req->n_ssids) {
2545 arg.n_ssids = req->n_ssids;
2546 for (i = 0; i < arg.n_ssids; i++) {
2547 arg.ssids[i].len = req->ssids[i].ssid_len;
2548 arg.ssids[i].ssid = req->ssids[i].ssid;
2549 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002550 } else {
2551 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 }
2553
2554 if (req->n_channels) {
2555 arg.n_channels = req->n_channels;
2556 for (i = 0; i < arg.n_channels; i++)
2557 arg.channels[i] = req->channels[i]->center_freq;
2558 }
2559
2560 ret = ath10k_start_scan(ar, &arg);
2561 if (ret) {
2562 ath10k_warn("could not start hw scan (%d)\n", ret);
2563 spin_lock_bh(&ar->data_lock);
2564 ar->scan.in_progress = false;
2565 spin_unlock_bh(&ar->data_lock);
2566 }
2567
2568exit:
2569 mutex_unlock(&ar->conf_mutex);
2570 return ret;
2571}
2572
2573static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2574 struct ieee80211_vif *vif)
2575{
2576 struct ath10k *ar = hw->priv;
2577 int ret;
2578
2579 mutex_lock(&ar->conf_mutex);
2580 ret = ath10k_abort_scan(ar);
2581 if (ret) {
2582 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2583 ret);
2584 ieee80211_scan_completed(hw, 1 /* aborted */);
2585 }
2586 mutex_unlock(&ar->conf_mutex);
2587}
2588
2589static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2590 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2591 struct ieee80211_key_conf *key)
2592{
2593 struct ath10k *ar = hw->priv;
2594 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2595 struct ath10k_peer *peer;
2596 const u8 *peer_addr;
2597 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2598 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2599 int ret = 0;
2600
2601 if (key->keyidx > WMI_MAX_KEY_INDEX)
2602 return -ENOSPC;
2603
2604 mutex_lock(&ar->conf_mutex);
2605
2606 if (sta)
2607 peer_addr = sta->addr;
2608 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2609 peer_addr = vif->bss_conf.bssid;
2610 else
2611 peer_addr = vif->addr;
2612
2613 key->hw_key_idx = key->keyidx;
2614
2615 /* the peer should not disappear in mid-way (unless FW goes awry) since
2616 * we already hold conf_mutex. we just make sure its there now. */
2617 spin_lock_bh(&ar->data_lock);
2618 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2619 spin_unlock_bh(&ar->data_lock);
2620
2621 if (!peer) {
2622 if (cmd == SET_KEY) {
2623 ath10k_warn("cannot install key for non-existent peer %pM\n",
2624 peer_addr);
2625 ret = -EOPNOTSUPP;
2626 goto exit;
2627 } else {
2628 /* if the peer doesn't exist there is no key to disable
2629 * anymore */
2630 goto exit;
2631 }
2632 }
2633
2634 if (is_wep) {
2635 if (cmd == SET_KEY)
2636 arvif->wep_keys[key->keyidx] = key;
2637 else
2638 arvif->wep_keys[key->keyidx] = NULL;
2639
2640 if (cmd == DISABLE_KEY)
2641 ath10k_clear_vdev_key(arvif, key);
2642 }
2643
2644 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2645 if (ret) {
2646 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2647 goto exit;
2648 }
2649
2650 spin_lock_bh(&ar->data_lock);
2651 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2652 if (peer && cmd == SET_KEY)
2653 peer->keys[key->keyidx] = key;
2654 else if (peer && cmd == DISABLE_KEY)
2655 peer->keys[key->keyidx] = NULL;
2656 else if (peer == NULL)
2657 /* impossible unless FW goes crazy */
2658 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2659 spin_unlock_bh(&ar->data_lock);
2660
2661exit:
2662 mutex_unlock(&ar->conf_mutex);
2663 return ret;
2664}
2665
2666static int ath10k_sta_state(struct ieee80211_hw *hw,
2667 struct ieee80211_vif *vif,
2668 struct ieee80211_sta *sta,
2669 enum ieee80211_sta_state old_state,
2670 enum ieee80211_sta_state new_state)
2671{
2672 struct ath10k *ar = hw->priv;
2673 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2674 int ret = 0;
2675
2676 mutex_lock(&ar->conf_mutex);
2677
2678 if (old_state == IEEE80211_STA_NOTEXIST &&
2679 new_state == IEEE80211_STA_NONE &&
2680 vif->type != NL80211_IFTYPE_STATION) {
2681 /*
2682 * New station addition.
2683 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002684 ath10k_dbg(ATH10K_DBG_MAC,
2685 "mac vdev %d peer create %pM (new sta)\n",
2686 arvif->vdev_id, sta->addr);
2687
Kalle Valo5e3dd152013-06-12 20:52:10 +03002688 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2689 if (ret)
2690 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2691 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692 } else if ((old_state == IEEE80211_STA_NONE &&
2693 new_state == IEEE80211_STA_NOTEXIST)) {
2694 /*
2695 * Existing station deletion.
2696 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002697 ath10k_dbg(ATH10K_DBG_MAC,
2698 "mac vdev %d peer delete %pM (sta gone)\n",
2699 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2701 if (ret)
2702 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2703 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704
2705 if (vif->type == NL80211_IFTYPE_STATION)
2706 ath10k_bss_disassoc(hw, vif);
2707 } else if (old_state == IEEE80211_STA_AUTH &&
2708 new_state == IEEE80211_STA_ASSOC &&
2709 (vif->type == NL80211_IFTYPE_AP ||
2710 vif->type == NL80211_IFTYPE_ADHOC)) {
2711 /*
2712 * New association.
2713 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002714 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2715 sta->addr);
2716
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717 ret = ath10k_station_assoc(ar, arvif, sta);
2718 if (ret)
2719 ath10k_warn("Failed to associate station: %pM\n",
2720 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002721 } else if (old_state == IEEE80211_STA_ASSOC &&
2722 new_state == IEEE80211_STA_AUTH &&
2723 (vif->type == NL80211_IFTYPE_AP ||
2724 vif->type == NL80211_IFTYPE_ADHOC)) {
2725 /*
2726 * Disassociation.
2727 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002728 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2729 sta->addr);
2730
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731 ret = ath10k_station_disassoc(ar, arvif, sta);
2732 if (ret)
2733 ath10k_warn("Failed to disassociate station: %pM\n",
2734 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002735 }
2736
2737 mutex_unlock(&ar->conf_mutex);
2738 return ret;
2739}
2740
2741static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2742 u16 ac, bool enable)
2743{
2744 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2745 u32 value = 0;
2746 int ret = 0;
2747
Michal Kazior548db542013-07-05 16:15:15 +03002748 lockdep_assert_held(&ar->conf_mutex);
2749
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2751 return 0;
2752
2753 switch (ac) {
2754 case IEEE80211_AC_VO:
2755 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2756 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2757 break;
2758 case IEEE80211_AC_VI:
2759 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2760 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2761 break;
2762 case IEEE80211_AC_BE:
2763 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2764 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2765 break;
2766 case IEEE80211_AC_BK:
2767 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2768 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2769 break;
2770 }
2771
2772 if (enable)
2773 arvif->u.sta.uapsd |= value;
2774 else
2775 arvif->u.sta.uapsd &= ~value;
2776
2777 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2778 WMI_STA_PS_PARAM_UAPSD,
2779 arvif->u.sta.uapsd);
2780 if (ret) {
2781 ath10k_warn("could not set uapsd params %d\n", ret);
2782 goto exit;
2783 }
2784
2785 if (arvif->u.sta.uapsd)
2786 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2787 else
2788 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2789
2790 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2791 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2792 value);
2793 if (ret)
2794 ath10k_warn("could not set rx wake param %d\n", ret);
2795
2796exit:
2797 return ret;
2798}
2799
2800static int ath10k_conf_tx(struct ieee80211_hw *hw,
2801 struct ieee80211_vif *vif, u16 ac,
2802 const struct ieee80211_tx_queue_params *params)
2803{
2804 struct ath10k *ar = hw->priv;
2805 struct wmi_wmm_params_arg *p = NULL;
2806 int ret;
2807
2808 mutex_lock(&ar->conf_mutex);
2809
2810 switch (ac) {
2811 case IEEE80211_AC_VO:
2812 p = &ar->wmm_params.ac_vo;
2813 break;
2814 case IEEE80211_AC_VI:
2815 p = &ar->wmm_params.ac_vi;
2816 break;
2817 case IEEE80211_AC_BE:
2818 p = &ar->wmm_params.ac_be;
2819 break;
2820 case IEEE80211_AC_BK:
2821 p = &ar->wmm_params.ac_bk;
2822 break;
2823 }
2824
2825 if (WARN_ON(!p)) {
2826 ret = -EINVAL;
2827 goto exit;
2828 }
2829
2830 p->cwmin = params->cw_min;
2831 p->cwmax = params->cw_max;
2832 p->aifs = params->aifs;
2833
2834 /*
2835 * The channel time duration programmed in the HW is in absolute
2836 * microseconds, while mac80211 gives the txop in units of
2837 * 32 microseconds.
2838 */
2839 p->txop = params->txop * 32;
2840
2841 /* FIXME: FW accepts wmm params per hw, not per vif */
2842 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2843 if (ret) {
2844 ath10k_warn("could not set wmm params %d\n", ret);
2845 goto exit;
2846 }
2847
2848 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2849 if (ret)
2850 ath10k_warn("could not set sta uapsd %d\n", ret);
2851
2852exit:
2853 mutex_unlock(&ar->conf_mutex);
2854 return ret;
2855}
2856
2857#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2858
2859static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2860 struct ieee80211_vif *vif,
2861 struct ieee80211_channel *chan,
2862 int duration,
2863 enum ieee80211_roc_type type)
2864{
2865 struct ath10k *ar = hw->priv;
2866 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2867 struct wmi_start_scan_arg arg;
2868 int ret;
2869
2870 mutex_lock(&ar->conf_mutex);
2871
2872 spin_lock_bh(&ar->data_lock);
2873 if (ar->scan.in_progress) {
2874 spin_unlock_bh(&ar->data_lock);
2875 ret = -EBUSY;
2876 goto exit;
2877 }
2878
2879 INIT_COMPLETION(ar->scan.started);
2880 INIT_COMPLETION(ar->scan.completed);
2881 INIT_COMPLETION(ar->scan.on_channel);
2882 ar->scan.in_progress = true;
2883 ar->scan.aborting = false;
2884 ar->scan.is_roc = true;
2885 ar->scan.vdev_id = arvif->vdev_id;
2886 ar->scan.roc_freq = chan->center_freq;
2887 spin_unlock_bh(&ar->data_lock);
2888
2889 memset(&arg, 0, sizeof(arg));
2890 ath10k_wmi_start_scan_init(ar, &arg);
2891 arg.vdev_id = arvif->vdev_id;
2892 arg.scan_id = ATH10K_SCAN_ID;
2893 arg.n_channels = 1;
2894 arg.channels[0] = chan->center_freq;
2895 arg.dwell_time_active = duration;
2896 arg.dwell_time_passive = duration;
2897 arg.max_scan_time = 2 * duration;
2898 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2899 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2900
2901 ret = ath10k_start_scan(ar, &arg);
2902 if (ret) {
2903 ath10k_warn("could not start roc scan (%d)\n", ret);
2904 spin_lock_bh(&ar->data_lock);
2905 ar->scan.in_progress = false;
2906 spin_unlock_bh(&ar->data_lock);
2907 goto exit;
2908 }
2909
2910 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2911 if (ret == 0) {
2912 ath10k_warn("could not switch to channel for roc scan\n");
2913 ath10k_abort_scan(ar);
2914 ret = -ETIMEDOUT;
2915 goto exit;
2916 }
2917
2918 ret = 0;
2919exit:
2920 mutex_unlock(&ar->conf_mutex);
2921 return ret;
2922}
2923
2924static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2925{
2926 struct ath10k *ar = hw->priv;
2927
2928 mutex_lock(&ar->conf_mutex);
2929 ath10k_abort_scan(ar);
2930 mutex_unlock(&ar->conf_mutex);
2931
2932 return 0;
2933}
2934
2935/*
2936 * Both RTS and Fragmentation threshold are interface-specific
2937 * in ath10k, but device-specific in mac80211.
2938 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002939
2940static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2941{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03002943 struct ath10k_vif *arvif;
2944 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03002945
Michal Kaziorad088bf2013-10-16 15:44:46 +03002946 mutex_lock(&ar->conf_mutex);
2947 list_for_each_entry(arvif, &ar->arvifs, list) {
2948 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
2949 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002950
Michal Kaziorad088bf2013-10-16 15:44:46 +03002951 ret = ath10k_mac_set_rts(arvif, value);
2952 if (ret) {
2953 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
2954 arvif->vdev_id, ret);
2955 break;
2956 }
2957 }
2958 mutex_unlock(&ar->conf_mutex);
2959
2960 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002961}
2962
2963static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2964{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002965 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03002966 struct ath10k_vif *arvif;
2967 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968
Kalle Valo5e3dd152013-06-12 20:52:10 +03002969 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002970 list_for_each_entry(arvif, &ar->arvifs, list) {
2971 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
2972 arvif->vdev_id, value);
2973
2974 ret = ath10k_mac_set_rts(arvif, value);
2975 if (ret) {
2976 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
2977 arvif->vdev_id, ret);
2978 break;
2979 }
2980 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002981 mutex_unlock(&ar->conf_mutex);
2982
Michal Kaziorad088bf2013-10-16 15:44:46 +03002983 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002984}
2985
2986static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2987{
2988 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02002989 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002990 int ret;
2991
2992 /* mac80211 doesn't care if we really xmit queued frames or not
2993 * we'll collect those frames either way if we stop/delete vdevs */
2994 if (drop)
2995 return;
2996
Michal Kazior548db542013-07-05 16:15:15 +03002997 mutex_lock(&ar->conf_mutex);
2998
Michal Kazioraffd3212013-07-16 09:54:35 +02002999 if (ar->state == ATH10K_STATE_WEDGED)
3000 goto skip;
3001
Michal Kazioredb82362013-07-05 16:15:14 +03003002 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003003 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003004
Michal Kazioredb82362013-07-05 16:15:14 +03003005 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003006 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003007 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003008
3009 skip = (ar->state == ATH10K_STATE_WEDGED);
3010
3011 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003012 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003013
3014 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003015 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003016
Michal Kazioraffd3212013-07-16 09:54:35 +02003017skip:
Michal Kazior548db542013-07-05 16:15:15 +03003018 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003019}
3020
3021/* TODO: Implement this function properly
3022 * For now it is needed to reply to Probe Requests in IBSS mode.
3023 * Propably we need this information from FW.
3024 */
3025static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3026{
3027 return 1;
3028}
3029
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003030#ifdef CONFIG_PM
3031static int ath10k_suspend(struct ieee80211_hw *hw,
3032 struct cfg80211_wowlan *wowlan)
3033{
3034 struct ath10k *ar = hw->priv;
3035 int ret;
3036
3037 ar->is_target_paused = false;
3038
3039 ret = ath10k_wmi_pdev_suspend_target(ar);
3040 if (ret) {
3041 ath10k_warn("could not suspend target (%d)\n", ret);
3042 return 1;
3043 }
3044
3045 ret = wait_event_interruptible_timeout(ar->event_queue,
3046 ar->is_target_paused == true,
3047 1 * HZ);
3048 if (ret < 0) {
3049 ath10k_warn("suspend interrupted (%d)\n", ret);
3050 goto resume;
3051 } else if (ret == 0) {
3052 ath10k_warn("suspend timed out - target pause event never came\n");
3053 goto resume;
3054 }
3055
3056 ret = ath10k_hif_suspend(ar);
3057 if (ret) {
3058 ath10k_warn("could not suspend hif (%d)\n", ret);
3059 goto resume;
3060 }
3061
3062 return 0;
3063resume:
3064 ret = ath10k_wmi_pdev_resume_target(ar);
3065 if (ret)
3066 ath10k_warn("could not resume target (%d)\n", ret);
3067 return 1;
3068}
3069
3070static int ath10k_resume(struct ieee80211_hw *hw)
3071{
3072 struct ath10k *ar = hw->priv;
3073 int ret;
3074
3075 ret = ath10k_hif_resume(ar);
3076 if (ret) {
3077 ath10k_warn("could not resume hif (%d)\n", ret);
3078 return 1;
3079 }
3080
3081 ret = ath10k_wmi_pdev_resume_target(ar);
3082 if (ret) {
3083 ath10k_warn("could not resume target (%d)\n", ret);
3084 return 1;
3085 }
3086
3087 return 0;
3088}
3089#endif
3090
Michal Kazioraffd3212013-07-16 09:54:35 +02003091static void ath10k_restart_complete(struct ieee80211_hw *hw)
3092{
3093 struct ath10k *ar = hw->priv;
3094
3095 mutex_lock(&ar->conf_mutex);
3096
3097 /* If device failed to restart it will be in a different state, e.g.
3098 * ATH10K_STATE_WEDGED */
3099 if (ar->state == ATH10K_STATE_RESTARTED) {
3100 ath10k_info("device successfully recovered\n");
3101 ar->state = ATH10K_STATE_ON;
3102 }
3103
3104 mutex_unlock(&ar->conf_mutex);
3105}
3106
Michal Kazior2e1dea42013-07-31 10:32:40 +02003107static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3108 struct survey_info *survey)
3109{
3110 struct ath10k *ar = hw->priv;
3111 struct ieee80211_supported_band *sband;
3112 struct survey_info *ar_survey = &ar->survey[idx];
3113 int ret = 0;
3114
3115 mutex_lock(&ar->conf_mutex);
3116
3117 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3118 if (sband && idx >= sband->n_channels) {
3119 idx -= sband->n_channels;
3120 sband = NULL;
3121 }
3122
3123 if (!sband)
3124 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3125
3126 if (!sband || idx >= sband->n_channels) {
3127 ret = -ENOENT;
3128 goto exit;
3129 }
3130
3131 spin_lock_bh(&ar->data_lock);
3132 memcpy(survey, ar_survey, sizeof(*survey));
3133 spin_unlock_bh(&ar->data_lock);
3134
3135 survey->channel = &sband->channels[idx];
3136
3137exit:
3138 mutex_unlock(&ar->conf_mutex);
3139 return ret;
3140}
3141
Kalle Valo5e3dd152013-06-12 20:52:10 +03003142static const struct ieee80211_ops ath10k_ops = {
3143 .tx = ath10k_tx,
3144 .start = ath10k_start,
3145 .stop = ath10k_stop,
3146 .config = ath10k_config,
3147 .add_interface = ath10k_add_interface,
3148 .remove_interface = ath10k_remove_interface,
3149 .configure_filter = ath10k_configure_filter,
3150 .bss_info_changed = ath10k_bss_info_changed,
3151 .hw_scan = ath10k_hw_scan,
3152 .cancel_hw_scan = ath10k_cancel_hw_scan,
3153 .set_key = ath10k_set_key,
3154 .sta_state = ath10k_sta_state,
3155 .conf_tx = ath10k_conf_tx,
3156 .remain_on_channel = ath10k_remain_on_channel,
3157 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3158 .set_rts_threshold = ath10k_set_rts_threshold,
3159 .set_frag_threshold = ath10k_set_frag_threshold,
3160 .flush = ath10k_flush,
3161 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003162 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003163 .get_survey = ath10k_get_survey,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003164#ifdef CONFIG_PM
3165 .suspend = ath10k_suspend,
3166 .resume = ath10k_resume,
3167#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168};
3169
3170#define RATETAB_ENT(_rate, _rateid, _flags) { \
3171 .bitrate = (_rate), \
3172 .flags = (_flags), \
3173 .hw_value = (_rateid), \
3174}
3175
3176#define CHAN2G(_channel, _freq, _flags) { \
3177 .band = IEEE80211_BAND_2GHZ, \
3178 .hw_value = (_channel), \
3179 .center_freq = (_freq), \
3180 .flags = (_flags), \
3181 .max_antenna_gain = 0, \
3182 .max_power = 30, \
3183}
3184
3185#define CHAN5G(_channel, _freq, _flags) { \
3186 .band = IEEE80211_BAND_5GHZ, \
3187 .hw_value = (_channel), \
3188 .center_freq = (_freq), \
3189 .flags = (_flags), \
3190 .max_antenna_gain = 0, \
3191 .max_power = 30, \
3192}
3193
3194static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3195 CHAN2G(1, 2412, 0),
3196 CHAN2G(2, 2417, 0),
3197 CHAN2G(3, 2422, 0),
3198 CHAN2G(4, 2427, 0),
3199 CHAN2G(5, 2432, 0),
3200 CHAN2G(6, 2437, 0),
3201 CHAN2G(7, 2442, 0),
3202 CHAN2G(8, 2447, 0),
3203 CHAN2G(9, 2452, 0),
3204 CHAN2G(10, 2457, 0),
3205 CHAN2G(11, 2462, 0),
3206 CHAN2G(12, 2467, 0),
3207 CHAN2G(13, 2472, 0),
3208 CHAN2G(14, 2484, 0),
3209};
3210
3211static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003212 CHAN5G(36, 5180, 0),
3213 CHAN5G(40, 5200, 0),
3214 CHAN5G(44, 5220, 0),
3215 CHAN5G(48, 5240, 0),
3216 CHAN5G(52, 5260, 0),
3217 CHAN5G(56, 5280, 0),
3218 CHAN5G(60, 5300, 0),
3219 CHAN5G(64, 5320, 0),
3220 CHAN5G(100, 5500, 0),
3221 CHAN5G(104, 5520, 0),
3222 CHAN5G(108, 5540, 0),
3223 CHAN5G(112, 5560, 0),
3224 CHAN5G(116, 5580, 0),
3225 CHAN5G(120, 5600, 0),
3226 CHAN5G(124, 5620, 0),
3227 CHAN5G(128, 5640, 0),
3228 CHAN5G(132, 5660, 0),
3229 CHAN5G(136, 5680, 0),
3230 CHAN5G(140, 5700, 0),
3231 CHAN5G(149, 5745, 0),
3232 CHAN5G(153, 5765, 0),
3233 CHAN5G(157, 5785, 0),
3234 CHAN5G(161, 5805, 0),
3235 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236};
3237
3238static struct ieee80211_rate ath10k_rates[] = {
3239 /* CCK */
3240 RATETAB_ENT(10, 0x82, 0),
3241 RATETAB_ENT(20, 0x84, 0),
3242 RATETAB_ENT(55, 0x8b, 0),
3243 RATETAB_ENT(110, 0x96, 0),
3244 /* OFDM */
3245 RATETAB_ENT(60, 0x0c, 0),
3246 RATETAB_ENT(90, 0x12, 0),
3247 RATETAB_ENT(120, 0x18, 0),
3248 RATETAB_ENT(180, 0x24, 0),
3249 RATETAB_ENT(240, 0x30, 0),
3250 RATETAB_ENT(360, 0x48, 0),
3251 RATETAB_ENT(480, 0x60, 0),
3252 RATETAB_ENT(540, 0x6c, 0),
3253};
3254
3255#define ath10k_a_rates (ath10k_rates + 4)
3256#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3257#define ath10k_g_rates (ath10k_rates + 0)
3258#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3259
3260struct ath10k *ath10k_mac_create(void)
3261{
3262 struct ieee80211_hw *hw;
3263 struct ath10k *ar;
3264
3265 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3266 if (!hw)
3267 return NULL;
3268
3269 ar = hw->priv;
3270 ar->hw = hw;
3271
3272 return ar;
3273}
3274
3275void ath10k_mac_destroy(struct ath10k *ar)
3276{
3277 ieee80211_free_hw(ar->hw);
3278}
3279
3280static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3281 {
3282 .max = 8,
3283 .types = BIT(NL80211_IFTYPE_STATION)
3284 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003285 },
3286 {
3287 .max = 3,
3288 .types = BIT(NL80211_IFTYPE_P2P_GO)
3289 },
3290 {
3291 .max = 7,
3292 .types = BIT(NL80211_IFTYPE_AP)
3293 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294};
3295
3296static const struct ieee80211_iface_combination ath10k_if_comb = {
3297 .limits = ath10k_if_limits,
3298 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3299 .max_interfaces = 8,
3300 .num_different_channels = 1,
3301 .beacon_int_infra_match = true,
3302};
3303
3304static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3305{
3306 struct ieee80211_sta_vht_cap vht_cap = {0};
3307 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003308 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309
3310 vht_cap.vht_supported = 1;
3311 vht_cap.cap = ar->vht_cap_info;
3312
Michal Kazior8865bee42013-07-24 12:36:46 +02003313 mcs_map = 0;
3314 for (i = 0; i < 8; i++) {
3315 if (i < ar->num_rf_chains)
3316 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3317 else
3318 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3319 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320
3321 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3322 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3323
3324 return vht_cap;
3325}
3326
3327static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3328{
3329 int i;
3330 struct ieee80211_sta_ht_cap ht_cap = {0};
3331
3332 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3333 return ht_cap;
3334
3335 ht_cap.ht_supported = 1;
3336 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3337 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3338 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3339 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3340 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3341
3342 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3343 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3344
3345 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3346 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3347
3348 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3349 u32 smps;
3350
3351 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3352 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3353
3354 ht_cap.cap |= smps;
3355 }
3356
3357 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3358 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3359
3360 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3361 u32 stbc;
3362
3363 stbc = ar->ht_cap_info;
3364 stbc &= WMI_HT_CAP_RX_STBC;
3365 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3366 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3367 stbc &= IEEE80211_HT_CAP_RX_STBC;
3368
3369 ht_cap.cap |= stbc;
3370 }
3371
3372 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3373 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3374
3375 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3376 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3377
3378 /* max AMSDU is implicitly taken from vht_cap_info */
3379 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3380 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3381
Michal Kazior8865bee42013-07-24 12:36:46 +02003382 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003383 ht_cap.mcs.rx_mask[i] = 0xFF;
3384
3385 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3386
3387 return ht_cap;
3388}
3389
3390
3391static void ath10k_get_arvif_iter(void *data, u8 *mac,
3392 struct ieee80211_vif *vif)
3393{
3394 struct ath10k_vif_iter *arvif_iter = data;
3395 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3396
3397 if (arvif->vdev_id == arvif_iter->vdev_id)
3398 arvif_iter->arvif = arvif;
3399}
3400
3401struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3402{
3403 struct ath10k_vif_iter arvif_iter;
3404 u32 flags;
3405
3406 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3407 arvif_iter.vdev_id = vdev_id;
3408
3409 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3410 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3411 flags,
3412 ath10k_get_arvif_iter,
3413 &arvif_iter);
3414 if (!arvif_iter.arvif) {
3415 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3416 return NULL;
3417 }
3418
3419 return arvif_iter.arvif;
3420}
3421
3422int ath10k_mac_register(struct ath10k *ar)
3423{
3424 struct ieee80211_supported_band *band;
3425 struct ieee80211_sta_vht_cap vht_cap;
3426 struct ieee80211_sta_ht_cap ht_cap;
3427 void *channels;
3428 int ret;
3429
3430 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3431
3432 SET_IEEE80211_DEV(ar->hw, ar->dev);
3433
3434 ht_cap = ath10k_get_ht_cap(ar);
3435 vht_cap = ath10k_create_vht_cap(ar);
3436
3437 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3438 channels = kmemdup(ath10k_2ghz_channels,
3439 sizeof(ath10k_2ghz_channels),
3440 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02003441 if (!channels) {
3442 ret = -ENOMEM;
3443 goto err_free;
3444 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003445
3446 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3447 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3448 band->channels = channels;
3449 band->n_bitrates = ath10k_g_rates_size;
3450 band->bitrates = ath10k_g_rates;
3451 band->ht_cap = ht_cap;
3452
3453 /* vht is not supported in 2.4 GHz */
3454
3455 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3456 }
3457
3458 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3459 channels = kmemdup(ath10k_5ghz_channels,
3460 sizeof(ath10k_5ghz_channels),
3461 GFP_KERNEL);
3462 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02003463 ret = -ENOMEM;
3464 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003465 }
3466
3467 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3468 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3469 band->channels = channels;
3470 band->n_bitrates = ath10k_a_rates_size;
3471 band->bitrates = ath10k_a_rates;
3472 band->ht_cap = ht_cap;
3473 band->vht_cap = vht_cap;
3474 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3475 }
3476
3477 ar->hw->wiphy->interface_modes =
3478 BIT(NL80211_IFTYPE_STATION) |
3479 BIT(NL80211_IFTYPE_ADHOC) |
3480 BIT(NL80211_IFTYPE_AP) |
3481 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3482 BIT(NL80211_IFTYPE_P2P_GO);
3483
3484 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3485 IEEE80211_HW_SUPPORTS_PS |
3486 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3487 IEEE80211_HW_SUPPORTS_UAPSD |
3488 IEEE80211_HW_MFP_CAPABLE |
3489 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3490 IEEE80211_HW_HAS_RATE_CONTROL |
3491 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3492 IEEE80211_HW_WANT_MONITOR_VIF |
3493 IEEE80211_HW_AP_LINK_PS;
3494
Michal Kazior1f8bb152013-09-18 14:43:22 +02003495 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3496 * bytes is used for padding/alignment if necessary. */
3497 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3498
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3500 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3501
3502 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3503 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3504 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3505 }
3506
3507 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3508 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3509
3510 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3511
3512 ar->hw->channel_change_time = 5000;
3513 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3514
3515 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3516 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3517
3518 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3519 /*
3520 * on LL hardware queues are managed entirely by the FW
3521 * so we only advertise to mac we can do the queues thing
3522 */
3523 ar->hw->queues = 4;
3524
3525 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3526 ar->hw->wiphy->n_iface_combinations = 1;
3527
Michal Kazior7c199992013-07-31 10:47:57 +02003528 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3529
Kalle Valo5e3dd152013-06-12 20:52:10 +03003530 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3531 ath10k_reg_notifier);
3532 if (ret) {
3533 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02003534 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003535 }
3536
3537 ret = ieee80211_register_hw(ar->hw);
3538 if (ret) {
3539 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02003540 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 }
3542
3543 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3544 ret = regulatory_hint(ar->hw->wiphy,
3545 ar->ath_common.regulatory.alpha2);
3546 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02003547 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003548 }
3549
3550 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02003551
3552err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003553 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02003554err_free:
3555 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3556 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3557
Kalle Valo5e3dd152013-06-12 20:52:10 +03003558 return ret;
3559}
3560
3561void ath10k_mac_unregister(struct ath10k *ar)
3562{
3563 ieee80211_unregister_hw(ar->hw);
3564
3565 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3566 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3567
3568 SET_IEEE80211_DEV(ar->hw, NULL);
3569}