blob: b70a3b2f9f466fece3ec83652d55352760cc5c3c [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
71 break;
72 default:
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
88 const u8 *macaddr)
89{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Kalle Valo5e3dd152013-06-12 20:52:10 +030095 INIT_COMPLETION(ar->install_key_done);
96
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
98 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
128
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 addr);
131 if (ret)
132 return ret;
133
134 peer->keys[i] = arvif->wep_keys[i];
135 }
136
137 return 0;
138}
139
140static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
141 const u8 *addr)
142{
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
145 int first_errno = 0;
146 int ret;
147 int i;
148
149 lockdep_assert_held(&ar->conf_mutex);
150
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
154
155 if (!peer)
156 return -ENOENT;
157
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
160 continue;
161
162 ret = ath10k_install_key(arvif, peer->keys[i],
163 DISABLE_KEY, addr);
164 if (ret && first_errno == 0)
165 first_errno = ret;
166
167 if (ret)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
169 i, ret);
170
171 peer->keys[i] = NULL;
172 }
173
174 return first_errno;
175}
176
177static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
179{
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
182 u8 addr[ETH_ALEN];
183 int first_errno = 0;
184 int ret;
185 int i;
186
187 lockdep_assert_held(&ar->conf_mutex);
188
189 for (;;) {
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
193 i = 0;
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
199 break;
200 }
201 }
202
203 if (i < ARRAY_SIZE(peer->keys))
204 break;
205 }
206 spin_unlock_bh(&ar->data_lock);
207
208 if (i == ARRAY_SIZE(peer->keys))
209 break;
210
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
213 first_errno = ret;
214
215 if (ret)
216 ath10k_warn("could not remove key for %pM\n", addr);
217 }
218
219 return first_errno;
220}
221
222
223/*********************/
224/* General utilities */
225/*********************/
226
227static inline enum wmi_phy_mode
228chan_to_phymode(const struct cfg80211_chan_def *chandef)
229{
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
236 phymode = MODE_11G;
237 break;
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
240 break;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
243 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
250 break;
251 }
252 break;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
256 phymode = MODE_11A;
257 break;
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
260 break;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
266 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
272 break;
273 }
274 break;
275 default:
276 break;
277 }
278
279 WARN_ON(phymode == MODE_UNKNOWN);
280 return phymode;
281}
282
283static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
284{
285/*
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
288 * 1 for 1/4 us
289 * 2 for 1/2 us
290 * 3 for 1 us
291 * 4 for 2 us
292 * 5 for 4 us
293 * 6 for 8 us
294 * 7 for 16 us
295 */
296 switch (mpdudensity) {
297 case 0:
298 return 0;
299 case 1:
300 case 2:
301 case 3:
302 /* Our lower layer calculations limit our precision to
303 1 microsecond */
304 return 1;
305 case 4:
306 return 2;
307 case 5:
308 return 4;
309 case 6:
310 return 8;
311 case 7:
312 return 16;
313 default:
314 return 0;
315 }
316}
317
318static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
319{
320 int ret;
321
322 lockdep_assert_held(&ar->conf_mutex);
323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
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
445 INIT_COMPLETION(ar->vdev_setup_done);
446
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
502 INIT_COMPLETION(ar->vdev_setup_done);
503
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 =
1480 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1481
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
Kalle Valo5e3dd152013-06-12 20:52:10 +03001488 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1489 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);
1809 INIT_COMPLETION(ar->offchan_tx_completed);
1810 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);
2178 }
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;
Michal Kazior424121c2013-07-22 14:13:31 +02002208 u32 value;
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 }
2300 }
2301
2302 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2303 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2304 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2305 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2306 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002307 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002309 goto err_peer_delete;
2310 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002311
2312 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2313 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2314 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2315 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002316 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002318 goto err_peer_delete;
2319 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320
2321 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2322 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2323 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2324 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002325 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002326 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002327 goto err_peer_delete;
2328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002329 }
2330
Michal Kazior424121c2013-07-22 14:13:31 +02002331 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002332 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002333 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2334 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002335 goto err_peer_delete;
2336 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002337
Michal Kazior424121c2013-07-22 14:13:31 +02002338 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002339 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002340 ath10k_warn("failed to set frag 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
Kalle Valo5e3dd152013-06-12 20:52:10 +03002345 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2346 ar->monitor_present = true;
2347
Kalle Valo5e3dd152013-06-12 20:52:10 +03002348 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002349 return 0;
2350
2351err_peer_delete:
2352 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2353 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2354
2355err_vdev_delete:
2356 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2357 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002358 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002359
2360err:
2361 mutex_unlock(&ar->conf_mutex);
2362
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363 return ret;
2364}
2365
2366static void ath10k_remove_interface(struct ieee80211_hw *hw,
2367 struct ieee80211_vif *vif)
2368{
2369 struct ath10k *ar = hw->priv;
2370 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2371 int ret;
2372
2373 mutex_lock(&ar->conf_mutex);
2374
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002375 cancel_work_sync(&arvif->wep_key_work);
2376
Michal Kaziored543882013-09-13 14:16:56 +02002377 spin_lock_bh(&ar->data_lock);
2378 if (arvif->beacon) {
2379 dev_kfree_skb_any(arvif->beacon);
2380 arvif->beacon = NULL;
2381 }
2382 spin_unlock_bh(&ar->data_lock);
2383
Kalle Valo5e3dd152013-06-12 20:52:10 +03002384 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002385 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386
2387 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2388 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2389 if (ret)
2390 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2391
2392 kfree(arvif->u.ap.noa_data);
2393 }
2394
Kalle Valo60c3daa2013-09-08 17:56:07 +03002395 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2396 arvif->vdev_id);
2397
Kalle Valo5e3dd152013-06-12 20:52:10 +03002398 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2399 if (ret)
2400 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2401
2402 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2403 ar->monitor_present = false;
2404
2405 ath10k_peer_cleanup(ar, arvif->vdev_id);
2406
2407 mutex_unlock(&ar->conf_mutex);
2408}
2409
2410/*
2411 * FIXME: Has to be verified.
2412 */
2413#define SUPPORTED_FILTERS \
2414 (FIF_PROMISC_IN_BSS | \
2415 FIF_ALLMULTI | \
2416 FIF_CONTROL | \
2417 FIF_PSPOLL | \
2418 FIF_OTHER_BSS | \
2419 FIF_BCN_PRBRESP_PROMISC | \
2420 FIF_PROBE_REQ | \
2421 FIF_FCSFAIL)
2422
2423static void ath10k_configure_filter(struct ieee80211_hw *hw,
2424 unsigned int changed_flags,
2425 unsigned int *total_flags,
2426 u64 multicast)
2427{
2428 struct ath10k *ar = hw->priv;
2429 int ret;
2430
2431 mutex_lock(&ar->conf_mutex);
2432
2433 changed_flags &= SUPPORTED_FILTERS;
2434 *total_flags &= SUPPORTED_FILTERS;
2435 ar->filter_flags = *total_flags;
2436
Michal Kaziorafd09222013-10-16 16:45:41 +03002437 /* Monitor must not be started if it wasn't created first.
2438 * Promiscuous mode may be started on a non-monitor interface - in
2439 * such case the monitor vdev is not created so starting the
2440 * monitor makes no sense. Since ath10k uses no special RX filters
2441 * (only BSS filter in STA mode) there's no need for any special
2442 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002443 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002444 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002445 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2446 ar->monitor_vdev_id);
2447
Kalle Valo5e3dd152013-06-12 20:52:10 +03002448 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2449 if (ret)
2450 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002451 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002452 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002453 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2454 ar->monitor_vdev_id);
2455
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456 ret = ath10k_monitor_stop(ar);
2457 if (ret)
2458 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 }
2460
2461 mutex_unlock(&ar->conf_mutex);
2462}
2463
2464static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2465 struct ieee80211_vif *vif,
2466 struct ieee80211_bss_conf *info,
2467 u32 changed)
2468{
2469 struct ath10k *ar = hw->priv;
2470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2471 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002472 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002473
2474 mutex_lock(&ar->conf_mutex);
2475
2476 if (changed & BSS_CHANGED_IBSS)
2477 ath10k_control_ibss(arvif, info, vif->addr);
2478
2479 if (changed & BSS_CHANGED_BEACON_INT) {
2480 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002481 vdev_param = ar->wmi.vdev_param->beacon_interval;
2482 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002483 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002484 ath10k_dbg(ATH10K_DBG_MAC,
2485 "mac vdev %d beacon_interval %d\n",
2486 arvif->vdev_id, arvif->beacon_interval);
2487
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488 if (ret)
2489 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2490 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491 }
2492
2493 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002494 ath10k_dbg(ATH10K_DBG_MAC,
2495 "vdev %d set beacon tx mode to staggered\n",
2496 arvif->vdev_id);
2497
Bartosz Markowski226a3392013-09-26 17:47:16 +02002498 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2499 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002500 WMI_BEACON_STAGGERED_MODE);
2501 if (ret)
2502 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2503 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002504 }
2505
John W. Linvilleb70727e2013-06-13 13:34:29 -04002506 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507 arvif->dtim_period = info->dtim_period;
2508
Kalle Valo60c3daa2013-09-08 17:56:07 +03002509 ath10k_dbg(ATH10K_DBG_MAC,
2510 "mac vdev %d dtim_period %d\n",
2511 arvif->vdev_id, arvif->dtim_period);
2512
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002513 vdev_param = ar->wmi.vdev_param->dtim_period;
2514 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515 arvif->dtim_period);
2516 if (ret)
2517 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2518 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002519 }
2520
2521 if (changed & BSS_CHANGED_SSID &&
2522 vif->type == NL80211_IFTYPE_AP) {
2523 arvif->u.ap.ssid_len = info->ssid_len;
2524 if (info->ssid_len)
2525 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2526 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2527 }
2528
2529 if (changed & BSS_CHANGED_BSSID) {
2530 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002531 ath10k_dbg(ATH10K_DBG_MAC,
2532 "mac vdev %d create peer %pM\n",
2533 arvif->vdev_id, info->bssid);
2534
Kalle Valo5e3dd152013-06-12 20:52:10 +03002535 ret = ath10k_peer_create(ar, arvif->vdev_id,
2536 info->bssid);
2537 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002538 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2539 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002540
2541 if (vif->type == NL80211_IFTYPE_STATION) {
2542 /*
2543 * this is never erased as we it for crypto key
2544 * clearing; this is FW requirement
2545 */
2546 memcpy(arvif->u.sta.bssid, info->bssid,
2547 ETH_ALEN);
2548
Kalle Valo60c3daa2013-09-08 17:56:07 +03002549 ath10k_dbg(ATH10K_DBG_MAC,
2550 "mac vdev %d start %pM\n",
2551 arvif->vdev_id, info->bssid);
2552
2553 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555 }
2556
2557 /*
2558 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2559 * so driver need to store it. It is needed when leaving
2560 * IBSS in order to remove BSSID peer.
2561 */
2562 if (vif->type == NL80211_IFTYPE_ADHOC)
2563 memcpy(arvif->u.ibss.bssid, info->bssid,
2564 ETH_ALEN);
2565 }
2566 }
2567
2568 if (changed & BSS_CHANGED_BEACON_ENABLED)
2569 ath10k_control_beaconing(arvif, info);
2570
2571 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2572 u32 cts_prot;
2573 if (info->use_cts_prot)
2574 cts_prot = 1;
2575 else
2576 cts_prot = 0;
2577
Kalle Valo60c3daa2013-09-08 17:56:07 +03002578 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2579 arvif->vdev_id, cts_prot);
2580
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002581 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2582 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583 cts_prot);
2584 if (ret)
2585 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2586 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587 }
2588
2589 if (changed & BSS_CHANGED_ERP_SLOT) {
2590 u32 slottime;
2591 if (info->use_short_slot)
2592 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2593
2594 else
2595 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2596
Kalle Valo60c3daa2013-09-08 17:56:07 +03002597 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2598 arvif->vdev_id, slottime);
2599
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002600 vdev_param = ar->wmi.vdev_param->slot_time;
2601 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002602 slottime);
2603 if (ret)
2604 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2605 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002606 }
2607
2608 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2609 u32 preamble;
2610 if (info->use_short_preamble)
2611 preamble = WMI_VDEV_PREAMBLE_SHORT;
2612 else
2613 preamble = WMI_VDEV_PREAMBLE_LONG;
2614
Kalle Valo60c3daa2013-09-08 17:56:07 +03002615 ath10k_dbg(ATH10K_DBG_MAC,
2616 "mac vdev %d preamble %dn",
2617 arvif->vdev_id, preamble);
2618
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002619 vdev_param = ar->wmi.vdev_param->preamble;
2620 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002621 preamble);
2622 if (ret)
2623 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2624 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002625 }
2626
2627 if (changed & BSS_CHANGED_ASSOC) {
2628 if (info->assoc)
2629 ath10k_bss_assoc(hw, vif, info);
2630 }
2631
2632 mutex_unlock(&ar->conf_mutex);
2633}
2634
2635static int ath10k_hw_scan(struct ieee80211_hw *hw,
2636 struct ieee80211_vif *vif,
2637 struct cfg80211_scan_request *req)
2638{
2639 struct ath10k *ar = hw->priv;
2640 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2641 struct wmi_start_scan_arg arg;
2642 int ret = 0;
2643 int i;
2644
2645 mutex_lock(&ar->conf_mutex);
2646
2647 spin_lock_bh(&ar->data_lock);
2648 if (ar->scan.in_progress) {
2649 spin_unlock_bh(&ar->data_lock);
2650 ret = -EBUSY;
2651 goto exit;
2652 }
2653
2654 INIT_COMPLETION(ar->scan.started);
2655 INIT_COMPLETION(ar->scan.completed);
2656 ar->scan.in_progress = true;
2657 ar->scan.aborting = false;
2658 ar->scan.is_roc = false;
2659 ar->scan.vdev_id = arvif->vdev_id;
2660 spin_unlock_bh(&ar->data_lock);
2661
2662 memset(&arg, 0, sizeof(arg));
2663 ath10k_wmi_start_scan_init(ar, &arg);
2664 arg.vdev_id = arvif->vdev_id;
2665 arg.scan_id = ATH10K_SCAN_ID;
2666
2667 if (!req->no_cck)
2668 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2669
2670 if (req->ie_len) {
2671 arg.ie_len = req->ie_len;
2672 memcpy(arg.ie, req->ie, arg.ie_len);
2673 }
2674
2675 if (req->n_ssids) {
2676 arg.n_ssids = req->n_ssids;
2677 for (i = 0; i < arg.n_ssids; i++) {
2678 arg.ssids[i].len = req->ssids[i].ssid_len;
2679 arg.ssids[i].ssid = req->ssids[i].ssid;
2680 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002681 } else {
2682 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683 }
2684
2685 if (req->n_channels) {
2686 arg.n_channels = req->n_channels;
2687 for (i = 0; i < arg.n_channels; i++)
2688 arg.channels[i] = req->channels[i]->center_freq;
2689 }
2690
2691 ret = ath10k_start_scan(ar, &arg);
2692 if (ret) {
2693 ath10k_warn("could not start hw scan (%d)\n", ret);
2694 spin_lock_bh(&ar->data_lock);
2695 ar->scan.in_progress = false;
2696 spin_unlock_bh(&ar->data_lock);
2697 }
2698
2699exit:
2700 mutex_unlock(&ar->conf_mutex);
2701 return ret;
2702}
2703
2704static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2705 struct ieee80211_vif *vif)
2706{
2707 struct ath10k *ar = hw->priv;
2708 int ret;
2709
2710 mutex_lock(&ar->conf_mutex);
2711 ret = ath10k_abort_scan(ar);
2712 if (ret) {
2713 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2714 ret);
2715 ieee80211_scan_completed(hw, 1 /* aborted */);
2716 }
2717 mutex_unlock(&ar->conf_mutex);
2718}
2719
2720static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2721 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2722 struct ieee80211_key_conf *key)
2723{
2724 struct ath10k *ar = hw->priv;
2725 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2726 struct ath10k_peer *peer;
2727 const u8 *peer_addr;
2728 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2729 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2730 int ret = 0;
2731
2732 if (key->keyidx > WMI_MAX_KEY_INDEX)
2733 return -ENOSPC;
2734
2735 mutex_lock(&ar->conf_mutex);
2736
2737 if (sta)
2738 peer_addr = sta->addr;
2739 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2740 peer_addr = vif->bss_conf.bssid;
2741 else
2742 peer_addr = vif->addr;
2743
2744 key->hw_key_idx = key->keyidx;
2745
2746 /* the peer should not disappear in mid-way (unless FW goes awry) since
2747 * we already hold conf_mutex. we just make sure its there now. */
2748 spin_lock_bh(&ar->data_lock);
2749 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2750 spin_unlock_bh(&ar->data_lock);
2751
2752 if (!peer) {
2753 if (cmd == SET_KEY) {
2754 ath10k_warn("cannot install key for non-existent peer %pM\n",
2755 peer_addr);
2756 ret = -EOPNOTSUPP;
2757 goto exit;
2758 } else {
2759 /* if the peer doesn't exist there is no key to disable
2760 * anymore */
2761 goto exit;
2762 }
2763 }
2764
2765 if (is_wep) {
2766 if (cmd == SET_KEY)
2767 arvif->wep_keys[key->keyidx] = key;
2768 else
2769 arvif->wep_keys[key->keyidx] = NULL;
2770
2771 if (cmd == DISABLE_KEY)
2772 ath10k_clear_vdev_key(arvif, key);
2773 }
2774
2775 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2776 if (ret) {
2777 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2778 goto exit;
2779 }
2780
2781 spin_lock_bh(&ar->data_lock);
2782 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2783 if (peer && cmd == SET_KEY)
2784 peer->keys[key->keyidx] = key;
2785 else if (peer && cmd == DISABLE_KEY)
2786 peer->keys[key->keyidx] = NULL;
2787 else if (peer == NULL)
2788 /* impossible unless FW goes crazy */
2789 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2790 spin_unlock_bh(&ar->data_lock);
2791
2792exit:
2793 mutex_unlock(&ar->conf_mutex);
2794 return ret;
2795}
2796
2797static int ath10k_sta_state(struct ieee80211_hw *hw,
2798 struct ieee80211_vif *vif,
2799 struct ieee80211_sta *sta,
2800 enum ieee80211_sta_state old_state,
2801 enum ieee80211_sta_state new_state)
2802{
2803 struct ath10k *ar = hw->priv;
2804 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2805 int ret = 0;
2806
2807 mutex_lock(&ar->conf_mutex);
2808
2809 if (old_state == IEEE80211_STA_NOTEXIST &&
2810 new_state == IEEE80211_STA_NONE &&
2811 vif->type != NL80211_IFTYPE_STATION) {
2812 /*
2813 * New station addition.
2814 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002815 ath10k_dbg(ATH10K_DBG_MAC,
2816 "mac vdev %d peer create %pM (new sta)\n",
2817 arvif->vdev_id, sta->addr);
2818
Kalle Valo5e3dd152013-06-12 20:52:10 +03002819 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2820 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002821 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
2822 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002823 } else if ((old_state == IEEE80211_STA_NONE &&
2824 new_state == IEEE80211_STA_NOTEXIST)) {
2825 /*
2826 * Existing station deletion.
2827 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002828 ath10k_dbg(ATH10K_DBG_MAC,
2829 "mac vdev %d peer delete %pM (sta gone)\n",
2830 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002831 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2832 if (ret)
2833 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2834 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835
2836 if (vif->type == NL80211_IFTYPE_STATION)
2837 ath10k_bss_disassoc(hw, vif);
2838 } else if (old_state == IEEE80211_STA_AUTH &&
2839 new_state == IEEE80211_STA_ASSOC &&
2840 (vif->type == NL80211_IFTYPE_AP ||
2841 vif->type == NL80211_IFTYPE_ADHOC)) {
2842 /*
2843 * New association.
2844 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002845 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2846 sta->addr);
2847
Kalle Valo5e3dd152013-06-12 20:52:10 +03002848 ret = ath10k_station_assoc(ar, arvif, sta);
2849 if (ret)
2850 ath10k_warn("Failed to associate station: %pM\n",
2851 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002852 } else if (old_state == IEEE80211_STA_ASSOC &&
2853 new_state == IEEE80211_STA_AUTH &&
2854 (vif->type == NL80211_IFTYPE_AP ||
2855 vif->type == NL80211_IFTYPE_ADHOC)) {
2856 /*
2857 * Disassociation.
2858 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002859 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2860 sta->addr);
2861
Kalle Valo5e3dd152013-06-12 20:52:10 +03002862 ret = ath10k_station_disassoc(ar, arvif, sta);
2863 if (ret)
2864 ath10k_warn("Failed to disassociate station: %pM\n",
2865 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866 }
2867
2868 mutex_unlock(&ar->conf_mutex);
2869 return ret;
2870}
2871
2872static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2873 u16 ac, bool enable)
2874{
2875 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2876 u32 value = 0;
2877 int ret = 0;
2878
Michal Kazior548db542013-07-05 16:15:15 +03002879 lockdep_assert_held(&ar->conf_mutex);
2880
Kalle Valo5e3dd152013-06-12 20:52:10 +03002881 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2882 return 0;
2883
2884 switch (ac) {
2885 case IEEE80211_AC_VO:
2886 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2887 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2888 break;
2889 case IEEE80211_AC_VI:
2890 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2891 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2892 break;
2893 case IEEE80211_AC_BE:
2894 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2895 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2896 break;
2897 case IEEE80211_AC_BK:
2898 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2899 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2900 break;
2901 }
2902
2903 if (enable)
2904 arvif->u.sta.uapsd |= value;
2905 else
2906 arvif->u.sta.uapsd &= ~value;
2907
2908 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2909 WMI_STA_PS_PARAM_UAPSD,
2910 arvif->u.sta.uapsd);
2911 if (ret) {
2912 ath10k_warn("could not set uapsd params %d\n", ret);
2913 goto exit;
2914 }
2915
2916 if (arvif->u.sta.uapsd)
2917 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2918 else
2919 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2920
2921 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2922 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2923 value);
2924 if (ret)
2925 ath10k_warn("could not set rx wake param %d\n", ret);
2926
2927exit:
2928 return ret;
2929}
2930
2931static int ath10k_conf_tx(struct ieee80211_hw *hw,
2932 struct ieee80211_vif *vif, u16 ac,
2933 const struct ieee80211_tx_queue_params *params)
2934{
2935 struct ath10k *ar = hw->priv;
2936 struct wmi_wmm_params_arg *p = NULL;
2937 int ret;
2938
2939 mutex_lock(&ar->conf_mutex);
2940
2941 switch (ac) {
2942 case IEEE80211_AC_VO:
2943 p = &ar->wmm_params.ac_vo;
2944 break;
2945 case IEEE80211_AC_VI:
2946 p = &ar->wmm_params.ac_vi;
2947 break;
2948 case IEEE80211_AC_BE:
2949 p = &ar->wmm_params.ac_be;
2950 break;
2951 case IEEE80211_AC_BK:
2952 p = &ar->wmm_params.ac_bk;
2953 break;
2954 }
2955
2956 if (WARN_ON(!p)) {
2957 ret = -EINVAL;
2958 goto exit;
2959 }
2960
2961 p->cwmin = params->cw_min;
2962 p->cwmax = params->cw_max;
2963 p->aifs = params->aifs;
2964
2965 /*
2966 * The channel time duration programmed in the HW is in absolute
2967 * microseconds, while mac80211 gives the txop in units of
2968 * 32 microseconds.
2969 */
2970 p->txop = params->txop * 32;
2971
2972 /* FIXME: FW accepts wmm params per hw, not per vif */
2973 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2974 if (ret) {
2975 ath10k_warn("could not set wmm params %d\n", ret);
2976 goto exit;
2977 }
2978
2979 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2980 if (ret)
2981 ath10k_warn("could not set sta uapsd %d\n", ret);
2982
2983exit:
2984 mutex_unlock(&ar->conf_mutex);
2985 return ret;
2986}
2987
2988#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2989
2990static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2991 struct ieee80211_vif *vif,
2992 struct ieee80211_channel *chan,
2993 int duration,
2994 enum ieee80211_roc_type type)
2995{
2996 struct ath10k *ar = hw->priv;
2997 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2998 struct wmi_start_scan_arg arg;
2999 int ret;
3000
3001 mutex_lock(&ar->conf_mutex);
3002
3003 spin_lock_bh(&ar->data_lock);
3004 if (ar->scan.in_progress) {
3005 spin_unlock_bh(&ar->data_lock);
3006 ret = -EBUSY;
3007 goto exit;
3008 }
3009
3010 INIT_COMPLETION(ar->scan.started);
3011 INIT_COMPLETION(ar->scan.completed);
3012 INIT_COMPLETION(ar->scan.on_channel);
3013 ar->scan.in_progress = true;
3014 ar->scan.aborting = false;
3015 ar->scan.is_roc = true;
3016 ar->scan.vdev_id = arvif->vdev_id;
3017 ar->scan.roc_freq = chan->center_freq;
3018 spin_unlock_bh(&ar->data_lock);
3019
3020 memset(&arg, 0, sizeof(arg));
3021 ath10k_wmi_start_scan_init(ar, &arg);
3022 arg.vdev_id = arvif->vdev_id;
3023 arg.scan_id = ATH10K_SCAN_ID;
3024 arg.n_channels = 1;
3025 arg.channels[0] = chan->center_freq;
3026 arg.dwell_time_active = duration;
3027 arg.dwell_time_passive = duration;
3028 arg.max_scan_time = 2 * duration;
3029 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3030 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3031
3032 ret = ath10k_start_scan(ar, &arg);
3033 if (ret) {
3034 ath10k_warn("could not start roc scan (%d)\n", ret);
3035 spin_lock_bh(&ar->data_lock);
3036 ar->scan.in_progress = false;
3037 spin_unlock_bh(&ar->data_lock);
3038 goto exit;
3039 }
3040
3041 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3042 if (ret == 0) {
3043 ath10k_warn("could not switch to channel for roc scan\n");
3044 ath10k_abort_scan(ar);
3045 ret = -ETIMEDOUT;
3046 goto exit;
3047 }
3048
3049 ret = 0;
3050exit:
3051 mutex_unlock(&ar->conf_mutex);
3052 return ret;
3053}
3054
3055static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3056{
3057 struct ath10k *ar = hw->priv;
3058
3059 mutex_lock(&ar->conf_mutex);
3060 ath10k_abort_scan(ar);
3061 mutex_unlock(&ar->conf_mutex);
3062
3063 return 0;
3064}
3065
3066/*
3067 * Both RTS and Fragmentation threshold are interface-specific
3068 * in ath10k, but device-specific in mac80211.
3069 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003070
3071static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3072{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003073 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003074 struct ath10k_vif *arvif;
3075 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003076
Michal Kaziorad088bf2013-10-16 15:44:46 +03003077 mutex_lock(&ar->conf_mutex);
3078 list_for_each_entry(arvif, &ar->arvifs, list) {
3079 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3080 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003081
Michal Kaziorad088bf2013-10-16 15:44:46 +03003082 ret = ath10k_mac_set_rts(arvif, value);
3083 if (ret) {
3084 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3085 arvif->vdev_id, ret);
3086 break;
3087 }
3088 }
3089 mutex_unlock(&ar->conf_mutex);
3090
3091 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003092}
3093
3094static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3095{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003096 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003097 struct ath10k_vif *arvif;
3098 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099
Kalle Valo5e3dd152013-06-12 20:52:10 +03003100 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003101 list_for_each_entry(arvif, &ar->arvifs, list) {
3102 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3103 arvif->vdev_id, value);
3104
3105 ret = ath10k_mac_set_rts(arvif, value);
3106 if (ret) {
3107 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3108 arvif->vdev_id, ret);
3109 break;
3110 }
3111 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003112 mutex_unlock(&ar->conf_mutex);
3113
Michal Kaziorad088bf2013-10-16 15:44:46 +03003114 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115}
3116
3117static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3118{
3119 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003120 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003121 int ret;
3122
3123 /* mac80211 doesn't care if we really xmit queued frames or not
3124 * we'll collect those frames either way if we stop/delete vdevs */
3125 if (drop)
3126 return;
3127
Michal Kazior548db542013-07-05 16:15:15 +03003128 mutex_lock(&ar->conf_mutex);
3129
Michal Kazioraffd3212013-07-16 09:54:35 +02003130 if (ar->state == ATH10K_STATE_WEDGED)
3131 goto skip;
3132
Michal Kazioredb82362013-07-05 16:15:14 +03003133 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003134 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003135
Michal Kazioredb82362013-07-05 16:15:14 +03003136 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003137 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003138 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003139
3140 skip = (ar->state == ATH10K_STATE_WEDGED);
3141
3142 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003143 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003144
3145 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003147
Michal Kazioraffd3212013-07-16 09:54:35 +02003148skip:
Michal Kazior548db542013-07-05 16:15:15 +03003149 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150}
3151
3152/* TODO: Implement this function properly
3153 * For now it is needed to reply to Probe Requests in IBSS mode.
3154 * Propably we need this information from FW.
3155 */
3156static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3157{
3158 return 1;
3159}
3160
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003161#ifdef CONFIG_PM
3162static int ath10k_suspend(struct ieee80211_hw *hw,
3163 struct cfg80211_wowlan *wowlan)
3164{
3165 struct ath10k *ar = hw->priv;
3166 int ret;
3167
3168 ar->is_target_paused = false;
3169
3170 ret = ath10k_wmi_pdev_suspend_target(ar);
3171 if (ret) {
3172 ath10k_warn("could not suspend target (%d)\n", ret);
3173 return 1;
3174 }
3175
3176 ret = wait_event_interruptible_timeout(ar->event_queue,
3177 ar->is_target_paused == true,
3178 1 * HZ);
3179 if (ret < 0) {
3180 ath10k_warn("suspend interrupted (%d)\n", ret);
3181 goto resume;
3182 } else if (ret == 0) {
3183 ath10k_warn("suspend timed out - target pause event never came\n");
3184 goto resume;
3185 }
3186
3187 ret = ath10k_hif_suspend(ar);
3188 if (ret) {
3189 ath10k_warn("could not suspend hif (%d)\n", ret);
3190 goto resume;
3191 }
3192
3193 return 0;
3194resume:
3195 ret = ath10k_wmi_pdev_resume_target(ar);
3196 if (ret)
3197 ath10k_warn("could not resume target (%d)\n", ret);
3198 return 1;
3199}
3200
3201static int ath10k_resume(struct ieee80211_hw *hw)
3202{
3203 struct ath10k *ar = hw->priv;
3204 int ret;
3205
3206 ret = ath10k_hif_resume(ar);
3207 if (ret) {
3208 ath10k_warn("could not resume hif (%d)\n", ret);
3209 return 1;
3210 }
3211
3212 ret = ath10k_wmi_pdev_resume_target(ar);
3213 if (ret) {
3214 ath10k_warn("could not resume target (%d)\n", ret);
3215 return 1;
3216 }
3217
3218 return 0;
3219}
3220#endif
3221
Michal Kazioraffd3212013-07-16 09:54:35 +02003222static void ath10k_restart_complete(struct ieee80211_hw *hw)
3223{
3224 struct ath10k *ar = hw->priv;
3225
3226 mutex_lock(&ar->conf_mutex);
3227
3228 /* If device failed to restart it will be in a different state, e.g.
3229 * ATH10K_STATE_WEDGED */
3230 if (ar->state == ATH10K_STATE_RESTARTED) {
3231 ath10k_info("device successfully recovered\n");
3232 ar->state = ATH10K_STATE_ON;
3233 }
3234
3235 mutex_unlock(&ar->conf_mutex);
3236}
3237
Michal Kazior2e1dea42013-07-31 10:32:40 +02003238static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3239 struct survey_info *survey)
3240{
3241 struct ath10k *ar = hw->priv;
3242 struct ieee80211_supported_band *sband;
3243 struct survey_info *ar_survey = &ar->survey[idx];
3244 int ret = 0;
3245
3246 mutex_lock(&ar->conf_mutex);
3247
3248 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3249 if (sband && idx >= sband->n_channels) {
3250 idx -= sband->n_channels;
3251 sband = NULL;
3252 }
3253
3254 if (!sband)
3255 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3256
3257 if (!sband || idx >= sband->n_channels) {
3258 ret = -ENOENT;
3259 goto exit;
3260 }
3261
3262 spin_lock_bh(&ar->data_lock);
3263 memcpy(survey, ar_survey, sizeof(*survey));
3264 spin_unlock_bh(&ar->data_lock);
3265
3266 survey->channel = &sband->channels[idx];
3267
3268exit:
3269 mutex_unlock(&ar->conf_mutex);
3270 return ret;
3271}
3272
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273static const struct ieee80211_ops ath10k_ops = {
3274 .tx = ath10k_tx,
3275 .start = ath10k_start,
3276 .stop = ath10k_stop,
3277 .config = ath10k_config,
3278 .add_interface = ath10k_add_interface,
3279 .remove_interface = ath10k_remove_interface,
3280 .configure_filter = ath10k_configure_filter,
3281 .bss_info_changed = ath10k_bss_info_changed,
3282 .hw_scan = ath10k_hw_scan,
3283 .cancel_hw_scan = ath10k_cancel_hw_scan,
3284 .set_key = ath10k_set_key,
3285 .sta_state = ath10k_sta_state,
3286 .conf_tx = ath10k_conf_tx,
3287 .remain_on_channel = ath10k_remain_on_channel,
3288 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3289 .set_rts_threshold = ath10k_set_rts_threshold,
3290 .set_frag_threshold = ath10k_set_frag_threshold,
3291 .flush = ath10k_flush,
3292 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003293 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003294 .get_survey = ath10k_get_survey,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003295#ifdef CONFIG_PM
3296 .suspend = ath10k_suspend,
3297 .resume = ath10k_resume,
3298#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003299};
3300
3301#define RATETAB_ENT(_rate, _rateid, _flags) { \
3302 .bitrate = (_rate), \
3303 .flags = (_flags), \
3304 .hw_value = (_rateid), \
3305}
3306
3307#define CHAN2G(_channel, _freq, _flags) { \
3308 .band = IEEE80211_BAND_2GHZ, \
3309 .hw_value = (_channel), \
3310 .center_freq = (_freq), \
3311 .flags = (_flags), \
3312 .max_antenna_gain = 0, \
3313 .max_power = 30, \
3314}
3315
3316#define CHAN5G(_channel, _freq, _flags) { \
3317 .band = IEEE80211_BAND_5GHZ, \
3318 .hw_value = (_channel), \
3319 .center_freq = (_freq), \
3320 .flags = (_flags), \
3321 .max_antenna_gain = 0, \
3322 .max_power = 30, \
3323}
3324
3325static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3326 CHAN2G(1, 2412, 0),
3327 CHAN2G(2, 2417, 0),
3328 CHAN2G(3, 2422, 0),
3329 CHAN2G(4, 2427, 0),
3330 CHAN2G(5, 2432, 0),
3331 CHAN2G(6, 2437, 0),
3332 CHAN2G(7, 2442, 0),
3333 CHAN2G(8, 2447, 0),
3334 CHAN2G(9, 2452, 0),
3335 CHAN2G(10, 2457, 0),
3336 CHAN2G(11, 2462, 0),
3337 CHAN2G(12, 2467, 0),
3338 CHAN2G(13, 2472, 0),
3339 CHAN2G(14, 2484, 0),
3340};
3341
3342static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003343 CHAN5G(36, 5180, 0),
3344 CHAN5G(40, 5200, 0),
3345 CHAN5G(44, 5220, 0),
3346 CHAN5G(48, 5240, 0),
3347 CHAN5G(52, 5260, 0),
3348 CHAN5G(56, 5280, 0),
3349 CHAN5G(60, 5300, 0),
3350 CHAN5G(64, 5320, 0),
3351 CHAN5G(100, 5500, 0),
3352 CHAN5G(104, 5520, 0),
3353 CHAN5G(108, 5540, 0),
3354 CHAN5G(112, 5560, 0),
3355 CHAN5G(116, 5580, 0),
3356 CHAN5G(120, 5600, 0),
3357 CHAN5G(124, 5620, 0),
3358 CHAN5G(128, 5640, 0),
3359 CHAN5G(132, 5660, 0),
3360 CHAN5G(136, 5680, 0),
3361 CHAN5G(140, 5700, 0),
3362 CHAN5G(149, 5745, 0),
3363 CHAN5G(153, 5765, 0),
3364 CHAN5G(157, 5785, 0),
3365 CHAN5G(161, 5805, 0),
3366 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003367};
3368
3369static struct ieee80211_rate ath10k_rates[] = {
3370 /* CCK */
3371 RATETAB_ENT(10, 0x82, 0),
3372 RATETAB_ENT(20, 0x84, 0),
3373 RATETAB_ENT(55, 0x8b, 0),
3374 RATETAB_ENT(110, 0x96, 0),
3375 /* OFDM */
3376 RATETAB_ENT(60, 0x0c, 0),
3377 RATETAB_ENT(90, 0x12, 0),
3378 RATETAB_ENT(120, 0x18, 0),
3379 RATETAB_ENT(180, 0x24, 0),
3380 RATETAB_ENT(240, 0x30, 0),
3381 RATETAB_ENT(360, 0x48, 0),
3382 RATETAB_ENT(480, 0x60, 0),
3383 RATETAB_ENT(540, 0x6c, 0),
3384};
3385
3386#define ath10k_a_rates (ath10k_rates + 4)
3387#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3388#define ath10k_g_rates (ath10k_rates + 0)
3389#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3390
3391struct ath10k *ath10k_mac_create(void)
3392{
3393 struct ieee80211_hw *hw;
3394 struct ath10k *ar;
3395
3396 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3397 if (!hw)
3398 return NULL;
3399
3400 ar = hw->priv;
3401 ar->hw = hw;
3402
3403 return ar;
3404}
3405
3406void ath10k_mac_destroy(struct ath10k *ar)
3407{
3408 ieee80211_free_hw(ar->hw);
3409}
3410
3411static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3412 {
3413 .max = 8,
3414 .types = BIT(NL80211_IFTYPE_STATION)
3415 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003416 },
3417 {
3418 .max = 3,
3419 .types = BIT(NL80211_IFTYPE_P2P_GO)
3420 },
3421 {
3422 .max = 7,
3423 .types = BIT(NL80211_IFTYPE_AP)
3424 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425};
3426
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003427#ifdef CONFIG_ATH10K_DFS_CERTIFIED
3428static const struct ieee80211_iface_limit ath10k_if_dfs_limits[] = {
3429 {
3430 .max = 8,
3431 .types = BIT(NL80211_IFTYPE_AP)
3432 },
3433};
3434#endif
3435
3436static const struct ieee80211_iface_combination ath10k_if_comb[] = {
3437 {
3438 .limits = ath10k_if_limits,
3439 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3440 .max_interfaces = 8,
3441 .num_different_channels = 1,
3442 .beacon_int_infra_match = true,
3443 },
3444#ifdef CONFIG_ATH10K_DFS_CERTIFIED
3445 {
3446 .limits = ath10k_if_dfs_limits,
3447 .n_limits = ARRAY_SIZE(ath10k_if_dfs_limits),
3448 .max_interfaces = 8,
3449 .num_different_channels = 1,
3450 .beacon_int_infra_match = true,
3451 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
3452 BIT(NL80211_CHAN_WIDTH_20) |
3453 BIT(NL80211_CHAN_WIDTH_40) |
3454 BIT(NL80211_CHAN_WIDTH_80),
3455 }
3456#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003457};
3458
3459static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3460{
3461 struct ieee80211_sta_vht_cap vht_cap = {0};
3462 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003463 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003464
3465 vht_cap.vht_supported = 1;
3466 vht_cap.cap = ar->vht_cap_info;
3467
Michal Kazior8865bee42013-07-24 12:36:46 +02003468 mcs_map = 0;
3469 for (i = 0; i < 8; i++) {
3470 if (i < ar->num_rf_chains)
3471 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3472 else
3473 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3474 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475
3476 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3477 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3478
3479 return vht_cap;
3480}
3481
3482static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3483{
3484 int i;
3485 struct ieee80211_sta_ht_cap ht_cap = {0};
3486
3487 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3488 return ht_cap;
3489
3490 ht_cap.ht_supported = 1;
3491 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3492 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3493 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3494 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3495 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3496
3497 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3498 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3499
3500 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3501 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3502
3503 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3504 u32 smps;
3505
3506 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3507 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3508
3509 ht_cap.cap |= smps;
3510 }
3511
3512 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3513 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3514
3515 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3516 u32 stbc;
3517
3518 stbc = ar->ht_cap_info;
3519 stbc &= WMI_HT_CAP_RX_STBC;
3520 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3521 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3522 stbc &= IEEE80211_HT_CAP_RX_STBC;
3523
3524 ht_cap.cap |= stbc;
3525 }
3526
3527 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3528 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3529
3530 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3531 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3532
3533 /* max AMSDU is implicitly taken from vht_cap_info */
3534 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3535 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3536
Michal Kazior8865bee42013-07-24 12:36:46 +02003537 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 ht_cap.mcs.rx_mask[i] = 0xFF;
3539
3540 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3541
3542 return ht_cap;
3543}
3544
3545
3546static void ath10k_get_arvif_iter(void *data, u8 *mac,
3547 struct ieee80211_vif *vif)
3548{
3549 struct ath10k_vif_iter *arvif_iter = data;
3550 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3551
3552 if (arvif->vdev_id == arvif_iter->vdev_id)
3553 arvif_iter->arvif = arvif;
3554}
3555
3556struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3557{
3558 struct ath10k_vif_iter arvif_iter;
3559 u32 flags;
3560
3561 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3562 arvif_iter.vdev_id = vdev_id;
3563
3564 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3565 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3566 flags,
3567 ath10k_get_arvif_iter,
3568 &arvif_iter);
3569 if (!arvif_iter.arvif) {
3570 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3571 return NULL;
3572 }
3573
3574 return arvif_iter.arvif;
3575}
3576
3577int ath10k_mac_register(struct ath10k *ar)
3578{
3579 struct ieee80211_supported_band *band;
3580 struct ieee80211_sta_vht_cap vht_cap;
3581 struct ieee80211_sta_ht_cap ht_cap;
3582 void *channels;
3583 int ret;
3584
3585 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3586
3587 SET_IEEE80211_DEV(ar->hw, ar->dev);
3588
3589 ht_cap = ath10k_get_ht_cap(ar);
3590 vht_cap = ath10k_create_vht_cap(ar);
3591
3592 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3593 channels = kmemdup(ath10k_2ghz_channels,
3594 sizeof(ath10k_2ghz_channels),
3595 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02003596 if (!channels) {
3597 ret = -ENOMEM;
3598 goto err_free;
3599 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003600
3601 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3602 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3603 band->channels = channels;
3604 band->n_bitrates = ath10k_g_rates_size;
3605 band->bitrates = ath10k_g_rates;
3606 band->ht_cap = ht_cap;
3607
3608 /* vht is not supported in 2.4 GHz */
3609
3610 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3611 }
3612
3613 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3614 channels = kmemdup(ath10k_5ghz_channels,
3615 sizeof(ath10k_5ghz_channels),
3616 GFP_KERNEL);
3617 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02003618 ret = -ENOMEM;
3619 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620 }
3621
3622 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3623 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3624 band->channels = channels;
3625 band->n_bitrates = ath10k_a_rates_size;
3626 band->bitrates = ath10k_a_rates;
3627 band->ht_cap = ht_cap;
3628 band->vht_cap = vht_cap;
3629 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3630 }
3631
3632 ar->hw->wiphy->interface_modes =
3633 BIT(NL80211_IFTYPE_STATION) |
3634 BIT(NL80211_IFTYPE_ADHOC) |
3635 BIT(NL80211_IFTYPE_AP) |
3636 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3637 BIT(NL80211_IFTYPE_P2P_GO);
3638
3639 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3640 IEEE80211_HW_SUPPORTS_PS |
3641 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3642 IEEE80211_HW_SUPPORTS_UAPSD |
3643 IEEE80211_HW_MFP_CAPABLE |
3644 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3645 IEEE80211_HW_HAS_RATE_CONTROL |
3646 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3647 IEEE80211_HW_WANT_MONITOR_VIF |
3648 IEEE80211_HW_AP_LINK_PS;
3649
Michal Kazior1f8bb152013-09-18 14:43:22 +02003650 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3651 * bytes is used for padding/alignment if necessary. */
3652 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3653
Kalle Valo5e3dd152013-06-12 20:52:10 +03003654 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3655 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3656
3657 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3658 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3659 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3660 }
3661
3662 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3663 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3664
3665 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3666
3667 ar->hw->channel_change_time = 5000;
3668 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3669
3670 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3671 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3672
3673 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3674 /*
3675 * on LL hardware queues are managed entirely by the FW
3676 * so we only advertise to mac we can do the queues thing
3677 */
3678 ar->hw->queues = 4;
3679
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003680 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
3681 ar->hw->wiphy->n_iface_combinations = ARRAY_SIZE(ath10k_if_comb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003682
Michal Kazior7c199992013-07-31 10:47:57 +02003683 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3684
Janusz Dziedzic9702c682013-11-20 09:59:41 +02003685 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
3686 /* Init ath dfs pattern detector */
3687 ar->ath_common.debug_mask = ATH_DBG_DFS;
3688 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
3689 NL80211_DFS_UNSET);
3690
3691 if (!ar->dfs_detector)
3692 ath10k_warn("dfs pattern detector init failed\n");
3693 }
3694
Kalle Valo5e3dd152013-06-12 20:52:10 +03003695 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3696 ath10k_reg_notifier);
3697 if (ret) {
3698 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02003699 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700 }
3701
3702 ret = ieee80211_register_hw(ar->hw);
3703 if (ret) {
3704 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02003705 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003706 }
3707
3708 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3709 ret = regulatory_hint(ar->hw->wiphy,
3710 ar->ath_common.regulatory.alpha2);
3711 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02003712 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003713 }
3714
3715 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02003716
3717err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003718 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02003719err_free:
3720 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3721 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3722
Kalle Valo5e3dd152013-06-12 20:52:10 +03003723 return ret;
3724}
3725
3726void ath10k_mac_unregister(struct ath10k *ar)
3727{
3728 ieee80211_unregister_hw(ar->hw);
3729
Janusz Dziedzic9702c682013-11-20 09:59:41 +02003730 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
3731 ar->dfs_detector->exit(ar->dfs_detector);
3732
Kalle Valo5e3dd152013-06-12 20:52:10 +03003733 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3734 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3735
3736 SET_IEEE80211_DEV(ar->hw, NULL);
3737}