blob: 9230ad5e0f87171a6e2cc2cc798bf1d0c4e6545a [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;
Michal Kaziorc930f742014-01-23 11:38:25 +0100491 struct cfg80211_chan_def *chandef = &ar->chandef;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300492 struct wmi_vdev_start_request_arg arg = {};
493 int ret = 0;
494
495 lockdep_assert_held(&ar->conf_mutex);
496
Wolfram Sang16735d02013-11-14 14:32:02 -0800497 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300498
499 arg.vdev_id = arvif->vdev_id;
500 arg.dtim_period = arvif->dtim_period;
501 arg.bcn_intval = arvif->beacon_interval;
502
Michal Kaziorc930f742014-01-23 11:38:25 +0100503 arg.channel.freq = chandef->chan->center_freq;
504 arg.channel.band_center_freq1 = chandef->center_freq1;
505 arg.channel.mode = chan_to_phymode(chandef);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300506
Michal Kazior89c5c842013-10-23 04:02:13 -0700507 arg.channel.min_power = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +0100508 arg.channel.max_power = chandef->chan->max_power * 2;
509 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
510 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300511
512 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
513 arg.ssid = arvif->u.ap.ssid;
514 arg.ssid_len = arvif->u.ap.ssid_len;
515 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200516
517 /* For now allow DFS for AP mode */
518 arg.channel.chan_radar =
Michal Kaziorc930f742014-01-23 11:38:25 +0100519 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300520 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
521 arg.ssid = arvif->vif->bss_conf.ssid;
522 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
523 }
524
Kalle Valo38a1d472013-09-08 17:56:14 +0300525 ath10k_dbg(ATH10K_DBG_MAC,
526 "mac vdev %d start center_freq %d phymode %s\n",
527 arg.vdev_id, arg.channel.freq,
528 ath10k_wmi_phymode_str(arg.channel.mode));
529
Kalle Valo5e3dd152013-06-12 20:52:10 +0300530 ret = ath10k_wmi_vdev_start(ar, &arg);
531 if (ret) {
532 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
533 return ret;
534 }
535
536 ret = ath10k_vdev_setup_sync(ar);
537 if (ret) {
538 ath10k_warn("vdev setup failed %d\n", ret);
539 return ret;
540 }
541
542 return ret;
543}
544
545static int ath10k_vdev_stop(struct ath10k_vif *arvif)
546{
547 struct ath10k *ar = arvif->ar;
548 int ret;
549
550 lockdep_assert_held(&ar->conf_mutex);
551
Wolfram Sang16735d02013-11-14 14:32:02 -0800552 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300553
554 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
555 if (ret) {
556 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
557 return ret;
558 }
559
560 ret = ath10k_vdev_setup_sync(ar);
561 if (ret) {
562 ath10k_warn("vdev setup failed %d\n", ret);
563 return ret;
564 }
565
566 return ret;
567}
568
569static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
570{
Michal Kaziorc930f742014-01-23 11:38:25 +0100571 struct cfg80211_chan_def *chandef = &ar->chandef;
572 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300573 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300574 int ret = 0;
575
576 lockdep_assert_held(&ar->conf_mutex);
577
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300578 if (!ar->monitor_present) {
579 ath10k_warn("mac montor stop -- monitor is not present\n");
580 return -EINVAL;
581 }
582
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583 arg.vdev_id = vdev_id;
584 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100585 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300586
587 /* TODO setup this dynamically, what in case we
588 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100589 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200590 arg.channel.chan_radar =
591 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592
Michal Kazior89c5c842013-10-23 04:02:13 -0700593 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700594 arg.channel.max_power = channel->max_power * 2;
595 arg.channel.max_reg_power = channel->max_reg_power * 2;
596 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300597
598 ret = ath10k_wmi_vdev_start(ar, &arg);
599 if (ret) {
600 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
601 return ret;
602 }
603
604 ret = ath10k_vdev_setup_sync(ar);
605 if (ret) {
606 ath10k_warn("Monitor vdev setup failed %d\n", ret);
607 return ret;
608 }
609
610 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
611 if (ret) {
612 ath10k_warn("Monitor vdev up failed: %d\n", ret);
613 goto vdev_stop;
614 }
615
616 ar->monitor_vdev_id = vdev_id;
617 ar->monitor_enabled = true;
618
619 return 0;
620
621vdev_stop:
622 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
623 if (ret)
624 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
625
626 return ret;
627}
628
629static int ath10k_monitor_stop(struct ath10k *ar)
630{
631 int ret = 0;
632
633 lockdep_assert_held(&ar->conf_mutex);
634
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300635 if (!ar->monitor_present) {
636 ath10k_warn("mac montor stop -- monitor is not present\n");
637 return -EINVAL;
638 }
639
640 if (!ar->monitor_enabled) {
641 ath10k_warn("mac montor stop -- monitor is not enabled\n");
642 return -EINVAL;
643 }
644
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200645 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
646 if (ret)
647 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648
649 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
650 if (ret)
651 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
652
653 ret = ath10k_vdev_setup_sync(ar);
654 if (ret)
655 ath10k_warn("Monitor_down sync failed: %d\n", ret);
656
657 ar->monitor_enabled = false;
658 return ret;
659}
660
661static int ath10k_monitor_create(struct ath10k *ar)
662{
663 int bit, ret = 0;
664
665 lockdep_assert_held(&ar->conf_mutex);
666
667 if (ar->monitor_present) {
668 ath10k_warn("Monitor mode already enabled\n");
669 return 0;
670 }
671
672 bit = ffs(ar->free_vdev_map);
673 if (bit == 0) {
674 ath10k_warn("No free VDEV slots\n");
675 return -ENOMEM;
676 }
677
678 ar->monitor_vdev_id = bit - 1;
679 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
680
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr);
684 if (ret) {
685 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
686 goto vdev_fail;
687 }
688
Kalle Valo60c3daa2013-09-08 17:56:07 +0300689 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300690 ar->monitor_vdev_id);
691
692 ar->monitor_present = true;
693 return 0;
694
695vdev_fail:
696 /*
697 * Restore the ID to the global map.
698 */
699 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
700 return ret;
701}
702
703static int ath10k_monitor_destroy(struct ath10k *ar)
704{
705 int ret = 0;
706
707 lockdep_assert_held(&ar->conf_mutex);
708
709 if (!ar->monitor_present)
710 return 0;
711
712 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
713 if (ret) {
714 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
715 return ret;
716 }
717
718 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
719 ar->monitor_present = false;
720
Kalle Valo60c3daa2013-09-08 17:56:07 +0300721 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300722 ar->monitor_vdev_id);
723 return ret;
724}
725
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200726static int ath10k_start_cac(struct ath10k *ar)
727{
728 int ret;
729
730 lockdep_assert_held(&ar->conf_mutex);
731
732 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
733
734 ret = ath10k_monitor_create(ar);
735 if (ret) {
736 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
737 return ret;
738 }
739
740 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
741 if (ret) {
742 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
743 ath10k_monitor_destroy(ar);
744 return ret;
745 }
746
747 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
748 ar->monitor_vdev_id);
749
750 return 0;
751}
752
753static int ath10k_stop_cac(struct ath10k *ar)
754{
755 lockdep_assert_held(&ar->conf_mutex);
756
757 /* CAC is not running - do nothing */
758 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
759 return 0;
760
761 ath10k_monitor_stop(ar);
762 ath10k_monitor_destroy(ar);
763 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
764
765 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
766
767 return 0;
768}
769
770static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
771{
772 switch (dfs_state) {
773 case NL80211_DFS_USABLE:
774 return "USABLE";
775 case NL80211_DFS_UNAVAILABLE:
776 return "UNAVAILABLE";
777 case NL80211_DFS_AVAILABLE:
778 return "AVAILABLE";
779 default:
780 WARN_ON(1);
781 return "bug";
782 }
783}
784
785static void ath10k_config_radar_detection(struct ath10k *ar)
786{
787 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
788 bool radar = ar->hw->conf.radar_enabled;
789 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
790 enum nl80211_dfs_state dfs_state = chan->dfs_state;
791 int ret;
792
793 lockdep_assert_held(&ar->conf_mutex);
794
795 ath10k_dbg(ATH10K_DBG_MAC,
796 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
797 chan->center_freq, radar, chan_radar,
798 ath10k_dfs_state(dfs_state));
799
800 /*
801 * It's safe to call it even if CAC is not started.
802 * This call here guarantees changing channel, etc. will stop CAC.
803 */
804 ath10k_stop_cac(ar);
805
806 if (!radar)
807 return;
808
809 if (!chan_radar)
810 return;
811
812 if (dfs_state != NL80211_DFS_USABLE)
813 return;
814
815 ret = ath10k_start_cac(ar);
816 if (ret) {
817 /*
818 * Not possible to start CAC on current channel so starting
819 * radiation is not allowed, make this channel DFS_UNAVAILABLE
820 * by indicating that radar was detected.
821 */
822 ath10k_warn("failed to start CAC (%d)\n", ret);
823 ieee80211_radar_detected(ar->hw);
824 }
825}
826
Kalle Valo5e3dd152013-06-12 20:52:10 +0300827static void ath10k_control_beaconing(struct ath10k_vif *arvif,
828 struct ieee80211_bss_conf *info)
829{
830 int ret = 0;
831
Michal Kazior548db542013-07-05 16:15:15 +0300832 lockdep_assert_held(&arvif->ar->conf_mutex);
833
Kalle Valo5e3dd152013-06-12 20:52:10 +0300834 if (!info->enable_beacon) {
835 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100836
837 arvif->is_started = false;
838 arvif->is_up = false;
839
Michal Kazior748afc42014-01-23 12:48:21 +0100840 spin_lock_bh(&arvif->ar->data_lock);
841 if (arvif->beacon) {
Michal Kazior767d34f2014-02-27 18:50:03 +0200842 dma_unmap_single(arvif->ar->dev,
843 ATH10K_SKB_CB(arvif->beacon)->paddr,
844 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kazior748afc42014-01-23 12:48:21 +0100845 dev_kfree_skb_any(arvif->beacon);
846
847 arvif->beacon = NULL;
848 arvif->beacon_sent = false;
849 }
850 spin_unlock_bh(&arvif->ar->data_lock);
851
Kalle Valo5e3dd152013-06-12 20:52:10 +0300852 return;
853 }
854
855 arvif->tx_seq_no = 0x1000;
856
857 ret = ath10k_vdev_start(arvif);
858 if (ret)
859 return;
860
Michal Kaziorc930f742014-01-23 11:38:25 +0100861 arvif->aid = 0;
862 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
863
864 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
865 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300866 if (ret) {
867 ath10k_warn("Failed to bring up VDEV: %d\n",
868 arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +0100869 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870 return;
871 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100872
873 arvif->is_started = true;
874 arvif->is_up = true;
875
Kalle Valo60c3daa2013-09-08 17:56:07 +0300876 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300877}
878
879static void ath10k_control_ibss(struct ath10k_vif *arvif,
880 struct ieee80211_bss_conf *info,
881 const u8 self_peer[ETH_ALEN])
882{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200883 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300884 int ret = 0;
885
Michal Kazior548db542013-07-05 16:15:15 +0300886 lockdep_assert_held(&arvif->ar->conf_mutex);
887
Kalle Valo5e3dd152013-06-12 20:52:10 +0300888 if (!info->ibss_joined) {
889 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
890 if (ret)
891 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
892 self_peer, arvif->vdev_id, ret);
893
Michal Kaziorc930f742014-01-23 11:38:25 +0100894 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300895 return;
896
897 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100898 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899 if (ret) {
900 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100901 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300902 return;
903 }
904
Michal Kaziorc930f742014-01-23 11:38:25 +0100905 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300906
907 return;
908 }
909
910 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
911 if (ret) {
912 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
913 self_peer, arvif->vdev_id, ret);
914 return;
915 }
916
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200917 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
918 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300919 ATH10K_DEFAULT_ATIM);
920 if (ret)
921 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
922 arvif->vdev_id, ret);
923}
924
925/*
926 * Review this when mac80211 gains per-interface powersave support.
927 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300928static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300930 struct ath10k *ar = arvif->ar;
931 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 enum wmi_sta_powersave_param param;
933 enum wmi_sta_ps_mode psmode;
934 int ret;
935
Michal Kazior548db542013-07-05 16:15:15 +0300936 lockdep_assert_held(&arvif->ar->conf_mutex);
937
Michal Kaziorad088bf2013-10-16 15:44:46 +0300938 if (arvif->vif->type != NL80211_IFTYPE_STATION)
939 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300940
941 if (conf->flags & IEEE80211_CONF_PS) {
942 psmode = WMI_STA_PS_MODE_ENABLED;
943 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
944
Michal Kaziorad088bf2013-10-16 15:44:46 +0300945 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300946 conf->dynamic_ps_timeout);
947 if (ret) {
948 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
949 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300950 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300951 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300952 } else {
953 psmode = WMI_STA_PS_MODE_DISABLED;
954 }
955
Kalle Valo60c3daa2013-09-08 17:56:07 +0300956 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
957 arvif->vdev_id, psmode ? "enable" : "disable");
958
Michal Kaziorad088bf2013-10-16 15:44:46 +0300959 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
960 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300961 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
962 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300963 return ret;
964 }
965
966 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967}
968
969/**********************/
970/* Station management */
971/**********************/
972
973static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
974 struct ath10k_vif *arvif,
975 struct ieee80211_sta *sta,
976 struct ieee80211_bss_conf *bss_conf,
977 struct wmi_peer_assoc_complete_arg *arg)
978{
Michal Kazior548db542013-07-05 16:15:15 +0300979 lockdep_assert_held(&ar->conf_mutex);
980
Kalle Valo5e3dd152013-06-12 20:52:10 +0300981 memcpy(arg->addr, sta->addr, ETH_ALEN);
982 arg->vdev_id = arvif->vdev_id;
983 arg->peer_aid = sta->aid;
984 arg->peer_flags |= WMI_PEER_AUTH;
985
986 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
987 /*
988 * Seems FW have problems with Power Save in STA
989 * mode when we setup this parameter to high (eg. 5).
990 * Often we see that FW don't send NULL (with clean P flags)
991 * frame even there is info about buffered frames in beacons.
992 * Sometimes we have to wait more than 10 seconds before FW
993 * will wakeup. Often sending one ping from AP to our device
994 * just fail (more than 50%).
995 *
996 * Seems setting this FW parameter to 1 couse FW
997 * will check every beacon and will wakup immediately
998 * after detection buffered data.
999 */
1000 arg->peer_listen_intval = 1;
1001 else
1002 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1003
1004 arg->peer_num_spatial_streams = 1;
1005
1006 /*
1007 * The assoc capabilities are available only in managed mode.
1008 */
1009 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1010 arg->peer_caps = bss_conf->assoc_capability;
1011}
1012
1013static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1014 struct ath10k_vif *arvif,
1015 struct wmi_peer_assoc_complete_arg *arg)
1016{
1017 struct ieee80211_vif *vif = arvif->vif;
1018 struct ieee80211_bss_conf *info = &vif->bss_conf;
1019 struct cfg80211_bss *bss;
1020 const u8 *rsnie = NULL;
1021 const u8 *wpaie = NULL;
1022
Michal Kazior548db542013-07-05 16:15:15 +03001023 lockdep_assert_held(&ar->conf_mutex);
1024
Kalle Valo5e3dd152013-06-12 20:52:10 +03001025 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1026 info->bssid, NULL, 0, 0, 0);
1027 if (bss) {
1028 const struct cfg80211_bss_ies *ies;
1029
1030 rcu_read_lock();
1031 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1032
1033 ies = rcu_dereference(bss->ies);
1034
1035 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1036 WLAN_OUI_TYPE_MICROSOFT_WPA,
1037 ies->data,
1038 ies->len);
1039 rcu_read_unlock();
1040 cfg80211_put_bss(ar->hw->wiphy, bss);
1041 }
1042
1043 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1044 if (rsnie || wpaie) {
1045 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1046 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1047 }
1048
1049 if (wpaie) {
1050 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1051 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1052 }
1053}
1054
1055static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1056 struct ieee80211_sta *sta,
1057 struct wmi_peer_assoc_complete_arg *arg)
1058{
1059 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1060 const struct ieee80211_supported_band *sband;
1061 const struct ieee80211_rate *rates;
1062 u32 ratemask;
1063 int i;
1064
Michal Kazior548db542013-07-05 16:15:15 +03001065 lockdep_assert_held(&ar->conf_mutex);
1066
Kalle Valo5e3dd152013-06-12 20:52:10 +03001067 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1068 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1069 rates = sband->bitrates;
1070
1071 rateset->num_rates = 0;
1072
1073 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1074 if (!(ratemask & 1))
1075 continue;
1076
1077 rateset->rates[rateset->num_rates] = rates->hw_value;
1078 rateset->num_rates++;
1079 }
1080}
1081
1082static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1083 struct ieee80211_sta *sta,
1084 struct wmi_peer_assoc_complete_arg *arg)
1085{
1086 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001087 int i, n;
1088
Michal Kazior548db542013-07-05 16:15:15 +03001089 lockdep_assert_held(&ar->conf_mutex);
1090
Kalle Valo5e3dd152013-06-12 20:52:10 +03001091 if (!ht_cap->ht_supported)
1092 return;
1093
1094 arg->peer_flags |= WMI_PEER_HT;
1095 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1096 ht_cap->ampdu_factor)) - 1;
1097
1098 arg->peer_mpdu_density =
1099 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1100
1101 arg->peer_ht_caps = ht_cap->cap;
1102 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1103
1104 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1105 arg->peer_flags |= WMI_PEER_LDPC;
1106
1107 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1108 arg->peer_flags |= WMI_PEER_40MHZ;
1109 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1110 }
1111
1112 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1113 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1114
1115 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1116 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1117
1118 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1119 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1120 arg->peer_flags |= WMI_PEER_STBC;
1121 }
1122
1123 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1124 u32 stbc;
1125 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1126 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1127 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1128 arg->peer_rate_caps |= stbc;
1129 arg->peer_flags |= WMI_PEER_STBC;
1130 }
1131
Kalle Valo5e3dd152013-06-12 20:52:10 +03001132 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1133 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1134 else if (ht_cap->mcs.rx_mask[1])
1135 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1136
1137 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1138 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1139 arg->peer_ht_rates.rates[n++] = i;
1140
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001141 /*
1142 * This is a workaround for HT-enabled STAs which break the spec
1143 * and have no HT capabilities RX mask (no HT RX MCS map).
1144 *
1145 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1146 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1147 *
1148 * Firmware asserts if such situation occurs.
1149 */
1150 if (n == 0) {
1151 arg->peer_ht_rates.num_rates = 8;
1152 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1153 arg->peer_ht_rates.rates[i] = i;
1154 } else {
1155 arg->peer_ht_rates.num_rates = n;
1156 arg->peer_num_spatial_streams = sta->rx_nss;
1157 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001158
Kalle Valo60c3daa2013-09-08 17:56:07 +03001159 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1160 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161 arg->peer_ht_rates.num_rates,
1162 arg->peer_num_spatial_streams);
1163}
1164
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001165static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1166 struct ath10k_vif *arvif,
1167 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001168{
1169 u32 uapsd = 0;
1170 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001171 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172
Michal Kazior548db542013-07-05 16:15:15 +03001173 lockdep_assert_held(&ar->conf_mutex);
1174
Kalle Valo5e3dd152013-06-12 20:52:10 +03001175 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001176 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177 sta->uapsd_queues, sta->max_sp);
1178
Kalle Valo5e3dd152013-06-12 20:52:10 +03001179 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1180 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1181 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1182 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1183 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1184 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1185 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1186 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1187 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1188 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1189 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1190 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1191
1192
1193 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1194 max_sp = sta->max_sp;
1195
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001196 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1197 sta->addr,
1198 WMI_AP_PS_PEER_PARAM_UAPSD,
1199 uapsd);
1200 if (ret) {
1201 ath10k_warn("failed to set ap ps peer param uapsd: %d\n",
1202 ret);
1203 return ret;
1204 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001205
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001206 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1207 sta->addr,
1208 WMI_AP_PS_PEER_PARAM_MAX_SP,
1209 max_sp);
1210 if (ret) {
1211 ath10k_warn("failed to set ap ps peer param max sp: %d\n",
1212 ret);
1213 return ret;
1214 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001215
1216 /* TODO setup this based on STA listen interval and
1217 beacon interval. Currently we don't know
1218 sta->listen_interval - mac80211 patch required.
1219 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001220 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1221 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1222 if (ret) {
1223 ath10k_warn("failed to set ap ps peer param ageout time: %d\n",
1224 ret);
1225 return ret;
1226 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001227 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001229 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001230}
1231
1232static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1233 struct ieee80211_sta *sta,
1234 struct wmi_peer_assoc_complete_arg *arg)
1235{
1236 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001237 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001238
1239 if (!vht_cap->vht_supported)
1240 return;
1241
1242 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243 arg->peer_vht_caps = vht_cap->cap;
1244
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001245
1246 ampdu_factor = (vht_cap->cap &
1247 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1248 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1249
1250 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1251 * zero in VHT IE. Using it would result in degraded throughput.
1252 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1253 * it if VHT max_mpdu is smaller. */
1254 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1255 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1256 ampdu_factor)) - 1);
1257
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1259 arg->peer_flags |= WMI_PEER_80MHZ;
1260
1261 arg->peer_vht_rates.rx_max_rate =
1262 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1263 arg->peer_vht_rates.rx_mcs_set =
1264 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1265 arg->peer_vht_rates.tx_max_rate =
1266 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1267 arg->peer_vht_rates.tx_mcs_set =
1268 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1269
Kalle Valo60c3daa2013-09-08 17:56:07 +03001270 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1271 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001272}
1273
1274static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1275 struct ath10k_vif *arvif,
1276 struct ieee80211_sta *sta,
1277 struct ieee80211_bss_conf *bss_conf,
1278 struct wmi_peer_assoc_complete_arg *arg)
1279{
1280 switch (arvif->vdev_type) {
1281 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001282 if (sta->wme)
1283 arg->peer_flags |= WMI_PEER_QOS;
1284
1285 if (sta->wme && sta->uapsd_queues) {
1286 arg->peer_flags |= WMI_PEER_APSD;
1287 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1288 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001289 break;
1290 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001291 if (bss_conf->qos)
1292 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001293 break;
1294 default:
1295 break;
1296 }
1297}
1298
1299static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1300 struct ath10k_vif *arvif,
1301 struct ieee80211_sta *sta,
1302 struct wmi_peer_assoc_complete_arg *arg)
1303{
1304 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1305
Kalle Valo5e3dd152013-06-12 20:52:10 +03001306 switch (ar->hw->conf.chandef.chan->band) {
1307 case IEEE80211_BAND_2GHZ:
1308 if (sta->ht_cap.ht_supported) {
1309 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1310 phymode = MODE_11NG_HT40;
1311 else
1312 phymode = MODE_11NG_HT20;
1313 } else {
1314 phymode = MODE_11G;
1315 }
1316
1317 break;
1318 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001319 /*
1320 * Check VHT first.
1321 */
1322 if (sta->vht_cap.vht_supported) {
1323 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1324 phymode = MODE_11AC_VHT80;
1325 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1326 phymode = MODE_11AC_VHT40;
1327 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1328 phymode = MODE_11AC_VHT20;
1329 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001330 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1331 phymode = MODE_11NA_HT40;
1332 else
1333 phymode = MODE_11NA_HT20;
1334 } else {
1335 phymode = MODE_11A;
1336 }
1337
1338 break;
1339 default:
1340 break;
1341 }
1342
Kalle Valo38a1d472013-09-08 17:56:14 +03001343 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1344 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001345
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346 arg->peer_phymode = phymode;
1347 WARN_ON(phymode == MODE_UNKNOWN);
1348}
1349
Kalle Valob9ada652013-10-16 15:44:46 +03001350static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1351 struct ath10k_vif *arvif,
1352 struct ieee80211_sta *sta,
1353 struct ieee80211_bss_conf *bss_conf,
1354 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355{
Michal Kazior548db542013-07-05 16:15:15 +03001356 lockdep_assert_held(&ar->conf_mutex);
1357
Kalle Valob9ada652013-10-16 15:44:46 +03001358 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359
Kalle Valob9ada652013-10-16 15:44:46 +03001360 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1361 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1362 ath10k_peer_assoc_h_rates(ar, sta, arg);
1363 ath10k_peer_assoc_h_ht(ar, sta, arg);
1364 ath10k_peer_assoc_h_vht(ar, sta, arg);
1365 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1366 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367
Kalle Valob9ada652013-10-16 15:44:46 +03001368 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369}
1370
Michal Kazior90046f52014-02-14 14:45:51 +01001371static const u32 ath10k_smps_map[] = {
1372 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1373 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1374 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1375 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1376};
1377
1378static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1379 const u8 *addr,
1380 const struct ieee80211_sta_ht_cap *ht_cap)
1381{
1382 int smps;
1383
1384 if (!ht_cap->ht_supported)
1385 return 0;
1386
1387 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1388 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1389
1390 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1391 return -EINVAL;
1392
1393 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1394 WMI_PEER_SMPS_STATE,
1395 ath10k_smps_map[smps]);
1396}
1397
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398/* can be called only in mac80211 callbacks due to `key_count` usage */
1399static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1400 struct ieee80211_vif *vif,
1401 struct ieee80211_bss_conf *bss_conf)
1402{
1403 struct ath10k *ar = hw->priv;
1404 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001405 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001406 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001407 struct ieee80211_sta *ap_sta;
1408 int ret;
1409
Michal Kazior548db542013-07-05 16:15:15 +03001410 lockdep_assert_held(&ar->conf_mutex);
1411
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412 rcu_read_lock();
1413
1414 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1415 if (!ap_sta) {
1416 ath10k_warn("Failed to find station entry for %pM\n",
1417 bss_conf->bssid);
1418 rcu_read_unlock();
1419 return;
1420 }
1421
Michal Kazior90046f52014-02-14 14:45:51 +01001422 /* ap_sta must be accessed only within rcu section which must be left
1423 * before calling ath10k_setup_peer_smps() which might sleep. */
1424 ht_cap = ap_sta->ht_cap;
1425
Kalle Valob9ada652013-10-16 15:44:46 +03001426 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1427 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001428 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001429 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1430 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001431 rcu_read_unlock();
1432 return;
1433 }
1434
1435 rcu_read_unlock();
1436
Kalle Valob9ada652013-10-16 15:44:46 +03001437 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1438 if (ret) {
1439 ath10k_warn("Peer assoc failed for %pM\n: %d",
1440 bss_conf->bssid, ret);
1441 return;
1442 }
1443
Michal Kazior90046f52014-02-14 14:45:51 +01001444 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1445 if (ret) {
1446 ath10k_warn("failed to setup peer SMPS: %d\n", ret);
1447 return;
1448 }
1449
Kalle Valo60c3daa2013-09-08 17:56:07 +03001450 ath10k_dbg(ATH10K_DBG_MAC,
1451 "mac vdev %d up (associated) bssid %pM aid %d\n",
1452 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1453
Michal Kaziorc930f742014-01-23 11:38:25 +01001454 arvif->aid = bss_conf->aid;
1455 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1456
1457 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1458 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459 ath10k_warn("VDEV: %d up failed: ret %d\n",
1460 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001461 return;
1462 }
1463
1464 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001465}
1466
1467/*
1468 * FIXME: flush TIDs
1469 */
1470static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1471 struct ieee80211_vif *vif)
1472{
1473 struct ath10k *ar = hw->priv;
1474 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1475 int ret;
1476
Michal Kazior548db542013-07-05 16:15:15 +03001477 lockdep_assert_held(&ar->conf_mutex);
1478
Kalle Valo5e3dd152013-06-12 20:52:10 +03001479 /*
1480 * For some reason, calling VDEV-DOWN before VDEV-STOP
1481 * makes the FW to send frames via HTT after disassociation.
1482 * No idea why this happens, even though VDEV-DOWN is supposed
1483 * to be analogous to link down, so just stop the VDEV.
1484 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001485 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1486 arvif->vdev_id);
1487
1488 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001489 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001490
1491 /*
1492 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1493 * report beacons from previously associated network through HTT.
1494 * This in turn would spam mac80211 WARN_ON if we bring down all
1495 * interfaces as it expects there is no rx when no interface is
1496 * running.
1497 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001498 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1499
1500 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001501 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001503 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001504
1505 arvif->is_started = false;
1506 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001507}
1508
1509static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1510 struct ieee80211_sta *sta)
1511{
Kalle Valob9ada652013-10-16 15:44:46 +03001512 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513 int ret = 0;
1514
Michal Kazior548db542013-07-05 16:15:15 +03001515 lockdep_assert_held(&ar->conf_mutex);
1516
Kalle Valob9ada652013-10-16 15:44:46 +03001517 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001519 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1520 sta->addr);
1521 return ret;
1522 }
1523
1524 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1525 if (ret) {
1526 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1527 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528 return ret;
1529 }
1530
Michal Kazior90046f52014-02-14 14:45:51 +01001531 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1532 if (ret) {
1533 ath10k_warn("failed to setup peer SMPS: %d\n", ret);
1534 return ret;
1535 }
1536
Kalle Valo5e3dd152013-06-12 20:52:10 +03001537 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1538 if (ret) {
1539 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1540 return ret;
1541 }
1542
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001543 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1544 if (ret) {
1545 ath10k_warn("could not set qos params for STA %pM, %d\n",
1546 sta->addr, ret);
1547 return ret;
1548 }
1549
Kalle Valo5e3dd152013-06-12 20:52:10 +03001550 return ret;
1551}
1552
1553static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1554 struct ieee80211_sta *sta)
1555{
1556 int ret = 0;
1557
Michal Kazior548db542013-07-05 16:15:15 +03001558 lockdep_assert_held(&ar->conf_mutex);
1559
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1561 if (ret) {
1562 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1563 return ret;
1564 }
1565
1566 return ret;
1567}
1568
1569/**************/
1570/* Regulatory */
1571/**************/
1572
1573static int ath10k_update_channel_list(struct ath10k *ar)
1574{
1575 struct ieee80211_hw *hw = ar->hw;
1576 struct ieee80211_supported_band **bands;
1577 enum ieee80211_band band;
1578 struct ieee80211_channel *channel;
1579 struct wmi_scan_chan_list_arg arg = {0};
1580 struct wmi_channel_arg *ch;
1581 bool passive;
1582 int len;
1583 int ret;
1584 int i;
1585
Michal Kazior548db542013-07-05 16:15:15 +03001586 lockdep_assert_held(&ar->conf_mutex);
1587
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588 bands = hw->wiphy->bands;
1589 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1590 if (!bands[band])
1591 continue;
1592
1593 for (i = 0; i < bands[band]->n_channels; i++) {
1594 if (bands[band]->channels[i].flags &
1595 IEEE80211_CHAN_DISABLED)
1596 continue;
1597
1598 arg.n_channels++;
1599 }
1600 }
1601
1602 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1603 arg.channels = kzalloc(len, GFP_KERNEL);
1604 if (!arg.channels)
1605 return -ENOMEM;
1606
1607 ch = arg.channels;
1608 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1609 if (!bands[band])
1610 continue;
1611
1612 for (i = 0; i < bands[band]->n_channels; i++) {
1613 channel = &bands[band]->channels[i];
1614
1615 if (channel->flags & IEEE80211_CHAN_DISABLED)
1616 continue;
1617
1618 ch->allow_ht = true;
1619
1620 /* FIXME: when should we really allow VHT? */
1621 ch->allow_vht = true;
1622
1623 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001624 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001625
1626 ch->ht40plus =
1627 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1628
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001629 ch->chan_radar =
1630 !!(channel->flags & IEEE80211_CHAN_RADAR);
1631
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001632 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 ch->passive = passive;
1634
1635 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001636 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001637 ch->max_power = channel->max_power * 2;
1638 ch->max_reg_power = channel->max_reg_power * 2;
1639 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 ch->reg_class_id = 0; /* FIXME */
1641
1642 /* FIXME: why use only legacy modes, why not any
1643 * HT/VHT modes? Would that even make any
1644 * difference? */
1645 if (channel->band == IEEE80211_BAND_2GHZ)
1646 ch->mode = MODE_11G;
1647 else
1648 ch->mode = MODE_11A;
1649
1650 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1651 continue;
1652
1653 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001654 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1655 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001656 ch->freq, ch->max_power, ch->max_reg_power,
1657 ch->max_antenna_gain, ch->mode);
1658
1659 ch++;
1660 }
1661 }
1662
1663 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1664 kfree(arg.channels);
1665
1666 return ret;
1667}
1668
Michal Kaziorf7843d72013-07-16 09:38:52 +02001669static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001670{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001672 int ret;
1673
Michal Kaziorf7843d72013-07-16 09:38:52 +02001674 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001675
1676 ret = ath10k_update_channel_list(ar);
1677 if (ret)
1678 ath10k_warn("could not update channel list (%d)\n", ret);
1679
1680 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001681
Kalle Valo5e3dd152013-06-12 20:52:10 +03001682 /* Target allows setting up per-band regdomain but ath_common provides
1683 * a combined one only */
1684 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001685 regpair->reg_domain,
1686 regpair->reg_domain, /* 2ghz */
1687 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001688 regpair->reg_2ghz_ctl,
1689 regpair->reg_5ghz_ctl);
1690 if (ret)
1691 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001692}
Michal Kazior548db542013-07-05 16:15:15 +03001693
Michal Kaziorf7843d72013-07-16 09:38:52 +02001694static void ath10k_reg_notifier(struct wiphy *wiphy,
1695 struct regulatory_request *request)
1696{
1697 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1698 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001699 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001700
1701 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1702
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001703 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1704 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1705 request->dfs_region);
1706 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1707 request->dfs_region);
1708 if (!result)
1709 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1710 request->dfs_region);
1711 }
1712
Michal Kaziorf7843d72013-07-16 09:38:52 +02001713 mutex_lock(&ar->conf_mutex);
1714 if (ar->state == ATH10K_STATE_ON)
1715 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001716 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001717}
1718
1719/***************/
1720/* TX handlers */
1721/***************/
1722
Michal Kazior42c3aa62013-10-02 11:03:38 +02001723static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1724{
1725 if (ieee80211_is_mgmt(hdr->frame_control))
1726 return HTT_DATA_TX_EXT_TID_MGMT;
1727
1728 if (!ieee80211_is_data_qos(hdr->frame_control))
1729 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1730
1731 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1732 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1733
1734 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1735}
1736
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001737static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1738 struct ieee80211_tx_info *info)
1739{
1740 if (info->control.vif)
1741 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1742
1743 if (ar->monitor_enabled)
1744 return ar->monitor_vdev_id;
1745
1746 ath10k_warn("could not resolve vdev id\n");
1747 return 0;
1748}
1749
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750/*
1751 * Frames sent to the FW have to be in "Native Wifi" format.
1752 * Strip the QoS field from the 802.11 header.
1753 */
1754static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1755 struct ieee80211_tx_control *control,
1756 struct sk_buff *skb)
1757{
1758 struct ieee80211_hdr *hdr = (void *)skb->data;
1759 u8 *qos_ctl;
1760
1761 if (!ieee80211_is_data_qos(hdr->frame_control))
1762 return;
1763
1764 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001765 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1766 skb->data, (void *)qos_ctl - (void *)skb->data);
1767 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001768}
1769
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001770static void ath10k_tx_wep_key_work(struct work_struct *work)
1771{
1772 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1773 wep_key_work);
1774 int ret, keyidx = arvif->def_wep_key_newidx;
1775
1776 if (arvif->def_wep_key_idx == keyidx)
1777 return;
1778
1779 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1780 arvif->vdev_id, keyidx);
1781
1782 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1783 arvif->vdev_id,
1784 arvif->ar->wmi.vdev_param->def_keyid,
1785 keyidx);
1786 if (ret) {
1787 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1788 return;
1789 }
1790
1791 arvif->def_wep_key_idx = keyidx;
1792}
1793
Kalle Valo5e3dd152013-06-12 20:52:10 +03001794static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1795{
1796 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1797 struct ieee80211_vif *vif = info->control.vif;
1798 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1799 struct ath10k *ar = arvif->ar;
1800 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1801 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802
Kalle Valo5e3dd152013-06-12 20:52:10 +03001803 if (!ieee80211_has_protected(hdr->frame_control))
1804 return;
1805
1806 if (!key)
1807 return;
1808
1809 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1810 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1811 return;
1812
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001813 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814 return;
1815
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001816 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1817 * queueing frames until key index is updated is not an option because
1818 * sk_buff may need more processing to be done, e.g. offchannel */
1819 arvif->def_wep_key_newidx = key->keyidx;
1820 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001821}
1822
1823static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1824{
1825 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1826 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1827 struct ieee80211_vif *vif = info->control.vif;
1828 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1829
1830 /* This is case only for P2P_GO */
1831 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1832 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1833 return;
1834
1835 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1836 spin_lock_bh(&ar->data_lock);
1837 if (arvif->u.ap.noa_data)
1838 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1839 GFP_ATOMIC))
1840 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1841 arvif->u.ap.noa_data,
1842 arvif->u.ap.noa_len);
1843 spin_unlock_bh(&ar->data_lock);
1844 }
1845}
1846
1847static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1848{
1849 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001850 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851
Michal Kazior961d4c32013-08-09 10:13:34 +02001852 if (ar->htt.target_version_major >= 3) {
1853 /* Since HTT 3.0 there is no separate mgmt tx command */
1854 ret = ath10k_htt_tx(&ar->htt, skb);
1855 goto exit;
1856 }
1857
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001858 if (ieee80211_is_mgmt(hdr->frame_control)) {
1859 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1860 ar->fw_features)) {
1861 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1862 ATH10K_MAX_NUM_MGMT_PENDING) {
1863 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1864 ret = -EBUSY;
1865 goto exit;
1866 }
1867
1868 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1869 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1870 } else {
1871 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1872 }
1873 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1874 ar->fw_features) &&
1875 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876 /* FW does not report tx status properly for NullFunc frames
1877 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001878 * those frames when it detects link/beacon loss and depends
1879 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001880 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001881 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001882 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001883 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884
Michal Kazior961d4c32013-08-09 10:13:34 +02001885exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001886 if (ret) {
1887 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1888 ieee80211_free_txskb(ar->hw, skb);
1889 }
1890}
1891
1892void ath10k_offchan_tx_purge(struct ath10k *ar)
1893{
1894 struct sk_buff *skb;
1895
1896 for (;;) {
1897 skb = skb_dequeue(&ar->offchan_tx_queue);
1898 if (!skb)
1899 break;
1900
1901 ieee80211_free_txskb(ar->hw, skb);
1902 }
1903}
1904
1905void ath10k_offchan_tx_work(struct work_struct *work)
1906{
1907 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1908 struct ath10k_peer *peer;
1909 struct ieee80211_hdr *hdr;
1910 struct sk_buff *skb;
1911 const u8 *peer_addr;
1912 int vdev_id;
1913 int ret;
1914
1915 /* FW requirement: We must create a peer before FW will send out
1916 * an offchannel frame. Otherwise the frame will be stuck and
1917 * never transmitted. We delete the peer upon tx completion.
1918 * It is unlikely that a peer for offchannel tx will already be
1919 * present. However it may be in some rare cases so account for that.
1920 * Otherwise we might remove a legitimate peer and break stuff. */
1921
1922 for (;;) {
1923 skb = skb_dequeue(&ar->offchan_tx_queue);
1924 if (!skb)
1925 break;
1926
1927 mutex_lock(&ar->conf_mutex);
1928
Kalle Valo60c3daa2013-09-08 17:56:07 +03001929 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930 skb);
1931
1932 hdr = (struct ieee80211_hdr *)skb->data;
1933 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001934 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001935
1936 spin_lock_bh(&ar->data_lock);
1937 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1938 spin_unlock_bh(&ar->data_lock);
1939
1940 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001941 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1943 peer_addr, vdev_id);
1944
1945 if (!peer) {
1946 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1947 if (ret)
1948 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1949 peer_addr, vdev_id, ret);
1950 }
1951
1952 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001953 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001954 ar->offchan_tx_skb = skb;
1955 spin_unlock_bh(&ar->data_lock);
1956
1957 ath10k_tx_htt(ar, skb);
1958
1959 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1960 3 * HZ);
1961 if (ret <= 0)
1962 ath10k_warn("timed out waiting for offchannel skb %p\n",
1963 skb);
1964
1965 if (!peer) {
1966 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1967 if (ret)
1968 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1969 peer_addr, vdev_id, ret);
1970 }
1971
1972 mutex_unlock(&ar->conf_mutex);
1973 }
1974}
1975
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001976void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1977{
1978 struct sk_buff *skb;
1979
1980 for (;;) {
1981 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1982 if (!skb)
1983 break;
1984
1985 ieee80211_free_txskb(ar->hw, skb);
1986 }
1987}
1988
1989void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1990{
1991 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1992 struct sk_buff *skb;
1993 int ret;
1994
1995 for (;;) {
1996 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1997 if (!skb)
1998 break;
1999
2000 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002001 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002002 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002003 ieee80211_free_txskb(ar->hw, skb);
2004 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002005 }
2006}
2007
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008/************/
2009/* Scanning */
2010/************/
2011
2012/*
2013 * This gets called if we dont get a heart-beat during scan.
2014 * This may indicate the FW has hung and we need to abort the
2015 * scan manually to prevent cancel_hw_scan() from deadlocking
2016 */
2017void ath10k_reset_scan(unsigned long ptr)
2018{
2019 struct ath10k *ar = (struct ath10k *)ptr;
2020
2021 spin_lock_bh(&ar->data_lock);
2022 if (!ar->scan.in_progress) {
2023 spin_unlock_bh(&ar->data_lock);
2024 return;
2025 }
2026
2027 ath10k_warn("scan timeout. resetting. fw issue?\n");
2028
2029 if (ar->scan.is_roc)
2030 ieee80211_remain_on_channel_expired(ar->hw);
2031 else
2032 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2033
2034 ar->scan.in_progress = false;
2035 complete_all(&ar->scan.completed);
2036 spin_unlock_bh(&ar->data_lock);
2037}
2038
2039static int ath10k_abort_scan(struct ath10k *ar)
2040{
2041 struct wmi_stop_scan_arg arg = {
2042 .req_id = 1, /* FIXME */
2043 .req_type = WMI_SCAN_STOP_ONE,
2044 .u.scan_id = ATH10K_SCAN_ID,
2045 };
2046 int ret;
2047
2048 lockdep_assert_held(&ar->conf_mutex);
2049
2050 del_timer_sync(&ar->scan.timeout);
2051
2052 spin_lock_bh(&ar->data_lock);
2053 if (!ar->scan.in_progress) {
2054 spin_unlock_bh(&ar->data_lock);
2055 return 0;
2056 }
2057
2058 ar->scan.aborting = true;
2059 spin_unlock_bh(&ar->data_lock);
2060
2061 ret = ath10k_wmi_stop_scan(ar, &arg);
2062 if (ret) {
2063 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03002064 spin_lock_bh(&ar->data_lock);
2065 ar->scan.in_progress = false;
2066 ath10k_offchan_tx_purge(ar);
2067 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 return -EIO;
2069 }
2070
Kalle Valo5e3dd152013-06-12 20:52:10 +03002071 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2072 if (ret == 0)
2073 ath10k_warn("timed out while waiting for scan to stop\n");
2074
2075 /* scan completion may be done right after we timeout here, so let's
2076 * check the in_progress and tell mac80211 scan is completed. if we
2077 * don't do that and FW fails to send us scan completion indication
2078 * then userspace won't be able to scan anymore */
2079 ret = 0;
2080
2081 spin_lock_bh(&ar->data_lock);
2082 if (ar->scan.in_progress) {
2083 ath10k_warn("could not stop scan. its still in progress\n");
2084 ar->scan.in_progress = false;
2085 ath10k_offchan_tx_purge(ar);
2086 ret = -ETIMEDOUT;
2087 }
2088 spin_unlock_bh(&ar->data_lock);
2089
2090 return ret;
2091}
2092
2093static int ath10k_start_scan(struct ath10k *ar,
2094 const struct wmi_start_scan_arg *arg)
2095{
2096 int ret;
2097
2098 lockdep_assert_held(&ar->conf_mutex);
2099
2100 ret = ath10k_wmi_start_scan(ar, arg);
2101 if (ret)
2102 return ret;
2103
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2105 if (ret == 0) {
2106 ath10k_abort_scan(ar);
2107 return ret;
2108 }
2109
2110 /* the scan can complete earlier, before we even
2111 * start the timer. in that case the timer handler
2112 * checks ar->scan.in_progress and bails out if its
2113 * false. Add a 200ms margin to account event/command
2114 * processing. */
2115 mod_timer(&ar->scan.timeout, jiffies +
2116 msecs_to_jiffies(arg->max_scan_time+200));
2117 return 0;
2118}
2119
2120/**********************/
2121/* mac80211 callbacks */
2122/**********************/
2123
2124static void ath10k_tx(struct ieee80211_hw *hw,
2125 struct ieee80211_tx_control *control,
2126 struct sk_buff *skb)
2127{
2128 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2129 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2130 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002131 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132
2133 /* We should disable CCK RATE due to P2P */
2134 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2135 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2136
2137 /* we must calculate tid before we apply qos workaround
2138 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002139 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002140 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002141
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002142 /* it makes no sense to process injected frames like that */
2143 if (info->control.vif &&
2144 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2145 ath10k_tx_h_qos_workaround(hw, control, skb);
2146 ath10k_tx_h_update_wep_key(skb);
2147 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2148 ath10k_tx_h_seq_no(skb);
2149 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002151 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002152 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153 ATH10K_SKB_CB(skb)->htt.tid = tid;
2154
2155 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2156 spin_lock_bh(&ar->data_lock);
2157 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002158 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159 spin_unlock_bh(&ar->data_lock);
2160
2161 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2162
2163 skb_queue_tail(&ar->offchan_tx_queue, skb);
2164 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2165 return;
2166 }
2167
2168 ath10k_tx_htt(ar, skb);
2169}
2170
2171/*
2172 * Initialize various parameters with default vaules.
2173 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002174void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002175{
2176 lockdep_assert_held(&ar->conf_mutex);
2177
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002178 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002179 del_timer_sync(&ar->scan.timeout);
2180 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002181 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002182 ath10k_peer_cleanup_all(ar);
2183 ath10k_core_stop(ar);
2184 ath10k_hif_power_down(ar);
2185
2186 spin_lock_bh(&ar->data_lock);
2187 if (ar->scan.in_progress) {
2188 del_timer(&ar->scan.timeout);
2189 ar->scan.in_progress = false;
2190 ieee80211_scan_completed(ar->hw, true);
2191 }
2192 spin_unlock_bh(&ar->data_lock);
2193}
2194
Kalle Valo5e3dd152013-06-12 20:52:10 +03002195static int ath10k_start(struct ieee80211_hw *hw)
2196{
2197 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002198 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199
Michal Kazior548db542013-07-05 16:15:15 +03002200 mutex_lock(&ar->conf_mutex);
2201
Michal Kazioraffd3212013-07-16 09:54:35 +02002202 if (ar->state != ATH10K_STATE_OFF &&
2203 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002204 ret = -EINVAL;
2205 goto exit;
2206 }
2207
2208 ret = ath10k_hif_power_up(ar);
2209 if (ret) {
2210 ath10k_err("could not init hif (%d)\n", ret);
2211 ar->state = ATH10K_STATE_OFF;
2212 goto exit;
2213 }
2214
2215 ret = ath10k_core_start(ar);
2216 if (ret) {
2217 ath10k_err("could not init core (%d)\n", ret);
2218 ath10k_hif_power_down(ar);
2219 ar->state = ATH10K_STATE_OFF;
2220 goto exit;
2221 }
2222
Michal Kazioraffd3212013-07-16 09:54:35 +02002223 if (ar->state == ATH10K_STATE_OFF)
2224 ar->state = ATH10K_STATE_ON;
2225 else if (ar->state == ATH10K_STATE_RESTARTING)
2226 ar->state = ATH10K_STATE_RESTARTED;
2227
Bartosz Markowski226a3392013-09-26 17:47:16 +02002228 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002229 if (ret)
2230 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2231 ret);
2232
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002233 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002234 if (ret)
2235 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2236 ret);
2237
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002238 /*
2239 * By default FW set ARP frames ac to voice (6). In that case ARP
2240 * exchange is not working properly for UAPSD enabled AP. ARP requests
2241 * which arrives with access category 0 are processed by network stack
2242 * and send back with access category 0, but FW changes access category
2243 * to 6. Set ARP frames access category to best effort (0) solves
2244 * this problem.
2245 */
2246
2247 ret = ath10k_wmi_pdev_set_param(ar,
2248 ar->wmi.pdev_param->arp_ac_override, 0);
2249 if (ret) {
2250 ath10k_warn("could not set arp ac override parameter: %d\n",
2251 ret);
2252 goto exit;
2253 }
2254
Michal Kaziorf7843d72013-07-16 09:38:52 +02002255 ath10k_regd_update(ar);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002256 ret = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002257
Michal Kazior818bdd12013-07-16 09:38:57 +02002258exit:
Michal Kazior548db542013-07-05 16:15:15 +03002259 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002260 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261}
2262
2263static void ath10k_stop(struct ieee80211_hw *hw)
2264{
2265 struct ath10k *ar = hw->priv;
2266
Michal Kazior548db542013-07-05 16:15:15 +03002267 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002268 if (ar->state == ATH10K_STATE_ON ||
2269 ar->state == ATH10K_STATE_RESTARTED ||
2270 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002271 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002272
Michal Kaziorf7843d72013-07-16 09:38:52 +02002273 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002274 mutex_unlock(&ar->conf_mutex);
2275
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002276 ath10k_mgmt_over_wmi_tx_purge(ar);
2277
Michal Kazior548db542013-07-05 16:15:15 +03002278 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002279 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002280 cancel_work_sync(&ar->restart_work);
2281}
2282
Michal Kaziorad088bf2013-10-16 15:44:46 +03002283static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002284{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002285 struct ath10k_vif *arvif;
2286 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002287
2288 lockdep_assert_held(&ar->conf_mutex);
2289
Michal Kaziorad088bf2013-10-16 15:44:46 +03002290 list_for_each_entry(arvif, &ar->arvifs, list) {
2291 ret = ath10k_mac_vif_setup_ps(arvif);
2292 if (ret) {
2293 ath10k_warn("could not setup powersave (%d)\n", ret);
2294 break;
2295 }
2296 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002297
Michal Kaziorad088bf2013-10-16 15:44:46 +03002298 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299}
2300
Michal Kaziorc930f742014-01-23 11:38:25 +01002301static const char *chandef_get_width(enum nl80211_chan_width width)
2302{
2303 switch (width) {
2304 case NL80211_CHAN_WIDTH_20_NOHT:
2305 return "20 (noht)";
2306 case NL80211_CHAN_WIDTH_20:
2307 return "20";
2308 case NL80211_CHAN_WIDTH_40:
2309 return "40";
2310 case NL80211_CHAN_WIDTH_80:
2311 return "80";
2312 case NL80211_CHAN_WIDTH_80P80:
2313 return "80+80";
2314 case NL80211_CHAN_WIDTH_160:
2315 return "160";
2316 case NL80211_CHAN_WIDTH_5:
2317 return "5";
2318 case NL80211_CHAN_WIDTH_10:
2319 return "10";
2320 }
2321 return "?";
2322}
2323
2324static void ath10k_config_chan(struct ath10k *ar)
2325{
2326 struct ath10k_vif *arvif;
2327 bool monitor_was_enabled;
2328 int ret;
2329
2330 lockdep_assert_held(&ar->conf_mutex);
2331
2332 ath10k_dbg(ATH10K_DBG_MAC,
2333 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2334 ar->chandef.chan->center_freq,
2335 ar->chandef.center_freq1,
2336 ar->chandef.center_freq2,
2337 chandef_get_width(ar->chandef.width));
2338
2339 /* First stop monitor interface. Some FW versions crash if there's a
2340 * lone monitor interface. */
2341 monitor_was_enabled = ar->monitor_enabled;
2342
2343 if (ar->monitor_enabled)
2344 ath10k_monitor_stop(ar);
2345
2346 list_for_each_entry(arvif, &ar->arvifs, list) {
2347 if (!arvif->is_started)
2348 continue;
2349
2350 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2351 continue;
2352
2353 ret = ath10k_vdev_stop(arvif);
2354 if (ret) {
2355 ath10k_warn("could not stop vdev %d (%d)\n",
2356 arvif->vdev_id, ret);
2357 continue;
2358 }
2359 }
2360
2361 /* all vdevs are now stopped - now attempt to restart them */
2362
2363 list_for_each_entry(arvif, &ar->arvifs, list) {
2364 if (!arvif->is_started)
2365 continue;
2366
2367 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2368 continue;
2369
2370 ret = ath10k_vdev_start(arvif);
2371 if (ret) {
2372 ath10k_warn("could not start vdev %d (%d)\n",
2373 arvif->vdev_id, ret);
2374 continue;
2375 }
2376
2377 if (!arvif->is_up)
2378 continue;
2379
2380 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2381 arvif->bssid);
2382 if (ret) {
2383 ath10k_warn("could not bring vdev up %d (%d)\n",
2384 arvif->vdev_id, ret);
2385 continue;
2386 }
2387 }
2388
2389 if (monitor_was_enabled)
2390 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2391}
2392
Kalle Valo5e3dd152013-06-12 20:52:10 +03002393static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2394{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395 struct ath10k *ar = hw->priv;
2396 struct ieee80211_conf *conf = &hw->conf;
2397 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002398 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002399
2400 mutex_lock(&ar->conf_mutex);
2401
2402 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002403 ath10k_dbg(ATH10K_DBG_MAC,
2404 "mac config channel %d mhz flags 0x%x\n",
2405 conf->chandef.chan->center_freq,
2406 conf->chandef.chan->flags);
2407
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408 spin_lock_bh(&ar->data_lock);
2409 ar->rx_channel = conf->chandef.chan;
2410 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002411
2412 ath10k_config_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002413
2414 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2415 ar->chandef = conf->chandef;
2416 ath10k_config_chan(ar);
2417 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418 }
2419
Michal Kazior5474efe2013-10-23 04:02:15 -07002420 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2421 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2422 hw->conf.power_level);
2423
2424 param = ar->wmi.pdev_param->txpower_limit2g;
2425 ret = ath10k_wmi_pdev_set_param(ar, param,
2426 hw->conf.power_level * 2);
2427 if (ret)
2428 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2429 hw->conf.power_level, ret);
2430
2431 param = ar->wmi.pdev_param->txpower_limit5g;
2432 ret = ath10k_wmi_pdev_set_param(ar, param,
2433 hw->conf.power_level * 2);
2434 if (ret)
2435 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2436 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002437 }
2438
Michal Kazioraffd3212013-07-16 09:54:35 +02002439 if (changed & IEEE80211_CONF_CHANGE_PS)
2440 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002441
2442 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2443 if (conf->flags & IEEE80211_CONF_MONITOR)
2444 ret = ath10k_monitor_create(ar);
2445 else
2446 ret = ath10k_monitor_destroy(ar);
2447 }
2448
2449 mutex_unlock(&ar->conf_mutex);
2450 return ret;
2451}
2452
2453/*
2454 * TODO:
2455 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2456 * because we will send mgmt frames without CCK. This requirement
2457 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2458 * in the TX packet.
2459 */
2460static int ath10k_add_interface(struct ieee80211_hw *hw,
2461 struct ieee80211_vif *vif)
2462{
2463 struct ath10k *ar = hw->priv;
2464 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2465 enum wmi_sta_powersave_param param;
2466 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002467 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002469 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002470
2471 mutex_lock(&ar->conf_mutex);
2472
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002473 memset(arvif, 0, sizeof(*arvif));
2474
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475 arvif->ar = ar;
2476 arvif->vif = vif;
2477
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002478 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002479 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002480
Kalle Valo5e3dd152013-06-12 20:52:10 +03002481 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2482 ath10k_warn("Only one monitor interface allowed\n");
2483 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002484 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485 }
2486
2487 bit = ffs(ar->free_vdev_map);
2488 if (bit == 0) {
2489 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002490 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491 }
2492
2493 arvif->vdev_id = bit - 1;
2494 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495
2496 if (ar->p2p)
2497 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2498
2499 switch (vif->type) {
2500 case NL80211_IFTYPE_UNSPECIFIED:
2501 case NL80211_IFTYPE_STATION:
2502 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2503 if (vif->p2p)
2504 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2505 break;
2506 case NL80211_IFTYPE_ADHOC:
2507 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2508 break;
2509 case NL80211_IFTYPE_AP:
2510 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2511
2512 if (vif->p2p)
2513 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2514 break;
2515 case NL80211_IFTYPE_MONITOR:
2516 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2517 break;
2518 default:
2519 WARN_ON(1);
2520 break;
2521 }
2522
Kalle Valo60c3daa2013-09-08 17:56:07 +03002523 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002524 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2525
2526 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2527 arvif->vdev_subtype, vif->addr);
2528 if (ret) {
2529 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002530 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002531 }
2532
Michal Kazior9dad14a2013-10-16 15:44:45 +03002533 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002534 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002535
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002536 vdev_param = ar->wmi.vdev_param->def_keyid;
2537 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002538 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002539 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002540 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002541 goto err_vdev_delete;
2542 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002543
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002544 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2545 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002546 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002547 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002548 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002549 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002550 goto err_vdev_delete;
2551 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552
2553 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2554 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2555 if (ret) {
2556 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002557 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002559
Kalle Valo5a13e762014-01-20 11:01:46 +02002560 ret = ath10k_mac_set_kickout(arvif);
2561 if (ret) {
2562 ath10k_warn("Failed to set kickout parameters: %d\n",
2563 ret);
2564 goto err_peer_delete;
2565 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002566 }
2567
2568 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2569 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2570 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2571 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2572 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002573 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002575 goto err_peer_delete;
2576 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002577
2578 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2579 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2580 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2581 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002582 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002584 goto err_peer_delete;
2585 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586
2587 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2588 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2589 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2590 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002591 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002592 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002593 goto err_peer_delete;
2594 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002595 }
2596
Michal Kazior424121c2013-07-22 14:13:31 +02002597 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002598 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002599 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2600 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002601 goto err_peer_delete;
2602 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002603
Michal Kazior424121c2013-07-22 14:13:31 +02002604 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002605 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002606 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2607 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002608 goto err_peer_delete;
2609 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002610
Kalle Valo5e3dd152013-06-12 20:52:10 +03002611 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2612 ar->monitor_present = true;
2613
Kalle Valo5e3dd152013-06-12 20:52:10 +03002614 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002615 return 0;
2616
2617err_peer_delete:
2618 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2619 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2620
2621err_vdev_delete:
2622 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2623 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002624 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002625
2626err:
2627 mutex_unlock(&ar->conf_mutex);
2628
Kalle Valo5e3dd152013-06-12 20:52:10 +03002629 return ret;
2630}
2631
2632static void ath10k_remove_interface(struct ieee80211_hw *hw,
2633 struct ieee80211_vif *vif)
2634{
2635 struct ath10k *ar = hw->priv;
2636 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2637 int ret;
2638
2639 mutex_lock(&ar->conf_mutex);
2640
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002641 cancel_work_sync(&arvif->wep_key_work);
2642
Michal Kaziored543882013-09-13 14:16:56 +02002643 spin_lock_bh(&ar->data_lock);
2644 if (arvif->beacon) {
2645 dev_kfree_skb_any(arvif->beacon);
2646 arvif->beacon = NULL;
2647 }
2648 spin_unlock_bh(&ar->data_lock);
2649
Kalle Valo5e3dd152013-06-12 20:52:10 +03002650 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002651 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002652
2653 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2654 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2655 if (ret)
2656 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2657
2658 kfree(arvif->u.ap.noa_data);
2659 }
2660
Kalle Valo60c3daa2013-09-08 17:56:07 +03002661 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2662 arvif->vdev_id);
2663
Kalle Valo5e3dd152013-06-12 20:52:10 +03002664 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2665 if (ret)
2666 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2667
2668 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2669 ar->monitor_present = false;
2670
2671 ath10k_peer_cleanup(ar, arvif->vdev_id);
2672
2673 mutex_unlock(&ar->conf_mutex);
2674}
2675
2676/*
2677 * FIXME: Has to be verified.
2678 */
2679#define SUPPORTED_FILTERS \
2680 (FIF_PROMISC_IN_BSS | \
2681 FIF_ALLMULTI | \
2682 FIF_CONTROL | \
2683 FIF_PSPOLL | \
2684 FIF_OTHER_BSS | \
2685 FIF_BCN_PRBRESP_PROMISC | \
2686 FIF_PROBE_REQ | \
2687 FIF_FCSFAIL)
2688
2689static void ath10k_configure_filter(struct ieee80211_hw *hw,
2690 unsigned int changed_flags,
2691 unsigned int *total_flags,
2692 u64 multicast)
2693{
2694 struct ath10k *ar = hw->priv;
2695 int ret;
2696
2697 mutex_lock(&ar->conf_mutex);
2698
2699 changed_flags &= SUPPORTED_FILTERS;
2700 *total_flags &= SUPPORTED_FILTERS;
2701 ar->filter_flags = *total_flags;
2702
Michal Kaziorafd09222013-10-16 16:45:41 +03002703 /* Monitor must not be started if it wasn't created first.
2704 * Promiscuous mode may be started on a non-monitor interface - in
2705 * such case the monitor vdev is not created so starting the
2706 * monitor makes no sense. Since ath10k uses no special RX filters
2707 * (only BSS filter in STA mode) there's no need for any special
2708 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002709 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002710 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002711 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2712 ar->monitor_vdev_id);
2713
Kalle Valo5e3dd152013-06-12 20:52:10 +03002714 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2715 if (ret)
2716 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002718 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002719 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2720 ar->monitor_vdev_id);
2721
Kalle Valo5e3dd152013-06-12 20:52:10 +03002722 ret = ath10k_monitor_stop(ar);
2723 if (ret)
2724 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002725 }
2726
2727 mutex_unlock(&ar->conf_mutex);
2728}
2729
2730static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2731 struct ieee80211_vif *vif,
2732 struct ieee80211_bss_conf *info,
2733 u32 changed)
2734{
2735 struct ath10k *ar = hw->priv;
2736 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2737 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002738 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002739
2740 mutex_lock(&ar->conf_mutex);
2741
2742 if (changed & BSS_CHANGED_IBSS)
2743 ath10k_control_ibss(arvif, info, vif->addr);
2744
2745 if (changed & BSS_CHANGED_BEACON_INT) {
2746 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002747 vdev_param = ar->wmi.vdev_param->beacon_interval;
2748 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002750 ath10k_dbg(ATH10K_DBG_MAC,
2751 "mac vdev %d beacon_interval %d\n",
2752 arvif->vdev_id, arvif->beacon_interval);
2753
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 if (ret)
2755 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2756 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757 }
2758
2759 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002760 ath10k_dbg(ATH10K_DBG_MAC,
2761 "vdev %d set beacon tx mode to staggered\n",
2762 arvif->vdev_id);
2763
Bartosz Markowski226a3392013-09-26 17:47:16 +02002764 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2765 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002766 WMI_BEACON_STAGGERED_MODE);
2767 if (ret)
2768 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2769 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002770 }
2771
John W. Linvilleb70727e2013-06-13 13:34:29 -04002772 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773 arvif->dtim_period = info->dtim_period;
2774
Kalle Valo60c3daa2013-09-08 17:56:07 +03002775 ath10k_dbg(ATH10K_DBG_MAC,
2776 "mac vdev %d dtim_period %d\n",
2777 arvif->vdev_id, arvif->dtim_period);
2778
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002779 vdev_param = ar->wmi.vdev_param->dtim_period;
2780 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002781 arvif->dtim_period);
2782 if (ret)
2783 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2784 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002785 }
2786
2787 if (changed & BSS_CHANGED_SSID &&
2788 vif->type == NL80211_IFTYPE_AP) {
2789 arvif->u.ap.ssid_len = info->ssid_len;
2790 if (info->ssid_len)
2791 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2792 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2793 }
2794
2795 if (changed & BSS_CHANGED_BSSID) {
2796 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002797 ath10k_dbg(ATH10K_DBG_MAC,
2798 "mac vdev %d create peer %pM\n",
2799 arvif->vdev_id, info->bssid);
2800
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801 ret = ath10k_peer_create(ar, arvif->vdev_id,
2802 info->bssid);
2803 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002804 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2805 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002806
2807 if (vif->type == NL80211_IFTYPE_STATION) {
2808 /*
2809 * this is never erased as we it for crypto key
2810 * clearing; this is FW requirement
2811 */
Michal Kaziorc930f742014-01-23 11:38:25 +01002812 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002813
Kalle Valo60c3daa2013-09-08 17:56:07 +03002814 ath10k_dbg(ATH10K_DBG_MAC,
2815 "mac vdev %d start %pM\n",
2816 arvif->vdev_id, info->bssid);
2817
Kalle Valo5e3dd152013-06-12 20:52:10 +03002818 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002819 if (ret) {
2820 ath10k_warn("failed to start vdev: %d\n",
2821 ret);
Kalle Valo75459e32014-02-13 18:13:12 +02002822 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01002823 }
2824
2825 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002826 }
2827
2828 /*
2829 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2830 * so driver need to store it. It is needed when leaving
2831 * IBSS in order to remove BSSID peer.
2832 */
2833 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01002834 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835 ETH_ALEN);
2836 }
2837 }
2838
2839 if (changed & BSS_CHANGED_BEACON_ENABLED)
2840 ath10k_control_beaconing(arvif, info);
2841
2842 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2843 u32 cts_prot;
2844 if (info->use_cts_prot)
2845 cts_prot = 1;
2846 else
2847 cts_prot = 0;
2848
Kalle Valo60c3daa2013-09-08 17:56:07 +03002849 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2850 arvif->vdev_id, cts_prot);
2851
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002852 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2853 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854 cts_prot);
2855 if (ret)
2856 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2857 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002858 }
2859
2860 if (changed & BSS_CHANGED_ERP_SLOT) {
2861 u32 slottime;
2862 if (info->use_short_slot)
2863 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2864
2865 else
2866 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2867
Kalle Valo60c3daa2013-09-08 17:56:07 +03002868 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2869 arvif->vdev_id, slottime);
2870
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002871 vdev_param = ar->wmi.vdev_param->slot_time;
2872 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002873 slottime);
2874 if (ret)
2875 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2876 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002877 }
2878
2879 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2880 u32 preamble;
2881 if (info->use_short_preamble)
2882 preamble = WMI_VDEV_PREAMBLE_SHORT;
2883 else
2884 preamble = WMI_VDEV_PREAMBLE_LONG;
2885
Kalle Valo60c3daa2013-09-08 17:56:07 +03002886 ath10k_dbg(ATH10K_DBG_MAC,
2887 "mac vdev %d preamble %dn",
2888 arvif->vdev_id, preamble);
2889
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002890 vdev_param = ar->wmi.vdev_param->preamble;
2891 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002892 preamble);
2893 if (ret)
2894 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2895 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002896 }
2897
2898 if (changed & BSS_CHANGED_ASSOC) {
2899 if (info->assoc)
2900 ath10k_bss_assoc(hw, vif, info);
2901 }
2902
Kalle Valo75459e32014-02-13 18:13:12 +02002903exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904 mutex_unlock(&ar->conf_mutex);
2905}
2906
2907static int ath10k_hw_scan(struct ieee80211_hw *hw,
2908 struct ieee80211_vif *vif,
2909 struct cfg80211_scan_request *req)
2910{
2911 struct ath10k *ar = hw->priv;
2912 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2913 struct wmi_start_scan_arg arg;
2914 int ret = 0;
2915 int i;
2916
2917 mutex_lock(&ar->conf_mutex);
2918
2919 spin_lock_bh(&ar->data_lock);
2920 if (ar->scan.in_progress) {
2921 spin_unlock_bh(&ar->data_lock);
2922 ret = -EBUSY;
2923 goto exit;
2924 }
2925
Wolfram Sang16735d02013-11-14 14:32:02 -08002926 reinit_completion(&ar->scan.started);
2927 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928 ar->scan.in_progress = true;
2929 ar->scan.aborting = false;
2930 ar->scan.is_roc = false;
2931 ar->scan.vdev_id = arvif->vdev_id;
2932 spin_unlock_bh(&ar->data_lock);
2933
2934 memset(&arg, 0, sizeof(arg));
2935 ath10k_wmi_start_scan_init(ar, &arg);
2936 arg.vdev_id = arvif->vdev_id;
2937 arg.scan_id = ATH10K_SCAN_ID;
2938
2939 if (!req->no_cck)
2940 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2941
2942 if (req->ie_len) {
2943 arg.ie_len = req->ie_len;
2944 memcpy(arg.ie, req->ie, arg.ie_len);
2945 }
2946
2947 if (req->n_ssids) {
2948 arg.n_ssids = req->n_ssids;
2949 for (i = 0; i < arg.n_ssids; i++) {
2950 arg.ssids[i].len = req->ssids[i].ssid_len;
2951 arg.ssids[i].ssid = req->ssids[i].ssid;
2952 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002953 } else {
2954 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955 }
2956
2957 if (req->n_channels) {
2958 arg.n_channels = req->n_channels;
2959 for (i = 0; i < arg.n_channels; i++)
2960 arg.channels[i] = req->channels[i]->center_freq;
2961 }
2962
2963 ret = ath10k_start_scan(ar, &arg);
2964 if (ret) {
2965 ath10k_warn("could not start hw scan (%d)\n", ret);
2966 spin_lock_bh(&ar->data_lock);
2967 ar->scan.in_progress = false;
2968 spin_unlock_bh(&ar->data_lock);
2969 }
2970
2971exit:
2972 mutex_unlock(&ar->conf_mutex);
2973 return ret;
2974}
2975
2976static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2977 struct ieee80211_vif *vif)
2978{
2979 struct ath10k *ar = hw->priv;
2980 int ret;
2981
2982 mutex_lock(&ar->conf_mutex);
2983 ret = ath10k_abort_scan(ar);
2984 if (ret) {
2985 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2986 ret);
2987 ieee80211_scan_completed(hw, 1 /* aborted */);
2988 }
2989 mutex_unlock(&ar->conf_mutex);
2990}
2991
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002992static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2993 struct ath10k_vif *arvif,
2994 enum set_key_cmd cmd,
2995 struct ieee80211_key_conf *key)
2996{
2997 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2998 int ret;
2999
3000 /* 10.1 firmware branch requires default key index to be set to group
3001 * key index after installing it. Otherwise FW/HW Txes corrupted
3002 * frames with multi-vif APs. This is not required for main firmware
3003 * branch (e.g. 636).
3004 *
3005 * FIXME: This has been tested only in AP. It remains unknown if this
3006 * is required for multi-vif STA interfaces on 10.1 */
3007
3008 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3009 return;
3010
3011 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3012 return;
3013
3014 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3015 return;
3016
3017 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3018 return;
3019
3020 if (cmd != SET_KEY)
3021 return;
3022
3023 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3024 key->keyidx);
3025 if (ret)
3026 ath10k_warn("failed to set group key as default key: %d\n",
3027 ret);
3028}
3029
Kalle Valo5e3dd152013-06-12 20:52:10 +03003030static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3031 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3032 struct ieee80211_key_conf *key)
3033{
3034 struct ath10k *ar = hw->priv;
3035 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3036 struct ath10k_peer *peer;
3037 const u8 *peer_addr;
3038 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3039 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3040 int ret = 0;
3041
3042 if (key->keyidx > WMI_MAX_KEY_INDEX)
3043 return -ENOSPC;
3044
3045 mutex_lock(&ar->conf_mutex);
3046
3047 if (sta)
3048 peer_addr = sta->addr;
3049 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3050 peer_addr = vif->bss_conf.bssid;
3051 else
3052 peer_addr = vif->addr;
3053
3054 key->hw_key_idx = key->keyidx;
3055
3056 /* the peer should not disappear in mid-way (unless FW goes awry) since
3057 * we already hold conf_mutex. we just make sure its there now. */
3058 spin_lock_bh(&ar->data_lock);
3059 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3060 spin_unlock_bh(&ar->data_lock);
3061
3062 if (!peer) {
3063 if (cmd == SET_KEY) {
3064 ath10k_warn("cannot install key for non-existent peer %pM\n",
3065 peer_addr);
3066 ret = -EOPNOTSUPP;
3067 goto exit;
3068 } else {
3069 /* if the peer doesn't exist there is no key to disable
3070 * anymore */
3071 goto exit;
3072 }
3073 }
3074
3075 if (is_wep) {
3076 if (cmd == SET_KEY)
3077 arvif->wep_keys[key->keyidx] = key;
3078 else
3079 arvif->wep_keys[key->keyidx] = NULL;
3080
3081 if (cmd == DISABLE_KEY)
3082 ath10k_clear_vdev_key(arvif, key);
3083 }
3084
3085 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3086 if (ret) {
3087 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
3088 goto exit;
3089 }
3090
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003091 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3092
Kalle Valo5e3dd152013-06-12 20:52:10 +03003093 spin_lock_bh(&ar->data_lock);
3094 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3095 if (peer && cmd == SET_KEY)
3096 peer->keys[key->keyidx] = key;
3097 else if (peer && cmd == DISABLE_KEY)
3098 peer->keys[key->keyidx] = NULL;
3099 else if (peer == NULL)
3100 /* impossible unless FW goes crazy */
3101 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3102 spin_unlock_bh(&ar->data_lock);
3103
3104exit:
3105 mutex_unlock(&ar->conf_mutex);
3106 return ret;
3107}
3108
Michal Kazior9797feb2014-02-14 14:49:48 +01003109static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3110{
3111 struct ath10k *ar;
3112 struct ath10k_vif *arvif;
3113 struct ath10k_sta *arsta;
3114 struct ieee80211_sta *sta;
3115 u32 changed, bw, nss, smps;
3116 int err;
3117
3118 arsta = container_of(wk, struct ath10k_sta, update_wk);
3119 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3120 arvif = arsta->arvif;
3121 ar = arvif->ar;
3122
3123 spin_lock_bh(&ar->data_lock);
3124
3125 changed = arsta->changed;
3126 arsta->changed = 0;
3127
3128 bw = arsta->bw;
3129 nss = arsta->nss;
3130 smps = arsta->smps;
3131
3132 spin_unlock_bh(&ar->data_lock);
3133
3134 mutex_lock(&ar->conf_mutex);
3135
3136 if (changed & IEEE80211_RC_BW_CHANGED) {
3137 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3138 sta->addr, bw);
3139
3140 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3141 WMI_PEER_CHAN_WIDTH, bw);
3142 if (err)
3143 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3144 sta->addr, bw, err);
3145 }
3146
3147 if (changed & IEEE80211_RC_NSS_CHANGED) {
3148 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3149 sta->addr, nss);
3150
3151 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3152 WMI_PEER_NSS, nss);
3153 if (err)
3154 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3155 sta->addr, nss, err);
3156 }
3157
3158 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3159 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3160 sta->addr, smps);
3161
3162 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3163 WMI_PEER_SMPS_STATE, smps);
3164 if (err)
3165 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3166 sta->addr, smps, err);
3167 }
3168
3169 mutex_unlock(&ar->conf_mutex);
3170}
3171
Kalle Valo5e3dd152013-06-12 20:52:10 +03003172static int ath10k_sta_state(struct ieee80211_hw *hw,
3173 struct ieee80211_vif *vif,
3174 struct ieee80211_sta *sta,
3175 enum ieee80211_sta_state old_state,
3176 enum ieee80211_sta_state new_state)
3177{
3178 struct ath10k *ar = hw->priv;
3179 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003180 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003181 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003182 int ret = 0;
3183
Michal Kazior76f90022014-02-25 09:29:57 +02003184 if (old_state == IEEE80211_STA_NOTEXIST &&
3185 new_state == IEEE80211_STA_NONE) {
3186 memset(arsta, 0, sizeof(*arsta));
3187 arsta->arvif = arvif;
3188 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3189 }
3190
Michal Kazior9797feb2014-02-14 14:49:48 +01003191 /* cancel must be done outside the mutex to avoid deadlock */
3192 if ((old_state == IEEE80211_STA_NONE &&
3193 new_state == IEEE80211_STA_NOTEXIST))
3194 cancel_work_sync(&arsta->update_wk);
3195
Kalle Valo5e3dd152013-06-12 20:52:10 +03003196 mutex_lock(&ar->conf_mutex);
3197
3198 if (old_state == IEEE80211_STA_NOTEXIST &&
3199 new_state == IEEE80211_STA_NONE &&
3200 vif->type != NL80211_IFTYPE_STATION) {
3201 /*
3202 * New station addition.
3203 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003204 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3205 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3206 else
3207 max_num_peers = TARGET_NUM_PEERS;
3208
3209 if (ar->num_peers >= max_num_peers) {
3210 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3211 ar->num_peers, max_num_peers);
3212 ret = -ENOBUFS;
3213 goto exit;
3214 }
3215
Kalle Valo60c3daa2013-09-08 17:56:07 +03003216 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003217 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3218 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003219
Kalle Valo5e3dd152013-06-12 20:52:10 +03003220 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3221 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08003222 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3223 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003224 } else if ((old_state == IEEE80211_STA_NONE &&
3225 new_state == IEEE80211_STA_NOTEXIST)) {
3226 /*
3227 * Existing station deletion.
3228 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003229 ath10k_dbg(ATH10K_DBG_MAC,
3230 "mac vdev %d peer delete %pM (sta gone)\n",
3231 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003232 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3233 if (ret)
3234 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
3235 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236
3237 if (vif->type == NL80211_IFTYPE_STATION)
3238 ath10k_bss_disassoc(hw, vif);
3239 } else if (old_state == IEEE80211_STA_AUTH &&
3240 new_state == IEEE80211_STA_ASSOC &&
3241 (vif->type == NL80211_IFTYPE_AP ||
3242 vif->type == NL80211_IFTYPE_ADHOC)) {
3243 /*
3244 * New association.
3245 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003246 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3247 sta->addr);
3248
Kalle Valo5e3dd152013-06-12 20:52:10 +03003249 ret = ath10k_station_assoc(ar, arvif, sta);
3250 if (ret)
3251 ath10k_warn("Failed to associate station: %pM\n",
3252 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003253 } else if (old_state == IEEE80211_STA_ASSOC &&
3254 new_state == IEEE80211_STA_AUTH &&
3255 (vif->type == NL80211_IFTYPE_AP ||
3256 vif->type == NL80211_IFTYPE_ADHOC)) {
3257 /*
3258 * Disassociation.
3259 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003260 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3261 sta->addr);
3262
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263 ret = ath10k_station_disassoc(ar, arvif, sta);
3264 if (ret)
3265 ath10k_warn("Failed to disassociate station: %pM\n",
3266 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003268exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269 mutex_unlock(&ar->conf_mutex);
3270 return ret;
3271}
3272
3273static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3274 u16 ac, bool enable)
3275{
3276 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3277 u32 value = 0;
3278 int ret = 0;
3279
Michal Kazior548db542013-07-05 16:15:15 +03003280 lockdep_assert_held(&ar->conf_mutex);
3281
Kalle Valo5e3dd152013-06-12 20:52:10 +03003282 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3283 return 0;
3284
3285 switch (ac) {
3286 case IEEE80211_AC_VO:
3287 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3288 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3289 break;
3290 case IEEE80211_AC_VI:
3291 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3292 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3293 break;
3294 case IEEE80211_AC_BE:
3295 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3296 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3297 break;
3298 case IEEE80211_AC_BK:
3299 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3300 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3301 break;
3302 }
3303
3304 if (enable)
3305 arvif->u.sta.uapsd |= value;
3306 else
3307 arvif->u.sta.uapsd &= ~value;
3308
3309 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3310 WMI_STA_PS_PARAM_UAPSD,
3311 arvif->u.sta.uapsd);
3312 if (ret) {
3313 ath10k_warn("could not set uapsd params %d\n", ret);
3314 goto exit;
3315 }
3316
3317 if (arvif->u.sta.uapsd)
3318 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3319 else
3320 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3321
3322 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3323 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3324 value);
3325 if (ret)
3326 ath10k_warn("could not set rx wake param %d\n", ret);
3327
3328exit:
3329 return ret;
3330}
3331
3332static int ath10k_conf_tx(struct ieee80211_hw *hw,
3333 struct ieee80211_vif *vif, u16 ac,
3334 const struct ieee80211_tx_queue_params *params)
3335{
3336 struct ath10k *ar = hw->priv;
3337 struct wmi_wmm_params_arg *p = NULL;
3338 int ret;
3339
3340 mutex_lock(&ar->conf_mutex);
3341
3342 switch (ac) {
3343 case IEEE80211_AC_VO:
3344 p = &ar->wmm_params.ac_vo;
3345 break;
3346 case IEEE80211_AC_VI:
3347 p = &ar->wmm_params.ac_vi;
3348 break;
3349 case IEEE80211_AC_BE:
3350 p = &ar->wmm_params.ac_be;
3351 break;
3352 case IEEE80211_AC_BK:
3353 p = &ar->wmm_params.ac_bk;
3354 break;
3355 }
3356
3357 if (WARN_ON(!p)) {
3358 ret = -EINVAL;
3359 goto exit;
3360 }
3361
3362 p->cwmin = params->cw_min;
3363 p->cwmax = params->cw_max;
3364 p->aifs = params->aifs;
3365
3366 /*
3367 * The channel time duration programmed in the HW is in absolute
3368 * microseconds, while mac80211 gives the txop in units of
3369 * 32 microseconds.
3370 */
3371 p->txop = params->txop * 32;
3372
3373 /* FIXME: FW accepts wmm params per hw, not per vif */
3374 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3375 if (ret) {
3376 ath10k_warn("could not set wmm params %d\n", ret);
3377 goto exit;
3378 }
3379
3380 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3381 if (ret)
3382 ath10k_warn("could not set sta uapsd %d\n", ret);
3383
3384exit:
3385 mutex_unlock(&ar->conf_mutex);
3386 return ret;
3387}
3388
3389#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3390
3391static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3392 struct ieee80211_vif *vif,
3393 struct ieee80211_channel *chan,
3394 int duration,
3395 enum ieee80211_roc_type type)
3396{
3397 struct ath10k *ar = hw->priv;
3398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3399 struct wmi_start_scan_arg arg;
3400 int ret;
3401
3402 mutex_lock(&ar->conf_mutex);
3403
3404 spin_lock_bh(&ar->data_lock);
3405 if (ar->scan.in_progress) {
3406 spin_unlock_bh(&ar->data_lock);
3407 ret = -EBUSY;
3408 goto exit;
3409 }
3410
Wolfram Sang16735d02013-11-14 14:32:02 -08003411 reinit_completion(&ar->scan.started);
3412 reinit_completion(&ar->scan.completed);
3413 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003414 ar->scan.in_progress = true;
3415 ar->scan.aborting = false;
3416 ar->scan.is_roc = true;
3417 ar->scan.vdev_id = arvif->vdev_id;
3418 ar->scan.roc_freq = chan->center_freq;
3419 spin_unlock_bh(&ar->data_lock);
3420
3421 memset(&arg, 0, sizeof(arg));
3422 ath10k_wmi_start_scan_init(ar, &arg);
3423 arg.vdev_id = arvif->vdev_id;
3424 arg.scan_id = ATH10K_SCAN_ID;
3425 arg.n_channels = 1;
3426 arg.channels[0] = chan->center_freq;
3427 arg.dwell_time_active = duration;
3428 arg.dwell_time_passive = duration;
3429 arg.max_scan_time = 2 * duration;
3430 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3431 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3432
3433 ret = ath10k_start_scan(ar, &arg);
3434 if (ret) {
3435 ath10k_warn("could not start roc scan (%d)\n", ret);
3436 spin_lock_bh(&ar->data_lock);
3437 ar->scan.in_progress = false;
3438 spin_unlock_bh(&ar->data_lock);
3439 goto exit;
3440 }
3441
3442 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3443 if (ret == 0) {
3444 ath10k_warn("could not switch to channel for roc scan\n");
3445 ath10k_abort_scan(ar);
3446 ret = -ETIMEDOUT;
3447 goto exit;
3448 }
3449
3450 ret = 0;
3451exit:
3452 mutex_unlock(&ar->conf_mutex);
3453 return ret;
3454}
3455
3456static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3457{
3458 struct ath10k *ar = hw->priv;
3459
3460 mutex_lock(&ar->conf_mutex);
3461 ath10k_abort_scan(ar);
3462 mutex_unlock(&ar->conf_mutex);
3463
3464 return 0;
3465}
3466
3467/*
3468 * Both RTS and Fragmentation threshold are interface-specific
3469 * in ath10k, but device-specific in mac80211.
3470 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003471
3472static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3473{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003474 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003475 struct ath10k_vif *arvif;
3476 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003477
Michal Kaziorad088bf2013-10-16 15:44:46 +03003478 mutex_lock(&ar->conf_mutex);
3479 list_for_each_entry(arvif, &ar->arvifs, list) {
3480 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3481 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003482
Michal Kaziorad088bf2013-10-16 15:44:46 +03003483 ret = ath10k_mac_set_rts(arvif, value);
3484 if (ret) {
3485 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3486 arvif->vdev_id, ret);
3487 break;
3488 }
3489 }
3490 mutex_unlock(&ar->conf_mutex);
3491
3492 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003493}
3494
3495static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3496{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003497 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003498 struct ath10k_vif *arvif;
3499 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500
Kalle Valo5e3dd152013-06-12 20:52:10 +03003501 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003502 list_for_each_entry(arvif, &ar->arvifs, list) {
3503 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3504 arvif->vdev_id, value);
3505
3506 ret = ath10k_mac_set_rts(arvif, value);
3507 if (ret) {
3508 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3509 arvif->vdev_id, ret);
3510 break;
3511 }
3512 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 mutex_unlock(&ar->conf_mutex);
3514
Michal Kaziorad088bf2013-10-16 15:44:46 +03003515 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516}
3517
3518static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3519{
3520 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003521 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003522 int ret;
3523
3524 /* mac80211 doesn't care if we really xmit queued frames or not
3525 * we'll collect those frames either way if we stop/delete vdevs */
3526 if (drop)
3527 return;
3528
Michal Kazior548db542013-07-05 16:15:15 +03003529 mutex_lock(&ar->conf_mutex);
3530
Michal Kazioraffd3212013-07-16 09:54:35 +02003531 if (ar->state == ATH10K_STATE_WEDGED)
3532 goto skip;
3533
Michal Kazioredb82362013-07-05 16:15:14 +03003534 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003535 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003536
Michal Kazioredb82362013-07-05 16:15:14 +03003537 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003538 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003539 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003540
3541 skip = (ar->state == ATH10K_STATE_WEDGED);
3542
3543 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003545
3546 if (ret <= 0 || skip)
Ben Greear9ba4c782014-02-25 09:29:57 +02003547 ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n",
3548 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003549
Michal Kazioraffd3212013-07-16 09:54:35 +02003550skip:
Michal Kazior548db542013-07-05 16:15:15 +03003551 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003552}
3553
3554/* TODO: Implement this function properly
3555 * For now it is needed to reply to Probe Requests in IBSS mode.
3556 * Propably we need this information from FW.
3557 */
3558static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3559{
3560 return 1;
3561}
3562
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003563#ifdef CONFIG_PM
3564static int ath10k_suspend(struct ieee80211_hw *hw,
3565 struct cfg80211_wowlan *wowlan)
3566{
3567 struct ath10k *ar = hw->priv;
3568 int ret;
3569
Marek Puzyniak9042e172014-02-10 17:14:23 +01003570 mutex_lock(&ar->conf_mutex);
3571
Marek Puzyniak00f54822014-02-10 17:14:24 +01003572 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003573 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003574 if (ret == -ETIMEDOUT)
3575 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003576 ret = 1;
3577 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003578 }
3579
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003580 ret = ath10k_hif_suspend(ar);
3581 if (ret) {
3582 ath10k_warn("could not suspend hif (%d)\n", ret);
3583 goto resume;
3584 }
3585
Marek Puzyniak9042e172014-02-10 17:14:23 +01003586 ret = 0;
3587 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003588resume:
3589 ret = ath10k_wmi_pdev_resume_target(ar);
3590 if (ret)
3591 ath10k_warn("could not resume target (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003592
3593 ret = 1;
3594exit:
3595 mutex_unlock(&ar->conf_mutex);
3596 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003597}
3598
3599static int ath10k_resume(struct ieee80211_hw *hw)
3600{
3601 struct ath10k *ar = hw->priv;
3602 int ret;
3603
Marek Puzyniak9042e172014-02-10 17:14:23 +01003604 mutex_lock(&ar->conf_mutex);
3605
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003606 ret = ath10k_hif_resume(ar);
3607 if (ret) {
3608 ath10k_warn("could not resume hif (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003609 ret = 1;
3610 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003611 }
3612
3613 ret = ath10k_wmi_pdev_resume_target(ar);
3614 if (ret) {
3615 ath10k_warn("could not resume target (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003616 ret = 1;
3617 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003618 }
3619
Marek Puzyniak9042e172014-02-10 17:14:23 +01003620 ret = 0;
3621exit:
3622 mutex_unlock(&ar->conf_mutex);
3623 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003624}
3625#endif
3626
Michal Kazioraffd3212013-07-16 09:54:35 +02003627static void ath10k_restart_complete(struct ieee80211_hw *hw)
3628{
3629 struct ath10k *ar = hw->priv;
3630
3631 mutex_lock(&ar->conf_mutex);
3632
3633 /* If device failed to restart it will be in a different state, e.g.
3634 * ATH10K_STATE_WEDGED */
3635 if (ar->state == ATH10K_STATE_RESTARTED) {
3636 ath10k_info("device successfully recovered\n");
3637 ar->state = ATH10K_STATE_ON;
3638 }
3639
3640 mutex_unlock(&ar->conf_mutex);
3641}
3642
Michal Kazior2e1dea42013-07-31 10:32:40 +02003643static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3644 struct survey_info *survey)
3645{
3646 struct ath10k *ar = hw->priv;
3647 struct ieee80211_supported_band *sband;
3648 struct survey_info *ar_survey = &ar->survey[idx];
3649 int ret = 0;
3650
3651 mutex_lock(&ar->conf_mutex);
3652
3653 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3654 if (sband && idx >= sband->n_channels) {
3655 idx -= sband->n_channels;
3656 sband = NULL;
3657 }
3658
3659 if (!sband)
3660 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3661
3662 if (!sband || idx >= sband->n_channels) {
3663 ret = -ENOENT;
3664 goto exit;
3665 }
3666
3667 spin_lock_bh(&ar->data_lock);
3668 memcpy(survey, ar_survey, sizeof(*survey));
3669 spin_unlock_bh(&ar->data_lock);
3670
3671 survey->channel = &sband->channels[idx];
3672
3673exit:
3674 mutex_unlock(&ar->conf_mutex);
3675 return ret;
3676}
3677
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003678/* Helper table for legacy fixed_rate/bitrate_mask */
3679static const u8 cck_ofdm_rate[] = {
3680 /* CCK */
3681 3, /* 1Mbps */
3682 2, /* 2Mbps */
3683 1, /* 5.5Mbps */
3684 0, /* 11Mbps */
3685 /* OFDM */
3686 3, /* 6Mbps */
3687 7, /* 9Mbps */
3688 2, /* 12Mbps */
3689 6, /* 18Mbps */
3690 1, /* 24Mbps */
3691 5, /* 36Mbps */
3692 0, /* 48Mbps */
3693 4, /* 54Mbps */
3694};
3695
3696/* Check if only one bit set */
3697static int ath10k_check_single_mask(u32 mask)
3698{
3699 int bit;
3700
3701 bit = ffs(mask);
3702 if (!bit)
3703 return 0;
3704
3705 mask &= ~BIT(bit - 1);
3706 if (mask)
3707 return 2;
3708
3709 return 1;
3710}
3711
3712static bool
3713ath10k_default_bitrate_mask(struct ath10k *ar,
3714 enum ieee80211_band band,
3715 const struct cfg80211_bitrate_mask *mask)
3716{
3717 u32 legacy = 0x00ff;
3718 u8 ht = 0xff, i;
3719 u16 vht = 0x3ff;
3720
3721 switch (band) {
3722 case IEEE80211_BAND_2GHZ:
3723 legacy = 0x00fff;
3724 vht = 0;
3725 break;
3726 case IEEE80211_BAND_5GHZ:
3727 break;
3728 default:
3729 return false;
3730 }
3731
3732 if (mask->control[band].legacy != legacy)
3733 return false;
3734
3735 for (i = 0; i < ar->num_rf_chains; i++)
3736 if (mask->control[band].ht_mcs[i] != ht)
3737 return false;
3738
3739 for (i = 0; i < ar->num_rf_chains; i++)
3740 if (mask->control[band].vht_mcs[i] != vht)
3741 return false;
3742
3743 return true;
3744}
3745
3746static bool
3747ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3748 enum ieee80211_band band,
3749 u8 *fixed_nss)
3750{
3751 int ht_nss = 0, vht_nss = 0, i;
3752
3753 /* check legacy */
3754 if (ath10k_check_single_mask(mask->control[band].legacy))
3755 return false;
3756
3757 /* check HT */
3758 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3759 if (mask->control[band].ht_mcs[i] == 0xff)
3760 continue;
3761 else if (mask->control[band].ht_mcs[i] == 0x00)
3762 break;
3763 else
3764 return false;
3765 }
3766
3767 ht_nss = i;
3768
3769 /* check VHT */
3770 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3771 if (mask->control[band].vht_mcs[i] == 0x03ff)
3772 continue;
3773 else if (mask->control[band].vht_mcs[i] == 0x0000)
3774 break;
3775 else
3776 return false;
3777 }
3778
3779 vht_nss = i;
3780
3781 if (ht_nss > 0 && vht_nss > 0)
3782 return false;
3783
3784 if (ht_nss)
3785 *fixed_nss = ht_nss;
3786 else if (vht_nss)
3787 *fixed_nss = vht_nss;
3788 else
3789 return false;
3790
3791 return true;
3792}
3793
3794static bool
3795ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3796 enum ieee80211_band band,
3797 enum wmi_rate_preamble *preamble)
3798{
3799 int legacy = 0, ht = 0, vht = 0, i;
3800
3801 *preamble = WMI_RATE_PREAMBLE_OFDM;
3802
3803 /* check legacy */
3804 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3805 if (legacy > 1)
3806 return false;
3807
3808 /* check HT */
3809 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3810 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3811 if (ht > 1)
3812 return false;
3813
3814 /* check VHT */
3815 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3816 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3817 if (vht > 1)
3818 return false;
3819
3820 /* Currently we support only one fixed_rate */
3821 if ((legacy + ht + vht) != 1)
3822 return false;
3823
3824 if (ht)
3825 *preamble = WMI_RATE_PREAMBLE_HT;
3826 else if (vht)
3827 *preamble = WMI_RATE_PREAMBLE_VHT;
3828
3829 return true;
3830}
3831
3832static bool
3833ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3834 enum ieee80211_band band,
3835 u8 *fixed_rate,
3836 u8 *fixed_nss)
3837{
3838 u8 rate = 0, pream = 0, nss = 0, i;
3839 enum wmi_rate_preamble preamble;
3840
3841 /* Check if single rate correct */
3842 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3843 return false;
3844
3845 pream = preamble;
3846
3847 switch (preamble) {
3848 case WMI_RATE_PREAMBLE_CCK:
3849 case WMI_RATE_PREAMBLE_OFDM:
3850 i = ffs(mask->control[band].legacy) - 1;
3851
3852 if (band == IEEE80211_BAND_2GHZ && i < 4)
3853 pream = WMI_RATE_PREAMBLE_CCK;
3854
3855 if (band == IEEE80211_BAND_5GHZ)
3856 i += 4;
3857
3858 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3859 return false;
3860
3861 rate = cck_ofdm_rate[i];
3862 break;
3863 case WMI_RATE_PREAMBLE_HT:
3864 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3865 if (mask->control[band].ht_mcs[i])
3866 break;
3867
3868 if (i == IEEE80211_HT_MCS_MASK_LEN)
3869 return false;
3870
3871 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3872 nss = i;
3873 break;
3874 case WMI_RATE_PREAMBLE_VHT:
3875 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3876 if (mask->control[band].vht_mcs[i])
3877 break;
3878
3879 if (i == NL80211_VHT_NSS_MAX)
3880 return false;
3881
3882 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3883 nss = i;
3884 break;
3885 }
3886
3887 *fixed_nss = nss + 1;
3888 nss <<= 4;
3889 pream <<= 6;
3890
3891 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3892 pream, nss, rate);
3893
3894 *fixed_rate = pream | nss | rate;
3895
3896 return true;
3897}
3898
3899static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3900 enum ieee80211_band band,
3901 u8 *fixed_rate,
3902 u8 *fixed_nss)
3903{
3904 /* First check full NSS mask, if we can simply limit NSS */
3905 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3906 return true;
3907
3908 /* Next Check single rate is set */
3909 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3910}
3911
3912static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3913 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003914 u8 fixed_nss,
3915 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003916{
3917 struct ath10k *ar = arvif->ar;
3918 u32 vdev_param;
3919 int ret = 0;
3920
3921 mutex_lock(&ar->conf_mutex);
3922
3923 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003924 arvif->fixed_nss == fixed_nss &&
3925 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003926 goto exit;
3927
3928 if (fixed_rate == WMI_FIXED_RATE_NONE)
3929 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3930
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003931 if (force_sgi)
3932 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
3933
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003934 vdev_param = ar->wmi.vdev_param->fixed_rate;
3935 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3936 vdev_param, fixed_rate);
3937 if (ret) {
3938 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3939 fixed_rate, ret);
3940 ret = -EINVAL;
3941 goto exit;
3942 }
3943
3944 arvif->fixed_rate = fixed_rate;
3945
3946 vdev_param = ar->wmi.vdev_param->nss;
3947 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3948 vdev_param, fixed_nss);
3949
3950 if (ret) {
3951 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3952 fixed_nss, ret);
3953 ret = -EINVAL;
3954 goto exit;
3955 }
3956
3957 arvif->fixed_nss = fixed_nss;
3958
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003959 vdev_param = ar->wmi.vdev_param->sgi;
3960 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3961 force_sgi);
3962
3963 if (ret) {
3964 ath10k_warn("Could not set sgi param %d: %d\n",
3965 force_sgi, ret);
3966 ret = -EINVAL;
3967 goto exit;
3968 }
3969
3970 arvif->force_sgi = force_sgi;
3971
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003972exit:
3973 mutex_unlock(&ar->conf_mutex);
3974 return ret;
3975}
3976
3977static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3978 struct ieee80211_vif *vif,
3979 const struct cfg80211_bitrate_mask *mask)
3980{
3981 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3982 struct ath10k *ar = arvif->ar;
3983 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3984 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3985 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003986 u8 force_sgi;
3987
3988 force_sgi = mask->control[band].gi;
3989 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
3990 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003991
3992 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3993 if (!ath10k_get_fixed_rate_nss(mask, band,
3994 &fixed_rate,
3995 &fixed_nss))
3996 return -EINVAL;
3997 }
3998
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003999 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4000 ath10k_warn("Could not force SGI usage for default rate settings\n");
4001 return -EINVAL;
4002 }
4003
4004 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4005 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004006}
4007
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004008static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
4009 struct ieee80211_vif *vif,
4010 struct cfg80211_chan_def *chandef)
4011{
4012 /* there's no need to do anything here. vif->csa_active is enough */
4013 return;
4014}
4015
Michal Kazior9797feb2014-02-14 14:49:48 +01004016static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4017 struct ieee80211_vif *vif,
4018 struct ieee80211_sta *sta,
4019 u32 changed)
4020{
4021 struct ath10k *ar = hw->priv;
4022 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4023 u32 bw, smps;
4024
4025 spin_lock_bh(&ar->data_lock);
4026
4027 ath10k_dbg(ATH10K_DBG_MAC,
4028 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4029 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4030 sta->smps_mode);
4031
4032 if (changed & IEEE80211_RC_BW_CHANGED) {
4033 bw = WMI_PEER_CHWIDTH_20MHZ;
4034
4035 switch (sta->bandwidth) {
4036 case IEEE80211_STA_RX_BW_20:
4037 bw = WMI_PEER_CHWIDTH_20MHZ;
4038 break;
4039 case IEEE80211_STA_RX_BW_40:
4040 bw = WMI_PEER_CHWIDTH_40MHZ;
4041 break;
4042 case IEEE80211_STA_RX_BW_80:
4043 bw = WMI_PEER_CHWIDTH_80MHZ;
4044 break;
4045 case IEEE80211_STA_RX_BW_160:
4046 ath10k_warn("mac sta rc update for %pM: invalid bw %d\n",
4047 sta->addr, sta->bandwidth);
4048 bw = WMI_PEER_CHWIDTH_20MHZ;
4049 break;
4050 }
4051
4052 arsta->bw = bw;
4053 }
4054
4055 if (changed & IEEE80211_RC_NSS_CHANGED)
4056 arsta->nss = sta->rx_nss;
4057
4058 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4059 smps = WMI_PEER_SMPS_PS_NONE;
4060
4061 switch (sta->smps_mode) {
4062 case IEEE80211_SMPS_AUTOMATIC:
4063 case IEEE80211_SMPS_OFF:
4064 smps = WMI_PEER_SMPS_PS_NONE;
4065 break;
4066 case IEEE80211_SMPS_STATIC:
4067 smps = WMI_PEER_SMPS_STATIC;
4068 break;
4069 case IEEE80211_SMPS_DYNAMIC:
4070 smps = WMI_PEER_SMPS_DYNAMIC;
4071 break;
4072 case IEEE80211_SMPS_NUM_MODES:
4073 ath10k_warn("mac sta rc update for %pM: invalid smps: %d\n",
4074 sta->addr, sta->smps_mode);
4075 smps = WMI_PEER_SMPS_PS_NONE;
4076 break;
4077 }
4078
4079 arsta->smps = smps;
4080 }
4081
4082 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
4083 /* FIXME: Not implemented. Probably the only way to do it would
4084 * be to re-assoc the peer. */
4085 changed &= ~IEEE80211_RC_SUPP_RATES_CHANGED;
4086 ath10k_dbg(ATH10K_DBG_MAC,
4087 "mac sta rc update for %pM: changing supported rates not implemented\n",
4088 sta->addr);
4089 }
4090
4091 arsta->changed |= changed;
4092
4093 spin_unlock_bh(&ar->data_lock);
4094
4095 ieee80211_queue_work(hw, &arsta->update_wk);
4096}
4097
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004098static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4099{
4100 /*
4101 * FIXME: Return 0 for time being. Need to figure out whether FW
4102 * has the API to fetch 64-bit local TSF
4103 */
4104
4105 return 0;
4106}
4107
Kalle Valo5e3dd152013-06-12 20:52:10 +03004108static const struct ieee80211_ops ath10k_ops = {
4109 .tx = ath10k_tx,
4110 .start = ath10k_start,
4111 .stop = ath10k_stop,
4112 .config = ath10k_config,
4113 .add_interface = ath10k_add_interface,
4114 .remove_interface = ath10k_remove_interface,
4115 .configure_filter = ath10k_configure_filter,
4116 .bss_info_changed = ath10k_bss_info_changed,
4117 .hw_scan = ath10k_hw_scan,
4118 .cancel_hw_scan = ath10k_cancel_hw_scan,
4119 .set_key = ath10k_set_key,
4120 .sta_state = ath10k_sta_state,
4121 .conf_tx = ath10k_conf_tx,
4122 .remain_on_channel = ath10k_remain_on_channel,
4123 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4124 .set_rts_threshold = ath10k_set_rts_threshold,
4125 .set_frag_threshold = ath10k_set_frag_threshold,
4126 .flush = ath10k_flush,
4127 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02004128 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004129 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004130 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004131 .channel_switch_beacon = ath10k_channel_switch_beacon,
Michal Kazior9797feb2014-02-14 14:49:48 +01004132 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004133 .get_tsf = ath10k_get_tsf,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004134#ifdef CONFIG_PM
4135 .suspend = ath10k_suspend,
4136 .resume = ath10k_resume,
4137#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004138};
4139
4140#define RATETAB_ENT(_rate, _rateid, _flags) { \
4141 .bitrate = (_rate), \
4142 .flags = (_flags), \
4143 .hw_value = (_rateid), \
4144}
4145
4146#define CHAN2G(_channel, _freq, _flags) { \
4147 .band = IEEE80211_BAND_2GHZ, \
4148 .hw_value = (_channel), \
4149 .center_freq = (_freq), \
4150 .flags = (_flags), \
4151 .max_antenna_gain = 0, \
4152 .max_power = 30, \
4153}
4154
4155#define CHAN5G(_channel, _freq, _flags) { \
4156 .band = IEEE80211_BAND_5GHZ, \
4157 .hw_value = (_channel), \
4158 .center_freq = (_freq), \
4159 .flags = (_flags), \
4160 .max_antenna_gain = 0, \
4161 .max_power = 30, \
4162}
4163
4164static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4165 CHAN2G(1, 2412, 0),
4166 CHAN2G(2, 2417, 0),
4167 CHAN2G(3, 2422, 0),
4168 CHAN2G(4, 2427, 0),
4169 CHAN2G(5, 2432, 0),
4170 CHAN2G(6, 2437, 0),
4171 CHAN2G(7, 2442, 0),
4172 CHAN2G(8, 2447, 0),
4173 CHAN2G(9, 2452, 0),
4174 CHAN2G(10, 2457, 0),
4175 CHAN2G(11, 2462, 0),
4176 CHAN2G(12, 2467, 0),
4177 CHAN2G(13, 2472, 0),
4178 CHAN2G(14, 2484, 0),
4179};
4180
4181static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004182 CHAN5G(36, 5180, 0),
4183 CHAN5G(40, 5200, 0),
4184 CHAN5G(44, 5220, 0),
4185 CHAN5G(48, 5240, 0),
4186 CHAN5G(52, 5260, 0),
4187 CHAN5G(56, 5280, 0),
4188 CHAN5G(60, 5300, 0),
4189 CHAN5G(64, 5320, 0),
4190 CHAN5G(100, 5500, 0),
4191 CHAN5G(104, 5520, 0),
4192 CHAN5G(108, 5540, 0),
4193 CHAN5G(112, 5560, 0),
4194 CHAN5G(116, 5580, 0),
4195 CHAN5G(120, 5600, 0),
4196 CHAN5G(124, 5620, 0),
4197 CHAN5G(128, 5640, 0),
4198 CHAN5G(132, 5660, 0),
4199 CHAN5G(136, 5680, 0),
4200 CHAN5G(140, 5700, 0),
4201 CHAN5G(149, 5745, 0),
4202 CHAN5G(153, 5765, 0),
4203 CHAN5G(157, 5785, 0),
4204 CHAN5G(161, 5805, 0),
4205 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004206};
4207
4208static struct ieee80211_rate ath10k_rates[] = {
4209 /* CCK */
4210 RATETAB_ENT(10, 0x82, 0),
4211 RATETAB_ENT(20, 0x84, 0),
4212 RATETAB_ENT(55, 0x8b, 0),
4213 RATETAB_ENT(110, 0x96, 0),
4214 /* OFDM */
4215 RATETAB_ENT(60, 0x0c, 0),
4216 RATETAB_ENT(90, 0x12, 0),
4217 RATETAB_ENT(120, 0x18, 0),
4218 RATETAB_ENT(180, 0x24, 0),
4219 RATETAB_ENT(240, 0x30, 0),
4220 RATETAB_ENT(360, 0x48, 0),
4221 RATETAB_ENT(480, 0x60, 0),
4222 RATETAB_ENT(540, 0x6c, 0),
4223};
4224
4225#define ath10k_a_rates (ath10k_rates + 4)
4226#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4227#define ath10k_g_rates (ath10k_rates + 0)
4228#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4229
4230struct ath10k *ath10k_mac_create(void)
4231{
4232 struct ieee80211_hw *hw;
4233 struct ath10k *ar;
4234
4235 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4236 if (!hw)
4237 return NULL;
4238
4239 ar = hw->priv;
4240 ar->hw = hw;
4241
4242 return ar;
4243}
4244
4245void ath10k_mac_destroy(struct ath10k *ar)
4246{
4247 ieee80211_free_hw(ar->hw);
4248}
4249
4250static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4251 {
4252 .max = 8,
4253 .types = BIT(NL80211_IFTYPE_STATION)
4254 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004255 },
4256 {
4257 .max = 3,
4258 .types = BIT(NL80211_IFTYPE_P2P_GO)
4259 },
4260 {
4261 .max = 7,
4262 .types = BIT(NL80211_IFTYPE_AP)
4263 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004264};
4265
Bartosz Markowskif2595092013-12-10 16:20:39 +01004266static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004267 {
4268 .max = 8,
4269 .types = BIT(NL80211_IFTYPE_AP)
4270 },
4271};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004272
4273static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4274 {
4275 .limits = ath10k_if_limits,
4276 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4277 .max_interfaces = 8,
4278 .num_different_channels = 1,
4279 .beacon_int_infra_match = true,
4280 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004281};
4282
4283static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004284 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004285 .limits = ath10k_10x_if_limits,
4286 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004287 .max_interfaces = 8,
4288 .num_different_channels = 1,
4289 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004290#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004291 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4292 BIT(NL80211_CHAN_WIDTH_20) |
4293 BIT(NL80211_CHAN_WIDTH_40) |
4294 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004295#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004296 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004297};
4298
4299static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4300{
4301 struct ieee80211_sta_vht_cap vht_cap = {0};
4302 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004303 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304
4305 vht_cap.vht_supported = 1;
4306 vht_cap.cap = ar->vht_cap_info;
4307
Michal Kazior8865bee42013-07-24 12:36:46 +02004308 mcs_map = 0;
4309 for (i = 0; i < 8; i++) {
4310 if (i < ar->num_rf_chains)
4311 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4312 else
4313 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4314 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004315
4316 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4317 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4318
4319 return vht_cap;
4320}
4321
4322static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4323{
4324 int i;
4325 struct ieee80211_sta_ht_cap ht_cap = {0};
4326
4327 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4328 return ht_cap;
4329
4330 ht_cap.ht_supported = 1;
4331 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4332 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4333 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4334 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4335 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4336
4337 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4338 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4339
4340 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4341 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4342
4343 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4344 u32 smps;
4345
4346 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4347 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4348
4349 ht_cap.cap |= smps;
4350 }
4351
4352 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4353 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4354
4355 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4356 u32 stbc;
4357
4358 stbc = ar->ht_cap_info;
4359 stbc &= WMI_HT_CAP_RX_STBC;
4360 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4361 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4362 stbc &= IEEE80211_HT_CAP_RX_STBC;
4363
4364 ht_cap.cap |= stbc;
4365 }
4366
4367 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4368 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4369
4370 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4371 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4372
4373 /* max AMSDU is implicitly taken from vht_cap_info */
4374 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4375 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4376
Michal Kazior8865bee42013-07-24 12:36:46 +02004377 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004378 ht_cap.mcs.rx_mask[i] = 0xFF;
4379
4380 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4381
4382 return ht_cap;
4383}
4384
4385
4386static void ath10k_get_arvif_iter(void *data, u8 *mac,
4387 struct ieee80211_vif *vif)
4388{
4389 struct ath10k_vif_iter *arvif_iter = data;
4390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4391
4392 if (arvif->vdev_id == arvif_iter->vdev_id)
4393 arvif_iter->arvif = arvif;
4394}
4395
4396struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4397{
4398 struct ath10k_vif_iter arvif_iter;
4399 u32 flags;
4400
4401 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4402 arvif_iter.vdev_id = vdev_id;
4403
4404 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4405 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4406 flags,
4407 ath10k_get_arvif_iter,
4408 &arvif_iter);
4409 if (!arvif_iter.arvif) {
4410 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
4411 return NULL;
4412 }
4413
4414 return arvif_iter.arvif;
4415}
4416
4417int ath10k_mac_register(struct ath10k *ar)
4418{
4419 struct ieee80211_supported_band *band;
4420 struct ieee80211_sta_vht_cap vht_cap;
4421 struct ieee80211_sta_ht_cap ht_cap;
4422 void *channels;
4423 int ret;
4424
4425 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4426
4427 SET_IEEE80211_DEV(ar->hw, ar->dev);
4428
4429 ht_cap = ath10k_get_ht_cap(ar);
4430 vht_cap = ath10k_create_vht_cap(ar);
4431
4432 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4433 channels = kmemdup(ath10k_2ghz_channels,
4434 sizeof(ath10k_2ghz_channels),
4435 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004436 if (!channels) {
4437 ret = -ENOMEM;
4438 goto err_free;
4439 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004440
4441 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4442 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4443 band->channels = channels;
4444 band->n_bitrates = ath10k_g_rates_size;
4445 band->bitrates = ath10k_g_rates;
4446 band->ht_cap = ht_cap;
4447
4448 /* vht is not supported in 2.4 GHz */
4449
4450 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4451 }
4452
4453 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4454 channels = kmemdup(ath10k_5ghz_channels,
4455 sizeof(ath10k_5ghz_channels),
4456 GFP_KERNEL);
4457 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004458 ret = -ENOMEM;
4459 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004460 }
4461
4462 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4463 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4464 band->channels = channels;
4465 band->n_bitrates = ath10k_a_rates_size;
4466 band->bitrates = ath10k_a_rates;
4467 band->ht_cap = ht_cap;
4468 band->vht_cap = vht_cap;
4469 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4470 }
4471
4472 ar->hw->wiphy->interface_modes =
4473 BIT(NL80211_IFTYPE_STATION) |
4474 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004475 BIT(NL80211_IFTYPE_AP);
4476
4477 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4478 ar->hw->wiphy->interface_modes |=
4479 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4480 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004481
4482 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4483 IEEE80211_HW_SUPPORTS_PS |
4484 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4485 IEEE80211_HW_SUPPORTS_UAPSD |
4486 IEEE80211_HW_MFP_CAPABLE |
4487 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4488 IEEE80211_HW_HAS_RATE_CONTROL |
4489 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4490 IEEE80211_HW_WANT_MONITOR_VIF |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004491 IEEE80211_HW_AP_LINK_PS |
4492 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004493
Michal Kazior1f8bb152013-09-18 14:43:22 +02004494 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4495 * bytes is used for padding/alignment if necessary. */
4496 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4497
Kalle Valo5e3dd152013-06-12 20:52:10 +03004498 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4499 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4500
4501 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4502 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4503 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4504 }
4505
4506 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4507 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4508
4509 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004510 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004511
Kalle Valo5e3dd152013-06-12 20:52:10 +03004512 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4513
4514 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004515 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004516 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4517
4518 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4519 /*
4520 * on LL hardware queues are managed entirely by the FW
4521 * so we only advertise to mac we can do the queues thing
4522 */
4523 ar->hw->queues = 4;
4524
Bartosz Markowskif2595092013-12-10 16:20:39 +01004525 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4526 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4527 ar->hw->wiphy->n_iface_combinations =
4528 ARRAY_SIZE(ath10k_10x_if_comb);
4529 } else {
4530 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4531 ar->hw->wiphy->n_iface_combinations =
4532 ARRAY_SIZE(ath10k_if_comb);
4533 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004534
Michal Kazior7c199992013-07-31 10:47:57 +02004535 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4536
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004537 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4538 /* Init ath dfs pattern detector */
4539 ar->ath_common.debug_mask = ATH_DBG_DFS;
4540 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4541 NL80211_DFS_UNSET);
4542
4543 if (!ar->dfs_detector)
4544 ath10k_warn("dfs pattern detector init failed\n");
4545 }
4546
Kalle Valo5e3dd152013-06-12 20:52:10 +03004547 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4548 ath10k_reg_notifier);
4549 if (ret) {
4550 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02004551 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004552 }
4553
4554 ret = ieee80211_register_hw(ar->hw);
4555 if (ret) {
4556 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004557 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004558 }
4559
4560 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4561 ret = regulatory_hint(ar->hw->wiphy,
4562 ar->ath_common.regulatory.alpha2);
4563 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004564 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004565 }
4566
4567 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004568
4569err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004570 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004571err_free:
4572 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4573 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4574
Kalle Valo5e3dd152013-06-12 20:52:10 +03004575 return ret;
4576}
4577
4578void ath10k_mac_unregister(struct ath10k *ar)
4579{
4580 ieee80211_unregister_hw(ar->hw);
4581
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004582 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4583 ar->dfs_detector->exit(ar->dfs_detector);
4584
Kalle Valo5e3dd152013-06-12 20:52:10 +03004585 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4586 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4587
4588 SET_IEEE80211_DEV(ar->hw, NULL);
4589}