blob: bff0871fa6bdf45f0bf12410a0f5272b67bbf46d [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
71 break;
72 default:
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
88 const u8 *macaddr)
89{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Wolfram Sang16735d02013-11-14 14:32:02 -080095 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030096
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
98 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
128
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 addr);
131 if (ret)
132 return ret;
133
134 peer->keys[i] = arvif->wep_keys[i];
135 }
136
137 return 0;
138}
139
140static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
141 const u8 *addr)
142{
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
145 int first_errno = 0;
146 int ret;
147 int i;
148
149 lockdep_assert_held(&ar->conf_mutex);
150
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
154
155 if (!peer)
156 return -ENOENT;
157
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
160 continue;
161
162 ret = ath10k_install_key(arvif, peer->keys[i],
163 DISABLE_KEY, addr);
164 if (ret && first_errno == 0)
165 first_errno = ret;
166
167 if (ret)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
169 i, ret);
170
171 peer->keys[i] = NULL;
172 }
173
174 return first_errno;
175}
176
177static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
179{
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
182 u8 addr[ETH_ALEN];
183 int first_errno = 0;
184 int ret;
185 int i;
186
187 lockdep_assert_held(&ar->conf_mutex);
188
189 for (;;) {
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
193 i = 0;
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
199 break;
200 }
201 }
202
203 if (i < ARRAY_SIZE(peer->keys))
204 break;
205 }
206 spin_unlock_bh(&ar->data_lock);
207
208 if (i == ARRAY_SIZE(peer->keys))
209 break;
210
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
213 first_errno = ret;
214
215 if (ret)
216 ath10k_warn("could not remove key for %pM\n", addr);
217 }
218
219 return first_errno;
220}
221
222
223/*********************/
224/* General utilities */
225/*********************/
226
227static inline enum wmi_phy_mode
228chan_to_phymode(const struct cfg80211_chan_def *chandef)
229{
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
236 phymode = MODE_11G;
237 break;
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
240 break;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
243 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
250 break;
251 }
252 break;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
256 phymode = MODE_11A;
257 break;
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
260 break;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
266 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
272 break;
273 }
274 break;
275 default:
276 break;
277 }
278
279 WARN_ON(phymode == MODE_UNKNOWN);
280 return phymode;
281}
282
283static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
284{
285/*
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
288 * 1 for 1/4 us
289 * 2 for 1/2 us
290 * 3 for 1 us
291 * 4 for 2 us
292 * 5 for 4 us
293 * 6 for 8 us
294 * 7 for 16 us
295 */
296 switch (mpdudensity) {
297 case 0:
298 return 0;
299 case 1:
300 case 2:
301 case 3:
302 /* Our lower layer calculations limit our precision to
303 1 microsecond */
304 return 1;
305 case 4:
306 return 2;
307 case 5:
308 return 4;
309 case 6:
310 return 8;
311 case 7:
312 return 16;
313 default:
314 return 0;
315 }
316}
317
318static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
319{
320 int ret;
321
322 lockdep_assert_held(&ar->conf_mutex);
323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800325 if (ret) {
326 ath10k_warn("Failed to create wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300329
330 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800331 if (ret) {
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100335 spin_lock_bh(&ar->data_lock);
336 ar->num_peers++;
337 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300338
339 return 0;
340}
341
Kalle Valo5a13e762014-01-20 11:01:46 +0200342static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
343{
344 struct ath10k *ar = arvif->ar;
345 u32 param;
346 int ret;
347
348 param = ar->wmi.pdev_param->sta_kickout_th;
349 ret = ath10k_wmi_pdev_set_param(ar, param,
350 ATH10K_KICKOUT_THRESHOLD);
351 if (ret) {
352 ath10k_warn("Failed to set kickout threshold: %d\n", ret);
353 return ret;
354 }
355
356 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
358 ATH10K_KEEPALIVE_MIN_IDLE);
359 if (ret) {
360 ath10k_warn("Failed to set keepalive minimum idle time : %d\n",
361 ret);
362 return ret;
363 }
364
365 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
366 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
367 ATH10K_KEEPALIVE_MAX_IDLE);
368 if (ret) {
369 ath10k_warn("Failed to set keepalive maximum idle time: %d\n",
370 ret);
371 return ret;
372 }
373
374 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
375 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
376 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
377 if (ret) {
378 ath10k_warn("Failed to set keepalive maximum unresponsive time: %d\n",
379 ret);
380 return ret;
381 }
382
383 return 0;
384}
385
Michal Kazior424121c2013-07-22 14:13:31 +0200386static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
387{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200388 struct ath10k *ar = arvif->ar;
389 u32 vdev_param;
390
Michal Kazior424121c2013-07-22 14:13:31 +0200391 if (value != 0xFFFFFFFF)
392 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
393 ATH10K_RTS_MAX);
394
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200395 vdev_param = ar->wmi.vdev_param->rts_threshold;
396 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200397}
398
399static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
400{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200401 struct ath10k *ar = arvif->ar;
402 u32 vdev_param;
403
Michal Kazior424121c2013-07-22 14:13:31 +0200404 if (value != 0xFFFFFFFF)
405 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
406 ATH10K_FRAGMT_THRESHOLD_MIN,
407 ATH10K_FRAGMT_THRESHOLD_MAX);
408
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
410 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200411}
412
Kalle Valo5e3dd152013-06-12 20:52:10 +0300413static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
414{
415 int ret;
416
417 lockdep_assert_held(&ar->conf_mutex);
418
419 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
420 if (ret)
421 return ret;
422
423 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
424 if (ret)
425 return ret;
426
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100427 spin_lock_bh(&ar->data_lock);
428 ar->num_peers--;
429 spin_unlock_bh(&ar->data_lock);
430
Kalle Valo5e3dd152013-06-12 20:52:10 +0300431 return 0;
432}
433
434static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
435{
436 struct ath10k_peer *peer, *tmp;
437
438 lockdep_assert_held(&ar->conf_mutex);
439
440 spin_lock_bh(&ar->data_lock);
441 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
442 if (peer->vdev_id != vdev_id)
443 continue;
444
445 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
446 peer->addr, vdev_id);
447
448 list_del(&peer->list);
449 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100450 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300451 }
452 spin_unlock_bh(&ar->data_lock);
453}
454
Michal Kaziora96d7742013-07-16 09:38:56 +0200455static void ath10k_peer_cleanup_all(struct ath10k *ar)
456{
457 struct ath10k_peer *peer, *tmp;
458
459 lockdep_assert_held(&ar->conf_mutex);
460
461 spin_lock_bh(&ar->data_lock);
462 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
463 list_del(&peer->list);
464 kfree(peer);
465 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100466 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200467 spin_unlock_bh(&ar->data_lock);
468}
469
Kalle Valo5e3dd152013-06-12 20:52:10 +0300470/************************/
471/* Interface management */
472/************************/
473
474static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
475{
476 int ret;
477
Michal Kazior548db542013-07-05 16:15:15 +0300478 lockdep_assert_held(&ar->conf_mutex);
479
Kalle Valo5e3dd152013-06-12 20:52:10 +0300480 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
481 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
482 if (ret == 0)
483 return -ETIMEDOUT;
484
485 return 0;
486}
487
488static int ath10k_vdev_start(struct ath10k_vif *arvif)
489{
490 struct ath10k *ar = arvif->ar;
491 struct ieee80211_conf *conf = &ar->hw->conf;
492 struct ieee80211_channel *channel = conf->chandef.chan;
493 struct wmi_vdev_start_request_arg arg = {};
494 int ret = 0;
495
496 lockdep_assert_held(&ar->conf_mutex);
497
Wolfram Sang16735d02013-11-14 14:32:02 -0800498 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300499
500 arg.vdev_id = arvif->vdev_id;
501 arg.dtim_period = arvif->dtim_period;
502 arg.bcn_intval = arvif->beacon_interval;
503
504 arg.channel.freq = channel->center_freq;
505
506 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
507
508 arg.channel.mode = chan_to_phymode(&conf->chandef);
509
Michal Kazior89c5c842013-10-23 04:02:13 -0700510 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700511 arg.channel.max_power = channel->max_power * 2;
512 arg.channel.max_reg_power = channel->max_reg_power * 2;
513 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300514
515 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
516 arg.ssid = arvif->u.ap.ssid;
517 arg.ssid_len = arvif->u.ap.ssid_len;
518 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200519
520 /* For now allow DFS for AP mode */
521 arg.channel.chan_radar =
522 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
524 arg.ssid = arvif->vif->bss_conf.ssid;
525 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
526 }
527
Kalle Valo38a1d472013-09-08 17:56:14 +0300528 ath10k_dbg(ATH10K_DBG_MAC,
529 "mac vdev %d start center_freq %d phymode %s\n",
530 arg.vdev_id, arg.channel.freq,
531 ath10k_wmi_phymode_str(arg.channel.mode));
532
Kalle Valo5e3dd152013-06-12 20:52:10 +0300533 ret = ath10k_wmi_vdev_start(ar, &arg);
534 if (ret) {
535 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
536 return ret;
537 }
538
539 ret = ath10k_vdev_setup_sync(ar);
540 if (ret) {
541 ath10k_warn("vdev setup failed %d\n", ret);
542 return ret;
543 }
544
545 return ret;
546}
547
548static int ath10k_vdev_stop(struct ath10k_vif *arvif)
549{
550 struct ath10k *ar = arvif->ar;
551 int ret;
552
553 lockdep_assert_held(&ar->conf_mutex);
554
Wolfram Sang16735d02013-11-14 14:32:02 -0800555 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300556
557 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
558 if (ret) {
559 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
560 return ret;
561 }
562
563 ret = ath10k_vdev_setup_sync(ar);
564 if (ret) {
565 ath10k_warn("vdev setup failed %d\n", ret);
566 return ret;
567 }
568
569 return ret;
570}
571
572static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
573{
574 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
575 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300576 int ret = 0;
577
578 lockdep_assert_held(&ar->conf_mutex);
579
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300580 if (!ar->monitor_present) {
581 ath10k_warn("mac montor stop -- monitor is not present\n");
582 return -EINVAL;
583 }
584
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585 arg.vdev_id = vdev_id;
586 arg.channel.freq = channel->center_freq;
587 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
588
589 /* TODO setup this dynamically, what in case we
590 don't have any vifs? */
591 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200592 arg.channel.chan_radar =
593 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
Michal Kazior89c5c842013-10-23 04:02:13 -0700595 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700596 arg.channel.max_power = channel->max_power * 2;
597 arg.channel.max_reg_power = channel->max_reg_power * 2;
598 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599
600 ret = ath10k_wmi_vdev_start(ar, &arg);
601 if (ret) {
602 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
603 return ret;
604 }
605
606 ret = ath10k_vdev_setup_sync(ar);
607 if (ret) {
608 ath10k_warn("Monitor vdev setup failed %d\n", ret);
609 return ret;
610 }
611
612 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
613 if (ret) {
614 ath10k_warn("Monitor vdev up failed: %d\n", ret);
615 goto vdev_stop;
616 }
617
618 ar->monitor_vdev_id = vdev_id;
619 ar->monitor_enabled = true;
620
621 return 0;
622
623vdev_stop:
624 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
625 if (ret)
626 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
627
628 return ret;
629}
630
631static int ath10k_monitor_stop(struct ath10k *ar)
632{
633 int ret = 0;
634
635 lockdep_assert_held(&ar->conf_mutex);
636
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300637 if (!ar->monitor_present) {
638 ath10k_warn("mac montor stop -- monitor is not present\n");
639 return -EINVAL;
640 }
641
642 if (!ar->monitor_enabled) {
643 ath10k_warn("mac montor stop -- monitor is not enabled\n");
644 return -EINVAL;
645 }
646
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200647 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
648 if (ret)
649 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300650
651 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
652 if (ret)
653 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
654
655 ret = ath10k_vdev_setup_sync(ar);
656 if (ret)
657 ath10k_warn("Monitor_down sync failed: %d\n", ret);
658
659 ar->monitor_enabled = false;
660 return ret;
661}
662
663static int ath10k_monitor_create(struct ath10k *ar)
664{
665 int bit, ret = 0;
666
667 lockdep_assert_held(&ar->conf_mutex);
668
669 if (ar->monitor_present) {
670 ath10k_warn("Monitor mode already enabled\n");
671 return 0;
672 }
673
674 bit = ffs(ar->free_vdev_map);
675 if (bit == 0) {
676 ath10k_warn("No free VDEV slots\n");
677 return -ENOMEM;
678 }
679
680 ar->monitor_vdev_id = bit - 1;
681 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
682
683 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
684 WMI_VDEV_TYPE_MONITOR,
685 0, ar->mac_addr);
686 if (ret) {
687 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
688 goto vdev_fail;
689 }
690
Kalle Valo60c3daa2013-09-08 17:56:07 +0300691 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 ar->monitor_vdev_id);
693
694 ar->monitor_present = true;
695 return 0;
696
697vdev_fail:
698 /*
699 * Restore the ID to the global map.
700 */
701 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
702 return ret;
703}
704
705static int ath10k_monitor_destroy(struct ath10k *ar)
706{
707 int ret = 0;
708
709 lockdep_assert_held(&ar->conf_mutex);
710
711 if (!ar->monitor_present)
712 return 0;
713
714 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
715 if (ret) {
716 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
717 return ret;
718 }
719
720 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
721 ar->monitor_present = false;
722
Kalle Valo60c3daa2013-09-08 17:56:07 +0300723 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300724 ar->monitor_vdev_id);
725 return ret;
726}
727
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200728static int ath10k_start_cac(struct ath10k *ar)
729{
730 int ret;
731
732 lockdep_assert_held(&ar->conf_mutex);
733
734 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
735
736 ret = ath10k_monitor_create(ar);
737 if (ret) {
738 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
739 return ret;
740 }
741
742 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
743 if (ret) {
744 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
745 ath10k_monitor_destroy(ar);
746 return ret;
747 }
748
749 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
750 ar->monitor_vdev_id);
751
752 return 0;
753}
754
755static int ath10k_stop_cac(struct ath10k *ar)
756{
757 lockdep_assert_held(&ar->conf_mutex);
758
759 /* CAC is not running - do nothing */
760 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
761 return 0;
762
763 ath10k_monitor_stop(ar);
764 ath10k_monitor_destroy(ar);
765 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
766
767 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
768
769 return 0;
770}
771
772static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
773{
774 switch (dfs_state) {
775 case NL80211_DFS_USABLE:
776 return "USABLE";
777 case NL80211_DFS_UNAVAILABLE:
778 return "UNAVAILABLE";
779 case NL80211_DFS_AVAILABLE:
780 return "AVAILABLE";
781 default:
782 WARN_ON(1);
783 return "bug";
784 }
785}
786
787static void ath10k_config_radar_detection(struct ath10k *ar)
788{
789 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
790 bool radar = ar->hw->conf.radar_enabled;
791 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
792 enum nl80211_dfs_state dfs_state = chan->dfs_state;
793 int ret;
794
795 lockdep_assert_held(&ar->conf_mutex);
796
797 ath10k_dbg(ATH10K_DBG_MAC,
798 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
799 chan->center_freq, radar, chan_radar,
800 ath10k_dfs_state(dfs_state));
801
802 /*
803 * It's safe to call it even if CAC is not started.
804 * This call here guarantees changing channel, etc. will stop CAC.
805 */
806 ath10k_stop_cac(ar);
807
808 if (!radar)
809 return;
810
811 if (!chan_radar)
812 return;
813
814 if (dfs_state != NL80211_DFS_USABLE)
815 return;
816
817 ret = ath10k_start_cac(ar);
818 if (ret) {
819 /*
820 * Not possible to start CAC on current channel so starting
821 * radiation is not allowed, make this channel DFS_UNAVAILABLE
822 * by indicating that radar was detected.
823 */
824 ath10k_warn("failed to start CAC (%d)\n", ret);
825 ieee80211_radar_detected(ar->hw);
826 }
827}
828
Kalle Valo5e3dd152013-06-12 20:52:10 +0300829static void ath10k_control_beaconing(struct ath10k_vif *arvif,
830 struct ieee80211_bss_conf *info)
831{
832 int ret = 0;
833
Michal Kazior548db542013-07-05 16:15:15 +0300834 lockdep_assert_held(&arvif->ar->conf_mutex);
835
Kalle Valo5e3dd152013-06-12 20:52:10 +0300836 if (!info->enable_beacon) {
837 ath10k_vdev_stop(arvif);
838 return;
839 }
840
841 arvif->tx_seq_no = 0x1000;
842
843 ret = ath10k_vdev_start(arvif);
844 if (ret)
845 return;
846
847 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
848 if (ret) {
849 ath10k_warn("Failed to bring up VDEV: %d\n",
850 arvif->vdev_id);
851 return;
852 }
Kalle Valo60c3daa2013-09-08 17:56:07 +0300853 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854}
855
856static void ath10k_control_ibss(struct ath10k_vif *arvif,
857 struct ieee80211_bss_conf *info,
858 const u8 self_peer[ETH_ALEN])
859{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200860 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300861 int ret = 0;
862
Michal Kazior548db542013-07-05 16:15:15 +0300863 lockdep_assert_held(&arvif->ar->conf_mutex);
864
Kalle Valo5e3dd152013-06-12 20:52:10 +0300865 if (!info->ibss_joined) {
866 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
867 if (ret)
868 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
869 self_peer, arvif->vdev_id, ret);
870
871 if (is_zero_ether_addr(arvif->u.ibss.bssid))
872 return;
873
874 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
875 arvif->u.ibss.bssid);
876 if (ret) {
877 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
878 arvif->u.ibss.bssid, arvif->vdev_id, ret);
879 return;
880 }
881
882 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
883
884 return;
885 }
886
887 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
888 if (ret) {
889 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
890 self_peer, arvif->vdev_id, ret);
891 return;
892 }
893
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200894 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
895 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300896 ATH10K_DEFAULT_ATIM);
897 if (ret)
898 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
899 arvif->vdev_id, ret);
900}
901
902/*
903 * Review this when mac80211 gains per-interface powersave support.
904 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300905static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300906{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300907 struct ath10k *ar = arvif->ar;
908 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300909 enum wmi_sta_powersave_param param;
910 enum wmi_sta_ps_mode psmode;
911 int ret;
912
Michal Kazior548db542013-07-05 16:15:15 +0300913 lockdep_assert_held(&arvif->ar->conf_mutex);
914
Michal Kaziorad088bf2013-10-16 15:44:46 +0300915 if (arvif->vif->type != NL80211_IFTYPE_STATION)
916 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917
918 if (conf->flags & IEEE80211_CONF_PS) {
919 psmode = WMI_STA_PS_MODE_ENABLED;
920 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
921
Michal Kaziorad088bf2013-10-16 15:44:46 +0300922 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300923 conf->dynamic_ps_timeout);
924 if (ret) {
925 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
926 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300927 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929 } else {
930 psmode = WMI_STA_PS_MODE_DISABLED;
931 }
932
Kalle Valo60c3daa2013-09-08 17:56:07 +0300933 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
934 arvif->vdev_id, psmode ? "enable" : "disable");
935
Michal Kaziorad088bf2013-10-16 15:44:46 +0300936 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
937 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
939 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300940 return ret;
941 }
942
943 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944}
945
946/**********************/
947/* Station management */
948/**********************/
949
950static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
951 struct ath10k_vif *arvif,
952 struct ieee80211_sta *sta,
953 struct ieee80211_bss_conf *bss_conf,
954 struct wmi_peer_assoc_complete_arg *arg)
955{
Michal Kazior548db542013-07-05 16:15:15 +0300956 lockdep_assert_held(&ar->conf_mutex);
957
Kalle Valo5e3dd152013-06-12 20:52:10 +0300958 memcpy(arg->addr, sta->addr, ETH_ALEN);
959 arg->vdev_id = arvif->vdev_id;
960 arg->peer_aid = sta->aid;
961 arg->peer_flags |= WMI_PEER_AUTH;
962
963 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
964 /*
965 * Seems FW have problems with Power Save in STA
966 * mode when we setup this parameter to high (eg. 5).
967 * Often we see that FW don't send NULL (with clean P flags)
968 * frame even there is info about buffered frames in beacons.
969 * Sometimes we have to wait more than 10 seconds before FW
970 * will wakeup. Often sending one ping from AP to our device
971 * just fail (more than 50%).
972 *
973 * Seems setting this FW parameter to 1 couse FW
974 * will check every beacon and will wakup immediately
975 * after detection buffered data.
976 */
977 arg->peer_listen_intval = 1;
978 else
979 arg->peer_listen_intval = ar->hw->conf.listen_interval;
980
981 arg->peer_num_spatial_streams = 1;
982
983 /*
984 * The assoc capabilities are available only in managed mode.
985 */
986 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
987 arg->peer_caps = bss_conf->assoc_capability;
988}
989
990static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
991 struct ath10k_vif *arvif,
992 struct wmi_peer_assoc_complete_arg *arg)
993{
994 struct ieee80211_vif *vif = arvif->vif;
995 struct ieee80211_bss_conf *info = &vif->bss_conf;
996 struct cfg80211_bss *bss;
997 const u8 *rsnie = NULL;
998 const u8 *wpaie = NULL;
999
Michal Kazior548db542013-07-05 16:15:15 +03001000 lockdep_assert_held(&ar->conf_mutex);
1001
Kalle Valo5e3dd152013-06-12 20:52:10 +03001002 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1003 info->bssid, NULL, 0, 0, 0);
1004 if (bss) {
1005 const struct cfg80211_bss_ies *ies;
1006
1007 rcu_read_lock();
1008 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1009
1010 ies = rcu_dereference(bss->ies);
1011
1012 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1013 WLAN_OUI_TYPE_MICROSOFT_WPA,
1014 ies->data,
1015 ies->len);
1016 rcu_read_unlock();
1017 cfg80211_put_bss(ar->hw->wiphy, bss);
1018 }
1019
1020 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1021 if (rsnie || wpaie) {
1022 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1023 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1024 }
1025
1026 if (wpaie) {
1027 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1028 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1029 }
1030}
1031
1032static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1033 struct ieee80211_sta *sta,
1034 struct wmi_peer_assoc_complete_arg *arg)
1035{
1036 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1037 const struct ieee80211_supported_band *sband;
1038 const struct ieee80211_rate *rates;
1039 u32 ratemask;
1040 int i;
1041
Michal Kazior548db542013-07-05 16:15:15 +03001042 lockdep_assert_held(&ar->conf_mutex);
1043
Kalle Valo5e3dd152013-06-12 20:52:10 +03001044 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1045 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1046 rates = sband->bitrates;
1047
1048 rateset->num_rates = 0;
1049
1050 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1051 if (!(ratemask & 1))
1052 continue;
1053
1054 rateset->rates[rateset->num_rates] = rates->hw_value;
1055 rateset->num_rates++;
1056 }
1057}
1058
1059static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1060 struct ieee80211_sta *sta,
1061 struct wmi_peer_assoc_complete_arg *arg)
1062{
1063 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1064 int smps;
1065 int i, n;
1066
Michal Kazior548db542013-07-05 16:15:15 +03001067 lockdep_assert_held(&ar->conf_mutex);
1068
Kalle Valo5e3dd152013-06-12 20:52:10 +03001069 if (!ht_cap->ht_supported)
1070 return;
1071
1072 arg->peer_flags |= WMI_PEER_HT;
1073 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1074 ht_cap->ampdu_factor)) - 1;
1075
1076 arg->peer_mpdu_density =
1077 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1078
1079 arg->peer_ht_caps = ht_cap->cap;
1080 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1081
1082 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1083 arg->peer_flags |= WMI_PEER_LDPC;
1084
1085 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1086 arg->peer_flags |= WMI_PEER_40MHZ;
1087 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1088 }
1089
1090 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1091 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1092
1093 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1094 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1095
1096 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1097 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1098 arg->peer_flags |= WMI_PEER_STBC;
1099 }
1100
1101 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1102 u32 stbc;
1103 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1104 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1105 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1106 arg->peer_rate_caps |= stbc;
1107 arg->peer_flags |= WMI_PEER_STBC;
1108 }
1109
1110 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1111 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1112
1113 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1114 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1115 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1116 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1117 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1118 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1119 }
1120
1121 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1122 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1123 else if (ht_cap->mcs.rx_mask[1])
1124 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1125
1126 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1127 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1128 arg->peer_ht_rates.rates[n++] = i;
1129
1130 arg->peer_ht_rates.num_rates = n;
1131 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
1132
Kalle Valo60c3daa2013-09-08 17:56:07 +03001133 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1134 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001135 arg->peer_ht_rates.num_rates,
1136 arg->peer_num_spatial_streams);
1137}
1138
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001139static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1140 struct ath10k_vif *arvif,
1141 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001142{
1143 u32 uapsd = 0;
1144 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001145 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001146
Michal Kazior548db542013-07-05 16:15:15 +03001147 lockdep_assert_held(&ar->conf_mutex);
1148
Kalle Valo5e3dd152013-06-12 20:52:10 +03001149 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001150 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 sta->uapsd_queues, sta->max_sp);
1152
Kalle Valo5e3dd152013-06-12 20:52:10 +03001153 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1154 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1155 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1156 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1157 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1158 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1159 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1160 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1161 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1162 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1163 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1164 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1165
1166
1167 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1168 max_sp = sta->max_sp;
1169
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001170 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1171 sta->addr,
1172 WMI_AP_PS_PEER_PARAM_UAPSD,
1173 uapsd);
1174 if (ret) {
1175 ath10k_warn("failed to set ap ps peer param uapsd: %d\n",
1176 ret);
1177 return ret;
1178 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001179
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001180 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1181 sta->addr,
1182 WMI_AP_PS_PEER_PARAM_MAX_SP,
1183 max_sp);
1184 if (ret) {
1185 ath10k_warn("failed to set ap ps peer param max sp: %d\n",
1186 ret);
1187 return ret;
1188 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189
1190 /* TODO setup this based on STA listen interval and
1191 beacon interval. Currently we don't know
1192 sta->listen_interval - mac80211 patch required.
1193 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001194 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1195 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1196 if (ret) {
1197 ath10k_warn("failed to set ap ps peer param ageout time: %d\n",
1198 ret);
1199 return ret;
1200 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001201 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001202
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001203 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001204}
1205
1206static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1207 struct ieee80211_sta *sta,
1208 struct wmi_peer_assoc_complete_arg *arg)
1209{
1210 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001211 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001212
1213 if (!vht_cap->vht_supported)
1214 return;
1215
1216 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001217 arg->peer_vht_caps = vht_cap->cap;
1218
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001219
1220 ampdu_factor = (vht_cap->cap &
1221 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1222 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1223
1224 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1225 * zero in VHT IE. Using it would result in degraded throughput.
1226 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1227 * it if VHT max_mpdu is smaller. */
1228 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1229 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1230 ampdu_factor)) - 1);
1231
Kalle Valo5e3dd152013-06-12 20:52:10 +03001232 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1233 arg->peer_flags |= WMI_PEER_80MHZ;
1234
1235 arg->peer_vht_rates.rx_max_rate =
1236 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1237 arg->peer_vht_rates.rx_mcs_set =
1238 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1239 arg->peer_vht_rates.tx_max_rate =
1240 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1241 arg->peer_vht_rates.tx_mcs_set =
1242 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1243
Kalle Valo60c3daa2013-09-08 17:56:07 +03001244 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1245 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001246}
1247
1248static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1249 struct ath10k_vif *arvif,
1250 struct ieee80211_sta *sta,
1251 struct ieee80211_bss_conf *bss_conf,
1252 struct wmi_peer_assoc_complete_arg *arg)
1253{
1254 switch (arvif->vdev_type) {
1255 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001256 if (sta->wme)
1257 arg->peer_flags |= WMI_PEER_QOS;
1258
1259 if (sta->wme && sta->uapsd_queues) {
1260 arg->peer_flags |= WMI_PEER_APSD;
1261 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1262 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263 break;
1264 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001265 if (bss_conf->qos)
1266 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267 break;
1268 default:
1269 break;
1270 }
1271}
1272
1273static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1274 struct ath10k_vif *arvif,
1275 struct ieee80211_sta *sta,
1276 struct wmi_peer_assoc_complete_arg *arg)
1277{
1278 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1279
Kalle Valo5e3dd152013-06-12 20:52:10 +03001280 switch (ar->hw->conf.chandef.chan->band) {
1281 case IEEE80211_BAND_2GHZ:
1282 if (sta->ht_cap.ht_supported) {
1283 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1284 phymode = MODE_11NG_HT40;
1285 else
1286 phymode = MODE_11NG_HT20;
1287 } else {
1288 phymode = MODE_11G;
1289 }
1290
1291 break;
1292 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001293 /*
1294 * Check VHT first.
1295 */
1296 if (sta->vht_cap.vht_supported) {
1297 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1298 phymode = MODE_11AC_VHT80;
1299 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1300 phymode = MODE_11AC_VHT40;
1301 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1302 phymode = MODE_11AC_VHT20;
1303 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001304 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1305 phymode = MODE_11NA_HT40;
1306 else
1307 phymode = MODE_11NA_HT20;
1308 } else {
1309 phymode = MODE_11A;
1310 }
1311
1312 break;
1313 default:
1314 break;
1315 }
1316
Kalle Valo38a1d472013-09-08 17:56:14 +03001317 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1318 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001319
Kalle Valo5e3dd152013-06-12 20:52:10 +03001320 arg->peer_phymode = phymode;
1321 WARN_ON(phymode == MODE_UNKNOWN);
1322}
1323
Kalle Valob9ada652013-10-16 15:44:46 +03001324static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1325 struct ath10k_vif *arvif,
1326 struct ieee80211_sta *sta,
1327 struct ieee80211_bss_conf *bss_conf,
1328 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001329{
Michal Kazior548db542013-07-05 16:15:15 +03001330 lockdep_assert_held(&ar->conf_mutex);
1331
Kalle Valob9ada652013-10-16 15:44:46 +03001332 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001333
Kalle Valob9ada652013-10-16 15:44:46 +03001334 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1335 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1336 ath10k_peer_assoc_h_rates(ar, sta, arg);
1337 ath10k_peer_assoc_h_ht(ar, sta, arg);
1338 ath10k_peer_assoc_h_vht(ar, sta, arg);
1339 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1340 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341
Kalle Valob9ada652013-10-16 15:44:46 +03001342 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001343}
1344
1345/* can be called only in mac80211 callbacks due to `key_count` usage */
1346static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1347 struct ieee80211_vif *vif,
1348 struct ieee80211_bss_conf *bss_conf)
1349{
1350 struct ath10k *ar = hw->priv;
1351 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001352 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001353 struct ieee80211_sta *ap_sta;
1354 int ret;
1355
Michal Kazior548db542013-07-05 16:15:15 +03001356 lockdep_assert_held(&ar->conf_mutex);
1357
Kalle Valo5e3dd152013-06-12 20:52:10 +03001358 rcu_read_lock();
1359
1360 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1361 if (!ap_sta) {
1362 ath10k_warn("Failed to find station entry for %pM\n",
1363 bss_conf->bssid);
1364 rcu_read_unlock();
1365 return;
1366 }
1367
Kalle Valob9ada652013-10-16 15:44:46 +03001368 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1369 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001370 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001371 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1372 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 rcu_read_unlock();
1374 return;
1375 }
1376
1377 rcu_read_unlock();
1378
Kalle Valob9ada652013-10-16 15:44:46 +03001379 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1380 if (ret) {
1381 ath10k_warn("Peer assoc failed for %pM\n: %d",
1382 bss_conf->bssid, ret);
1383 return;
1384 }
1385
Kalle Valo60c3daa2013-09-08 17:56:07 +03001386 ath10k_dbg(ATH10K_DBG_MAC,
1387 "mac vdev %d up (associated) bssid %pM aid %d\n",
1388 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1389
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1391 bss_conf->bssid);
1392 if (ret)
1393 ath10k_warn("VDEV: %d up failed: ret %d\n",
1394 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001395}
1396
1397/*
1398 * FIXME: flush TIDs
1399 */
1400static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1401 struct ieee80211_vif *vif)
1402{
1403 struct ath10k *ar = hw->priv;
1404 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1405 int ret;
1406
Michal Kazior548db542013-07-05 16:15:15 +03001407 lockdep_assert_held(&ar->conf_mutex);
1408
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 /*
1410 * For some reason, calling VDEV-DOWN before VDEV-STOP
1411 * makes the FW to send frames via HTT after disassociation.
1412 * No idea why this happens, even though VDEV-DOWN is supposed
1413 * to be analogous to link down, so just stop the VDEV.
1414 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001415 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1416 arvif->vdev_id);
1417
1418 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001419 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001420
1421 /*
1422 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1423 * report beacons from previously associated network through HTT.
1424 * This in turn would spam mac80211 WARN_ON if we bring down all
1425 * interfaces as it expects there is no rx when no interface is
1426 * running.
1427 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001428 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1429
1430 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001431 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001432
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001433 arvif->def_wep_key_idx = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001434}
1435
1436static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1437 struct ieee80211_sta *sta)
1438{
Kalle Valob9ada652013-10-16 15:44:46 +03001439 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001440 int ret = 0;
1441
Michal Kazior548db542013-07-05 16:15:15 +03001442 lockdep_assert_held(&ar->conf_mutex);
1443
Kalle Valob9ada652013-10-16 15:44:46 +03001444 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001445 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001446 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1447 sta->addr);
1448 return ret;
1449 }
1450
1451 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1452 if (ret) {
1453 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1454 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001455 return ret;
1456 }
1457
1458 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1459 if (ret) {
1460 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1461 return ret;
1462 }
1463
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001464 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1465 if (ret) {
1466 ath10k_warn("could not set qos params for STA %pM, %d\n",
1467 sta->addr, ret);
1468 return ret;
1469 }
1470
Kalle Valo5e3dd152013-06-12 20:52:10 +03001471 return ret;
1472}
1473
1474static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1475 struct ieee80211_sta *sta)
1476{
1477 int ret = 0;
1478
Michal Kazior548db542013-07-05 16:15:15 +03001479 lockdep_assert_held(&ar->conf_mutex);
1480
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1482 if (ret) {
1483 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1484 return ret;
1485 }
1486
1487 return ret;
1488}
1489
1490/**************/
1491/* Regulatory */
1492/**************/
1493
1494static int ath10k_update_channel_list(struct ath10k *ar)
1495{
1496 struct ieee80211_hw *hw = ar->hw;
1497 struct ieee80211_supported_band **bands;
1498 enum ieee80211_band band;
1499 struct ieee80211_channel *channel;
1500 struct wmi_scan_chan_list_arg arg = {0};
1501 struct wmi_channel_arg *ch;
1502 bool passive;
1503 int len;
1504 int ret;
1505 int i;
1506
Michal Kazior548db542013-07-05 16:15:15 +03001507 lockdep_assert_held(&ar->conf_mutex);
1508
Kalle Valo5e3dd152013-06-12 20:52:10 +03001509 bands = hw->wiphy->bands;
1510 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1511 if (!bands[band])
1512 continue;
1513
1514 for (i = 0; i < bands[band]->n_channels; i++) {
1515 if (bands[band]->channels[i].flags &
1516 IEEE80211_CHAN_DISABLED)
1517 continue;
1518
1519 arg.n_channels++;
1520 }
1521 }
1522
1523 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1524 arg.channels = kzalloc(len, GFP_KERNEL);
1525 if (!arg.channels)
1526 return -ENOMEM;
1527
1528 ch = arg.channels;
1529 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1530 if (!bands[band])
1531 continue;
1532
1533 for (i = 0; i < bands[band]->n_channels; i++) {
1534 channel = &bands[band]->channels[i];
1535
1536 if (channel->flags & IEEE80211_CHAN_DISABLED)
1537 continue;
1538
1539 ch->allow_ht = true;
1540
1541 /* FIXME: when should we really allow VHT? */
1542 ch->allow_vht = true;
1543
1544 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001545 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001546
1547 ch->ht40plus =
1548 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1549
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001550 ch->chan_radar =
1551 !!(channel->flags & IEEE80211_CHAN_RADAR);
1552
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001553 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554 ch->passive = passive;
1555
1556 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001557 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001558 ch->max_power = channel->max_power * 2;
1559 ch->max_reg_power = channel->max_reg_power * 2;
1560 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 ch->reg_class_id = 0; /* FIXME */
1562
1563 /* FIXME: why use only legacy modes, why not any
1564 * HT/VHT modes? Would that even make any
1565 * difference? */
1566 if (channel->band == IEEE80211_BAND_2GHZ)
1567 ch->mode = MODE_11G;
1568 else
1569 ch->mode = MODE_11A;
1570
1571 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1572 continue;
1573
1574 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001575 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1576 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001577 ch->freq, ch->max_power, ch->max_reg_power,
1578 ch->max_antenna_gain, ch->mode);
1579
1580 ch++;
1581 }
1582 }
1583
1584 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1585 kfree(arg.channels);
1586
1587 return ret;
1588}
1589
Michal Kaziorf7843d72013-07-16 09:38:52 +02001590static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001593 int ret;
1594
Michal Kaziorf7843d72013-07-16 09:38:52 +02001595 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001596
1597 ret = ath10k_update_channel_list(ar);
1598 if (ret)
1599 ath10k_warn("could not update channel list (%d)\n", ret);
1600
1601 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001602
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 /* Target allows setting up per-band regdomain but ath_common provides
1604 * a combined one only */
1605 ret = ath10k_wmi_pdev_set_regdomain(ar,
1606 regpair->regDmnEnum,
1607 regpair->regDmnEnum, /* 2ghz */
1608 regpair->regDmnEnum, /* 5ghz */
1609 regpair->reg_2ghz_ctl,
1610 regpair->reg_5ghz_ctl);
1611 if (ret)
1612 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001613}
Michal Kazior548db542013-07-05 16:15:15 +03001614
Michal Kaziorf7843d72013-07-16 09:38:52 +02001615static void ath10k_reg_notifier(struct wiphy *wiphy,
1616 struct regulatory_request *request)
1617{
1618 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1619 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001620 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001621
1622 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1623
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001624 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1625 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1626 request->dfs_region);
1627 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1628 request->dfs_region);
1629 if (!result)
1630 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1631 request->dfs_region);
1632 }
1633
Michal Kaziorf7843d72013-07-16 09:38:52 +02001634 mutex_lock(&ar->conf_mutex);
1635 if (ar->state == ATH10K_STATE_ON)
1636 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001637 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001638}
1639
1640/***************/
1641/* TX handlers */
1642/***************/
1643
Michal Kazior42c3aa62013-10-02 11:03:38 +02001644static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1645{
1646 if (ieee80211_is_mgmt(hdr->frame_control))
1647 return HTT_DATA_TX_EXT_TID_MGMT;
1648
1649 if (!ieee80211_is_data_qos(hdr->frame_control))
1650 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1651
1652 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1653 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1654
1655 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1656}
1657
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001658static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1659 struct ieee80211_tx_info *info)
1660{
1661 if (info->control.vif)
1662 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1663
1664 if (ar->monitor_enabled)
1665 return ar->monitor_vdev_id;
1666
1667 ath10k_warn("could not resolve vdev id\n");
1668 return 0;
1669}
1670
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671/*
1672 * Frames sent to the FW have to be in "Native Wifi" format.
1673 * Strip the QoS field from the 802.11 header.
1674 */
1675static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1676 struct ieee80211_tx_control *control,
1677 struct sk_buff *skb)
1678{
1679 struct ieee80211_hdr *hdr = (void *)skb->data;
1680 u8 *qos_ctl;
1681
1682 if (!ieee80211_is_data_qos(hdr->frame_control))
1683 return;
1684
1685 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001686 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1687 skb->data, (void *)qos_ctl - (void *)skb->data);
1688 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001689}
1690
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001691static void ath10k_tx_wep_key_work(struct work_struct *work)
1692{
1693 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1694 wep_key_work);
1695 int ret, keyidx = arvif->def_wep_key_newidx;
1696
1697 if (arvif->def_wep_key_idx == keyidx)
1698 return;
1699
1700 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1701 arvif->vdev_id, keyidx);
1702
1703 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1704 arvif->vdev_id,
1705 arvif->ar->wmi.vdev_param->def_keyid,
1706 keyidx);
1707 if (ret) {
1708 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1709 return;
1710 }
1711
1712 arvif->def_wep_key_idx = keyidx;
1713}
1714
Kalle Valo5e3dd152013-06-12 20:52:10 +03001715static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1716{
1717 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1718 struct ieee80211_vif *vif = info->control.vif;
1719 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1720 struct ath10k *ar = arvif->ar;
1721 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1722 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001723
Kalle Valo5e3dd152013-06-12 20:52:10 +03001724 if (!ieee80211_has_protected(hdr->frame_control))
1725 return;
1726
1727 if (!key)
1728 return;
1729
1730 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1731 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1732 return;
1733
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001734 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735 return;
1736
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001737 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1738 * queueing frames until key index is updated is not an option because
1739 * sk_buff may need more processing to be done, e.g. offchannel */
1740 arvif->def_wep_key_newidx = key->keyidx;
1741 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742}
1743
1744static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1745{
1746 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1747 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1748 struct ieee80211_vif *vif = info->control.vif;
1749 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1750
1751 /* This is case only for P2P_GO */
1752 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1753 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1754 return;
1755
1756 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1757 spin_lock_bh(&ar->data_lock);
1758 if (arvif->u.ap.noa_data)
1759 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1760 GFP_ATOMIC))
1761 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1762 arvif->u.ap.noa_data,
1763 arvif->u.ap.noa_len);
1764 spin_unlock_bh(&ar->data_lock);
1765 }
1766}
1767
1768static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1769{
1770 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001771 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001772
Michal Kazior961d4c32013-08-09 10:13:34 +02001773 if (ar->htt.target_version_major >= 3) {
1774 /* Since HTT 3.0 there is no separate mgmt tx command */
1775 ret = ath10k_htt_tx(&ar->htt, skb);
1776 goto exit;
1777 }
1778
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001779 if (ieee80211_is_mgmt(hdr->frame_control)) {
1780 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1781 ar->fw_features)) {
1782 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1783 ATH10K_MAX_NUM_MGMT_PENDING) {
1784 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1785 ret = -EBUSY;
1786 goto exit;
1787 }
1788
1789 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1790 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1791 } else {
1792 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1793 }
1794 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1795 ar->fw_features) &&
1796 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001797 /* FW does not report tx status properly for NullFunc frames
1798 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001799 * those frames when it detects link/beacon loss and depends
1800 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001801 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001802 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001803 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001804 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001805
Michal Kazior961d4c32013-08-09 10:13:34 +02001806exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001807 if (ret) {
1808 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1809 ieee80211_free_txskb(ar->hw, skb);
1810 }
1811}
1812
1813void ath10k_offchan_tx_purge(struct ath10k *ar)
1814{
1815 struct sk_buff *skb;
1816
1817 for (;;) {
1818 skb = skb_dequeue(&ar->offchan_tx_queue);
1819 if (!skb)
1820 break;
1821
1822 ieee80211_free_txskb(ar->hw, skb);
1823 }
1824}
1825
1826void ath10k_offchan_tx_work(struct work_struct *work)
1827{
1828 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1829 struct ath10k_peer *peer;
1830 struct ieee80211_hdr *hdr;
1831 struct sk_buff *skb;
1832 const u8 *peer_addr;
1833 int vdev_id;
1834 int ret;
1835
1836 /* FW requirement: We must create a peer before FW will send out
1837 * an offchannel frame. Otherwise the frame will be stuck and
1838 * never transmitted. We delete the peer upon tx completion.
1839 * It is unlikely that a peer for offchannel tx will already be
1840 * present. However it may be in some rare cases so account for that.
1841 * Otherwise we might remove a legitimate peer and break stuff. */
1842
1843 for (;;) {
1844 skb = skb_dequeue(&ar->offchan_tx_queue);
1845 if (!skb)
1846 break;
1847
1848 mutex_lock(&ar->conf_mutex);
1849
Kalle Valo60c3daa2013-09-08 17:56:07 +03001850 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851 skb);
1852
1853 hdr = (struct ieee80211_hdr *)skb->data;
1854 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001855 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001856
1857 spin_lock_bh(&ar->data_lock);
1858 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1859 spin_unlock_bh(&ar->data_lock);
1860
1861 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001862 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001863 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1864 peer_addr, vdev_id);
1865
1866 if (!peer) {
1867 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1868 if (ret)
1869 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1870 peer_addr, vdev_id, ret);
1871 }
1872
1873 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001874 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001875 ar->offchan_tx_skb = skb;
1876 spin_unlock_bh(&ar->data_lock);
1877
1878 ath10k_tx_htt(ar, skb);
1879
1880 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1881 3 * HZ);
1882 if (ret <= 0)
1883 ath10k_warn("timed out waiting for offchannel skb %p\n",
1884 skb);
1885
1886 if (!peer) {
1887 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1888 if (ret)
1889 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1890 peer_addr, vdev_id, ret);
1891 }
1892
1893 mutex_unlock(&ar->conf_mutex);
1894 }
1895}
1896
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001897void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1898{
1899 struct sk_buff *skb;
1900
1901 for (;;) {
1902 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1903 if (!skb)
1904 break;
1905
1906 ieee80211_free_txskb(ar->hw, skb);
1907 }
1908}
1909
1910void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1911{
1912 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1913 struct sk_buff *skb;
1914 int ret;
1915
1916 for (;;) {
1917 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1918 if (!skb)
1919 break;
1920
1921 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001922 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001923 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001924 ieee80211_free_txskb(ar->hw, skb);
1925 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001926 }
1927}
1928
Kalle Valo5e3dd152013-06-12 20:52:10 +03001929/************/
1930/* Scanning */
1931/************/
1932
1933/*
1934 * This gets called if we dont get a heart-beat during scan.
1935 * This may indicate the FW has hung and we need to abort the
1936 * scan manually to prevent cancel_hw_scan() from deadlocking
1937 */
1938void ath10k_reset_scan(unsigned long ptr)
1939{
1940 struct ath10k *ar = (struct ath10k *)ptr;
1941
1942 spin_lock_bh(&ar->data_lock);
1943 if (!ar->scan.in_progress) {
1944 spin_unlock_bh(&ar->data_lock);
1945 return;
1946 }
1947
1948 ath10k_warn("scan timeout. resetting. fw issue?\n");
1949
1950 if (ar->scan.is_roc)
1951 ieee80211_remain_on_channel_expired(ar->hw);
1952 else
1953 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1954
1955 ar->scan.in_progress = false;
1956 complete_all(&ar->scan.completed);
1957 spin_unlock_bh(&ar->data_lock);
1958}
1959
1960static int ath10k_abort_scan(struct ath10k *ar)
1961{
1962 struct wmi_stop_scan_arg arg = {
1963 .req_id = 1, /* FIXME */
1964 .req_type = WMI_SCAN_STOP_ONE,
1965 .u.scan_id = ATH10K_SCAN_ID,
1966 };
1967 int ret;
1968
1969 lockdep_assert_held(&ar->conf_mutex);
1970
1971 del_timer_sync(&ar->scan.timeout);
1972
1973 spin_lock_bh(&ar->data_lock);
1974 if (!ar->scan.in_progress) {
1975 spin_unlock_bh(&ar->data_lock);
1976 return 0;
1977 }
1978
1979 ar->scan.aborting = true;
1980 spin_unlock_bh(&ar->data_lock);
1981
1982 ret = ath10k_wmi_stop_scan(ar, &arg);
1983 if (ret) {
1984 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03001985 spin_lock_bh(&ar->data_lock);
1986 ar->scan.in_progress = false;
1987 ath10k_offchan_tx_purge(ar);
1988 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001989 return -EIO;
1990 }
1991
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1993 if (ret == 0)
1994 ath10k_warn("timed out while waiting for scan to stop\n");
1995
1996 /* scan completion may be done right after we timeout here, so let's
1997 * check the in_progress and tell mac80211 scan is completed. if we
1998 * don't do that and FW fails to send us scan completion indication
1999 * then userspace won't be able to scan anymore */
2000 ret = 0;
2001
2002 spin_lock_bh(&ar->data_lock);
2003 if (ar->scan.in_progress) {
2004 ath10k_warn("could not stop scan. its still in progress\n");
2005 ar->scan.in_progress = false;
2006 ath10k_offchan_tx_purge(ar);
2007 ret = -ETIMEDOUT;
2008 }
2009 spin_unlock_bh(&ar->data_lock);
2010
2011 return ret;
2012}
2013
2014static int ath10k_start_scan(struct ath10k *ar,
2015 const struct wmi_start_scan_arg *arg)
2016{
2017 int ret;
2018
2019 lockdep_assert_held(&ar->conf_mutex);
2020
2021 ret = ath10k_wmi_start_scan(ar, arg);
2022 if (ret)
2023 return ret;
2024
Kalle Valo5e3dd152013-06-12 20:52:10 +03002025 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2026 if (ret == 0) {
2027 ath10k_abort_scan(ar);
2028 return ret;
2029 }
2030
2031 /* the scan can complete earlier, before we even
2032 * start the timer. in that case the timer handler
2033 * checks ar->scan.in_progress and bails out if its
2034 * false. Add a 200ms margin to account event/command
2035 * processing. */
2036 mod_timer(&ar->scan.timeout, jiffies +
2037 msecs_to_jiffies(arg->max_scan_time+200));
2038 return 0;
2039}
2040
2041/**********************/
2042/* mac80211 callbacks */
2043/**********************/
2044
2045static void ath10k_tx(struct ieee80211_hw *hw,
2046 struct ieee80211_tx_control *control,
2047 struct sk_buff *skb)
2048{
2049 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2050 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2051 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002052 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002053
2054 /* We should disable CCK RATE due to P2P */
2055 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2056 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2057
2058 /* we must calculate tid before we apply qos workaround
2059 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002060 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002061 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002062
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002063 /* it makes no sense to process injected frames like that */
2064 if (info->control.vif &&
2065 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2066 ath10k_tx_h_qos_workaround(hw, control, skb);
2067 ath10k_tx_h_update_wep_key(skb);
2068 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2069 ath10k_tx_h_seq_no(skb);
2070 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002071
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002072 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002073 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074 ATH10K_SKB_CB(skb)->htt.tid = tid;
2075
2076 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2077 spin_lock_bh(&ar->data_lock);
2078 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002079 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080 spin_unlock_bh(&ar->data_lock);
2081
2082 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2083
2084 skb_queue_tail(&ar->offchan_tx_queue, skb);
2085 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2086 return;
2087 }
2088
2089 ath10k_tx_htt(ar, skb);
2090}
2091
2092/*
2093 * Initialize various parameters with default vaules.
2094 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002095void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002096{
2097 lockdep_assert_held(&ar->conf_mutex);
2098
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002099 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002100 del_timer_sync(&ar->scan.timeout);
2101 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002102 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002103 ath10k_peer_cleanup_all(ar);
2104 ath10k_core_stop(ar);
2105 ath10k_hif_power_down(ar);
2106
2107 spin_lock_bh(&ar->data_lock);
2108 if (ar->scan.in_progress) {
2109 del_timer(&ar->scan.timeout);
2110 ar->scan.in_progress = false;
2111 ieee80211_scan_completed(ar->hw, true);
2112 }
2113 spin_unlock_bh(&ar->data_lock);
2114}
2115
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116static int ath10k_start(struct ieee80211_hw *hw)
2117{
2118 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002119 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002120
Michal Kazior548db542013-07-05 16:15:15 +03002121 mutex_lock(&ar->conf_mutex);
2122
Michal Kazioraffd3212013-07-16 09:54:35 +02002123 if (ar->state != ATH10K_STATE_OFF &&
2124 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002125 ret = -EINVAL;
2126 goto exit;
2127 }
2128
2129 ret = ath10k_hif_power_up(ar);
2130 if (ret) {
2131 ath10k_err("could not init hif (%d)\n", ret);
2132 ar->state = ATH10K_STATE_OFF;
2133 goto exit;
2134 }
2135
2136 ret = ath10k_core_start(ar);
2137 if (ret) {
2138 ath10k_err("could not init core (%d)\n", ret);
2139 ath10k_hif_power_down(ar);
2140 ar->state = ATH10K_STATE_OFF;
2141 goto exit;
2142 }
2143
Michal Kazioraffd3212013-07-16 09:54:35 +02002144 if (ar->state == ATH10K_STATE_OFF)
2145 ar->state = ATH10K_STATE_ON;
2146 else if (ar->state == ATH10K_STATE_RESTARTING)
2147 ar->state = ATH10K_STATE_RESTARTED;
2148
Bartosz Markowski226a3392013-09-26 17:47:16 +02002149 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150 if (ret)
2151 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2152 ret);
2153
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002154 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155 if (ret)
2156 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2157 ret);
2158
Michal Kaziorf7843d72013-07-16 09:38:52 +02002159 ath10k_regd_update(ar);
2160
Michal Kazior818bdd12013-07-16 09:38:57 +02002161exit:
Michal Kazior548db542013-07-05 16:15:15 +03002162 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163 return 0;
2164}
2165
2166static void ath10k_stop(struct ieee80211_hw *hw)
2167{
2168 struct ath10k *ar = hw->priv;
2169
Michal Kazior548db542013-07-05 16:15:15 +03002170 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002171 if (ar->state == ATH10K_STATE_ON ||
2172 ar->state == ATH10K_STATE_RESTARTED ||
2173 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002174 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002175
Michal Kaziorf7843d72013-07-16 09:38:52 +02002176 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002177 mutex_unlock(&ar->conf_mutex);
2178
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002179 ath10k_mgmt_over_wmi_tx_purge(ar);
2180
Michal Kazior548db542013-07-05 16:15:15 +03002181 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002182 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002183 cancel_work_sync(&ar->restart_work);
2184}
2185
Michal Kaziorad088bf2013-10-16 15:44:46 +03002186static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002187{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002188 struct ath10k_vif *arvif;
2189 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002190
2191 lockdep_assert_held(&ar->conf_mutex);
2192
Michal Kaziorad088bf2013-10-16 15:44:46 +03002193 list_for_each_entry(arvif, &ar->arvifs, list) {
2194 ret = ath10k_mac_vif_setup_ps(arvif);
2195 if (ret) {
2196 ath10k_warn("could not setup powersave (%d)\n", ret);
2197 break;
2198 }
2199 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002200
Michal Kaziorad088bf2013-10-16 15:44:46 +03002201 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002202}
2203
2204static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2205{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002206 struct ath10k *ar = hw->priv;
2207 struct ieee80211_conf *conf = &hw->conf;
2208 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002209 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210
2211 mutex_lock(&ar->conf_mutex);
2212
2213 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002214 ath10k_dbg(ATH10K_DBG_MAC,
2215 "mac config channel %d mhz flags 0x%x\n",
2216 conf->chandef.chan->center_freq,
2217 conf->chandef.chan->flags);
2218
Kalle Valo5e3dd152013-06-12 20:52:10 +03002219 spin_lock_bh(&ar->data_lock);
2220 ar->rx_channel = conf->chandef.chan;
2221 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002222
2223 ath10k_config_radar_detection(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224 }
2225
Michal Kazior5474efe2013-10-23 04:02:15 -07002226 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2227 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2228 hw->conf.power_level);
2229
2230 param = ar->wmi.pdev_param->txpower_limit2g;
2231 ret = ath10k_wmi_pdev_set_param(ar, param,
2232 hw->conf.power_level * 2);
2233 if (ret)
2234 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2235 hw->conf.power_level, ret);
2236
2237 param = ar->wmi.pdev_param->txpower_limit5g;
2238 ret = ath10k_wmi_pdev_set_param(ar, param,
2239 hw->conf.power_level * 2);
2240 if (ret)
2241 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2242 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 }
2244
Michal Kazioraffd3212013-07-16 09:54:35 +02002245 if (changed & IEEE80211_CONF_CHANGE_PS)
2246 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247
2248 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2249 if (conf->flags & IEEE80211_CONF_MONITOR)
2250 ret = ath10k_monitor_create(ar);
2251 else
2252 ret = ath10k_monitor_destroy(ar);
2253 }
2254
2255 mutex_unlock(&ar->conf_mutex);
2256 return ret;
2257}
2258
2259/*
2260 * TODO:
2261 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2262 * because we will send mgmt frames without CCK. This requirement
2263 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2264 * in the TX packet.
2265 */
2266static int ath10k_add_interface(struct ieee80211_hw *hw,
2267 struct ieee80211_vif *vif)
2268{
2269 struct ath10k *ar = hw->priv;
2270 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2271 enum wmi_sta_powersave_param param;
2272 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002273 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002274 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002275 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276
2277 mutex_lock(&ar->conf_mutex);
2278
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002279 memset(arvif, 0, sizeof(*arvif));
2280
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 arvif->ar = ar;
2282 arvif->vif = vif;
2283
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002284 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002285 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002286
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2288 ath10k_warn("Only one monitor interface allowed\n");
2289 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002290 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 }
2292
2293 bit = ffs(ar->free_vdev_map);
2294 if (bit == 0) {
2295 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002296 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002297 }
2298
2299 arvif->vdev_id = bit - 1;
2300 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301
2302 if (ar->p2p)
2303 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2304
2305 switch (vif->type) {
2306 case NL80211_IFTYPE_UNSPECIFIED:
2307 case NL80211_IFTYPE_STATION:
2308 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2309 if (vif->p2p)
2310 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2311 break;
2312 case NL80211_IFTYPE_ADHOC:
2313 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2314 break;
2315 case NL80211_IFTYPE_AP:
2316 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2317
2318 if (vif->p2p)
2319 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2320 break;
2321 case NL80211_IFTYPE_MONITOR:
2322 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2323 break;
2324 default:
2325 WARN_ON(1);
2326 break;
2327 }
2328
Kalle Valo60c3daa2013-09-08 17:56:07 +03002329 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002330 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2331
2332 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2333 arvif->vdev_subtype, vif->addr);
2334 if (ret) {
2335 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002336 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002337 }
2338
Michal Kazior9dad14a2013-10-16 15:44:45 +03002339 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002340 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002341
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002342 vdev_param = ar->wmi.vdev_param->def_keyid;
2343 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002344 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002345 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002347 goto err_vdev_delete;
2348 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002349
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002350 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2351 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002352 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002353 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002354 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002356 goto err_vdev_delete;
2357 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002358
2359 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2360 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2361 if (ret) {
2362 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002363 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002364 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002365
Kalle Valo5a13e762014-01-20 11:01:46 +02002366 ret = ath10k_mac_set_kickout(arvif);
2367 if (ret) {
2368 ath10k_warn("Failed to set kickout parameters: %d\n",
2369 ret);
2370 goto err_peer_delete;
2371 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002372 }
2373
2374 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2375 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2376 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2377 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2378 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002379 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002380 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002381 goto err_peer_delete;
2382 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002383
2384 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2385 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2386 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2387 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002388 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002389 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002390 goto err_peer_delete;
2391 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002392
2393 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2394 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2395 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2396 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002397 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002398 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002399 goto err_peer_delete;
2400 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002401 }
2402
Michal Kazior424121c2013-07-22 14:13:31 +02002403 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002404 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002405 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2406 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002407 goto err_peer_delete;
2408 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002409
Michal Kazior424121c2013-07-22 14:13:31 +02002410 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002411 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002412 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2413 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002414 goto err_peer_delete;
2415 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002416
Kalle Valo5e3dd152013-06-12 20:52:10 +03002417 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2418 ar->monitor_present = true;
2419
Kalle Valo5e3dd152013-06-12 20:52:10 +03002420 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002421 return 0;
2422
2423err_peer_delete:
2424 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2425 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2426
2427err_vdev_delete:
2428 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2429 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002430 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002431
2432err:
2433 mutex_unlock(&ar->conf_mutex);
2434
Kalle Valo5e3dd152013-06-12 20:52:10 +03002435 return ret;
2436}
2437
2438static void ath10k_remove_interface(struct ieee80211_hw *hw,
2439 struct ieee80211_vif *vif)
2440{
2441 struct ath10k *ar = hw->priv;
2442 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2443 int ret;
2444
2445 mutex_lock(&ar->conf_mutex);
2446
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002447 cancel_work_sync(&arvif->wep_key_work);
2448
Michal Kaziored543882013-09-13 14:16:56 +02002449 spin_lock_bh(&ar->data_lock);
2450 if (arvif->beacon) {
2451 dev_kfree_skb_any(arvif->beacon);
2452 arvif->beacon = NULL;
2453 }
2454 spin_unlock_bh(&ar->data_lock);
2455
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002457 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458
2459 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2460 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2461 if (ret)
2462 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2463
2464 kfree(arvif->u.ap.noa_data);
2465 }
2466
Kalle Valo60c3daa2013-09-08 17:56:07 +03002467 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2468 arvif->vdev_id);
2469
Kalle Valo5e3dd152013-06-12 20:52:10 +03002470 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2471 if (ret)
2472 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2473
2474 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2475 ar->monitor_present = false;
2476
2477 ath10k_peer_cleanup(ar, arvif->vdev_id);
2478
2479 mutex_unlock(&ar->conf_mutex);
2480}
2481
2482/*
2483 * FIXME: Has to be verified.
2484 */
2485#define SUPPORTED_FILTERS \
2486 (FIF_PROMISC_IN_BSS | \
2487 FIF_ALLMULTI | \
2488 FIF_CONTROL | \
2489 FIF_PSPOLL | \
2490 FIF_OTHER_BSS | \
2491 FIF_BCN_PRBRESP_PROMISC | \
2492 FIF_PROBE_REQ | \
2493 FIF_FCSFAIL)
2494
2495static void ath10k_configure_filter(struct ieee80211_hw *hw,
2496 unsigned int changed_flags,
2497 unsigned int *total_flags,
2498 u64 multicast)
2499{
2500 struct ath10k *ar = hw->priv;
2501 int ret;
2502
2503 mutex_lock(&ar->conf_mutex);
2504
2505 changed_flags &= SUPPORTED_FILTERS;
2506 *total_flags &= SUPPORTED_FILTERS;
2507 ar->filter_flags = *total_flags;
2508
Michal Kaziorafd09222013-10-16 16:45:41 +03002509 /* Monitor must not be started if it wasn't created first.
2510 * Promiscuous mode may be started on a non-monitor interface - in
2511 * such case the monitor vdev is not created so starting the
2512 * monitor makes no sense. Since ath10k uses no special RX filters
2513 * (only BSS filter in STA mode) there's no need for any special
2514 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002516 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002517 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2518 ar->monitor_vdev_id);
2519
Kalle Valo5e3dd152013-06-12 20:52:10 +03002520 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2521 if (ret)
2522 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002524 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002525 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2526 ar->monitor_vdev_id);
2527
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528 ret = ath10k_monitor_stop(ar);
2529 if (ret)
2530 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002531 }
2532
2533 mutex_unlock(&ar->conf_mutex);
2534}
2535
2536static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2537 struct ieee80211_vif *vif,
2538 struct ieee80211_bss_conf *info,
2539 u32 changed)
2540{
2541 struct ath10k *ar = hw->priv;
2542 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2543 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002544 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545
2546 mutex_lock(&ar->conf_mutex);
2547
2548 if (changed & BSS_CHANGED_IBSS)
2549 ath10k_control_ibss(arvif, info, vif->addr);
2550
2551 if (changed & BSS_CHANGED_BEACON_INT) {
2552 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002553 vdev_param = ar->wmi.vdev_param->beacon_interval;
2554 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002556 ath10k_dbg(ATH10K_DBG_MAC,
2557 "mac vdev %d beacon_interval %d\n",
2558 arvif->vdev_id, arvif->beacon_interval);
2559
Kalle Valo5e3dd152013-06-12 20:52:10 +03002560 if (ret)
2561 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2562 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002563 }
2564
2565 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002566 ath10k_dbg(ATH10K_DBG_MAC,
2567 "vdev %d set beacon tx mode to staggered\n",
2568 arvif->vdev_id);
2569
Bartosz Markowski226a3392013-09-26 17:47:16 +02002570 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2571 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572 WMI_BEACON_STAGGERED_MODE);
2573 if (ret)
2574 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2575 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576 }
2577
John W. Linvilleb70727e2013-06-13 13:34:29 -04002578 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002579 arvif->dtim_period = info->dtim_period;
2580
Kalle Valo60c3daa2013-09-08 17:56:07 +03002581 ath10k_dbg(ATH10K_DBG_MAC,
2582 "mac vdev %d dtim_period %d\n",
2583 arvif->vdev_id, arvif->dtim_period);
2584
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002585 vdev_param = ar->wmi.vdev_param->dtim_period;
2586 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587 arvif->dtim_period);
2588 if (ret)
2589 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2590 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002591 }
2592
2593 if (changed & BSS_CHANGED_SSID &&
2594 vif->type == NL80211_IFTYPE_AP) {
2595 arvif->u.ap.ssid_len = info->ssid_len;
2596 if (info->ssid_len)
2597 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2598 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2599 }
2600
2601 if (changed & BSS_CHANGED_BSSID) {
2602 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002603 ath10k_dbg(ATH10K_DBG_MAC,
2604 "mac vdev %d create peer %pM\n",
2605 arvif->vdev_id, info->bssid);
2606
Kalle Valo5e3dd152013-06-12 20:52:10 +03002607 ret = ath10k_peer_create(ar, arvif->vdev_id,
2608 info->bssid);
2609 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002610 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2611 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002612
2613 if (vif->type == NL80211_IFTYPE_STATION) {
2614 /*
2615 * this is never erased as we it for crypto key
2616 * clearing; this is FW requirement
2617 */
2618 memcpy(arvif->u.sta.bssid, info->bssid,
2619 ETH_ALEN);
2620
Kalle Valo60c3daa2013-09-08 17:56:07 +03002621 ath10k_dbg(ATH10K_DBG_MAC,
2622 "mac vdev %d start %pM\n",
2623 arvif->vdev_id, info->bssid);
2624
2625 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002627 }
2628
2629 /*
2630 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2631 * so driver need to store it. It is needed when leaving
2632 * IBSS in order to remove BSSID peer.
2633 */
2634 if (vif->type == NL80211_IFTYPE_ADHOC)
2635 memcpy(arvif->u.ibss.bssid, info->bssid,
2636 ETH_ALEN);
2637 }
2638 }
2639
2640 if (changed & BSS_CHANGED_BEACON_ENABLED)
2641 ath10k_control_beaconing(arvif, info);
2642
2643 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2644 u32 cts_prot;
2645 if (info->use_cts_prot)
2646 cts_prot = 1;
2647 else
2648 cts_prot = 0;
2649
Kalle Valo60c3daa2013-09-08 17:56:07 +03002650 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2651 arvif->vdev_id, cts_prot);
2652
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002653 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2654 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655 cts_prot);
2656 if (ret)
2657 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2658 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002659 }
2660
2661 if (changed & BSS_CHANGED_ERP_SLOT) {
2662 u32 slottime;
2663 if (info->use_short_slot)
2664 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2665
2666 else
2667 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2668
Kalle Valo60c3daa2013-09-08 17:56:07 +03002669 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2670 arvif->vdev_id, slottime);
2671
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002672 vdev_param = ar->wmi.vdev_param->slot_time;
2673 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674 slottime);
2675 if (ret)
2676 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2677 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002678 }
2679
2680 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2681 u32 preamble;
2682 if (info->use_short_preamble)
2683 preamble = WMI_VDEV_PREAMBLE_SHORT;
2684 else
2685 preamble = WMI_VDEV_PREAMBLE_LONG;
2686
Kalle Valo60c3daa2013-09-08 17:56:07 +03002687 ath10k_dbg(ATH10K_DBG_MAC,
2688 "mac vdev %d preamble %dn",
2689 arvif->vdev_id, preamble);
2690
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002691 vdev_param = ar->wmi.vdev_param->preamble;
2692 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693 preamble);
2694 if (ret)
2695 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2696 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002697 }
2698
2699 if (changed & BSS_CHANGED_ASSOC) {
2700 if (info->assoc)
2701 ath10k_bss_assoc(hw, vif, info);
2702 }
2703
2704 mutex_unlock(&ar->conf_mutex);
2705}
2706
2707static int ath10k_hw_scan(struct ieee80211_hw *hw,
2708 struct ieee80211_vif *vif,
2709 struct cfg80211_scan_request *req)
2710{
2711 struct ath10k *ar = hw->priv;
2712 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2713 struct wmi_start_scan_arg arg;
2714 int ret = 0;
2715 int i;
2716
2717 mutex_lock(&ar->conf_mutex);
2718
2719 spin_lock_bh(&ar->data_lock);
2720 if (ar->scan.in_progress) {
2721 spin_unlock_bh(&ar->data_lock);
2722 ret = -EBUSY;
2723 goto exit;
2724 }
2725
Wolfram Sang16735d02013-11-14 14:32:02 -08002726 reinit_completion(&ar->scan.started);
2727 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002728 ar->scan.in_progress = true;
2729 ar->scan.aborting = false;
2730 ar->scan.is_roc = false;
2731 ar->scan.vdev_id = arvif->vdev_id;
2732 spin_unlock_bh(&ar->data_lock);
2733
2734 memset(&arg, 0, sizeof(arg));
2735 ath10k_wmi_start_scan_init(ar, &arg);
2736 arg.vdev_id = arvif->vdev_id;
2737 arg.scan_id = ATH10K_SCAN_ID;
2738
2739 if (!req->no_cck)
2740 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2741
2742 if (req->ie_len) {
2743 arg.ie_len = req->ie_len;
2744 memcpy(arg.ie, req->ie, arg.ie_len);
2745 }
2746
2747 if (req->n_ssids) {
2748 arg.n_ssids = req->n_ssids;
2749 for (i = 0; i < arg.n_ssids; i++) {
2750 arg.ssids[i].len = req->ssids[i].ssid_len;
2751 arg.ssids[i].ssid = req->ssids[i].ssid;
2752 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002753 } else {
2754 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002755 }
2756
2757 if (req->n_channels) {
2758 arg.n_channels = req->n_channels;
2759 for (i = 0; i < arg.n_channels; i++)
2760 arg.channels[i] = req->channels[i]->center_freq;
2761 }
2762
2763 ret = ath10k_start_scan(ar, &arg);
2764 if (ret) {
2765 ath10k_warn("could not start hw scan (%d)\n", ret);
2766 spin_lock_bh(&ar->data_lock);
2767 ar->scan.in_progress = false;
2768 spin_unlock_bh(&ar->data_lock);
2769 }
2770
2771exit:
2772 mutex_unlock(&ar->conf_mutex);
2773 return ret;
2774}
2775
2776static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2777 struct ieee80211_vif *vif)
2778{
2779 struct ath10k *ar = hw->priv;
2780 int ret;
2781
2782 mutex_lock(&ar->conf_mutex);
2783 ret = ath10k_abort_scan(ar);
2784 if (ret) {
2785 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2786 ret);
2787 ieee80211_scan_completed(hw, 1 /* aborted */);
2788 }
2789 mutex_unlock(&ar->conf_mutex);
2790}
2791
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002792static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2793 struct ath10k_vif *arvif,
2794 enum set_key_cmd cmd,
2795 struct ieee80211_key_conf *key)
2796{
2797 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2798 int ret;
2799
2800 /* 10.1 firmware branch requires default key index to be set to group
2801 * key index after installing it. Otherwise FW/HW Txes corrupted
2802 * frames with multi-vif APs. This is not required for main firmware
2803 * branch (e.g. 636).
2804 *
2805 * FIXME: This has been tested only in AP. It remains unknown if this
2806 * is required for multi-vif STA interfaces on 10.1 */
2807
2808 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2809 return;
2810
2811 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2812 return;
2813
2814 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2815 return;
2816
2817 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2818 return;
2819
2820 if (cmd != SET_KEY)
2821 return;
2822
2823 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2824 key->keyidx);
2825 if (ret)
2826 ath10k_warn("failed to set group key as default key: %d\n",
2827 ret);
2828}
2829
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2831 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2832 struct ieee80211_key_conf *key)
2833{
2834 struct ath10k *ar = hw->priv;
2835 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2836 struct ath10k_peer *peer;
2837 const u8 *peer_addr;
2838 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2839 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2840 int ret = 0;
2841
2842 if (key->keyidx > WMI_MAX_KEY_INDEX)
2843 return -ENOSPC;
2844
2845 mutex_lock(&ar->conf_mutex);
2846
2847 if (sta)
2848 peer_addr = sta->addr;
2849 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2850 peer_addr = vif->bss_conf.bssid;
2851 else
2852 peer_addr = vif->addr;
2853
2854 key->hw_key_idx = key->keyidx;
2855
2856 /* the peer should not disappear in mid-way (unless FW goes awry) since
2857 * we already hold conf_mutex. we just make sure its there now. */
2858 spin_lock_bh(&ar->data_lock);
2859 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2860 spin_unlock_bh(&ar->data_lock);
2861
2862 if (!peer) {
2863 if (cmd == SET_KEY) {
2864 ath10k_warn("cannot install key for non-existent peer %pM\n",
2865 peer_addr);
2866 ret = -EOPNOTSUPP;
2867 goto exit;
2868 } else {
2869 /* if the peer doesn't exist there is no key to disable
2870 * anymore */
2871 goto exit;
2872 }
2873 }
2874
2875 if (is_wep) {
2876 if (cmd == SET_KEY)
2877 arvif->wep_keys[key->keyidx] = key;
2878 else
2879 arvif->wep_keys[key->keyidx] = NULL;
2880
2881 if (cmd == DISABLE_KEY)
2882 ath10k_clear_vdev_key(arvif, key);
2883 }
2884
2885 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2886 if (ret) {
2887 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2888 goto exit;
2889 }
2890
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002891 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
2892
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 spin_lock_bh(&ar->data_lock);
2894 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2895 if (peer && cmd == SET_KEY)
2896 peer->keys[key->keyidx] = key;
2897 else if (peer && cmd == DISABLE_KEY)
2898 peer->keys[key->keyidx] = NULL;
2899 else if (peer == NULL)
2900 /* impossible unless FW goes crazy */
2901 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2902 spin_unlock_bh(&ar->data_lock);
2903
2904exit:
2905 mutex_unlock(&ar->conf_mutex);
2906 return ret;
2907}
2908
2909static int ath10k_sta_state(struct ieee80211_hw *hw,
2910 struct ieee80211_vif *vif,
2911 struct ieee80211_sta *sta,
2912 enum ieee80211_sta_state old_state,
2913 enum ieee80211_sta_state new_state)
2914{
2915 struct ath10k *ar = hw->priv;
2916 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01002917 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918 int ret = 0;
2919
2920 mutex_lock(&ar->conf_mutex);
2921
2922 if (old_state == IEEE80211_STA_NOTEXIST &&
2923 new_state == IEEE80211_STA_NONE &&
2924 vif->type != NL80211_IFTYPE_STATION) {
2925 /*
2926 * New station addition.
2927 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01002928 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2929 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
2930 else
2931 max_num_peers = TARGET_NUM_PEERS;
2932
2933 if (ar->num_peers >= max_num_peers) {
2934 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
2935 ar->num_peers, max_num_peers);
2936 ret = -ENOBUFS;
2937 goto exit;
2938 }
2939
Kalle Valo60c3daa2013-09-08 17:56:07 +03002940 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01002941 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
2942 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002943
Kalle Valo5e3dd152013-06-12 20:52:10 +03002944 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2945 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002946 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
2947 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002948 } else if ((old_state == IEEE80211_STA_NONE &&
2949 new_state == IEEE80211_STA_NOTEXIST)) {
2950 /*
2951 * Existing station deletion.
2952 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002953 ath10k_dbg(ATH10K_DBG_MAC,
2954 "mac vdev %d peer delete %pM (sta gone)\n",
2955 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002956 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2957 if (ret)
2958 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2959 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002960
2961 if (vif->type == NL80211_IFTYPE_STATION)
2962 ath10k_bss_disassoc(hw, vif);
2963 } else if (old_state == IEEE80211_STA_AUTH &&
2964 new_state == IEEE80211_STA_ASSOC &&
2965 (vif->type == NL80211_IFTYPE_AP ||
2966 vif->type == NL80211_IFTYPE_ADHOC)) {
2967 /*
2968 * New association.
2969 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002970 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2971 sta->addr);
2972
Kalle Valo5e3dd152013-06-12 20:52:10 +03002973 ret = ath10k_station_assoc(ar, arvif, sta);
2974 if (ret)
2975 ath10k_warn("Failed to associate station: %pM\n",
2976 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002977 } else if (old_state == IEEE80211_STA_ASSOC &&
2978 new_state == IEEE80211_STA_AUTH &&
2979 (vif->type == NL80211_IFTYPE_AP ||
2980 vif->type == NL80211_IFTYPE_ADHOC)) {
2981 /*
2982 * Disassociation.
2983 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002984 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2985 sta->addr);
2986
Kalle Valo5e3dd152013-06-12 20:52:10 +03002987 ret = ath10k_station_disassoc(ar, arvif, sta);
2988 if (ret)
2989 ath10k_warn("Failed to disassociate station: %pM\n",
2990 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002991 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01002992exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002993 mutex_unlock(&ar->conf_mutex);
2994 return ret;
2995}
2996
2997static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2998 u16 ac, bool enable)
2999{
3000 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3001 u32 value = 0;
3002 int ret = 0;
3003
Michal Kazior548db542013-07-05 16:15:15 +03003004 lockdep_assert_held(&ar->conf_mutex);
3005
Kalle Valo5e3dd152013-06-12 20:52:10 +03003006 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3007 return 0;
3008
3009 switch (ac) {
3010 case IEEE80211_AC_VO:
3011 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3012 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3013 break;
3014 case IEEE80211_AC_VI:
3015 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3016 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3017 break;
3018 case IEEE80211_AC_BE:
3019 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3020 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3021 break;
3022 case IEEE80211_AC_BK:
3023 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3024 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3025 break;
3026 }
3027
3028 if (enable)
3029 arvif->u.sta.uapsd |= value;
3030 else
3031 arvif->u.sta.uapsd &= ~value;
3032
3033 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3034 WMI_STA_PS_PARAM_UAPSD,
3035 arvif->u.sta.uapsd);
3036 if (ret) {
3037 ath10k_warn("could not set uapsd params %d\n", ret);
3038 goto exit;
3039 }
3040
3041 if (arvif->u.sta.uapsd)
3042 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3043 else
3044 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3045
3046 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3047 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3048 value);
3049 if (ret)
3050 ath10k_warn("could not set rx wake param %d\n", ret);
3051
3052exit:
3053 return ret;
3054}
3055
3056static int ath10k_conf_tx(struct ieee80211_hw *hw,
3057 struct ieee80211_vif *vif, u16 ac,
3058 const struct ieee80211_tx_queue_params *params)
3059{
3060 struct ath10k *ar = hw->priv;
3061 struct wmi_wmm_params_arg *p = NULL;
3062 int ret;
3063
3064 mutex_lock(&ar->conf_mutex);
3065
3066 switch (ac) {
3067 case IEEE80211_AC_VO:
3068 p = &ar->wmm_params.ac_vo;
3069 break;
3070 case IEEE80211_AC_VI:
3071 p = &ar->wmm_params.ac_vi;
3072 break;
3073 case IEEE80211_AC_BE:
3074 p = &ar->wmm_params.ac_be;
3075 break;
3076 case IEEE80211_AC_BK:
3077 p = &ar->wmm_params.ac_bk;
3078 break;
3079 }
3080
3081 if (WARN_ON(!p)) {
3082 ret = -EINVAL;
3083 goto exit;
3084 }
3085
3086 p->cwmin = params->cw_min;
3087 p->cwmax = params->cw_max;
3088 p->aifs = params->aifs;
3089
3090 /*
3091 * The channel time duration programmed in the HW is in absolute
3092 * microseconds, while mac80211 gives the txop in units of
3093 * 32 microseconds.
3094 */
3095 p->txop = params->txop * 32;
3096
3097 /* FIXME: FW accepts wmm params per hw, not per vif */
3098 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3099 if (ret) {
3100 ath10k_warn("could not set wmm params %d\n", ret);
3101 goto exit;
3102 }
3103
3104 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3105 if (ret)
3106 ath10k_warn("could not set sta uapsd %d\n", ret);
3107
3108exit:
3109 mutex_unlock(&ar->conf_mutex);
3110 return ret;
3111}
3112
3113#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3114
3115static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3116 struct ieee80211_vif *vif,
3117 struct ieee80211_channel *chan,
3118 int duration,
3119 enum ieee80211_roc_type type)
3120{
3121 struct ath10k *ar = hw->priv;
3122 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3123 struct wmi_start_scan_arg arg;
3124 int ret;
3125
3126 mutex_lock(&ar->conf_mutex);
3127
3128 spin_lock_bh(&ar->data_lock);
3129 if (ar->scan.in_progress) {
3130 spin_unlock_bh(&ar->data_lock);
3131 ret = -EBUSY;
3132 goto exit;
3133 }
3134
Wolfram Sang16735d02013-11-14 14:32:02 -08003135 reinit_completion(&ar->scan.started);
3136 reinit_completion(&ar->scan.completed);
3137 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003138 ar->scan.in_progress = true;
3139 ar->scan.aborting = false;
3140 ar->scan.is_roc = true;
3141 ar->scan.vdev_id = arvif->vdev_id;
3142 ar->scan.roc_freq = chan->center_freq;
3143 spin_unlock_bh(&ar->data_lock);
3144
3145 memset(&arg, 0, sizeof(arg));
3146 ath10k_wmi_start_scan_init(ar, &arg);
3147 arg.vdev_id = arvif->vdev_id;
3148 arg.scan_id = ATH10K_SCAN_ID;
3149 arg.n_channels = 1;
3150 arg.channels[0] = chan->center_freq;
3151 arg.dwell_time_active = duration;
3152 arg.dwell_time_passive = duration;
3153 arg.max_scan_time = 2 * duration;
3154 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3155 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3156
3157 ret = ath10k_start_scan(ar, &arg);
3158 if (ret) {
3159 ath10k_warn("could not start roc scan (%d)\n", ret);
3160 spin_lock_bh(&ar->data_lock);
3161 ar->scan.in_progress = false;
3162 spin_unlock_bh(&ar->data_lock);
3163 goto exit;
3164 }
3165
3166 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3167 if (ret == 0) {
3168 ath10k_warn("could not switch to channel for roc scan\n");
3169 ath10k_abort_scan(ar);
3170 ret = -ETIMEDOUT;
3171 goto exit;
3172 }
3173
3174 ret = 0;
3175exit:
3176 mutex_unlock(&ar->conf_mutex);
3177 return ret;
3178}
3179
3180static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3181{
3182 struct ath10k *ar = hw->priv;
3183
3184 mutex_lock(&ar->conf_mutex);
3185 ath10k_abort_scan(ar);
3186 mutex_unlock(&ar->conf_mutex);
3187
3188 return 0;
3189}
3190
3191/*
3192 * Both RTS and Fragmentation threshold are interface-specific
3193 * in ath10k, but device-specific in mac80211.
3194 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003195
3196static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3197{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003198 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003199 struct ath10k_vif *arvif;
3200 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003201
Michal Kaziorad088bf2013-10-16 15:44:46 +03003202 mutex_lock(&ar->conf_mutex);
3203 list_for_each_entry(arvif, &ar->arvifs, list) {
3204 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3205 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003206
Michal Kaziorad088bf2013-10-16 15:44:46 +03003207 ret = ath10k_mac_set_rts(arvif, value);
3208 if (ret) {
3209 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3210 arvif->vdev_id, ret);
3211 break;
3212 }
3213 }
3214 mutex_unlock(&ar->conf_mutex);
3215
3216 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003217}
3218
3219static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3220{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003221 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003222 struct ath10k_vif *arvif;
3223 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003224
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003226 list_for_each_entry(arvif, &ar->arvifs, list) {
3227 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3228 arvif->vdev_id, value);
3229
3230 ret = ath10k_mac_set_rts(arvif, value);
3231 if (ret) {
3232 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3233 arvif->vdev_id, ret);
3234 break;
3235 }
3236 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003237 mutex_unlock(&ar->conf_mutex);
3238
Michal Kaziorad088bf2013-10-16 15:44:46 +03003239 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240}
3241
3242static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3243{
3244 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003245 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003246 int ret;
3247
3248 /* mac80211 doesn't care if we really xmit queued frames or not
3249 * we'll collect those frames either way if we stop/delete vdevs */
3250 if (drop)
3251 return;
3252
Michal Kazior548db542013-07-05 16:15:15 +03003253 mutex_lock(&ar->conf_mutex);
3254
Michal Kazioraffd3212013-07-16 09:54:35 +02003255 if (ar->state == ATH10K_STATE_WEDGED)
3256 goto skip;
3257
Michal Kazioredb82362013-07-05 16:15:14 +03003258 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003260
Michal Kazioredb82362013-07-05 16:15:14 +03003261 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003262 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003263 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003264
3265 skip = (ar->state == ATH10K_STATE_WEDGED);
3266
3267 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003268 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003269
3270 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003272
Michal Kazioraffd3212013-07-16 09:54:35 +02003273skip:
Michal Kazior548db542013-07-05 16:15:15 +03003274 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003275}
3276
3277/* TODO: Implement this function properly
3278 * For now it is needed to reply to Probe Requests in IBSS mode.
3279 * Propably we need this information from FW.
3280 */
3281static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3282{
3283 return 1;
3284}
3285
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003286#ifdef CONFIG_PM
3287static int ath10k_suspend(struct ieee80211_hw *hw,
3288 struct cfg80211_wowlan *wowlan)
3289{
3290 struct ath10k *ar = hw->priv;
3291 int ret;
3292
3293 ar->is_target_paused = false;
3294
3295 ret = ath10k_wmi_pdev_suspend_target(ar);
3296 if (ret) {
3297 ath10k_warn("could not suspend target (%d)\n", ret);
3298 return 1;
3299 }
3300
3301 ret = wait_event_interruptible_timeout(ar->event_queue,
3302 ar->is_target_paused == true,
3303 1 * HZ);
3304 if (ret < 0) {
3305 ath10k_warn("suspend interrupted (%d)\n", ret);
3306 goto resume;
3307 } else if (ret == 0) {
3308 ath10k_warn("suspend timed out - target pause event never came\n");
3309 goto resume;
3310 }
3311
3312 ret = ath10k_hif_suspend(ar);
3313 if (ret) {
3314 ath10k_warn("could not suspend hif (%d)\n", ret);
3315 goto resume;
3316 }
3317
3318 return 0;
3319resume:
3320 ret = ath10k_wmi_pdev_resume_target(ar);
3321 if (ret)
3322 ath10k_warn("could not resume target (%d)\n", ret);
3323 return 1;
3324}
3325
3326static int ath10k_resume(struct ieee80211_hw *hw)
3327{
3328 struct ath10k *ar = hw->priv;
3329 int ret;
3330
3331 ret = ath10k_hif_resume(ar);
3332 if (ret) {
3333 ath10k_warn("could not resume hif (%d)\n", ret);
3334 return 1;
3335 }
3336
3337 ret = ath10k_wmi_pdev_resume_target(ar);
3338 if (ret) {
3339 ath10k_warn("could not resume target (%d)\n", ret);
3340 return 1;
3341 }
3342
3343 return 0;
3344}
3345#endif
3346
Michal Kazioraffd3212013-07-16 09:54:35 +02003347static void ath10k_restart_complete(struct ieee80211_hw *hw)
3348{
3349 struct ath10k *ar = hw->priv;
3350
3351 mutex_lock(&ar->conf_mutex);
3352
3353 /* If device failed to restart it will be in a different state, e.g.
3354 * ATH10K_STATE_WEDGED */
3355 if (ar->state == ATH10K_STATE_RESTARTED) {
3356 ath10k_info("device successfully recovered\n");
3357 ar->state = ATH10K_STATE_ON;
3358 }
3359
3360 mutex_unlock(&ar->conf_mutex);
3361}
3362
Michal Kazior2e1dea42013-07-31 10:32:40 +02003363static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3364 struct survey_info *survey)
3365{
3366 struct ath10k *ar = hw->priv;
3367 struct ieee80211_supported_band *sband;
3368 struct survey_info *ar_survey = &ar->survey[idx];
3369 int ret = 0;
3370
3371 mutex_lock(&ar->conf_mutex);
3372
3373 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3374 if (sband && idx >= sband->n_channels) {
3375 idx -= sband->n_channels;
3376 sband = NULL;
3377 }
3378
3379 if (!sband)
3380 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3381
3382 if (!sband || idx >= sband->n_channels) {
3383 ret = -ENOENT;
3384 goto exit;
3385 }
3386
3387 spin_lock_bh(&ar->data_lock);
3388 memcpy(survey, ar_survey, sizeof(*survey));
3389 spin_unlock_bh(&ar->data_lock);
3390
3391 survey->channel = &sband->channels[idx];
3392
3393exit:
3394 mutex_unlock(&ar->conf_mutex);
3395 return ret;
3396}
3397
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003398/* Helper table for legacy fixed_rate/bitrate_mask */
3399static const u8 cck_ofdm_rate[] = {
3400 /* CCK */
3401 3, /* 1Mbps */
3402 2, /* 2Mbps */
3403 1, /* 5.5Mbps */
3404 0, /* 11Mbps */
3405 /* OFDM */
3406 3, /* 6Mbps */
3407 7, /* 9Mbps */
3408 2, /* 12Mbps */
3409 6, /* 18Mbps */
3410 1, /* 24Mbps */
3411 5, /* 36Mbps */
3412 0, /* 48Mbps */
3413 4, /* 54Mbps */
3414};
3415
3416/* Check if only one bit set */
3417static int ath10k_check_single_mask(u32 mask)
3418{
3419 int bit;
3420
3421 bit = ffs(mask);
3422 if (!bit)
3423 return 0;
3424
3425 mask &= ~BIT(bit - 1);
3426 if (mask)
3427 return 2;
3428
3429 return 1;
3430}
3431
3432static bool
3433ath10k_default_bitrate_mask(struct ath10k *ar,
3434 enum ieee80211_band band,
3435 const struct cfg80211_bitrate_mask *mask)
3436{
3437 u32 legacy = 0x00ff;
3438 u8 ht = 0xff, i;
3439 u16 vht = 0x3ff;
3440
3441 switch (band) {
3442 case IEEE80211_BAND_2GHZ:
3443 legacy = 0x00fff;
3444 vht = 0;
3445 break;
3446 case IEEE80211_BAND_5GHZ:
3447 break;
3448 default:
3449 return false;
3450 }
3451
3452 if (mask->control[band].legacy != legacy)
3453 return false;
3454
3455 for (i = 0; i < ar->num_rf_chains; i++)
3456 if (mask->control[band].ht_mcs[i] != ht)
3457 return false;
3458
3459 for (i = 0; i < ar->num_rf_chains; i++)
3460 if (mask->control[band].vht_mcs[i] != vht)
3461 return false;
3462
3463 return true;
3464}
3465
3466static bool
3467ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3468 enum ieee80211_band band,
3469 u8 *fixed_nss)
3470{
3471 int ht_nss = 0, vht_nss = 0, i;
3472
3473 /* check legacy */
3474 if (ath10k_check_single_mask(mask->control[band].legacy))
3475 return false;
3476
3477 /* check HT */
3478 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3479 if (mask->control[band].ht_mcs[i] == 0xff)
3480 continue;
3481 else if (mask->control[band].ht_mcs[i] == 0x00)
3482 break;
3483 else
3484 return false;
3485 }
3486
3487 ht_nss = i;
3488
3489 /* check VHT */
3490 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3491 if (mask->control[band].vht_mcs[i] == 0x03ff)
3492 continue;
3493 else if (mask->control[band].vht_mcs[i] == 0x0000)
3494 break;
3495 else
3496 return false;
3497 }
3498
3499 vht_nss = i;
3500
3501 if (ht_nss > 0 && vht_nss > 0)
3502 return false;
3503
3504 if (ht_nss)
3505 *fixed_nss = ht_nss;
3506 else if (vht_nss)
3507 *fixed_nss = vht_nss;
3508 else
3509 return false;
3510
3511 return true;
3512}
3513
3514static bool
3515ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3516 enum ieee80211_band band,
3517 enum wmi_rate_preamble *preamble)
3518{
3519 int legacy = 0, ht = 0, vht = 0, i;
3520
3521 *preamble = WMI_RATE_PREAMBLE_OFDM;
3522
3523 /* check legacy */
3524 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3525 if (legacy > 1)
3526 return false;
3527
3528 /* check HT */
3529 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3530 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3531 if (ht > 1)
3532 return false;
3533
3534 /* check VHT */
3535 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3536 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3537 if (vht > 1)
3538 return false;
3539
3540 /* Currently we support only one fixed_rate */
3541 if ((legacy + ht + vht) != 1)
3542 return false;
3543
3544 if (ht)
3545 *preamble = WMI_RATE_PREAMBLE_HT;
3546 else if (vht)
3547 *preamble = WMI_RATE_PREAMBLE_VHT;
3548
3549 return true;
3550}
3551
3552static bool
3553ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3554 enum ieee80211_band band,
3555 u8 *fixed_rate,
3556 u8 *fixed_nss)
3557{
3558 u8 rate = 0, pream = 0, nss = 0, i;
3559 enum wmi_rate_preamble preamble;
3560
3561 /* Check if single rate correct */
3562 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3563 return false;
3564
3565 pream = preamble;
3566
3567 switch (preamble) {
3568 case WMI_RATE_PREAMBLE_CCK:
3569 case WMI_RATE_PREAMBLE_OFDM:
3570 i = ffs(mask->control[band].legacy) - 1;
3571
3572 if (band == IEEE80211_BAND_2GHZ && i < 4)
3573 pream = WMI_RATE_PREAMBLE_CCK;
3574
3575 if (band == IEEE80211_BAND_5GHZ)
3576 i += 4;
3577
3578 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3579 return false;
3580
3581 rate = cck_ofdm_rate[i];
3582 break;
3583 case WMI_RATE_PREAMBLE_HT:
3584 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3585 if (mask->control[band].ht_mcs[i])
3586 break;
3587
3588 if (i == IEEE80211_HT_MCS_MASK_LEN)
3589 return false;
3590
3591 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3592 nss = i;
3593 break;
3594 case WMI_RATE_PREAMBLE_VHT:
3595 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3596 if (mask->control[band].vht_mcs[i])
3597 break;
3598
3599 if (i == NL80211_VHT_NSS_MAX)
3600 return false;
3601
3602 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3603 nss = i;
3604 break;
3605 }
3606
3607 *fixed_nss = nss + 1;
3608 nss <<= 4;
3609 pream <<= 6;
3610
3611 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3612 pream, nss, rate);
3613
3614 *fixed_rate = pream | nss | rate;
3615
3616 return true;
3617}
3618
3619static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3620 enum ieee80211_band band,
3621 u8 *fixed_rate,
3622 u8 *fixed_nss)
3623{
3624 /* First check full NSS mask, if we can simply limit NSS */
3625 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3626 return true;
3627
3628 /* Next Check single rate is set */
3629 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3630}
3631
3632static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3633 u8 fixed_rate,
3634 u8 fixed_nss)
3635{
3636 struct ath10k *ar = arvif->ar;
3637 u32 vdev_param;
3638 int ret = 0;
3639
3640 mutex_lock(&ar->conf_mutex);
3641
3642 if (arvif->fixed_rate == fixed_rate &&
3643 arvif->fixed_nss == fixed_nss)
3644 goto exit;
3645
3646 if (fixed_rate == WMI_FIXED_RATE_NONE)
3647 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3648
3649 vdev_param = ar->wmi.vdev_param->fixed_rate;
3650 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3651 vdev_param, fixed_rate);
3652 if (ret) {
3653 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3654 fixed_rate, ret);
3655 ret = -EINVAL;
3656 goto exit;
3657 }
3658
3659 arvif->fixed_rate = fixed_rate;
3660
3661 vdev_param = ar->wmi.vdev_param->nss;
3662 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3663 vdev_param, fixed_nss);
3664
3665 if (ret) {
3666 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3667 fixed_nss, ret);
3668 ret = -EINVAL;
3669 goto exit;
3670 }
3671
3672 arvif->fixed_nss = fixed_nss;
3673
3674exit:
3675 mutex_unlock(&ar->conf_mutex);
3676 return ret;
3677}
3678
3679static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3680 struct ieee80211_vif *vif,
3681 const struct cfg80211_bitrate_mask *mask)
3682{
3683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3684 struct ath10k *ar = arvif->ar;
3685 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3686 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3687 u8 fixed_nss = ar->num_rf_chains;
3688
3689 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3690 if (!ath10k_get_fixed_rate_nss(mask, band,
3691 &fixed_rate,
3692 &fixed_nss))
3693 return -EINVAL;
3694 }
3695
3696 return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss);
3697}
3698
Kalle Valo5e3dd152013-06-12 20:52:10 +03003699static const struct ieee80211_ops ath10k_ops = {
3700 .tx = ath10k_tx,
3701 .start = ath10k_start,
3702 .stop = ath10k_stop,
3703 .config = ath10k_config,
3704 .add_interface = ath10k_add_interface,
3705 .remove_interface = ath10k_remove_interface,
3706 .configure_filter = ath10k_configure_filter,
3707 .bss_info_changed = ath10k_bss_info_changed,
3708 .hw_scan = ath10k_hw_scan,
3709 .cancel_hw_scan = ath10k_cancel_hw_scan,
3710 .set_key = ath10k_set_key,
3711 .sta_state = ath10k_sta_state,
3712 .conf_tx = ath10k_conf_tx,
3713 .remain_on_channel = ath10k_remain_on_channel,
3714 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3715 .set_rts_threshold = ath10k_set_rts_threshold,
3716 .set_frag_threshold = ath10k_set_frag_threshold,
3717 .flush = ath10k_flush,
3718 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003719 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003720 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003721 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003722#ifdef CONFIG_PM
3723 .suspend = ath10k_suspend,
3724 .resume = ath10k_resume,
3725#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003726};
3727
3728#define RATETAB_ENT(_rate, _rateid, _flags) { \
3729 .bitrate = (_rate), \
3730 .flags = (_flags), \
3731 .hw_value = (_rateid), \
3732}
3733
3734#define CHAN2G(_channel, _freq, _flags) { \
3735 .band = IEEE80211_BAND_2GHZ, \
3736 .hw_value = (_channel), \
3737 .center_freq = (_freq), \
3738 .flags = (_flags), \
3739 .max_antenna_gain = 0, \
3740 .max_power = 30, \
3741}
3742
3743#define CHAN5G(_channel, _freq, _flags) { \
3744 .band = IEEE80211_BAND_5GHZ, \
3745 .hw_value = (_channel), \
3746 .center_freq = (_freq), \
3747 .flags = (_flags), \
3748 .max_antenna_gain = 0, \
3749 .max_power = 30, \
3750}
3751
3752static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3753 CHAN2G(1, 2412, 0),
3754 CHAN2G(2, 2417, 0),
3755 CHAN2G(3, 2422, 0),
3756 CHAN2G(4, 2427, 0),
3757 CHAN2G(5, 2432, 0),
3758 CHAN2G(6, 2437, 0),
3759 CHAN2G(7, 2442, 0),
3760 CHAN2G(8, 2447, 0),
3761 CHAN2G(9, 2452, 0),
3762 CHAN2G(10, 2457, 0),
3763 CHAN2G(11, 2462, 0),
3764 CHAN2G(12, 2467, 0),
3765 CHAN2G(13, 2472, 0),
3766 CHAN2G(14, 2484, 0),
3767};
3768
3769static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003770 CHAN5G(36, 5180, 0),
3771 CHAN5G(40, 5200, 0),
3772 CHAN5G(44, 5220, 0),
3773 CHAN5G(48, 5240, 0),
3774 CHAN5G(52, 5260, 0),
3775 CHAN5G(56, 5280, 0),
3776 CHAN5G(60, 5300, 0),
3777 CHAN5G(64, 5320, 0),
3778 CHAN5G(100, 5500, 0),
3779 CHAN5G(104, 5520, 0),
3780 CHAN5G(108, 5540, 0),
3781 CHAN5G(112, 5560, 0),
3782 CHAN5G(116, 5580, 0),
3783 CHAN5G(120, 5600, 0),
3784 CHAN5G(124, 5620, 0),
3785 CHAN5G(128, 5640, 0),
3786 CHAN5G(132, 5660, 0),
3787 CHAN5G(136, 5680, 0),
3788 CHAN5G(140, 5700, 0),
3789 CHAN5G(149, 5745, 0),
3790 CHAN5G(153, 5765, 0),
3791 CHAN5G(157, 5785, 0),
3792 CHAN5G(161, 5805, 0),
3793 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003794};
3795
3796static struct ieee80211_rate ath10k_rates[] = {
3797 /* CCK */
3798 RATETAB_ENT(10, 0x82, 0),
3799 RATETAB_ENT(20, 0x84, 0),
3800 RATETAB_ENT(55, 0x8b, 0),
3801 RATETAB_ENT(110, 0x96, 0),
3802 /* OFDM */
3803 RATETAB_ENT(60, 0x0c, 0),
3804 RATETAB_ENT(90, 0x12, 0),
3805 RATETAB_ENT(120, 0x18, 0),
3806 RATETAB_ENT(180, 0x24, 0),
3807 RATETAB_ENT(240, 0x30, 0),
3808 RATETAB_ENT(360, 0x48, 0),
3809 RATETAB_ENT(480, 0x60, 0),
3810 RATETAB_ENT(540, 0x6c, 0),
3811};
3812
3813#define ath10k_a_rates (ath10k_rates + 4)
3814#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3815#define ath10k_g_rates (ath10k_rates + 0)
3816#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3817
3818struct ath10k *ath10k_mac_create(void)
3819{
3820 struct ieee80211_hw *hw;
3821 struct ath10k *ar;
3822
3823 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3824 if (!hw)
3825 return NULL;
3826
3827 ar = hw->priv;
3828 ar->hw = hw;
3829
3830 return ar;
3831}
3832
3833void ath10k_mac_destroy(struct ath10k *ar)
3834{
3835 ieee80211_free_hw(ar->hw);
3836}
3837
3838static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3839 {
3840 .max = 8,
3841 .types = BIT(NL80211_IFTYPE_STATION)
3842 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003843 },
3844 {
3845 .max = 3,
3846 .types = BIT(NL80211_IFTYPE_P2P_GO)
3847 },
3848 {
3849 .max = 7,
3850 .types = BIT(NL80211_IFTYPE_AP)
3851 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003852};
3853
Bartosz Markowskif2595092013-12-10 16:20:39 +01003854static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003855 {
3856 .max = 8,
3857 .types = BIT(NL80211_IFTYPE_AP)
3858 },
3859};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003860
3861static const struct ieee80211_iface_combination ath10k_if_comb[] = {
3862 {
3863 .limits = ath10k_if_limits,
3864 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3865 .max_interfaces = 8,
3866 .num_different_channels = 1,
3867 .beacon_int_infra_match = true,
3868 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01003869};
3870
3871static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003872 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01003873 .limits = ath10k_10x_if_limits,
3874 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003875 .max_interfaces = 8,
3876 .num_different_channels = 1,
3877 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01003878#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003879 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
3880 BIT(NL80211_CHAN_WIDTH_20) |
3881 BIT(NL80211_CHAN_WIDTH_40) |
3882 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003883#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01003884 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003885};
3886
3887static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3888{
3889 struct ieee80211_sta_vht_cap vht_cap = {0};
3890 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003891 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003892
3893 vht_cap.vht_supported = 1;
3894 vht_cap.cap = ar->vht_cap_info;
3895
Michal Kazior8865bee42013-07-24 12:36:46 +02003896 mcs_map = 0;
3897 for (i = 0; i < 8; i++) {
3898 if (i < ar->num_rf_chains)
3899 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3900 else
3901 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3902 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003903
3904 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3905 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3906
3907 return vht_cap;
3908}
3909
3910static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3911{
3912 int i;
3913 struct ieee80211_sta_ht_cap ht_cap = {0};
3914
3915 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3916 return ht_cap;
3917
3918 ht_cap.ht_supported = 1;
3919 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3920 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3921 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3922 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3923 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3924
3925 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3926 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3927
3928 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3929 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3930
3931 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3932 u32 smps;
3933
3934 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3935 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3936
3937 ht_cap.cap |= smps;
3938 }
3939
3940 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3941 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3942
3943 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3944 u32 stbc;
3945
3946 stbc = ar->ht_cap_info;
3947 stbc &= WMI_HT_CAP_RX_STBC;
3948 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3949 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3950 stbc &= IEEE80211_HT_CAP_RX_STBC;
3951
3952 ht_cap.cap |= stbc;
3953 }
3954
3955 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3956 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3957
3958 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3959 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3960
3961 /* max AMSDU is implicitly taken from vht_cap_info */
3962 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3963 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3964
Michal Kazior8865bee42013-07-24 12:36:46 +02003965 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003966 ht_cap.mcs.rx_mask[i] = 0xFF;
3967
3968 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3969
3970 return ht_cap;
3971}
3972
3973
3974static void ath10k_get_arvif_iter(void *data, u8 *mac,
3975 struct ieee80211_vif *vif)
3976{
3977 struct ath10k_vif_iter *arvif_iter = data;
3978 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3979
3980 if (arvif->vdev_id == arvif_iter->vdev_id)
3981 arvif_iter->arvif = arvif;
3982}
3983
3984struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3985{
3986 struct ath10k_vif_iter arvif_iter;
3987 u32 flags;
3988
3989 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3990 arvif_iter.vdev_id = vdev_id;
3991
3992 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3993 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3994 flags,
3995 ath10k_get_arvif_iter,
3996 &arvif_iter);
3997 if (!arvif_iter.arvif) {
3998 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3999 return NULL;
4000 }
4001
4002 return arvif_iter.arvif;
4003}
4004
4005int ath10k_mac_register(struct ath10k *ar)
4006{
4007 struct ieee80211_supported_band *band;
4008 struct ieee80211_sta_vht_cap vht_cap;
4009 struct ieee80211_sta_ht_cap ht_cap;
4010 void *channels;
4011 int ret;
4012
4013 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4014
4015 SET_IEEE80211_DEV(ar->hw, ar->dev);
4016
4017 ht_cap = ath10k_get_ht_cap(ar);
4018 vht_cap = ath10k_create_vht_cap(ar);
4019
4020 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4021 channels = kmemdup(ath10k_2ghz_channels,
4022 sizeof(ath10k_2ghz_channels),
4023 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004024 if (!channels) {
4025 ret = -ENOMEM;
4026 goto err_free;
4027 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028
4029 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4030 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4031 band->channels = channels;
4032 band->n_bitrates = ath10k_g_rates_size;
4033 band->bitrates = ath10k_g_rates;
4034 band->ht_cap = ht_cap;
4035
4036 /* vht is not supported in 2.4 GHz */
4037
4038 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4039 }
4040
4041 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4042 channels = kmemdup(ath10k_5ghz_channels,
4043 sizeof(ath10k_5ghz_channels),
4044 GFP_KERNEL);
4045 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004046 ret = -ENOMEM;
4047 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004048 }
4049
4050 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4051 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4052 band->channels = channels;
4053 band->n_bitrates = ath10k_a_rates_size;
4054 band->bitrates = ath10k_a_rates;
4055 band->ht_cap = ht_cap;
4056 band->vht_cap = vht_cap;
4057 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4058 }
4059
4060 ar->hw->wiphy->interface_modes =
4061 BIT(NL80211_IFTYPE_STATION) |
4062 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004063 BIT(NL80211_IFTYPE_AP);
4064
4065 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4066 ar->hw->wiphy->interface_modes |=
4067 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4068 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004069
4070 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4071 IEEE80211_HW_SUPPORTS_PS |
4072 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4073 IEEE80211_HW_SUPPORTS_UAPSD |
4074 IEEE80211_HW_MFP_CAPABLE |
4075 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4076 IEEE80211_HW_HAS_RATE_CONTROL |
4077 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4078 IEEE80211_HW_WANT_MONITOR_VIF |
4079 IEEE80211_HW_AP_LINK_PS;
4080
Michal Kazior1f8bb152013-09-18 14:43:22 +02004081 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4082 * bytes is used for padding/alignment if necessary. */
4083 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4084
Kalle Valo5e3dd152013-06-12 20:52:10 +03004085 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4086 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4087
4088 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4089 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4090 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4091 }
4092
4093 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4094 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4095
4096 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4097
Kalle Valo5e3dd152013-06-12 20:52:10 +03004098 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4099
4100 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4101 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4102
4103 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4104 /*
4105 * on LL hardware queues are managed entirely by the FW
4106 * so we only advertise to mac we can do the queues thing
4107 */
4108 ar->hw->queues = 4;
4109
Bartosz Markowskif2595092013-12-10 16:20:39 +01004110 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4111 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4112 ar->hw->wiphy->n_iface_combinations =
4113 ARRAY_SIZE(ath10k_10x_if_comb);
4114 } else {
4115 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4116 ar->hw->wiphy->n_iface_combinations =
4117 ARRAY_SIZE(ath10k_if_comb);
4118 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004119
Michal Kazior7c199992013-07-31 10:47:57 +02004120 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4121
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004122 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4123 /* Init ath dfs pattern detector */
4124 ar->ath_common.debug_mask = ATH_DBG_DFS;
4125 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4126 NL80211_DFS_UNSET);
4127
4128 if (!ar->dfs_detector)
4129 ath10k_warn("dfs pattern detector init failed\n");
4130 }
4131
Kalle Valo5e3dd152013-06-12 20:52:10 +03004132 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4133 ath10k_reg_notifier);
4134 if (ret) {
4135 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02004136 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004137 }
4138
4139 ret = ieee80211_register_hw(ar->hw);
4140 if (ret) {
4141 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004142 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004143 }
4144
4145 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4146 ret = regulatory_hint(ar->hw->wiphy,
4147 ar->ath_common.regulatory.alpha2);
4148 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004149 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004150 }
4151
4152 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004153
4154err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004155 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004156err_free:
4157 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4158 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4159
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160 return ret;
4161}
4162
4163void ath10k_mac_unregister(struct ath10k *ar)
4164{
4165 ieee80211_unregister_hw(ar->hw);
4166
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004167 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4168 ar->dfs_detector->exit(ar->dfs_detector);
4169
Kalle Valo5e3dd152013-06-12 20:52:10 +03004170 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4171 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4172
4173 SET_IEEE80211_DEV(ar->hw, NULL);
4174}