blob: bb1c8397c0d34c8c8829947b65cf83f0d0f6e57d [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
71 break;
72 default:
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
88 const u8 *macaddr)
89{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Wolfram Sang16735d02013-11-14 14:32:02 -080095 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030096
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
98 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
128
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 addr);
131 if (ret)
132 return ret;
133
134 peer->keys[i] = arvif->wep_keys[i];
135 }
136
137 return 0;
138}
139
140static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
141 const u8 *addr)
142{
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
145 int first_errno = 0;
146 int ret;
147 int i;
148
149 lockdep_assert_held(&ar->conf_mutex);
150
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
154
155 if (!peer)
156 return -ENOENT;
157
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
160 continue;
161
162 ret = ath10k_install_key(arvif, peer->keys[i],
163 DISABLE_KEY, addr);
164 if (ret && first_errno == 0)
165 first_errno = ret;
166
167 if (ret)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
169 i, ret);
170
171 peer->keys[i] = NULL;
172 }
173
174 return first_errno;
175}
176
177static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
179{
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
182 u8 addr[ETH_ALEN];
183 int first_errno = 0;
184 int ret;
185 int i;
186
187 lockdep_assert_held(&ar->conf_mutex);
188
189 for (;;) {
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
193 i = 0;
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
199 break;
200 }
201 }
202
203 if (i < ARRAY_SIZE(peer->keys))
204 break;
205 }
206 spin_unlock_bh(&ar->data_lock);
207
208 if (i == ARRAY_SIZE(peer->keys))
209 break;
210
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
213 first_errno = ret;
214
215 if (ret)
216 ath10k_warn("could not remove key for %pM\n", addr);
217 }
218
219 return first_errno;
220}
221
222
223/*********************/
224/* General utilities */
225/*********************/
226
227static inline enum wmi_phy_mode
228chan_to_phymode(const struct cfg80211_chan_def *chandef)
229{
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
236 phymode = MODE_11G;
237 break;
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
240 break;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
243 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
250 break;
251 }
252 break;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
256 phymode = MODE_11A;
257 break;
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
260 break;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
266 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
272 break;
273 }
274 break;
275 default:
276 break;
277 }
278
279 WARN_ON(phymode == MODE_UNKNOWN);
280 return phymode;
281}
282
283static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
284{
285/*
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
288 * 1 for 1/4 us
289 * 2 for 1/2 us
290 * 3 for 1 us
291 * 4 for 2 us
292 * 5 for 4 us
293 * 6 for 8 us
294 * 7 for 16 us
295 */
296 switch (mpdudensity) {
297 case 0:
298 return 0;
299 case 1:
300 case 2:
301 case 3:
302 /* Our lower layer calculations limit our precision to
303 1 microsecond */
304 return 1;
305 case 4:
306 return 2;
307 case 5:
308 return 4;
309 case 6:
310 return 8;
311 case 7:
312 return 16;
313 default:
314 return 0;
315 }
316}
317
318static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
319{
320 int ret;
321
322 lockdep_assert_held(&ar->conf_mutex);
323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800325 if (ret) {
326 ath10k_warn("Failed to create wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300329
330 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800331 if (ret) {
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100335 spin_lock_bh(&ar->data_lock);
336 ar->num_peers++;
337 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300338
339 return 0;
340}
341
Kalle Valo5a13e762014-01-20 11:01:46 +0200342static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
343{
344 struct ath10k *ar = arvif->ar;
345 u32 param;
346 int ret;
347
348 param = ar->wmi.pdev_param->sta_kickout_th;
349 ret = ath10k_wmi_pdev_set_param(ar, param,
350 ATH10K_KICKOUT_THRESHOLD);
351 if (ret) {
352 ath10k_warn("Failed to set kickout threshold: %d\n", ret);
353 return ret;
354 }
355
356 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
358 ATH10K_KEEPALIVE_MIN_IDLE);
359 if (ret) {
360 ath10k_warn("Failed to set keepalive minimum idle time : %d\n",
361 ret);
362 return ret;
363 }
364
365 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
366 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
367 ATH10K_KEEPALIVE_MAX_IDLE);
368 if (ret) {
369 ath10k_warn("Failed to set keepalive maximum idle time: %d\n",
370 ret);
371 return ret;
372 }
373
374 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
375 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
376 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
377 if (ret) {
378 ath10k_warn("Failed to set keepalive maximum unresponsive time: %d\n",
379 ret);
380 return ret;
381 }
382
383 return 0;
384}
385
Michal Kazior424121c2013-07-22 14:13:31 +0200386static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
387{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200388 struct ath10k *ar = arvif->ar;
389 u32 vdev_param;
390
Michal Kazior424121c2013-07-22 14:13:31 +0200391 if (value != 0xFFFFFFFF)
392 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
393 ATH10K_RTS_MAX);
394
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200395 vdev_param = ar->wmi.vdev_param->rts_threshold;
396 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200397}
398
399static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
400{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200401 struct ath10k *ar = arvif->ar;
402 u32 vdev_param;
403
Michal Kazior424121c2013-07-22 14:13:31 +0200404 if (value != 0xFFFFFFFF)
405 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
406 ATH10K_FRAGMT_THRESHOLD_MIN,
407 ATH10K_FRAGMT_THRESHOLD_MAX);
408
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
410 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200411}
412
Kalle Valo5e3dd152013-06-12 20:52:10 +0300413static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
414{
415 int ret;
416
417 lockdep_assert_held(&ar->conf_mutex);
418
419 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
420 if (ret)
421 return ret;
422
423 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
424 if (ret)
425 return ret;
426
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100427 spin_lock_bh(&ar->data_lock);
428 ar->num_peers--;
429 spin_unlock_bh(&ar->data_lock);
430
Kalle Valo5e3dd152013-06-12 20:52:10 +0300431 return 0;
432}
433
434static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
435{
436 struct ath10k_peer *peer, *tmp;
437
438 lockdep_assert_held(&ar->conf_mutex);
439
440 spin_lock_bh(&ar->data_lock);
441 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
442 if (peer->vdev_id != vdev_id)
443 continue;
444
445 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
446 peer->addr, vdev_id);
447
448 list_del(&peer->list);
449 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100450 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300451 }
452 spin_unlock_bh(&ar->data_lock);
453}
454
Michal Kaziora96d7742013-07-16 09:38:56 +0200455static void ath10k_peer_cleanup_all(struct ath10k *ar)
456{
457 struct ath10k_peer *peer, *tmp;
458
459 lockdep_assert_held(&ar->conf_mutex);
460
461 spin_lock_bh(&ar->data_lock);
462 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
463 list_del(&peer->list);
464 kfree(peer);
465 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100466 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200467 spin_unlock_bh(&ar->data_lock);
468}
469
Kalle Valo5e3dd152013-06-12 20:52:10 +0300470/************************/
471/* Interface management */
472/************************/
473
474static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
475{
476 int ret;
477
Michal Kazior548db542013-07-05 16:15:15 +0300478 lockdep_assert_held(&ar->conf_mutex);
479
Kalle Valo5e3dd152013-06-12 20:52:10 +0300480 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
481 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
482 if (ret == 0)
483 return -ETIMEDOUT;
484
485 return 0;
486}
487
488static int ath10k_vdev_start(struct ath10k_vif *arvif)
489{
490 struct ath10k *ar = arvif->ar;
Michal Kaziorc930f742014-01-23 11:38:25 +0100491 struct cfg80211_chan_def *chandef = &ar->chandef;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300492 struct wmi_vdev_start_request_arg arg = {};
493 int ret = 0;
494
495 lockdep_assert_held(&ar->conf_mutex);
496
Wolfram Sang16735d02013-11-14 14:32:02 -0800497 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300498
499 arg.vdev_id = arvif->vdev_id;
500 arg.dtim_period = arvif->dtim_period;
501 arg.bcn_intval = arvif->beacon_interval;
502
Michal Kaziorc930f742014-01-23 11:38:25 +0100503 arg.channel.freq = chandef->chan->center_freq;
504 arg.channel.band_center_freq1 = chandef->center_freq1;
505 arg.channel.mode = chan_to_phymode(chandef);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300506
Michal Kazior89c5c842013-10-23 04:02:13 -0700507 arg.channel.min_power = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +0100508 arg.channel.max_power = chandef->chan->max_power * 2;
509 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
510 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300511
512 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
513 arg.ssid = arvif->u.ap.ssid;
514 arg.ssid_len = arvif->u.ap.ssid_len;
515 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200516
517 /* For now allow DFS for AP mode */
518 arg.channel.chan_radar =
Michal Kaziorc930f742014-01-23 11:38:25 +0100519 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300520 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
521 arg.ssid = arvif->vif->bss_conf.ssid;
522 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
523 }
524
Kalle Valo38a1d472013-09-08 17:56:14 +0300525 ath10k_dbg(ATH10K_DBG_MAC,
526 "mac vdev %d start center_freq %d phymode %s\n",
527 arg.vdev_id, arg.channel.freq,
528 ath10k_wmi_phymode_str(arg.channel.mode));
529
Kalle Valo5e3dd152013-06-12 20:52:10 +0300530 ret = ath10k_wmi_vdev_start(ar, &arg);
531 if (ret) {
532 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
533 return ret;
534 }
535
536 ret = ath10k_vdev_setup_sync(ar);
537 if (ret) {
538 ath10k_warn("vdev setup failed %d\n", ret);
539 return ret;
540 }
541
542 return ret;
543}
544
545static int ath10k_vdev_stop(struct ath10k_vif *arvif)
546{
547 struct ath10k *ar = arvif->ar;
548 int ret;
549
550 lockdep_assert_held(&ar->conf_mutex);
551
Wolfram Sang16735d02013-11-14 14:32:02 -0800552 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300553
554 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
555 if (ret) {
556 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
557 return ret;
558 }
559
560 ret = ath10k_vdev_setup_sync(ar);
561 if (ret) {
562 ath10k_warn("vdev setup failed %d\n", ret);
563 return ret;
564 }
565
566 return ret;
567}
568
569static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
570{
Michal Kaziorc930f742014-01-23 11:38:25 +0100571 struct cfg80211_chan_def *chandef = &ar->chandef;
572 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300573 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300574 int ret = 0;
575
576 lockdep_assert_held(&ar->conf_mutex);
577
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300578 if (!ar->monitor_present) {
579 ath10k_warn("mac montor stop -- monitor is not present\n");
580 return -EINVAL;
581 }
582
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583 arg.vdev_id = vdev_id;
584 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100585 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300586
587 /* TODO setup this dynamically, what in case we
588 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100589 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200590 arg.channel.chan_radar =
591 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592
Michal Kazior89c5c842013-10-23 04:02:13 -0700593 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700594 arg.channel.max_power = channel->max_power * 2;
595 arg.channel.max_reg_power = channel->max_reg_power * 2;
596 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300597
598 ret = ath10k_wmi_vdev_start(ar, &arg);
599 if (ret) {
600 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
601 return ret;
602 }
603
604 ret = ath10k_vdev_setup_sync(ar);
605 if (ret) {
606 ath10k_warn("Monitor vdev setup failed %d\n", ret);
607 return ret;
608 }
609
610 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
611 if (ret) {
612 ath10k_warn("Monitor vdev up failed: %d\n", ret);
613 goto vdev_stop;
614 }
615
616 ar->monitor_vdev_id = vdev_id;
617 ar->monitor_enabled = true;
618
619 return 0;
620
621vdev_stop:
622 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
623 if (ret)
624 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
625
626 return ret;
627}
628
629static int ath10k_monitor_stop(struct ath10k *ar)
630{
631 int ret = 0;
632
633 lockdep_assert_held(&ar->conf_mutex);
634
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300635 if (!ar->monitor_present) {
636 ath10k_warn("mac montor stop -- monitor is not present\n");
637 return -EINVAL;
638 }
639
640 if (!ar->monitor_enabled) {
641 ath10k_warn("mac montor stop -- monitor is not enabled\n");
642 return -EINVAL;
643 }
644
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200645 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
646 if (ret)
647 ath10k_warn("Monitor vdev down failed: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648
649 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
650 if (ret)
651 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
652
653 ret = ath10k_vdev_setup_sync(ar);
654 if (ret)
655 ath10k_warn("Monitor_down sync failed: %d\n", ret);
656
657 ar->monitor_enabled = false;
658 return ret;
659}
660
661static int ath10k_monitor_create(struct ath10k *ar)
662{
663 int bit, ret = 0;
664
665 lockdep_assert_held(&ar->conf_mutex);
666
667 if (ar->monitor_present) {
668 ath10k_warn("Monitor mode already enabled\n");
669 return 0;
670 }
671
672 bit = ffs(ar->free_vdev_map);
673 if (bit == 0) {
674 ath10k_warn("No free VDEV slots\n");
675 return -ENOMEM;
676 }
677
678 ar->monitor_vdev_id = bit - 1;
679 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
680
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr);
684 if (ret) {
685 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
686 goto vdev_fail;
687 }
688
Kalle Valo60c3daa2013-09-08 17:56:07 +0300689 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300690 ar->monitor_vdev_id);
691
692 ar->monitor_present = true;
693 return 0;
694
695vdev_fail:
696 /*
697 * Restore the ID to the global map.
698 */
699 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
700 return ret;
701}
702
703static int ath10k_monitor_destroy(struct ath10k *ar)
704{
705 int ret = 0;
706
707 lockdep_assert_held(&ar->conf_mutex);
708
709 if (!ar->monitor_present)
710 return 0;
711
712 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
713 if (ret) {
714 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
715 return ret;
716 }
717
718 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
719 ar->monitor_present = false;
720
Kalle Valo60c3daa2013-09-08 17:56:07 +0300721 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300722 ar->monitor_vdev_id);
723 return ret;
724}
725
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200726static int ath10k_start_cac(struct ath10k *ar)
727{
728 int ret;
729
730 lockdep_assert_held(&ar->conf_mutex);
731
732 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
733
734 ret = ath10k_monitor_create(ar);
735 if (ret) {
736 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
737 return ret;
738 }
739
740 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
741 if (ret) {
742 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
743 ath10k_monitor_destroy(ar);
744 return ret;
745 }
746
747 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
748 ar->monitor_vdev_id);
749
750 return 0;
751}
752
753static int ath10k_stop_cac(struct ath10k *ar)
754{
755 lockdep_assert_held(&ar->conf_mutex);
756
757 /* CAC is not running - do nothing */
758 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
759 return 0;
760
761 ath10k_monitor_stop(ar);
762 ath10k_monitor_destroy(ar);
763 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
764
765 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
766
767 return 0;
768}
769
770static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
771{
772 switch (dfs_state) {
773 case NL80211_DFS_USABLE:
774 return "USABLE";
775 case NL80211_DFS_UNAVAILABLE:
776 return "UNAVAILABLE";
777 case NL80211_DFS_AVAILABLE:
778 return "AVAILABLE";
779 default:
780 WARN_ON(1);
781 return "bug";
782 }
783}
784
785static void ath10k_config_radar_detection(struct ath10k *ar)
786{
787 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
788 bool radar = ar->hw->conf.radar_enabled;
789 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
790 enum nl80211_dfs_state dfs_state = chan->dfs_state;
791 int ret;
792
793 lockdep_assert_held(&ar->conf_mutex);
794
795 ath10k_dbg(ATH10K_DBG_MAC,
796 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
797 chan->center_freq, radar, chan_radar,
798 ath10k_dfs_state(dfs_state));
799
800 /*
801 * It's safe to call it even if CAC is not started.
802 * This call here guarantees changing channel, etc. will stop CAC.
803 */
804 ath10k_stop_cac(ar);
805
806 if (!radar)
807 return;
808
809 if (!chan_radar)
810 return;
811
812 if (dfs_state != NL80211_DFS_USABLE)
813 return;
814
815 ret = ath10k_start_cac(ar);
816 if (ret) {
817 /*
818 * Not possible to start CAC on current channel so starting
819 * radiation is not allowed, make this channel DFS_UNAVAILABLE
820 * by indicating that radar was detected.
821 */
822 ath10k_warn("failed to start CAC (%d)\n", ret);
823 ieee80211_radar_detected(ar->hw);
824 }
825}
826
Kalle Valo5e3dd152013-06-12 20:52:10 +0300827static void ath10k_control_beaconing(struct ath10k_vif *arvif,
828 struct ieee80211_bss_conf *info)
829{
830 int ret = 0;
831
Michal Kazior548db542013-07-05 16:15:15 +0300832 lockdep_assert_held(&arvif->ar->conf_mutex);
833
Kalle Valo5e3dd152013-06-12 20:52:10 +0300834 if (!info->enable_beacon) {
835 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100836
837 arvif->is_started = false;
838 arvif->is_up = false;
839
Michal Kazior748afc42014-01-23 12:48:21 +0100840 spin_lock_bh(&arvif->ar->data_lock);
841 if (arvif->beacon) {
842 ath10k_skb_unmap(arvif->ar->dev, arvif->beacon);
843 dev_kfree_skb_any(arvif->beacon);
844
845 arvif->beacon = NULL;
846 arvif->beacon_sent = false;
847 }
848 spin_unlock_bh(&arvif->ar->data_lock);
849
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850 return;
851 }
852
853 arvif->tx_seq_no = 0x1000;
854
855 ret = ath10k_vdev_start(arvif);
856 if (ret)
857 return;
858
Michal Kaziorc930f742014-01-23 11:38:25 +0100859 arvif->aid = 0;
860 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
861
862 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
863 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300864 if (ret) {
865 ath10k_warn("Failed to bring up VDEV: %d\n",
866 arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +0100867 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868 return;
869 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100870
871 arvif->is_started = true;
872 arvif->is_up = true;
873
Kalle Valo60c3daa2013-09-08 17:56:07 +0300874 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300875}
876
877static void ath10k_control_ibss(struct ath10k_vif *arvif,
878 struct ieee80211_bss_conf *info,
879 const u8 self_peer[ETH_ALEN])
880{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200881 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 int ret = 0;
883
Michal Kazior548db542013-07-05 16:15:15 +0300884 lockdep_assert_held(&arvif->ar->conf_mutex);
885
Kalle Valo5e3dd152013-06-12 20:52:10 +0300886 if (!info->ibss_joined) {
887 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
888 if (ret)
889 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
890 self_peer, arvif->vdev_id, ret);
891
Michal Kaziorc930f742014-01-23 11:38:25 +0100892 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300893 return;
894
895 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100896 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300897 if (ret) {
898 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100899 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300900 return;
901 }
902
Michal Kaziorc930f742014-01-23 11:38:25 +0100903 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300904
905 return;
906 }
907
908 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
909 if (ret) {
910 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
911 self_peer, arvif->vdev_id, ret);
912 return;
913 }
914
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200915 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
916 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917 ATH10K_DEFAULT_ATIM);
918 if (ret)
919 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
920 arvif->vdev_id, ret);
921}
922
923/*
924 * Review this when mac80211 gains per-interface powersave support.
925 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300926static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300927{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300928 struct ath10k *ar = arvif->ar;
929 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300930 enum wmi_sta_powersave_param param;
931 enum wmi_sta_ps_mode psmode;
932 int ret;
933
Michal Kazior548db542013-07-05 16:15:15 +0300934 lockdep_assert_held(&arvif->ar->conf_mutex);
935
Michal Kaziorad088bf2013-10-16 15:44:46 +0300936 if (arvif->vif->type != NL80211_IFTYPE_STATION)
937 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938
939 if (conf->flags & IEEE80211_CONF_PS) {
940 psmode = WMI_STA_PS_MODE_ENABLED;
941 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
942
Michal Kaziorad088bf2013-10-16 15:44:46 +0300943 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944 conf->dynamic_ps_timeout);
945 if (ret) {
946 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
947 arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300948 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300950 } else {
951 psmode = WMI_STA_PS_MODE_DISABLED;
952 }
953
Kalle Valo60c3daa2013-09-08 17:56:07 +0300954 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
955 arvif->vdev_id, psmode ? "enable" : "disable");
956
Michal Kaziorad088bf2013-10-16 15:44:46 +0300957 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
958 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300959 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
960 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300961 return ret;
962 }
963
964 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300965}
966
967/**********************/
968/* Station management */
969/**********************/
970
971static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
972 struct ath10k_vif *arvif,
973 struct ieee80211_sta *sta,
974 struct ieee80211_bss_conf *bss_conf,
975 struct wmi_peer_assoc_complete_arg *arg)
976{
Michal Kazior548db542013-07-05 16:15:15 +0300977 lockdep_assert_held(&ar->conf_mutex);
978
Kalle Valo5e3dd152013-06-12 20:52:10 +0300979 memcpy(arg->addr, sta->addr, ETH_ALEN);
980 arg->vdev_id = arvif->vdev_id;
981 arg->peer_aid = sta->aid;
982 arg->peer_flags |= WMI_PEER_AUTH;
983
984 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
985 /*
986 * Seems FW have problems with Power Save in STA
987 * mode when we setup this parameter to high (eg. 5).
988 * Often we see that FW don't send NULL (with clean P flags)
989 * frame even there is info about buffered frames in beacons.
990 * Sometimes we have to wait more than 10 seconds before FW
991 * will wakeup. Often sending one ping from AP to our device
992 * just fail (more than 50%).
993 *
994 * Seems setting this FW parameter to 1 couse FW
995 * will check every beacon and will wakup immediately
996 * after detection buffered data.
997 */
998 arg->peer_listen_intval = 1;
999 else
1000 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1001
1002 arg->peer_num_spatial_streams = 1;
1003
1004 /*
1005 * The assoc capabilities are available only in managed mode.
1006 */
1007 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1008 arg->peer_caps = bss_conf->assoc_capability;
1009}
1010
1011static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1012 struct ath10k_vif *arvif,
1013 struct wmi_peer_assoc_complete_arg *arg)
1014{
1015 struct ieee80211_vif *vif = arvif->vif;
1016 struct ieee80211_bss_conf *info = &vif->bss_conf;
1017 struct cfg80211_bss *bss;
1018 const u8 *rsnie = NULL;
1019 const u8 *wpaie = NULL;
1020
Michal Kazior548db542013-07-05 16:15:15 +03001021 lockdep_assert_held(&ar->conf_mutex);
1022
Kalle Valo5e3dd152013-06-12 20:52:10 +03001023 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1024 info->bssid, NULL, 0, 0, 0);
1025 if (bss) {
1026 const struct cfg80211_bss_ies *ies;
1027
1028 rcu_read_lock();
1029 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1030
1031 ies = rcu_dereference(bss->ies);
1032
1033 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1034 WLAN_OUI_TYPE_MICROSOFT_WPA,
1035 ies->data,
1036 ies->len);
1037 rcu_read_unlock();
1038 cfg80211_put_bss(ar->hw->wiphy, bss);
1039 }
1040
1041 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1042 if (rsnie || wpaie) {
1043 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1044 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1045 }
1046
1047 if (wpaie) {
1048 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1049 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1050 }
1051}
1052
1053static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1054 struct ieee80211_sta *sta,
1055 struct wmi_peer_assoc_complete_arg *arg)
1056{
1057 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1058 const struct ieee80211_supported_band *sband;
1059 const struct ieee80211_rate *rates;
1060 u32 ratemask;
1061 int i;
1062
Michal Kazior548db542013-07-05 16:15:15 +03001063 lockdep_assert_held(&ar->conf_mutex);
1064
Kalle Valo5e3dd152013-06-12 20:52:10 +03001065 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1066 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1067 rates = sband->bitrates;
1068
1069 rateset->num_rates = 0;
1070
1071 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1072 if (!(ratemask & 1))
1073 continue;
1074
1075 rateset->rates[rateset->num_rates] = rates->hw_value;
1076 rateset->num_rates++;
1077 }
1078}
1079
1080static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1081 struct ieee80211_sta *sta,
1082 struct wmi_peer_assoc_complete_arg *arg)
1083{
1084 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1085 int smps;
1086 int i, n;
1087
Michal Kazior548db542013-07-05 16:15:15 +03001088 lockdep_assert_held(&ar->conf_mutex);
1089
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090 if (!ht_cap->ht_supported)
1091 return;
1092
1093 arg->peer_flags |= WMI_PEER_HT;
1094 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1095 ht_cap->ampdu_factor)) - 1;
1096
1097 arg->peer_mpdu_density =
1098 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1099
1100 arg->peer_ht_caps = ht_cap->cap;
1101 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1102
1103 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1104 arg->peer_flags |= WMI_PEER_LDPC;
1105
1106 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1107 arg->peer_flags |= WMI_PEER_40MHZ;
1108 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1109 }
1110
1111 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1112 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1113
1114 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1115 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1116
1117 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1118 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1119 arg->peer_flags |= WMI_PEER_STBC;
1120 }
1121
1122 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1123 u32 stbc;
1124 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1125 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1126 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1127 arg->peer_rate_caps |= stbc;
1128 arg->peer_flags |= WMI_PEER_STBC;
1129 }
1130
1131 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1132 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1133
1134 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1135 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1136 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1137 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1138 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1139 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1140 }
1141
1142 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1143 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1144 else if (ht_cap->mcs.rx_mask[1])
1145 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1146
1147 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1148 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1149 arg->peer_ht_rates.rates[n++] = i;
1150
1151 arg->peer_ht_rates.num_rates = n;
1152 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
1153
Kalle Valo60c3daa2013-09-08 17:56:07 +03001154 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1155 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001156 arg->peer_ht_rates.num_rates,
1157 arg->peer_num_spatial_streams);
1158}
1159
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001160static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1161 struct ath10k_vif *arvif,
1162 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001163{
1164 u32 uapsd = 0;
1165 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001166 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001167
Michal Kazior548db542013-07-05 16:15:15 +03001168 lockdep_assert_held(&ar->conf_mutex);
1169
Kalle Valo5e3dd152013-06-12 20:52:10 +03001170 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001171 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172 sta->uapsd_queues, sta->max_sp);
1173
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1175 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1176 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1177 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1178 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1179 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1180 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1181 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1182 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1183 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1184 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1185 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1186
1187
1188 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1189 max_sp = sta->max_sp;
1190
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_UAPSD,
1194 uapsd);
1195 if (ret) {
1196 ath10k_warn("failed to set ap ps peer param uapsd: %d\n",
1197 ret);
1198 return ret;
1199 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001200
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001201 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1202 sta->addr,
1203 WMI_AP_PS_PEER_PARAM_MAX_SP,
1204 max_sp);
1205 if (ret) {
1206 ath10k_warn("failed to set ap ps peer param max sp: %d\n",
1207 ret);
1208 return ret;
1209 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001210
1211 /* TODO setup this based on STA listen interval and
1212 beacon interval. Currently we don't know
1213 sta->listen_interval - mac80211 patch required.
1214 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001215 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1216 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1217 if (ret) {
1218 ath10k_warn("failed to set ap ps peer param ageout time: %d\n",
1219 ret);
1220 return ret;
1221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001222 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001223
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001224 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001225}
1226
1227static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1228 struct ieee80211_sta *sta,
1229 struct wmi_peer_assoc_complete_arg *arg)
1230{
1231 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001232 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001233
1234 if (!vht_cap->vht_supported)
1235 return;
1236
1237 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001238 arg->peer_vht_caps = vht_cap->cap;
1239
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001240
1241 ampdu_factor = (vht_cap->cap &
1242 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1243 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1244
1245 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1246 * zero in VHT IE. Using it would result in degraded throughput.
1247 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1248 * it if VHT max_mpdu is smaller. */
1249 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1250 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1251 ampdu_factor)) - 1);
1252
Kalle Valo5e3dd152013-06-12 20:52:10 +03001253 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1254 arg->peer_flags |= WMI_PEER_80MHZ;
1255
1256 arg->peer_vht_rates.rx_max_rate =
1257 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1258 arg->peer_vht_rates.rx_mcs_set =
1259 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1260 arg->peer_vht_rates.tx_max_rate =
1261 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1262 arg->peer_vht_rates.tx_mcs_set =
1263 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1264
Kalle Valo60c3daa2013-09-08 17:56:07 +03001265 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1266 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267}
1268
1269static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1270 struct ath10k_vif *arvif,
1271 struct ieee80211_sta *sta,
1272 struct ieee80211_bss_conf *bss_conf,
1273 struct wmi_peer_assoc_complete_arg *arg)
1274{
1275 switch (arvif->vdev_type) {
1276 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001277 if (sta->wme)
1278 arg->peer_flags |= WMI_PEER_QOS;
1279
1280 if (sta->wme && sta->uapsd_queues) {
1281 arg->peer_flags |= WMI_PEER_APSD;
1282 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001284 break;
1285 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001286 if (bss_conf->qos)
1287 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288 break;
1289 default:
1290 break;
1291 }
1292}
1293
1294static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1295 struct ath10k_vif *arvif,
1296 struct ieee80211_sta *sta,
1297 struct wmi_peer_assoc_complete_arg *arg)
1298{
1299 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1300
Kalle Valo5e3dd152013-06-12 20:52:10 +03001301 switch (ar->hw->conf.chandef.chan->band) {
1302 case IEEE80211_BAND_2GHZ:
1303 if (sta->ht_cap.ht_supported) {
1304 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1305 phymode = MODE_11NG_HT40;
1306 else
1307 phymode = MODE_11NG_HT20;
1308 } else {
1309 phymode = MODE_11G;
1310 }
1311
1312 break;
1313 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001314 /*
1315 * Check VHT first.
1316 */
1317 if (sta->vht_cap.vht_supported) {
1318 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1319 phymode = MODE_11AC_VHT80;
1320 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1321 phymode = MODE_11AC_VHT40;
1322 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1323 phymode = MODE_11AC_VHT20;
1324 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001325 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1326 phymode = MODE_11NA_HT40;
1327 else
1328 phymode = MODE_11NA_HT20;
1329 } else {
1330 phymode = MODE_11A;
1331 }
1332
1333 break;
1334 default:
1335 break;
1336 }
1337
Kalle Valo38a1d472013-09-08 17:56:14 +03001338 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1339 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001340
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341 arg->peer_phymode = phymode;
1342 WARN_ON(phymode == MODE_UNKNOWN);
1343}
1344
Kalle Valob9ada652013-10-16 15:44:46 +03001345static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1346 struct ath10k_vif *arvif,
1347 struct ieee80211_sta *sta,
1348 struct ieee80211_bss_conf *bss_conf,
1349 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001350{
Michal Kazior548db542013-07-05 16:15:15 +03001351 lockdep_assert_held(&ar->conf_mutex);
1352
Kalle Valob9ada652013-10-16 15:44:46 +03001353 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001354
Kalle Valob9ada652013-10-16 15:44:46 +03001355 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1356 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1357 ath10k_peer_assoc_h_rates(ar, sta, arg);
1358 ath10k_peer_assoc_h_ht(ar, sta, arg);
1359 ath10k_peer_assoc_h_vht(ar, sta, arg);
1360 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1361 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362
Kalle Valob9ada652013-10-16 15:44:46 +03001363 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364}
1365
1366/* can be called only in mac80211 callbacks due to `key_count` usage */
1367static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1368 struct ieee80211_vif *vif,
1369 struct ieee80211_bss_conf *bss_conf)
1370{
1371 struct ath10k *ar = hw->priv;
1372 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001373 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001374 struct ieee80211_sta *ap_sta;
1375 int ret;
1376
Michal Kazior548db542013-07-05 16:15:15 +03001377 lockdep_assert_held(&ar->conf_mutex);
1378
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 rcu_read_lock();
1380
1381 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1382 if (!ap_sta) {
1383 ath10k_warn("Failed to find station entry for %pM\n",
1384 bss_conf->bssid);
1385 rcu_read_unlock();
1386 return;
1387 }
1388
Kalle Valob9ada652013-10-16 15:44:46 +03001389 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1390 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001391 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001392 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1393 bss_conf->bssid, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001394 rcu_read_unlock();
1395 return;
1396 }
1397
1398 rcu_read_unlock();
1399
Kalle Valob9ada652013-10-16 15:44:46 +03001400 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1401 if (ret) {
1402 ath10k_warn("Peer assoc failed for %pM\n: %d",
1403 bss_conf->bssid, ret);
1404 return;
1405 }
1406
Kalle Valo60c3daa2013-09-08 17:56:07 +03001407 ath10k_dbg(ATH10K_DBG_MAC,
1408 "mac vdev %d up (associated) bssid %pM aid %d\n",
1409 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1410
Michal Kaziorc930f742014-01-23 11:38:25 +01001411 arvif->aid = bss_conf->aid;
1412 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1413
1414 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1415 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001416 ath10k_warn("VDEV: %d up failed: ret %d\n",
1417 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001418 return;
1419 }
1420
1421 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001422}
1423
1424/*
1425 * FIXME: flush TIDs
1426 */
1427static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1428 struct ieee80211_vif *vif)
1429{
1430 struct ath10k *ar = hw->priv;
1431 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1432 int ret;
1433
Michal Kazior548db542013-07-05 16:15:15 +03001434 lockdep_assert_held(&ar->conf_mutex);
1435
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436 /*
1437 * For some reason, calling VDEV-DOWN before VDEV-STOP
1438 * makes the FW to send frames via HTT after disassociation.
1439 * No idea why this happens, even though VDEV-DOWN is supposed
1440 * to be analogous to link down, so just stop the VDEV.
1441 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001442 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1443 arvif->vdev_id);
1444
1445 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001446 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447
1448 /*
1449 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1450 * report beacons from previously associated network through HTT.
1451 * This in turn would spam mac80211 WARN_ON if we bring down all
1452 * interfaces as it expects there is no rx when no interface is
1453 * running.
1454 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001455 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1456
1457 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001458 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001460 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001461
1462 arvif->is_started = false;
1463 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001464}
1465
1466static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1467 struct ieee80211_sta *sta)
1468{
Kalle Valob9ada652013-10-16 15:44:46 +03001469 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001470 int ret = 0;
1471
Michal Kazior548db542013-07-05 16:15:15 +03001472 lockdep_assert_held(&ar->conf_mutex);
1473
Kalle Valob9ada652013-10-16 15:44:46 +03001474 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001475 if (ret) {
Kalle Valob9ada652013-10-16 15:44:46 +03001476 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1477 sta->addr);
1478 return ret;
1479 }
1480
1481 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1482 if (ret) {
1483 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1484 sta->addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 return ret;
1486 }
1487
1488 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1489 if (ret) {
1490 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1491 return ret;
1492 }
1493
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001494 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1495 if (ret) {
1496 ath10k_warn("could not set qos params for STA %pM, %d\n",
1497 sta->addr, ret);
1498 return ret;
1499 }
1500
Kalle Valo5e3dd152013-06-12 20:52:10 +03001501 return ret;
1502}
1503
1504static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1505 struct ieee80211_sta *sta)
1506{
1507 int ret = 0;
1508
Michal Kazior548db542013-07-05 16:15:15 +03001509 lockdep_assert_held(&ar->conf_mutex);
1510
Kalle Valo5e3dd152013-06-12 20:52:10 +03001511 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1512 if (ret) {
1513 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1514 return ret;
1515 }
1516
1517 return ret;
1518}
1519
1520/**************/
1521/* Regulatory */
1522/**************/
1523
1524static int ath10k_update_channel_list(struct ath10k *ar)
1525{
1526 struct ieee80211_hw *hw = ar->hw;
1527 struct ieee80211_supported_band **bands;
1528 enum ieee80211_band band;
1529 struct ieee80211_channel *channel;
1530 struct wmi_scan_chan_list_arg arg = {0};
1531 struct wmi_channel_arg *ch;
1532 bool passive;
1533 int len;
1534 int ret;
1535 int i;
1536
Michal Kazior548db542013-07-05 16:15:15 +03001537 lockdep_assert_held(&ar->conf_mutex);
1538
Kalle Valo5e3dd152013-06-12 20:52:10 +03001539 bands = hw->wiphy->bands;
1540 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1541 if (!bands[band])
1542 continue;
1543
1544 for (i = 0; i < bands[band]->n_channels; i++) {
1545 if (bands[band]->channels[i].flags &
1546 IEEE80211_CHAN_DISABLED)
1547 continue;
1548
1549 arg.n_channels++;
1550 }
1551 }
1552
1553 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1554 arg.channels = kzalloc(len, GFP_KERNEL);
1555 if (!arg.channels)
1556 return -ENOMEM;
1557
1558 ch = arg.channels;
1559 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1560 if (!bands[band])
1561 continue;
1562
1563 for (i = 0; i < bands[band]->n_channels; i++) {
1564 channel = &bands[band]->channels[i];
1565
1566 if (channel->flags & IEEE80211_CHAN_DISABLED)
1567 continue;
1568
1569 ch->allow_ht = true;
1570
1571 /* FIXME: when should we really allow VHT? */
1572 ch->allow_vht = true;
1573
1574 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001575 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576
1577 ch->ht40plus =
1578 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1579
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001580 ch->chan_radar =
1581 !!(channel->flags & IEEE80211_CHAN_RADAR);
1582
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001583 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584 ch->passive = passive;
1585
1586 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001587 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001588 ch->max_power = channel->max_power * 2;
1589 ch->max_reg_power = channel->max_reg_power * 2;
1590 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591 ch->reg_class_id = 0; /* FIXME */
1592
1593 /* FIXME: why use only legacy modes, why not any
1594 * HT/VHT modes? Would that even make any
1595 * difference? */
1596 if (channel->band == IEEE80211_BAND_2GHZ)
1597 ch->mode = MODE_11G;
1598 else
1599 ch->mode = MODE_11A;
1600
1601 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1602 continue;
1603
1604 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001605 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1606 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 ch->freq, ch->max_power, ch->max_reg_power,
1608 ch->max_antenna_gain, ch->mode);
1609
1610 ch++;
1611 }
1612 }
1613
1614 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1615 kfree(arg.channels);
1616
1617 return ret;
1618}
1619
Michal Kaziorf7843d72013-07-16 09:38:52 +02001620static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 int ret;
1624
Michal Kaziorf7843d72013-07-16 09:38:52 +02001625 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626
1627 ret = ath10k_update_channel_list(ar);
1628 if (ret)
1629 ath10k_warn("could not update channel list (%d)\n", ret);
1630
1631 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001632
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 /* Target allows setting up per-band regdomain but ath_common provides
1634 * a combined one only */
1635 ret = ath10k_wmi_pdev_set_regdomain(ar,
1636 regpair->regDmnEnum,
1637 regpair->regDmnEnum, /* 2ghz */
1638 regpair->regDmnEnum, /* 5ghz */
1639 regpair->reg_2ghz_ctl,
1640 regpair->reg_5ghz_ctl);
1641 if (ret)
1642 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001643}
Michal Kazior548db542013-07-05 16:15:15 +03001644
Michal Kaziorf7843d72013-07-16 09:38:52 +02001645static void ath10k_reg_notifier(struct wiphy *wiphy,
1646 struct regulatory_request *request)
1647{
1648 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1649 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001650 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001651
1652 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1653
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001654 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1655 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1656 request->dfs_region);
1657 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1658 request->dfs_region);
1659 if (!result)
1660 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1661 request->dfs_region);
1662 }
1663
Michal Kaziorf7843d72013-07-16 09:38:52 +02001664 mutex_lock(&ar->conf_mutex);
1665 if (ar->state == ATH10K_STATE_ON)
1666 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001667 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668}
1669
1670/***************/
1671/* TX handlers */
1672/***************/
1673
Michal Kazior42c3aa62013-10-02 11:03:38 +02001674static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1675{
1676 if (ieee80211_is_mgmt(hdr->frame_control))
1677 return HTT_DATA_TX_EXT_TID_MGMT;
1678
1679 if (!ieee80211_is_data_qos(hdr->frame_control))
1680 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1681
1682 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1683 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1684
1685 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1686}
1687
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001688static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1689 struct ieee80211_tx_info *info)
1690{
1691 if (info->control.vif)
1692 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1693
1694 if (ar->monitor_enabled)
1695 return ar->monitor_vdev_id;
1696
1697 ath10k_warn("could not resolve vdev id\n");
1698 return 0;
1699}
1700
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701/*
1702 * Frames sent to the FW have to be in "Native Wifi" format.
1703 * Strip the QoS field from the 802.11 header.
1704 */
1705static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1706 struct ieee80211_tx_control *control,
1707 struct sk_buff *skb)
1708{
1709 struct ieee80211_hdr *hdr = (void *)skb->data;
1710 u8 *qos_ctl;
1711
1712 if (!ieee80211_is_data_qos(hdr->frame_control))
1713 return;
1714
1715 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001716 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1717 skb->data, (void *)qos_ctl - (void *)skb->data);
1718 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001719}
1720
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001721static void ath10k_tx_wep_key_work(struct work_struct *work)
1722{
1723 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1724 wep_key_work);
1725 int ret, keyidx = arvif->def_wep_key_newidx;
1726
1727 if (arvif->def_wep_key_idx == keyidx)
1728 return;
1729
1730 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1731 arvif->vdev_id, keyidx);
1732
1733 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1734 arvif->vdev_id,
1735 arvif->ar->wmi.vdev_param->def_keyid,
1736 keyidx);
1737 if (ret) {
1738 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1739 return;
1740 }
1741
1742 arvif->def_wep_key_idx = keyidx;
1743}
1744
Kalle Valo5e3dd152013-06-12 20:52:10 +03001745static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1746{
1747 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1748 struct ieee80211_vif *vif = info->control.vif;
1749 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1750 struct ath10k *ar = arvif->ar;
1751 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1752 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001753
Kalle Valo5e3dd152013-06-12 20:52:10 +03001754 if (!ieee80211_has_protected(hdr->frame_control))
1755 return;
1756
1757 if (!key)
1758 return;
1759
1760 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1761 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1762 return;
1763
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001764 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001765 return;
1766
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001767 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1768 * queueing frames until key index is updated is not an option because
1769 * sk_buff may need more processing to be done, e.g. offchannel */
1770 arvif->def_wep_key_newidx = key->keyidx;
1771 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001772}
1773
1774static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1775{
1776 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1777 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1778 struct ieee80211_vif *vif = info->control.vif;
1779 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1780
1781 /* This is case only for P2P_GO */
1782 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1783 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1784 return;
1785
1786 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1787 spin_lock_bh(&ar->data_lock);
1788 if (arvif->u.ap.noa_data)
1789 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1790 GFP_ATOMIC))
1791 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1792 arvif->u.ap.noa_data,
1793 arvif->u.ap.noa_len);
1794 spin_unlock_bh(&ar->data_lock);
1795 }
1796}
1797
1798static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1799{
1800 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001801 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802
Michal Kazior961d4c32013-08-09 10:13:34 +02001803 if (ar->htt.target_version_major >= 3) {
1804 /* Since HTT 3.0 there is no separate mgmt tx command */
1805 ret = ath10k_htt_tx(&ar->htt, skb);
1806 goto exit;
1807 }
1808
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001809 if (ieee80211_is_mgmt(hdr->frame_control)) {
1810 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1811 ar->fw_features)) {
1812 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1813 ATH10K_MAX_NUM_MGMT_PENDING) {
1814 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1815 ret = -EBUSY;
1816 goto exit;
1817 }
1818
1819 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1820 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1821 } else {
1822 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1823 }
1824 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1825 ar->fw_features) &&
1826 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001827 /* FW does not report tx status properly for NullFunc frames
1828 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001829 * those frames when it detects link/beacon loss and depends
1830 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001831 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001832 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001833 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001834 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835
Michal Kazior961d4c32013-08-09 10:13:34 +02001836exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001837 if (ret) {
1838 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1839 ieee80211_free_txskb(ar->hw, skb);
1840 }
1841}
1842
1843void ath10k_offchan_tx_purge(struct ath10k *ar)
1844{
1845 struct sk_buff *skb;
1846
1847 for (;;) {
1848 skb = skb_dequeue(&ar->offchan_tx_queue);
1849 if (!skb)
1850 break;
1851
1852 ieee80211_free_txskb(ar->hw, skb);
1853 }
1854}
1855
1856void ath10k_offchan_tx_work(struct work_struct *work)
1857{
1858 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1859 struct ath10k_peer *peer;
1860 struct ieee80211_hdr *hdr;
1861 struct sk_buff *skb;
1862 const u8 *peer_addr;
1863 int vdev_id;
1864 int ret;
1865
1866 /* FW requirement: We must create a peer before FW will send out
1867 * an offchannel frame. Otherwise the frame will be stuck and
1868 * never transmitted. We delete the peer upon tx completion.
1869 * It is unlikely that a peer for offchannel tx will already be
1870 * present. However it may be in some rare cases so account for that.
1871 * Otherwise we might remove a legitimate peer and break stuff. */
1872
1873 for (;;) {
1874 skb = skb_dequeue(&ar->offchan_tx_queue);
1875 if (!skb)
1876 break;
1877
1878 mutex_lock(&ar->conf_mutex);
1879
Kalle Valo60c3daa2013-09-08 17:56:07 +03001880 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881 skb);
1882
1883 hdr = (struct ieee80211_hdr *)skb->data;
1884 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001885 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001886
1887 spin_lock_bh(&ar->data_lock);
1888 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1889 spin_unlock_bh(&ar->data_lock);
1890
1891 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001892 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001893 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1894 peer_addr, vdev_id);
1895
1896 if (!peer) {
1897 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1898 if (ret)
1899 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1900 peer_addr, vdev_id, ret);
1901 }
1902
1903 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001904 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905 ar->offchan_tx_skb = skb;
1906 spin_unlock_bh(&ar->data_lock);
1907
1908 ath10k_tx_htt(ar, skb);
1909
1910 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1911 3 * HZ);
1912 if (ret <= 0)
1913 ath10k_warn("timed out waiting for offchannel skb %p\n",
1914 skb);
1915
1916 if (!peer) {
1917 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1918 if (ret)
1919 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1920 peer_addr, vdev_id, ret);
1921 }
1922
1923 mutex_unlock(&ar->conf_mutex);
1924 }
1925}
1926
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001927void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1928{
1929 struct sk_buff *skb;
1930
1931 for (;;) {
1932 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1933 if (!skb)
1934 break;
1935
1936 ieee80211_free_txskb(ar->hw, skb);
1937 }
1938}
1939
1940void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1941{
1942 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1943 struct sk_buff *skb;
1944 int ret;
1945
1946 for (;;) {
1947 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1948 if (!skb)
1949 break;
1950
1951 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001952 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001953 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01001954 ieee80211_free_txskb(ar->hw, skb);
1955 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001956 }
1957}
1958
Kalle Valo5e3dd152013-06-12 20:52:10 +03001959/************/
1960/* Scanning */
1961/************/
1962
1963/*
1964 * This gets called if we dont get a heart-beat during scan.
1965 * This may indicate the FW has hung and we need to abort the
1966 * scan manually to prevent cancel_hw_scan() from deadlocking
1967 */
1968void ath10k_reset_scan(unsigned long ptr)
1969{
1970 struct ath10k *ar = (struct ath10k *)ptr;
1971
1972 spin_lock_bh(&ar->data_lock);
1973 if (!ar->scan.in_progress) {
1974 spin_unlock_bh(&ar->data_lock);
1975 return;
1976 }
1977
1978 ath10k_warn("scan timeout. resetting. fw issue?\n");
1979
1980 if (ar->scan.is_roc)
1981 ieee80211_remain_on_channel_expired(ar->hw);
1982 else
1983 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1984
1985 ar->scan.in_progress = false;
1986 complete_all(&ar->scan.completed);
1987 spin_unlock_bh(&ar->data_lock);
1988}
1989
1990static int ath10k_abort_scan(struct ath10k *ar)
1991{
1992 struct wmi_stop_scan_arg arg = {
1993 .req_id = 1, /* FIXME */
1994 .req_type = WMI_SCAN_STOP_ONE,
1995 .u.scan_id = ATH10K_SCAN_ID,
1996 };
1997 int ret;
1998
1999 lockdep_assert_held(&ar->conf_mutex);
2000
2001 del_timer_sync(&ar->scan.timeout);
2002
2003 spin_lock_bh(&ar->data_lock);
2004 if (!ar->scan.in_progress) {
2005 spin_unlock_bh(&ar->data_lock);
2006 return 0;
2007 }
2008
2009 ar->scan.aborting = true;
2010 spin_unlock_bh(&ar->data_lock);
2011
2012 ret = ath10k_wmi_stop_scan(ar, &arg);
2013 if (ret) {
2014 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03002015 spin_lock_bh(&ar->data_lock);
2016 ar->scan.in_progress = false;
2017 ath10k_offchan_tx_purge(ar);
2018 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002019 return -EIO;
2020 }
2021
Kalle Valo5e3dd152013-06-12 20:52:10 +03002022 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2023 if (ret == 0)
2024 ath10k_warn("timed out while waiting for scan to stop\n");
2025
2026 /* scan completion may be done right after we timeout here, so let's
2027 * check the in_progress and tell mac80211 scan is completed. if we
2028 * don't do that and FW fails to send us scan completion indication
2029 * then userspace won't be able to scan anymore */
2030 ret = 0;
2031
2032 spin_lock_bh(&ar->data_lock);
2033 if (ar->scan.in_progress) {
2034 ath10k_warn("could not stop scan. its still in progress\n");
2035 ar->scan.in_progress = false;
2036 ath10k_offchan_tx_purge(ar);
2037 ret = -ETIMEDOUT;
2038 }
2039 spin_unlock_bh(&ar->data_lock);
2040
2041 return ret;
2042}
2043
2044static int ath10k_start_scan(struct ath10k *ar,
2045 const struct wmi_start_scan_arg *arg)
2046{
2047 int ret;
2048
2049 lockdep_assert_held(&ar->conf_mutex);
2050
2051 ret = ath10k_wmi_start_scan(ar, arg);
2052 if (ret)
2053 return ret;
2054
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2056 if (ret == 0) {
2057 ath10k_abort_scan(ar);
2058 return ret;
2059 }
2060
2061 /* the scan can complete earlier, before we even
2062 * start the timer. in that case the timer handler
2063 * checks ar->scan.in_progress and bails out if its
2064 * false. Add a 200ms margin to account event/command
2065 * processing. */
2066 mod_timer(&ar->scan.timeout, jiffies +
2067 msecs_to_jiffies(arg->max_scan_time+200));
2068 return 0;
2069}
2070
2071/**********************/
2072/* mac80211 callbacks */
2073/**********************/
2074
2075static void ath10k_tx(struct ieee80211_hw *hw,
2076 struct ieee80211_tx_control *control,
2077 struct sk_buff *skb)
2078{
2079 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2080 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2081 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002082 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083
2084 /* We should disable CCK RATE due to P2P */
2085 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2086 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2087
2088 /* we must calculate tid before we apply qos workaround
2089 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002090 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002091 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002092
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002093 /* it makes no sense to process injected frames like that */
2094 if (info->control.vif &&
2095 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2096 ath10k_tx_h_qos_workaround(hw, control, skb);
2097 ath10k_tx_h_update_wep_key(skb);
2098 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2099 ath10k_tx_h_seq_no(skb);
2100 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002102 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002103 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104 ATH10K_SKB_CB(skb)->htt.tid = tid;
2105
2106 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2107 spin_lock_bh(&ar->data_lock);
2108 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002109 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 spin_unlock_bh(&ar->data_lock);
2111
2112 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2113
2114 skb_queue_tail(&ar->offchan_tx_queue, skb);
2115 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2116 return;
2117 }
2118
2119 ath10k_tx_htt(ar, skb);
2120}
2121
2122/*
2123 * Initialize various parameters with default vaules.
2124 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002125void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002126{
2127 lockdep_assert_held(&ar->conf_mutex);
2128
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002129 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002130 del_timer_sync(&ar->scan.timeout);
2131 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002132 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002133 ath10k_peer_cleanup_all(ar);
2134 ath10k_core_stop(ar);
2135 ath10k_hif_power_down(ar);
2136
2137 spin_lock_bh(&ar->data_lock);
2138 if (ar->scan.in_progress) {
2139 del_timer(&ar->scan.timeout);
2140 ar->scan.in_progress = false;
2141 ieee80211_scan_completed(ar->hw, true);
2142 }
2143 spin_unlock_bh(&ar->data_lock);
2144}
2145
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146static int ath10k_start(struct ieee80211_hw *hw)
2147{
2148 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002149 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150
Michal Kazior548db542013-07-05 16:15:15 +03002151 mutex_lock(&ar->conf_mutex);
2152
Michal Kazioraffd3212013-07-16 09:54:35 +02002153 if (ar->state != ATH10K_STATE_OFF &&
2154 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002155 ret = -EINVAL;
2156 goto exit;
2157 }
2158
2159 ret = ath10k_hif_power_up(ar);
2160 if (ret) {
2161 ath10k_err("could not init hif (%d)\n", ret);
2162 ar->state = ATH10K_STATE_OFF;
2163 goto exit;
2164 }
2165
2166 ret = ath10k_core_start(ar);
2167 if (ret) {
2168 ath10k_err("could not init core (%d)\n", ret);
2169 ath10k_hif_power_down(ar);
2170 ar->state = ATH10K_STATE_OFF;
2171 goto exit;
2172 }
2173
Michal Kazioraffd3212013-07-16 09:54:35 +02002174 if (ar->state == ATH10K_STATE_OFF)
2175 ar->state = ATH10K_STATE_ON;
2176 else if (ar->state == ATH10K_STATE_RESTARTING)
2177 ar->state = ATH10K_STATE_RESTARTED;
2178
Bartosz Markowski226a3392013-09-26 17:47:16 +02002179 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180 if (ret)
2181 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2182 ret);
2183
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002184 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 if (ret)
2186 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2187 ret);
2188
Michal Kaziorf7843d72013-07-16 09:38:52 +02002189 ath10k_regd_update(ar);
2190
Michal Kazior818bdd12013-07-16 09:38:57 +02002191exit:
Michal Kazior548db542013-07-05 16:15:15 +03002192 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193 return 0;
2194}
2195
2196static void ath10k_stop(struct ieee80211_hw *hw)
2197{
2198 struct ath10k *ar = hw->priv;
2199
Michal Kazior548db542013-07-05 16:15:15 +03002200 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002201 if (ar->state == ATH10K_STATE_ON ||
2202 ar->state == ATH10K_STATE_RESTARTED ||
2203 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002204 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002205
Michal Kaziorf7843d72013-07-16 09:38:52 +02002206 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002207 mutex_unlock(&ar->conf_mutex);
2208
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002209 ath10k_mgmt_over_wmi_tx_purge(ar);
2210
Michal Kazior548db542013-07-05 16:15:15 +03002211 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002212 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002213 cancel_work_sync(&ar->restart_work);
2214}
2215
Michal Kaziorad088bf2013-10-16 15:44:46 +03002216static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002217{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002218 struct ath10k_vif *arvif;
2219 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002220
2221 lockdep_assert_held(&ar->conf_mutex);
2222
Michal Kaziorad088bf2013-10-16 15:44:46 +03002223 list_for_each_entry(arvif, &ar->arvifs, list) {
2224 ret = ath10k_mac_vif_setup_ps(arvif);
2225 if (ret) {
2226 ath10k_warn("could not setup powersave (%d)\n", ret);
2227 break;
2228 }
2229 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002230
Michal Kaziorad088bf2013-10-16 15:44:46 +03002231 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232}
2233
Michal Kaziorc930f742014-01-23 11:38:25 +01002234static const char *chandef_get_width(enum nl80211_chan_width width)
2235{
2236 switch (width) {
2237 case NL80211_CHAN_WIDTH_20_NOHT:
2238 return "20 (noht)";
2239 case NL80211_CHAN_WIDTH_20:
2240 return "20";
2241 case NL80211_CHAN_WIDTH_40:
2242 return "40";
2243 case NL80211_CHAN_WIDTH_80:
2244 return "80";
2245 case NL80211_CHAN_WIDTH_80P80:
2246 return "80+80";
2247 case NL80211_CHAN_WIDTH_160:
2248 return "160";
2249 case NL80211_CHAN_WIDTH_5:
2250 return "5";
2251 case NL80211_CHAN_WIDTH_10:
2252 return "10";
2253 }
2254 return "?";
2255}
2256
2257static void ath10k_config_chan(struct ath10k *ar)
2258{
2259 struct ath10k_vif *arvif;
2260 bool monitor_was_enabled;
2261 int ret;
2262
2263 lockdep_assert_held(&ar->conf_mutex);
2264
2265 ath10k_dbg(ATH10K_DBG_MAC,
2266 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2267 ar->chandef.chan->center_freq,
2268 ar->chandef.center_freq1,
2269 ar->chandef.center_freq2,
2270 chandef_get_width(ar->chandef.width));
2271
2272 /* First stop monitor interface. Some FW versions crash if there's a
2273 * lone monitor interface. */
2274 monitor_was_enabled = ar->monitor_enabled;
2275
2276 if (ar->monitor_enabled)
2277 ath10k_monitor_stop(ar);
2278
2279 list_for_each_entry(arvif, &ar->arvifs, list) {
2280 if (!arvif->is_started)
2281 continue;
2282
2283 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2284 continue;
2285
2286 ret = ath10k_vdev_stop(arvif);
2287 if (ret) {
2288 ath10k_warn("could not stop vdev %d (%d)\n",
2289 arvif->vdev_id, ret);
2290 continue;
2291 }
2292 }
2293
2294 /* all vdevs are now stopped - now attempt to restart them */
2295
2296 list_for_each_entry(arvif, &ar->arvifs, list) {
2297 if (!arvif->is_started)
2298 continue;
2299
2300 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2301 continue;
2302
2303 ret = ath10k_vdev_start(arvif);
2304 if (ret) {
2305 ath10k_warn("could not start vdev %d (%d)\n",
2306 arvif->vdev_id, ret);
2307 continue;
2308 }
2309
2310 if (!arvif->is_up)
2311 continue;
2312
2313 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2314 arvif->bssid);
2315 if (ret) {
2316 ath10k_warn("could not bring vdev up %d (%d)\n",
2317 arvif->vdev_id, ret);
2318 continue;
2319 }
2320 }
2321
2322 if (monitor_was_enabled)
2323 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2324}
2325
Kalle Valo5e3dd152013-06-12 20:52:10 +03002326static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2327{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002328 struct ath10k *ar = hw->priv;
2329 struct ieee80211_conf *conf = &hw->conf;
2330 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002331 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332
2333 mutex_lock(&ar->conf_mutex);
2334
2335 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002336 ath10k_dbg(ATH10K_DBG_MAC,
2337 "mac config channel %d mhz flags 0x%x\n",
2338 conf->chandef.chan->center_freq,
2339 conf->chandef.chan->flags);
2340
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341 spin_lock_bh(&ar->data_lock);
2342 ar->rx_channel = conf->chandef.chan;
2343 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002344
2345 ath10k_config_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002346
2347 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2348 ar->chandef = conf->chandef;
2349 ath10k_config_chan(ar);
2350 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002351 }
2352
Michal Kazior5474efe2013-10-23 04:02:15 -07002353 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2354 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2355 hw->conf.power_level);
2356
2357 param = ar->wmi.pdev_param->txpower_limit2g;
2358 ret = ath10k_wmi_pdev_set_param(ar, param,
2359 hw->conf.power_level * 2);
2360 if (ret)
2361 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2362 hw->conf.power_level, ret);
2363
2364 param = ar->wmi.pdev_param->txpower_limit5g;
2365 ret = ath10k_wmi_pdev_set_param(ar, param,
2366 hw->conf.power_level * 2);
2367 if (ret)
2368 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2369 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 }
2371
Michal Kazioraffd3212013-07-16 09:54:35 +02002372 if (changed & IEEE80211_CONF_CHANGE_PS)
2373 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002374
2375 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2376 if (conf->flags & IEEE80211_CONF_MONITOR)
2377 ret = ath10k_monitor_create(ar);
2378 else
2379 ret = ath10k_monitor_destroy(ar);
2380 }
2381
2382 mutex_unlock(&ar->conf_mutex);
2383 return ret;
2384}
2385
2386/*
2387 * TODO:
2388 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2389 * because we will send mgmt frames without CCK. This requirement
2390 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2391 * in the TX packet.
2392 */
2393static int ath10k_add_interface(struct ieee80211_hw *hw,
2394 struct ieee80211_vif *vif)
2395{
2396 struct ath10k *ar = hw->priv;
2397 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2398 enum wmi_sta_powersave_param param;
2399 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002400 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002401 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002402 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002403
2404 mutex_lock(&ar->conf_mutex);
2405
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002406 memset(arvif, 0, sizeof(*arvif));
2407
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408 arvif->ar = ar;
2409 arvif->vif = vif;
2410
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002411 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002412 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002413
Kalle Valo5e3dd152013-06-12 20:52:10 +03002414 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2415 ath10k_warn("Only one monitor interface allowed\n");
2416 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002417 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418 }
2419
2420 bit = ffs(ar->free_vdev_map);
2421 if (bit == 0) {
2422 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002423 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002424 }
2425
2426 arvif->vdev_id = bit - 1;
2427 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002428
2429 if (ar->p2p)
2430 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2431
2432 switch (vif->type) {
2433 case NL80211_IFTYPE_UNSPECIFIED:
2434 case NL80211_IFTYPE_STATION:
2435 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2436 if (vif->p2p)
2437 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2438 break;
2439 case NL80211_IFTYPE_ADHOC:
2440 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2441 break;
2442 case NL80211_IFTYPE_AP:
2443 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2444
2445 if (vif->p2p)
2446 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2447 break;
2448 case NL80211_IFTYPE_MONITOR:
2449 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2450 break;
2451 default:
2452 WARN_ON(1);
2453 break;
2454 }
2455
Kalle Valo60c3daa2013-09-08 17:56:07 +03002456 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2458
2459 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2460 arvif->vdev_subtype, vif->addr);
2461 if (ret) {
2462 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002463 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464 }
2465
Michal Kazior9dad14a2013-10-16 15:44:45 +03002466 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002467 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002468
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002469 vdev_param = ar->wmi.vdev_param->def_keyid;
2470 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002471 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002472 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002473 ath10k_warn("Failed to set default keyid: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002474 goto err_vdev_delete;
2475 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002476
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002477 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2478 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002479 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002480 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002481 if (ret && ret != -EOPNOTSUPP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002482 ath10k_warn("Failed to set TX encap: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002483 goto err_vdev_delete;
2484 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485
2486 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2487 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2488 if (ret) {
2489 ath10k_warn("Failed to create peer for AP: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002490 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002492
Kalle Valo5a13e762014-01-20 11:01:46 +02002493 ret = ath10k_mac_set_kickout(arvif);
2494 if (ret) {
2495 ath10k_warn("Failed to set kickout parameters: %d\n",
2496 ret);
2497 goto err_peer_delete;
2498 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002499 }
2500
2501 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2502 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2503 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2504 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2505 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002506 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002508 goto err_peer_delete;
2509 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002510
2511 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2512 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2513 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2514 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002515 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002516 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002517 goto err_peer_delete;
2518 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002519
2520 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2521 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2522 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2523 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002524 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002526 goto err_peer_delete;
2527 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002528 }
2529
Michal Kazior424121c2013-07-22 14:13:31 +02002530 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002531 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002532 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2533 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002534 goto err_peer_delete;
2535 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002536
Michal Kazior424121c2013-07-22 14:13:31 +02002537 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002538 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002539 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2540 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002541 goto err_peer_delete;
2542 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002543
Kalle Valo5e3dd152013-06-12 20:52:10 +03002544 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2545 ar->monitor_present = true;
2546
Kalle Valo5e3dd152013-06-12 20:52:10 +03002547 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002548 return 0;
2549
2550err_peer_delete:
2551 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2552 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2553
2554err_vdev_delete:
2555 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2556 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002557 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002558
2559err:
2560 mutex_unlock(&ar->conf_mutex);
2561
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562 return ret;
2563}
2564
2565static void ath10k_remove_interface(struct ieee80211_hw *hw,
2566 struct ieee80211_vif *vif)
2567{
2568 struct ath10k *ar = hw->priv;
2569 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2570 int ret;
2571
2572 mutex_lock(&ar->conf_mutex);
2573
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002574 cancel_work_sync(&arvif->wep_key_work);
2575
Michal Kaziored543882013-09-13 14:16:56 +02002576 spin_lock_bh(&ar->data_lock);
2577 if (arvif->beacon) {
2578 dev_kfree_skb_any(arvif->beacon);
2579 arvif->beacon = NULL;
2580 }
2581 spin_unlock_bh(&ar->data_lock);
2582
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002584 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002585
2586 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2587 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2588 if (ret)
2589 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2590
2591 kfree(arvif->u.ap.noa_data);
2592 }
2593
Kalle Valo60c3daa2013-09-08 17:56:07 +03002594 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2595 arvif->vdev_id);
2596
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2598 if (ret)
2599 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2600
2601 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2602 ar->monitor_present = false;
2603
2604 ath10k_peer_cleanup(ar, arvif->vdev_id);
2605
2606 mutex_unlock(&ar->conf_mutex);
2607}
2608
2609/*
2610 * FIXME: Has to be verified.
2611 */
2612#define SUPPORTED_FILTERS \
2613 (FIF_PROMISC_IN_BSS | \
2614 FIF_ALLMULTI | \
2615 FIF_CONTROL | \
2616 FIF_PSPOLL | \
2617 FIF_OTHER_BSS | \
2618 FIF_BCN_PRBRESP_PROMISC | \
2619 FIF_PROBE_REQ | \
2620 FIF_FCSFAIL)
2621
2622static void ath10k_configure_filter(struct ieee80211_hw *hw,
2623 unsigned int changed_flags,
2624 unsigned int *total_flags,
2625 u64 multicast)
2626{
2627 struct ath10k *ar = hw->priv;
2628 int ret;
2629
2630 mutex_lock(&ar->conf_mutex);
2631
2632 changed_flags &= SUPPORTED_FILTERS;
2633 *total_flags &= SUPPORTED_FILTERS;
2634 ar->filter_flags = *total_flags;
2635
Michal Kaziorafd09222013-10-16 16:45:41 +03002636 /* Monitor must not be started if it wasn't created first.
2637 * Promiscuous mode may be started on a non-monitor interface - in
2638 * such case the monitor vdev is not created so starting the
2639 * monitor makes no sense. Since ath10k uses no special RX filters
2640 * (only BSS filter in STA mode) there's no need for any special
2641 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002642 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002643 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002644 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2645 ar->monitor_vdev_id);
2646
Kalle Valo5e3dd152013-06-12 20:52:10 +03002647 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2648 if (ret)
2649 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002650 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002651 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002652 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2653 ar->monitor_vdev_id);
2654
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655 ret = ath10k_monitor_stop(ar);
2656 if (ret)
2657 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002658 }
2659
2660 mutex_unlock(&ar->conf_mutex);
2661}
2662
2663static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2664 struct ieee80211_vif *vif,
2665 struct ieee80211_bss_conf *info,
2666 u32 changed)
2667{
2668 struct ath10k *ar = hw->priv;
2669 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2670 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002671 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002672
2673 mutex_lock(&ar->conf_mutex);
2674
2675 if (changed & BSS_CHANGED_IBSS)
2676 ath10k_control_ibss(arvif, info, vif->addr);
2677
2678 if (changed & BSS_CHANGED_BEACON_INT) {
2679 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002680 vdev_param = ar->wmi.vdev_param->beacon_interval;
2681 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002683 ath10k_dbg(ATH10K_DBG_MAC,
2684 "mac vdev %d beacon_interval %d\n",
2685 arvif->vdev_id, arvif->beacon_interval);
2686
Kalle Valo5e3dd152013-06-12 20:52:10 +03002687 if (ret)
2688 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2689 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690 }
2691
2692 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002693 ath10k_dbg(ATH10K_DBG_MAC,
2694 "vdev %d set beacon tx mode to staggered\n",
2695 arvif->vdev_id);
2696
Bartosz Markowski226a3392013-09-26 17:47:16 +02002697 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2698 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002699 WMI_BEACON_STAGGERED_MODE);
2700 if (ret)
2701 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2702 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002703 }
2704
John W. Linvilleb70727e2013-06-13 13:34:29 -04002705 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706 arvif->dtim_period = info->dtim_period;
2707
Kalle Valo60c3daa2013-09-08 17:56:07 +03002708 ath10k_dbg(ATH10K_DBG_MAC,
2709 "mac vdev %d dtim_period %d\n",
2710 arvif->vdev_id, arvif->dtim_period);
2711
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002712 vdev_param = ar->wmi.vdev_param->dtim_period;
2713 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002714 arvif->dtim_period);
2715 if (ret)
2716 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2717 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002718 }
2719
2720 if (changed & BSS_CHANGED_SSID &&
2721 vif->type == NL80211_IFTYPE_AP) {
2722 arvif->u.ap.ssid_len = info->ssid_len;
2723 if (info->ssid_len)
2724 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2725 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2726 }
2727
2728 if (changed & BSS_CHANGED_BSSID) {
2729 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002730 ath10k_dbg(ATH10K_DBG_MAC,
2731 "mac vdev %d create peer %pM\n",
2732 arvif->vdev_id, info->bssid);
2733
Kalle Valo5e3dd152013-06-12 20:52:10 +03002734 ret = ath10k_peer_create(ar, arvif->vdev_id,
2735 info->bssid);
2736 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08002737 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2738 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002739
2740 if (vif->type == NL80211_IFTYPE_STATION) {
2741 /*
2742 * this is never erased as we it for crypto key
2743 * clearing; this is FW requirement
2744 */
Michal Kaziorc930f742014-01-23 11:38:25 +01002745 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002746
Kalle Valo60c3daa2013-09-08 17:56:07 +03002747 ath10k_dbg(ATH10K_DBG_MAC,
2748 "mac vdev %d start %pM\n",
2749 arvif->vdev_id, info->bssid);
2750
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002752 if (ret) {
2753 ath10k_warn("failed to start vdev: %d\n",
2754 ret);
2755 return;
2756 }
2757
2758 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759 }
2760
2761 /*
2762 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2763 * so driver need to store it. It is needed when leaving
2764 * IBSS in order to remove BSSID peer.
2765 */
2766 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01002767 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002768 ETH_ALEN);
2769 }
2770 }
2771
2772 if (changed & BSS_CHANGED_BEACON_ENABLED)
2773 ath10k_control_beaconing(arvif, info);
2774
2775 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2776 u32 cts_prot;
2777 if (info->use_cts_prot)
2778 cts_prot = 1;
2779 else
2780 cts_prot = 0;
2781
Kalle Valo60c3daa2013-09-08 17:56:07 +03002782 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2783 arvif->vdev_id, cts_prot);
2784
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002785 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2786 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002787 cts_prot);
2788 if (ret)
2789 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2790 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791 }
2792
2793 if (changed & BSS_CHANGED_ERP_SLOT) {
2794 u32 slottime;
2795 if (info->use_short_slot)
2796 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2797
2798 else
2799 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2800
Kalle Valo60c3daa2013-09-08 17:56:07 +03002801 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2802 arvif->vdev_id, slottime);
2803
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002804 vdev_param = ar->wmi.vdev_param->slot_time;
2805 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002806 slottime);
2807 if (ret)
2808 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2809 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002810 }
2811
2812 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2813 u32 preamble;
2814 if (info->use_short_preamble)
2815 preamble = WMI_VDEV_PREAMBLE_SHORT;
2816 else
2817 preamble = WMI_VDEV_PREAMBLE_LONG;
2818
Kalle Valo60c3daa2013-09-08 17:56:07 +03002819 ath10k_dbg(ATH10K_DBG_MAC,
2820 "mac vdev %d preamble %dn",
2821 arvif->vdev_id, preamble);
2822
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002823 vdev_param = ar->wmi.vdev_param->preamble;
2824 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002825 preamble);
2826 if (ret)
2827 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2828 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002829 }
2830
2831 if (changed & BSS_CHANGED_ASSOC) {
2832 if (info->assoc)
2833 ath10k_bss_assoc(hw, vif, info);
2834 }
2835
2836 mutex_unlock(&ar->conf_mutex);
2837}
2838
2839static int ath10k_hw_scan(struct ieee80211_hw *hw,
2840 struct ieee80211_vif *vif,
2841 struct cfg80211_scan_request *req)
2842{
2843 struct ath10k *ar = hw->priv;
2844 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2845 struct wmi_start_scan_arg arg;
2846 int ret = 0;
2847 int i;
2848
2849 mutex_lock(&ar->conf_mutex);
2850
2851 spin_lock_bh(&ar->data_lock);
2852 if (ar->scan.in_progress) {
2853 spin_unlock_bh(&ar->data_lock);
2854 ret = -EBUSY;
2855 goto exit;
2856 }
2857
Wolfram Sang16735d02013-11-14 14:32:02 -08002858 reinit_completion(&ar->scan.started);
2859 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002860 ar->scan.in_progress = true;
2861 ar->scan.aborting = false;
2862 ar->scan.is_roc = false;
2863 ar->scan.vdev_id = arvif->vdev_id;
2864 spin_unlock_bh(&ar->data_lock);
2865
2866 memset(&arg, 0, sizeof(arg));
2867 ath10k_wmi_start_scan_init(ar, &arg);
2868 arg.vdev_id = arvif->vdev_id;
2869 arg.scan_id = ATH10K_SCAN_ID;
2870
2871 if (!req->no_cck)
2872 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2873
2874 if (req->ie_len) {
2875 arg.ie_len = req->ie_len;
2876 memcpy(arg.ie, req->ie, arg.ie_len);
2877 }
2878
2879 if (req->n_ssids) {
2880 arg.n_ssids = req->n_ssids;
2881 for (i = 0; i < arg.n_ssids; i++) {
2882 arg.ssids[i].len = req->ssids[i].ssid_len;
2883 arg.ssids[i].ssid = req->ssids[i].ssid;
2884 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002885 } else {
2886 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002887 }
2888
2889 if (req->n_channels) {
2890 arg.n_channels = req->n_channels;
2891 for (i = 0; i < arg.n_channels; i++)
2892 arg.channels[i] = req->channels[i]->center_freq;
2893 }
2894
2895 ret = ath10k_start_scan(ar, &arg);
2896 if (ret) {
2897 ath10k_warn("could not start hw scan (%d)\n", ret);
2898 spin_lock_bh(&ar->data_lock);
2899 ar->scan.in_progress = false;
2900 spin_unlock_bh(&ar->data_lock);
2901 }
2902
2903exit:
2904 mutex_unlock(&ar->conf_mutex);
2905 return ret;
2906}
2907
2908static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2909 struct ieee80211_vif *vif)
2910{
2911 struct ath10k *ar = hw->priv;
2912 int ret;
2913
2914 mutex_lock(&ar->conf_mutex);
2915 ret = ath10k_abort_scan(ar);
2916 if (ret) {
2917 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2918 ret);
2919 ieee80211_scan_completed(hw, 1 /* aborted */);
2920 }
2921 mutex_unlock(&ar->conf_mutex);
2922}
2923
Michal Kaziorcfb27d22013-12-02 09:06:36 +01002924static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2925 struct ath10k_vif *arvif,
2926 enum set_key_cmd cmd,
2927 struct ieee80211_key_conf *key)
2928{
2929 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2930 int ret;
2931
2932 /* 10.1 firmware branch requires default key index to be set to group
2933 * key index after installing it. Otherwise FW/HW Txes corrupted
2934 * frames with multi-vif APs. This is not required for main firmware
2935 * branch (e.g. 636).
2936 *
2937 * FIXME: This has been tested only in AP. It remains unknown if this
2938 * is required for multi-vif STA interfaces on 10.1 */
2939
2940 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2941 return;
2942
2943 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2944 return;
2945
2946 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2947 return;
2948
2949 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2950 return;
2951
2952 if (cmd != SET_KEY)
2953 return;
2954
2955 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2956 key->keyidx);
2957 if (ret)
2958 ath10k_warn("failed to set group key as default key: %d\n",
2959 ret);
2960}
2961
Kalle Valo5e3dd152013-06-12 20:52:10 +03002962static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2963 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2964 struct ieee80211_key_conf *key)
2965{
2966 struct ath10k *ar = hw->priv;
2967 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2968 struct ath10k_peer *peer;
2969 const u8 *peer_addr;
2970 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2971 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2972 int ret = 0;
2973
2974 if (key->keyidx > WMI_MAX_KEY_INDEX)
2975 return -ENOSPC;
2976
2977 mutex_lock(&ar->conf_mutex);
2978
2979 if (sta)
2980 peer_addr = sta->addr;
2981 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2982 peer_addr = vif->bss_conf.bssid;
2983 else
2984 peer_addr = vif->addr;
2985
2986 key->hw_key_idx = key->keyidx;
2987
2988 /* the peer should not disappear in mid-way (unless FW goes awry) since
2989 * we already hold conf_mutex. we just make sure its there now. */
2990 spin_lock_bh(&ar->data_lock);
2991 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2992 spin_unlock_bh(&ar->data_lock);
2993
2994 if (!peer) {
2995 if (cmd == SET_KEY) {
2996 ath10k_warn("cannot install key for non-existent peer %pM\n",
2997 peer_addr);
2998 ret = -EOPNOTSUPP;
2999 goto exit;
3000 } else {
3001 /* if the peer doesn't exist there is no key to disable
3002 * anymore */
3003 goto exit;
3004 }
3005 }
3006
3007 if (is_wep) {
3008 if (cmd == SET_KEY)
3009 arvif->wep_keys[key->keyidx] = key;
3010 else
3011 arvif->wep_keys[key->keyidx] = NULL;
3012
3013 if (cmd == DISABLE_KEY)
3014 ath10k_clear_vdev_key(arvif, key);
3015 }
3016
3017 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3018 if (ret) {
3019 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
3020 goto exit;
3021 }
3022
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003023 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3024
Kalle Valo5e3dd152013-06-12 20:52:10 +03003025 spin_lock_bh(&ar->data_lock);
3026 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3027 if (peer && cmd == SET_KEY)
3028 peer->keys[key->keyidx] = key;
3029 else if (peer && cmd == DISABLE_KEY)
3030 peer->keys[key->keyidx] = NULL;
3031 else if (peer == NULL)
3032 /* impossible unless FW goes crazy */
3033 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3034 spin_unlock_bh(&ar->data_lock);
3035
3036exit:
3037 mutex_unlock(&ar->conf_mutex);
3038 return ret;
3039}
3040
3041static int ath10k_sta_state(struct ieee80211_hw *hw,
3042 struct ieee80211_vif *vif,
3043 struct ieee80211_sta *sta,
3044 enum ieee80211_sta_state old_state,
3045 enum ieee80211_sta_state new_state)
3046{
3047 struct ath10k *ar = hw->priv;
3048 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003049 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003050 int ret = 0;
3051
3052 mutex_lock(&ar->conf_mutex);
3053
3054 if (old_state == IEEE80211_STA_NOTEXIST &&
3055 new_state == IEEE80211_STA_NONE &&
3056 vif->type != NL80211_IFTYPE_STATION) {
3057 /*
3058 * New station addition.
3059 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003060 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3061 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3062 else
3063 max_num_peers = TARGET_NUM_PEERS;
3064
3065 if (ar->num_peers >= max_num_peers) {
3066 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3067 ar->num_peers, max_num_peers);
3068 ret = -ENOBUFS;
3069 goto exit;
3070 }
3071
Kalle Valo60c3daa2013-09-08 17:56:07 +03003072 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003073 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3074 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003075
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3077 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08003078 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3079 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003080 } else if ((old_state == IEEE80211_STA_NONE &&
3081 new_state == IEEE80211_STA_NOTEXIST)) {
3082 /*
3083 * Existing station deletion.
3084 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003085 ath10k_dbg(ATH10K_DBG_MAC,
3086 "mac vdev %d peer delete %pM (sta gone)\n",
3087 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003088 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3089 if (ret)
3090 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
3091 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003092
3093 if (vif->type == NL80211_IFTYPE_STATION)
3094 ath10k_bss_disassoc(hw, vif);
3095 } else if (old_state == IEEE80211_STA_AUTH &&
3096 new_state == IEEE80211_STA_ASSOC &&
3097 (vif->type == NL80211_IFTYPE_AP ||
3098 vif->type == NL80211_IFTYPE_ADHOC)) {
3099 /*
3100 * New association.
3101 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003102 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3103 sta->addr);
3104
Kalle Valo5e3dd152013-06-12 20:52:10 +03003105 ret = ath10k_station_assoc(ar, arvif, sta);
3106 if (ret)
3107 ath10k_warn("Failed to associate station: %pM\n",
3108 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003109 } else if (old_state == IEEE80211_STA_ASSOC &&
3110 new_state == IEEE80211_STA_AUTH &&
3111 (vif->type == NL80211_IFTYPE_AP ||
3112 vif->type == NL80211_IFTYPE_ADHOC)) {
3113 /*
3114 * Disassociation.
3115 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003116 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3117 sta->addr);
3118
Kalle Valo5e3dd152013-06-12 20:52:10 +03003119 ret = ath10k_station_disassoc(ar, arvif, sta);
3120 if (ret)
3121 ath10k_warn("Failed to disassociate station: %pM\n",
3122 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003123 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003124exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003125 mutex_unlock(&ar->conf_mutex);
3126 return ret;
3127}
3128
3129static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3130 u16 ac, bool enable)
3131{
3132 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3133 u32 value = 0;
3134 int ret = 0;
3135
Michal Kazior548db542013-07-05 16:15:15 +03003136 lockdep_assert_held(&ar->conf_mutex);
3137
Kalle Valo5e3dd152013-06-12 20:52:10 +03003138 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3139 return 0;
3140
3141 switch (ac) {
3142 case IEEE80211_AC_VO:
3143 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3144 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3145 break;
3146 case IEEE80211_AC_VI:
3147 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3148 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3149 break;
3150 case IEEE80211_AC_BE:
3151 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3152 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3153 break;
3154 case IEEE80211_AC_BK:
3155 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3156 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3157 break;
3158 }
3159
3160 if (enable)
3161 arvif->u.sta.uapsd |= value;
3162 else
3163 arvif->u.sta.uapsd &= ~value;
3164
3165 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3166 WMI_STA_PS_PARAM_UAPSD,
3167 arvif->u.sta.uapsd);
3168 if (ret) {
3169 ath10k_warn("could not set uapsd params %d\n", ret);
3170 goto exit;
3171 }
3172
3173 if (arvif->u.sta.uapsd)
3174 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3175 else
3176 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3177
3178 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3179 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3180 value);
3181 if (ret)
3182 ath10k_warn("could not set rx wake param %d\n", ret);
3183
3184exit:
3185 return ret;
3186}
3187
3188static int ath10k_conf_tx(struct ieee80211_hw *hw,
3189 struct ieee80211_vif *vif, u16 ac,
3190 const struct ieee80211_tx_queue_params *params)
3191{
3192 struct ath10k *ar = hw->priv;
3193 struct wmi_wmm_params_arg *p = NULL;
3194 int ret;
3195
3196 mutex_lock(&ar->conf_mutex);
3197
3198 switch (ac) {
3199 case IEEE80211_AC_VO:
3200 p = &ar->wmm_params.ac_vo;
3201 break;
3202 case IEEE80211_AC_VI:
3203 p = &ar->wmm_params.ac_vi;
3204 break;
3205 case IEEE80211_AC_BE:
3206 p = &ar->wmm_params.ac_be;
3207 break;
3208 case IEEE80211_AC_BK:
3209 p = &ar->wmm_params.ac_bk;
3210 break;
3211 }
3212
3213 if (WARN_ON(!p)) {
3214 ret = -EINVAL;
3215 goto exit;
3216 }
3217
3218 p->cwmin = params->cw_min;
3219 p->cwmax = params->cw_max;
3220 p->aifs = params->aifs;
3221
3222 /*
3223 * The channel time duration programmed in the HW is in absolute
3224 * microseconds, while mac80211 gives the txop in units of
3225 * 32 microseconds.
3226 */
3227 p->txop = params->txop * 32;
3228
3229 /* FIXME: FW accepts wmm params per hw, not per vif */
3230 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3231 if (ret) {
3232 ath10k_warn("could not set wmm params %d\n", ret);
3233 goto exit;
3234 }
3235
3236 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3237 if (ret)
3238 ath10k_warn("could not set sta uapsd %d\n", ret);
3239
3240exit:
3241 mutex_unlock(&ar->conf_mutex);
3242 return ret;
3243}
3244
3245#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3246
3247static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3248 struct ieee80211_vif *vif,
3249 struct ieee80211_channel *chan,
3250 int duration,
3251 enum ieee80211_roc_type type)
3252{
3253 struct ath10k *ar = hw->priv;
3254 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3255 struct wmi_start_scan_arg arg;
3256 int ret;
3257
3258 mutex_lock(&ar->conf_mutex);
3259
3260 spin_lock_bh(&ar->data_lock);
3261 if (ar->scan.in_progress) {
3262 spin_unlock_bh(&ar->data_lock);
3263 ret = -EBUSY;
3264 goto exit;
3265 }
3266
Wolfram Sang16735d02013-11-14 14:32:02 -08003267 reinit_completion(&ar->scan.started);
3268 reinit_completion(&ar->scan.completed);
3269 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003270 ar->scan.in_progress = true;
3271 ar->scan.aborting = false;
3272 ar->scan.is_roc = true;
3273 ar->scan.vdev_id = arvif->vdev_id;
3274 ar->scan.roc_freq = chan->center_freq;
3275 spin_unlock_bh(&ar->data_lock);
3276
3277 memset(&arg, 0, sizeof(arg));
3278 ath10k_wmi_start_scan_init(ar, &arg);
3279 arg.vdev_id = arvif->vdev_id;
3280 arg.scan_id = ATH10K_SCAN_ID;
3281 arg.n_channels = 1;
3282 arg.channels[0] = chan->center_freq;
3283 arg.dwell_time_active = duration;
3284 arg.dwell_time_passive = duration;
3285 arg.max_scan_time = 2 * duration;
3286 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3287 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3288
3289 ret = ath10k_start_scan(ar, &arg);
3290 if (ret) {
3291 ath10k_warn("could not start roc scan (%d)\n", ret);
3292 spin_lock_bh(&ar->data_lock);
3293 ar->scan.in_progress = false;
3294 spin_unlock_bh(&ar->data_lock);
3295 goto exit;
3296 }
3297
3298 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3299 if (ret == 0) {
3300 ath10k_warn("could not switch to channel for roc scan\n");
3301 ath10k_abort_scan(ar);
3302 ret = -ETIMEDOUT;
3303 goto exit;
3304 }
3305
3306 ret = 0;
3307exit:
3308 mutex_unlock(&ar->conf_mutex);
3309 return ret;
3310}
3311
3312static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3313{
3314 struct ath10k *ar = hw->priv;
3315
3316 mutex_lock(&ar->conf_mutex);
3317 ath10k_abort_scan(ar);
3318 mutex_unlock(&ar->conf_mutex);
3319
3320 return 0;
3321}
3322
3323/*
3324 * Both RTS and Fragmentation threshold are interface-specific
3325 * in ath10k, but device-specific in mac80211.
3326 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003327
3328static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3329{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003330 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003331 struct ath10k_vif *arvif;
3332 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003333
Michal Kaziorad088bf2013-10-16 15:44:46 +03003334 mutex_lock(&ar->conf_mutex);
3335 list_for_each_entry(arvif, &ar->arvifs, list) {
3336 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3337 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003338
Michal Kaziorad088bf2013-10-16 15:44:46 +03003339 ret = ath10k_mac_set_rts(arvif, value);
3340 if (ret) {
3341 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3342 arvif->vdev_id, ret);
3343 break;
3344 }
3345 }
3346 mutex_unlock(&ar->conf_mutex);
3347
3348 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003349}
3350
3351static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3352{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003353 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003354 struct ath10k_vif *arvif;
3355 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003356
Kalle Valo5e3dd152013-06-12 20:52:10 +03003357 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003358 list_for_each_entry(arvif, &ar->arvifs, list) {
3359 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3360 arvif->vdev_id, value);
3361
3362 ret = ath10k_mac_set_rts(arvif, value);
3363 if (ret) {
3364 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3365 arvif->vdev_id, ret);
3366 break;
3367 }
3368 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369 mutex_unlock(&ar->conf_mutex);
3370
Michal Kaziorad088bf2013-10-16 15:44:46 +03003371 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372}
3373
3374static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3375{
3376 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003377 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003378 int ret;
3379
3380 /* mac80211 doesn't care if we really xmit queued frames or not
3381 * we'll collect those frames either way if we stop/delete vdevs */
3382 if (drop)
3383 return;
3384
Michal Kazior548db542013-07-05 16:15:15 +03003385 mutex_lock(&ar->conf_mutex);
3386
Michal Kazioraffd3212013-07-16 09:54:35 +02003387 if (ar->state == ATH10K_STATE_WEDGED)
3388 goto skip;
3389
Michal Kazioredb82362013-07-05 16:15:14 +03003390 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003392
Michal Kazioredb82362013-07-05 16:15:14 +03003393 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003394 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003395 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003396
3397 skip = (ar->state == ATH10K_STATE_WEDGED);
3398
3399 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003401
3402 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03003404
Michal Kazioraffd3212013-07-16 09:54:35 +02003405skip:
Michal Kazior548db542013-07-05 16:15:15 +03003406 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003407}
3408
3409/* TODO: Implement this function properly
3410 * For now it is needed to reply to Probe Requests in IBSS mode.
3411 * Propably we need this information from FW.
3412 */
3413static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3414{
3415 return 1;
3416}
3417
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003418#ifdef CONFIG_PM
3419static int ath10k_suspend(struct ieee80211_hw *hw,
3420 struct cfg80211_wowlan *wowlan)
3421{
3422 struct ath10k *ar = hw->priv;
3423 int ret;
3424
3425 ar->is_target_paused = false;
3426
3427 ret = ath10k_wmi_pdev_suspend_target(ar);
3428 if (ret) {
3429 ath10k_warn("could not suspend target (%d)\n", ret);
3430 return 1;
3431 }
3432
3433 ret = wait_event_interruptible_timeout(ar->event_queue,
3434 ar->is_target_paused == true,
3435 1 * HZ);
3436 if (ret < 0) {
3437 ath10k_warn("suspend interrupted (%d)\n", ret);
3438 goto resume;
3439 } else if (ret == 0) {
3440 ath10k_warn("suspend timed out - target pause event never came\n");
3441 goto resume;
3442 }
3443
3444 ret = ath10k_hif_suspend(ar);
3445 if (ret) {
3446 ath10k_warn("could not suspend hif (%d)\n", ret);
3447 goto resume;
3448 }
3449
3450 return 0;
3451resume:
3452 ret = ath10k_wmi_pdev_resume_target(ar);
3453 if (ret)
3454 ath10k_warn("could not resume target (%d)\n", ret);
3455 return 1;
3456}
3457
3458static int ath10k_resume(struct ieee80211_hw *hw)
3459{
3460 struct ath10k *ar = hw->priv;
3461 int ret;
3462
3463 ret = ath10k_hif_resume(ar);
3464 if (ret) {
3465 ath10k_warn("could not resume hif (%d)\n", ret);
3466 return 1;
3467 }
3468
3469 ret = ath10k_wmi_pdev_resume_target(ar);
3470 if (ret) {
3471 ath10k_warn("could not resume target (%d)\n", ret);
3472 return 1;
3473 }
3474
3475 return 0;
3476}
3477#endif
3478
Michal Kazioraffd3212013-07-16 09:54:35 +02003479static void ath10k_restart_complete(struct ieee80211_hw *hw)
3480{
3481 struct ath10k *ar = hw->priv;
3482
3483 mutex_lock(&ar->conf_mutex);
3484
3485 /* If device failed to restart it will be in a different state, e.g.
3486 * ATH10K_STATE_WEDGED */
3487 if (ar->state == ATH10K_STATE_RESTARTED) {
3488 ath10k_info("device successfully recovered\n");
3489 ar->state = ATH10K_STATE_ON;
3490 }
3491
3492 mutex_unlock(&ar->conf_mutex);
3493}
3494
Michal Kazior2e1dea42013-07-31 10:32:40 +02003495static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3496 struct survey_info *survey)
3497{
3498 struct ath10k *ar = hw->priv;
3499 struct ieee80211_supported_band *sband;
3500 struct survey_info *ar_survey = &ar->survey[idx];
3501 int ret = 0;
3502
3503 mutex_lock(&ar->conf_mutex);
3504
3505 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3506 if (sband && idx >= sband->n_channels) {
3507 idx -= sband->n_channels;
3508 sband = NULL;
3509 }
3510
3511 if (!sband)
3512 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3513
3514 if (!sband || idx >= sband->n_channels) {
3515 ret = -ENOENT;
3516 goto exit;
3517 }
3518
3519 spin_lock_bh(&ar->data_lock);
3520 memcpy(survey, ar_survey, sizeof(*survey));
3521 spin_unlock_bh(&ar->data_lock);
3522
3523 survey->channel = &sband->channels[idx];
3524
3525exit:
3526 mutex_unlock(&ar->conf_mutex);
3527 return ret;
3528}
3529
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003530/* Helper table for legacy fixed_rate/bitrate_mask */
3531static const u8 cck_ofdm_rate[] = {
3532 /* CCK */
3533 3, /* 1Mbps */
3534 2, /* 2Mbps */
3535 1, /* 5.5Mbps */
3536 0, /* 11Mbps */
3537 /* OFDM */
3538 3, /* 6Mbps */
3539 7, /* 9Mbps */
3540 2, /* 12Mbps */
3541 6, /* 18Mbps */
3542 1, /* 24Mbps */
3543 5, /* 36Mbps */
3544 0, /* 48Mbps */
3545 4, /* 54Mbps */
3546};
3547
3548/* Check if only one bit set */
3549static int ath10k_check_single_mask(u32 mask)
3550{
3551 int bit;
3552
3553 bit = ffs(mask);
3554 if (!bit)
3555 return 0;
3556
3557 mask &= ~BIT(bit - 1);
3558 if (mask)
3559 return 2;
3560
3561 return 1;
3562}
3563
3564static bool
3565ath10k_default_bitrate_mask(struct ath10k *ar,
3566 enum ieee80211_band band,
3567 const struct cfg80211_bitrate_mask *mask)
3568{
3569 u32 legacy = 0x00ff;
3570 u8 ht = 0xff, i;
3571 u16 vht = 0x3ff;
3572
3573 switch (band) {
3574 case IEEE80211_BAND_2GHZ:
3575 legacy = 0x00fff;
3576 vht = 0;
3577 break;
3578 case IEEE80211_BAND_5GHZ:
3579 break;
3580 default:
3581 return false;
3582 }
3583
3584 if (mask->control[band].legacy != legacy)
3585 return false;
3586
3587 for (i = 0; i < ar->num_rf_chains; i++)
3588 if (mask->control[band].ht_mcs[i] != ht)
3589 return false;
3590
3591 for (i = 0; i < ar->num_rf_chains; i++)
3592 if (mask->control[band].vht_mcs[i] != vht)
3593 return false;
3594
3595 return true;
3596}
3597
3598static bool
3599ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3600 enum ieee80211_band band,
3601 u8 *fixed_nss)
3602{
3603 int ht_nss = 0, vht_nss = 0, i;
3604
3605 /* check legacy */
3606 if (ath10k_check_single_mask(mask->control[band].legacy))
3607 return false;
3608
3609 /* check HT */
3610 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3611 if (mask->control[band].ht_mcs[i] == 0xff)
3612 continue;
3613 else if (mask->control[band].ht_mcs[i] == 0x00)
3614 break;
3615 else
3616 return false;
3617 }
3618
3619 ht_nss = i;
3620
3621 /* check VHT */
3622 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3623 if (mask->control[band].vht_mcs[i] == 0x03ff)
3624 continue;
3625 else if (mask->control[band].vht_mcs[i] == 0x0000)
3626 break;
3627 else
3628 return false;
3629 }
3630
3631 vht_nss = i;
3632
3633 if (ht_nss > 0 && vht_nss > 0)
3634 return false;
3635
3636 if (ht_nss)
3637 *fixed_nss = ht_nss;
3638 else if (vht_nss)
3639 *fixed_nss = vht_nss;
3640 else
3641 return false;
3642
3643 return true;
3644}
3645
3646static bool
3647ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3648 enum ieee80211_band band,
3649 enum wmi_rate_preamble *preamble)
3650{
3651 int legacy = 0, ht = 0, vht = 0, i;
3652
3653 *preamble = WMI_RATE_PREAMBLE_OFDM;
3654
3655 /* check legacy */
3656 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3657 if (legacy > 1)
3658 return false;
3659
3660 /* check HT */
3661 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3662 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3663 if (ht > 1)
3664 return false;
3665
3666 /* check VHT */
3667 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3668 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3669 if (vht > 1)
3670 return false;
3671
3672 /* Currently we support only one fixed_rate */
3673 if ((legacy + ht + vht) != 1)
3674 return false;
3675
3676 if (ht)
3677 *preamble = WMI_RATE_PREAMBLE_HT;
3678 else if (vht)
3679 *preamble = WMI_RATE_PREAMBLE_VHT;
3680
3681 return true;
3682}
3683
3684static bool
3685ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3686 enum ieee80211_band band,
3687 u8 *fixed_rate,
3688 u8 *fixed_nss)
3689{
3690 u8 rate = 0, pream = 0, nss = 0, i;
3691 enum wmi_rate_preamble preamble;
3692
3693 /* Check if single rate correct */
3694 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3695 return false;
3696
3697 pream = preamble;
3698
3699 switch (preamble) {
3700 case WMI_RATE_PREAMBLE_CCK:
3701 case WMI_RATE_PREAMBLE_OFDM:
3702 i = ffs(mask->control[band].legacy) - 1;
3703
3704 if (band == IEEE80211_BAND_2GHZ && i < 4)
3705 pream = WMI_RATE_PREAMBLE_CCK;
3706
3707 if (band == IEEE80211_BAND_5GHZ)
3708 i += 4;
3709
3710 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3711 return false;
3712
3713 rate = cck_ofdm_rate[i];
3714 break;
3715 case WMI_RATE_PREAMBLE_HT:
3716 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3717 if (mask->control[band].ht_mcs[i])
3718 break;
3719
3720 if (i == IEEE80211_HT_MCS_MASK_LEN)
3721 return false;
3722
3723 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3724 nss = i;
3725 break;
3726 case WMI_RATE_PREAMBLE_VHT:
3727 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3728 if (mask->control[band].vht_mcs[i])
3729 break;
3730
3731 if (i == NL80211_VHT_NSS_MAX)
3732 return false;
3733
3734 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3735 nss = i;
3736 break;
3737 }
3738
3739 *fixed_nss = nss + 1;
3740 nss <<= 4;
3741 pream <<= 6;
3742
3743 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3744 pream, nss, rate);
3745
3746 *fixed_rate = pream | nss | rate;
3747
3748 return true;
3749}
3750
3751static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3752 enum ieee80211_band band,
3753 u8 *fixed_rate,
3754 u8 *fixed_nss)
3755{
3756 /* First check full NSS mask, if we can simply limit NSS */
3757 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3758 return true;
3759
3760 /* Next Check single rate is set */
3761 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3762}
3763
3764static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3765 u8 fixed_rate,
3766 u8 fixed_nss)
3767{
3768 struct ath10k *ar = arvif->ar;
3769 u32 vdev_param;
3770 int ret = 0;
3771
3772 mutex_lock(&ar->conf_mutex);
3773
3774 if (arvif->fixed_rate == fixed_rate &&
3775 arvif->fixed_nss == fixed_nss)
3776 goto exit;
3777
3778 if (fixed_rate == WMI_FIXED_RATE_NONE)
3779 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3780
3781 vdev_param = ar->wmi.vdev_param->fixed_rate;
3782 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3783 vdev_param, fixed_rate);
3784 if (ret) {
3785 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3786 fixed_rate, ret);
3787 ret = -EINVAL;
3788 goto exit;
3789 }
3790
3791 arvif->fixed_rate = fixed_rate;
3792
3793 vdev_param = ar->wmi.vdev_param->nss;
3794 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3795 vdev_param, fixed_nss);
3796
3797 if (ret) {
3798 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3799 fixed_nss, ret);
3800 ret = -EINVAL;
3801 goto exit;
3802 }
3803
3804 arvif->fixed_nss = fixed_nss;
3805
3806exit:
3807 mutex_unlock(&ar->conf_mutex);
3808 return ret;
3809}
3810
3811static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3812 struct ieee80211_vif *vif,
3813 const struct cfg80211_bitrate_mask *mask)
3814{
3815 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3816 struct ath10k *ar = arvif->ar;
3817 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3818 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3819 u8 fixed_nss = ar->num_rf_chains;
3820
3821 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3822 if (!ath10k_get_fixed_rate_nss(mask, band,
3823 &fixed_rate,
3824 &fixed_nss))
3825 return -EINVAL;
3826 }
3827
3828 return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss);
3829}
3830
Michal Kaziorc2df44b2014-01-23 11:38:26 +01003831static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
3832 struct ieee80211_vif *vif,
3833 struct cfg80211_chan_def *chandef)
3834{
3835 /* there's no need to do anything here. vif->csa_active is enough */
3836 return;
3837}
3838
Kalle Valo5e3dd152013-06-12 20:52:10 +03003839static const struct ieee80211_ops ath10k_ops = {
3840 .tx = ath10k_tx,
3841 .start = ath10k_start,
3842 .stop = ath10k_stop,
3843 .config = ath10k_config,
3844 .add_interface = ath10k_add_interface,
3845 .remove_interface = ath10k_remove_interface,
3846 .configure_filter = ath10k_configure_filter,
3847 .bss_info_changed = ath10k_bss_info_changed,
3848 .hw_scan = ath10k_hw_scan,
3849 .cancel_hw_scan = ath10k_cancel_hw_scan,
3850 .set_key = ath10k_set_key,
3851 .sta_state = ath10k_sta_state,
3852 .conf_tx = ath10k_conf_tx,
3853 .remain_on_channel = ath10k_remain_on_channel,
3854 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3855 .set_rts_threshold = ath10k_set_rts_threshold,
3856 .set_frag_threshold = ath10k_set_frag_threshold,
3857 .flush = ath10k_flush,
3858 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003859 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003860 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003861 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kaziorc2df44b2014-01-23 11:38:26 +01003862 .channel_switch_beacon = ath10k_channel_switch_beacon,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003863#ifdef CONFIG_PM
3864 .suspend = ath10k_suspend,
3865 .resume = ath10k_resume,
3866#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003867};
3868
3869#define RATETAB_ENT(_rate, _rateid, _flags) { \
3870 .bitrate = (_rate), \
3871 .flags = (_flags), \
3872 .hw_value = (_rateid), \
3873}
3874
3875#define CHAN2G(_channel, _freq, _flags) { \
3876 .band = IEEE80211_BAND_2GHZ, \
3877 .hw_value = (_channel), \
3878 .center_freq = (_freq), \
3879 .flags = (_flags), \
3880 .max_antenna_gain = 0, \
3881 .max_power = 30, \
3882}
3883
3884#define CHAN5G(_channel, _freq, _flags) { \
3885 .band = IEEE80211_BAND_5GHZ, \
3886 .hw_value = (_channel), \
3887 .center_freq = (_freq), \
3888 .flags = (_flags), \
3889 .max_antenna_gain = 0, \
3890 .max_power = 30, \
3891}
3892
3893static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3894 CHAN2G(1, 2412, 0),
3895 CHAN2G(2, 2417, 0),
3896 CHAN2G(3, 2422, 0),
3897 CHAN2G(4, 2427, 0),
3898 CHAN2G(5, 2432, 0),
3899 CHAN2G(6, 2437, 0),
3900 CHAN2G(7, 2442, 0),
3901 CHAN2G(8, 2447, 0),
3902 CHAN2G(9, 2452, 0),
3903 CHAN2G(10, 2457, 0),
3904 CHAN2G(11, 2462, 0),
3905 CHAN2G(12, 2467, 0),
3906 CHAN2G(13, 2472, 0),
3907 CHAN2G(14, 2484, 0),
3908};
3909
3910static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003911 CHAN5G(36, 5180, 0),
3912 CHAN5G(40, 5200, 0),
3913 CHAN5G(44, 5220, 0),
3914 CHAN5G(48, 5240, 0),
3915 CHAN5G(52, 5260, 0),
3916 CHAN5G(56, 5280, 0),
3917 CHAN5G(60, 5300, 0),
3918 CHAN5G(64, 5320, 0),
3919 CHAN5G(100, 5500, 0),
3920 CHAN5G(104, 5520, 0),
3921 CHAN5G(108, 5540, 0),
3922 CHAN5G(112, 5560, 0),
3923 CHAN5G(116, 5580, 0),
3924 CHAN5G(120, 5600, 0),
3925 CHAN5G(124, 5620, 0),
3926 CHAN5G(128, 5640, 0),
3927 CHAN5G(132, 5660, 0),
3928 CHAN5G(136, 5680, 0),
3929 CHAN5G(140, 5700, 0),
3930 CHAN5G(149, 5745, 0),
3931 CHAN5G(153, 5765, 0),
3932 CHAN5G(157, 5785, 0),
3933 CHAN5G(161, 5805, 0),
3934 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003935};
3936
3937static struct ieee80211_rate ath10k_rates[] = {
3938 /* CCK */
3939 RATETAB_ENT(10, 0x82, 0),
3940 RATETAB_ENT(20, 0x84, 0),
3941 RATETAB_ENT(55, 0x8b, 0),
3942 RATETAB_ENT(110, 0x96, 0),
3943 /* OFDM */
3944 RATETAB_ENT(60, 0x0c, 0),
3945 RATETAB_ENT(90, 0x12, 0),
3946 RATETAB_ENT(120, 0x18, 0),
3947 RATETAB_ENT(180, 0x24, 0),
3948 RATETAB_ENT(240, 0x30, 0),
3949 RATETAB_ENT(360, 0x48, 0),
3950 RATETAB_ENT(480, 0x60, 0),
3951 RATETAB_ENT(540, 0x6c, 0),
3952};
3953
3954#define ath10k_a_rates (ath10k_rates + 4)
3955#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3956#define ath10k_g_rates (ath10k_rates + 0)
3957#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3958
3959struct ath10k *ath10k_mac_create(void)
3960{
3961 struct ieee80211_hw *hw;
3962 struct ath10k *ar;
3963
3964 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3965 if (!hw)
3966 return NULL;
3967
3968 ar = hw->priv;
3969 ar->hw = hw;
3970
3971 return ar;
3972}
3973
3974void ath10k_mac_destroy(struct ath10k *ar)
3975{
3976 ieee80211_free_hw(ar->hw);
3977}
3978
3979static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3980 {
3981 .max = 8,
3982 .types = BIT(NL80211_IFTYPE_STATION)
3983 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003984 },
3985 {
3986 .max = 3,
3987 .types = BIT(NL80211_IFTYPE_P2P_GO)
3988 },
3989 {
3990 .max = 7,
3991 .types = BIT(NL80211_IFTYPE_AP)
3992 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003993};
3994
Bartosz Markowskif2595092013-12-10 16:20:39 +01003995static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003996 {
3997 .max = 8,
3998 .types = BIT(NL80211_IFTYPE_AP)
3999 },
4000};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004001
4002static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4003 {
4004 .limits = ath10k_if_limits,
4005 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4006 .max_interfaces = 8,
4007 .num_different_channels = 1,
4008 .beacon_int_infra_match = true,
4009 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004010};
4011
4012static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004013 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004014 .limits = ath10k_10x_if_limits,
4015 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004016 .max_interfaces = 8,
4017 .num_different_channels = 1,
4018 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004019#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004020 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4021 BIT(NL80211_CHAN_WIDTH_20) |
4022 BIT(NL80211_CHAN_WIDTH_40) |
4023 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004024#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004025 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026};
4027
4028static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4029{
4030 struct ieee80211_sta_vht_cap vht_cap = {0};
4031 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004032 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004033
4034 vht_cap.vht_supported = 1;
4035 vht_cap.cap = ar->vht_cap_info;
4036
Michal Kazior8865bee42013-07-24 12:36:46 +02004037 mcs_map = 0;
4038 for (i = 0; i < 8; i++) {
4039 if (i < ar->num_rf_chains)
4040 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4041 else
4042 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4043 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004044
4045 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4046 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4047
4048 return vht_cap;
4049}
4050
4051static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4052{
4053 int i;
4054 struct ieee80211_sta_ht_cap ht_cap = {0};
4055
4056 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4057 return ht_cap;
4058
4059 ht_cap.ht_supported = 1;
4060 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4061 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4062 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4063 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4064 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4065
4066 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4067 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4068
4069 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4070 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4071
4072 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4073 u32 smps;
4074
4075 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4076 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4077
4078 ht_cap.cap |= smps;
4079 }
4080
4081 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4082 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4083
4084 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4085 u32 stbc;
4086
4087 stbc = ar->ht_cap_info;
4088 stbc &= WMI_HT_CAP_RX_STBC;
4089 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4090 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4091 stbc &= IEEE80211_HT_CAP_RX_STBC;
4092
4093 ht_cap.cap |= stbc;
4094 }
4095
4096 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4097 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4098
4099 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4100 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4101
4102 /* max AMSDU is implicitly taken from vht_cap_info */
4103 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4104 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4105
Michal Kazior8865bee42013-07-24 12:36:46 +02004106 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004107 ht_cap.mcs.rx_mask[i] = 0xFF;
4108
4109 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4110
4111 return ht_cap;
4112}
4113
4114
4115static void ath10k_get_arvif_iter(void *data, u8 *mac,
4116 struct ieee80211_vif *vif)
4117{
4118 struct ath10k_vif_iter *arvif_iter = data;
4119 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4120
4121 if (arvif->vdev_id == arvif_iter->vdev_id)
4122 arvif_iter->arvif = arvif;
4123}
4124
4125struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4126{
4127 struct ath10k_vif_iter arvif_iter;
4128 u32 flags;
4129
4130 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4131 arvif_iter.vdev_id = vdev_id;
4132
4133 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4134 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4135 flags,
4136 ath10k_get_arvif_iter,
4137 &arvif_iter);
4138 if (!arvif_iter.arvif) {
4139 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
4140 return NULL;
4141 }
4142
4143 return arvif_iter.arvif;
4144}
4145
4146int ath10k_mac_register(struct ath10k *ar)
4147{
4148 struct ieee80211_supported_band *band;
4149 struct ieee80211_sta_vht_cap vht_cap;
4150 struct ieee80211_sta_ht_cap ht_cap;
4151 void *channels;
4152 int ret;
4153
4154 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4155
4156 SET_IEEE80211_DEV(ar->hw, ar->dev);
4157
4158 ht_cap = ath10k_get_ht_cap(ar);
4159 vht_cap = ath10k_create_vht_cap(ar);
4160
4161 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4162 channels = kmemdup(ath10k_2ghz_channels,
4163 sizeof(ath10k_2ghz_channels),
4164 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004165 if (!channels) {
4166 ret = -ENOMEM;
4167 goto err_free;
4168 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004169
4170 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4171 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4172 band->channels = channels;
4173 band->n_bitrates = ath10k_g_rates_size;
4174 band->bitrates = ath10k_g_rates;
4175 band->ht_cap = ht_cap;
4176
4177 /* vht is not supported in 2.4 GHz */
4178
4179 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4180 }
4181
4182 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4183 channels = kmemdup(ath10k_5ghz_channels,
4184 sizeof(ath10k_5ghz_channels),
4185 GFP_KERNEL);
4186 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004187 ret = -ENOMEM;
4188 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004189 }
4190
4191 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4192 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4193 band->channels = channels;
4194 band->n_bitrates = ath10k_a_rates_size;
4195 band->bitrates = ath10k_a_rates;
4196 band->ht_cap = ht_cap;
4197 band->vht_cap = vht_cap;
4198 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4199 }
4200
4201 ar->hw->wiphy->interface_modes =
4202 BIT(NL80211_IFTYPE_STATION) |
4203 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004204 BIT(NL80211_IFTYPE_AP);
4205
4206 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4207 ar->hw->wiphy->interface_modes |=
4208 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4209 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004210
4211 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4212 IEEE80211_HW_SUPPORTS_PS |
4213 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4214 IEEE80211_HW_SUPPORTS_UAPSD |
4215 IEEE80211_HW_MFP_CAPABLE |
4216 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4217 IEEE80211_HW_HAS_RATE_CONTROL |
4218 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4219 IEEE80211_HW_WANT_MONITOR_VIF |
4220 IEEE80211_HW_AP_LINK_PS;
4221
Michal Kazior1f8bb152013-09-18 14:43:22 +02004222 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4223 * bytes is used for padding/alignment if necessary. */
4224 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4225
Kalle Valo5e3dd152013-06-12 20:52:10 +03004226 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4227 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4228
4229 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4230 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4231 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4232 }
4233
4234 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4235 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4236
4237 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4238
Kalle Valo5e3dd152013-06-12 20:52:10 +03004239 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4240
4241 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004242 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004243 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4244
4245 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4246 /*
4247 * on LL hardware queues are managed entirely by the FW
4248 * so we only advertise to mac we can do the queues thing
4249 */
4250 ar->hw->queues = 4;
4251
Bartosz Markowskif2595092013-12-10 16:20:39 +01004252 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4253 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4254 ar->hw->wiphy->n_iface_combinations =
4255 ARRAY_SIZE(ath10k_10x_if_comb);
4256 } else {
4257 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4258 ar->hw->wiphy->n_iface_combinations =
4259 ARRAY_SIZE(ath10k_if_comb);
4260 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004261
Michal Kazior7c199992013-07-31 10:47:57 +02004262 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4263
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004264 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4265 /* Init ath dfs pattern detector */
4266 ar->ath_common.debug_mask = ATH_DBG_DFS;
4267 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4268 NL80211_DFS_UNSET);
4269
4270 if (!ar->dfs_detector)
4271 ath10k_warn("dfs pattern detector init failed\n");
4272 }
4273
Kalle Valo5e3dd152013-06-12 20:52:10 +03004274 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4275 ath10k_reg_notifier);
4276 if (ret) {
4277 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02004278 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004279 }
4280
4281 ret = ieee80211_register_hw(ar->hw);
4282 if (ret) {
4283 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004284 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004285 }
4286
4287 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4288 ret = regulatory_hint(ar->hw->wiphy,
4289 ar->ath_common.regulatory.alpha2);
4290 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004291 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292 }
4293
4294 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004295
4296err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004297 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004298err_free:
4299 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4300 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4301
Kalle Valo5e3dd152013-06-12 20:52:10 +03004302 return ret;
4303}
4304
4305void ath10k_mac_unregister(struct ath10k *ar)
4306{
4307 ieee80211_unregister_hw(ar->hw);
4308
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004309 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4310 ar->dfs_detector->exit(ar->dfs_detector);
4311
Kalle Valo5e3dd152013-06-12 20:52:10 +03004312 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4313 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4314
4315 SET_IEEE80211_DEV(ar->hw, NULL);
4316}