blob: 2a4e7aa4611a44a051ec156f9c3f4d502ee3e439 [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
Wolfram Sang16735d02013-11-14 14:32:02 -080095 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030096
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);
Ben Greear479398b2013-11-04 09:19:34 -0800325 if (ret) {
326 ath10k_warn("Failed to create wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300329
330 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800331 if (ret) {
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 return 0;
337}
338
Michal Kazior424121c2013-07-22 14:13:31 +0200339static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
340{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200341 struct ath10k *ar = arvif->ar;
342 u32 vdev_param;
343
Michal Kazior424121c2013-07-22 14:13:31 +0200344 if (value != 0xFFFFFFFF)
345 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
346 ATH10K_RTS_MAX);
347
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200348 vdev_param = ar->wmi.vdev_param->rts_threshold;
349 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200350}
351
352static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
353{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200354 struct ath10k *ar = arvif->ar;
355 u32 vdev_param;
356
Michal Kazior424121c2013-07-22 14:13:31 +0200357 if (value != 0xFFFFFFFF)
358 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
359 ATH10K_FRAGMT_THRESHOLD_MIN,
360 ATH10K_FRAGMT_THRESHOLD_MAX);
361
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200362 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
363 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200364}
365
Kalle Valo5e3dd152013-06-12 20:52:10 +0300366static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
367{
368 int ret;
369
370 lockdep_assert_held(&ar->conf_mutex);
371
372 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
373 if (ret)
374 return ret;
375
376 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
377 if (ret)
378 return ret;
379
380 return 0;
381}
382
383static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
384{
385 struct ath10k_peer *peer, *tmp;
386
387 lockdep_assert_held(&ar->conf_mutex);
388
389 spin_lock_bh(&ar->data_lock);
390 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
391 if (peer->vdev_id != vdev_id)
392 continue;
393
394 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
395 peer->addr, vdev_id);
396
397 list_del(&peer->list);
398 kfree(peer);
399 }
400 spin_unlock_bh(&ar->data_lock);
401}
402
Michal Kaziora96d7742013-07-16 09:38:56 +0200403static void ath10k_peer_cleanup_all(struct ath10k *ar)
404{
405 struct ath10k_peer *peer, *tmp;
406
407 lockdep_assert_held(&ar->conf_mutex);
408
409 spin_lock_bh(&ar->data_lock);
410 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
411 list_del(&peer->list);
412 kfree(peer);
413 }
414 spin_unlock_bh(&ar->data_lock);
415}
416
Kalle Valo5e3dd152013-06-12 20:52:10 +0300417/************************/
418/* Interface management */
419/************************/
420
421static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
422{
423 int ret;
424
Michal Kazior548db542013-07-05 16:15:15 +0300425 lockdep_assert_held(&ar->conf_mutex);
426
Kalle Valo5e3dd152013-06-12 20:52:10 +0300427 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
428 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
429 if (ret == 0)
430 return -ETIMEDOUT;
431
432 return 0;
433}
434
435static int ath10k_vdev_start(struct ath10k_vif *arvif)
436{
437 struct ath10k *ar = arvif->ar;
438 struct ieee80211_conf *conf = &ar->hw->conf;
439 struct ieee80211_channel *channel = conf->chandef.chan;
440 struct wmi_vdev_start_request_arg arg = {};
441 int ret = 0;
442
443 lockdep_assert_held(&ar->conf_mutex);
444
Wolfram Sang16735d02013-11-14 14:32:02 -0800445 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300446
447 arg.vdev_id = arvif->vdev_id;
448 arg.dtim_period = arvif->dtim_period;
449 arg.bcn_intval = arvif->beacon_interval;
450
451 arg.channel.freq = channel->center_freq;
452
453 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
454
455 arg.channel.mode = chan_to_phymode(&conf->chandef);
456
Michal Kazior89c5c842013-10-23 04:02:13 -0700457 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700458 arg.channel.max_power = channel->max_power * 2;
459 arg.channel.max_reg_power = channel->max_reg_power * 2;
460 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300461
462 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
463 arg.ssid = arvif->u.ap.ssid;
464 arg.ssid_len = arvif->u.ap.ssid_len;
465 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200466
467 /* For now allow DFS for AP mode */
468 arg.channel.chan_radar =
469 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300470 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
471 arg.ssid = arvif->vif->bss_conf.ssid;
472 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
473 }
474
Kalle Valo38a1d472013-09-08 17:56:14 +0300475 ath10k_dbg(ATH10K_DBG_MAC,
476 "mac vdev %d start center_freq %d phymode %s\n",
477 arg.vdev_id, arg.channel.freq,
478 ath10k_wmi_phymode_str(arg.channel.mode));
479
Kalle Valo5e3dd152013-06-12 20:52:10 +0300480 ret = ath10k_wmi_vdev_start(ar, &arg);
481 if (ret) {
482 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
483 return ret;
484 }
485
486 ret = ath10k_vdev_setup_sync(ar);
487 if (ret) {
488 ath10k_warn("vdev setup failed %d\n", ret);
489 return ret;
490 }
491
492 return ret;
493}
494
495static int ath10k_vdev_stop(struct ath10k_vif *arvif)
496{
497 struct ath10k *ar = arvif->ar;
498 int ret;
499
500 lockdep_assert_held(&ar->conf_mutex);
501
Wolfram Sang16735d02013-11-14 14:32:02 -0800502 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300503
504 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
505 if (ret) {
506 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
507 return ret;
508 }
509
510 ret = ath10k_vdev_setup_sync(ar);
511 if (ret) {
512 ath10k_warn("vdev setup failed %d\n", ret);
513 return ret;
514 }
515
516 return ret;
517}
518
519static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
520{
521 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
522 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523 int ret = 0;
524
525 lockdep_assert_held(&ar->conf_mutex);
526
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300527 if (!ar->monitor_present) {
528 ath10k_warn("mac montor stop -- monitor is not present\n");
529 return -EINVAL;
530 }
531
Kalle Valo5e3dd152013-06-12 20:52:10 +0300532 arg.vdev_id = vdev_id;
533 arg.channel.freq = channel->center_freq;
534 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
535
536 /* TODO setup this dynamically, what in case we
537 don't have any vifs? */
538 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200539 arg.channel.chan_radar =
540 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300541
Michal Kazior89c5c842013-10-23 04:02:13 -0700542 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700543 arg.channel.max_power = channel->max_power * 2;
544 arg.channel.max_reg_power = channel->max_reg_power * 2;
545 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300546
547 ret = ath10k_wmi_vdev_start(ar, &arg);
548 if (ret) {
549 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
550 return ret;
551 }
552
553 ret = ath10k_vdev_setup_sync(ar);
554 if (ret) {
555 ath10k_warn("Monitor vdev setup failed %d\n", ret);
556 return ret;
557 }
558
559 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
560 if (ret) {
561 ath10k_warn("Monitor vdev up failed: %d\n", ret);
562 goto vdev_stop;
563 }
564
565 ar->monitor_vdev_id = vdev_id;
566 ar->monitor_enabled = true;
567
568 return 0;
569
570vdev_stop:
571 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
572 if (ret)
573 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
574
575 return ret;
576}
577
578static int ath10k_monitor_stop(struct ath10k *ar)
579{
580 int ret = 0;
581
582 lockdep_assert_held(&ar->conf_mutex);
583
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300584 if (!ar->monitor_present) {
585 ath10k_warn("mac montor stop -- monitor is not present\n");
586 return -EINVAL;
587 }
588
589 if (!ar->monitor_enabled) {
590 ath10k_warn("mac montor stop -- monitor is not enabled\n");
591 return -EINVAL;
592 }
593
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200594 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
595 if (ret)
596 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300597
598 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
599 if (ret)
600 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
601
602 ret = ath10k_vdev_setup_sync(ar);
603 if (ret)
604 ath10k_warn("Monitor_down sync failed: %d\n", ret);
605
606 ar->monitor_enabled = false;
607 return ret;
608}
609
610static int ath10k_monitor_create(struct ath10k *ar)
611{
612 int bit, ret = 0;
613
614 lockdep_assert_held(&ar->conf_mutex);
615
616 if (ar->monitor_present) {
617 ath10k_warn("Monitor mode already enabled\n");
618 return 0;
619 }
620
621 bit = ffs(ar->free_vdev_map);
622 if (bit == 0) {
623 ath10k_warn("No free VDEV slots\n");
624 return -ENOMEM;
625 }
626
627 ar->monitor_vdev_id = bit - 1;
628 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
629
630 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
631 WMI_VDEV_TYPE_MONITOR,
632 0, ar->mac_addr);
633 if (ret) {
634 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
635 goto vdev_fail;
636 }
637
Kalle Valo60c3daa2013-09-08 17:56:07 +0300638 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300639 ar->monitor_vdev_id);
640
641 ar->monitor_present = true;
642 return 0;
643
644vdev_fail:
645 /*
646 * Restore the ID to the global map.
647 */
648 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
649 return ret;
650}
651
652static int ath10k_monitor_destroy(struct ath10k *ar)
653{
654 int ret = 0;
655
656 lockdep_assert_held(&ar->conf_mutex);
657
658 if (!ar->monitor_present)
659 return 0;
660
661 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
662 if (ret) {
663 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
664 return ret;
665 }
666
667 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
668 ar->monitor_present = false;
669
Kalle Valo60c3daa2013-09-08 17:56:07 +0300670 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300671 ar->monitor_vdev_id);
672 return ret;
673}
674
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200675static int ath10k_start_cac(struct ath10k *ar)
676{
677 int ret;
678
679 lockdep_assert_held(&ar->conf_mutex);
680
681 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
682
683 ret = ath10k_monitor_create(ar);
684 if (ret) {
685 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
686 return ret;
687 }
688
689 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
690 if (ret) {
691 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
692 ath10k_monitor_destroy(ar);
693 return ret;
694 }
695
696 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
697 ar->monitor_vdev_id);
698
699 return 0;
700}
701
702static int ath10k_stop_cac(struct ath10k *ar)
703{
704 lockdep_assert_held(&ar->conf_mutex);
705
706 /* CAC is not running - do nothing */
707 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
708 return 0;
709
710 ath10k_monitor_stop(ar);
711 ath10k_monitor_destroy(ar);
712 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
713
714 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
715
716 return 0;
717}
718
719static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
720{
721 switch (dfs_state) {
722 case NL80211_DFS_USABLE:
723 return "USABLE";
724 case NL80211_DFS_UNAVAILABLE:
725 return "UNAVAILABLE";
726 case NL80211_DFS_AVAILABLE:
727 return "AVAILABLE";
728 default:
729 WARN_ON(1);
730 return "bug";
731 }
732}
733
734static void ath10k_config_radar_detection(struct ath10k *ar)
735{
736 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
737 bool radar = ar->hw->conf.radar_enabled;
738 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
739 enum nl80211_dfs_state dfs_state = chan->dfs_state;
740 int ret;
741
742 lockdep_assert_held(&ar->conf_mutex);
743
744 ath10k_dbg(ATH10K_DBG_MAC,
745 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
746 chan->center_freq, radar, chan_radar,
747 ath10k_dfs_state(dfs_state));
748
749 /*
750 * It's safe to call it even if CAC is not started.
751 * This call here guarantees changing channel, etc. will stop CAC.
752 */
753 ath10k_stop_cac(ar);
754
755 if (!radar)
756 return;
757
758 if (!chan_radar)
759 return;
760
761 if (dfs_state != NL80211_DFS_USABLE)
762 return;
763
764 ret = ath10k_start_cac(ar);
765 if (ret) {
766 /*
767 * Not possible to start CAC on current channel so starting
768 * radiation is not allowed, make this channel DFS_UNAVAILABLE
769 * by indicating that radar was detected.
770 */
771 ath10k_warn("failed to start CAC (%d)\n", ret);
772 ieee80211_radar_detected(ar->hw);
773 }
774}
775
Kalle Valo5e3dd152013-06-12 20:52:10 +0300776static void ath10k_control_beaconing(struct ath10k_vif *arvif,
777 struct ieee80211_bss_conf *info)
778{
779 int ret = 0;
780
Michal Kazior548db542013-07-05 16:15:15 +0300781 lockdep_assert_held(&arvif->ar->conf_mutex);
782
Kalle Valo5e3dd152013-06-12 20:52:10 +0300783 if (!info->enable_beacon) {
784 ath10k_vdev_stop(arvif);
785 return;
786 }
787
788 arvif->tx_seq_no = 0x1000;
789
790 ret = ath10k_vdev_start(arvif);
791 if (ret)
792 return;
793
794 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
795 if (ret) {
796 ath10k_warn("Failed to bring up VDEV: %d\n",
797 arvif->vdev_id);
798 return;
799 }
Kalle Valo60c3daa2013-09-08 17:56:07 +0300800 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300801}
802
803static void ath10k_control_ibss(struct ath10k_vif *arvif,
804 struct ieee80211_bss_conf *info,
805 const u8 self_peer[ETH_ALEN])
806{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200807 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300808 int ret = 0;
809
Michal Kazior548db542013-07-05 16:15:15 +0300810 lockdep_assert_held(&arvif->ar->conf_mutex);
811
Kalle Valo5e3dd152013-06-12 20:52:10 +0300812 if (!info->ibss_joined) {
813 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
814 if (ret)
815 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
816 self_peer, arvif->vdev_id, ret);
817
818 if (is_zero_ether_addr(arvif->u.ibss.bssid))
819 return;
820
821 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
822 arvif->u.ibss.bssid);
823 if (ret) {
824 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
825 arvif->u.ibss.bssid, arvif->vdev_id, ret);
826 return;
827 }
828
829 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
830
831 return;
832 }
833
834 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
835 if (ret) {
836 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
837 self_peer, arvif->vdev_id, ret);
838 return;
839 }
840
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200841 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
842 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300843 ATH10K_DEFAULT_ATIM);
844 if (ret)
845 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
846 arvif->vdev_id, ret);
847}
848
849/*
850 * Review this when mac80211 gains per-interface powersave support.
851 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300852static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300853{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300854 struct ath10k *ar = arvif->ar;
855 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300856 enum wmi_sta_powersave_param param;
857 enum wmi_sta_ps_mode psmode;
858 int ret;
859
Michal Kazior548db542013-07-05 16:15:15 +0300860 lockdep_assert_held(&arvif->ar->conf_mutex);
861
Michal Kaziorad088bf2013-10-16 15:44:46 +0300862 if (arvif->vif->type != NL80211_IFTYPE_STATION)
863 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300864
865 if (conf->flags & IEEE80211_CONF_PS) {
866 psmode = WMI_STA_PS_MODE_ENABLED;
867 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
868
Michal Kaziorad088bf2013-10-16 15:44:46 +0300869 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870 conf->dynamic_ps_timeout);
871 if (ret) {
872 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
873 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300874 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300875 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300876 } else {
877 psmode = WMI_STA_PS_MODE_DISABLED;
878 }
879
Kalle Valo60c3daa2013-09-08 17:56:07 +0300880 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
881 arvif->vdev_id, psmode ? "enable" : "disable");
882
Michal Kaziorad088bf2013-10-16 15:44:46 +0300883 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
884 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300885 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
886 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300887 return ret;
888 }
889
890 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300891}
892
893/**********************/
894/* Station management */
895/**********************/
896
897static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
898 struct ath10k_vif *arvif,
899 struct ieee80211_sta *sta,
900 struct ieee80211_bss_conf *bss_conf,
901 struct wmi_peer_assoc_complete_arg *arg)
902{
Michal Kazior548db542013-07-05 16:15:15 +0300903 lockdep_assert_held(&ar->conf_mutex);
904
Kalle Valo5e3dd152013-06-12 20:52:10 +0300905 memcpy(arg->addr, sta->addr, ETH_ALEN);
906 arg->vdev_id = arvif->vdev_id;
907 arg->peer_aid = sta->aid;
908 arg->peer_flags |= WMI_PEER_AUTH;
909
910 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
911 /*
912 * Seems FW have problems with Power Save in STA
913 * mode when we setup this parameter to high (eg. 5).
914 * Often we see that FW don't send NULL (with clean P flags)
915 * frame even there is info about buffered frames in beacons.
916 * Sometimes we have to wait more than 10 seconds before FW
917 * will wakeup. Often sending one ping from AP to our device
918 * just fail (more than 50%).
919 *
920 * Seems setting this FW parameter to 1 couse FW
921 * will check every beacon and will wakup immediately
922 * after detection buffered data.
923 */
924 arg->peer_listen_intval = 1;
925 else
926 arg->peer_listen_intval = ar->hw->conf.listen_interval;
927
928 arg->peer_num_spatial_streams = 1;
929
930 /*
931 * The assoc capabilities are available only in managed mode.
932 */
933 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
934 arg->peer_caps = bss_conf->assoc_capability;
935}
936
937static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
938 struct ath10k_vif *arvif,
939 struct wmi_peer_assoc_complete_arg *arg)
940{
941 struct ieee80211_vif *vif = arvif->vif;
942 struct ieee80211_bss_conf *info = &vif->bss_conf;
943 struct cfg80211_bss *bss;
944 const u8 *rsnie = NULL;
945 const u8 *wpaie = NULL;
946
Michal Kazior548db542013-07-05 16:15:15 +0300947 lockdep_assert_held(&ar->conf_mutex);
948
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
950 info->bssid, NULL, 0, 0, 0);
951 if (bss) {
952 const struct cfg80211_bss_ies *ies;
953
954 rcu_read_lock();
955 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
956
957 ies = rcu_dereference(bss->ies);
958
959 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
960 WLAN_OUI_TYPE_MICROSOFT_WPA,
961 ies->data,
962 ies->len);
963 rcu_read_unlock();
964 cfg80211_put_bss(ar->hw->wiphy, bss);
965 }
966
967 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
968 if (rsnie || wpaie) {
969 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
970 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
971 }
972
973 if (wpaie) {
974 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
975 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
976 }
977}
978
979static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
980 struct ieee80211_sta *sta,
981 struct wmi_peer_assoc_complete_arg *arg)
982{
983 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
984 const struct ieee80211_supported_band *sband;
985 const struct ieee80211_rate *rates;
986 u32 ratemask;
987 int i;
988
Michal Kazior548db542013-07-05 16:15:15 +0300989 lockdep_assert_held(&ar->conf_mutex);
990
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
992 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
993 rates = sband->bitrates;
994
995 rateset->num_rates = 0;
996
997 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
998 if (!(ratemask & 1))
999 continue;
1000
1001 rateset->rates[rateset->num_rates] = rates->hw_value;
1002 rateset->num_rates++;
1003 }
1004}
1005
1006static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1007 struct ieee80211_sta *sta,
1008 struct wmi_peer_assoc_complete_arg *arg)
1009{
1010 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1011 int smps;
1012 int i, n;
1013
Michal Kazior548db542013-07-05 16:15:15 +03001014 lockdep_assert_held(&ar->conf_mutex);
1015
Kalle Valo5e3dd152013-06-12 20:52:10 +03001016 if (!ht_cap->ht_supported)
1017 return;
1018
1019 arg->peer_flags |= WMI_PEER_HT;
1020 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1021 ht_cap->ampdu_factor)) - 1;
1022
1023 arg->peer_mpdu_density =
1024 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1025
1026 arg->peer_ht_caps = ht_cap->cap;
1027 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1028
1029 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1030 arg->peer_flags |= WMI_PEER_LDPC;
1031
1032 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1033 arg->peer_flags |= WMI_PEER_40MHZ;
1034 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1035 }
1036
1037 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1038 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1039
1040 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1041 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1042
1043 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1044 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1045 arg->peer_flags |= WMI_PEER_STBC;
1046 }
1047
1048 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1049 u32 stbc;
1050 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1051 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1052 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1053 arg->peer_rate_caps |= stbc;
1054 arg->peer_flags |= WMI_PEER_STBC;
1055 }
1056
1057 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1058 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1059
1060 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1061 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1062 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1063 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1064 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1065 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1066 }
1067
1068 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1069 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1070 else if (ht_cap->mcs.rx_mask[1])
1071 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1072
1073 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1074 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1075 arg->peer_ht_rates.rates[n++] = i;
1076
1077 arg->peer_ht_rates.num_rates = n;
1078 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
1079
Kalle Valo60c3daa2013-09-08 17:56:07 +03001080 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1081 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001082 arg->peer_ht_rates.num_rates,
1083 arg->peer_num_spatial_streams);
1084}
1085
1086static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
1087 struct ath10k_vif *arvif,
1088 struct ieee80211_sta *sta,
1089 struct ieee80211_bss_conf *bss_conf,
1090 struct wmi_peer_assoc_complete_arg *arg)
1091{
1092 u32 uapsd = 0;
1093 u32 max_sp = 0;
1094
Michal Kazior548db542013-07-05 16:15:15 +03001095 lockdep_assert_held(&ar->conf_mutex);
1096
Kalle Valo5e3dd152013-06-12 20:52:10 +03001097 if (sta->wme)
1098 arg->peer_flags |= WMI_PEER_QOS;
1099
1100 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001101 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001102 sta->uapsd_queues, sta->max_sp);
1103
1104 arg->peer_flags |= WMI_PEER_APSD;
Janusz Dziedzicc69029b2013-08-07 12:10:49 +02001105 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001106
1107 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1108 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1109 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1110 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1111 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1112 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1113 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1114 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1115 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1116 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1117 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1118 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1119
1120
1121 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1122 max_sp = sta->max_sp;
1123
1124 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1125 sta->addr,
1126 WMI_AP_PS_PEER_PARAM_UAPSD,
1127 uapsd);
1128
1129 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1130 sta->addr,
1131 WMI_AP_PS_PEER_PARAM_MAX_SP,
1132 max_sp);
1133
1134 /* TODO setup this based on STA listen interval and
1135 beacon interval. Currently we don't know
1136 sta->listen_interval - mac80211 patch required.
1137 Currently use 10 seconds */
1138 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1139 sta->addr,
1140 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1141 10);
1142 }
1143}
1144
1145static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1146 struct ath10k_vif *arvif,
1147 struct ieee80211_sta *sta,
1148 struct ieee80211_bss_conf *bss_conf,
1149 struct wmi_peer_assoc_complete_arg *arg)
1150{
1151 if (bss_conf->qos)
1152 arg->peer_flags |= WMI_PEER_QOS;
1153}
1154
1155static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1156 struct ieee80211_sta *sta,
1157 struct wmi_peer_assoc_complete_arg *arg)
1158{
1159 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001160 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161
1162 if (!vht_cap->vht_supported)
1163 return;
1164
1165 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001166 arg->peer_vht_caps = vht_cap->cap;
1167
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001168
1169 ampdu_factor = (vht_cap->cap &
1170 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1171 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1172
1173 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1174 * zero in VHT IE. Using it would result in degraded throughput.
1175 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1176 * it if VHT max_mpdu is smaller. */
1177 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1178 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1179 ampdu_factor)) - 1);
1180
Kalle Valo5e3dd152013-06-12 20:52:10 +03001181 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1182 arg->peer_flags |= WMI_PEER_80MHZ;
1183
1184 arg->peer_vht_rates.rx_max_rate =
1185 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1186 arg->peer_vht_rates.rx_mcs_set =
1187 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1188 arg->peer_vht_rates.tx_max_rate =
1189 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1190 arg->peer_vht_rates.tx_mcs_set =
1191 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1192
Kalle Valo60c3daa2013-09-08 17:56:07 +03001193 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1194 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195}
1196
1197static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1198 struct ath10k_vif *arvif,
1199 struct ieee80211_sta *sta,
1200 struct ieee80211_bss_conf *bss_conf,
1201 struct wmi_peer_assoc_complete_arg *arg)
1202{
1203 switch (arvif->vdev_type) {
1204 case WMI_VDEV_TYPE_AP:
1205 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1206 break;
1207 case WMI_VDEV_TYPE_STA:
1208 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1209 break;
1210 default:
1211 break;
1212 }
1213}
1214
1215static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1216 struct ath10k_vif *arvif,
1217 struct ieee80211_sta *sta,
1218 struct wmi_peer_assoc_complete_arg *arg)
1219{
1220 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1221
Kalle Valo5e3dd152013-06-12 20:52:10 +03001222 switch (ar->hw->conf.chandef.chan->band) {
1223 case IEEE80211_BAND_2GHZ:
1224 if (sta->ht_cap.ht_supported) {
1225 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1226 phymode = MODE_11NG_HT40;
1227 else
1228 phymode = MODE_11NG_HT20;
1229 } else {
1230 phymode = MODE_11G;
1231 }
1232
1233 break;
1234 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001235 /*
1236 * Check VHT first.
1237 */
1238 if (sta->vht_cap.vht_supported) {
1239 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1240 phymode = MODE_11AC_VHT80;
1241 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1242 phymode = MODE_11AC_VHT40;
1243 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1244 phymode = MODE_11AC_VHT20;
1245 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001246 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1247 phymode = MODE_11NA_HT40;
1248 else
1249 phymode = MODE_11NA_HT20;
1250 } else {
1251 phymode = MODE_11A;
1252 }
1253
1254 break;
1255 default:
1256 break;
1257 }
1258
Kalle Valo38a1d472013-09-08 17:56:14 +03001259 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1260 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001261
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262 arg->peer_phymode = phymode;
1263 WARN_ON(phymode == MODE_UNKNOWN);
1264}
1265
Kalle Valob9ada652013-10-16 15:44:46 +03001266static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1267 struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta,
1269 struct ieee80211_bss_conf *bss_conf,
1270 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001271{
Michal Kazior548db542013-07-05 16:15:15 +03001272 lockdep_assert_held(&ar->conf_mutex);
1273
Kalle Valob9ada652013-10-16 15:44:46 +03001274 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001275
Kalle Valob9ada652013-10-16 15:44:46 +03001276 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1277 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1278 ath10k_peer_assoc_h_rates(ar, sta, arg);
1279 ath10k_peer_assoc_h_ht(ar, sta, arg);
1280 ath10k_peer_assoc_h_vht(ar, sta, arg);
1281 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1282 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283
Kalle Valob9ada652013-10-16 15:44:46 +03001284 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001285}
1286
1287/* can be called only in mac80211 callbacks due to `key_count` usage */
1288static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1289 struct ieee80211_vif *vif,
1290 struct ieee80211_bss_conf *bss_conf)
1291{
1292 struct ath10k *ar = hw->priv;
1293 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001294 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295 struct ieee80211_sta *ap_sta;
1296 int ret;
1297
Michal Kazior548db542013-07-05 16:15:15 +03001298 lockdep_assert_held(&ar->conf_mutex);
1299
Kalle Valo5e3dd152013-06-12 20:52:10 +03001300 rcu_read_lock();
1301
1302 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1303 if (!ap_sta) {
1304 ath10k_warn("Failed to find station entry for %pM\n",
1305 bss_conf->bssid);
1306 rcu_read_unlock();
1307 return;
1308 }
1309
Kalle Valob9ada652013-10-16 15:44:46 +03001310 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1311 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001313 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1314 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001315 rcu_read_unlock();
1316 return;
1317 }
1318
1319 rcu_read_unlock();
1320
Kalle Valob9ada652013-10-16 15:44:46 +03001321 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1322 if (ret) {
1323 ath10k_warn("Peer assoc failed for %pM\n: %d",
1324 bss_conf->bssid, ret);
1325 return;
1326 }
1327
Kalle Valo60c3daa2013-09-08 17:56:07 +03001328 ath10k_dbg(ATH10K_DBG_MAC,
1329 "mac vdev %d up (associated) bssid %pM aid %d\n",
1330 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1331
Kalle Valo5e3dd152013-06-12 20:52:10 +03001332 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1333 bss_conf->bssid);
1334 if (ret)
1335 ath10k_warn("VDEV: %d up failed: ret %d\n",
1336 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001337}
1338
1339/*
1340 * FIXME: flush TIDs
1341 */
1342static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1343 struct ieee80211_vif *vif)
1344{
1345 struct ath10k *ar = hw->priv;
1346 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1347 int ret;
1348
Michal Kazior548db542013-07-05 16:15:15 +03001349 lockdep_assert_held(&ar->conf_mutex);
1350
Kalle Valo5e3dd152013-06-12 20:52:10 +03001351 /*
1352 * For some reason, calling VDEV-DOWN before VDEV-STOP
1353 * makes the FW to send frames via HTT after disassociation.
1354 * No idea why this happens, even though VDEV-DOWN is supposed
1355 * to be analogous to link down, so just stop the VDEV.
1356 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001357 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1358 arvif->vdev_id);
1359
1360 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001361 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362
1363 /*
1364 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1365 * report beacons from previously associated network through HTT.
1366 * This in turn would spam mac80211 WARN_ON if we bring down all
1367 * interfaces as it expects there is no rx when no interface is
1368 * running.
1369 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001370 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1371
1372 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001374
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001375 arvif->def_wep_key_idx = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001376}
1377
1378static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1379 struct ieee80211_sta *sta)
1380{
Kalle Valob9ada652013-10-16 15:44:46 +03001381 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001382 int ret = 0;
1383
Michal Kazior548db542013-07-05 16:15:15 +03001384 lockdep_assert_held(&ar->conf_mutex);
1385
Kalle Valob9ada652013-10-16 15:44:46 +03001386 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001387 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001388 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1389 sta->addr);
1390 return ret;
1391 }
1392
1393 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1394 if (ret) {
1395 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1396 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001397 return ret;
1398 }
1399
1400 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1401 if (ret) {
1402 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1403 return ret;
1404 }
1405
1406 return ret;
1407}
1408
1409static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1410 struct ieee80211_sta *sta)
1411{
1412 int ret = 0;
1413
Michal Kazior548db542013-07-05 16:15:15 +03001414 lockdep_assert_held(&ar->conf_mutex);
1415
Kalle Valo5e3dd152013-06-12 20:52:10 +03001416 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1417 if (ret) {
1418 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1419 return ret;
1420 }
1421
1422 return ret;
1423}
1424
1425/**************/
1426/* Regulatory */
1427/**************/
1428
1429static int ath10k_update_channel_list(struct ath10k *ar)
1430{
1431 struct ieee80211_hw *hw = ar->hw;
1432 struct ieee80211_supported_band **bands;
1433 enum ieee80211_band band;
1434 struct ieee80211_channel *channel;
1435 struct wmi_scan_chan_list_arg arg = {0};
1436 struct wmi_channel_arg *ch;
1437 bool passive;
1438 int len;
1439 int ret;
1440 int i;
1441
Michal Kazior548db542013-07-05 16:15:15 +03001442 lockdep_assert_held(&ar->conf_mutex);
1443
Kalle Valo5e3dd152013-06-12 20:52:10 +03001444 bands = hw->wiphy->bands;
1445 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1446 if (!bands[band])
1447 continue;
1448
1449 for (i = 0; i < bands[band]->n_channels; i++) {
1450 if (bands[band]->channels[i].flags &
1451 IEEE80211_CHAN_DISABLED)
1452 continue;
1453
1454 arg.n_channels++;
1455 }
1456 }
1457
1458 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1459 arg.channels = kzalloc(len, GFP_KERNEL);
1460 if (!arg.channels)
1461 return -ENOMEM;
1462
1463 ch = arg.channels;
1464 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1465 if (!bands[band])
1466 continue;
1467
1468 for (i = 0; i < bands[band]->n_channels; i++) {
1469 channel = &bands[band]->channels[i];
1470
1471 if (channel->flags & IEEE80211_CHAN_DISABLED)
1472 continue;
1473
1474 ch->allow_ht = true;
1475
1476 /* FIXME: when should we really allow VHT? */
1477 ch->allow_vht = true;
1478
1479 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001480 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481
1482 ch->ht40plus =
1483 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1484
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001485 ch->chan_radar =
1486 !!(channel->flags & IEEE80211_CHAN_RADAR);
1487
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001488 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001489 ch->passive = passive;
1490
1491 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001492 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001493 ch->max_power = channel->max_power * 2;
1494 ch->max_reg_power = channel->max_reg_power * 2;
1495 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001496 ch->reg_class_id = 0; /* FIXME */
1497
1498 /* FIXME: why use only legacy modes, why not any
1499 * HT/VHT modes? Would that even make any
1500 * difference? */
1501 if (channel->band == IEEE80211_BAND_2GHZ)
1502 ch->mode = MODE_11G;
1503 else
1504 ch->mode = MODE_11A;
1505
1506 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1507 continue;
1508
1509 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001510 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1511 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001512 ch->freq, ch->max_power, ch->max_reg_power,
1513 ch->max_antenna_gain, ch->mode);
1514
1515 ch++;
1516 }
1517 }
1518
1519 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1520 kfree(arg.channels);
1521
1522 return ret;
1523}
1524
Michal Kaziorf7843d72013-07-16 09:38:52 +02001525static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001526{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001527 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528 int ret;
1529
Michal Kaziorf7843d72013-07-16 09:38:52 +02001530 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001531
1532 ret = ath10k_update_channel_list(ar);
1533 if (ret)
1534 ath10k_warn("could not update channel list (%d)\n", ret);
1535
1536 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001537
Kalle Valo5e3dd152013-06-12 20:52:10 +03001538 /* Target allows setting up per-band regdomain but ath_common provides
1539 * a combined one only */
1540 ret = ath10k_wmi_pdev_set_regdomain(ar,
1541 regpair->regDmnEnum,
1542 regpair->regDmnEnum, /* 2ghz */
1543 regpair->regDmnEnum, /* 5ghz */
1544 regpair->reg_2ghz_ctl,
1545 regpair->reg_5ghz_ctl);
1546 if (ret)
1547 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001548}
Michal Kazior548db542013-07-05 16:15:15 +03001549
Michal Kaziorf7843d72013-07-16 09:38:52 +02001550static void ath10k_reg_notifier(struct wiphy *wiphy,
1551 struct regulatory_request *request)
1552{
1553 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1554 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001555 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001556
1557 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1558
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001559 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1560 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1561 request->dfs_region);
1562 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1563 request->dfs_region);
1564 if (!result)
1565 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1566 request->dfs_region);
1567 }
1568
Michal Kaziorf7843d72013-07-16 09:38:52 +02001569 mutex_lock(&ar->conf_mutex);
1570 if (ar->state == ATH10K_STATE_ON)
1571 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001572 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573}
1574
1575/***************/
1576/* TX handlers */
1577/***************/
1578
Michal Kazior42c3aa62013-10-02 11:03:38 +02001579static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1580{
1581 if (ieee80211_is_mgmt(hdr->frame_control))
1582 return HTT_DATA_TX_EXT_TID_MGMT;
1583
1584 if (!ieee80211_is_data_qos(hdr->frame_control))
1585 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1586
1587 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1588 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1589
1590 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1591}
1592
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001593static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1594 struct ieee80211_tx_info *info)
1595{
1596 if (info->control.vif)
1597 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1598
1599 if (ar->monitor_enabled)
1600 return ar->monitor_vdev_id;
1601
1602 ath10k_warn("could not resolve vdev id\n");
1603 return 0;
1604}
1605
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606/*
1607 * Frames sent to the FW have to be in "Native Wifi" format.
1608 * Strip the QoS field from the 802.11 header.
1609 */
1610static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1611 struct ieee80211_tx_control *control,
1612 struct sk_buff *skb)
1613{
1614 struct ieee80211_hdr *hdr = (void *)skb->data;
1615 u8 *qos_ctl;
1616
1617 if (!ieee80211_is_data_qos(hdr->frame_control))
1618 return;
1619
1620 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001621 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1622 skb->data, (void *)qos_ctl - (void *)skb->data);
1623 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624}
1625
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001626static void ath10k_tx_wep_key_work(struct work_struct *work)
1627{
1628 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1629 wep_key_work);
1630 int ret, keyidx = arvif->def_wep_key_newidx;
1631
1632 if (arvif->def_wep_key_idx == keyidx)
1633 return;
1634
1635 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1636 arvif->vdev_id, keyidx);
1637
1638 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1639 arvif->vdev_id,
1640 arvif->ar->wmi.vdev_param->def_keyid,
1641 keyidx);
1642 if (ret) {
1643 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1644 return;
1645 }
1646
1647 arvif->def_wep_key_idx = keyidx;
1648}
1649
Kalle Valo5e3dd152013-06-12 20:52:10 +03001650static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1651{
1652 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1653 struct ieee80211_vif *vif = info->control.vif;
1654 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1655 struct ath10k *ar = arvif->ar;
1656 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1657 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658
Kalle Valo5e3dd152013-06-12 20:52:10 +03001659 if (!ieee80211_has_protected(hdr->frame_control))
1660 return;
1661
1662 if (!key)
1663 return;
1664
1665 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1666 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1667 return;
1668
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001669 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001670 return;
1671
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001672 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1673 * queueing frames until key index is updated is not an option because
1674 * sk_buff may need more processing to be done, e.g. offchannel */
1675 arvif->def_wep_key_newidx = key->keyidx;
1676 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677}
1678
1679static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1680{
1681 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1682 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1683 struct ieee80211_vif *vif = info->control.vif;
1684 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1685
1686 /* This is case only for P2P_GO */
1687 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1688 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1689 return;
1690
1691 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1692 spin_lock_bh(&ar->data_lock);
1693 if (arvif->u.ap.noa_data)
1694 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1695 GFP_ATOMIC))
1696 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1697 arvif->u.ap.noa_data,
1698 arvif->u.ap.noa_len);
1699 spin_unlock_bh(&ar->data_lock);
1700 }
1701}
1702
1703static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1704{
1705 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001706 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707
Michal Kazior961d4c32013-08-09 10:13:34 +02001708 if (ar->htt.target_version_major >= 3) {
1709 /* Since HTT 3.0 there is no separate mgmt tx command */
1710 ret = ath10k_htt_tx(&ar->htt, skb);
1711 goto exit;
1712 }
1713
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001714 if (ieee80211_is_mgmt(hdr->frame_control)) {
1715 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1716 ar->fw_features)) {
1717 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1718 ATH10K_MAX_NUM_MGMT_PENDING) {
1719 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1720 ret = -EBUSY;
1721 goto exit;
1722 }
1723
1724 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1725 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1726 } else {
1727 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1728 }
1729 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1730 ar->fw_features) &&
1731 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001732 /* FW does not report tx status properly for NullFunc frames
1733 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001734 * those frames when it detects link/beacon loss and depends
1735 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001736 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001737 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001738 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001739 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001740
Michal Kazior961d4c32013-08-09 10:13:34 +02001741exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742 if (ret) {
1743 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1744 ieee80211_free_txskb(ar->hw, skb);
1745 }
1746}
1747
1748void ath10k_offchan_tx_purge(struct ath10k *ar)
1749{
1750 struct sk_buff *skb;
1751
1752 for (;;) {
1753 skb = skb_dequeue(&ar->offchan_tx_queue);
1754 if (!skb)
1755 break;
1756
1757 ieee80211_free_txskb(ar->hw, skb);
1758 }
1759}
1760
1761void ath10k_offchan_tx_work(struct work_struct *work)
1762{
1763 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1764 struct ath10k_peer *peer;
1765 struct ieee80211_hdr *hdr;
1766 struct sk_buff *skb;
1767 const u8 *peer_addr;
1768 int vdev_id;
1769 int ret;
1770
1771 /* FW requirement: We must create a peer before FW will send out
1772 * an offchannel frame. Otherwise the frame will be stuck and
1773 * never transmitted. We delete the peer upon tx completion.
1774 * It is unlikely that a peer for offchannel tx will already be
1775 * present. However it may be in some rare cases so account for that.
1776 * Otherwise we might remove a legitimate peer and break stuff. */
1777
1778 for (;;) {
1779 skb = skb_dequeue(&ar->offchan_tx_queue);
1780 if (!skb)
1781 break;
1782
1783 mutex_lock(&ar->conf_mutex);
1784
Kalle Valo60c3daa2013-09-08 17:56:07 +03001785 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786 skb);
1787
1788 hdr = (struct ieee80211_hdr *)skb->data;
1789 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001790 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791
1792 spin_lock_bh(&ar->data_lock);
1793 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1794 spin_unlock_bh(&ar->data_lock);
1795
1796 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001797 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1799 peer_addr, vdev_id);
1800
1801 if (!peer) {
1802 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1803 if (ret)
1804 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1805 peer_addr, vdev_id, ret);
1806 }
1807
1808 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001809 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810 ar->offchan_tx_skb = skb;
1811 spin_unlock_bh(&ar->data_lock);
1812
1813 ath10k_tx_htt(ar, skb);
1814
1815 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1816 3 * HZ);
1817 if (ret <= 0)
1818 ath10k_warn("timed out waiting for offchannel skb %p\n",
1819 skb);
1820
1821 if (!peer) {
1822 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1823 if (ret)
1824 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1825 peer_addr, vdev_id, ret);
1826 }
1827
1828 mutex_unlock(&ar->conf_mutex);
1829 }
1830}
1831
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001832void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1833{
1834 struct sk_buff *skb;
1835
1836 for (;;) {
1837 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1838 if (!skb)
1839 break;
1840
1841 ieee80211_free_txskb(ar->hw, skb);
1842 }
1843}
1844
1845void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1846{
1847 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1848 struct sk_buff *skb;
1849 int ret;
1850
1851 for (;;) {
1852 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1853 if (!skb)
1854 break;
1855
1856 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001857 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001858 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001859 ieee80211_free_txskb(ar->hw, skb);
1860 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001861 }
1862}
1863
Kalle Valo5e3dd152013-06-12 20:52:10 +03001864/************/
1865/* Scanning */
1866/************/
1867
1868/*
1869 * This gets called if we dont get a heart-beat during scan.
1870 * This may indicate the FW has hung and we need to abort the
1871 * scan manually to prevent cancel_hw_scan() from deadlocking
1872 */
1873void ath10k_reset_scan(unsigned long ptr)
1874{
1875 struct ath10k *ar = (struct ath10k *)ptr;
1876
1877 spin_lock_bh(&ar->data_lock);
1878 if (!ar->scan.in_progress) {
1879 spin_unlock_bh(&ar->data_lock);
1880 return;
1881 }
1882
1883 ath10k_warn("scan timeout. resetting. fw issue?\n");
1884
1885 if (ar->scan.is_roc)
1886 ieee80211_remain_on_channel_expired(ar->hw);
1887 else
1888 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1889
1890 ar->scan.in_progress = false;
1891 complete_all(&ar->scan.completed);
1892 spin_unlock_bh(&ar->data_lock);
1893}
1894
1895static int ath10k_abort_scan(struct ath10k *ar)
1896{
1897 struct wmi_stop_scan_arg arg = {
1898 .req_id = 1, /* FIXME */
1899 .req_type = WMI_SCAN_STOP_ONE,
1900 .u.scan_id = ATH10K_SCAN_ID,
1901 };
1902 int ret;
1903
1904 lockdep_assert_held(&ar->conf_mutex);
1905
1906 del_timer_sync(&ar->scan.timeout);
1907
1908 spin_lock_bh(&ar->data_lock);
1909 if (!ar->scan.in_progress) {
1910 spin_unlock_bh(&ar->data_lock);
1911 return 0;
1912 }
1913
1914 ar->scan.aborting = true;
1915 spin_unlock_bh(&ar->data_lock);
1916
1917 ret = ath10k_wmi_stop_scan(ar, &arg);
1918 if (ret) {
1919 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03001920 spin_lock_bh(&ar->data_lock);
1921 ar->scan.in_progress = false;
1922 ath10k_offchan_tx_purge(ar);
1923 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 return -EIO;
1925 }
1926
Kalle Valo5e3dd152013-06-12 20:52:10 +03001927 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1928 if (ret == 0)
1929 ath10k_warn("timed out while waiting for scan to stop\n");
1930
1931 /* scan completion may be done right after we timeout here, so let's
1932 * check the in_progress and tell mac80211 scan is completed. if we
1933 * don't do that and FW fails to send us scan completion indication
1934 * then userspace won't be able to scan anymore */
1935 ret = 0;
1936
1937 spin_lock_bh(&ar->data_lock);
1938 if (ar->scan.in_progress) {
1939 ath10k_warn("could not stop scan. its still in progress\n");
1940 ar->scan.in_progress = false;
1941 ath10k_offchan_tx_purge(ar);
1942 ret = -ETIMEDOUT;
1943 }
1944 spin_unlock_bh(&ar->data_lock);
1945
1946 return ret;
1947}
1948
1949static int ath10k_start_scan(struct ath10k *ar,
1950 const struct wmi_start_scan_arg *arg)
1951{
1952 int ret;
1953
1954 lockdep_assert_held(&ar->conf_mutex);
1955
1956 ret = ath10k_wmi_start_scan(ar, arg);
1957 if (ret)
1958 return ret;
1959
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1961 if (ret == 0) {
1962 ath10k_abort_scan(ar);
1963 return ret;
1964 }
1965
1966 /* the scan can complete earlier, before we even
1967 * start the timer. in that case the timer handler
1968 * checks ar->scan.in_progress and bails out if its
1969 * false. Add a 200ms margin to account event/command
1970 * processing. */
1971 mod_timer(&ar->scan.timeout, jiffies +
1972 msecs_to_jiffies(arg->max_scan_time+200));
1973 return 0;
1974}
1975
1976/**********************/
1977/* mac80211 callbacks */
1978/**********************/
1979
1980static void ath10k_tx(struct ieee80211_hw *hw,
1981 struct ieee80211_tx_control *control,
1982 struct sk_buff *skb)
1983{
1984 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1985 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1986 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001987 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988
1989 /* We should disable CCK RATE due to P2P */
1990 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1991 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1992
1993 /* we must calculate tid before we apply qos workaround
1994 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02001995 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001996 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001997
Michal Kaziorcf84bd42013-07-16 11:04:54 +02001998 /* it makes no sense to process injected frames like that */
1999 if (info->control.vif &&
2000 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2001 ath10k_tx_h_qos_workaround(hw, control, skb);
2002 ath10k_tx_h_update_wep_key(skb);
2003 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2004 ath10k_tx_h_seq_no(skb);
2005 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002007 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002008 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002009 ATH10K_SKB_CB(skb)->htt.tid = tid;
2010
2011 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2012 spin_lock_bh(&ar->data_lock);
2013 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002014 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 spin_unlock_bh(&ar->data_lock);
2016
2017 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2018
2019 skb_queue_tail(&ar->offchan_tx_queue, skb);
2020 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2021 return;
2022 }
2023
2024 ath10k_tx_htt(ar, skb);
2025}
2026
2027/*
2028 * Initialize various parameters with default vaules.
2029 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002030void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002031{
2032 lockdep_assert_held(&ar->conf_mutex);
2033
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002034 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002035 del_timer_sync(&ar->scan.timeout);
2036 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002037 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002038 ath10k_peer_cleanup_all(ar);
2039 ath10k_core_stop(ar);
2040 ath10k_hif_power_down(ar);
2041
2042 spin_lock_bh(&ar->data_lock);
2043 if (ar->scan.in_progress) {
2044 del_timer(&ar->scan.timeout);
2045 ar->scan.in_progress = false;
2046 ieee80211_scan_completed(ar->hw, true);
2047 }
2048 spin_unlock_bh(&ar->data_lock);
2049}
2050
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051static int ath10k_start(struct ieee80211_hw *hw)
2052{
2053 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002054 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055
Michal Kazior548db542013-07-05 16:15:15 +03002056 mutex_lock(&ar->conf_mutex);
2057
Michal Kazioraffd3212013-07-16 09:54:35 +02002058 if (ar->state != ATH10K_STATE_OFF &&
2059 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002060 ret = -EINVAL;
2061 goto exit;
2062 }
2063
2064 ret = ath10k_hif_power_up(ar);
2065 if (ret) {
2066 ath10k_err("could not init hif (%d)\n", ret);
2067 ar->state = ATH10K_STATE_OFF;
2068 goto exit;
2069 }
2070
2071 ret = ath10k_core_start(ar);
2072 if (ret) {
2073 ath10k_err("could not init core (%d)\n", ret);
2074 ath10k_hif_power_down(ar);
2075 ar->state = ATH10K_STATE_OFF;
2076 goto exit;
2077 }
2078
Michal Kazioraffd3212013-07-16 09:54:35 +02002079 if (ar->state == ATH10K_STATE_OFF)
2080 ar->state = ATH10K_STATE_ON;
2081 else if (ar->state == ATH10K_STATE_RESTARTING)
2082 ar->state = ATH10K_STATE_RESTARTED;
2083
Bartosz Markowski226a3392013-09-26 17:47:16 +02002084 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085 if (ret)
2086 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2087 ret);
2088
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002089 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090 if (ret)
2091 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2092 ret);
2093
Michal Kaziorf7843d72013-07-16 09:38:52 +02002094 ath10k_regd_update(ar);
2095
Michal Kazior818bdd12013-07-16 09:38:57 +02002096exit:
Michal Kazior548db542013-07-05 16:15:15 +03002097 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002098 return 0;
2099}
2100
2101static void ath10k_stop(struct ieee80211_hw *hw)
2102{
2103 struct ath10k *ar = hw->priv;
2104
Michal Kazior548db542013-07-05 16:15:15 +03002105 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002106 if (ar->state == ATH10K_STATE_ON ||
2107 ar->state == ATH10K_STATE_RESTARTED ||
2108 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002109 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002110
Michal Kaziorf7843d72013-07-16 09:38:52 +02002111 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002112 mutex_unlock(&ar->conf_mutex);
2113
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002114 ath10k_mgmt_over_wmi_tx_purge(ar);
2115
Michal Kazior548db542013-07-05 16:15:15 +03002116 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002117 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002118 cancel_work_sync(&ar->restart_work);
2119}
2120
Michal Kaziorad088bf2013-10-16 15:44:46 +03002121static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002122{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002123 struct ath10k_vif *arvif;
2124 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002125
2126 lockdep_assert_held(&ar->conf_mutex);
2127
Michal Kaziorad088bf2013-10-16 15:44:46 +03002128 list_for_each_entry(arvif, &ar->arvifs, list) {
2129 ret = ath10k_mac_vif_setup_ps(arvif);
2130 if (ret) {
2131 ath10k_warn("could not setup powersave (%d)\n", ret);
2132 break;
2133 }
2134 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002135
Michal Kaziorad088bf2013-10-16 15:44:46 +03002136 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137}
2138
2139static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2140{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002141 struct ath10k *ar = hw->priv;
2142 struct ieee80211_conf *conf = &hw->conf;
2143 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002144 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002145
2146 mutex_lock(&ar->conf_mutex);
2147
2148 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002149 ath10k_dbg(ATH10K_DBG_MAC,
2150 "mac config channel %d mhz flags 0x%x\n",
2151 conf->chandef.chan->center_freq,
2152 conf->chandef.chan->flags);
2153
Kalle Valo5e3dd152013-06-12 20:52:10 +03002154 spin_lock_bh(&ar->data_lock);
2155 ar->rx_channel = conf->chandef.chan;
2156 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002157
2158 ath10k_config_radar_detection(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159 }
2160
Michal Kazior5474efe2013-10-23 04:02:15 -07002161 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2162 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2163 hw->conf.power_level);
2164
2165 param = ar->wmi.pdev_param->txpower_limit2g;
2166 ret = ath10k_wmi_pdev_set_param(ar, param,
2167 hw->conf.power_level * 2);
2168 if (ret)
2169 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2170 hw->conf.power_level, ret);
2171
2172 param = ar->wmi.pdev_param->txpower_limit5g;
2173 ret = ath10k_wmi_pdev_set_param(ar, param,
2174 hw->conf.power_level * 2);
2175 if (ret)
2176 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2177 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002178 }
2179
Michal Kazioraffd3212013-07-16 09:54:35 +02002180 if (changed & IEEE80211_CONF_CHANGE_PS)
2181 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182
2183 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2184 if (conf->flags & IEEE80211_CONF_MONITOR)
2185 ret = ath10k_monitor_create(ar);
2186 else
2187 ret = ath10k_monitor_destroy(ar);
2188 }
2189
2190 mutex_unlock(&ar->conf_mutex);
2191 return ret;
2192}
2193
2194/*
2195 * TODO:
2196 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2197 * because we will send mgmt frames without CCK. This requirement
2198 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2199 * in the TX packet.
2200 */
2201static int ath10k_add_interface(struct ieee80211_hw *hw,
2202 struct ieee80211_vif *vif)
2203{
2204 struct ath10k *ar = hw->priv;
2205 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2206 enum wmi_sta_powersave_param param;
2207 int ret = 0;
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002208 u32 value, param_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002210 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211
2212 mutex_lock(&ar->conf_mutex);
2213
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002214 memset(arvif, 0, sizeof(*arvif));
2215
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 arvif->ar = ar;
2217 arvif->vif = vif;
2218
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002219 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002220 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002221
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2223 ath10k_warn("Only one monitor interface allowed\n");
2224 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002225 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002226 }
2227
2228 bit = ffs(ar->free_vdev_map);
2229 if (bit == 0) {
2230 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002231 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232 }
2233
2234 arvif->vdev_id = bit - 1;
2235 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002236
2237 if (ar->p2p)
2238 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2239
2240 switch (vif->type) {
2241 case NL80211_IFTYPE_UNSPECIFIED:
2242 case NL80211_IFTYPE_STATION:
2243 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2244 if (vif->p2p)
2245 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2246 break;
2247 case NL80211_IFTYPE_ADHOC:
2248 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2249 break;
2250 case NL80211_IFTYPE_AP:
2251 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2252
2253 if (vif->p2p)
2254 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2255 break;
2256 case NL80211_IFTYPE_MONITOR:
2257 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2258 break;
2259 default:
2260 WARN_ON(1);
2261 break;
2262 }
2263
Kalle Valo60c3daa2013-09-08 17:56:07 +03002264 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002265 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2266
2267 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2268 arvif->vdev_subtype, vif->addr);
2269 if (ret) {
2270 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002271 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002272 }
2273
Michal Kazior9dad14a2013-10-16 15:44:45 +03002274 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002275 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002276
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002277 vdev_param = ar->wmi.vdev_param->def_keyid;
2278 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002279 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002280 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002282 goto err_vdev_delete;
2283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002285 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2286 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002288 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002289 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002290 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002291 goto err_vdev_delete;
2292 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002293
2294 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2295 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2296 if (ret) {
2297 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002298 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002300
2301 param_id = ar->wmi.pdev_param->sta_kickout_th;
2302
2303 /* Disable STA KICKOUT functionality in FW */
2304 ret = ath10k_wmi_pdev_set_param(ar, param_id, 0);
2305 if (ret)
2306 ath10k_warn("Failed to disable STA KICKOUT\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002307 }
2308
2309 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2310 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2311 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2312 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2313 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002314 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002315 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002316 goto err_peer_delete;
2317 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002318
2319 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2320 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2321 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2322 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002323 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002324 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002325 goto err_peer_delete;
2326 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327
2328 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2329 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2330 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2331 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002332 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002334 goto err_peer_delete;
2335 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336 }
2337
Michal Kazior424121c2013-07-22 14:13:31 +02002338 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002339 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002340 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2341 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002342 goto err_peer_delete;
2343 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002344
Michal Kazior424121c2013-07-22 14:13:31 +02002345 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002346 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002347 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2348 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002349 goto err_peer_delete;
2350 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002351
Kalle Valo5e3dd152013-06-12 20:52:10 +03002352 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2353 ar->monitor_present = true;
2354
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002356 return 0;
2357
2358err_peer_delete:
2359 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2360 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2361
2362err_vdev_delete:
2363 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2364 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002365 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002366
2367err:
2368 mutex_unlock(&ar->conf_mutex);
2369
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 return ret;
2371}
2372
2373static void ath10k_remove_interface(struct ieee80211_hw *hw,
2374 struct ieee80211_vif *vif)
2375{
2376 struct ath10k *ar = hw->priv;
2377 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2378 int ret;
2379
2380 mutex_lock(&ar->conf_mutex);
2381
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002382 cancel_work_sync(&arvif->wep_key_work);
2383
Michal Kaziored543882013-09-13 14:16:56 +02002384 spin_lock_bh(&ar->data_lock);
2385 if (arvif->beacon) {
2386 dev_kfree_skb_any(arvif->beacon);
2387 arvif->beacon = NULL;
2388 }
2389 spin_unlock_bh(&ar->data_lock);
2390
Kalle Valo5e3dd152013-06-12 20:52:10 +03002391 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002392 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002393
2394 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2395 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2396 if (ret)
2397 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2398
2399 kfree(arvif->u.ap.noa_data);
2400 }
2401
Kalle Valo60c3daa2013-09-08 17:56:07 +03002402 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2403 arvif->vdev_id);
2404
Kalle Valo5e3dd152013-06-12 20:52:10 +03002405 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2406 if (ret)
2407 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2408
2409 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2410 ar->monitor_present = false;
2411
2412 ath10k_peer_cleanup(ar, arvif->vdev_id);
2413
2414 mutex_unlock(&ar->conf_mutex);
2415}
2416
2417/*
2418 * FIXME: Has to be verified.
2419 */
2420#define SUPPORTED_FILTERS \
2421 (FIF_PROMISC_IN_BSS | \
2422 FIF_ALLMULTI | \
2423 FIF_CONTROL | \
2424 FIF_PSPOLL | \
2425 FIF_OTHER_BSS | \
2426 FIF_BCN_PRBRESP_PROMISC | \
2427 FIF_PROBE_REQ | \
2428 FIF_FCSFAIL)
2429
2430static void ath10k_configure_filter(struct ieee80211_hw *hw,
2431 unsigned int changed_flags,
2432 unsigned int *total_flags,
2433 u64 multicast)
2434{
2435 struct ath10k *ar = hw->priv;
2436 int ret;
2437
2438 mutex_lock(&ar->conf_mutex);
2439
2440 changed_flags &= SUPPORTED_FILTERS;
2441 *total_flags &= SUPPORTED_FILTERS;
2442 ar->filter_flags = *total_flags;
2443
Michal Kaziorafd09222013-10-16 16:45:41 +03002444 /* Monitor must not be started if it wasn't created first.
2445 * Promiscuous mode may be started on a non-monitor interface - in
2446 * such case the monitor vdev is not created so starting the
2447 * monitor makes no sense. Since ath10k uses no special RX filters
2448 * (only BSS filter in STA mode) there's no need for any special
2449 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002450 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002451 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002452 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2453 ar->monitor_vdev_id);
2454
Kalle Valo5e3dd152013-06-12 20:52:10 +03002455 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2456 if (ret)
2457 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002459 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002460 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2461 ar->monitor_vdev_id);
2462
Kalle Valo5e3dd152013-06-12 20:52:10 +03002463 ret = ath10k_monitor_stop(ar);
2464 if (ret)
2465 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466 }
2467
2468 mutex_unlock(&ar->conf_mutex);
2469}
2470
2471static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2472 struct ieee80211_vif *vif,
2473 struct ieee80211_bss_conf *info,
2474 u32 changed)
2475{
2476 struct ath10k *ar = hw->priv;
2477 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2478 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002479 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002480
2481 mutex_lock(&ar->conf_mutex);
2482
2483 if (changed & BSS_CHANGED_IBSS)
2484 ath10k_control_ibss(arvif, info, vif->addr);
2485
2486 if (changed & BSS_CHANGED_BEACON_INT) {
2487 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002488 vdev_param = ar->wmi.vdev_param->beacon_interval;
2489 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002491 ath10k_dbg(ATH10K_DBG_MAC,
2492 "mac vdev %d beacon_interval %d\n",
2493 arvif->vdev_id, arvif->beacon_interval);
2494
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495 if (ret)
2496 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2497 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002498 }
2499
2500 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002501 ath10k_dbg(ATH10K_DBG_MAC,
2502 "vdev %d set beacon tx mode to staggered\n",
2503 arvif->vdev_id);
2504
Bartosz Markowski226a3392013-09-26 17:47:16 +02002505 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2506 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507 WMI_BEACON_STAGGERED_MODE);
2508 if (ret)
2509 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2510 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002511 }
2512
John W. Linvilleb70727e2013-06-13 13:34:29 -04002513 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002514 arvif->dtim_period = info->dtim_period;
2515
Kalle Valo60c3daa2013-09-08 17:56:07 +03002516 ath10k_dbg(ATH10K_DBG_MAC,
2517 "mac vdev %d dtim_period %d\n",
2518 arvif->vdev_id, arvif->dtim_period);
2519
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002520 vdev_param = ar->wmi.vdev_param->dtim_period;
2521 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002522 arvif->dtim_period);
2523 if (ret)
2524 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2525 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002526 }
2527
2528 if (changed & BSS_CHANGED_SSID &&
2529 vif->type == NL80211_IFTYPE_AP) {
2530 arvif->u.ap.ssid_len = info->ssid_len;
2531 if (info->ssid_len)
2532 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2533 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2534 }
2535
2536 if (changed & BSS_CHANGED_BSSID) {
2537 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002538 ath10k_dbg(ATH10K_DBG_MAC,
2539 "mac vdev %d create peer %pM\n",
2540 arvif->vdev_id, info->bssid);
2541
Kalle Valo5e3dd152013-06-12 20:52:10 +03002542 ret = ath10k_peer_create(ar, arvif->vdev_id,
2543 info->bssid);
2544 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002545 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2546 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002547
2548 if (vif->type == NL80211_IFTYPE_STATION) {
2549 /*
2550 * this is never erased as we it for crypto key
2551 * clearing; this is FW requirement
2552 */
2553 memcpy(arvif->u.sta.bssid, info->bssid,
2554 ETH_ALEN);
2555
Kalle Valo60c3daa2013-09-08 17:56:07 +03002556 ath10k_dbg(ATH10K_DBG_MAC,
2557 "mac vdev %d start %pM\n",
2558 arvif->vdev_id, info->bssid);
2559
2560 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002561 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562 }
2563
2564 /*
2565 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2566 * so driver need to store it. It is needed when leaving
2567 * IBSS in order to remove BSSID peer.
2568 */
2569 if (vif->type == NL80211_IFTYPE_ADHOC)
2570 memcpy(arvif->u.ibss.bssid, info->bssid,
2571 ETH_ALEN);
2572 }
2573 }
2574
2575 if (changed & BSS_CHANGED_BEACON_ENABLED)
2576 ath10k_control_beaconing(arvif, info);
2577
2578 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2579 u32 cts_prot;
2580 if (info->use_cts_prot)
2581 cts_prot = 1;
2582 else
2583 cts_prot = 0;
2584
Kalle Valo60c3daa2013-09-08 17:56:07 +03002585 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2586 arvif->vdev_id, cts_prot);
2587
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002588 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2589 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590 cts_prot);
2591 if (ret)
2592 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2593 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002594 }
2595
2596 if (changed & BSS_CHANGED_ERP_SLOT) {
2597 u32 slottime;
2598 if (info->use_short_slot)
2599 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2600
2601 else
2602 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2603
Kalle Valo60c3daa2013-09-08 17:56:07 +03002604 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2605 arvif->vdev_id, slottime);
2606
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002607 vdev_param = ar->wmi.vdev_param->slot_time;
2608 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002609 slottime);
2610 if (ret)
2611 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2612 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002613 }
2614
2615 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2616 u32 preamble;
2617 if (info->use_short_preamble)
2618 preamble = WMI_VDEV_PREAMBLE_SHORT;
2619 else
2620 preamble = WMI_VDEV_PREAMBLE_LONG;
2621
Kalle Valo60c3daa2013-09-08 17:56:07 +03002622 ath10k_dbg(ATH10K_DBG_MAC,
2623 "mac vdev %d preamble %dn",
2624 arvif->vdev_id, preamble);
2625
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002626 vdev_param = ar->wmi.vdev_param->preamble;
2627 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002628 preamble);
2629 if (ret)
2630 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2631 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002632 }
2633
2634 if (changed & BSS_CHANGED_ASSOC) {
2635 if (info->assoc)
2636 ath10k_bss_assoc(hw, vif, info);
2637 }
2638
2639 mutex_unlock(&ar->conf_mutex);
2640}
2641
2642static int ath10k_hw_scan(struct ieee80211_hw *hw,
2643 struct ieee80211_vif *vif,
2644 struct cfg80211_scan_request *req)
2645{
2646 struct ath10k *ar = hw->priv;
2647 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2648 struct wmi_start_scan_arg arg;
2649 int ret = 0;
2650 int i;
2651
2652 mutex_lock(&ar->conf_mutex);
2653
2654 spin_lock_bh(&ar->data_lock);
2655 if (ar->scan.in_progress) {
2656 spin_unlock_bh(&ar->data_lock);
2657 ret = -EBUSY;
2658 goto exit;
2659 }
2660
Wolfram Sang16735d02013-11-14 14:32:02 -08002661 reinit_completion(&ar->scan.started);
2662 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 ar->scan.in_progress = true;
2664 ar->scan.aborting = false;
2665 ar->scan.is_roc = false;
2666 ar->scan.vdev_id = arvif->vdev_id;
2667 spin_unlock_bh(&ar->data_lock);
2668
2669 memset(&arg, 0, sizeof(arg));
2670 ath10k_wmi_start_scan_init(ar, &arg);
2671 arg.vdev_id = arvif->vdev_id;
2672 arg.scan_id = ATH10K_SCAN_ID;
2673
2674 if (!req->no_cck)
2675 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2676
2677 if (req->ie_len) {
2678 arg.ie_len = req->ie_len;
2679 memcpy(arg.ie, req->ie, arg.ie_len);
2680 }
2681
2682 if (req->n_ssids) {
2683 arg.n_ssids = req->n_ssids;
2684 for (i = 0; i < arg.n_ssids; i++) {
2685 arg.ssids[i].len = req->ssids[i].ssid_len;
2686 arg.ssids[i].ssid = req->ssids[i].ssid;
2687 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002688 } else {
2689 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690 }
2691
2692 if (req->n_channels) {
2693 arg.n_channels = req->n_channels;
2694 for (i = 0; i < arg.n_channels; i++)
2695 arg.channels[i] = req->channels[i]->center_freq;
2696 }
2697
2698 ret = ath10k_start_scan(ar, &arg);
2699 if (ret) {
2700 ath10k_warn("could not start hw scan (%d)\n", ret);
2701 spin_lock_bh(&ar->data_lock);
2702 ar->scan.in_progress = false;
2703 spin_unlock_bh(&ar->data_lock);
2704 }
2705
2706exit:
2707 mutex_unlock(&ar->conf_mutex);
2708 return ret;
2709}
2710
2711static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2712 struct ieee80211_vif *vif)
2713{
2714 struct ath10k *ar = hw->priv;
2715 int ret;
2716
2717 mutex_lock(&ar->conf_mutex);
2718 ret = ath10k_abort_scan(ar);
2719 if (ret) {
2720 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2721 ret);
2722 ieee80211_scan_completed(hw, 1 /* aborted */);
2723 }
2724 mutex_unlock(&ar->conf_mutex);
2725}
2726
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002727static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2728 struct ath10k_vif *arvif,
2729 enum set_key_cmd cmd,
2730 struct ieee80211_key_conf *key)
2731{
2732 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2733 int ret;
2734
2735 /* 10.1 firmware branch requires default key index to be set to group
2736 * key index after installing it. Otherwise FW/HW Txes corrupted
2737 * frames with multi-vif APs. This is not required for main firmware
2738 * branch (e.g. 636).
2739 *
2740 * FIXME: This has been tested only in AP. It remains unknown if this
2741 * is required for multi-vif STA interfaces on 10.1 */
2742
2743 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2744 return;
2745
2746 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2747 return;
2748
2749 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2750 return;
2751
2752 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2753 return;
2754
2755 if (cmd != SET_KEY)
2756 return;
2757
2758 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2759 key->keyidx);
2760 if (ret)
2761 ath10k_warn("failed to set group key as default key: %d\n",
2762 ret);
2763}
2764
Kalle Valo5e3dd152013-06-12 20:52:10 +03002765static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2766 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2767 struct ieee80211_key_conf *key)
2768{
2769 struct ath10k *ar = hw->priv;
2770 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2771 struct ath10k_peer *peer;
2772 const u8 *peer_addr;
2773 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2774 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2775 int ret = 0;
2776
2777 if (key->keyidx > WMI_MAX_KEY_INDEX)
2778 return -ENOSPC;
2779
2780 mutex_lock(&ar->conf_mutex);
2781
2782 if (sta)
2783 peer_addr = sta->addr;
2784 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2785 peer_addr = vif->bss_conf.bssid;
2786 else
2787 peer_addr = vif->addr;
2788
2789 key->hw_key_idx = key->keyidx;
2790
2791 /* the peer should not disappear in mid-way (unless FW goes awry) since
2792 * we already hold conf_mutex. we just make sure its there now. */
2793 spin_lock_bh(&ar->data_lock);
2794 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2795 spin_unlock_bh(&ar->data_lock);
2796
2797 if (!peer) {
2798 if (cmd == SET_KEY) {
2799 ath10k_warn("cannot install key for non-existent peer %pM\n",
2800 peer_addr);
2801 ret = -EOPNOTSUPP;
2802 goto exit;
2803 } else {
2804 /* if the peer doesn't exist there is no key to disable
2805 * anymore */
2806 goto exit;
2807 }
2808 }
2809
2810 if (is_wep) {
2811 if (cmd == SET_KEY)
2812 arvif->wep_keys[key->keyidx] = key;
2813 else
2814 arvif->wep_keys[key->keyidx] = NULL;
2815
2816 if (cmd == DISABLE_KEY)
2817 ath10k_clear_vdev_key(arvif, key);
2818 }
2819
2820 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2821 if (ret) {
2822 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2823 goto exit;
2824 }
2825
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002826 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
2827
Kalle Valo5e3dd152013-06-12 20:52:10 +03002828 spin_lock_bh(&ar->data_lock);
2829 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2830 if (peer && cmd == SET_KEY)
2831 peer->keys[key->keyidx] = key;
2832 else if (peer && cmd == DISABLE_KEY)
2833 peer->keys[key->keyidx] = NULL;
2834 else if (peer == NULL)
2835 /* impossible unless FW goes crazy */
2836 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2837 spin_unlock_bh(&ar->data_lock);
2838
2839exit:
2840 mutex_unlock(&ar->conf_mutex);
2841 return ret;
2842}
2843
2844static int ath10k_sta_state(struct ieee80211_hw *hw,
2845 struct ieee80211_vif *vif,
2846 struct ieee80211_sta *sta,
2847 enum ieee80211_sta_state old_state,
2848 enum ieee80211_sta_state new_state)
2849{
2850 struct ath10k *ar = hw->priv;
2851 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2852 int ret = 0;
2853
2854 mutex_lock(&ar->conf_mutex);
2855
2856 if (old_state == IEEE80211_STA_NOTEXIST &&
2857 new_state == IEEE80211_STA_NONE &&
2858 vif->type != NL80211_IFTYPE_STATION) {
2859 /*
2860 * New station addition.
2861 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002862 ath10k_dbg(ATH10K_DBG_MAC,
2863 "mac vdev %d peer create %pM (new sta)\n",
2864 arvif->vdev_id, sta->addr);
2865
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2867 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002868 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
2869 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002870 } else if ((old_state == IEEE80211_STA_NONE &&
2871 new_state == IEEE80211_STA_NOTEXIST)) {
2872 /*
2873 * Existing station deletion.
2874 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002875 ath10k_dbg(ATH10K_DBG_MAC,
2876 "mac vdev %d peer delete %pM (sta gone)\n",
2877 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002878 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2879 if (ret)
2880 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2881 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002882
2883 if (vif->type == NL80211_IFTYPE_STATION)
2884 ath10k_bss_disassoc(hw, vif);
2885 } else if (old_state == IEEE80211_STA_AUTH &&
2886 new_state == IEEE80211_STA_ASSOC &&
2887 (vif->type == NL80211_IFTYPE_AP ||
2888 vif->type == NL80211_IFTYPE_ADHOC)) {
2889 /*
2890 * New association.
2891 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002892 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2893 sta->addr);
2894
Kalle Valo5e3dd152013-06-12 20:52:10 +03002895 ret = ath10k_station_assoc(ar, arvif, sta);
2896 if (ret)
2897 ath10k_warn("Failed to associate station: %pM\n",
2898 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002899 } else if (old_state == IEEE80211_STA_ASSOC &&
2900 new_state == IEEE80211_STA_AUTH &&
2901 (vif->type == NL80211_IFTYPE_AP ||
2902 vif->type == NL80211_IFTYPE_ADHOC)) {
2903 /*
2904 * Disassociation.
2905 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002906 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2907 sta->addr);
2908
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909 ret = ath10k_station_disassoc(ar, arvif, sta);
2910 if (ret)
2911 ath10k_warn("Failed to disassociate station: %pM\n",
2912 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002913 }
2914
2915 mutex_unlock(&ar->conf_mutex);
2916 return ret;
2917}
2918
2919static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2920 u16 ac, bool enable)
2921{
2922 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2923 u32 value = 0;
2924 int ret = 0;
2925
Michal Kazior548db542013-07-05 16:15:15 +03002926 lockdep_assert_held(&ar->conf_mutex);
2927
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2929 return 0;
2930
2931 switch (ac) {
2932 case IEEE80211_AC_VO:
2933 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2934 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2935 break;
2936 case IEEE80211_AC_VI:
2937 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2938 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2939 break;
2940 case IEEE80211_AC_BE:
2941 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2942 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2943 break;
2944 case IEEE80211_AC_BK:
2945 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2946 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2947 break;
2948 }
2949
2950 if (enable)
2951 arvif->u.sta.uapsd |= value;
2952 else
2953 arvif->u.sta.uapsd &= ~value;
2954
2955 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2956 WMI_STA_PS_PARAM_UAPSD,
2957 arvif->u.sta.uapsd);
2958 if (ret) {
2959 ath10k_warn("could not set uapsd params %d\n", ret);
2960 goto exit;
2961 }
2962
2963 if (arvif->u.sta.uapsd)
2964 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2965 else
2966 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2967
2968 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2969 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2970 value);
2971 if (ret)
2972 ath10k_warn("could not set rx wake param %d\n", ret);
2973
2974exit:
2975 return ret;
2976}
2977
2978static int ath10k_conf_tx(struct ieee80211_hw *hw,
2979 struct ieee80211_vif *vif, u16 ac,
2980 const struct ieee80211_tx_queue_params *params)
2981{
2982 struct ath10k *ar = hw->priv;
2983 struct wmi_wmm_params_arg *p = NULL;
2984 int ret;
2985
2986 mutex_lock(&ar->conf_mutex);
2987
2988 switch (ac) {
2989 case IEEE80211_AC_VO:
2990 p = &ar->wmm_params.ac_vo;
2991 break;
2992 case IEEE80211_AC_VI:
2993 p = &ar->wmm_params.ac_vi;
2994 break;
2995 case IEEE80211_AC_BE:
2996 p = &ar->wmm_params.ac_be;
2997 break;
2998 case IEEE80211_AC_BK:
2999 p = &ar->wmm_params.ac_bk;
3000 break;
3001 }
3002
3003 if (WARN_ON(!p)) {
3004 ret = -EINVAL;
3005 goto exit;
3006 }
3007
3008 p->cwmin = params->cw_min;
3009 p->cwmax = params->cw_max;
3010 p->aifs = params->aifs;
3011
3012 /*
3013 * The channel time duration programmed in the HW is in absolute
3014 * microseconds, while mac80211 gives the txop in units of
3015 * 32 microseconds.
3016 */
3017 p->txop = params->txop * 32;
3018
3019 /* FIXME: FW accepts wmm params per hw, not per vif */
3020 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3021 if (ret) {
3022 ath10k_warn("could not set wmm params %d\n", ret);
3023 goto exit;
3024 }
3025
3026 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3027 if (ret)
3028 ath10k_warn("could not set sta uapsd %d\n", ret);
3029
3030exit:
3031 mutex_unlock(&ar->conf_mutex);
3032 return ret;
3033}
3034
3035#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3036
3037static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3038 struct ieee80211_vif *vif,
3039 struct ieee80211_channel *chan,
3040 int duration,
3041 enum ieee80211_roc_type type)
3042{
3043 struct ath10k *ar = hw->priv;
3044 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3045 struct wmi_start_scan_arg arg;
3046 int ret;
3047
3048 mutex_lock(&ar->conf_mutex);
3049
3050 spin_lock_bh(&ar->data_lock);
3051 if (ar->scan.in_progress) {
3052 spin_unlock_bh(&ar->data_lock);
3053 ret = -EBUSY;
3054 goto exit;
3055 }
3056
Wolfram Sang16735d02013-11-14 14:32:02 -08003057 reinit_completion(&ar->scan.started);
3058 reinit_completion(&ar->scan.completed);
3059 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003060 ar->scan.in_progress = true;
3061 ar->scan.aborting = false;
3062 ar->scan.is_roc = true;
3063 ar->scan.vdev_id = arvif->vdev_id;
3064 ar->scan.roc_freq = chan->center_freq;
3065 spin_unlock_bh(&ar->data_lock);
3066
3067 memset(&arg, 0, sizeof(arg));
3068 ath10k_wmi_start_scan_init(ar, &arg);
3069 arg.vdev_id = arvif->vdev_id;
3070 arg.scan_id = ATH10K_SCAN_ID;
3071 arg.n_channels = 1;
3072 arg.channels[0] = chan->center_freq;
3073 arg.dwell_time_active = duration;
3074 arg.dwell_time_passive = duration;
3075 arg.max_scan_time = 2 * duration;
3076 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3077 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3078
3079 ret = ath10k_start_scan(ar, &arg);
3080 if (ret) {
3081 ath10k_warn("could not start roc scan (%d)\n", ret);
3082 spin_lock_bh(&ar->data_lock);
3083 ar->scan.in_progress = false;
3084 spin_unlock_bh(&ar->data_lock);
3085 goto exit;
3086 }
3087
3088 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3089 if (ret == 0) {
3090 ath10k_warn("could not switch to channel for roc scan\n");
3091 ath10k_abort_scan(ar);
3092 ret = -ETIMEDOUT;
3093 goto exit;
3094 }
3095
3096 ret = 0;
3097exit:
3098 mutex_unlock(&ar->conf_mutex);
3099 return ret;
3100}
3101
3102static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3103{
3104 struct ath10k *ar = hw->priv;
3105
3106 mutex_lock(&ar->conf_mutex);
3107 ath10k_abort_scan(ar);
3108 mutex_unlock(&ar->conf_mutex);
3109
3110 return 0;
3111}
3112
3113/*
3114 * Both RTS and Fragmentation threshold are interface-specific
3115 * in ath10k, but device-specific in mac80211.
3116 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003117
3118static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3119{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003120 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003121 struct ath10k_vif *arvif;
3122 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003123
Michal Kaziorad088bf2013-10-16 15:44:46 +03003124 mutex_lock(&ar->conf_mutex);
3125 list_for_each_entry(arvif, &ar->arvifs, list) {
3126 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3127 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003128
Michal Kaziorad088bf2013-10-16 15:44:46 +03003129 ret = ath10k_mac_set_rts(arvif, value);
3130 if (ret) {
3131 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3132 arvif->vdev_id, ret);
3133 break;
3134 }
3135 }
3136 mutex_unlock(&ar->conf_mutex);
3137
3138 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139}
3140
3141static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3142{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003143 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003144 struct ath10k_vif *arvif;
3145 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146
Kalle Valo5e3dd152013-06-12 20:52:10 +03003147 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003148 list_for_each_entry(arvif, &ar->arvifs, list) {
3149 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3150 arvif->vdev_id, value);
3151
3152 ret = ath10k_mac_set_rts(arvif, value);
3153 if (ret) {
3154 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3155 arvif->vdev_id, ret);
3156 break;
3157 }
3158 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003159 mutex_unlock(&ar->conf_mutex);
3160
Michal Kaziorad088bf2013-10-16 15:44:46 +03003161 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003162}
3163
3164static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3165{
3166 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003167 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168 int ret;
3169
3170 /* mac80211 doesn't care if we really xmit queued frames or not
3171 * we'll collect those frames either way if we stop/delete vdevs */
3172 if (drop)
3173 return;
3174
Michal Kazior548db542013-07-05 16:15:15 +03003175 mutex_lock(&ar->conf_mutex);
3176
Michal Kazioraffd3212013-07-16 09:54:35 +02003177 if (ar->state == ATH10K_STATE_WEDGED)
3178 goto skip;
3179
Michal Kazioredb82362013-07-05 16:15:14 +03003180 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003182
Michal Kazioredb82362013-07-05 16:15:14 +03003183 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003184 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003185 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003186
3187 skip = (ar->state == ATH10K_STATE_WEDGED);
3188
3189 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003191
3192 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003193 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003194
Michal Kazioraffd3212013-07-16 09:54:35 +02003195skip:
Michal Kazior548db542013-07-05 16:15:15 +03003196 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197}
3198
3199/* TODO: Implement this function properly
3200 * For now it is needed to reply to Probe Requests in IBSS mode.
3201 * Propably we need this information from FW.
3202 */
3203static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3204{
3205 return 1;
3206}
3207
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003208#ifdef CONFIG_PM
3209static int ath10k_suspend(struct ieee80211_hw *hw,
3210 struct cfg80211_wowlan *wowlan)
3211{
3212 struct ath10k *ar = hw->priv;
3213 int ret;
3214
3215 ar->is_target_paused = false;
3216
3217 ret = ath10k_wmi_pdev_suspend_target(ar);
3218 if (ret) {
3219 ath10k_warn("could not suspend target (%d)\n", ret);
3220 return 1;
3221 }
3222
3223 ret = wait_event_interruptible_timeout(ar->event_queue,
3224 ar->is_target_paused == true,
3225 1 * HZ);
3226 if (ret < 0) {
3227 ath10k_warn("suspend interrupted (%d)\n", ret);
3228 goto resume;
3229 } else if (ret == 0) {
3230 ath10k_warn("suspend timed out - target pause event never came\n");
3231 goto resume;
3232 }
3233
3234 ret = ath10k_hif_suspend(ar);
3235 if (ret) {
3236 ath10k_warn("could not suspend hif (%d)\n", ret);
3237 goto resume;
3238 }
3239
3240 return 0;
3241resume:
3242 ret = ath10k_wmi_pdev_resume_target(ar);
3243 if (ret)
3244 ath10k_warn("could not resume target (%d)\n", ret);
3245 return 1;
3246}
3247
3248static int ath10k_resume(struct ieee80211_hw *hw)
3249{
3250 struct ath10k *ar = hw->priv;
3251 int ret;
3252
3253 ret = ath10k_hif_resume(ar);
3254 if (ret) {
3255 ath10k_warn("could not resume hif (%d)\n", ret);
3256 return 1;
3257 }
3258
3259 ret = ath10k_wmi_pdev_resume_target(ar);
3260 if (ret) {
3261 ath10k_warn("could not resume target (%d)\n", ret);
3262 return 1;
3263 }
3264
3265 return 0;
3266}
3267#endif
3268
Michal Kazioraffd3212013-07-16 09:54:35 +02003269static void ath10k_restart_complete(struct ieee80211_hw *hw)
3270{
3271 struct ath10k *ar = hw->priv;
3272
3273 mutex_lock(&ar->conf_mutex);
3274
3275 /* If device failed to restart it will be in a different state, e.g.
3276 * ATH10K_STATE_WEDGED */
3277 if (ar->state == ATH10K_STATE_RESTARTED) {
3278 ath10k_info("device successfully recovered\n");
3279 ar->state = ATH10K_STATE_ON;
3280 }
3281
3282 mutex_unlock(&ar->conf_mutex);
3283}
3284
Michal Kazior2e1dea42013-07-31 10:32:40 +02003285static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3286 struct survey_info *survey)
3287{
3288 struct ath10k *ar = hw->priv;
3289 struct ieee80211_supported_band *sband;
3290 struct survey_info *ar_survey = &ar->survey[idx];
3291 int ret = 0;
3292
3293 mutex_lock(&ar->conf_mutex);
3294
3295 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3296 if (sband && idx >= sband->n_channels) {
3297 idx -= sband->n_channels;
3298 sband = NULL;
3299 }
3300
3301 if (!sband)
3302 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3303
3304 if (!sband || idx >= sband->n_channels) {
3305 ret = -ENOENT;
3306 goto exit;
3307 }
3308
3309 spin_lock_bh(&ar->data_lock);
3310 memcpy(survey, ar_survey, sizeof(*survey));
3311 spin_unlock_bh(&ar->data_lock);
3312
3313 survey->channel = &sband->channels[idx];
3314
3315exit:
3316 mutex_unlock(&ar->conf_mutex);
3317 return ret;
3318}
3319
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320static const struct ieee80211_ops ath10k_ops = {
3321 .tx = ath10k_tx,
3322 .start = ath10k_start,
3323 .stop = ath10k_stop,
3324 .config = ath10k_config,
3325 .add_interface = ath10k_add_interface,
3326 .remove_interface = ath10k_remove_interface,
3327 .configure_filter = ath10k_configure_filter,
3328 .bss_info_changed = ath10k_bss_info_changed,
3329 .hw_scan = ath10k_hw_scan,
3330 .cancel_hw_scan = ath10k_cancel_hw_scan,
3331 .set_key = ath10k_set_key,
3332 .sta_state = ath10k_sta_state,
3333 .conf_tx = ath10k_conf_tx,
3334 .remain_on_channel = ath10k_remain_on_channel,
3335 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3336 .set_rts_threshold = ath10k_set_rts_threshold,
3337 .set_frag_threshold = ath10k_set_frag_threshold,
3338 .flush = ath10k_flush,
3339 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003340 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003341 .get_survey = ath10k_get_survey,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003342#ifdef CONFIG_PM
3343 .suspend = ath10k_suspend,
3344 .resume = ath10k_resume,
3345#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003346};
3347
3348#define RATETAB_ENT(_rate, _rateid, _flags) { \
3349 .bitrate = (_rate), \
3350 .flags = (_flags), \
3351 .hw_value = (_rateid), \
3352}
3353
3354#define CHAN2G(_channel, _freq, _flags) { \
3355 .band = IEEE80211_BAND_2GHZ, \
3356 .hw_value = (_channel), \
3357 .center_freq = (_freq), \
3358 .flags = (_flags), \
3359 .max_antenna_gain = 0, \
3360 .max_power = 30, \
3361}
3362
3363#define CHAN5G(_channel, _freq, _flags) { \
3364 .band = IEEE80211_BAND_5GHZ, \
3365 .hw_value = (_channel), \
3366 .center_freq = (_freq), \
3367 .flags = (_flags), \
3368 .max_antenna_gain = 0, \
3369 .max_power = 30, \
3370}
3371
3372static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3373 CHAN2G(1, 2412, 0),
3374 CHAN2G(2, 2417, 0),
3375 CHAN2G(3, 2422, 0),
3376 CHAN2G(4, 2427, 0),
3377 CHAN2G(5, 2432, 0),
3378 CHAN2G(6, 2437, 0),
3379 CHAN2G(7, 2442, 0),
3380 CHAN2G(8, 2447, 0),
3381 CHAN2G(9, 2452, 0),
3382 CHAN2G(10, 2457, 0),
3383 CHAN2G(11, 2462, 0),
3384 CHAN2G(12, 2467, 0),
3385 CHAN2G(13, 2472, 0),
3386 CHAN2G(14, 2484, 0),
3387};
3388
3389static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003390 CHAN5G(36, 5180, 0),
3391 CHAN5G(40, 5200, 0),
3392 CHAN5G(44, 5220, 0),
3393 CHAN5G(48, 5240, 0),
3394 CHAN5G(52, 5260, 0),
3395 CHAN5G(56, 5280, 0),
3396 CHAN5G(60, 5300, 0),
3397 CHAN5G(64, 5320, 0),
3398 CHAN5G(100, 5500, 0),
3399 CHAN5G(104, 5520, 0),
3400 CHAN5G(108, 5540, 0),
3401 CHAN5G(112, 5560, 0),
3402 CHAN5G(116, 5580, 0),
3403 CHAN5G(120, 5600, 0),
3404 CHAN5G(124, 5620, 0),
3405 CHAN5G(128, 5640, 0),
3406 CHAN5G(132, 5660, 0),
3407 CHAN5G(136, 5680, 0),
3408 CHAN5G(140, 5700, 0),
3409 CHAN5G(149, 5745, 0),
3410 CHAN5G(153, 5765, 0),
3411 CHAN5G(157, 5785, 0),
3412 CHAN5G(161, 5805, 0),
3413 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003414};
3415
3416static struct ieee80211_rate ath10k_rates[] = {
3417 /* CCK */
3418 RATETAB_ENT(10, 0x82, 0),
3419 RATETAB_ENT(20, 0x84, 0),
3420 RATETAB_ENT(55, 0x8b, 0),
3421 RATETAB_ENT(110, 0x96, 0),
3422 /* OFDM */
3423 RATETAB_ENT(60, 0x0c, 0),
3424 RATETAB_ENT(90, 0x12, 0),
3425 RATETAB_ENT(120, 0x18, 0),
3426 RATETAB_ENT(180, 0x24, 0),
3427 RATETAB_ENT(240, 0x30, 0),
3428 RATETAB_ENT(360, 0x48, 0),
3429 RATETAB_ENT(480, 0x60, 0),
3430 RATETAB_ENT(540, 0x6c, 0),
3431};
3432
3433#define ath10k_a_rates (ath10k_rates + 4)
3434#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3435#define ath10k_g_rates (ath10k_rates + 0)
3436#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3437
3438struct ath10k *ath10k_mac_create(void)
3439{
3440 struct ieee80211_hw *hw;
3441 struct ath10k *ar;
3442
3443 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3444 if (!hw)
3445 return NULL;
3446
3447 ar = hw->priv;
3448 ar->hw = hw;
3449
3450 return ar;
3451}
3452
3453void ath10k_mac_destroy(struct ath10k *ar)
3454{
3455 ieee80211_free_hw(ar->hw);
3456}
3457
3458static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3459 {
3460 .max = 8,
3461 .types = BIT(NL80211_IFTYPE_STATION)
3462 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003463 },
3464 {
3465 .max = 3,
3466 .types = BIT(NL80211_IFTYPE_P2P_GO)
3467 },
3468 {
3469 .max = 7,
3470 .types = BIT(NL80211_IFTYPE_AP)
3471 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003472};
3473
Bartosz Markowskif2595092013-12-10 16:20:39 +01003474static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003475 {
3476 .max = 8,
3477 .types = BIT(NL80211_IFTYPE_AP)
3478 },
3479};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003480
3481static const struct ieee80211_iface_combination ath10k_if_comb[] = {
3482 {
3483 .limits = ath10k_if_limits,
3484 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3485 .max_interfaces = 8,
3486 .num_different_channels = 1,
3487 .beacon_int_infra_match = true,
3488 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01003489};
3490
3491static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003492 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01003493 .limits = ath10k_10x_if_limits,
3494 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003495 .max_interfaces = 8,
3496 .num_different_channels = 1,
3497 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01003498#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003499 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
3500 BIT(NL80211_CHAN_WIDTH_20) |
3501 BIT(NL80211_CHAN_WIDTH_40) |
3502 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003503#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01003504 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003505};
3506
3507static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3508{
3509 struct ieee80211_sta_vht_cap vht_cap = {0};
3510 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003511 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003512
3513 vht_cap.vht_supported = 1;
3514 vht_cap.cap = ar->vht_cap_info;
3515
Michal Kazior8865bee42013-07-24 12:36:46 +02003516 mcs_map = 0;
3517 for (i = 0; i < 8; i++) {
3518 if (i < ar->num_rf_chains)
3519 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3520 else
3521 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3522 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003523
3524 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3525 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3526
3527 return vht_cap;
3528}
3529
3530static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3531{
3532 int i;
3533 struct ieee80211_sta_ht_cap ht_cap = {0};
3534
3535 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3536 return ht_cap;
3537
3538 ht_cap.ht_supported = 1;
3539 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3540 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3541 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3542 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3543 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3544
3545 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3546 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3547
3548 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3549 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3550
3551 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3552 u32 smps;
3553
3554 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3555 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3556
3557 ht_cap.cap |= smps;
3558 }
3559
3560 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3561 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3562
3563 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3564 u32 stbc;
3565
3566 stbc = ar->ht_cap_info;
3567 stbc &= WMI_HT_CAP_RX_STBC;
3568 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3569 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3570 stbc &= IEEE80211_HT_CAP_RX_STBC;
3571
3572 ht_cap.cap |= stbc;
3573 }
3574
3575 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3576 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3577
3578 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3579 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3580
3581 /* max AMSDU is implicitly taken from vht_cap_info */
3582 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3583 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3584
Michal Kazior8865bee42013-07-24 12:36:46 +02003585 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 ht_cap.mcs.rx_mask[i] = 0xFF;
3587
3588 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3589
3590 return ht_cap;
3591}
3592
3593
3594static void ath10k_get_arvif_iter(void *data, u8 *mac,
3595 struct ieee80211_vif *vif)
3596{
3597 struct ath10k_vif_iter *arvif_iter = data;
3598 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3599
3600 if (arvif->vdev_id == arvif_iter->vdev_id)
3601 arvif_iter->arvif = arvif;
3602}
3603
3604struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3605{
3606 struct ath10k_vif_iter arvif_iter;
3607 u32 flags;
3608
3609 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3610 arvif_iter.vdev_id = vdev_id;
3611
3612 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3613 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3614 flags,
3615 ath10k_get_arvif_iter,
3616 &arvif_iter);
3617 if (!arvif_iter.arvif) {
3618 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3619 return NULL;
3620 }
3621
3622 return arvif_iter.arvif;
3623}
3624
3625int ath10k_mac_register(struct ath10k *ar)
3626{
3627 struct ieee80211_supported_band *band;
3628 struct ieee80211_sta_vht_cap vht_cap;
3629 struct ieee80211_sta_ht_cap ht_cap;
3630 void *channels;
3631 int ret;
3632
3633 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3634
3635 SET_IEEE80211_DEV(ar->hw, ar->dev);
3636
3637 ht_cap = ath10k_get_ht_cap(ar);
3638 vht_cap = ath10k_create_vht_cap(ar);
3639
3640 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3641 channels = kmemdup(ath10k_2ghz_channels,
3642 sizeof(ath10k_2ghz_channels),
3643 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02003644 if (!channels) {
3645 ret = -ENOMEM;
3646 goto err_free;
3647 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003648
3649 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3650 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3651 band->channels = channels;
3652 band->n_bitrates = ath10k_g_rates_size;
3653 band->bitrates = ath10k_g_rates;
3654 band->ht_cap = ht_cap;
3655
3656 /* vht is not supported in 2.4 GHz */
3657
3658 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3659 }
3660
3661 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3662 channels = kmemdup(ath10k_5ghz_channels,
3663 sizeof(ath10k_5ghz_channels),
3664 GFP_KERNEL);
3665 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02003666 ret = -ENOMEM;
3667 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003668 }
3669
3670 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3671 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3672 band->channels = channels;
3673 band->n_bitrates = ath10k_a_rates_size;
3674 band->bitrates = ath10k_a_rates;
3675 band->ht_cap = ht_cap;
3676 band->vht_cap = vht_cap;
3677 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3678 }
3679
3680 ar->hw->wiphy->interface_modes =
3681 BIT(NL80211_IFTYPE_STATION) |
3682 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01003683 BIT(NL80211_IFTYPE_AP);
3684
3685 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
3686 ar->hw->wiphy->interface_modes |=
3687 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3688 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003689
3690 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3691 IEEE80211_HW_SUPPORTS_PS |
3692 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3693 IEEE80211_HW_SUPPORTS_UAPSD |
3694 IEEE80211_HW_MFP_CAPABLE |
3695 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3696 IEEE80211_HW_HAS_RATE_CONTROL |
3697 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3698 IEEE80211_HW_WANT_MONITOR_VIF |
3699 IEEE80211_HW_AP_LINK_PS;
3700
Michal Kazior1f8bb152013-09-18 14:43:22 +02003701 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3702 * bytes is used for padding/alignment if necessary. */
3703 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3704
Kalle Valo5e3dd152013-06-12 20:52:10 +03003705 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3706 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3707
3708 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3709 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3710 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3711 }
3712
3713 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3714 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3715
3716 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3717
3718 ar->hw->channel_change_time = 5000;
3719 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3720
3721 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3722 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3723
3724 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3725 /*
3726 * on LL hardware queues are managed entirely by the FW
3727 * so we only advertise to mac we can do the queues thing
3728 */
3729 ar->hw->queues = 4;
3730
Bartosz Markowskif2595092013-12-10 16:20:39 +01003731 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3732 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
3733 ar->hw->wiphy->n_iface_combinations =
3734 ARRAY_SIZE(ath10k_10x_if_comb);
3735 } else {
3736 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
3737 ar->hw->wiphy->n_iface_combinations =
3738 ARRAY_SIZE(ath10k_if_comb);
3739 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003740
Michal Kazior7c199992013-07-31 10:47:57 +02003741 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3742
Janusz Dziedzic9702c682013-11-20 09:59:41 +02003743 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
3744 /* Init ath dfs pattern detector */
3745 ar->ath_common.debug_mask = ATH_DBG_DFS;
3746 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
3747 NL80211_DFS_UNSET);
3748
3749 if (!ar->dfs_detector)
3750 ath10k_warn("dfs pattern detector init failed\n");
3751 }
3752
Kalle Valo5e3dd152013-06-12 20:52:10 +03003753 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3754 ath10k_reg_notifier);
3755 if (ret) {
3756 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02003757 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003758 }
3759
3760 ret = ieee80211_register_hw(ar->hw);
3761 if (ret) {
3762 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02003763 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003764 }
3765
3766 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3767 ret = regulatory_hint(ar->hw->wiphy,
3768 ar->ath_common.regulatory.alpha2);
3769 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02003770 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003771 }
3772
3773 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02003774
3775err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003776 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02003777err_free:
3778 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3779 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3780
Kalle Valo5e3dd152013-06-12 20:52:10 +03003781 return ret;
3782}
3783
3784void ath10k_mac_unregister(struct ath10k *ar)
3785{
3786 ieee80211_unregister_hw(ar->hw);
3787
Janusz Dziedzic9702c682013-11-20 09:59:41 +02003788 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
3789 ar->dfs_detector->exit(ar->dfs_detector);
3790
Kalle Valo5e3dd152013-06-12 20:52:10 +03003791 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3792 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3793
3794 SET_IEEE80211_DEV(ar->hw, NULL);
3795}