blob: 8fe451796fdea5a4c1e26de3a798170098ca608e [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
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840 return;
841 }
842
843 arvif->tx_seq_no = 0x1000;
844
845 ret = ath10k_vdev_start(arvif);
846 if (ret)
847 return;
848
Michal Kaziorc930f742014-01-23 11:38:25 +0100849 arvif->aid = 0;
850 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
851
852 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
853 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854 if (ret) {
855 ath10k_warn("Failed to bring up VDEV: %d\n",
856 arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +0100857 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300858 return;
859 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100860
861 arvif->is_started = true;
862 arvif->is_up = true;
863
Kalle Valo60c3daa2013-09-08 17:56:07 +0300864 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300865}
866
867static void ath10k_control_ibss(struct ath10k_vif *arvif,
868 struct ieee80211_bss_conf *info,
869 const u8 self_peer[ETH_ALEN])
870{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200871 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300872 int ret = 0;
873
Michal Kazior548db542013-07-05 16:15:15 +0300874 lockdep_assert_held(&arvif->ar->conf_mutex);
875
Kalle Valo5e3dd152013-06-12 20:52:10 +0300876 if (!info->ibss_joined) {
877 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
878 if (ret)
879 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
880 self_peer, arvif->vdev_id, ret);
881
Michal Kaziorc930f742014-01-23 11:38:25 +0100882 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300883 return;
884
885 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100886 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300887 if (ret) {
888 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100889 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300890 return;
891 }
892
Michal Kaziorc930f742014-01-23 11:38:25 +0100893 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300894
895 return;
896 }
897
898 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
899 if (ret) {
900 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
901 self_peer, arvif->vdev_id, ret);
902 return;
903 }
904
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200905 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
906 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907 ATH10K_DEFAULT_ATIM);
908 if (ret)
909 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
910 arvif->vdev_id, ret);
911}
912
913/*
914 * Review this when mac80211 gains per-interface powersave support.
915 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300916static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300918 struct ath10k *ar = arvif->ar;
919 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 enum wmi_sta_powersave_param param;
921 enum wmi_sta_ps_mode psmode;
922 int ret;
923
Michal Kazior548db542013-07-05 16:15:15 +0300924 lockdep_assert_held(&arvif->ar->conf_mutex);
925
Michal Kaziorad088bf2013-10-16 15:44:46 +0300926 if (arvif->vif->type != NL80211_IFTYPE_STATION)
927 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928
929 if (conf->flags & IEEE80211_CONF_PS) {
930 psmode = WMI_STA_PS_MODE_ENABLED;
931 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
932
Michal Kaziorad088bf2013-10-16 15:44:46 +0300933 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300934 conf->dynamic_ps_timeout);
935 if (ret) {
936 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
937 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300938 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300939 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300940 } else {
941 psmode = WMI_STA_PS_MODE_DISABLED;
942 }
943
Kalle Valo60c3daa2013-09-08 17:56:07 +0300944 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
945 arvif->vdev_id, psmode ? "enable" : "disable");
946
Michal Kaziorad088bf2013-10-16 15:44:46 +0300947 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
948 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
950 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300951 return ret;
952 }
953
954 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955}
956
957/**********************/
958/* Station management */
959/**********************/
960
961static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
962 struct ath10k_vif *arvif,
963 struct ieee80211_sta *sta,
964 struct ieee80211_bss_conf *bss_conf,
965 struct wmi_peer_assoc_complete_arg *arg)
966{
Michal Kazior548db542013-07-05 16:15:15 +0300967 lockdep_assert_held(&ar->conf_mutex);
968
Kalle Valo5e3dd152013-06-12 20:52:10 +0300969 memcpy(arg->addr, sta->addr, ETH_ALEN);
970 arg->vdev_id = arvif->vdev_id;
971 arg->peer_aid = sta->aid;
972 arg->peer_flags |= WMI_PEER_AUTH;
973
974 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
975 /*
976 * Seems FW have problems with Power Save in STA
977 * mode when we setup this parameter to high (eg. 5).
978 * Often we see that FW don't send NULL (with clean P flags)
979 * frame even there is info about buffered frames in beacons.
980 * Sometimes we have to wait more than 10 seconds before FW
981 * will wakeup. Often sending one ping from AP to our device
982 * just fail (more than 50%).
983 *
984 * Seems setting this FW parameter to 1 couse FW
985 * will check every beacon and will wakup immediately
986 * after detection buffered data.
987 */
988 arg->peer_listen_intval = 1;
989 else
990 arg->peer_listen_intval = ar->hw->conf.listen_interval;
991
992 arg->peer_num_spatial_streams = 1;
993
994 /*
995 * The assoc capabilities are available only in managed mode.
996 */
997 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
998 arg->peer_caps = bss_conf->assoc_capability;
999}
1000
1001static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1002 struct ath10k_vif *arvif,
1003 struct wmi_peer_assoc_complete_arg *arg)
1004{
1005 struct ieee80211_vif *vif = arvif->vif;
1006 struct ieee80211_bss_conf *info = &vif->bss_conf;
1007 struct cfg80211_bss *bss;
1008 const u8 *rsnie = NULL;
1009 const u8 *wpaie = NULL;
1010
Michal Kazior548db542013-07-05 16:15:15 +03001011 lockdep_assert_held(&ar->conf_mutex);
1012
Kalle Valo5e3dd152013-06-12 20:52:10 +03001013 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1014 info->bssid, NULL, 0, 0, 0);
1015 if (bss) {
1016 const struct cfg80211_bss_ies *ies;
1017
1018 rcu_read_lock();
1019 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1020
1021 ies = rcu_dereference(bss->ies);
1022
1023 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1024 WLAN_OUI_TYPE_MICROSOFT_WPA,
1025 ies->data,
1026 ies->len);
1027 rcu_read_unlock();
1028 cfg80211_put_bss(ar->hw->wiphy, bss);
1029 }
1030
1031 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1032 if (rsnie || wpaie) {
1033 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1034 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1035 }
1036
1037 if (wpaie) {
1038 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1039 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1040 }
1041}
1042
1043static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1044 struct ieee80211_sta *sta,
1045 struct wmi_peer_assoc_complete_arg *arg)
1046{
1047 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1048 const struct ieee80211_supported_band *sband;
1049 const struct ieee80211_rate *rates;
1050 u32 ratemask;
1051 int i;
1052
Michal Kazior548db542013-07-05 16:15:15 +03001053 lockdep_assert_held(&ar->conf_mutex);
1054
Kalle Valo5e3dd152013-06-12 20:52:10 +03001055 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1056 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1057 rates = sband->bitrates;
1058
1059 rateset->num_rates = 0;
1060
1061 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1062 if (!(ratemask & 1))
1063 continue;
1064
1065 rateset->rates[rateset->num_rates] = rates->hw_value;
1066 rateset->num_rates++;
1067 }
1068}
1069
1070static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1071 struct ieee80211_sta *sta,
1072 struct wmi_peer_assoc_complete_arg *arg)
1073{
1074 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1075 int smps;
1076 int i, n;
1077
Michal Kazior548db542013-07-05 16:15:15 +03001078 lockdep_assert_held(&ar->conf_mutex);
1079
Kalle Valo5e3dd152013-06-12 20:52:10 +03001080 if (!ht_cap->ht_supported)
1081 return;
1082
1083 arg->peer_flags |= WMI_PEER_HT;
1084 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1085 ht_cap->ampdu_factor)) - 1;
1086
1087 arg->peer_mpdu_density =
1088 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1089
1090 arg->peer_ht_caps = ht_cap->cap;
1091 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1092
1093 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1094 arg->peer_flags |= WMI_PEER_LDPC;
1095
1096 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1097 arg->peer_flags |= WMI_PEER_40MHZ;
1098 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1099 }
1100
1101 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1102 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1103
1104 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1105 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1106
1107 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1108 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1109 arg->peer_flags |= WMI_PEER_STBC;
1110 }
1111
1112 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1113 u32 stbc;
1114 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1115 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1116 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1117 arg->peer_rate_caps |= stbc;
1118 arg->peer_flags |= WMI_PEER_STBC;
1119 }
1120
1121 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1122 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1123
1124 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1125 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1126 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1127 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1128 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1129 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1130 }
1131
1132 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
1141 arg->peer_ht_rates.num_rates = n;
1142 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
1143
Kalle Valo60c3daa2013-09-08 17:56:07 +03001144 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1145 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001146 arg->peer_ht_rates.num_rates,
1147 arg->peer_num_spatial_streams);
1148}
1149
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001150static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1151 struct ath10k_vif *arvif,
1152 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001153{
1154 u32 uapsd = 0;
1155 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001156 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001157
Michal Kazior548db542013-07-05 16:15:15 +03001158 lockdep_assert_held(&ar->conf_mutex);
1159
Kalle Valo5e3dd152013-06-12 20:52:10 +03001160 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001161 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162 sta->uapsd_queues, sta->max_sp);
1163
Kalle Valo5e3dd152013-06-12 20:52:10 +03001164 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1165 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1166 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1167 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1168 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1169 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1170 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1171 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1172 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1173 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1174 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1175 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1176
1177
1178 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1179 max_sp = sta->max_sp;
1180
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001181 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1182 sta->addr,
1183 WMI_AP_PS_PEER_PARAM_UAPSD,
1184 uapsd);
1185 if (ret) {
1186 ath10k_warn("failed to set ap ps peer param uapsd: %d\n",
1187 ret);
1188 return ret;
1189 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001190
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001191 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1192 sta->addr,
1193 WMI_AP_PS_PEER_PARAM_MAX_SP,
1194 max_sp);
1195 if (ret) {
1196 ath10k_warn("failed to set ap ps peer param max sp: %d\n",
1197 ret);
1198 return ret;
1199 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001200
1201 /* TODO setup this based on STA listen interval and
1202 beacon interval. Currently we don't know
1203 sta->listen_interval - mac80211 patch required.
1204 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001205 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1206 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1207 if (ret) {
1208 ath10k_warn("failed to set ap ps peer param ageout time: %d\n",
1209 ret);
1210 return ret;
1211 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001212 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001213
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001214 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001215}
1216
1217static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1218 struct ieee80211_sta *sta,
1219 struct wmi_peer_assoc_complete_arg *arg)
1220{
1221 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001222 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001223
1224 if (!vht_cap->vht_supported)
1225 return;
1226
1227 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228 arg->peer_vht_caps = vht_cap->cap;
1229
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001230
1231 ampdu_factor = (vht_cap->cap &
1232 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1233 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1234
1235 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1236 * zero in VHT IE. Using it would result in degraded throughput.
1237 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1238 * it if VHT max_mpdu is smaller. */
1239 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1240 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1241 ampdu_factor)) - 1);
1242
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1244 arg->peer_flags |= WMI_PEER_80MHZ;
1245
1246 arg->peer_vht_rates.rx_max_rate =
1247 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1248 arg->peer_vht_rates.rx_mcs_set =
1249 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1250 arg->peer_vht_rates.tx_max_rate =
1251 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1252 arg->peer_vht_rates.tx_mcs_set =
1253 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1254
Kalle Valo60c3daa2013-09-08 17:56:07 +03001255 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1256 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001257}
1258
1259static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1260 struct ath10k_vif *arvif,
1261 struct ieee80211_sta *sta,
1262 struct ieee80211_bss_conf *bss_conf,
1263 struct wmi_peer_assoc_complete_arg *arg)
1264{
1265 switch (arvif->vdev_type) {
1266 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001267 if (sta->wme)
1268 arg->peer_flags |= WMI_PEER_QOS;
1269
1270 if (sta->wme && sta->uapsd_queues) {
1271 arg->peer_flags |= WMI_PEER_APSD;
1272 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1273 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001274 break;
1275 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001276 if (bss_conf->qos)
1277 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001278 break;
1279 default:
1280 break;
1281 }
1282}
1283
1284static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1285 struct ath10k_vif *arvif,
1286 struct ieee80211_sta *sta,
1287 struct wmi_peer_assoc_complete_arg *arg)
1288{
1289 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1290
Kalle Valo5e3dd152013-06-12 20:52:10 +03001291 switch (ar->hw->conf.chandef.chan->band) {
1292 case IEEE80211_BAND_2GHZ:
1293 if (sta->ht_cap.ht_supported) {
1294 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1295 phymode = MODE_11NG_HT40;
1296 else
1297 phymode = MODE_11NG_HT20;
1298 } else {
1299 phymode = MODE_11G;
1300 }
1301
1302 break;
1303 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001304 /*
1305 * Check VHT first.
1306 */
1307 if (sta->vht_cap.vht_supported) {
1308 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1309 phymode = MODE_11AC_VHT80;
1310 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1311 phymode = MODE_11AC_VHT40;
1312 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1313 phymode = MODE_11AC_VHT20;
1314 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001315 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1316 phymode = MODE_11NA_HT40;
1317 else
1318 phymode = MODE_11NA_HT20;
1319 } else {
1320 phymode = MODE_11A;
1321 }
1322
1323 break;
1324 default:
1325 break;
1326 }
1327
Kalle Valo38a1d472013-09-08 17:56:14 +03001328 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1329 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001330
Kalle Valo5e3dd152013-06-12 20:52:10 +03001331 arg->peer_phymode = phymode;
1332 WARN_ON(phymode == MODE_UNKNOWN);
1333}
1334
Kalle Valob9ada652013-10-16 15:44:46 +03001335static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1336 struct ath10k_vif *arvif,
1337 struct ieee80211_sta *sta,
1338 struct ieee80211_bss_conf *bss_conf,
1339 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001340{
Michal Kazior548db542013-07-05 16:15:15 +03001341 lockdep_assert_held(&ar->conf_mutex);
1342
Kalle Valob9ada652013-10-16 15:44:46 +03001343 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344
Kalle Valob9ada652013-10-16 15:44:46 +03001345 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1346 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1347 ath10k_peer_assoc_h_rates(ar, sta, arg);
1348 ath10k_peer_assoc_h_ht(ar, sta, arg);
1349 ath10k_peer_assoc_h_vht(ar, sta, arg);
1350 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1351 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352
Kalle Valob9ada652013-10-16 15:44:46 +03001353 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001354}
1355
1356/* can be called only in mac80211 callbacks due to `key_count` usage */
1357static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1358 struct ieee80211_vif *vif,
1359 struct ieee80211_bss_conf *bss_conf)
1360{
1361 struct ath10k *ar = hw->priv;
1362 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001363 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364 struct ieee80211_sta *ap_sta;
1365 int ret;
1366
Michal Kazior548db542013-07-05 16:15:15 +03001367 lockdep_assert_held(&ar->conf_mutex);
1368
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369 rcu_read_lock();
1370
1371 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1372 if (!ap_sta) {
1373 ath10k_warn("Failed to find station entry for %pM\n",
1374 bss_conf->bssid);
1375 rcu_read_unlock();
1376 return;
1377 }
1378
Kalle Valob9ada652013-10-16 15:44:46 +03001379 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1380 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001382 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1383 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 rcu_read_unlock();
1385 return;
1386 }
1387
1388 rcu_read_unlock();
1389
Kalle Valob9ada652013-10-16 15:44:46 +03001390 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1391 if (ret) {
1392 ath10k_warn("Peer assoc failed for %pM\n: %d",
1393 bss_conf->bssid, ret);
1394 return;
1395 }
1396
Kalle Valo60c3daa2013-09-08 17:56:07 +03001397 ath10k_dbg(ATH10K_DBG_MAC,
1398 "mac vdev %d up (associated) bssid %pM aid %d\n",
1399 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1400
Michal Kaziorc930f742014-01-23 11:38:25 +01001401 arvif->aid = bss_conf->aid;
1402 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1403
1404 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1405 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001406 ath10k_warn("VDEV: %d up failed: ret %d\n",
1407 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001408 return;
1409 }
1410
1411 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412}
1413
1414/*
1415 * FIXME: flush TIDs
1416 */
1417static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1418 struct ieee80211_vif *vif)
1419{
1420 struct ath10k *ar = hw->priv;
1421 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1422 int ret;
1423
Michal Kazior548db542013-07-05 16:15:15 +03001424 lockdep_assert_held(&ar->conf_mutex);
1425
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426 /*
1427 * For some reason, calling VDEV-DOWN before VDEV-STOP
1428 * makes the FW to send frames via HTT after disassociation.
1429 * No idea why this happens, even though VDEV-DOWN is supposed
1430 * to be analogous to link down, so just stop the VDEV.
1431 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001432 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1433 arvif->vdev_id);
1434
1435 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001437
1438 /*
1439 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1440 * report beacons from previously associated network through HTT.
1441 * This in turn would spam mac80211 WARN_ON if we bring down all
1442 * interfaces as it expects there is no rx when no interface is
1443 * running.
1444 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001445 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1446
1447 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001448 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001449
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001450 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001451
1452 arvif->is_started = false;
1453 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001454}
1455
1456static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1457 struct ieee80211_sta *sta)
1458{
Kalle Valob9ada652013-10-16 15:44:46 +03001459 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001460 int ret = 0;
1461
Michal Kazior548db542013-07-05 16:15:15 +03001462 lockdep_assert_held(&ar->conf_mutex);
1463
Kalle Valob9ada652013-10-16 15:44:46 +03001464 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001465 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001466 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1467 sta->addr);
1468 return ret;
1469 }
1470
1471 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1472 if (ret) {
1473 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1474 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001475 return ret;
1476 }
1477
1478 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1479 if (ret) {
1480 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1481 return ret;
1482 }
1483
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001484 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1485 if (ret) {
1486 ath10k_warn("could not set qos params for STA %pM, %d\n",
1487 sta->addr, ret);
1488 return ret;
1489 }
1490
Kalle Valo5e3dd152013-06-12 20:52:10 +03001491 return ret;
1492}
1493
1494static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1495 struct ieee80211_sta *sta)
1496{
1497 int ret = 0;
1498
Michal Kazior548db542013-07-05 16:15:15 +03001499 lockdep_assert_held(&ar->conf_mutex);
1500
Kalle Valo5e3dd152013-06-12 20:52:10 +03001501 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1502 if (ret) {
1503 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1504 return ret;
1505 }
1506
1507 return ret;
1508}
1509
1510/**************/
1511/* Regulatory */
1512/**************/
1513
1514static int ath10k_update_channel_list(struct ath10k *ar)
1515{
1516 struct ieee80211_hw *hw = ar->hw;
1517 struct ieee80211_supported_band **bands;
1518 enum ieee80211_band band;
1519 struct ieee80211_channel *channel;
1520 struct wmi_scan_chan_list_arg arg = {0};
1521 struct wmi_channel_arg *ch;
1522 bool passive;
1523 int len;
1524 int ret;
1525 int i;
1526
Michal Kazior548db542013-07-05 16:15:15 +03001527 lockdep_assert_held(&ar->conf_mutex);
1528
Kalle Valo5e3dd152013-06-12 20:52:10 +03001529 bands = hw->wiphy->bands;
1530 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1531 if (!bands[band])
1532 continue;
1533
1534 for (i = 0; i < bands[band]->n_channels; i++) {
1535 if (bands[band]->channels[i].flags &
1536 IEEE80211_CHAN_DISABLED)
1537 continue;
1538
1539 arg.n_channels++;
1540 }
1541 }
1542
1543 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1544 arg.channels = kzalloc(len, GFP_KERNEL);
1545 if (!arg.channels)
1546 return -ENOMEM;
1547
1548 ch = arg.channels;
1549 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1550 if (!bands[band])
1551 continue;
1552
1553 for (i = 0; i < bands[band]->n_channels; i++) {
1554 channel = &bands[band]->channels[i];
1555
1556 if (channel->flags & IEEE80211_CHAN_DISABLED)
1557 continue;
1558
1559 ch->allow_ht = true;
1560
1561 /* FIXME: when should we really allow VHT? */
1562 ch->allow_vht = true;
1563
1564 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001565 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001566
1567 ch->ht40plus =
1568 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1569
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001570 ch->chan_radar =
1571 !!(channel->flags & IEEE80211_CHAN_RADAR);
1572
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001573 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574 ch->passive = passive;
1575
1576 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001577 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001578 ch->max_power = channel->max_power * 2;
1579 ch->max_reg_power = channel->max_reg_power * 2;
1580 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581 ch->reg_class_id = 0; /* FIXME */
1582
1583 /* FIXME: why use only legacy modes, why not any
1584 * HT/VHT modes? Would that even make any
1585 * difference? */
1586 if (channel->band == IEEE80211_BAND_2GHZ)
1587 ch->mode = MODE_11G;
1588 else
1589 ch->mode = MODE_11A;
1590
1591 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1592 continue;
1593
1594 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001595 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1596 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597 ch->freq, ch->max_power, ch->max_reg_power,
1598 ch->max_antenna_gain, ch->mode);
1599
1600 ch++;
1601 }
1602 }
1603
1604 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1605 kfree(arg.channels);
1606
1607 return ret;
1608}
1609
Michal Kaziorf7843d72013-07-16 09:38:52 +02001610static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001613 int ret;
1614
Michal Kaziorf7843d72013-07-16 09:38:52 +02001615 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616
1617 ret = ath10k_update_channel_list(ar);
1618 if (ret)
1619 ath10k_warn("could not update channel list (%d)\n", ret);
1620
1621 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001622
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 /* Target allows setting up per-band regdomain but ath_common provides
1624 * a combined one only */
1625 ret = ath10k_wmi_pdev_set_regdomain(ar,
1626 regpair->regDmnEnum,
1627 regpair->regDmnEnum, /* 2ghz */
1628 regpair->regDmnEnum, /* 5ghz */
1629 regpair->reg_2ghz_ctl,
1630 regpair->reg_5ghz_ctl);
1631 if (ret)
1632 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001633}
Michal Kazior548db542013-07-05 16:15:15 +03001634
Michal Kaziorf7843d72013-07-16 09:38:52 +02001635static void ath10k_reg_notifier(struct wiphy *wiphy,
1636 struct regulatory_request *request)
1637{
1638 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1639 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001640 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001641
1642 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1643
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001644 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1645 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1646 request->dfs_region);
1647 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1648 request->dfs_region);
1649 if (!result)
1650 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1651 request->dfs_region);
1652 }
1653
Michal Kaziorf7843d72013-07-16 09:38:52 +02001654 mutex_lock(&ar->conf_mutex);
1655 if (ar->state == ATH10K_STATE_ON)
1656 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001657 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658}
1659
1660/***************/
1661/* TX handlers */
1662/***************/
1663
Michal Kazior42c3aa62013-10-02 11:03:38 +02001664static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1665{
1666 if (ieee80211_is_mgmt(hdr->frame_control))
1667 return HTT_DATA_TX_EXT_TID_MGMT;
1668
1669 if (!ieee80211_is_data_qos(hdr->frame_control))
1670 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1671
1672 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1673 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1674
1675 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1676}
1677
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001678static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1679 struct ieee80211_tx_info *info)
1680{
1681 if (info->control.vif)
1682 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1683
1684 if (ar->monitor_enabled)
1685 return ar->monitor_vdev_id;
1686
1687 ath10k_warn("could not resolve vdev id\n");
1688 return 0;
1689}
1690
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691/*
1692 * Frames sent to the FW have to be in "Native Wifi" format.
1693 * Strip the QoS field from the 802.11 header.
1694 */
1695static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1696 struct ieee80211_tx_control *control,
1697 struct sk_buff *skb)
1698{
1699 struct ieee80211_hdr *hdr = (void *)skb->data;
1700 u8 *qos_ctl;
1701
1702 if (!ieee80211_is_data_qos(hdr->frame_control))
1703 return;
1704
1705 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001706 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1707 skb->data, (void *)qos_ctl - (void *)skb->data);
1708 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001709}
1710
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001711static void ath10k_tx_wep_key_work(struct work_struct *work)
1712{
1713 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1714 wep_key_work);
1715 int ret, keyidx = arvif->def_wep_key_newidx;
1716
1717 if (arvif->def_wep_key_idx == keyidx)
1718 return;
1719
1720 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1721 arvif->vdev_id, keyidx);
1722
1723 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1724 arvif->vdev_id,
1725 arvif->ar->wmi.vdev_param->def_keyid,
1726 keyidx);
1727 if (ret) {
1728 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1729 return;
1730 }
1731
1732 arvif->def_wep_key_idx = keyidx;
1733}
1734
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1736{
1737 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1738 struct ieee80211_vif *vif = info->control.vif;
1739 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1740 struct ath10k *ar = arvif->ar;
1741 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1742 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743
Kalle Valo5e3dd152013-06-12 20:52:10 +03001744 if (!ieee80211_has_protected(hdr->frame_control))
1745 return;
1746
1747 if (!key)
1748 return;
1749
1750 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1751 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1752 return;
1753
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001754 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001755 return;
1756
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001757 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1758 * queueing frames until key index is updated is not an option because
1759 * sk_buff may need more processing to be done, e.g. offchannel */
1760 arvif->def_wep_key_newidx = key->keyidx;
1761 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001762}
1763
1764static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1765{
1766 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1767 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1768 struct ieee80211_vif *vif = info->control.vif;
1769 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1770
1771 /* This is case only for P2P_GO */
1772 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1773 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1774 return;
1775
1776 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1777 spin_lock_bh(&ar->data_lock);
1778 if (arvif->u.ap.noa_data)
1779 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1780 GFP_ATOMIC))
1781 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1782 arvif->u.ap.noa_data,
1783 arvif->u.ap.noa_len);
1784 spin_unlock_bh(&ar->data_lock);
1785 }
1786}
1787
1788static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1789{
1790 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001791 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001792
Michal Kazior961d4c32013-08-09 10:13:34 +02001793 if (ar->htt.target_version_major >= 3) {
1794 /* Since HTT 3.0 there is no separate mgmt tx command */
1795 ret = ath10k_htt_tx(&ar->htt, skb);
1796 goto exit;
1797 }
1798
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001799 if (ieee80211_is_mgmt(hdr->frame_control)) {
1800 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1801 ar->fw_features)) {
1802 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1803 ATH10K_MAX_NUM_MGMT_PENDING) {
1804 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1805 ret = -EBUSY;
1806 goto exit;
1807 }
1808
1809 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1810 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1811 } else {
1812 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1813 }
1814 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1815 ar->fw_features) &&
1816 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001817 /* FW does not report tx status properly for NullFunc frames
1818 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001819 * those frames when it detects link/beacon loss and depends
1820 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001821 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001822 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001823 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001824 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001825
Michal Kazior961d4c32013-08-09 10:13:34 +02001826exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001827 if (ret) {
1828 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1829 ieee80211_free_txskb(ar->hw, skb);
1830 }
1831}
1832
1833void ath10k_offchan_tx_purge(struct ath10k *ar)
1834{
1835 struct sk_buff *skb;
1836
1837 for (;;) {
1838 skb = skb_dequeue(&ar->offchan_tx_queue);
1839 if (!skb)
1840 break;
1841
1842 ieee80211_free_txskb(ar->hw, skb);
1843 }
1844}
1845
1846void ath10k_offchan_tx_work(struct work_struct *work)
1847{
1848 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1849 struct ath10k_peer *peer;
1850 struct ieee80211_hdr *hdr;
1851 struct sk_buff *skb;
1852 const u8 *peer_addr;
1853 int vdev_id;
1854 int ret;
1855
1856 /* FW requirement: We must create a peer before FW will send out
1857 * an offchannel frame. Otherwise the frame will be stuck and
1858 * never transmitted. We delete the peer upon tx completion.
1859 * It is unlikely that a peer for offchannel tx will already be
1860 * present. However it may be in some rare cases so account for that.
1861 * Otherwise we might remove a legitimate peer and break stuff. */
1862
1863 for (;;) {
1864 skb = skb_dequeue(&ar->offchan_tx_queue);
1865 if (!skb)
1866 break;
1867
1868 mutex_lock(&ar->conf_mutex);
1869
Kalle Valo60c3daa2013-09-08 17:56:07 +03001870 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871 skb);
1872
1873 hdr = (struct ieee80211_hdr *)skb->data;
1874 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001875 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876
1877 spin_lock_bh(&ar->data_lock);
1878 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1879 spin_unlock_bh(&ar->data_lock);
1880
1881 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001882 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001883 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1884 peer_addr, vdev_id);
1885
1886 if (!peer) {
1887 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1888 if (ret)
1889 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1890 peer_addr, vdev_id, ret);
1891 }
1892
1893 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001894 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001895 ar->offchan_tx_skb = skb;
1896 spin_unlock_bh(&ar->data_lock);
1897
1898 ath10k_tx_htt(ar, skb);
1899
1900 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1901 3 * HZ);
1902 if (ret <= 0)
1903 ath10k_warn("timed out waiting for offchannel skb %p\n",
1904 skb);
1905
1906 if (!peer) {
1907 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1908 if (ret)
1909 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1910 peer_addr, vdev_id, ret);
1911 }
1912
1913 mutex_unlock(&ar->conf_mutex);
1914 }
1915}
1916
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001917void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1918{
1919 struct sk_buff *skb;
1920
1921 for (;;) {
1922 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1923 if (!skb)
1924 break;
1925
1926 ieee80211_free_txskb(ar->hw, skb);
1927 }
1928}
1929
1930void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1931{
1932 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1933 struct sk_buff *skb;
1934 int ret;
1935
1936 for (;;) {
1937 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1938 if (!skb)
1939 break;
1940
1941 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001942 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001943 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001944 ieee80211_free_txskb(ar->hw, skb);
1945 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001946 }
1947}
1948
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949/************/
1950/* Scanning */
1951/************/
1952
1953/*
1954 * This gets called if we dont get a heart-beat during scan.
1955 * This may indicate the FW has hung and we need to abort the
1956 * scan manually to prevent cancel_hw_scan() from deadlocking
1957 */
1958void ath10k_reset_scan(unsigned long ptr)
1959{
1960 struct ath10k *ar = (struct ath10k *)ptr;
1961
1962 spin_lock_bh(&ar->data_lock);
1963 if (!ar->scan.in_progress) {
1964 spin_unlock_bh(&ar->data_lock);
1965 return;
1966 }
1967
1968 ath10k_warn("scan timeout. resetting. fw issue?\n");
1969
1970 if (ar->scan.is_roc)
1971 ieee80211_remain_on_channel_expired(ar->hw);
1972 else
1973 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1974
1975 ar->scan.in_progress = false;
1976 complete_all(&ar->scan.completed);
1977 spin_unlock_bh(&ar->data_lock);
1978}
1979
1980static int ath10k_abort_scan(struct ath10k *ar)
1981{
1982 struct wmi_stop_scan_arg arg = {
1983 .req_id = 1, /* FIXME */
1984 .req_type = WMI_SCAN_STOP_ONE,
1985 .u.scan_id = ATH10K_SCAN_ID,
1986 };
1987 int ret;
1988
1989 lockdep_assert_held(&ar->conf_mutex);
1990
1991 del_timer_sync(&ar->scan.timeout);
1992
1993 spin_lock_bh(&ar->data_lock);
1994 if (!ar->scan.in_progress) {
1995 spin_unlock_bh(&ar->data_lock);
1996 return 0;
1997 }
1998
1999 ar->scan.aborting = true;
2000 spin_unlock_bh(&ar->data_lock);
2001
2002 ret = ath10k_wmi_stop_scan(ar, &arg);
2003 if (ret) {
2004 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03002005 spin_lock_bh(&ar->data_lock);
2006 ar->scan.in_progress = false;
2007 ath10k_offchan_tx_purge(ar);
2008 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002009 return -EIO;
2010 }
2011
Kalle Valo5e3dd152013-06-12 20:52:10 +03002012 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2013 if (ret == 0)
2014 ath10k_warn("timed out while waiting for scan to stop\n");
2015
2016 /* scan completion may be done right after we timeout here, so let's
2017 * check the in_progress and tell mac80211 scan is completed. if we
2018 * don't do that and FW fails to send us scan completion indication
2019 * then userspace won't be able to scan anymore */
2020 ret = 0;
2021
2022 spin_lock_bh(&ar->data_lock);
2023 if (ar->scan.in_progress) {
2024 ath10k_warn("could not stop scan. its still in progress\n");
2025 ar->scan.in_progress = false;
2026 ath10k_offchan_tx_purge(ar);
2027 ret = -ETIMEDOUT;
2028 }
2029 spin_unlock_bh(&ar->data_lock);
2030
2031 return ret;
2032}
2033
2034static int ath10k_start_scan(struct ath10k *ar,
2035 const struct wmi_start_scan_arg *arg)
2036{
2037 int ret;
2038
2039 lockdep_assert_held(&ar->conf_mutex);
2040
2041 ret = ath10k_wmi_start_scan(ar, arg);
2042 if (ret)
2043 return ret;
2044
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2046 if (ret == 0) {
2047 ath10k_abort_scan(ar);
2048 return ret;
2049 }
2050
2051 /* the scan can complete earlier, before we even
2052 * start the timer. in that case the timer handler
2053 * checks ar->scan.in_progress and bails out if its
2054 * false. Add a 200ms margin to account event/command
2055 * processing. */
2056 mod_timer(&ar->scan.timeout, jiffies +
2057 msecs_to_jiffies(arg->max_scan_time+200));
2058 return 0;
2059}
2060
2061/**********************/
2062/* mac80211 callbacks */
2063/**********************/
2064
2065static void ath10k_tx(struct ieee80211_hw *hw,
2066 struct ieee80211_tx_control *control,
2067 struct sk_buff *skb)
2068{
2069 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2070 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2071 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002072 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002073
2074 /* We should disable CCK RATE due to P2P */
2075 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2076 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2077
2078 /* we must calculate tid before we apply qos workaround
2079 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002080 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002081 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002083 /* it makes no sense to process injected frames like that */
2084 if (info->control.vif &&
2085 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2086 ath10k_tx_h_qos_workaround(hw, control, skb);
2087 ath10k_tx_h_update_wep_key(skb);
2088 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2089 ath10k_tx_h_seq_no(skb);
2090 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002092 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002093 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094 ATH10K_SKB_CB(skb)->htt.tid = tid;
2095
2096 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2097 spin_lock_bh(&ar->data_lock);
2098 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002099 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002100 spin_unlock_bh(&ar->data_lock);
2101
2102 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2103
2104 skb_queue_tail(&ar->offchan_tx_queue, skb);
2105 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2106 return;
2107 }
2108
2109 ath10k_tx_htt(ar, skb);
2110}
2111
2112/*
2113 * Initialize various parameters with default vaules.
2114 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002115void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002116{
2117 lockdep_assert_held(&ar->conf_mutex);
2118
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002119 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002120 del_timer_sync(&ar->scan.timeout);
2121 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002122 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002123 ath10k_peer_cleanup_all(ar);
2124 ath10k_core_stop(ar);
2125 ath10k_hif_power_down(ar);
2126
2127 spin_lock_bh(&ar->data_lock);
2128 if (ar->scan.in_progress) {
2129 del_timer(&ar->scan.timeout);
2130 ar->scan.in_progress = false;
2131 ieee80211_scan_completed(ar->hw, true);
2132 }
2133 spin_unlock_bh(&ar->data_lock);
2134}
2135
Kalle Valo5e3dd152013-06-12 20:52:10 +03002136static int ath10k_start(struct ieee80211_hw *hw)
2137{
2138 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002139 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002140
Michal Kazior548db542013-07-05 16:15:15 +03002141 mutex_lock(&ar->conf_mutex);
2142
Michal Kazioraffd3212013-07-16 09:54:35 +02002143 if (ar->state != ATH10K_STATE_OFF &&
2144 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002145 ret = -EINVAL;
2146 goto exit;
2147 }
2148
2149 ret = ath10k_hif_power_up(ar);
2150 if (ret) {
2151 ath10k_err("could not init hif (%d)\n", ret);
2152 ar->state = ATH10K_STATE_OFF;
2153 goto exit;
2154 }
2155
2156 ret = ath10k_core_start(ar);
2157 if (ret) {
2158 ath10k_err("could not init core (%d)\n", ret);
2159 ath10k_hif_power_down(ar);
2160 ar->state = ATH10K_STATE_OFF;
2161 goto exit;
2162 }
2163
Michal Kazioraffd3212013-07-16 09:54:35 +02002164 if (ar->state == ATH10K_STATE_OFF)
2165 ar->state = ATH10K_STATE_ON;
2166 else if (ar->state == ATH10K_STATE_RESTARTING)
2167 ar->state = ATH10K_STATE_RESTARTED;
2168
Bartosz Markowski226a3392013-09-26 17:47:16 +02002169 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170 if (ret)
2171 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2172 ret);
2173
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002174 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002175 if (ret)
2176 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2177 ret);
2178
Michal Kaziorf7843d72013-07-16 09:38:52 +02002179 ath10k_regd_update(ar);
2180
Michal Kazior818bdd12013-07-16 09:38:57 +02002181exit:
Michal Kazior548db542013-07-05 16:15:15 +03002182 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183 return 0;
2184}
2185
2186static void ath10k_stop(struct ieee80211_hw *hw)
2187{
2188 struct ath10k *ar = hw->priv;
2189
Michal Kazior548db542013-07-05 16:15:15 +03002190 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002191 if (ar->state == ATH10K_STATE_ON ||
2192 ar->state == ATH10K_STATE_RESTARTED ||
2193 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002194 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002195
Michal Kaziorf7843d72013-07-16 09:38:52 +02002196 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002197 mutex_unlock(&ar->conf_mutex);
2198
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002199 ath10k_mgmt_over_wmi_tx_purge(ar);
2200
Michal Kazior548db542013-07-05 16:15:15 +03002201 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002202 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002203 cancel_work_sync(&ar->restart_work);
2204}
2205
Michal Kaziorad088bf2013-10-16 15:44:46 +03002206static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002207{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002208 struct ath10k_vif *arvif;
2209 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002210
2211 lockdep_assert_held(&ar->conf_mutex);
2212
Michal Kaziorad088bf2013-10-16 15:44:46 +03002213 list_for_each_entry(arvif, &ar->arvifs, list) {
2214 ret = ath10k_mac_vif_setup_ps(arvif);
2215 if (ret) {
2216 ath10k_warn("could not setup powersave (%d)\n", ret);
2217 break;
2218 }
2219 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002220
Michal Kaziorad088bf2013-10-16 15:44:46 +03002221 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222}
2223
Michal Kaziorc930f742014-01-23 11:38:25 +01002224static const char *chandef_get_width(enum nl80211_chan_width width)
2225{
2226 switch (width) {
2227 case NL80211_CHAN_WIDTH_20_NOHT:
2228 return "20 (noht)";
2229 case NL80211_CHAN_WIDTH_20:
2230 return "20";
2231 case NL80211_CHAN_WIDTH_40:
2232 return "40";
2233 case NL80211_CHAN_WIDTH_80:
2234 return "80";
2235 case NL80211_CHAN_WIDTH_80P80:
2236 return "80+80";
2237 case NL80211_CHAN_WIDTH_160:
2238 return "160";
2239 case NL80211_CHAN_WIDTH_5:
2240 return "5";
2241 case NL80211_CHAN_WIDTH_10:
2242 return "10";
2243 }
2244 return "?";
2245}
2246
2247static void ath10k_config_chan(struct ath10k *ar)
2248{
2249 struct ath10k_vif *arvif;
2250 bool monitor_was_enabled;
2251 int ret;
2252
2253 lockdep_assert_held(&ar->conf_mutex);
2254
2255 ath10k_dbg(ATH10K_DBG_MAC,
2256 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2257 ar->chandef.chan->center_freq,
2258 ar->chandef.center_freq1,
2259 ar->chandef.center_freq2,
2260 chandef_get_width(ar->chandef.width));
2261
2262 /* First stop monitor interface. Some FW versions crash if there's a
2263 * lone monitor interface. */
2264 monitor_was_enabled = ar->monitor_enabled;
2265
2266 if (ar->monitor_enabled)
2267 ath10k_monitor_stop(ar);
2268
2269 list_for_each_entry(arvif, &ar->arvifs, list) {
2270 if (!arvif->is_started)
2271 continue;
2272
2273 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2274 continue;
2275
2276 ret = ath10k_vdev_stop(arvif);
2277 if (ret) {
2278 ath10k_warn("could not stop vdev %d (%d)\n",
2279 arvif->vdev_id, ret);
2280 continue;
2281 }
2282 }
2283
2284 /* all vdevs are now stopped - now attempt to restart them */
2285
2286 list_for_each_entry(arvif, &ar->arvifs, list) {
2287 if (!arvif->is_started)
2288 continue;
2289
2290 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2291 continue;
2292
2293 ret = ath10k_vdev_start(arvif);
2294 if (ret) {
2295 ath10k_warn("could not start vdev %d (%d)\n",
2296 arvif->vdev_id, ret);
2297 continue;
2298 }
2299
2300 if (!arvif->is_up)
2301 continue;
2302
2303 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2304 arvif->bssid);
2305 if (ret) {
2306 ath10k_warn("could not bring vdev up %d (%d)\n",
2307 arvif->vdev_id, ret);
2308 continue;
2309 }
2310 }
2311
2312 if (monitor_was_enabled)
2313 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2314}
2315
Kalle Valo5e3dd152013-06-12 20:52:10 +03002316static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2317{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002318 struct ath10k *ar = hw->priv;
2319 struct ieee80211_conf *conf = &hw->conf;
2320 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002321 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322
2323 mutex_lock(&ar->conf_mutex);
2324
2325 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002326 ath10k_dbg(ATH10K_DBG_MAC,
2327 "mac config channel %d mhz flags 0x%x\n",
2328 conf->chandef.chan->center_freq,
2329 conf->chandef.chan->flags);
2330
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 spin_lock_bh(&ar->data_lock);
2332 ar->rx_channel = conf->chandef.chan;
2333 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002334
2335 ath10k_config_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002336
2337 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2338 ar->chandef = conf->chandef;
2339 ath10k_config_chan(ar);
2340 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341 }
2342
Michal Kazior5474efe2013-10-23 04:02:15 -07002343 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2344 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2345 hw->conf.power_level);
2346
2347 param = ar->wmi.pdev_param->txpower_limit2g;
2348 ret = ath10k_wmi_pdev_set_param(ar, param,
2349 hw->conf.power_level * 2);
2350 if (ret)
2351 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2352 hw->conf.power_level, ret);
2353
2354 param = ar->wmi.pdev_param->txpower_limit5g;
2355 ret = ath10k_wmi_pdev_set_param(ar, param,
2356 hw->conf.power_level * 2);
2357 if (ret)
2358 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2359 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360 }
2361
Michal Kazioraffd3212013-07-16 09:54:35 +02002362 if (changed & IEEE80211_CONF_CHANGE_PS)
2363 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002364
2365 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2366 if (conf->flags & IEEE80211_CONF_MONITOR)
2367 ret = ath10k_monitor_create(ar);
2368 else
2369 ret = ath10k_monitor_destroy(ar);
2370 }
2371
2372 mutex_unlock(&ar->conf_mutex);
2373 return ret;
2374}
2375
2376/*
2377 * TODO:
2378 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2379 * because we will send mgmt frames without CCK. This requirement
2380 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2381 * in the TX packet.
2382 */
2383static int ath10k_add_interface(struct ieee80211_hw *hw,
2384 struct ieee80211_vif *vif)
2385{
2386 struct ath10k *ar = hw->priv;
2387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2388 enum wmi_sta_powersave_param param;
2389 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002390 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002391 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002392 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002393
2394 mutex_lock(&ar->conf_mutex);
2395
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002396 memset(arvif, 0, sizeof(*arvif));
2397
Kalle Valo5e3dd152013-06-12 20:52:10 +03002398 arvif->ar = ar;
2399 arvif->vif = vif;
2400
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002401 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002402 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002403
Kalle Valo5e3dd152013-06-12 20:52:10 +03002404 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2405 ath10k_warn("Only one monitor interface allowed\n");
2406 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002407 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408 }
2409
2410 bit = ffs(ar->free_vdev_map);
2411 if (bit == 0) {
2412 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002413 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002414 }
2415
2416 arvif->vdev_id = bit - 1;
2417 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418
2419 if (ar->p2p)
2420 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2421
2422 switch (vif->type) {
2423 case NL80211_IFTYPE_UNSPECIFIED:
2424 case NL80211_IFTYPE_STATION:
2425 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2426 if (vif->p2p)
2427 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2428 break;
2429 case NL80211_IFTYPE_ADHOC:
2430 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2431 break;
2432 case NL80211_IFTYPE_AP:
2433 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2434
2435 if (vif->p2p)
2436 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2437 break;
2438 case NL80211_IFTYPE_MONITOR:
2439 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2440 break;
2441 default:
2442 WARN_ON(1);
2443 break;
2444 }
2445
Kalle Valo60c3daa2013-09-08 17:56:07 +03002446 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002447 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2448
2449 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2450 arvif->vdev_subtype, vif->addr);
2451 if (ret) {
2452 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002453 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002454 }
2455
Michal Kazior9dad14a2013-10-16 15:44:45 +03002456 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002457 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002458
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002459 vdev_param = ar->wmi.vdev_param->def_keyid;
2460 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002461 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002462 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002463 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002464 goto err_vdev_delete;
2465 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002467 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2468 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002469 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002470 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002471 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002473 goto err_vdev_delete;
2474 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475
2476 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2477 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2478 if (ret) {
2479 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002480 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002481 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002482
Kalle Valo5a13e762014-01-20 11:01:46 +02002483 ret = ath10k_mac_set_kickout(arvif);
2484 if (ret) {
2485 ath10k_warn("Failed to set kickout parameters: %d\n",
2486 ret);
2487 goto err_peer_delete;
2488 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002489 }
2490
2491 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2492 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2493 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2494 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2495 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002496 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002497 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002498 goto err_peer_delete;
2499 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002500
2501 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2502 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2503 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2504 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002505 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002506 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002507 goto err_peer_delete;
2508 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509
2510 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2511 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2512 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2513 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002514 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002516 goto err_peer_delete;
2517 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002518 }
2519
Michal Kazior424121c2013-07-22 14:13:31 +02002520 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002521 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002522 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2523 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002524 goto err_peer_delete;
2525 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002526
Michal Kazior424121c2013-07-22 14:13:31 +02002527 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002528 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002529 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2530 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002531 goto err_peer_delete;
2532 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002533
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2535 ar->monitor_present = true;
2536
Kalle Valo5e3dd152013-06-12 20:52:10 +03002537 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002538 return 0;
2539
2540err_peer_delete:
2541 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2542 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2543
2544err_vdev_delete:
2545 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2546 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002547 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002548
2549err:
2550 mutex_unlock(&ar->conf_mutex);
2551
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 return ret;
2553}
2554
2555static void ath10k_remove_interface(struct ieee80211_hw *hw,
2556 struct ieee80211_vif *vif)
2557{
2558 struct ath10k *ar = hw->priv;
2559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2560 int ret;
2561
2562 mutex_lock(&ar->conf_mutex);
2563
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002564 cancel_work_sync(&arvif->wep_key_work);
2565
Michal Kaziored543882013-09-13 14:16:56 +02002566 spin_lock_bh(&ar->data_lock);
2567 if (arvif->beacon) {
2568 dev_kfree_skb_any(arvif->beacon);
2569 arvif->beacon = NULL;
2570 }
2571 spin_unlock_bh(&ar->data_lock);
2572
Kalle Valo5e3dd152013-06-12 20:52:10 +03002573 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002574 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575
2576 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2577 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2578 if (ret)
2579 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2580
2581 kfree(arvif->u.ap.noa_data);
2582 }
2583
Kalle Valo60c3daa2013-09-08 17:56:07 +03002584 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2585 arvif->vdev_id);
2586
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2588 if (ret)
2589 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2590
2591 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2592 ar->monitor_present = false;
2593
2594 ath10k_peer_cleanup(ar, arvif->vdev_id);
2595
2596 mutex_unlock(&ar->conf_mutex);
2597}
2598
2599/*
2600 * FIXME: Has to be verified.
2601 */
2602#define SUPPORTED_FILTERS \
2603 (FIF_PROMISC_IN_BSS | \
2604 FIF_ALLMULTI | \
2605 FIF_CONTROL | \
2606 FIF_PSPOLL | \
2607 FIF_OTHER_BSS | \
2608 FIF_BCN_PRBRESP_PROMISC | \
2609 FIF_PROBE_REQ | \
2610 FIF_FCSFAIL)
2611
2612static void ath10k_configure_filter(struct ieee80211_hw *hw,
2613 unsigned int changed_flags,
2614 unsigned int *total_flags,
2615 u64 multicast)
2616{
2617 struct ath10k *ar = hw->priv;
2618 int ret;
2619
2620 mutex_lock(&ar->conf_mutex);
2621
2622 changed_flags &= SUPPORTED_FILTERS;
2623 *total_flags &= SUPPORTED_FILTERS;
2624 ar->filter_flags = *total_flags;
2625
Michal Kaziorafd09222013-10-16 16:45:41 +03002626 /* Monitor must not be started if it wasn't created first.
2627 * Promiscuous mode may be started on a non-monitor interface - in
2628 * such case the monitor vdev is not created so starting the
2629 * monitor makes no sense. Since ath10k uses no special RX filters
2630 * (only BSS filter in STA mode) there's no need for any special
2631 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002632 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002633 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002634 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2635 ar->monitor_vdev_id);
2636
Kalle Valo5e3dd152013-06-12 20:52:10 +03002637 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2638 if (ret)
2639 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002640 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002641 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002642 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2643 ar->monitor_vdev_id);
2644
Kalle Valo5e3dd152013-06-12 20:52:10 +03002645 ret = ath10k_monitor_stop(ar);
2646 if (ret)
2647 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002648 }
2649
2650 mutex_unlock(&ar->conf_mutex);
2651}
2652
2653static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2654 struct ieee80211_vif *vif,
2655 struct ieee80211_bss_conf *info,
2656 u32 changed)
2657{
2658 struct ath10k *ar = hw->priv;
2659 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2660 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002661 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002662
2663 mutex_lock(&ar->conf_mutex);
2664
2665 if (changed & BSS_CHANGED_IBSS)
2666 ath10k_control_ibss(arvif, info, vif->addr);
2667
2668 if (changed & BSS_CHANGED_BEACON_INT) {
2669 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002670 vdev_param = ar->wmi.vdev_param->beacon_interval;
2671 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002672 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002673 ath10k_dbg(ATH10K_DBG_MAC,
2674 "mac vdev %d beacon_interval %d\n",
2675 arvif->vdev_id, arvif->beacon_interval);
2676
Kalle Valo5e3dd152013-06-12 20:52:10 +03002677 if (ret)
2678 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2679 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002680 }
2681
2682 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002683 ath10k_dbg(ATH10K_DBG_MAC,
2684 "vdev %d set beacon tx mode to staggered\n",
2685 arvif->vdev_id);
2686
Bartosz Markowski226a3392013-09-26 17:47:16 +02002687 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2688 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002689 WMI_BEACON_STAGGERED_MODE);
2690 if (ret)
2691 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2692 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693 }
2694
John W. Linvilleb70727e2013-06-13 13:34:29 -04002695 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 arvif->dtim_period = info->dtim_period;
2697
Kalle Valo60c3daa2013-09-08 17:56:07 +03002698 ath10k_dbg(ATH10K_DBG_MAC,
2699 "mac vdev %d dtim_period %d\n",
2700 arvif->vdev_id, arvif->dtim_period);
2701
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002702 vdev_param = ar->wmi.vdev_param->dtim_period;
2703 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704 arvif->dtim_period);
2705 if (ret)
2706 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2707 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708 }
2709
2710 if (changed & BSS_CHANGED_SSID &&
2711 vif->type == NL80211_IFTYPE_AP) {
2712 arvif->u.ap.ssid_len = info->ssid_len;
2713 if (info->ssid_len)
2714 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2715 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2716 }
2717
2718 if (changed & BSS_CHANGED_BSSID) {
2719 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002720 ath10k_dbg(ATH10K_DBG_MAC,
2721 "mac vdev %d create peer %pM\n",
2722 arvif->vdev_id, info->bssid);
2723
Kalle Valo5e3dd152013-06-12 20:52:10 +03002724 ret = ath10k_peer_create(ar, arvif->vdev_id,
2725 info->bssid);
2726 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002727 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2728 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002729
2730 if (vif->type == NL80211_IFTYPE_STATION) {
2731 /*
2732 * this is never erased as we it for crypto key
2733 * clearing; this is FW requirement
2734 */
Michal Kaziorc930f742014-01-23 11:38:25 +01002735 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002736
Kalle Valo60c3daa2013-09-08 17:56:07 +03002737 ath10k_dbg(ATH10K_DBG_MAC,
2738 "mac vdev %d start %pM\n",
2739 arvif->vdev_id, info->bssid);
2740
Kalle Valo5e3dd152013-06-12 20:52:10 +03002741 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002742 if (ret) {
2743 ath10k_warn("failed to start vdev: %d\n",
2744 ret);
2745 return;
2746 }
2747
2748 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749 }
2750
2751 /*
2752 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2753 * so driver need to store it. It is needed when leaving
2754 * IBSS in order to remove BSSID peer.
2755 */
2756 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01002757 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758 ETH_ALEN);
2759 }
2760 }
2761
2762 if (changed & BSS_CHANGED_BEACON_ENABLED)
2763 ath10k_control_beaconing(arvif, info);
2764
2765 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2766 u32 cts_prot;
2767 if (info->use_cts_prot)
2768 cts_prot = 1;
2769 else
2770 cts_prot = 0;
2771
Kalle Valo60c3daa2013-09-08 17:56:07 +03002772 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2773 arvif->vdev_id, cts_prot);
2774
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002775 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2776 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002777 cts_prot);
2778 if (ret)
2779 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2780 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002781 }
2782
2783 if (changed & BSS_CHANGED_ERP_SLOT) {
2784 u32 slottime;
2785 if (info->use_short_slot)
2786 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2787
2788 else
2789 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2790
Kalle Valo60c3daa2013-09-08 17:56:07 +03002791 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2792 arvif->vdev_id, slottime);
2793
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002794 vdev_param = ar->wmi.vdev_param->slot_time;
2795 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002796 slottime);
2797 if (ret)
2798 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2799 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800 }
2801
2802 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2803 u32 preamble;
2804 if (info->use_short_preamble)
2805 preamble = WMI_VDEV_PREAMBLE_SHORT;
2806 else
2807 preamble = WMI_VDEV_PREAMBLE_LONG;
2808
Kalle Valo60c3daa2013-09-08 17:56:07 +03002809 ath10k_dbg(ATH10K_DBG_MAC,
2810 "mac vdev %d preamble %dn",
2811 arvif->vdev_id, preamble);
2812
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002813 vdev_param = ar->wmi.vdev_param->preamble;
2814 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815 preamble);
2816 if (ret)
2817 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2818 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002819 }
2820
2821 if (changed & BSS_CHANGED_ASSOC) {
2822 if (info->assoc)
2823 ath10k_bss_assoc(hw, vif, info);
2824 }
2825
2826 mutex_unlock(&ar->conf_mutex);
2827}
2828
2829static int ath10k_hw_scan(struct ieee80211_hw *hw,
2830 struct ieee80211_vif *vif,
2831 struct cfg80211_scan_request *req)
2832{
2833 struct ath10k *ar = hw->priv;
2834 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2835 struct wmi_start_scan_arg arg;
2836 int ret = 0;
2837 int i;
2838
2839 mutex_lock(&ar->conf_mutex);
2840
2841 spin_lock_bh(&ar->data_lock);
2842 if (ar->scan.in_progress) {
2843 spin_unlock_bh(&ar->data_lock);
2844 ret = -EBUSY;
2845 goto exit;
2846 }
2847
Wolfram Sang16735d02013-11-14 14:32:02 -08002848 reinit_completion(&ar->scan.started);
2849 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850 ar->scan.in_progress = true;
2851 ar->scan.aborting = false;
2852 ar->scan.is_roc = false;
2853 ar->scan.vdev_id = arvif->vdev_id;
2854 spin_unlock_bh(&ar->data_lock);
2855
2856 memset(&arg, 0, sizeof(arg));
2857 ath10k_wmi_start_scan_init(ar, &arg);
2858 arg.vdev_id = arvif->vdev_id;
2859 arg.scan_id = ATH10K_SCAN_ID;
2860
2861 if (!req->no_cck)
2862 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2863
2864 if (req->ie_len) {
2865 arg.ie_len = req->ie_len;
2866 memcpy(arg.ie, req->ie, arg.ie_len);
2867 }
2868
2869 if (req->n_ssids) {
2870 arg.n_ssids = req->n_ssids;
2871 for (i = 0; i < arg.n_ssids; i++) {
2872 arg.ssids[i].len = req->ssids[i].ssid_len;
2873 arg.ssids[i].ssid = req->ssids[i].ssid;
2874 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002875 } else {
2876 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002877 }
2878
2879 if (req->n_channels) {
2880 arg.n_channels = req->n_channels;
2881 for (i = 0; i < arg.n_channels; i++)
2882 arg.channels[i] = req->channels[i]->center_freq;
2883 }
2884
2885 ret = ath10k_start_scan(ar, &arg);
2886 if (ret) {
2887 ath10k_warn("could not start hw scan (%d)\n", ret);
2888 spin_lock_bh(&ar->data_lock);
2889 ar->scan.in_progress = false;
2890 spin_unlock_bh(&ar->data_lock);
2891 }
2892
2893exit:
2894 mutex_unlock(&ar->conf_mutex);
2895 return ret;
2896}
2897
2898static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2899 struct ieee80211_vif *vif)
2900{
2901 struct ath10k *ar = hw->priv;
2902 int ret;
2903
2904 mutex_lock(&ar->conf_mutex);
2905 ret = ath10k_abort_scan(ar);
2906 if (ret) {
2907 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2908 ret);
2909 ieee80211_scan_completed(hw, 1 /* aborted */);
2910 }
2911 mutex_unlock(&ar->conf_mutex);
2912}
2913
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002914static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2915 struct ath10k_vif *arvif,
2916 enum set_key_cmd cmd,
2917 struct ieee80211_key_conf *key)
2918{
2919 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2920 int ret;
2921
2922 /* 10.1 firmware branch requires default key index to be set to group
2923 * key index after installing it. Otherwise FW/HW Txes corrupted
2924 * frames with multi-vif APs. This is not required for main firmware
2925 * branch (e.g. 636).
2926 *
2927 * FIXME: This has been tested only in AP. It remains unknown if this
2928 * is required for multi-vif STA interfaces on 10.1 */
2929
2930 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2931 return;
2932
2933 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2934 return;
2935
2936 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2937 return;
2938
2939 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2940 return;
2941
2942 if (cmd != SET_KEY)
2943 return;
2944
2945 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2946 key->keyidx);
2947 if (ret)
2948 ath10k_warn("failed to set group key as default key: %d\n",
2949 ret);
2950}
2951
Kalle Valo5e3dd152013-06-12 20:52:10 +03002952static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2953 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2954 struct ieee80211_key_conf *key)
2955{
2956 struct ath10k *ar = hw->priv;
2957 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2958 struct ath10k_peer *peer;
2959 const u8 *peer_addr;
2960 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2961 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2962 int ret = 0;
2963
2964 if (key->keyidx > WMI_MAX_KEY_INDEX)
2965 return -ENOSPC;
2966
2967 mutex_lock(&ar->conf_mutex);
2968
2969 if (sta)
2970 peer_addr = sta->addr;
2971 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2972 peer_addr = vif->bss_conf.bssid;
2973 else
2974 peer_addr = vif->addr;
2975
2976 key->hw_key_idx = key->keyidx;
2977
2978 /* the peer should not disappear in mid-way (unless FW goes awry) since
2979 * we already hold conf_mutex. we just make sure its there now. */
2980 spin_lock_bh(&ar->data_lock);
2981 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2982 spin_unlock_bh(&ar->data_lock);
2983
2984 if (!peer) {
2985 if (cmd == SET_KEY) {
2986 ath10k_warn("cannot install key for non-existent peer %pM\n",
2987 peer_addr);
2988 ret = -EOPNOTSUPP;
2989 goto exit;
2990 } else {
2991 /* if the peer doesn't exist there is no key to disable
2992 * anymore */
2993 goto exit;
2994 }
2995 }
2996
2997 if (is_wep) {
2998 if (cmd == SET_KEY)
2999 arvif->wep_keys[key->keyidx] = key;
3000 else
3001 arvif->wep_keys[key->keyidx] = NULL;
3002
3003 if (cmd == DISABLE_KEY)
3004 ath10k_clear_vdev_key(arvif, key);
3005 }
3006
3007 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3008 if (ret) {
3009 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
3010 goto exit;
3011 }
3012
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003013 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3014
Kalle Valo5e3dd152013-06-12 20:52:10 +03003015 spin_lock_bh(&ar->data_lock);
3016 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3017 if (peer && cmd == SET_KEY)
3018 peer->keys[key->keyidx] = key;
3019 else if (peer && cmd == DISABLE_KEY)
3020 peer->keys[key->keyidx] = NULL;
3021 else if (peer == NULL)
3022 /* impossible unless FW goes crazy */
3023 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3024 spin_unlock_bh(&ar->data_lock);
3025
3026exit:
3027 mutex_unlock(&ar->conf_mutex);
3028 return ret;
3029}
3030
3031static int ath10k_sta_state(struct ieee80211_hw *hw,
3032 struct ieee80211_vif *vif,
3033 struct ieee80211_sta *sta,
3034 enum ieee80211_sta_state old_state,
3035 enum ieee80211_sta_state new_state)
3036{
3037 struct ath10k *ar = hw->priv;
3038 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003039 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003040 int ret = 0;
3041
3042 mutex_lock(&ar->conf_mutex);
3043
3044 if (old_state == IEEE80211_STA_NOTEXIST &&
3045 new_state == IEEE80211_STA_NONE &&
3046 vif->type != NL80211_IFTYPE_STATION) {
3047 /*
3048 * New station addition.
3049 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003050 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3051 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3052 else
3053 max_num_peers = TARGET_NUM_PEERS;
3054
3055 if (ar->num_peers >= max_num_peers) {
3056 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3057 ar->num_peers, max_num_peers);
3058 ret = -ENOBUFS;
3059 goto exit;
3060 }
3061
Kalle Valo60c3daa2013-09-08 17:56:07 +03003062 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003063 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3064 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003065
Kalle Valo5e3dd152013-06-12 20:52:10 +03003066 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3067 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08003068 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3069 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003070 } else if ((old_state == IEEE80211_STA_NONE &&
3071 new_state == IEEE80211_STA_NOTEXIST)) {
3072 /*
3073 * Existing station deletion.
3074 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003075 ath10k_dbg(ATH10K_DBG_MAC,
3076 "mac vdev %d peer delete %pM (sta gone)\n",
3077 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003078 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3079 if (ret)
3080 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
3081 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003082
3083 if (vif->type == NL80211_IFTYPE_STATION)
3084 ath10k_bss_disassoc(hw, vif);
3085 } else if (old_state == IEEE80211_STA_AUTH &&
3086 new_state == IEEE80211_STA_ASSOC &&
3087 (vif->type == NL80211_IFTYPE_AP ||
3088 vif->type == NL80211_IFTYPE_ADHOC)) {
3089 /*
3090 * New association.
3091 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003092 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3093 sta->addr);
3094
Kalle Valo5e3dd152013-06-12 20:52:10 +03003095 ret = ath10k_station_assoc(ar, arvif, sta);
3096 if (ret)
3097 ath10k_warn("Failed to associate station: %pM\n",
3098 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 } else if (old_state == IEEE80211_STA_ASSOC &&
3100 new_state == IEEE80211_STA_AUTH &&
3101 (vif->type == NL80211_IFTYPE_AP ||
3102 vif->type == NL80211_IFTYPE_ADHOC)) {
3103 /*
3104 * Disassociation.
3105 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003106 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3107 sta->addr);
3108
Kalle Valo5e3dd152013-06-12 20:52:10 +03003109 ret = ath10k_station_disassoc(ar, arvif, sta);
3110 if (ret)
3111 ath10k_warn("Failed to disassociate station: %pM\n",
3112 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003114exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115 mutex_unlock(&ar->conf_mutex);
3116 return ret;
3117}
3118
3119static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3120 u16 ac, bool enable)
3121{
3122 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3123 u32 value = 0;
3124 int ret = 0;
3125
Michal Kazior548db542013-07-05 16:15:15 +03003126 lockdep_assert_held(&ar->conf_mutex);
3127
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3129 return 0;
3130
3131 switch (ac) {
3132 case IEEE80211_AC_VO:
3133 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3134 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3135 break;
3136 case IEEE80211_AC_VI:
3137 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3138 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3139 break;
3140 case IEEE80211_AC_BE:
3141 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3142 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3143 break;
3144 case IEEE80211_AC_BK:
3145 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3146 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3147 break;
3148 }
3149
3150 if (enable)
3151 arvif->u.sta.uapsd |= value;
3152 else
3153 arvif->u.sta.uapsd &= ~value;
3154
3155 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3156 WMI_STA_PS_PARAM_UAPSD,
3157 arvif->u.sta.uapsd);
3158 if (ret) {
3159 ath10k_warn("could not set uapsd params %d\n", ret);
3160 goto exit;
3161 }
3162
3163 if (arvif->u.sta.uapsd)
3164 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3165 else
3166 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3167
3168 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3169 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3170 value);
3171 if (ret)
3172 ath10k_warn("could not set rx wake param %d\n", ret);
3173
3174exit:
3175 return ret;
3176}
3177
3178static int ath10k_conf_tx(struct ieee80211_hw *hw,
3179 struct ieee80211_vif *vif, u16 ac,
3180 const struct ieee80211_tx_queue_params *params)
3181{
3182 struct ath10k *ar = hw->priv;
3183 struct wmi_wmm_params_arg *p = NULL;
3184 int ret;
3185
3186 mutex_lock(&ar->conf_mutex);
3187
3188 switch (ac) {
3189 case IEEE80211_AC_VO:
3190 p = &ar->wmm_params.ac_vo;
3191 break;
3192 case IEEE80211_AC_VI:
3193 p = &ar->wmm_params.ac_vi;
3194 break;
3195 case IEEE80211_AC_BE:
3196 p = &ar->wmm_params.ac_be;
3197 break;
3198 case IEEE80211_AC_BK:
3199 p = &ar->wmm_params.ac_bk;
3200 break;
3201 }
3202
3203 if (WARN_ON(!p)) {
3204 ret = -EINVAL;
3205 goto exit;
3206 }
3207
3208 p->cwmin = params->cw_min;
3209 p->cwmax = params->cw_max;
3210 p->aifs = params->aifs;
3211
3212 /*
3213 * The channel time duration programmed in the HW is in absolute
3214 * microseconds, while mac80211 gives the txop in units of
3215 * 32 microseconds.
3216 */
3217 p->txop = params->txop * 32;
3218
3219 /* FIXME: FW accepts wmm params per hw, not per vif */
3220 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3221 if (ret) {
3222 ath10k_warn("could not set wmm params %d\n", ret);
3223 goto exit;
3224 }
3225
3226 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3227 if (ret)
3228 ath10k_warn("could not set sta uapsd %d\n", ret);
3229
3230exit:
3231 mutex_unlock(&ar->conf_mutex);
3232 return ret;
3233}
3234
3235#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3236
3237static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3238 struct ieee80211_vif *vif,
3239 struct ieee80211_channel *chan,
3240 int duration,
3241 enum ieee80211_roc_type type)
3242{
3243 struct ath10k *ar = hw->priv;
3244 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3245 struct wmi_start_scan_arg arg;
3246 int ret;
3247
3248 mutex_lock(&ar->conf_mutex);
3249
3250 spin_lock_bh(&ar->data_lock);
3251 if (ar->scan.in_progress) {
3252 spin_unlock_bh(&ar->data_lock);
3253 ret = -EBUSY;
3254 goto exit;
3255 }
3256
Wolfram Sang16735d02013-11-14 14:32:02 -08003257 reinit_completion(&ar->scan.started);
3258 reinit_completion(&ar->scan.completed);
3259 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003260 ar->scan.in_progress = true;
3261 ar->scan.aborting = false;
3262 ar->scan.is_roc = true;
3263 ar->scan.vdev_id = arvif->vdev_id;
3264 ar->scan.roc_freq = chan->center_freq;
3265 spin_unlock_bh(&ar->data_lock);
3266
3267 memset(&arg, 0, sizeof(arg));
3268 ath10k_wmi_start_scan_init(ar, &arg);
3269 arg.vdev_id = arvif->vdev_id;
3270 arg.scan_id = ATH10K_SCAN_ID;
3271 arg.n_channels = 1;
3272 arg.channels[0] = chan->center_freq;
3273 arg.dwell_time_active = duration;
3274 arg.dwell_time_passive = duration;
3275 arg.max_scan_time = 2 * duration;
3276 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3277 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3278
3279 ret = ath10k_start_scan(ar, &arg);
3280 if (ret) {
3281 ath10k_warn("could not start roc scan (%d)\n", ret);
3282 spin_lock_bh(&ar->data_lock);
3283 ar->scan.in_progress = false;
3284 spin_unlock_bh(&ar->data_lock);
3285 goto exit;
3286 }
3287
3288 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3289 if (ret == 0) {
3290 ath10k_warn("could not switch to channel for roc scan\n");
3291 ath10k_abort_scan(ar);
3292 ret = -ETIMEDOUT;
3293 goto exit;
3294 }
3295
3296 ret = 0;
3297exit:
3298 mutex_unlock(&ar->conf_mutex);
3299 return ret;
3300}
3301
3302static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3303{
3304 struct ath10k *ar = hw->priv;
3305
3306 mutex_lock(&ar->conf_mutex);
3307 ath10k_abort_scan(ar);
3308 mutex_unlock(&ar->conf_mutex);
3309
3310 return 0;
3311}
3312
3313/*
3314 * Both RTS and Fragmentation threshold are interface-specific
3315 * in ath10k, but device-specific in mac80211.
3316 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317
3318static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3319{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003321 struct ath10k_vif *arvif;
3322 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003323
Michal Kaziorad088bf2013-10-16 15:44:46 +03003324 mutex_lock(&ar->conf_mutex);
3325 list_for_each_entry(arvif, &ar->arvifs, list) {
3326 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3327 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003328
Michal Kaziorad088bf2013-10-16 15:44:46 +03003329 ret = ath10k_mac_set_rts(arvif, value);
3330 if (ret) {
3331 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3332 arvif->vdev_id, ret);
3333 break;
3334 }
3335 }
3336 mutex_unlock(&ar->conf_mutex);
3337
3338 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003339}
3340
3341static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3342{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003343 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003344 struct ath10k_vif *arvif;
3345 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003346
Kalle Valo5e3dd152013-06-12 20:52:10 +03003347 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003348 list_for_each_entry(arvif, &ar->arvifs, list) {
3349 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3350 arvif->vdev_id, value);
3351
3352 ret = ath10k_mac_set_rts(arvif, value);
3353 if (ret) {
3354 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3355 arvif->vdev_id, ret);
3356 break;
3357 }
3358 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003359 mutex_unlock(&ar->conf_mutex);
3360
Michal Kaziorad088bf2013-10-16 15:44:46 +03003361 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003362}
3363
3364static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3365{
3366 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003367 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003368 int ret;
3369
3370 /* mac80211 doesn't care if we really xmit queued frames or not
3371 * we'll collect those frames either way if we stop/delete vdevs */
3372 if (drop)
3373 return;
3374
Michal Kazior548db542013-07-05 16:15:15 +03003375 mutex_lock(&ar->conf_mutex);
3376
Michal Kazioraffd3212013-07-16 09:54:35 +02003377 if (ar->state == ATH10K_STATE_WEDGED)
3378 goto skip;
3379
Michal Kazioredb82362013-07-05 16:15:14 +03003380 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003381 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003382
Michal Kazioredb82362013-07-05 16:15:14 +03003383 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003384 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003385 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003386
3387 skip = (ar->state == ATH10K_STATE_WEDGED);
3388
3389 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003390 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003391
3392 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003393 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003394
Michal Kazioraffd3212013-07-16 09:54:35 +02003395skip:
Michal Kazior548db542013-07-05 16:15:15 +03003396 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003397}
3398
3399/* TODO: Implement this function properly
3400 * For now it is needed to reply to Probe Requests in IBSS mode.
3401 * Propably we need this information from FW.
3402 */
3403static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3404{
3405 return 1;
3406}
3407
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003408#ifdef CONFIG_PM
3409static int ath10k_suspend(struct ieee80211_hw *hw,
3410 struct cfg80211_wowlan *wowlan)
3411{
3412 struct ath10k *ar = hw->priv;
3413 int ret;
3414
3415 ar->is_target_paused = false;
3416
3417 ret = ath10k_wmi_pdev_suspend_target(ar);
3418 if (ret) {
3419 ath10k_warn("could not suspend target (%d)\n", ret);
3420 return 1;
3421 }
3422
3423 ret = wait_event_interruptible_timeout(ar->event_queue,
3424 ar->is_target_paused == true,
3425 1 * HZ);
3426 if (ret < 0) {
3427 ath10k_warn("suspend interrupted (%d)\n", ret);
3428 goto resume;
3429 } else if (ret == 0) {
3430 ath10k_warn("suspend timed out - target pause event never came\n");
3431 goto resume;
3432 }
3433
3434 ret = ath10k_hif_suspend(ar);
3435 if (ret) {
3436 ath10k_warn("could not suspend hif (%d)\n", ret);
3437 goto resume;
3438 }
3439
3440 return 0;
3441resume:
3442 ret = ath10k_wmi_pdev_resume_target(ar);
3443 if (ret)
3444 ath10k_warn("could not resume target (%d)\n", ret);
3445 return 1;
3446}
3447
3448static int ath10k_resume(struct ieee80211_hw *hw)
3449{
3450 struct ath10k *ar = hw->priv;
3451 int ret;
3452
3453 ret = ath10k_hif_resume(ar);
3454 if (ret) {
3455 ath10k_warn("could not resume hif (%d)\n", ret);
3456 return 1;
3457 }
3458
3459 ret = ath10k_wmi_pdev_resume_target(ar);
3460 if (ret) {
3461 ath10k_warn("could not resume target (%d)\n", ret);
3462 return 1;
3463 }
3464
3465 return 0;
3466}
3467#endif
3468
Michal Kazioraffd3212013-07-16 09:54:35 +02003469static void ath10k_restart_complete(struct ieee80211_hw *hw)
3470{
3471 struct ath10k *ar = hw->priv;
3472
3473 mutex_lock(&ar->conf_mutex);
3474
3475 /* If device failed to restart it will be in a different state, e.g.
3476 * ATH10K_STATE_WEDGED */
3477 if (ar->state == ATH10K_STATE_RESTARTED) {
3478 ath10k_info("device successfully recovered\n");
3479 ar->state = ATH10K_STATE_ON;
3480 }
3481
3482 mutex_unlock(&ar->conf_mutex);
3483}
3484
Michal Kazior2e1dea42013-07-31 10:32:40 +02003485static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3486 struct survey_info *survey)
3487{
3488 struct ath10k *ar = hw->priv;
3489 struct ieee80211_supported_band *sband;
3490 struct survey_info *ar_survey = &ar->survey[idx];
3491 int ret = 0;
3492
3493 mutex_lock(&ar->conf_mutex);
3494
3495 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3496 if (sband && idx >= sband->n_channels) {
3497 idx -= sband->n_channels;
3498 sband = NULL;
3499 }
3500
3501 if (!sband)
3502 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3503
3504 if (!sband || idx >= sband->n_channels) {
3505 ret = -ENOENT;
3506 goto exit;
3507 }
3508
3509 spin_lock_bh(&ar->data_lock);
3510 memcpy(survey, ar_survey, sizeof(*survey));
3511 spin_unlock_bh(&ar->data_lock);
3512
3513 survey->channel = &sband->channels[idx];
3514
3515exit:
3516 mutex_unlock(&ar->conf_mutex);
3517 return ret;
3518}
3519
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003520/* Helper table for legacy fixed_rate/bitrate_mask */
3521static const u8 cck_ofdm_rate[] = {
3522 /* CCK */
3523 3, /* 1Mbps */
3524 2, /* 2Mbps */
3525 1, /* 5.5Mbps */
3526 0, /* 11Mbps */
3527 /* OFDM */
3528 3, /* 6Mbps */
3529 7, /* 9Mbps */
3530 2, /* 12Mbps */
3531 6, /* 18Mbps */
3532 1, /* 24Mbps */
3533 5, /* 36Mbps */
3534 0, /* 48Mbps */
3535 4, /* 54Mbps */
3536};
3537
3538/* Check if only one bit set */
3539static int ath10k_check_single_mask(u32 mask)
3540{
3541 int bit;
3542
3543 bit = ffs(mask);
3544 if (!bit)
3545 return 0;
3546
3547 mask &= ~BIT(bit - 1);
3548 if (mask)
3549 return 2;
3550
3551 return 1;
3552}
3553
3554static bool
3555ath10k_default_bitrate_mask(struct ath10k *ar,
3556 enum ieee80211_band band,
3557 const struct cfg80211_bitrate_mask *mask)
3558{
3559 u32 legacy = 0x00ff;
3560 u8 ht = 0xff, i;
3561 u16 vht = 0x3ff;
3562
3563 switch (band) {
3564 case IEEE80211_BAND_2GHZ:
3565 legacy = 0x00fff;
3566 vht = 0;
3567 break;
3568 case IEEE80211_BAND_5GHZ:
3569 break;
3570 default:
3571 return false;
3572 }
3573
3574 if (mask->control[band].legacy != legacy)
3575 return false;
3576
3577 for (i = 0; i < ar->num_rf_chains; i++)
3578 if (mask->control[band].ht_mcs[i] != ht)
3579 return false;
3580
3581 for (i = 0; i < ar->num_rf_chains; i++)
3582 if (mask->control[band].vht_mcs[i] != vht)
3583 return false;
3584
3585 return true;
3586}
3587
3588static bool
3589ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3590 enum ieee80211_band band,
3591 u8 *fixed_nss)
3592{
3593 int ht_nss = 0, vht_nss = 0, i;
3594
3595 /* check legacy */
3596 if (ath10k_check_single_mask(mask->control[band].legacy))
3597 return false;
3598
3599 /* check HT */
3600 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3601 if (mask->control[band].ht_mcs[i] == 0xff)
3602 continue;
3603 else if (mask->control[band].ht_mcs[i] == 0x00)
3604 break;
3605 else
3606 return false;
3607 }
3608
3609 ht_nss = i;
3610
3611 /* check VHT */
3612 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3613 if (mask->control[band].vht_mcs[i] == 0x03ff)
3614 continue;
3615 else if (mask->control[band].vht_mcs[i] == 0x0000)
3616 break;
3617 else
3618 return false;
3619 }
3620
3621 vht_nss = i;
3622
3623 if (ht_nss > 0 && vht_nss > 0)
3624 return false;
3625
3626 if (ht_nss)
3627 *fixed_nss = ht_nss;
3628 else if (vht_nss)
3629 *fixed_nss = vht_nss;
3630 else
3631 return false;
3632
3633 return true;
3634}
3635
3636static bool
3637ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3638 enum ieee80211_band band,
3639 enum wmi_rate_preamble *preamble)
3640{
3641 int legacy = 0, ht = 0, vht = 0, i;
3642
3643 *preamble = WMI_RATE_PREAMBLE_OFDM;
3644
3645 /* check legacy */
3646 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3647 if (legacy > 1)
3648 return false;
3649
3650 /* check HT */
3651 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3652 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3653 if (ht > 1)
3654 return false;
3655
3656 /* check VHT */
3657 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3658 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3659 if (vht > 1)
3660 return false;
3661
3662 /* Currently we support only one fixed_rate */
3663 if ((legacy + ht + vht) != 1)
3664 return false;
3665
3666 if (ht)
3667 *preamble = WMI_RATE_PREAMBLE_HT;
3668 else if (vht)
3669 *preamble = WMI_RATE_PREAMBLE_VHT;
3670
3671 return true;
3672}
3673
3674static bool
3675ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3676 enum ieee80211_band band,
3677 u8 *fixed_rate,
3678 u8 *fixed_nss)
3679{
3680 u8 rate = 0, pream = 0, nss = 0, i;
3681 enum wmi_rate_preamble preamble;
3682
3683 /* Check if single rate correct */
3684 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3685 return false;
3686
3687 pream = preamble;
3688
3689 switch (preamble) {
3690 case WMI_RATE_PREAMBLE_CCK:
3691 case WMI_RATE_PREAMBLE_OFDM:
3692 i = ffs(mask->control[band].legacy) - 1;
3693
3694 if (band == IEEE80211_BAND_2GHZ && i < 4)
3695 pream = WMI_RATE_PREAMBLE_CCK;
3696
3697 if (band == IEEE80211_BAND_5GHZ)
3698 i += 4;
3699
3700 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3701 return false;
3702
3703 rate = cck_ofdm_rate[i];
3704 break;
3705 case WMI_RATE_PREAMBLE_HT:
3706 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3707 if (mask->control[band].ht_mcs[i])
3708 break;
3709
3710 if (i == IEEE80211_HT_MCS_MASK_LEN)
3711 return false;
3712
3713 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3714 nss = i;
3715 break;
3716 case WMI_RATE_PREAMBLE_VHT:
3717 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3718 if (mask->control[band].vht_mcs[i])
3719 break;
3720
3721 if (i == NL80211_VHT_NSS_MAX)
3722 return false;
3723
3724 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3725 nss = i;
3726 break;
3727 }
3728
3729 *fixed_nss = nss + 1;
3730 nss <<= 4;
3731 pream <<= 6;
3732
3733 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3734 pream, nss, rate);
3735
3736 *fixed_rate = pream | nss | rate;
3737
3738 return true;
3739}
3740
3741static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3742 enum ieee80211_band band,
3743 u8 *fixed_rate,
3744 u8 *fixed_nss)
3745{
3746 /* First check full NSS mask, if we can simply limit NSS */
3747 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3748 return true;
3749
3750 /* Next Check single rate is set */
3751 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3752}
3753
3754static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3755 u8 fixed_rate,
3756 u8 fixed_nss)
3757{
3758 struct ath10k *ar = arvif->ar;
3759 u32 vdev_param;
3760 int ret = 0;
3761
3762 mutex_lock(&ar->conf_mutex);
3763
3764 if (arvif->fixed_rate == fixed_rate &&
3765 arvif->fixed_nss == fixed_nss)
3766 goto exit;
3767
3768 if (fixed_rate == WMI_FIXED_RATE_NONE)
3769 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3770
3771 vdev_param = ar->wmi.vdev_param->fixed_rate;
3772 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3773 vdev_param, fixed_rate);
3774 if (ret) {
3775 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3776 fixed_rate, ret);
3777 ret = -EINVAL;
3778 goto exit;
3779 }
3780
3781 arvif->fixed_rate = fixed_rate;
3782
3783 vdev_param = ar->wmi.vdev_param->nss;
3784 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3785 vdev_param, fixed_nss);
3786
3787 if (ret) {
3788 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3789 fixed_nss, ret);
3790 ret = -EINVAL;
3791 goto exit;
3792 }
3793
3794 arvif->fixed_nss = fixed_nss;
3795
3796exit:
3797 mutex_unlock(&ar->conf_mutex);
3798 return ret;
3799}
3800
3801static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3802 struct ieee80211_vif *vif,
3803 const struct cfg80211_bitrate_mask *mask)
3804{
3805 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3806 struct ath10k *ar = arvif->ar;
3807 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3808 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3809 u8 fixed_nss = ar->num_rf_chains;
3810
3811 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3812 if (!ath10k_get_fixed_rate_nss(mask, band,
3813 &fixed_rate,
3814 &fixed_nss))
3815 return -EINVAL;
3816 }
3817
3818 return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss);
3819}
3820
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821static const struct ieee80211_ops ath10k_ops = {
3822 .tx = ath10k_tx,
3823 .start = ath10k_start,
3824 .stop = ath10k_stop,
3825 .config = ath10k_config,
3826 .add_interface = ath10k_add_interface,
3827 .remove_interface = ath10k_remove_interface,
3828 .configure_filter = ath10k_configure_filter,
3829 .bss_info_changed = ath10k_bss_info_changed,
3830 .hw_scan = ath10k_hw_scan,
3831 .cancel_hw_scan = ath10k_cancel_hw_scan,
3832 .set_key = ath10k_set_key,
3833 .sta_state = ath10k_sta_state,
3834 .conf_tx = ath10k_conf_tx,
3835 .remain_on_channel = ath10k_remain_on_channel,
3836 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3837 .set_rts_threshold = ath10k_set_rts_threshold,
3838 .set_frag_threshold = ath10k_set_frag_threshold,
3839 .flush = ath10k_flush,
3840 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003841 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003842 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003843 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003844#ifdef CONFIG_PM
3845 .suspend = ath10k_suspend,
3846 .resume = ath10k_resume,
3847#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003848};
3849
3850#define RATETAB_ENT(_rate, _rateid, _flags) { \
3851 .bitrate = (_rate), \
3852 .flags = (_flags), \
3853 .hw_value = (_rateid), \
3854}
3855
3856#define CHAN2G(_channel, _freq, _flags) { \
3857 .band = IEEE80211_BAND_2GHZ, \
3858 .hw_value = (_channel), \
3859 .center_freq = (_freq), \
3860 .flags = (_flags), \
3861 .max_antenna_gain = 0, \
3862 .max_power = 30, \
3863}
3864
3865#define CHAN5G(_channel, _freq, _flags) { \
3866 .band = IEEE80211_BAND_5GHZ, \
3867 .hw_value = (_channel), \
3868 .center_freq = (_freq), \
3869 .flags = (_flags), \
3870 .max_antenna_gain = 0, \
3871 .max_power = 30, \
3872}
3873
3874static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3875 CHAN2G(1, 2412, 0),
3876 CHAN2G(2, 2417, 0),
3877 CHAN2G(3, 2422, 0),
3878 CHAN2G(4, 2427, 0),
3879 CHAN2G(5, 2432, 0),
3880 CHAN2G(6, 2437, 0),
3881 CHAN2G(7, 2442, 0),
3882 CHAN2G(8, 2447, 0),
3883 CHAN2G(9, 2452, 0),
3884 CHAN2G(10, 2457, 0),
3885 CHAN2G(11, 2462, 0),
3886 CHAN2G(12, 2467, 0),
3887 CHAN2G(13, 2472, 0),
3888 CHAN2G(14, 2484, 0),
3889};
3890
3891static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003892 CHAN5G(36, 5180, 0),
3893 CHAN5G(40, 5200, 0),
3894 CHAN5G(44, 5220, 0),
3895 CHAN5G(48, 5240, 0),
3896 CHAN5G(52, 5260, 0),
3897 CHAN5G(56, 5280, 0),
3898 CHAN5G(60, 5300, 0),
3899 CHAN5G(64, 5320, 0),
3900 CHAN5G(100, 5500, 0),
3901 CHAN5G(104, 5520, 0),
3902 CHAN5G(108, 5540, 0),
3903 CHAN5G(112, 5560, 0),
3904 CHAN5G(116, 5580, 0),
3905 CHAN5G(120, 5600, 0),
3906 CHAN5G(124, 5620, 0),
3907 CHAN5G(128, 5640, 0),
3908 CHAN5G(132, 5660, 0),
3909 CHAN5G(136, 5680, 0),
3910 CHAN5G(140, 5700, 0),
3911 CHAN5G(149, 5745, 0),
3912 CHAN5G(153, 5765, 0),
3913 CHAN5G(157, 5785, 0),
3914 CHAN5G(161, 5805, 0),
3915 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003916};
3917
3918static struct ieee80211_rate ath10k_rates[] = {
3919 /* CCK */
3920 RATETAB_ENT(10, 0x82, 0),
3921 RATETAB_ENT(20, 0x84, 0),
3922 RATETAB_ENT(55, 0x8b, 0),
3923 RATETAB_ENT(110, 0x96, 0),
3924 /* OFDM */
3925 RATETAB_ENT(60, 0x0c, 0),
3926 RATETAB_ENT(90, 0x12, 0),
3927 RATETAB_ENT(120, 0x18, 0),
3928 RATETAB_ENT(180, 0x24, 0),
3929 RATETAB_ENT(240, 0x30, 0),
3930 RATETAB_ENT(360, 0x48, 0),
3931 RATETAB_ENT(480, 0x60, 0),
3932 RATETAB_ENT(540, 0x6c, 0),
3933};
3934
3935#define ath10k_a_rates (ath10k_rates + 4)
3936#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3937#define ath10k_g_rates (ath10k_rates + 0)
3938#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3939
3940struct ath10k *ath10k_mac_create(void)
3941{
3942 struct ieee80211_hw *hw;
3943 struct ath10k *ar;
3944
3945 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3946 if (!hw)
3947 return NULL;
3948
3949 ar = hw->priv;
3950 ar->hw = hw;
3951
3952 return ar;
3953}
3954
3955void ath10k_mac_destroy(struct ath10k *ar)
3956{
3957 ieee80211_free_hw(ar->hw);
3958}
3959
3960static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3961 {
3962 .max = 8,
3963 .types = BIT(NL80211_IFTYPE_STATION)
3964 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003965 },
3966 {
3967 .max = 3,
3968 .types = BIT(NL80211_IFTYPE_P2P_GO)
3969 },
3970 {
3971 .max = 7,
3972 .types = BIT(NL80211_IFTYPE_AP)
3973 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003974};
3975
Bartosz Markowskif2595092013-12-10 16:20:39 +01003976static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003977 {
3978 .max = 8,
3979 .types = BIT(NL80211_IFTYPE_AP)
3980 },
3981};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003982
3983static const struct ieee80211_iface_combination ath10k_if_comb[] = {
3984 {
3985 .limits = ath10k_if_limits,
3986 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3987 .max_interfaces = 8,
3988 .num_different_channels = 1,
3989 .beacon_int_infra_match = true,
3990 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01003991};
3992
3993static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003994 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01003995 .limits = ath10k_10x_if_limits,
3996 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003997 .max_interfaces = 8,
3998 .num_different_channels = 1,
3999 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004000#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004001 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4002 BIT(NL80211_CHAN_WIDTH_20) |
4003 BIT(NL80211_CHAN_WIDTH_40) |
4004 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004005#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004006 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004007};
4008
4009static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4010{
4011 struct ieee80211_sta_vht_cap vht_cap = {0};
4012 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004013 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014
4015 vht_cap.vht_supported = 1;
4016 vht_cap.cap = ar->vht_cap_info;
4017
Michal Kazior8865bee42013-07-24 12:36:46 +02004018 mcs_map = 0;
4019 for (i = 0; i < 8; i++) {
4020 if (i < ar->num_rf_chains)
4021 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4022 else
4023 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4024 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004025
4026 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4027 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4028
4029 return vht_cap;
4030}
4031
4032static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4033{
4034 int i;
4035 struct ieee80211_sta_ht_cap ht_cap = {0};
4036
4037 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4038 return ht_cap;
4039
4040 ht_cap.ht_supported = 1;
4041 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4042 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4043 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4044 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4045 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4046
4047 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4048 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4049
4050 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4051 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4052
4053 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4054 u32 smps;
4055
4056 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4057 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4058
4059 ht_cap.cap |= smps;
4060 }
4061
4062 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4063 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4064
4065 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4066 u32 stbc;
4067
4068 stbc = ar->ht_cap_info;
4069 stbc &= WMI_HT_CAP_RX_STBC;
4070 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4071 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4072 stbc &= IEEE80211_HT_CAP_RX_STBC;
4073
4074 ht_cap.cap |= stbc;
4075 }
4076
4077 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4078 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4079
4080 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4081 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4082
4083 /* max AMSDU is implicitly taken from vht_cap_info */
4084 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4085 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4086
Michal Kazior8865bee42013-07-24 12:36:46 +02004087 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004088 ht_cap.mcs.rx_mask[i] = 0xFF;
4089
4090 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4091
4092 return ht_cap;
4093}
4094
4095
4096static void ath10k_get_arvif_iter(void *data, u8 *mac,
4097 struct ieee80211_vif *vif)
4098{
4099 struct ath10k_vif_iter *arvif_iter = data;
4100 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4101
4102 if (arvif->vdev_id == arvif_iter->vdev_id)
4103 arvif_iter->arvif = arvif;
4104}
4105
4106struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4107{
4108 struct ath10k_vif_iter arvif_iter;
4109 u32 flags;
4110
4111 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4112 arvif_iter.vdev_id = vdev_id;
4113
4114 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4115 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4116 flags,
4117 ath10k_get_arvif_iter,
4118 &arvif_iter);
4119 if (!arvif_iter.arvif) {
4120 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
4121 return NULL;
4122 }
4123
4124 return arvif_iter.arvif;
4125}
4126
4127int ath10k_mac_register(struct ath10k *ar)
4128{
4129 struct ieee80211_supported_band *band;
4130 struct ieee80211_sta_vht_cap vht_cap;
4131 struct ieee80211_sta_ht_cap ht_cap;
4132 void *channels;
4133 int ret;
4134
4135 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4136
4137 SET_IEEE80211_DEV(ar->hw, ar->dev);
4138
4139 ht_cap = ath10k_get_ht_cap(ar);
4140 vht_cap = ath10k_create_vht_cap(ar);
4141
4142 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4143 channels = kmemdup(ath10k_2ghz_channels,
4144 sizeof(ath10k_2ghz_channels),
4145 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004146 if (!channels) {
4147 ret = -ENOMEM;
4148 goto err_free;
4149 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004150
4151 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4152 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4153 band->channels = channels;
4154 band->n_bitrates = ath10k_g_rates_size;
4155 band->bitrates = ath10k_g_rates;
4156 band->ht_cap = ht_cap;
4157
4158 /* vht is not supported in 2.4 GHz */
4159
4160 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4161 }
4162
4163 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4164 channels = kmemdup(ath10k_5ghz_channels,
4165 sizeof(ath10k_5ghz_channels),
4166 GFP_KERNEL);
4167 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004168 ret = -ENOMEM;
4169 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004170 }
4171
4172 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4173 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4174 band->channels = channels;
4175 band->n_bitrates = ath10k_a_rates_size;
4176 band->bitrates = ath10k_a_rates;
4177 band->ht_cap = ht_cap;
4178 band->vht_cap = vht_cap;
4179 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4180 }
4181
4182 ar->hw->wiphy->interface_modes =
4183 BIT(NL80211_IFTYPE_STATION) |
4184 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004185 BIT(NL80211_IFTYPE_AP);
4186
4187 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4188 ar->hw->wiphy->interface_modes |=
4189 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4190 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004191
4192 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4193 IEEE80211_HW_SUPPORTS_PS |
4194 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4195 IEEE80211_HW_SUPPORTS_UAPSD |
4196 IEEE80211_HW_MFP_CAPABLE |
4197 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4198 IEEE80211_HW_HAS_RATE_CONTROL |
4199 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4200 IEEE80211_HW_WANT_MONITOR_VIF |
4201 IEEE80211_HW_AP_LINK_PS;
4202
Michal Kazior1f8bb152013-09-18 14:43:22 +02004203 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4204 * bytes is used for padding/alignment if necessary. */
4205 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4206
Kalle Valo5e3dd152013-06-12 20:52:10 +03004207 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4208 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4209
4210 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4211 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4212 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4213 }
4214
4215 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4216 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4217
4218 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4219
Kalle Valo5e3dd152013-06-12 20:52:10 +03004220 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4221
4222 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4223 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4224
4225 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4226 /*
4227 * on LL hardware queues are managed entirely by the FW
4228 * so we only advertise to mac we can do the queues thing
4229 */
4230 ar->hw->queues = 4;
4231
Bartosz Markowskif2595092013-12-10 16:20:39 +01004232 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4233 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4234 ar->hw->wiphy->n_iface_combinations =
4235 ARRAY_SIZE(ath10k_10x_if_comb);
4236 } else {
4237 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4238 ar->hw->wiphy->n_iface_combinations =
4239 ARRAY_SIZE(ath10k_if_comb);
4240 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004241
Michal Kazior7c199992013-07-31 10:47:57 +02004242 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4243
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004244 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4245 /* Init ath dfs pattern detector */
4246 ar->ath_common.debug_mask = ATH_DBG_DFS;
4247 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4248 NL80211_DFS_UNSET);
4249
4250 if (!ar->dfs_detector)
4251 ath10k_warn("dfs pattern detector init failed\n");
4252 }
4253
Kalle Valo5e3dd152013-06-12 20:52:10 +03004254 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4255 ath10k_reg_notifier);
4256 if (ret) {
4257 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02004258 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004259 }
4260
4261 ret = ieee80211_register_hw(ar->hw);
4262 if (ret) {
4263 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004264 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004265 }
4266
4267 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4268 ret = regulatory_hint(ar->hw->wiphy,
4269 ar->ath_common.regulatory.alpha2);
4270 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004271 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004272 }
4273
4274 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004275
4276err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004277 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004278err_free:
4279 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4280 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4281
Kalle Valo5e3dd152013-06-12 20:52:10 +03004282 return ret;
4283}
4284
4285void ath10k_mac_unregister(struct ath10k *ar)
4286{
4287 ieee80211_unregister_hw(ar->hw);
4288
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004289 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4290 ar->dfs_detector->exit(ar->dfs_detector);
4291
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4293 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4294
4295 SET_IEEE80211_DEV(ar->hw, NULL);
4296}