blob: 16e55bd22fc2f8359efe3b1ce49edc0d05ee51ef [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
453 arg.channel.min_power = channel->max_power * 3;
454 arg.channel.max_power = channel->max_power * 4;
455 arg.channel.max_reg_power = channel->max_reg_power * 4;
456 arg.channel.max_antenna_gain = channel->max_antenna_gain;
457
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
Kalle Valo5e3dd152013-06-12 20:52:10 +0300519 arg.vdev_id = vdev_id;
520 arg.channel.freq = channel->center_freq;
521 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
522
523 /* TODO setup this dynamically, what in case we
524 don't have any vifs? */
525 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
526
527 arg.channel.min_power = channel->max_power * 3;
528 arg.channel.max_power = channel->max_power * 4;
529 arg.channel.max_reg_power = channel->max_reg_power * 4;
530 arg.channel.max_antenna_gain = channel->max_antenna_gain;
531
532 ret = ath10k_wmi_vdev_start(ar, &arg);
533 if (ret) {
534 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
535 return ret;
536 }
537
538 ret = ath10k_vdev_setup_sync(ar);
539 if (ret) {
540 ath10k_warn("Monitor vdev setup failed %d\n", ret);
541 return ret;
542 }
543
544 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
545 if (ret) {
546 ath10k_warn("Monitor vdev up failed: %d\n", ret);
547 goto vdev_stop;
548 }
549
550 ar->monitor_vdev_id = vdev_id;
551 ar->monitor_enabled = true;
552
553 return 0;
554
555vdev_stop:
556 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
557 if (ret)
558 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
559
560 return ret;
561}
562
563static int ath10k_monitor_stop(struct ath10k *ar)
564{
565 int ret = 0;
566
567 lockdep_assert_held(&ar->conf_mutex);
568
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200569 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
570 if (ret)
571 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300572
573 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
574 if (ret)
575 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
576
577 ret = ath10k_vdev_setup_sync(ar);
578 if (ret)
579 ath10k_warn("Monitor_down sync failed: %d\n", ret);
580
581 ar->monitor_enabled = false;
582 return ret;
583}
584
585static int ath10k_monitor_create(struct ath10k *ar)
586{
587 int bit, ret = 0;
588
589 lockdep_assert_held(&ar->conf_mutex);
590
591 if (ar->monitor_present) {
592 ath10k_warn("Monitor mode already enabled\n");
593 return 0;
594 }
595
596 bit = ffs(ar->free_vdev_map);
597 if (bit == 0) {
598 ath10k_warn("No free VDEV slots\n");
599 return -ENOMEM;
600 }
601
602 ar->monitor_vdev_id = bit - 1;
603 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
604
605 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
606 WMI_VDEV_TYPE_MONITOR,
607 0, ar->mac_addr);
608 if (ret) {
609 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
610 goto vdev_fail;
611 }
612
Kalle Valo60c3daa2013-09-08 17:56:07 +0300613 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300614 ar->monitor_vdev_id);
615
616 ar->monitor_present = true;
617 return 0;
618
619vdev_fail:
620 /*
621 * Restore the ID to the global map.
622 */
623 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
624 return ret;
625}
626
627static int ath10k_monitor_destroy(struct ath10k *ar)
628{
629 int ret = 0;
630
631 lockdep_assert_held(&ar->conf_mutex);
632
633 if (!ar->monitor_present)
634 return 0;
635
636 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
637 if (ret) {
638 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
639 return ret;
640 }
641
642 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
643 ar->monitor_present = false;
644
Kalle Valo60c3daa2013-09-08 17:56:07 +0300645 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300646 ar->monitor_vdev_id);
647 return ret;
648}
649
650static void ath10k_control_beaconing(struct ath10k_vif *arvif,
651 struct ieee80211_bss_conf *info)
652{
653 int ret = 0;
654
Michal Kazior548db542013-07-05 16:15:15 +0300655 lockdep_assert_held(&arvif->ar->conf_mutex);
656
Kalle Valo5e3dd152013-06-12 20:52:10 +0300657 if (!info->enable_beacon) {
658 ath10k_vdev_stop(arvif);
659 return;
660 }
661
662 arvif->tx_seq_no = 0x1000;
663
664 ret = ath10k_vdev_start(arvif);
665 if (ret)
666 return;
667
668 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
669 if (ret) {
670 ath10k_warn("Failed to bring up VDEV: %d\n",
671 arvif->vdev_id);
672 return;
673 }
Kalle Valo60c3daa2013-09-08 17:56:07 +0300674 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300675}
676
677static void ath10k_control_ibss(struct ath10k_vif *arvif,
678 struct ieee80211_bss_conf *info,
679 const u8 self_peer[ETH_ALEN])
680{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200681 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682 int ret = 0;
683
Michal Kazior548db542013-07-05 16:15:15 +0300684 lockdep_assert_held(&arvif->ar->conf_mutex);
685
Kalle Valo5e3dd152013-06-12 20:52:10 +0300686 if (!info->ibss_joined) {
687 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
688 if (ret)
689 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
690 self_peer, arvif->vdev_id, ret);
691
692 if (is_zero_ether_addr(arvif->u.ibss.bssid))
693 return;
694
695 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
696 arvif->u.ibss.bssid);
697 if (ret) {
698 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
699 arvif->u.ibss.bssid, arvif->vdev_id, ret);
700 return;
701 }
702
703 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
704
705 return;
706 }
707
708 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
709 if (ret) {
710 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
711 self_peer, arvif->vdev_id, ret);
712 return;
713 }
714
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200715 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
716 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300717 ATH10K_DEFAULT_ATIM);
718 if (ret)
719 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
720 arvif->vdev_id, ret);
721}
722
723/*
724 * Review this when mac80211 gains per-interface powersave support.
725 */
726static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
727{
728 struct ath10k_generic_iter *ar_iter = data;
729 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
730 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
731 enum wmi_sta_powersave_param param;
732 enum wmi_sta_ps_mode psmode;
733 int ret;
734
Michal Kazior548db542013-07-05 16:15:15 +0300735 lockdep_assert_held(&arvif->ar->conf_mutex);
736
Kalle Valo5e3dd152013-06-12 20:52:10 +0300737 if (vif->type != NL80211_IFTYPE_STATION)
738 return;
739
740 if (conf->flags & IEEE80211_CONF_PS) {
741 psmode = WMI_STA_PS_MODE_ENABLED;
742 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
743
744 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
745 arvif->vdev_id,
746 param,
747 conf->dynamic_ps_timeout);
748 if (ret) {
749 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
750 arvif->vdev_id);
751 return;
752 }
753
754 ar_iter->ret = ret;
755 } else {
756 psmode = WMI_STA_PS_MODE_DISABLED;
757 }
758
Kalle Valo60c3daa2013-09-08 17:56:07 +0300759 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
760 arvif->vdev_id, psmode ? "enable" : "disable");
761
Kalle Valo5e3dd152013-06-12 20:52:10 +0300762 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
763 psmode);
764 if (ar_iter->ret)
765 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
766 psmode, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300767}
768
769/**********************/
770/* Station management */
771/**********************/
772
773static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
774 struct ath10k_vif *arvif,
775 struct ieee80211_sta *sta,
776 struct ieee80211_bss_conf *bss_conf,
777 struct wmi_peer_assoc_complete_arg *arg)
778{
Michal Kazior548db542013-07-05 16:15:15 +0300779 lockdep_assert_held(&ar->conf_mutex);
780
Kalle Valo5e3dd152013-06-12 20:52:10 +0300781 memcpy(arg->addr, sta->addr, ETH_ALEN);
782 arg->vdev_id = arvif->vdev_id;
783 arg->peer_aid = sta->aid;
784 arg->peer_flags |= WMI_PEER_AUTH;
785
786 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
787 /*
788 * Seems FW have problems with Power Save in STA
789 * mode when we setup this parameter to high (eg. 5).
790 * Often we see that FW don't send NULL (with clean P flags)
791 * frame even there is info about buffered frames in beacons.
792 * Sometimes we have to wait more than 10 seconds before FW
793 * will wakeup. Often sending one ping from AP to our device
794 * just fail (more than 50%).
795 *
796 * Seems setting this FW parameter to 1 couse FW
797 * will check every beacon and will wakup immediately
798 * after detection buffered data.
799 */
800 arg->peer_listen_intval = 1;
801 else
802 arg->peer_listen_intval = ar->hw->conf.listen_interval;
803
804 arg->peer_num_spatial_streams = 1;
805
806 /*
807 * The assoc capabilities are available only in managed mode.
808 */
809 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
810 arg->peer_caps = bss_conf->assoc_capability;
811}
812
813static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
814 struct ath10k_vif *arvif,
815 struct wmi_peer_assoc_complete_arg *arg)
816{
817 struct ieee80211_vif *vif = arvif->vif;
818 struct ieee80211_bss_conf *info = &vif->bss_conf;
819 struct cfg80211_bss *bss;
820 const u8 *rsnie = NULL;
821 const u8 *wpaie = NULL;
822
Michal Kazior548db542013-07-05 16:15:15 +0300823 lockdep_assert_held(&ar->conf_mutex);
824
Kalle Valo5e3dd152013-06-12 20:52:10 +0300825 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
826 info->bssid, NULL, 0, 0, 0);
827 if (bss) {
828 const struct cfg80211_bss_ies *ies;
829
830 rcu_read_lock();
831 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
832
833 ies = rcu_dereference(bss->ies);
834
835 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
836 WLAN_OUI_TYPE_MICROSOFT_WPA,
837 ies->data,
838 ies->len);
839 rcu_read_unlock();
840 cfg80211_put_bss(ar->hw->wiphy, bss);
841 }
842
843 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
844 if (rsnie || wpaie) {
845 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
846 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
847 }
848
849 if (wpaie) {
850 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
851 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
852 }
853}
854
855static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
856 struct ieee80211_sta *sta,
857 struct wmi_peer_assoc_complete_arg *arg)
858{
859 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
860 const struct ieee80211_supported_band *sband;
861 const struct ieee80211_rate *rates;
862 u32 ratemask;
863 int i;
864
Michal Kazior548db542013-07-05 16:15:15 +0300865 lockdep_assert_held(&ar->conf_mutex);
866
Kalle Valo5e3dd152013-06-12 20:52:10 +0300867 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
868 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
869 rates = sband->bitrates;
870
871 rateset->num_rates = 0;
872
873 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
874 if (!(ratemask & 1))
875 continue;
876
877 rateset->rates[rateset->num_rates] = rates->hw_value;
878 rateset->num_rates++;
879 }
880}
881
882static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
883 struct ieee80211_sta *sta,
884 struct wmi_peer_assoc_complete_arg *arg)
885{
886 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
887 int smps;
888 int i, n;
889
Michal Kazior548db542013-07-05 16:15:15 +0300890 lockdep_assert_held(&ar->conf_mutex);
891
Kalle Valo5e3dd152013-06-12 20:52:10 +0300892 if (!ht_cap->ht_supported)
893 return;
894
895 arg->peer_flags |= WMI_PEER_HT;
896 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
897 ht_cap->ampdu_factor)) - 1;
898
899 arg->peer_mpdu_density =
900 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
901
902 arg->peer_ht_caps = ht_cap->cap;
903 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
904
905 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
906 arg->peer_flags |= WMI_PEER_LDPC;
907
908 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
909 arg->peer_flags |= WMI_PEER_40MHZ;
910 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
911 }
912
913 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
914 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
915
916 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
917 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
918
919 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
920 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
921 arg->peer_flags |= WMI_PEER_STBC;
922 }
923
924 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
925 u32 stbc;
926 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
927 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
928 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
929 arg->peer_rate_caps |= stbc;
930 arg->peer_flags |= WMI_PEER_STBC;
931 }
932
933 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
934 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
935
936 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
937 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
938 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
939 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
940 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
941 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
942 }
943
944 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
945 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
946 else if (ht_cap->mcs.rx_mask[1])
947 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
948
949 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
950 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
951 arg->peer_ht_rates.rates[n++] = i;
952
953 arg->peer_ht_rates.num_rates = n;
954 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
955
Kalle Valo60c3daa2013-09-08 17:56:07 +0300956 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
957 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300958 arg->peer_ht_rates.num_rates,
959 arg->peer_num_spatial_streams);
960}
961
962static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
963 struct ath10k_vif *arvif,
964 struct ieee80211_sta *sta,
965 struct ieee80211_bss_conf *bss_conf,
966 struct wmi_peer_assoc_complete_arg *arg)
967{
968 u32 uapsd = 0;
969 u32 max_sp = 0;
970
Michal Kazior548db542013-07-05 16:15:15 +0300971 lockdep_assert_held(&ar->conf_mutex);
972
Kalle Valo5e3dd152013-06-12 20:52:10 +0300973 if (sta->wme)
974 arg->peer_flags |= WMI_PEER_QOS;
975
976 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +0300977 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300978 sta->uapsd_queues, sta->max_sp);
979
980 arg->peer_flags |= WMI_PEER_APSD;
Janusz Dziedzicc69029b2013-08-07 12:10:49 +0200981 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982
983 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
984 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
985 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
986 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
987 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
988 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
989 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
990 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
991 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
992 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
993 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
994 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
995
996
997 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
998 max_sp = sta->max_sp;
999
1000 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1001 sta->addr,
1002 WMI_AP_PS_PEER_PARAM_UAPSD,
1003 uapsd);
1004
1005 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1006 sta->addr,
1007 WMI_AP_PS_PEER_PARAM_MAX_SP,
1008 max_sp);
1009
1010 /* TODO setup this based on STA listen interval and
1011 beacon interval. Currently we don't know
1012 sta->listen_interval - mac80211 patch required.
1013 Currently use 10 seconds */
1014 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1015 sta->addr,
1016 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1017 10);
1018 }
1019}
1020
1021static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1022 struct ath10k_vif *arvif,
1023 struct ieee80211_sta *sta,
1024 struct ieee80211_bss_conf *bss_conf,
1025 struct wmi_peer_assoc_complete_arg *arg)
1026{
1027 if (bss_conf->qos)
1028 arg->peer_flags |= WMI_PEER_QOS;
1029}
1030
1031static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1032 struct ieee80211_sta *sta,
1033 struct wmi_peer_assoc_complete_arg *arg)
1034{
1035 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001036 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001037
1038 if (!vht_cap->vht_supported)
1039 return;
1040
1041 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001042 arg->peer_vht_caps = vht_cap->cap;
1043
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001044
1045 ampdu_factor = (vht_cap->cap &
1046 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1047 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1048
1049 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1050 * zero in VHT IE. Using it would result in degraded throughput.
1051 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1052 * it if VHT max_mpdu is smaller. */
1053 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1054 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1055 ampdu_factor)) - 1);
1056
Kalle Valo5e3dd152013-06-12 20:52:10 +03001057 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1058 arg->peer_flags |= WMI_PEER_80MHZ;
1059
1060 arg->peer_vht_rates.rx_max_rate =
1061 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1062 arg->peer_vht_rates.rx_mcs_set =
1063 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1064 arg->peer_vht_rates.tx_max_rate =
1065 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1066 arg->peer_vht_rates.tx_mcs_set =
1067 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1068
Kalle Valo60c3daa2013-09-08 17:56:07 +03001069 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1070 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001071}
1072
1073static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1074 struct ath10k_vif *arvif,
1075 struct ieee80211_sta *sta,
1076 struct ieee80211_bss_conf *bss_conf,
1077 struct wmi_peer_assoc_complete_arg *arg)
1078{
1079 switch (arvif->vdev_type) {
1080 case WMI_VDEV_TYPE_AP:
1081 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1082 break;
1083 case WMI_VDEV_TYPE_STA:
1084 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1085 break;
1086 default:
1087 break;
1088 }
1089}
1090
1091static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1092 struct ath10k_vif *arvif,
1093 struct ieee80211_sta *sta,
1094 struct wmi_peer_assoc_complete_arg *arg)
1095{
1096 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1097
Kalle Valo5e3dd152013-06-12 20:52:10 +03001098 switch (ar->hw->conf.chandef.chan->band) {
1099 case IEEE80211_BAND_2GHZ:
1100 if (sta->ht_cap.ht_supported) {
1101 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1102 phymode = MODE_11NG_HT40;
1103 else
1104 phymode = MODE_11NG_HT20;
1105 } else {
1106 phymode = MODE_11G;
1107 }
1108
1109 break;
1110 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001111 /*
1112 * Check VHT first.
1113 */
1114 if (sta->vht_cap.vht_supported) {
1115 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1116 phymode = MODE_11AC_VHT80;
1117 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1118 phymode = MODE_11AC_VHT40;
1119 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1120 phymode = MODE_11AC_VHT20;
1121 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1123 phymode = MODE_11NA_HT40;
1124 else
1125 phymode = MODE_11NA_HT20;
1126 } else {
1127 phymode = MODE_11A;
1128 }
1129
1130 break;
1131 default:
1132 break;
1133 }
1134
Kalle Valo38a1d472013-09-08 17:56:14 +03001135 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1136 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001137
Kalle Valo5e3dd152013-06-12 20:52:10 +03001138 arg->peer_phymode = phymode;
1139 WARN_ON(phymode == MODE_UNKNOWN);
1140}
1141
1142static int ath10k_peer_assoc(struct ath10k *ar,
1143 struct ath10k_vif *arvif,
1144 struct ieee80211_sta *sta,
1145 struct ieee80211_bss_conf *bss_conf)
1146{
1147 struct wmi_peer_assoc_complete_arg arg;
1148
Michal Kazior548db542013-07-05 16:15:15 +03001149 lockdep_assert_held(&ar->conf_mutex);
1150
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1152
1153 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1154 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1155 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1156 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1157 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1158 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1159 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1160
1161 return ath10k_wmi_peer_assoc(ar, &arg);
1162}
1163
1164/* can be called only in mac80211 callbacks due to `key_count` usage */
1165static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1166 struct ieee80211_vif *vif,
1167 struct ieee80211_bss_conf *bss_conf)
1168{
1169 struct ath10k *ar = hw->priv;
1170 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1171 struct ieee80211_sta *ap_sta;
1172 int ret;
1173
Michal Kazior548db542013-07-05 16:15:15 +03001174 lockdep_assert_held(&ar->conf_mutex);
1175
Kalle Valo5e3dd152013-06-12 20:52:10 +03001176 rcu_read_lock();
1177
1178 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1179 if (!ap_sta) {
1180 ath10k_warn("Failed to find station entry for %pM\n",
1181 bss_conf->bssid);
1182 rcu_read_unlock();
1183 return;
1184 }
1185
1186 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1187 if (ret) {
1188 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1189 rcu_read_unlock();
1190 return;
1191 }
1192
1193 rcu_read_unlock();
1194
Kalle Valo60c3daa2013-09-08 17:56:07 +03001195 ath10k_dbg(ATH10K_DBG_MAC,
1196 "mac vdev %d up (associated) bssid %pM aid %d\n",
1197 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1198
Kalle Valo5e3dd152013-06-12 20:52:10 +03001199 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1200 bss_conf->bssid);
1201 if (ret)
1202 ath10k_warn("VDEV: %d up failed: ret %d\n",
1203 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001204}
1205
1206/*
1207 * FIXME: flush TIDs
1208 */
1209static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1210 struct ieee80211_vif *vif)
1211{
1212 struct ath10k *ar = hw->priv;
1213 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1214 int ret;
1215
Michal Kazior548db542013-07-05 16:15:15 +03001216 lockdep_assert_held(&ar->conf_mutex);
1217
Kalle Valo5e3dd152013-06-12 20:52:10 +03001218 /*
1219 * For some reason, calling VDEV-DOWN before VDEV-STOP
1220 * makes the FW to send frames via HTT after disassociation.
1221 * No idea why this happens, even though VDEV-DOWN is supposed
1222 * to be analogous to link down, so just stop the VDEV.
1223 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001224 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1225 arvif->vdev_id);
1226
1227 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001229
1230 /*
1231 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1232 * report beacons from previously associated network through HTT.
1233 * This in turn would spam mac80211 WARN_ON if we bring down all
1234 * interfaces as it expects there is no rx when no interface is
1235 * running.
1236 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001237 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1238
1239 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001241
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001242 arvif->def_wep_key_idx = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243}
1244
1245static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1246 struct ieee80211_sta *sta)
1247{
1248 int ret = 0;
1249
Michal Kazior548db542013-07-05 16:15:15 +03001250 lockdep_assert_held(&ar->conf_mutex);
1251
Kalle Valo5e3dd152013-06-12 20:52:10 +03001252 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1253 if (ret) {
1254 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1255 return ret;
1256 }
1257
1258 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1259 if (ret) {
1260 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1261 return ret;
1262 }
1263
1264 return ret;
1265}
1266
1267static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta)
1269{
1270 int ret = 0;
1271
Michal Kazior548db542013-07-05 16:15:15 +03001272 lockdep_assert_held(&ar->conf_mutex);
1273
Kalle Valo5e3dd152013-06-12 20:52:10 +03001274 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1275 if (ret) {
1276 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1277 return ret;
1278 }
1279
1280 return ret;
1281}
1282
1283/**************/
1284/* Regulatory */
1285/**************/
1286
1287static int ath10k_update_channel_list(struct ath10k *ar)
1288{
1289 struct ieee80211_hw *hw = ar->hw;
1290 struct ieee80211_supported_band **bands;
1291 enum ieee80211_band band;
1292 struct ieee80211_channel *channel;
1293 struct wmi_scan_chan_list_arg arg = {0};
1294 struct wmi_channel_arg *ch;
1295 bool passive;
1296 int len;
1297 int ret;
1298 int i;
1299
Michal Kazior548db542013-07-05 16:15:15 +03001300 lockdep_assert_held(&ar->conf_mutex);
1301
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302 bands = hw->wiphy->bands;
1303 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1304 if (!bands[band])
1305 continue;
1306
1307 for (i = 0; i < bands[band]->n_channels; i++) {
1308 if (bands[band]->channels[i].flags &
1309 IEEE80211_CHAN_DISABLED)
1310 continue;
1311
1312 arg.n_channels++;
1313 }
1314 }
1315
1316 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1317 arg.channels = kzalloc(len, GFP_KERNEL);
1318 if (!arg.channels)
1319 return -ENOMEM;
1320
1321 ch = arg.channels;
1322 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1323 if (!bands[band])
1324 continue;
1325
1326 for (i = 0; i < bands[band]->n_channels; i++) {
1327 channel = &bands[band]->channels[i];
1328
1329 if (channel->flags & IEEE80211_CHAN_DISABLED)
1330 continue;
1331
1332 ch->allow_ht = true;
1333
1334 /* FIXME: when should we really allow VHT? */
1335 ch->allow_vht = true;
1336
1337 ch->allow_ibss =
1338 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1339
1340 ch->ht40plus =
1341 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1342
1343 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1344 ch->passive = passive;
1345
1346 ch->freq = channel->center_freq;
1347 ch->min_power = channel->max_power * 3;
1348 ch->max_power = channel->max_power * 4;
1349 ch->max_reg_power = channel->max_reg_power * 4;
1350 ch->max_antenna_gain = channel->max_antenna_gain;
1351 ch->reg_class_id = 0; /* FIXME */
1352
1353 /* FIXME: why use only legacy modes, why not any
1354 * HT/VHT modes? Would that even make any
1355 * difference? */
1356 if (channel->band == IEEE80211_BAND_2GHZ)
1357 ch->mode = MODE_11G;
1358 else
1359 ch->mode = MODE_11A;
1360
1361 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1362 continue;
1363
1364 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001365 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1366 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367 ch->freq, ch->max_power, ch->max_reg_power,
1368 ch->max_antenna_gain, ch->mode);
1369
1370 ch++;
1371 }
1372 }
1373
1374 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1375 kfree(arg.channels);
1376
1377 return ret;
1378}
1379
Michal Kaziorf7843d72013-07-16 09:38:52 +02001380static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001382 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383 int ret;
1384
Michal Kaziorf7843d72013-07-16 09:38:52 +02001385 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386
1387 ret = ath10k_update_channel_list(ar);
1388 if (ret)
1389 ath10k_warn("could not update channel list (%d)\n", ret);
1390
1391 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001392
Kalle Valo5e3dd152013-06-12 20:52:10 +03001393 /* Target allows setting up per-band regdomain but ath_common provides
1394 * a combined one only */
1395 ret = ath10k_wmi_pdev_set_regdomain(ar,
1396 regpair->regDmnEnum,
1397 regpair->regDmnEnum, /* 2ghz */
1398 regpair->regDmnEnum, /* 5ghz */
1399 regpair->reg_2ghz_ctl,
1400 regpair->reg_5ghz_ctl);
1401 if (ret)
1402 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001403}
Michal Kazior548db542013-07-05 16:15:15 +03001404
Michal Kaziorf7843d72013-07-16 09:38:52 +02001405static void ath10k_reg_notifier(struct wiphy *wiphy,
1406 struct regulatory_request *request)
1407{
1408 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1409 struct ath10k *ar = hw->priv;
1410
1411 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1412
1413 mutex_lock(&ar->conf_mutex);
1414 if (ar->state == ATH10K_STATE_ON)
1415 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001416 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417}
1418
1419/***************/
1420/* TX handlers */
1421/***************/
1422
Michal Kazior42c3aa62013-10-02 11:03:38 +02001423static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1424{
1425 if (ieee80211_is_mgmt(hdr->frame_control))
1426 return HTT_DATA_TX_EXT_TID_MGMT;
1427
1428 if (!ieee80211_is_data_qos(hdr->frame_control))
1429 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1430
1431 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1432 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1433
1434 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1435}
1436
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001437static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1438 struct ieee80211_tx_info *info)
1439{
1440 if (info->control.vif)
1441 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1442
1443 if (ar->monitor_enabled)
1444 return ar->monitor_vdev_id;
1445
1446 ath10k_warn("could not resolve vdev id\n");
1447 return 0;
1448}
1449
Kalle Valo5e3dd152013-06-12 20:52:10 +03001450/*
1451 * Frames sent to the FW have to be in "Native Wifi" format.
1452 * Strip the QoS field from the 802.11 header.
1453 */
1454static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1455 struct ieee80211_tx_control *control,
1456 struct sk_buff *skb)
1457{
1458 struct ieee80211_hdr *hdr = (void *)skb->data;
1459 u8 *qos_ctl;
1460
1461 if (!ieee80211_is_data_qos(hdr->frame_control))
1462 return;
1463
1464 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001465 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1466 skb->data, (void *)qos_ctl - (void *)skb->data);
1467 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001468}
1469
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001470static void ath10k_tx_wep_key_work(struct work_struct *work)
1471{
1472 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1473 wep_key_work);
1474 int ret, keyidx = arvif->def_wep_key_newidx;
1475
1476 if (arvif->def_wep_key_idx == keyidx)
1477 return;
1478
1479 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1480 arvif->vdev_id, keyidx);
1481
1482 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1483 arvif->vdev_id,
1484 arvif->ar->wmi.vdev_param->def_keyid,
1485 keyidx);
1486 if (ret) {
1487 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1488 return;
1489 }
1490
1491 arvif->def_wep_key_idx = keyidx;
1492}
1493
Kalle Valo5e3dd152013-06-12 20:52:10 +03001494static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1495{
1496 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1497 struct ieee80211_vif *vif = info->control.vif;
1498 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1499 struct ath10k *ar = arvif->ar;
1500 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1501 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502
Kalle Valo5e3dd152013-06-12 20:52:10 +03001503 if (!ieee80211_has_protected(hdr->frame_control))
1504 return;
1505
1506 if (!key)
1507 return;
1508
1509 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1510 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1511 return;
1512
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001513 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001514 return;
1515
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001516 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1517 * queueing frames until key index is updated is not an option because
1518 * sk_buff may need more processing to be done, e.g. offchannel */
1519 arvif->def_wep_key_newidx = key->keyidx;
1520 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001521}
1522
1523static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1524{
1525 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1526 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1527 struct ieee80211_vif *vif = info->control.vif;
1528 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1529
1530 /* This is case only for P2P_GO */
1531 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1532 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1533 return;
1534
1535 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1536 spin_lock_bh(&ar->data_lock);
1537 if (arvif->u.ap.noa_data)
1538 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1539 GFP_ATOMIC))
1540 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1541 arvif->u.ap.noa_data,
1542 arvif->u.ap.noa_len);
1543 spin_unlock_bh(&ar->data_lock);
1544 }
1545}
1546
1547static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1548{
1549 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001550 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001551
Michal Kazior961d4c32013-08-09 10:13:34 +02001552 if (ar->htt.target_version_major >= 3) {
1553 /* Since HTT 3.0 there is no separate mgmt tx command */
1554 ret = ath10k_htt_tx(&ar->htt, skb);
1555 goto exit;
1556 }
1557
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001558 if (ieee80211_is_mgmt(hdr->frame_control)) {
1559 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1560 ar->fw_features)) {
1561 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1562 ATH10K_MAX_NUM_MGMT_PENDING) {
1563 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1564 ret = -EBUSY;
1565 goto exit;
1566 }
1567
1568 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1569 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1570 } else {
1571 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1572 }
1573 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1574 ar->fw_features) &&
1575 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576 /* FW does not report tx status properly for NullFunc frames
1577 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001578 * those frames when it detects link/beacon loss and depends
1579 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001580 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001581 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001582 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001583 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584
Michal Kazior961d4c32013-08-09 10:13:34 +02001585exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 if (ret) {
1587 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1588 ieee80211_free_txskb(ar->hw, skb);
1589 }
1590}
1591
1592void ath10k_offchan_tx_purge(struct ath10k *ar)
1593{
1594 struct sk_buff *skb;
1595
1596 for (;;) {
1597 skb = skb_dequeue(&ar->offchan_tx_queue);
1598 if (!skb)
1599 break;
1600
1601 ieee80211_free_txskb(ar->hw, skb);
1602 }
1603}
1604
1605void ath10k_offchan_tx_work(struct work_struct *work)
1606{
1607 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1608 struct ath10k_peer *peer;
1609 struct ieee80211_hdr *hdr;
1610 struct sk_buff *skb;
1611 const u8 *peer_addr;
1612 int vdev_id;
1613 int ret;
1614
1615 /* FW requirement: We must create a peer before FW will send out
1616 * an offchannel frame. Otherwise the frame will be stuck and
1617 * never transmitted. We delete the peer upon tx completion.
1618 * It is unlikely that a peer for offchannel tx will already be
1619 * present. However it may be in some rare cases so account for that.
1620 * Otherwise we might remove a legitimate peer and break stuff. */
1621
1622 for (;;) {
1623 skb = skb_dequeue(&ar->offchan_tx_queue);
1624 if (!skb)
1625 break;
1626
1627 mutex_lock(&ar->conf_mutex);
1628
Kalle Valo60c3daa2013-09-08 17:56:07 +03001629 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001630 skb);
1631
1632 hdr = (struct ieee80211_hdr *)skb->data;
1633 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001634 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635
1636 spin_lock_bh(&ar->data_lock);
1637 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1638 spin_unlock_bh(&ar->data_lock);
1639
1640 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001641 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001642 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1643 peer_addr, vdev_id);
1644
1645 if (!peer) {
1646 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1647 if (ret)
1648 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1649 peer_addr, vdev_id, ret);
1650 }
1651
1652 spin_lock_bh(&ar->data_lock);
1653 INIT_COMPLETION(ar->offchan_tx_completed);
1654 ar->offchan_tx_skb = skb;
1655 spin_unlock_bh(&ar->data_lock);
1656
1657 ath10k_tx_htt(ar, skb);
1658
1659 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1660 3 * HZ);
1661 if (ret <= 0)
1662 ath10k_warn("timed out waiting for offchannel skb %p\n",
1663 skb);
1664
1665 if (!peer) {
1666 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1667 if (ret)
1668 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1669 peer_addr, vdev_id, ret);
1670 }
1671
1672 mutex_unlock(&ar->conf_mutex);
1673 }
1674}
1675
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001676void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1677{
1678 struct sk_buff *skb;
1679
1680 for (;;) {
1681 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1682 if (!skb)
1683 break;
1684
1685 ieee80211_free_txskb(ar->hw, skb);
1686 }
1687}
1688
1689void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1690{
1691 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1692 struct sk_buff *skb;
1693 int ret;
1694
1695 for (;;) {
1696 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1697 if (!skb)
1698 break;
1699
1700 ret = ath10k_wmi_mgmt_tx(ar, skb);
1701 if (ret)
1702 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
1703 }
1704}
1705
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706/************/
1707/* Scanning */
1708/************/
1709
1710/*
1711 * This gets called if we dont get a heart-beat during scan.
1712 * This may indicate the FW has hung and we need to abort the
1713 * scan manually to prevent cancel_hw_scan() from deadlocking
1714 */
1715void ath10k_reset_scan(unsigned long ptr)
1716{
1717 struct ath10k *ar = (struct ath10k *)ptr;
1718
1719 spin_lock_bh(&ar->data_lock);
1720 if (!ar->scan.in_progress) {
1721 spin_unlock_bh(&ar->data_lock);
1722 return;
1723 }
1724
1725 ath10k_warn("scan timeout. resetting. fw issue?\n");
1726
1727 if (ar->scan.is_roc)
1728 ieee80211_remain_on_channel_expired(ar->hw);
1729 else
1730 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1731
1732 ar->scan.in_progress = false;
1733 complete_all(&ar->scan.completed);
1734 spin_unlock_bh(&ar->data_lock);
1735}
1736
1737static int ath10k_abort_scan(struct ath10k *ar)
1738{
1739 struct wmi_stop_scan_arg arg = {
1740 .req_id = 1, /* FIXME */
1741 .req_type = WMI_SCAN_STOP_ONE,
1742 .u.scan_id = ATH10K_SCAN_ID,
1743 };
1744 int ret;
1745
1746 lockdep_assert_held(&ar->conf_mutex);
1747
1748 del_timer_sync(&ar->scan.timeout);
1749
1750 spin_lock_bh(&ar->data_lock);
1751 if (!ar->scan.in_progress) {
1752 spin_unlock_bh(&ar->data_lock);
1753 return 0;
1754 }
1755
1756 ar->scan.aborting = true;
1757 spin_unlock_bh(&ar->data_lock);
1758
1759 ret = ath10k_wmi_stop_scan(ar, &arg);
1760 if (ret) {
1761 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03001762 spin_lock_bh(&ar->data_lock);
1763 ar->scan.in_progress = false;
1764 ath10k_offchan_tx_purge(ar);
1765 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766 return -EIO;
1767 }
1768
Kalle Valo5e3dd152013-06-12 20:52:10 +03001769 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1770 if (ret == 0)
1771 ath10k_warn("timed out while waiting for scan to stop\n");
1772
1773 /* scan completion may be done right after we timeout here, so let's
1774 * check the in_progress and tell mac80211 scan is completed. if we
1775 * don't do that and FW fails to send us scan completion indication
1776 * then userspace won't be able to scan anymore */
1777 ret = 0;
1778
1779 spin_lock_bh(&ar->data_lock);
1780 if (ar->scan.in_progress) {
1781 ath10k_warn("could not stop scan. its still in progress\n");
1782 ar->scan.in_progress = false;
1783 ath10k_offchan_tx_purge(ar);
1784 ret = -ETIMEDOUT;
1785 }
1786 spin_unlock_bh(&ar->data_lock);
1787
1788 return ret;
1789}
1790
1791static int ath10k_start_scan(struct ath10k *ar,
1792 const struct wmi_start_scan_arg *arg)
1793{
1794 int ret;
1795
1796 lockdep_assert_held(&ar->conf_mutex);
1797
1798 ret = ath10k_wmi_start_scan(ar, arg);
1799 if (ret)
1800 return ret;
1801
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1803 if (ret == 0) {
1804 ath10k_abort_scan(ar);
1805 return ret;
1806 }
1807
1808 /* the scan can complete earlier, before we even
1809 * start the timer. in that case the timer handler
1810 * checks ar->scan.in_progress and bails out if its
1811 * false. Add a 200ms margin to account event/command
1812 * processing. */
1813 mod_timer(&ar->scan.timeout, jiffies +
1814 msecs_to_jiffies(arg->max_scan_time+200));
1815 return 0;
1816}
1817
1818/**********************/
1819/* mac80211 callbacks */
1820/**********************/
1821
1822static void ath10k_tx(struct ieee80211_hw *hw,
1823 struct ieee80211_tx_control *control,
1824 struct sk_buff *skb)
1825{
1826 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1827 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1828 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001829 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830
1831 /* We should disable CCK RATE due to P2P */
1832 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1833 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1834
1835 /* we must calculate tid before we apply qos workaround
1836 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02001837 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001838 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839
Michal Kaziorcf84bd42013-07-16 11:04:54 +02001840 /* it makes no sense to process injected frames like that */
1841 if (info->control.vif &&
1842 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1843 ath10k_tx_h_qos_workaround(hw, control, skb);
1844 ath10k_tx_h_update_wep_key(skb);
1845 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1846 ath10k_tx_h_seq_no(skb);
1847 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001849 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02001850 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851 ATH10K_SKB_CB(skb)->htt.tid = tid;
1852
1853 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1854 spin_lock_bh(&ar->data_lock);
1855 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001856 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001857 spin_unlock_bh(&ar->data_lock);
1858
1859 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1860
1861 skb_queue_tail(&ar->offchan_tx_queue, skb);
1862 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1863 return;
1864 }
1865
1866 ath10k_tx_htt(ar, skb);
1867}
1868
1869/*
1870 * Initialize various parameters with default vaules.
1871 */
Michal Kazioraffd3212013-07-16 09:54:35 +02001872void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02001873{
1874 lockdep_assert_held(&ar->conf_mutex);
1875
1876 del_timer_sync(&ar->scan.timeout);
1877 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001878 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02001879 ath10k_peer_cleanup_all(ar);
1880 ath10k_core_stop(ar);
1881 ath10k_hif_power_down(ar);
1882
1883 spin_lock_bh(&ar->data_lock);
1884 if (ar->scan.in_progress) {
1885 del_timer(&ar->scan.timeout);
1886 ar->scan.in_progress = false;
1887 ieee80211_scan_completed(ar->hw, true);
1888 }
1889 spin_unlock_bh(&ar->data_lock);
1890}
1891
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892static int ath10k_start(struct ieee80211_hw *hw)
1893{
1894 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02001895 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896
Michal Kazior548db542013-07-05 16:15:15 +03001897 mutex_lock(&ar->conf_mutex);
1898
Michal Kazioraffd3212013-07-16 09:54:35 +02001899 if (ar->state != ATH10K_STATE_OFF &&
1900 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02001901 ret = -EINVAL;
1902 goto exit;
1903 }
1904
1905 ret = ath10k_hif_power_up(ar);
1906 if (ret) {
1907 ath10k_err("could not init hif (%d)\n", ret);
1908 ar->state = ATH10K_STATE_OFF;
1909 goto exit;
1910 }
1911
1912 ret = ath10k_core_start(ar);
1913 if (ret) {
1914 ath10k_err("could not init core (%d)\n", ret);
1915 ath10k_hif_power_down(ar);
1916 ar->state = ATH10K_STATE_OFF;
1917 goto exit;
1918 }
1919
Michal Kazioraffd3212013-07-16 09:54:35 +02001920 if (ar->state == ATH10K_STATE_OFF)
1921 ar->state = ATH10K_STATE_ON;
1922 else if (ar->state == ATH10K_STATE_RESTARTING)
1923 ar->state = ATH10K_STATE_RESTARTED;
1924
Bartosz Markowski226a3392013-09-26 17:47:16 +02001925 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926 if (ret)
1927 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1928 ret);
1929
Bartosz Markowski226a3392013-09-26 17:47:16 +02001930 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001931 if (ret)
1932 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1933 ret);
1934
Michal Kaziorf7843d72013-07-16 09:38:52 +02001935 ath10k_regd_update(ar);
1936
Michal Kazior818bdd12013-07-16 09:38:57 +02001937exit:
Michal Kazior548db542013-07-05 16:15:15 +03001938 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 return 0;
1940}
1941
1942static void ath10k_stop(struct ieee80211_hw *hw)
1943{
1944 struct ath10k *ar = hw->priv;
1945
Michal Kazior548db542013-07-05 16:15:15 +03001946 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02001947 if (ar->state == ATH10K_STATE_ON ||
1948 ar->state == ATH10K_STATE_RESTARTED ||
1949 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02001950 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02001951
Michal Kaziorf7843d72013-07-16 09:38:52 +02001952 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03001953 mutex_unlock(&ar->conf_mutex);
1954
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001955 ath10k_mgmt_over_wmi_tx_purge(ar);
1956
Michal Kazior548db542013-07-05 16:15:15 +03001957 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001958 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02001959 cancel_work_sync(&ar->restart_work);
1960}
1961
1962static void ath10k_config_ps(struct ath10k *ar)
1963{
1964 struct ath10k_generic_iter ar_iter;
1965
1966 lockdep_assert_held(&ar->conf_mutex);
1967
1968 /* During HW reconfiguration mac80211 reports all interfaces that were
1969 * running until reconfiguration was started. Since FW doesn't have any
1970 * vdevs at this point we must not iterate over this interface list.
1971 * This setting will be updated upon add_interface(). */
1972 if (ar->state == ATH10K_STATE_RESTARTED)
1973 return;
1974
1975 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1976 ar_iter.ar = ar;
1977
1978 ieee80211_iterate_active_interfaces_atomic(
1979 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1980 ath10k_ps_iter, &ar_iter);
1981
1982 if (ar_iter.ret)
1983 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984}
1985
1986static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1987{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988 struct ath10k *ar = hw->priv;
1989 struct ieee80211_conf *conf = &hw->conf;
1990 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001991
1992 mutex_lock(&ar->conf_mutex);
1993
1994 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001995 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001996 conf->chandef.chan->center_freq);
1997 spin_lock_bh(&ar->data_lock);
1998 ar->rx_channel = conf->chandef.chan;
1999 spin_unlock_bh(&ar->data_lock);
2000 }
2001
Michal Kazioraffd3212013-07-16 09:54:35 +02002002 if (changed & IEEE80211_CONF_CHANGE_PS)
2003 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004
2005 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2006 if (conf->flags & IEEE80211_CONF_MONITOR)
2007 ret = ath10k_monitor_create(ar);
2008 else
2009 ret = ath10k_monitor_destroy(ar);
2010 }
2011
2012 mutex_unlock(&ar->conf_mutex);
2013 return ret;
2014}
2015
2016/*
2017 * TODO:
2018 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2019 * because we will send mgmt frames without CCK. This requirement
2020 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2021 * in the TX packet.
2022 */
2023static int ath10k_add_interface(struct ieee80211_hw *hw,
2024 struct ieee80211_vif *vif)
2025{
2026 struct ath10k *ar = hw->priv;
2027 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2028 enum wmi_sta_powersave_param param;
2029 int ret = 0;
Michal Kazior424121c2013-07-22 14:13:31 +02002030 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002031 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002032 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002033
2034 mutex_lock(&ar->conf_mutex);
2035
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002036 memset(arvif, 0, sizeof(*arvif));
2037
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038 arvif->ar = ar;
2039 arvif->vif = vif;
2040
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002041 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2042
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2044 ath10k_warn("Only one monitor interface allowed\n");
2045 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002046 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047 }
2048
2049 bit = ffs(ar->free_vdev_map);
2050 if (bit == 0) {
2051 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002052 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002053 }
2054
2055 arvif->vdev_id = bit - 1;
2056 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057
2058 if (ar->p2p)
2059 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2060
2061 switch (vif->type) {
2062 case NL80211_IFTYPE_UNSPECIFIED:
2063 case NL80211_IFTYPE_STATION:
2064 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2065 if (vif->p2p)
2066 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2067 break;
2068 case NL80211_IFTYPE_ADHOC:
2069 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2070 break;
2071 case NL80211_IFTYPE_AP:
2072 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2073
2074 if (vif->p2p)
2075 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2076 break;
2077 case NL80211_IFTYPE_MONITOR:
2078 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2079 break;
2080 default:
2081 WARN_ON(1);
2082 break;
2083 }
2084
Kalle Valo60c3daa2013-09-08 17:56:07 +03002085 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002086 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2087
2088 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2089 arvif->vdev_subtype, vif->addr);
2090 if (ret) {
2091 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002092 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093 }
2094
Michal Kazior9dad14a2013-10-16 15:44:45 +03002095 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2096
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002097 vdev_param = ar->wmi.vdev_param->def_keyid;
2098 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002099 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002100 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002102 goto err_vdev_delete;
2103 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002105 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2106 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002107 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002108 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002109 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002111 goto err_vdev_delete;
2112 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002113
2114 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2115 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2116 if (ret) {
2117 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002118 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119 }
2120 }
2121
2122 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2123 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2124 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2125 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2126 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002127 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002129 goto err_peer_delete;
2130 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131
2132 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2133 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2134 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2135 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002136 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002138 goto err_peer_delete;
2139 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002140
2141 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2142 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2143 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2144 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002145 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002147 goto err_peer_delete;
2148 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149 }
2150
Michal Kazior424121c2013-07-22 14:13:31 +02002151 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002152 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002153 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2154 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002155 goto err_peer_delete;
2156 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002157
Michal Kazior424121c2013-07-22 14:13:31 +02002158 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002159 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002160 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2161 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002162 goto err_peer_delete;
2163 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002164
Kalle Valo5e3dd152013-06-12 20:52:10 +03002165 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2166 ar->monitor_present = true;
2167
Kalle Valo5e3dd152013-06-12 20:52:10 +03002168 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002169 return 0;
2170
2171err_peer_delete:
2172 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2173 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2174
2175err_vdev_delete:
2176 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2177 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2178
2179err:
2180 mutex_unlock(&ar->conf_mutex);
2181
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182 return ret;
2183}
2184
2185static void ath10k_remove_interface(struct ieee80211_hw *hw,
2186 struct ieee80211_vif *vif)
2187{
2188 struct ath10k *ar = hw->priv;
2189 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2190 int ret;
2191
2192 mutex_lock(&ar->conf_mutex);
2193
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002194 cancel_work_sync(&arvif->wep_key_work);
2195
Michal Kaziored543882013-09-13 14:16:56 +02002196 spin_lock_bh(&ar->data_lock);
2197 if (arvif->beacon) {
2198 dev_kfree_skb_any(arvif->beacon);
2199 arvif->beacon = NULL;
2200 }
2201 spin_unlock_bh(&ar->data_lock);
2202
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2204
2205 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2206 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2207 if (ret)
2208 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2209
2210 kfree(arvif->u.ap.noa_data);
2211 }
2212
Kalle Valo60c3daa2013-09-08 17:56:07 +03002213 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2214 arvif->vdev_id);
2215
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2217 if (ret)
2218 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2219
2220 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2221 ar->monitor_present = false;
2222
2223 ath10k_peer_cleanup(ar, arvif->vdev_id);
2224
2225 mutex_unlock(&ar->conf_mutex);
2226}
2227
2228/*
2229 * FIXME: Has to be verified.
2230 */
2231#define SUPPORTED_FILTERS \
2232 (FIF_PROMISC_IN_BSS | \
2233 FIF_ALLMULTI | \
2234 FIF_CONTROL | \
2235 FIF_PSPOLL | \
2236 FIF_OTHER_BSS | \
2237 FIF_BCN_PRBRESP_PROMISC | \
2238 FIF_PROBE_REQ | \
2239 FIF_FCSFAIL)
2240
2241static void ath10k_configure_filter(struct ieee80211_hw *hw,
2242 unsigned int changed_flags,
2243 unsigned int *total_flags,
2244 u64 multicast)
2245{
2246 struct ath10k *ar = hw->priv;
2247 int ret;
2248
2249 mutex_lock(&ar->conf_mutex);
2250
2251 changed_flags &= SUPPORTED_FILTERS;
2252 *total_flags &= SUPPORTED_FILTERS;
2253 ar->filter_flags = *total_flags;
2254
2255 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2256 !ar->monitor_enabled) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002257 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2258 ar->monitor_vdev_id);
2259
Kalle Valo5e3dd152013-06-12 20:52:10 +03002260 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2261 if (ret)
2262 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002263 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2264 ar->monitor_enabled) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002265 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2266 ar->monitor_vdev_id);
2267
Kalle Valo5e3dd152013-06-12 20:52:10 +03002268 ret = ath10k_monitor_stop(ar);
2269 if (ret)
2270 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002271 }
2272
2273 mutex_unlock(&ar->conf_mutex);
2274}
2275
2276static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2277 struct ieee80211_vif *vif,
2278 struct ieee80211_bss_conf *info,
2279 u32 changed)
2280{
2281 struct ath10k *ar = hw->priv;
2282 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2283 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002284 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285
2286 mutex_lock(&ar->conf_mutex);
2287
2288 if (changed & BSS_CHANGED_IBSS)
2289 ath10k_control_ibss(arvif, info, vif->addr);
2290
2291 if (changed & BSS_CHANGED_BEACON_INT) {
2292 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002293 vdev_param = ar->wmi.vdev_param->beacon_interval;
2294 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002295 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002296 ath10k_dbg(ATH10K_DBG_MAC,
2297 "mac vdev %d beacon_interval %d\n",
2298 arvif->vdev_id, arvif->beacon_interval);
2299
Kalle Valo5e3dd152013-06-12 20:52:10 +03002300 if (ret)
2301 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2302 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303 }
2304
2305 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002306 ath10k_dbg(ATH10K_DBG_MAC,
2307 "vdev %d set beacon tx mode to staggered\n",
2308 arvif->vdev_id);
2309
Bartosz Markowski226a3392013-09-26 17:47:16 +02002310 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2311 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002312 WMI_BEACON_STAGGERED_MODE);
2313 if (ret)
2314 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2315 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002316 }
2317
John W. Linvilleb70727e2013-06-13 13:34:29 -04002318 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319 arvif->dtim_period = info->dtim_period;
2320
Kalle Valo60c3daa2013-09-08 17:56:07 +03002321 ath10k_dbg(ATH10K_DBG_MAC,
2322 "mac vdev %d dtim_period %d\n",
2323 arvif->vdev_id, arvif->dtim_period);
2324
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002325 vdev_param = ar->wmi.vdev_param->dtim_period;
2326 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327 arvif->dtim_period);
2328 if (ret)
2329 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2330 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 }
2332
2333 if (changed & BSS_CHANGED_SSID &&
2334 vif->type == NL80211_IFTYPE_AP) {
2335 arvif->u.ap.ssid_len = info->ssid_len;
2336 if (info->ssid_len)
2337 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2338 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2339 }
2340
2341 if (changed & BSS_CHANGED_BSSID) {
2342 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002343 ath10k_dbg(ATH10K_DBG_MAC,
2344 "mac vdev %d create peer %pM\n",
2345 arvif->vdev_id, info->bssid);
2346
Kalle Valo5e3dd152013-06-12 20:52:10 +03002347 ret = ath10k_peer_create(ar, arvif->vdev_id,
2348 info->bssid);
2349 if (ret)
2350 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2351 info->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002352
2353 if (vif->type == NL80211_IFTYPE_STATION) {
2354 /*
2355 * this is never erased as we it for crypto key
2356 * clearing; this is FW requirement
2357 */
2358 memcpy(arvif->u.sta.bssid, info->bssid,
2359 ETH_ALEN);
2360
Kalle Valo60c3daa2013-09-08 17:56:07 +03002361 ath10k_dbg(ATH10K_DBG_MAC,
2362 "mac vdev %d start %pM\n",
2363 arvif->vdev_id, info->bssid);
2364
2365 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002367 }
2368
2369 /*
2370 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2371 * so driver need to store it. It is needed when leaving
2372 * IBSS in order to remove BSSID peer.
2373 */
2374 if (vif->type == NL80211_IFTYPE_ADHOC)
2375 memcpy(arvif->u.ibss.bssid, info->bssid,
2376 ETH_ALEN);
2377 }
2378 }
2379
2380 if (changed & BSS_CHANGED_BEACON_ENABLED)
2381 ath10k_control_beaconing(arvif, info);
2382
2383 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2384 u32 cts_prot;
2385 if (info->use_cts_prot)
2386 cts_prot = 1;
2387 else
2388 cts_prot = 0;
2389
Kalle Valo60c3daa2013-09-08 17:56:07 +03002390 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2391 arvif->vdev_id, cts_prot);
2392
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002393 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2394 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395 cts_prot);
2396 if (ret)
2397 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2398 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002399 }
2400
2401 if (changed & BSS_CHANGED_ERP_SLOT) {
2402 u32 slottime;
2403 if (info->use_short_slot)
2404 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2405
2406 else
2407 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2408
Kalle Valo60c3daa2013-09-08 17:56:07 +03002409 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2410 arvif->vdev_id, slottime);
2411
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002412 vdev_param = ar->wmi.vdev_param->slot_time;
2413 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002414 slottime);
2415 if (ret)
2416 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2417 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418 }
2419
2420 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2421 u32 preamble;
2422 if (info->use_short_preamble)
2423 preamble = WMI_VDEV_PREAMBLE_SHORT;
2424 else
2425 preamble = WMI_VDEV_PREAMBLE_LONG;
2426
Kalle Valo60c3daa2013-09-08 17:56:07 +03002427 ath10k_dbg(ATH10K_DBG_MAC,
2428 "mac vdev %d preamble %dn",
2429 arvif->vdev_id, preamble);
2430
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002431 vdev_param = ar->wmi.vdev_param->preamble;
2432 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002433 preamble);
2434 if (ret)
2435 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2436 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002437 }
2438
2439 if (changed & BSS_CHANGED_ASSOC) {
2440 if (info->assoc)
2441 ath10k_bss_assoc(hw, vif, info);
2442 }
2443
2444 mutex_unlock(&ar->conf_mutex);
2445}
2446
2447static int ath10k_hw_scan(struct ieee80211_hw *hw,
2448 struct ieee80211_vif *vif,
2449 struct cfg80211_scan_request *req)
2450{
2451 struct ath10k *ar = hw->priv;
2452 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2453 struct wmi_start_scan_arg arg;
2454 int ret = 0;
2455 int i;
2456
2457 mutex_lock(&ar->conf_mutex);
2458
2459 spin_lock_bh(&ar->data_lock);
2460 if (ar->scan.in_progress) {
2461 spin_unlock_bh(&ar->data_lock);
2462 ret = -EBUSY;
2463 goto exit;
2464 }
2465
2466 INIT_COMPLETION(ar->scan.started);
2467 INIT_COMPLETION(ar->scan.completed);
2468 ar->scan.in_progress = true;
2469 ar->scan.aborting = false;
2470 ar->scan.is_roc = false;
2471 ar->scan.vdev_id = arvif->vdev_id;
2472 spin_unlock_bh(&ar->data_lock);
2473
2474 memset(&arg, 0, sizeof(arg));
2475 ath10k_wmi_start_scan_init(ar, &arg);
2476 arg.vdev_id = arvif->vdev_id;
2477 arg.scan_id = ATH10K_SCAN_ID;
2478
2479 if (!req->no_cck)
2480 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2481
2482 if (req->ie_len) {
2483 arg.ie_len = req->ie_len;
2484 memcpy(arg.ie, req->ie, arg.ie_len);
2485 }
2486
2487 if (req->n_ssids) {
2488 arg.n_ssids = req->n_ssids;
2489 for (i = 0; i < arg.n_ssids; i++) {
2490 arg.ssids[i].len = req->ssids[i].ssid_len;
2491 arg.ssids[i].ssid = req->ssids[i].ssid;
2492 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002493 } else {
2494 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495 }
2496
2497 if (req->n_channels) {
2498 arg.n_channels = req->n_channels;
2499 for (i = 0; i < arg.n_channels; i++)
2500 arg.channels[i] = req->channels[i]->center_freq;
2501 }
2502
2503 ret = ath10k_start_scan(ar, &arg);
2504 if (ret) {
2505 ath10k_warn("could not start hw scan (%d)\n", ret);
2506 spin_lock_bh(&ar->data_lock);
2507 ar->scan.in_progress = false;
2508 spin_unlock_bh(&ar->data_lock);
2509 }
2510
2511exit:
2512 mutex_unlock(&ar->conf_mutex);
2513 return ret;
2514}
2515
2516static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2517 struct ieee80211_vif *vif)
2518{
2519 struct ath10k *ar = hw->priv;
2520 int ret;
2521
2522 mutex_lock(&ar->conf_mutex);
2523 ret = ath10k_abort_scan(ar);
2524 if (ret) {
2525 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2526 ret);
2527 ieee80211_scan_completed(hw, 1 /* aborted */);
2528 }
2529 mutex_unlock(&ar->conf_mutex);
2530}
2531
2532static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2533 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2534 struct ieee80211_key_conf *key)
2535{
2536 struct ath10k *ar = hw->priv;
2537 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2538 struct ath10k_peer *peer;
2539 const u8 *peer_addr;
2540 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2541 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2542 int ret = 0;
2543
2544 if (key->keyidx > WMI_MAX_KEY_INDEX)
2545 return -ENOSPC;
2546
2547 mutex_lock(&ar->conf_mutex);
2548
2549 if (sta)
2550 peer_addr = sta->addr;
2551 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2552 peer_addr = vif->bss_conf.bssid;
2553 else
2554 peer_addr = vif->addr;
2555
2556 key->hw_key_idx = key->keyidx;
2557
2558 /* the peer should not disappear in mid-way (unless FW goes awry) since
2559 * we already hold conf_mutex. we just make sure its there now. */
2560 spin_lock_bh(&ar->data_lock);
2561 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2562 spin_unlock_bh(&ar->data_lock);
2563
2564 if (!peer) {
2565 if (cmd == SET_KEY) {
2566 ath10k_warn("cannot install key for non-existent peer %pM\n",
2567 peer_addr);
2568 ret = -EOPNOTSUPP;
2569 goto exit;
2570 } else {
2571 /* if the peer doesn't exist there is no key to disable
2572 * anymore */
2573 goto exit;
2574 }
2575 }
2576
2577 if (is_wep) {
2578 if (cmd == SET_KEY)
2579 arvif->wep_keys[key->keyidx] = key;
2580 else
2581 arvif->wep_keys[key->keyidx] = NULL;
2582
2583 if (cmd == DISABLE_KEY)
2584 ath10k_clear_vdev_key(arvif, key);
2585 }
2586
2587 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2588 if (ret) {
2589 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2590 goto exit;
2591 }
2592
2593 spin_lock_bh(&ar->data_lock);
2594 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2595 if (peer && cmd == SET_KEY)
2596 peer->keys[key->keyidx] = key;
2597 else if (peer && cmd == DISABLE_KEY)
2598 peer->keys[key->keyidx] = NULL;
2599 else if (peer == NULL)
2600 /* impossible unless FW goes crazy */
2601 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2602 spin_unlock_bh(&ar->data_lock);
2603
2604exit:
2605 mutex_unlock(&ar->conf_mutex);
2606 return ret;
2607}
2608
2609static int ath10k_sta_state(struct ieee80211_hw *hw,
2610 struct ieee80211_vif *vif,
2611 struct ieee80211_sta *sta,
2612 enum ieee80211_sta_state old_state,
2613 enum ieee80211_sta_state new_state)
2614{
2615 struct ath10k *ar = hw->priv;
2616 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2617 int ret = 0;
2618
2619 mutex_lock(&ar->conf_mutex);
2620
2621 if (old_state == IEEE80211_STA_NOTEXIST &&
2622 new_state == IEEE80211_STA_NONE &&
2623 vif->type != NL80211_IFTYPE_STATION) {
2624 /*
2625 * New station addition.
2626 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002627 ath10k_dbg(ATH10K_DBG_MAC,
2628 "mac vdev %d peer create %pM (new sta)\n",
2629 arvif->vdev_id, sta->addr);
2630
Kalle Valo5e3dd152013-06-12 20:52:10 +03002631 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2632 if (ret)
2633 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2634 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002635 } else if ((old_state == IEEE80211_STA_NONE &&
2636 new_state == IEEE80211_STA_NOTEXIST)) {
2637 /*
2638 * Existing station deletion.
2639 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002640 ath10k_dbg(ATH10K_DBG_MAC,
2641 "mac vdev %d peer delete %pM (sta gone)\n",
2642 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002643 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2644 if (ret)
2645 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2646 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002647
2648 if (vif->type == NL80211_IFTYPE_STATION)
2649 ath10k_bss_disassoc(hw, vif);
2650 } else if (old_state == IEEE80211_STA_AUTH &&
2651 new_state == IEEE80211_STA_ASSOC &&
2652 (vif->type == NL80211_IFTYPE_AP ||
2653 vif->type == NL80211_IFTYPE_ADHOC)) {
2654 /*
2655 * New association.
2656 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002657 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2658 sta->addr);
2659
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660 ret = ath10k_station_assoc(ar, arvif, sta);
2661 if (ret)
2662 ath10k_warn("Failed to associate station: %pM\n",
2663 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002664 } else if (old_state == IEEE80211_STA_ASSOC &&
2665 new_state == IEEE80211_STA_AUTH &&
2666 (vif->type == NL80211_IFTYPE_AP ||
2667 vif->type == NL80211_IFTYPE_ADHOC)) {
2668 /*
2669 * Disassociation.
2670 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002671 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2672 sta->addr);
2673
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674 ret = ath10k_station_disassoc(ar, arvif, sta);
2675 if (ret)
2676 ath10k_warn("Failed to disassociate station: %pM\n",
2677 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002678 }
2679
2680 mutex_unlock(&ar->conf_mutex);
2681 return ret;
2682}
2683
2684static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2685 u16 ac, bool enable)
2686{
2687 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2688 u32 value = 0;
2689 int ret = 0;
2690
Michal Kazior548db542013-07-05 16:15:15 +03002691 lockdep_assert_held(&ar->conf_mutex);
2692
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2694 return 0;
2695
2696 switch (ac) {
2697 case IEEE80211_AC_VO:
2698 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2699 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2700 break;
2701 case IEEE80211_AC_VI:
2702 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2703 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2704 break;
2705 case IEEE80211_AC_BE:
2706 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2707 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2708 break;
2709 case IEEE80211_AC_BK:
2710 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2711 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2712 break;
2713 }
2714
2715 if (enable)
2716 arvif->u.sta.uapsd |= value;
2717 else
2718 arvif->u.sta.uapsd &= ~value;
2719
2720 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2721 WMI_STA_PS_PARAM_UAPSD,
2722 arvif->u.sta.uapsd);
2723 if (ret) {
2724 ath10k_warn("could not set uapsd params %d\n", ret);
2725 goto exit;
2726 }
2727
2728 if (arvif->u.sta.uapsd)
2729 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2730 else
2731 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2732
2733 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2734 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2735 value);
2736 if (ret)
2737 ath10k_warn("could not set rx wake param %d\n", ret);
2738
2739exit:
2740 return ret;
2741}
2742
2743static int ath10k_conf_tx(struct ieee80211_hw *hw,
2744 struct ieee80211_vif *vif, u16 ac,
2745 const struct ieee80211_tx_queue_params *params)
2746{
2747 struct ath10k *ar = hw->priv;
2748 struct wmi_wmm_params_arg *p = NULL;
2749 int ret;
2750
2751 mutex_lock(&ar->conf_mutex);
2752
2753 switch (ac) {
2754 case IEEE80211_AC_VO:
2755 p = &ar->wmm_params.ac_vo;
2756 break;
2757 case IEEE80211_AC_VI:
2758 p = &ar->wmm_params.ac_vi;
2759 break;
2760 case IEEE80211_AC_BE:
2761 p = &ar->wmm_params.ac_be;
2762 break;
2763 case IEEE80211_AC_BK:
2764 p = &ar->wmm_params.ac_bk;
2765 break;
2766 }
2767
2768 if (WARN_ON(!p)) {
2769 ret = -EINVAL;
2770 goto exit;
2771 }
2772
2773 p->cwmin = params->cw_min;
2774 p->cwmax = params->cw_max;
2775 p->aifs = params->aifs;
2776
2777 /*
2778 * The channel time duration programmed in the HW is in absolute
2779 * microseconds, while mac80211 gives the txop in units of
2780 * 32 microseconds.
2781 */
2782 p->txop = params->txop * 32;
2783
2784 /* FIXME: FW accepts wmm params per hw, not per vif */
2785 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2786 if (ret) {
2787 ath10k_warn("could not set wmm params %d\n", ret);
2788 goto exit;
2789 }
2790
2791 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2792 if (ret)
2793 ath10k_warn("could not set sta uapsd %d\n", ret);
2794
2795exit:
2796 mutex_unlock(&ar->conf_mutex);
2797 return ret;
2798}
2799
2800#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2801
2802static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2803 struct ieee80211_vif *vif,
2804 struct ieee80211_channel *chan,
2805 int duration,
2806 enum ieee80211_roc_type type)
2807{
2808 struct ath10k *ar = hw->priv;
2809 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2810 struct wmi_start_scan_arg arg;
2811 int ret;
2812
2813 mutex_lock(&ar->conf_mutex);
2814
2815 spin_lock_bh(&ar->data_lock);
2816 if (ar->scan.in_progress) {
2817 spin_unlock_bh(&ar->data_lock);
2818 ret = -EBUSY;
2819 goto exit;
2820 }
2821
2822 INIT_COMPLETION(ar->scan.started);
2823 INIT_COMPLETION(ar->scan.completed);
2824 INIT_COMPLETION(ar->scan.on_channel);
2825 ar->scan.in_progress = true;
2826 ar->scan.aborting = false;
2827 ar->scan.is_roc = true;
2828 ar->scan.vdev_id = arvif->vdev_id;
2829 ar->scan.roc_freq = chan->center_freq;
2830 spin_unlock_bh(&ar->data_lock);
2831
2832 memset(&arg, 0, sizeof(arg));
2833 ath10k_wmi_start_scan_init(ar, &arg);
2834 arg.vdev_id = arvif->vdev_id;
2835 arg.scan_id = ATH10K_SCAN_ID;
2836 arg.n_channels = 1;
2837 arg.channels[0] = chan->center_freq;
2838 arg.dwell_time_active = duration;
2839 arg.dwell_time_passive = duration;
2840 arg.max_scan_time = 2 * duration;
2841 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2842 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2843
2844 ret = ath10k_start_scan(ar, &arg);
2845 if (ret) {
2846 ath10k_warn("could not start roc scan (%d)\n", ret);
2847 spin_lock_bh(&ar->data_lock);
2848 ar->scan.in_progress = false;
2849 spin_unlock_bh(&ar->data_lock);
2850 goto exit;
2851 }
2852
2853 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2854 if (ret == 0) {
2855 ath10k_warn("could not switch to channel for roc scan\n");
2856 ath10k_abort_scan(ar);
2857 ret = -ETIMEDOUT;
2858 goto exit;
2859 }
2860
2861 ret = 0;
2862exit:
2863 mutex_unlock(&ar->conf_mutex);
2864 return ret;
2865}
2866
2867static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2868{
2869 struct ath10k *ar = hw->priv;
2870
2871 mutex_lock(&ar->conf_mutex);
2872 ath10k_abort_scan(ar);
2873 mutex_unlock(&ar->conf_mutex);
2874
2875 return 0;
2876}
2877
2878/*
2879 * Both RTS and Fragmentation threshold are interface-specific
2880 * in ath10k, but device-specific in mac80211.
2881 */
2882static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2883{
2884 struct ath10k_generic_iter *ar_iter = data;
2885 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2886 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2887
Michal Kazior548db542013-07-05 16:15:15 +03002888 lockdep_assert_held(&arvif->ar->conf_mutex);
2889
Michal Kazioraffd3212013-07-16 09:54:35 +02002890 /* During HW reconfiguration mac80211 reports all interfaces that were
2891 * running until reconfiguration was started. Since FW doesn't have any
2892 * vdevs at this point we must not iterate over this interface list.
2893 * This setting will be updated upon add_interface(). */
2894 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2895 return;
2896
Kalle Valo60c3daa2013-09-08 17:56:07 +03002897 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2898 arvif->vdev_id, rts);
2899
Michal Kazior424121c2013-07-22 14:13:31 +02002900 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901 if (ar_iter->ret)
2902 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2903 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904}
2905
2906static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2907{
2908 struct ath10k_generic_iter ar_iter;
2909 struct ath10k *ar = hw->priv;
2910
2911 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2912 ar_iter.ar = ar;
2913
2914 mutex_lock(&ar->conf_mutex);
Michal Kazior80c78c62013-07-05 16:15:03 +03002915 ieee80211_iterate_active_interfaces_atomic(
Michal Kazior671b96d2013-07-05 16:15:05 +03002916 hw, IEEE80211_IFACE_ITER_NORMAL,
Michal Kazior80c78c62013-07-05 16:15:03 +03002917 ath10k_set_rts_iter, &ar_iter);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918 mutex_unlock(&ar->conf_mutex);
2919
2920 return ar_iter.ret;
2921}
2922
2923static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2924{
2925 struct ath10k_generic_iter *ar_iter = data;
2926 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2927 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928
Michal Kazior548db542013-07-05 16:15:15 +03002929 lockdep_assert_held(&arvif->ar->conf_mutex);
2930
Michal Kazioraffd3212013-07-16 09:54:35 +02002931 /* During HW reconfiguration mac80211 reports all interfaces that were
2932 * running until reconfiguration was started. Since FW doesn't have any
2933 * vdevs at this point we must not iterate over this interface list.
2934 * This setting will be updated upon add_interface(). */
2935 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2936 return;
2937
Kalle Valo60c3daa2013-09-08 17:56:07 +03002938 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2939 arvif->vdev_id, frag);
2940
Michal Kazior424121c2013-07-22 14:13:31 +02002941 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942 if (ar_iter->ret)
2943 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2944 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002945}
2946
2947static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2948{
2949 struct ath10k_generic_iter ar_iter;
2950 struct ath10k *ar = hw->priv;
2951
2952 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2953 ar_iter.ar = ar;
2954
2955 mutex_lock(&ar->conf_mutex);
Michal Kazior80c78c62013-07-05 16:15:03 +03002956 ieee80211_iterate_active_interfaces_atomic(
Michal Kazior671b96d2013-07-05 16:15:05 +03002957 hw, IEEE80211_IFACE_ITER_NORMAL,
Michal Kazior80c78c62013-07-05 16:15:03 +03002958 ath10k_set_frag_iter, &ar_iter);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002959 mutex_unlock(&ar->conf_mutex);
2960
2961 return ar_iter.ret;
2962}
2963
2964static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2965{
2966 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02002967 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968 int ret;
2969
2970 /* mac80211 doesn't care if we really xmit queued frames or not
2971 * we'll collect those frames either way if we stop/delete vdevs */
2972 if (drop)
2973 return;
2974
Michal Kazior548db542013-07-05 16:15:15 +03002975 mutex_lock(&ar->conf_mutex);
2976
Michal Kazioraffd3212013-07-16 09:54:35 +02002977 if (ar->state == ATH10K_STATE_WEDGED)
2978 goto skip;
2979
Michal Kazioredb82362013-07-05 16:15:14 +03002980 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03002981 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02002982
Michal Kazioredb82362013-07-05 16:15:14 +03002983 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02002984 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03002985 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02002986
2987 skip = (ar->state == ATH10K_STATE_WEDGED);
2988
2989 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002990 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02002991
2992 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002993 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03002994
Michal Kazioraffd3212013-07-16 09:54:35 +02002995skip:
Michal Kazior548db542013-07-05 16:15:15 +03002996 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002997}
2998
2999/* TODO: Implement this function properly
3000 * For now it is needed to reply to Probe Requests in IBSS mode.
3001 * Propably we need this information from FW.
3002 */
3003static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3004{
3005 return 1;
3006}
3007
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003008#ifdef CONFIG_PM
3009static int ath10k_suspend(struct ieee80211_hw *hw,
3010 struct cfg80211_wowlan *wowlan)
3011{
3012 struct ath10k *ar = hw->priv;
3013 int ret;
3014
3015 ar->is_target_paused = false;
3016
3017 ret = ath10k_wmi_pdev_suspend_target(ar);
3018 if (ret) {
3019 ath10k_warn("could not suspend target (%d)\n", ret);
3020 return 1;
3021 }
3022
3023 ret = wait_event_interruptible_timeout(ar->event_queue,
3024 ar->is_target_paused == true,
3025 1 * HZ);
3026 if (ret < 0) {
3027 ath10k_warn("suspend interrupted (%d)\n", ret);
3028 goto resume;
3029 } else if (ret == 0) {
3030 ath10k_warn("suspend timed out - target pause event never came\n");
3031 goto resume;
3032 }
3033
3034 ret = ath10k_hif_suspend(ar);
3035 if (ret) {
3036 ath10k_warn("could not suspend hif (%d)\n", ret);
3037 goto resume;
3038 }
3039
3040 return 0;
3041resume:
3042 ret = ath10k_wmi_pdev_resume_target(ar);
3043 if (ret)
3044 ath10k_warn("could not resume target (%d)\n", ret);
3045 return 1;
3046}
3047
3048static int ath10k_resume(struct ieee80211_hw *hw)
3049{
3050 struct ath10k *ar = hw->priv;
3051 int ret;
3052
3053 ret = ath10k_hif_resume(ar);
3054 if (ret) {
3055 ath10k_warn("could not resume hif (%d)\n", ret);
3056 return 1;
3057 }
3058
3059 ret = ath10k_wmi_pdev_resume_target(ar);
3060 if (ret) {
3061 ath10k_warn("could not resume target (%d)\n", ret);
3062 return 1;
3063 }
3064
3065 return 0;
3066}
3067#endif
3068
Michal Kazioraffd3212013-07-16 09:54:35 +02003069static void ath10k_restart_complete(struct ieee80211_hw *hw)
3070{
3071 struct ath10k *ar = hw->priv;
3072
3073 mutex_lock(&ar->conf_mutex);
3074
3075 /* If device failed to restart it will be in a different state, e.g.
3076 * ATH10K_STATE_WEDGED */
3077 if (ar->state == ATH10K_STATE_RESTARTED) {
3078 ath10k_info("device successfully recovered\n");
3079 ar->state = ATH10K_STATE_ON;
3080 }
3081
3082 mutex_unlock(&ar->conf_mutex);
3083}
3084
Michal Kazior2e1dea42013-07-31 10:32:40 +02003085static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3086 struct survey_info *survey)
3087{
3088 struct ath10k *ar = hw->priv;
3089 struct ieee80211_supported_band *sband;
3090 struct survey_info *ar_survey = &ar->survey[idx];
3091 int ret = 0;
3092
3093 mutex_lock(&ar->conf_mutex);
3094
3095 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3096 if (sband && idx >= sband->n_channels) {
3097 idx -= sband->n_channels;
3098 sband = NULL;
3099 }
3100
3101 if (!sband)
3102 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3103
3104 if (!sband || idx >= sband->n_channels) {
3105 ret = -ENOENT;
3106 goto exit;
3107 }
3108
3109 spin_lock_bh(&ar->data_lock);
3110 memcpy(survey, ar_survey, sizeof(*survey));
3111 spin_unlock_bh(&ar->data_lock);
3112
3113 survey->channel = &sband->channels[idx];
3114
3115exit:
3116 mutex_unlock(&ar->conf_mutex);
3117 return ret;
3118}
3119
Kalle Valo5e3dd152013-06-12 20:52:10 +03003120static const struct ieee80211_ops ath10k_ops = {
3121 .tx = ath10k_tx,
3122 .start = ath10k_start,
3123 .stop = ath10k_stop,
3124 .config = ath10k_config,
3125 .add_interface = ath10k_add_interface,
3126 .remove_interface = ath10k_remove_interface,
3127 .configure_filter = ath10k_configure_filter,
3128 .bss_info_changed = ath10k_bss_info_changed,
3129 .hw_scan = ath10k_hw_scan,
3130 .cancel_hw_scan = ath10k_cancel_hw_scan,
3131 .set_key = ath10k_set_key,
3132 .sta_state = ath10k_sta_state,
3133 .conf_tx = ath10k_conf_tx,
3134 .remain_on_channel = ath10k_remain_on_channel,
3135 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3136 .set_rts_threshold = ath10k_set_rts_threshold,
3137 .set_frag_threshold = ath10k_set_frag_threshold,
3138 .flush = ath10k_flush,
3139 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003140 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003141 .get_survey = ath10k_get_survey,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003142#ifdef CONFIG_PM
3143 .suspend = ath10k_suspend,
3144 .resume = ath10k_resume,
3145#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146};
3147
3148#define RATETAB_ENT(_rate, _rateid, _flags) { \
3149 .bitrate = (_rate), \
3150 .flags = (_flags), \
3151 .hw_value = (_rateid), \
3152}
3153
3154#define CHAN2G(_channel, _freq, _flags) { \
3155 .band = IEEE80211_BAND_2GHZ, \
3156 .hw_value = (_channel), \
3157 .center_freq = (_freq), \
3158 .flags = (_flags), \
3159 .max_antenna_gain = 0, \
3160 .max_power = 30, \
3161}
3162
3163#define CHAN5G(_channel, _freq, _flags) { \
3164 .band = IEEE80211_BAND_5GHZ, \
3165 .hw_value = (_channel), \
3166 .center_freq = (_freq), \
3167 .flags = (_flags), \
3168 .max_antenna_gain = 0, \
3169 .max_power = 30, \
3170}
3171
3172static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3173 CHAN2G(1, 2412, 0),
3174 CHAN2G(2, 2417, 0),
3175 CHAN2G(3, 2422, 0),
3176 CHAN2G(4, 2427, 0),
3177 CHAN2G(5, 2432, 0),
3178 CHAN2G(6, 2437, 0),
3179 CHAN2G(7, 2442, 0),
3180 CHAN2G(8, 2447, 0),
3181 CHAN2G(9, 2452, 0),
3182 CHAN2G(10, 2457, 0),
3183 CHAN2G(11, 2462, 0),
3184 CHAN2G(12, 2467, 0),
3185 CHAN2G(13, 2472, 0),
3186 CHAN2G(14, 2484, 0),
3187};
3188
3189static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003190 CHAN5G(36, 5180, 0),
3191 CHAN5G(40, 5200, 0),
3192 CHAN5G(44, 5220, 0),
3193 CHAN5G(48, 5240, 0),
3194 CHAN5G(52, 5260, 0),
3195 CHAN5G(56, 5280, 0),
3196 CHAN5G(60, 5300, 0),
3197 CHAN5G(64, 5320, 0),
3198 CHAN5G(100, 5500, 0),
3199 CHAN5G(104, 5520, 0),
3200 CHAN5G(108, 5540, 0),
3201 CHAN5G(112, 5560, 0),
3202 CHAN5G(116, 5580, 0),
3203 CHAN5G(120, 5600, 0),
3204 CHAN5G(124, 5620, 0),
3205 CHAN5G(128, 5640, 0),
3206 CHAN5G(132, 5660, 0),
3207 CHAN5G(136, 5680, 0),
3208 CHAN5G(140, 5700, 0),
3209 CHAN5G(149, 5745, 0),
3210 CHAN5G(153, 5765, 0),
3211 CHAN5G(157, 5785, 0),
3212 CHAN5G(161, 5805, 0),
3213 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003214};
3215
3216static struct ieee80211_rate ath10k_rates[] = {
3217 /* CCK */
3218 RATETAB_ENT(10, 0x82, 0),
3219 RATETAB_ENT(20, 0x84, 0),
3220 RATETAB_ENT(55, 0x8b, 0),
3221 RATETAB_ENT(110, 0x96, 0),
3222 /* OFDM */
3223 RATETAB_ENT(60, 0x0c, 0),
3224 RATETAB_ENT(90, 0x12, 0),
3225 RATETAB_ENT(120, 0x18, 0),
3226 RATETAB_ENT(180, 0x24, 0),
3227 RATETAB_ENT(240, 0x30, 0),
3228 RATETAB_ENT(360, 0x48, 0),
3229 RATETAB_ENT(480, 0x60, 0),
3230 RATETAB_ENT(540, 0x6c, 0),
3231};
3232
3233#define ath10k_a_rates (ath10k_rates + 4)
3234#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3235#define ath10k_g_rates (ath10k_rates + 0)
3236#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3237
3238struct ath10k *ath10k_mac_create(void)
3239{
3240 struct ieee80211_hw *hw;
3241 struct ath10k *ar;
3242
3243 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3244 if (!hw)
3245 return NULL;
3246
3247 ar = hw->priv;
3248 ar->hw = hw;
3249
3250 return ar;
3251}
3252
3253void ath10k_mac_destroy(struct ath10k *ar)
3254{
3255 ieee80211_free_hw(ar->hw);
3256}
3257
3258static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3259 {
3260 .max = 8,
3261 .types = BIT(NL80211_IFTYPE_STATION)
3262 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003263 },
3264 {
3265 .max = 3,
3266 .types = BIT(NL80211_IFTYPE_P2P_GO)
3267 },
3268 {
3269 .max = 7,
3270 .types = BIT(NL80211_IFTYPE_AP)
3271 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272};
3273
3274static const struct ieee80211_iface_combination ath10k_if_comb = {
3275 .limits = ath10k_if_limits,
3276 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3277 .max_interfaces = 8,
3278 .num_different_channels = 1,
3279 .beacon_int_infra_match = true,
3280};
3281
3282static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3283{
3284 struct ieee80211_sta_vht_cap vht_cap = {0};
3285 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003286 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003287
3288 vht_cap.vht_supported = 1;
3289 vht_cap.cap = ar->vht_cap_info;
3290
Michal Kazior8865bee42013-07-24 12:36:46 +02003291 mcs_map = 0;
3292 for (i = 0; i < 8; i++) {
3293 if (i < ar->num_rf_chains)
3294 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3295 else
3296 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3297 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003298
3299 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3300 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3301
3302 return vht_cap;
3303}
3304
3305static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3306{
3307 int i;
3308 struct ieee80211_sta_ht_cap ht_cap = {0};
3309
3310 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3311 return ht_cap;
3312
3313 ht_cap.ht_supported = 1;
3314 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3315 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3316 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3317 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3318 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3319
3320 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3321 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3322
3323 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3324 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3325
3326 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3327 u32 smps;
3328
3329 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3330 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3331
3332 ht_cap.cap |= smps;
3333 }
3334
3335 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3336 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3337
3338 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3339 u32 stbc;
3340
3341 stbc = ar->ht_cap_info;
3342 stbc &= WMI_HT_CAP_RX_STBC;
3343 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3344 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3345 stbc &= IEEE80211_HT_CAP_RX_STBC;
3346
3347 ht_cap.cap |= stbc;
3348 }
3349
3350 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3351 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3352
3353 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3354 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3355
3356 /* max AMSDU is implicitly taken from vht_cap_info */
3357 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3358 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3359
Michal Kazior8865bee42013-07-24 12:36:46 +02003360 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003361 ht_cap.mcs.rx_mask[i] = 0xFF;
3362
3363 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3364
3365 return ht_cap;
3366}
3367
3368
3369static void ath10k_get_arvif_iter(void *data, u8 *mac,
3370 struct ieee80211_vif *vif)
3371{
3372 struct ath10k_vif_iter *arvif_iter = data;
3373 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3374
3375 if (arvif->vdev_id == arvif_iter->vdev_id)
3376 arvif_iter->arvif = arvif;
3377}
3378
3379struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3380{
3381 struct ath10k_vif_iter arvif_iter;
3382 u32 flags;
3383
3384 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3385 arvif_iter.vdev_id = vdev_id;
3386
3387 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3388 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3389 flags,
3390 ath10k_get_arvif_iter,
3391 &arvif_iter);
3392 if (!arvif_iter.arvif) {
3393 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3394 return NULL;
3395 }
3396
3397 return arvif_iter.arvif;
3398}
3399
3400int ath10k_mac_register(struct ath10k *ar)
3401{
3402 struct ieee80211_supported_band *band;
3403 struct ieee80211_sta_vht_cap vht_cap;
3404 struct ieee80211_sta_ht_cap ht_cap;
3405 void *channels;
3406 int ret;
3407
3408 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3409
3410 SET_IEEE80211_DEV(ar->hw, ar->dev);
3411
3412 ht_cap = ath10k_get_ht_cap(ar);
3413 vht_cap = ath10k_create_vht_cap(ar);
3414
3415 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3416 channels = kmemdup(ath10k_2ghz_channels,
3417 sizeof(ath10k_2ghz_channels),
3418 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02003419 if (!channels) {
3420 ret = -ENOMEM;
3421 goto err_free;
3422 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003423
3424 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3425 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3426 band->channels = channels;
3427 band->n_bitrates = ath10k_g_rates_size;
3428 band->bitrates = ath10k_g_rates;
3429 band->ht_cap = ht_cap;
3430
3431 /* vht is not supported in 2.4 GHz */
3432
3433 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3434 }
3435
3436 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3437 channels = kmemdup(ath10k_5ghz_channels,
3438 sizeof(ath10k_5ghz_channels),
3439 GFP_KERNEL);
3440 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02003441 ret = -ENOMEM;
3442 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003443 }
3444
3445 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3446 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3447 band->channels = channels;
3448 band->n_bitrates = ath10k_a_rates_size;
3449 band->bitrates = ath10k_a_rates;
3450 band->ht_cap = ht_cap;
3451 band->vht_cap = vht_cap;
3452 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3453 }
3454
3455 ar->hw->wiphy->interface_modes =
3456 BIT(NL80211_IFTYPE_STATION) |
3457 BIT(NL80211_IFTYPE_ADHOC) |
3458 BIT(NL80211_IFTYPE_AP) |
3459 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3460 BIT(NL80211_IFTYPE_P2P_GO);
3461
3462 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3463 IEEE80211_HW_SUPPORTS_PS |
3464 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3465 IEEE80211_HW_SUPPORTS_UAPSD |
3466 IEEE80211_HW_MFP_CAPABLE |
3467 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3468 IEEE80211_HW_HAS_RATE_CONTROL |
3469 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3470 IEEE80211_HW_WANT_MONITOR_VIF |
3471 IEEE80211_HW_AP_LINK_PS;
3472
Michal Kazior1f8bb152013-09-18 14:43:22 +02003473 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3474 * bytes is used for padding/alignment if necessary. */
3475 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3476
Kalle Valo5e3dd152013-06-12 20:52:10 +03003477 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3478 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3479
3480 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3481 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3482 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3483 }
3484
3485 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3486 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3487
3488 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3489
3490 ar->hw->channel_change_time = 5000;
3491 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3492
3493 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3494 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3495
3496 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3497 /*
3498 * on LL hardware queues are managed entirely by the FW
3499 * so we only advertise to mac we can do the queues thing
3500 */
3501 ar->hw->queues = 4;
3502
3503 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3504 ar->hw->wiphy->n_iface_combinations = 1;
3505
Michal Kazior7c199992013-07-31 10:47:57 +02003506 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3507
Kalle Valo5e3dd152013-06-12 20:52:10 +03003508 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3509 ath10k_reg_notifier);
3510 if (ret) {
3511 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02003512 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 }
3514
3515 ret = ieee80211_register_hw(ar->hw);
3516 if (ret) {
3517 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02003518 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003519 }
3520
3521 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3522 ret = regulatory_hint(ar->hw->wiphy,
3523 ar->ath_common.regulatory.alpha2);
3524 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02003525 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003526 }
3527
3528 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02003529
3530err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003531 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02003532err_free:
3533 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3534 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3535
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536 return ret;
3537}
3538
3539void ath10k_mac_unregister(struct ath10k *ar)
3540{
3541 ieee80211_unregister_hw(ar->hw);
3542
3543 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3544 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3545
3546 SET_IEEE80211_DEV(ar->hw, NULL);
3547}