blob: 9ad1869fc5d3741378c7b20aa2d0d86e556f5c62 [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) {
Ben Greear69244e52014-02-27 18:50:00 +0200326 ath10k_warn("Failed to create wmi peer %pM on vdev %i: %i\n",
327 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300328 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800329 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300330
331 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800332 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200333 ath10k_warn("Failed to wait for created wmi peer %pM on vdev %i: %i\n",
334 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800336 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100337 spin_lock_bh(&ar->data_lock);
338 ar->num_peers++;
339 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340
341 return 0;
342}
343
Kalle Valo5a13e762014-01-20 11:01:46 +0200344static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
345{
346 struct ath10k *ar = arvif->ar;
347 u32 param;
348 int ret;
349
350 param = ar->wmi.pdev_param->sta_kickout_th;
351 ret = ath10k_wmi_pdev_set_param(ar, param,
352 ATH10K_KICKOUT_THRESHOLD);
353 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200354 ath10k_warn("Failed to set kickout threshold on vdev %i: %d\n",
355 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200356 return ret;
357 }
358
359 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
360 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
361 ATH10K_KEEPALIVE_MIN_IDLE);
362 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200363 ath10k_warn("Failed to set keepalive minimum idle time on vdev %i : %d\n",
364 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200365 return ret;
366 }
367
368 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
369 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
370 ATH10K_KEEPALIVE_MAX_IDLE);
371 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200372 ath10k_warn("Failed to set keepalive maximum idle time on vdev %i: %d\n",
373 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200374 return ret;
375 }
376
377 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
378 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
379 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
380 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200381 ath10k_warn("Failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
382 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200383 return ret;
384 }
385
386 return 0;
387}
388
Michal Kazior424121c2013-07-22 14:13:31 +0200389static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
390{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200391 struct ath10k *ar = arvif->ar;
392 u32 vdev_param;
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394 if (value != 0xFFFFFFFF)
395 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
396 ATH10K_RTS_MAX);
397
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200398 vdev_param = ar->wmi.vdev_param->rts_threshold;
399 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200400}
401
402static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
403{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200404 struct ath10k *ar = arvif->ar;
405 u32 vdev_param;
406
Michal Kazior424121c2013-07-22 14:13:31 +0200407 if (value != 0xFFFFFFFF)
408 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
409 ATH10K_FRAGMT_THRESHOLD_MIN,
410 ATH10K_FRAGMT_THRESHOLD_MAX);
411
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200412 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
413 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200414}
415
Kalle Valo5e3dd152013-06-12 20:52:10 +0300416static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
417{
418 int ret;
419
420 lockdep_assert_held(&ar->conf_mutex);
421
422 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
423 if (ret)
424 return ret;
425
426 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
427 if (ret)
428 return ret;
429
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100430 spin_lock_bh(&ar->data_lock);
431 ar->num_peers--;
432 spin_unlock_bh(&ar->data_lock);
433
Kalle Valo5e3dd152013-06-12 20:52:10 +0300434 return 0;
435}
436
437static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
438{
439 struct ath10k_peer *peer, *tmp;
440
441 lockdep_assert_held(&ar->conf_mutex);
442
443 spin_lock_bh(&ar->data_lock);
444 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
445 if (peer->vdev_id != vdev_id)
446 continue;
447
448 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
449 peer->addr, vdev_id);
450
451 list_del(&peer->list);
452 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100453 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 }
455 spin_unlock_bh(&ar->data_lock);
456}
457
Michal Kaziora96d7742013-07-16 09:38:56 +0200458static void ath10k_peer_cleanup_all(struct ath10k *ar)
459{
460 struct ath10k_peer *peer, *tmp;
461
462 lockdep_assert_held(&ar->conf_mutex);
463
464 spin_lock_bh(&ar->data_lock);
465 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
466 list_del(&peer->list);
467 kfree(peer);
468 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100469 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200470 spin_unlock_bh(&ar->data_lock);
471}
472
Kalle Valo5e3dd152013-06-12 20:52:10 +0300473/************************/
474/* Interface management */
475/************************/
476
477static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
478{
479 int ret;
480
Michal Kazior548db542013-07-05 16:15:15 +0300481 lockdep_assert_held(&ar->conf_mutex);
482
Kalle Valo5e3dd152013-06-12 20:52:10 +0300483 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
484 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
485 if (ret == 0)
486 return -ETIMEDOUT;
487
488 return 0;
489}
490
491static int ath10k_vdev_start(struct ath10k_vif *arvif)
492{
493 struct ath10k *ar = arvif->ar;
Michal Kaziorc930f742014-01-23 11:38:25 +0100494 struct cfg80211_chan_def *chandef = &ar->chandef;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300495 struct wmi_vdev_start_request_arg arg = {};
496 int ret = 0;
497
498 lockdep_assert_held(&ar->conf_mutex);
499
Wolfram Sang16735d02013-11-14 14:32:02 -0800500 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300501
502 arg.vdev_id = arvif->vdev_id;
503 arg.dtim_period = arvif->dtim_period;
504 arg.bcn_intval = arvif->beacon_interval;
505
Michal Kaziorc930f742014-01-23 11:38:25 +0100506 arg.channel.freq = chandef->chan->center_freq;
507 arg.channel.band_center_freq1 = chandef->center_freq1;
508 arg.channel.mode = chan_to_phymode(chandef);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300509
Michal Kazior89c5c842013-10-23 04:02:13 -0700510 arg.channel.min_power = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +0100511 arg.channel.max_power = chandef->chan->max_power * 2;
512 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
513 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300514
515 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
516 arg.ssid = arvif->u.ap.ssid;
517 arg.ssid_len = arvif->u.ap.ssid_len;
518 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200519
520 /* For now allow DFS for AP mode */
521 arg.channel.chan_radar =
Michal Kaziorc930f742014-01-23 11:38:25 +0100522 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
524 arg.ssid = arvif->vif->bss_conf.ssid;
525 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
526 }
527
Kalle Valo38a1d472013-09-08 17:56:14 +0300528 ath10k_dbg(ATH10K_DBG_MAC,
529 "mac vdev %d start center_freq %d phymode %s\n",
530 arg.vdev_id, arg.channel.freq,
531 ath10k_wmi_phymode_str(arg.channel.mode));
532
Kalle Valo5e3dd152013-06-12 20:52:10 +0300533 ret = ath10k_wmi_vdev_start(ar, &arg);
534 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200535 ath10k_warn("WMI vdev %i start failed: ret %d\n",
536 arg.vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300537 return ret;
538 }
539
540 ret = ath10k_vdev_setup_sync(ar);
541 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200542 ath10k_warn("vdev %i setup failed %d\n",
543 arg.vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300544 return ret;
545 }
546
547 return ret;
548}
549
550static int ath10k_vdev_stop(struct ath10k_vif *arvif)
551{
552 struct ath10k *ar = arvif->ar;
553 int ret;
554
555 lockdep_assert_held(&ar->conf_mutex);
556
Wolfram Sang16735d02013-11-14 14:32:02 -0800557 reinit_completion(&ar->vdev_setup_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558
559 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
560 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200561 ath10k_warn("WMI vdev %i stop failed: ret %d\n",
562 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563 return ret;
564 }
565
566 ret = ath10k_vdev_setup_sync(ar);
567 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200568 ath10k_warn("vdev %i setup sync failed %d\n",
569 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570 return ret;
571 }
572
573 return ret;
574}
575
576static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
577{
Michal Kaziorc930f742014-01-23 11:38:25 +0100578 struct cfg80211_chan_def *chandef = &ar->chandef;
579 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 int ret = 0;
582
583 lockdep_assert_held(&ar->conf_mutex);
584
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300585 if (!ar->monitor_present) {
586 ath10k_warn("mac montor stop -- monitor is not present\n");
587 return -EINVAL;
588 }
589
Kalle Valo5e3dd152013-06-12 20:52:10 +0300590 arg.vdev_id = vdev_id;
591 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100592 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300593
594 /* TODO setup this dynamically, what in case we
595 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100596 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200597 arg.channel.chan_radar =
598 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599
Michal Kazior89c5c842013-10-23 04:02:13 -0700600 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700601 arg.channel.max_power = channel->max_power * 2;
602 arg.channel.max_reg_power = channel->max_reg_power * 2;
603 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300604
605 ret = ath10k_wmi_vdev_start(ar, &arg);
606 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200607 ath10k_warn("Monitor vdev %i start failed: ret %d\n",
608 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609 return ret;
610 }
611
612 ret = ath10k_vdev_setup_sync(ar);
613 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200614 ath10k_warn("Monitor vdev %i setup failed %d\n",
615 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616 return ret;
617 }
618
619 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
620 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200621 ath10k_warn("Monitor vdev %i up failed: %d\n",
622 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623 goto vdev_stop;
624 }
625
626 ar->monitor_vdev_id = vdev_id;
627 ar->monitor_enabled = true;
628
629 return 0;
630
631vdev_stop:
632 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
633 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +0200634 ath10k_warn("Monitor vdev %i stop failed: %d\n",
635 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636
637 return ret;
638}
639
640static int ath10k_monitor_stop(struct ath10k *ar)
641{
642 int ret = 0;
643
644 lockdep_assert_held(&ar->conf_mutex);
645
Michal Kazior0ed00ee2013-10-16 16:45:48 +0300646 if (!ar->monitor_present) {
647 ath10k_warn("mac montor stop -- monitor is not present\n");
648 return -EINVAL;
649 }
650
651 if (!ar->monitor_enabled) {
652 ath10k_warn("mac montor stop -- monitor is not enabled\n");
653 return -EINVAL;
654 }
655
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200656 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
657 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +0200658 ath10k_warn("Monitor vdev %i down failed: %d\n",
659 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660
661 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
662 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +0200663 ath10k_warn("Monitor vdev %i stop failed: %d\n",
664 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300665
666 ret = ath10k_vdev_setup_sync(ar);
667 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +0200668 ath10k_warn("Monitor_down sync failed, vdev %i: %d\n",
669 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670
671 ar->monitor_enabled = false;
672 return ret;
673}
674
675static int ath10k_monitor_create(struct ath10k *ar)
676{
677 int bit, ret = 0;
678
679 lockdep_assert_held(&ar->conf_mutex);
680
681 if (ar->monitor_present) {
682 ath10k_warn("Monitor mode already enabled\n");
683 return 0;
684 }
685
686 bit = ffs(ar->free_vdev_map);
687 if (bit == 0) {
688 ath10k_warn("No free VDEV slots\n");
689 return -ENOMEM;
690 }
691
692 ar->monitor_vdev_id = bit - 1;
693 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
694
695 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
696 WMI_VDEV_TYPE_MONITOR,
697 0, ar->mac_addr);
698 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200699 ath10k_warn("WMI vdev %i monitor create failed: ret %d\n",
700 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300701 goto vdev_fail;
702 }
703
Kalle Valo60c3daa2013-09-08 17:56:07 +0300704 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300705 ar->monitor_vdev_id);
706
707 ar->monitor_present = true;
708 return 0;
709
710vdev_fail:
711 /*
712 * Restore the ID to the global map.
713 */
714 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
715 return ret;
716}
717
718static int ath10k_monitor_destroy(struct ath10k *ar)
719{
720 int ret = 0;
721
722 lockdep_assert_held(&ar->conf_mutex);
723
724 if (!ar->monitor_present)
725 return 0;
726
727 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
728 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200729 ath10k_warn("WMI vdev %i monitor delete failed: %d\n",
730 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300731 return ret;
732 }
733
734 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
735 ar->monitor_present = false;
736
Kalle Valo60c3daa2013-09-08 17:56:07 +0300737 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300738 ar->monitor_vdev_id);
739 return ret;
740}
741
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200742static int ath10k_start_cac(struct ath10k *ar)
743{
744 int ret;
745
746 lockdep_assert_held(&ar->conf_mutex);
747
748 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
749
750 ret = ath10k_monitor_create(ar);
751 if (ret) {
752 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
753 return ret;
754 }
755
756 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
757 if (ret) {
758 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
759 ath10k_monitor_destroy(ar);
760 return ret;
761 }
762
763 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
764 ar->monitor_vdev_id);
765
766 return 0;
767}
768
769static int ath10k_stop_cac(struct ath10k *ar)
770{
771 lockdep_assert_held(&ar->conf_mutex);
772
773 /* CAC is not running - do nothing */
774 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
775 return 0;
776
777 ath10k_monitor_stop(ar);
778 ath10k_monitor_destroy(ar);
779 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
780
781 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
782
783 return 0;
784}
785
786static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
787{
788 switch (dfs_state) {
789 case NL80211_DFS_USABLE:
790 return "USABLE";
791 case NL80211_DFS_UNAVAILABLE:
792 return "UNAVAILABLE";
793 case NL80211_DFS_AVAILABLE:
794 return "AVAILABLE";
795 default:
796 WARN_ON(1);
797 return "bug";
798 }
799}
800
801static void ath10k_config_radar_detection(struct ath10k *ar)
802{
803 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
804 bool radar = ar->hw->conf.radar_enabled;
805 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
806 enum nl80211_dfs_state dfs_state = chan->dfs_state;
807 int ret;
808
809 lockdep_assert_held(&ar->conf_mutex);
810
811 ath10k_dbg(ATH10K_DBG_MAC,
812 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
813 chan->center_freq, radar, chan_radar,
814 ath10k_dfs_state(dfs_state));
815
816 /*
817 * It's safe to call it even if CAC is not started.
818 * This call here guarantees changing channel, etc. will stop CAC.
819 */
820 ath10k_stop_cac(ar);
821
822 if (!radar)
823 return;
824
825 if (!chan_radar)
826 return;
827
828 if (dfs_state != NL80211_DFS_USABLE)
829 return;
830
831 ret = ath10k_start_cac(ar);
832 if (ret) {
833 /*
834 * Not possible to start CAC on current channel so starting
835 * radiation is not allowed, make this channel DFS_UNAVAILABLE
836 * by indicating that radar was detected.
837 */
838 ath10k_warn("failed to start CAC (%d)\n", ret);
839 ieee80211_radar_detected(ar->hw);
840 }
841}
842
Kalle Valo5e3dd152013-06-12 20:52:10 +0300843static void ath10k_control_beaconing(struct ath10k_vif *arvif,
844 struct ieee80211_bss_conf *info)
845{
846 int ret = 0;
847
Michal Kazior548db542013-07-05 16:15:15 +0300848 lockdep_assert_held(&arvif->ar->conf_mutex);
849
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850 if (!info->enable_beacon) {
851 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100852
853 arvif->is_started = false;
854 arvif->is_up = false;
855
Michal Kazior748afc42014-01-23 12:48:21 +0100856 spin_lock_bh(&arvif->ar->data_lock);
857 if (arvif->beacon) {
Michal Kazior767d34f2014-02-27 18:50:03 +0200858 dma_unmap_single(arvif->ar->dev,
859 ATH10K_SKB_CB(arvif->beacon)->paddr,
860 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kazior748afc42014-01-23 12:48:21 +0100861 dev_kfree_skb_any(arvif->beacon);
862
863 arvif->beacon = NULL;
864 arvif->beacon_sent = false;
865 }
866 spin_unlock_bh(&arvif->ar->data_lock);
867
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868 return;
869 }
870
871 arvif->tx_seq_no = 0x1000;
872
873 ret = ath10k_vdev_start(arvif);
874 if (ret)
875 return;
876
Michal Kaziorc930f742014-01-23 11:38:25 +0100877 arvif->aid = 0;
878 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
879
880 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
881 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200883 ath10k_warn("Failed to bring up vdev %d: %i\n",
884 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100885 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300886 return;
887 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100888
889 arvif->is_started = true;
890 arvif->is_up = true;
891
Kalle Valo60c3daa2013-09-08 17:56:07 +0300892 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300893}
894
895static void ath10k_control_ibss(struct ath10k_vif *arvif,
896 struct ieee80211_bss_conf *info,
897 const u8 self_peer[ETH_ALEN])
898{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200899 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300900 int ret = 0;
901
Michal Kazior548db542013-07-05 16:15:15 +0300902 lockdep_assert_held(&arvif->ar->conf_mutex);
903
Kalle Valo5e3dd152013-06-12 20:52:10 +0300904 if (!info->ibss_joined) {
905 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
906 if (ret)
907 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
908 self_peer, arvif->vdev_id, ret);
909
Michal Kaziorc930f742014-01-23 11:38:25 +0100910 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300911 return;
912
913 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100914 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300915 if (ret) {
916 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100917 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300918 return;
919 }
920
Michal Kaziorc930f742014-01-23 11:38:25 +0100921 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300922
923 return;
924 }
925
926 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
927 if (ret) {
928 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
929 self_peer, arvif->vdev_id, ret);
930 return;
931 }
932
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200933 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
934 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935 ATH10K_DEFAULT_ATIM);
936 if (ret)
937 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
938 arvif->vdev_id, ret);
939}
940
941/*
942 * Review this when mac80211 gains per-interface powersave support.
943 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300944static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300945{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300946 struct ath10k *ar = arvif->ar;
947 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300948 enum wmi_sta_powersave_param param;
949 enum wmi_sta_ps_mode psmode;
950 int ret;
951
Michal Kazior548db542013-07-05 16:15:15 +0300952 lockdep_assert_held(&arvif->ar->conf_mutex);
953
Michal Kaziorad088bf2013-10-16 15:44:46 +0300954 if (arvif->vif->type != NL80211_IFTYPE_STATION)
955 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956
957 if (conf->flags & IEEE80211_CONF_PS) {
958 psmode = WMI_STA_PS_MODE_ENABLED;
959 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
960
Michal Kaziorad088bf2013-10-16 15:44:46 +0300961 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300962 conf->dynamic_ps_timeout);
963 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +0200964 ath10k_warn("Failed to set inactivity time for vdev %d: %i\n",
965 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300966 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300968 } else {
969 psmode = WMI_STA_PS_MODE_DISABLED;
970 }
971
Kalle Valo60c3daa2013-09-08 17:56:07 +0300972 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
973 arvif->vdev_id, psmode ? "enable" : "disable");
974
Michal Kaziorad088bf2013-10-16 15:44:46 +0300975 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
976 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300977 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
978 psmode, arvif->vdev_id);
Michal Kaziorad088bf2013-10-16 15:44:46 +0300979 return ret;
980 }
981
982 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300983}
984
985/**********************/
986/* Station management */
987/**********************/
988
989static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
990 struct ath10k_vif *arvif,
991 struct ieee80211_sta *sta,
992 struct ieee80211_bss_conf *bss_conf,
993 struct wmi_peer_assoc_complete_arg *arg)
994{
Michal Kazior548db542013-07-05 16:15:15 +0300995 lockdep_assert_held(&ar->conf_mutex);
996
Kalle Valo5e3dd152013-06-12 20:52:10 +0300997 memcpy(arg->addr, sta->addr, ETH_ALEN);
998 arg->vdev_id = arvif->vdev_id;
999 arg->peer_aid = sta->aid;
1000 arg->peer_flags |= WMI_PEER_AUTH;
1001
1002 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1003 /*
1004 * Seems FW have problems with Power Save in STA
1005 * mode when we setup this parameter to high (eg. 5).
1006 * Often we see that FW don't send NULL (with clean P flags)
1007 * frame even there is info about buffered frames in beacons.
1008 * Sometimes we have to wait more than 10 seconds before FW
1009 * will wakeup. Often sending one ping from AP to our device
1010 * just fail (more than 50%).
1011 *
1012 * Seems setting this FW parameter to 1 couse FW
1013 * will check every beacon and will wakup immediately
1014 * after detection buffered data.
1015 */
1016 arg->peer_listen_intval = 1;
1017 else
1018 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1019
1020 arg->peer_num_spatial_streams = 1;
1021
1022 /*
1023 * The assoc capabilities are available only in managed mode.
1024 */
1025 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1026 arg->peer_caps = bss_conf->assoc_capability;
1027}
1028
1029static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1030 struct ath10k_vif *arvif,
1031 struct wmi_peer_assoc_complete_arg *arg)
1032{
1033 struct ieee80211_vif *vif = arvif->vif;
1034 struct ieee80211_bss_conf *info = &vif->bss_conf;
1035 struct cfg80211_bss *bss;
1036 const u8 *rsnie = NULL;
1037 const u8 *wpaie = NULL;
1038
Michal Kazior548db542013-07-05 16:15:15 +03001039 lockdep_assert_held(&ar->conf_mutex);
1040
Kalle Valo5e3dd152013-06-12 20:52:10 +03001041 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1042 info->bssid, NULL, 0, 0, 0);
1043 if (bss) {
1044 const struct cfg80211_bss_ies *ies;
1045
1046 rcu_read_lock();
1047 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1048
1049 ies = rcu_dereference(bss->ies);
1050
1051 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1052 WLAN_OUI_TYPE_MICROSOFT_WPA,
1053 ies->data,
1054 ies->len);
1055 rcu_read_unlock();
1056 cfg80211_put_bss(ar->hw->wiphy, bss);
1057 }
1058
1059 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1060 if (rsnie || wpaie) {
1061 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1062 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1063 }
1064
1065 if (wpaie) {
1066 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1067 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1068 }
1069}
1070
1071static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1072 struct ieee80211_sta *sta,
1073 struct wmi_peer_assoc_complete_arg *arg)
1074{
1075 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1076 const struct ieee80211_supported_band *sband;
1077 const struct ieee80211_rate *rates;
1078 u32 ratemask;
1079 int i;
1080
Michal Kazior548db542013-07-05 16:15:15 +03001081 lockdep_assert_held(&ar->conf_mutex);
1082
Kalle Valo5e3dd152013-06-12 20:52:10 +03001083 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1084 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1085 rates = sband->bitrates;
1086
1087 rateset->num_rates = 0;
1088
1089 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1090 if (!(ratemask & 1))
1091 continue;
1092
1093 rateset->rates[rateset->num_rates] = rates->hw_value;
1094 rateset->num_rates++;
1095 }
1096}
1097
1098static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1099 struct ieee80211_sta *sta,
1100 struct wmi_peer_assoc_complete_arg *arg)
1101{
1102 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001103 int i, n;
1104
Michal Kazior548db542013-07-05 16:15:15 +03001105 lockdep_assert_held(&ar->conf_mutex);
1106
Kalle Valo5e3dd152013-06-12 20:52:10 +03001107 if (!ht_cap->ht_supported)
1108 return;
1109
1110 arg->peer_flags |= WMI_PEER_HT;
1111 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1112 ht_cap->ampdu_factor)) - 1;
1113
1114 arg->peer_mpdu_density =
1115 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1116
1117 arg->peer_ht_caps = ht_cap->cap;
1118 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1119
1120 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1121 arg->peer_flags |= WMI_PEER_LDPC;
1122
1123 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1124 arg->peer_flags |= WMI_PEER_40MHZ;
1125 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1126 }
1127
1128 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1129 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1130
1131 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1132 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1133
1134 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1135 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1136 arg->peer_flags |= WMI_PEER_STBC;
1137 }
1138
1139 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1140 u32 stbc;
1141 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1142 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1143 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1144 arg->peer_rate_caps |= stbc;
1145 arg->peer_flags |= WMI_PEER_STBC;
1146 }
1147
Kalle Valo5e3dd152013-06-12 20:52:10 +03001148 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1149 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1150 else if (ht_cap->mcs.rx_mask[1])
1151 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1152
1153 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1154 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1155 arg->peer_ht_rates.rates[n++] = i;
1156
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001157 /*
1158 * This is a workaround for HT-enabled STAs which break the spec
1159 * and have no HT capabilities RX mask (no HT RX MCS map).
1160 *
1161 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1162 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1163 *
1164 * Firmware asserts if such situation occurs.
1165 */
1166 if (n == 0) {
1167 arg->peer_ht_rates.num_rates = 8;
1168 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1169 arg->peer_ht_rates.rates[i] = i;
1170 } else {
1171 arg->peer_ht_rates.num_rates = n;
1172 arg->peer_num_spatial_streams = sta->rx_nss;
1173 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174
Kalle Valo60c3daa2013-09-08 17:56:07 +03001175 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1176 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177 arg->peer_ht_rates.num_rates,
1178 arg->peer_num_spatial_streams);
1179}
1180
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001181static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1182 struct ath10k_vif *arvif,
1183 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001184{
1185 u32 uapsd = 0;
1186 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001187 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001188
Michal Kazior548db542013-07-05 16:15:15 +03001189 lockdep_assert_held(&ar->conf_mutex);
1190
Kalle Valo5e3dd152013-06-12 20:52:10 +03001191 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001192 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193 sta->uapsd_queues, sta->max_sp);
1194
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1196 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1197 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1198 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1199 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1200 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1201 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1202 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1203 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1204 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1205 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1206 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1207
1208
1209 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1210 max_sp = sta->max_sp;
1211
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001212 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1213 sta->addr,
1214 WMI_AP_PS_PEER_PARAM_UAPSD,
1215 uapsd);
1216 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001217 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1218 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001219 return ret;
1220 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001221
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001222 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1223 sta->addr,
1224 WMI_AP_PS_PEER_PARAM_MAX_SP,
1225 max_sp);
1226 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001227 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1228 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001229 return ret;
1230 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001231
1232 /* TODO setup this based on STA listen interval and
1233 beacon interval. Currently we don't know
1234 sta->listen_interval - mac80211 patch required.
1235 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001236 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1237 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1238 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001239 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1240 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001241 return ret;
1242 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001244
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001245 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001246}
1247
1248static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1249 struct ieee80211_sta *sta,
1250 struct wmi_peer_assoc_complete_arg *arg)
1251{
1252 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001253 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254
1255 if (!vht_cap->vht_supported)
1256 return;
1257
1258 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259 arg->peer_vht_caps = vht_cap->cap;
1260
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001261
1262 ampdu_factor = (vht_cap->cap &
1263 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1264 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1265
1266 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1267 * zero in VHT IE. Using it would result in degraded throughput.
1268 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1269 * it if VHT max_mpdu is smaller. */
1270 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1271 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1272 ampdu_factor)) - 1);
1273
Kalle Valo5e3dd152013-06-12 20:52:10 +03001274 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1275 arg->peer_flags |= WMI_PEER_80MHZ;
1276
1277 arg->peer_vht_rates.rx_max_rate =
1278 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1279 arg->peer_vht_rates.rx_mcs_set =
1280 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1281 arg->peer_vht_rates.tx_max_rate =
1282 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1283 arg->peer_vht_rates.tx_mcs_set =
1284 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1285
Kalle Valo60c3daa2013-09-08 17:56:07 +03001286 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1287 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288}
1289
1290static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1291 struct ath10k_vif *arvif,
1292 struct ieee80211_sta *sta,
1293 struct ieee80211_bss_conf *bss_conf,
1294 struct wmi_peer_assoc_complete_arg *arg)
1295{
1296 switch (arvif->vdev_type) {
1297 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001298 if (sta->wme)
1299 arg->peer_flags |= WMI_PEER_QOS;
1300
1301 if (sta->wme && sta->uapsd_queues) {
1302 arg->peer_flags |= WMI_PEER_APSD;
1303 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1304 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305 break;
1306 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001307 if (bss_conf->qos)
1308 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001309 break;
1310 default:
1311 break;
1312 }
1313}
1314
1315static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1316 struct ath10k_vif *arvif,
1317 struct ieee80211_sta *sta,
1318 struct wmi_peer_assoc_complete_arg *arg)
1319{
1320 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1321
Kalle Valo5e3dd152013-06-12 20:52:10 +03001322 switch (ar->hw->conf.chandef.chan->band) {
1323 case IEEE80211_BAND_2GHZ:
1324 if (sta->ht_cap.ht_supported) {
1325 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1326 phymode = MODE_11NG_HT40;
1327 else
1328 phymode = MODE_11NG_HT20;
1329 } else {
1330 phymode = MODE_11G;
1331 }
1332
1333 break;
1334 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001335 /*
1336 * Check VHT first.
1337 */
1338 if (sta->vht_cap.vht_supported) {
1339 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1340 phymode = MODE_11AC_VHT80;
1341 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1342 phymode = MODE_11AC_VHT40;
1343 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1344 phymode = MODE_11AC_VHT20;
1345 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1347 phymode = MODE_11NA_HT40;
1348 else
1349 phymode = MODE_11NA_HT20;
1350 } else {
1351 phymode = MODE_11A;
1352 }
1353
1354 break;
1355 default:
1356 break;
1357 }
1358
Kalle Valo38a1d472013-09-08 17:56:14 +03001359 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1360 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001361
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362 arg->peer_phymode = phymode;
1363 WARN_ON(phymode == MODE_UNKNOWN);
1364}
1365
Kalle Valob9ada652013-10-16 15:44:46 +03001366static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1367 struct ath10k_vif *arvif,
1368 struct ieee80211_sta *sta,
1369 struct ieee80211_bss_conf *bss_conf,
1370 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371{
Michal Kazior548db542013-07-05 16:15:15 +03001372 lockdep_assert_held(&ar->conf_mutex);
1373
Kalle Valob9ada652013-10-16 15:44:46 +03001374 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001375
Kalle Valob9ada652013-10-16 15:44:46 +03001376 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1377 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1378 ath10k_peer_assoc_h_rates(ar, sta, arg);
1379 ath10k_peer_assoc_h_ht(ar, sta, arg);
1380 ath10k_peer_assoc_h_vht(ar, sta, arg);
1381 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1382 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383
Kalle Valob9ada652013-10-16 15:44:46 +03001384 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385}
1386
Michal Kazior90046f52014-02-14 14:45:51 +01001387static const u32 ath10k_smps_map[] = {
1388 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1389 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1390 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1391 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1392};
1393
1394static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1395 const u8 *addr,
1396 const struct ieee80211_sta_ht_cap *ht_cap)
1397{
1398 int smps;
1399
1400 if (!ht_cap->ht_supported)
1401 return 0;
1402
1403 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1404 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1405
1406 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1407 return -EINVAL;
1408
1409 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1410 WMI_PEER_SMPS_STATE,
1411 ath10k_smps_map[smps]);
1412}
1413
Kalle Valo5e3dd152013-06-12 20:52:10 +03001414/* can be called only in mac80211 callbacks due to `key_count` usage */
1415static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1416 struct ieee80211_vif *vif,
1417 struct ieee80211_bss_conf *bss_conf)
1418{
1419 struct ath10k *ar = hw->priv;
1420 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001421 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001422 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001423 struct ieee80211_sta *ap_sta;
1424 int ret;
1425
Michal Kazior548db542013-07-05 16:15:15 +03001426 lockdep_assert_held(&ar->conf_mutex);
1427
Kalle Valo5e3dd152013-06-12 20:52:10 +03001428 rcu_read_lock();
1429
1430 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1431 if (!ap_sta) {
Ben Greear69244e52014-02-27 18:50:00 +02001432 ath10k_warn("Failed to find station entry for %pM, vdev %i\n",
1433 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001434 rcu_read_unlock();
1435 return;
1436 }
1437
Michal Kazior90046f52014-02-14 14:45:51 +01001438 /* ap_sta must be accessed only within rcu section which must be left
1439 * before calling ath10k_setup_peer_smps() which might sleep. */
1440 ht_cap = ap_sta->ht_cap;
1441
Kalle Valob9ada652013-10-16 15:44:46 +03001442 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1443 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001444 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001445 ath10k_warn("Peer assoc prepare failed for %pM vdev %i\n: %d",
1446 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447 rcu_read_unlock();
1448 return;
1449 }
1450
1451 rcu_read_unlock();
1452
Kalle Valob9ada652013-10-16 15:44:46 +03001453 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1454 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001455 ath10k_warn("Peer assoc failed for %pM vdev %i\n: %d",
1456 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001457 return;
1458 }
1459
Michal Kazior90046f52014-02-14 14:45:51 +01001460 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1461 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001462 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1463 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001464 return;
1465 }
1466
Kalle Valo60c3daa2013-09-08 17:56:07 +03001467 ath10k_dbg(ATH10K_DBG_MAC,
1468 "mac vdev %d up (associated) bssid %pM aid %d\n",
1469 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1470
Michal Kaziorc930f742014-01-23 11:38:25 +01001471 arvif->aid = bss_conf->aid;
1472 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1473
1474 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1475 if (ret) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001476 ath10k_warn("VDEV: %d up failed: ret %d\n",
1477 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001478 return;
1479 }
1480
1481 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001482}
1483
1484/*
1485 * FIXME: flush TIDs
1486 */
1487static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1488 struct ieee80211_vif *vif)
1489{
1490 struct ath10k *ar = hw->priv;
1491 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1492 int ret;
1493
Michal Kazior548db542013-07-05 16:15:15 +03001494 lockdep_assert_held(&ar->conf_mutex);
1495
Kalle Valo5e3dd152013-06-12 20:52:10 +03001496 /*
1497 * For some reason, calling VDEV-DOWN before VDEV-STOP
1498 * makes the FW to send frames via HTT after disassociation.
1499 * No idea why this happens, even though VDEV-DOWN is supposed
1500 * to be analogous to link down, so just stop the VDEV.
1501 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001502 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1503 arvif->vdev_id);
1504
1505 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001506 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001507
1508 /*
1509 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1510 * report beacons from previously associated network through HTT.
1511 * This in turn would spam mac80211 WARN_ON if we bring down all
1512 * interfaces as it expects there is no rx when no interface is
1513 * running.
1514 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001515 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1516
1517 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001519
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001520 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001521
1522 arvif->is_started = false;
1523 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001524}
1525
1526static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001527 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528{
Kalle Valob9ada652013-10-16 15:44:46 +03001529 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001530 int ret = 0;
1531
Michal Kazior548db542013-07-05 16:15:15 +03001532 lockdep_assert_held(&ar->conf_mutex);
1533
Kalle Valob9ada652013-10-16 15:44:46 +03001534 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001535 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001536 ath10k_warn("WMI peer assoc prepare failed for %pM vdev %i: %i\n",
1537 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001538 return ret;
1539 }
1540
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001541 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001542 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1543 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001544 ath10k_warn("Peer assoc failed for STA %pM vdev %i: %d\n",
1545 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001546 return ret;
1547 }
1548
Michal Kazior90046f52014-02-14 14:45:51 +01001549 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1550 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001551 ath10k_warn("failed to setup peer SMPS for vdev: %d\n", ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001552 return ret;
1553 }
1554
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1556 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001557 ath10k_warn("could not install peer wep keys for vdev %i: %d\n",
1558 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001559 return ret;
1560 }
1561
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001562 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1563 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001564 ath10k_warn("could not set qos params for STA %pM for vdev %i: %d\n",
1565 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001566 return ret;
1567 }
1568
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569 return ret;
1570}
1571
1572static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1573 struct ieee80211_sta *sta)
1574{
1575 int ret = 0;
1576
Michal Kazior548db542013-07-05 16:15:15 +03001577 lockdep_assert_held(&ar->conf_mutex);
1578
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1580 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001581 ath10k_warn("could not clear all peer wep keys for vdev %i: %d\n",
1582 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 return ret;
1584 }
1585
1586 return ret;
1587}
1588
1589/**************/
1590/* Regulatory */
1591/**************/
1592
1593static int ath10k_update_channel_list(struct ath10k *ar)
1594{
1595 struct ieee80211_hw *hw = ar->hw;
1596 struct ieee80211_supported_band **bands;
1597 enum ieee80211_band band;
1598 struct ieee80211_channel *channel;
1599 struct wmi_scan_chan_list_arg arg = {0};
1600 struct wmi_channel_arg *ch;
1601 bool passive;
1602 int len;
1603 int ret;
1604 int i;
1605
Michal Kazior548db542013-07-05 16:15:15 +03001606 lockdep_assert_held(&ar->conf_mutex);
1607
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 bands = hw->wiphy->bands;
1609 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1610 if (!bands[band])
1611 continue;
1612
1613 for (i = 0; i < bands[band]->n_channels; i++) {
1614 if (bands[band]->channels[i].flags &
1615 IEEE80211_CHAN_DISABLED)
1616 continue;
1617
1618 arg.n_channels++;
1619 }
1620 }
1621
1622 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1623 arg.channels = kzalloc(len, GFP_KERNEL);
1624 if (!arg.channels)
1625 return -ENOMEM;
1626
1627 ch = arg.channels;
1628 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1629 if (!bands[band])
1630 continue;
1631
1632 for (i = 0; i < bands[band]->n_channels; i++) {
1633 channel = &bands[band]->channels[i];
1634
1635 if (channel->flags & IEEE80211_CHAN_DISABLED)
1636 continue;
1637
1638 ch->allow_ht = true;
1639
1640 /* FIXME: when should we really allow VHT? */
1641 ch->allow_vht = true;
1642
1643 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001644 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001645
1646 ch->ht40plus =
1647 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1648
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001649 ch->chan_radar =
1650 !!(channel->flags & IEEE80211_CHAN_RADAR);
1651
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001652 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 ch->passive = passive;
1654
1655 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001656 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001657 ch->max_power = channel->max_power * 2;
1658 ch->max_reg_power = channel->max_reg_power * 2;
1659 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001660 ch->reg_class_id = 0; /* FIXME */
1661
1662 /* FIXME: why use only legacy modes, why not any
1663 * HT/VHT modes? Would that even make any
1664 * difference? */
1665 if (channel->band == IEEE80211_BAND_2GHZ)
1666 ch->mode = MODE_11G;
1667 else
1668 ch->mode = MODE_11A;
1669
1670 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1671 continue;
1672
1673 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001674 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1675 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001676 ch->freq, ch->max_power, ch->max_reg_power,
1677 ch->max_antenna_gain, ch->mode);
1678
1679 ch++;
1680 }
1681 }
1682
1683 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1684 kfree(arg.channels);
1685
1686 return ret;
1687}
1688
Michal Kaziorf7843d72013-07-16 09:38:52 +02001689static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692 int ret;
1693
Michal Kaziorf7843d72013-07-16 09:38:52 +02001694 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
1696 ret = ath10k_update_channel_list(ar);
1697 if (ret)
1698 ath10k_warn("could not update channel list (%d)\n", ret);
1699
1700 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001701
Kalle Valo5e3dd152013-06-12 20:52:10 +03001702 /* Target allows setting up per-band regdomain but ath_common provides
1703 * a combined one only */
1704 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001705 regpair->reg_domain,
1706 regpair->reg_domain, /* 2ghz */
1707 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001708 regpair->reg_2ghz_ctl,
1709 regpair->reg_5ghz_ctl);
1710 if (ret)
1711 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001712}
Michal Kazior548db542013-07-05 16:15:15 +03001713
Michal Kaziorf7843d72013-07-16 09:38:52 +02001714static void ath10k_reg_notifier(struct wiphy *wiphy,
1715 struct regulatory_request *request)
1716{
1717 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1718 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001719 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001720
1721 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1722
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001723 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1724 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1725 request->dfs_region);
1726 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1727 request->dfs_region);
1728 if (!result)
1729 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1730 request->dfs_region);
1731 }
1732
Michal Kaziorf7843d72013-07-16 09:38:52 +02001733 mutex_lock(&ar->conf_mutex);
1734 if (ar->state == ATH10K_STATE_ON)
1735 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001736 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737}
1738
1739/***************/
1740/* TX handlers */
1741/***************/
1742
Michal Kazior42c3aa62013-10-02 11:03:38 +02001743static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1744{
1745 if (ieee80211_is_mgmt(hdr->frame_control))
1746 return HTT_DATA_TX_EXT_TID_MGMT;
1747
1748 if (!ieee80211_is_data_qos(hdr->frame_control))
1749 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1750
1751 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1752 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1753
1754 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1755}
1756
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001757static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1758 struct ieee80211_tx_info *info)
1759{
1760 if (info->control.vif)
1761 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1762
1763 if (ar->monitor_enabled)
1764 return ar->monitor_vdev_id;
1765
1766 ath10k_warn("could not resolve vdev id\n");
1767 return 0;
1768}
1769
Kalle Valo5e3dd152013-06-12 20:52:10 +03001770/*
1771 * Frames sent to the FW have to be in "Native Wifi" format.
1772 * Strip the QoS field from the 802.11 header.
1773 */
1774static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1775 struct ieee80211_tx_control *control,
1776 struct sk_buff *skb)
1777{
1778 struct ieee80211_hdr *hdr = (void *)skb->data;
1779 u8 *qos_ctl;
1780
1781 if (!ieee80211_is_data_qos(hdr->frame_control))
1782 return;
1783
1784 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001785 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1786 skb->data, (void *)qos_ctl - (void *)skb->data);
1787 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001788}
1789
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001790static void ath10k_tx_wep_key_work(struct work_struct *work)
1791{
1792 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1793 wep_key_work);
1794 int ret, keyidx = arvif->def_wep_key_newidx;
1795
1796 if (arvif->def_wep_key_idx == keyidx)
1797 return;
1798
1799 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1800 arvif->vdev_id, keyidx);
1801
1802 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1803 arvif->vdev_id,
1804 arvif->ar->wmi.vdev_param->def_keyid,
1805 keyidx);
1806 if (ret) {
1807 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1808 return;
1809 }
1810
1811 arvif->def_wep_key_idx = keyidx;
1812}
1813
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1815{
1816 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1817 struct ieee80211_vif *vif = info->control.vif;
1818 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1819 struct ath10k *ar = arvif->ar;
1820 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1821 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001822
Kalle Valo5e3dd152013-06-12 20:52:10 +03001823 if (!ieee80211_has_protected(hdr->frame_control))
1824 return;
1825
1826 if (!key)
1827 return;
1828
1829 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1830 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1831 return;
1832
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001833 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001834 return;
1835
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001836 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1837 * queueing frames until key index is updated is not an option because
1838 * sk_buff may need more processing to be done, e.g. offchannel */
1839 arvif->def_wep_key_newidx = key->keyidx;
1840 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001841}
1842
1843static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1844{
1845 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1846 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1847 struct ieee80211_vif *vif = info->control.vif;
1848 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1849
1850 /* This is case only for P2P_GO */
1851 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1852 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1853 return;
1854
1855 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1856 spin_lock_bh(&ar->data_lock);
1857 if (arvif->u.ap.noa_data)
1858 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1859 GFP_ATOMIC))
1860 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1861 arvif->u.ap.noa_data,
1862 arvif->u.ap.noa_len);
1863 spin_unlock_bh(&ar->data_lock);
1864 }
1865}
1866
1867static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1868{
1869 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001870 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871
Michal Kazior961d4c32013-08-09 10:13:34 +02001872 if (ar->htt.target_version_major >= 3) {
1873 /* Since HTT 3.0 there is no separate mgmt tx command */
1874 ret = ath10k_htt_tx(&ar->htt, skb);
1875 goto exit;
1876 }
1877
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001878 if (ieee80211_is_mgmt(hdr->frame_control)) {
1879 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1880 ar->fw_features)) {
1881 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1882 ATH10K_MAX_NUM_MGMT_PENDING) {
1883 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1884 ret = -EBUSY;
1885 goto exit;
1886 }
1887
1888 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1889 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1890 } else {
1891 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1892 }
1893 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1894 ar->fw_features) &&
1895 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896 /* FW does not report tx status properly for NullFunc frames
1897 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001898 * those frames when it detects link/beacon loss and depends
1899 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001900 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001901 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03001902 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001903 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001904
Michal Kazior961d4c32013-08-09 10:13:34 +02001905exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001906 if (ret) {
1907 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1908 ieee80211_free_txskb(ar->hw, skb);
1909 }
1910}
1911
1912void ath10k_offchan_tx_purge(struct ath10k *ar)
1913{
1914 struct sk_buff *skb;
1915
1916 for (;;) {
1917 skb = skb_dequeue(&ar->offchan_tx_queue);
1918 if (!skb)
1919 break;
1920
1921 ieee80211_free_txskb(ar->hw, skb);
1922 }
1923}
1924
1925void ath10k_offchan_tx_work(struct work_struct *work)
1926{
1927 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1928 struct ath10k_peer *peer;
1929 struct ieee80211_hdr *hdr;
1930 struct sk_buff *skb;
1931 const u8 *peer_addr;
1932 int vdev_id;
1933 int ret;
1934
1935 /* FW requirement: We must create a peer before FW will send out
1936 * an offchannel frame. Otherwise the frame will be stuck and
1937 * never transmitted. We delete the peer upon tx completion.
1938 * It is unlikely that a peer for offchannel tx will already be
1939 * present. However it may be in some rare cases so account for that.
1940 * Otherwise we might remove a legitimate peer and break stuff. */
1941
1942 for (;;) {
1943 skb = skb_dequeue(&ar->offchan_tx_queue);
1944 if (!skb)
1945 break;
1946
1947 mutex_lock(&ar->conf_mutex);
1948
Kalle Valo60c3daa2013-09-08 17:56:07 +03001949 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 skb);
1951
1952 hdr = (struct ieee80211_hdr *)skb->data;
1953 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001954 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955
1956 spin_lock_bh(&ar->data_lock);
1957 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1958 spin_unlock_bh(&ar->data_lock);
1959
1960 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001961 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1963 peer_addr, vdev_id);
1964
1965 if (!peer) {
1966 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1967 if (ret)
1968 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1969 peer_addr, vdev_id, ret);
1970 }
1971
1972 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08001973 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001974 ar->offchan_tx_skb = skb;
1975 spin_unlock_bh(&ar->data_lock);
1976
1977 ath10k_tx_htt(ar, skb);
1978
1979 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1980 3 * HZ);
1981 if (ret <= 0)
1982 ath10k_warn("timed out waiting for offchannel skb %p\n",
1983 skb);
1984
1985 if (!peer) {
1986 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1987 if (ret)
1988 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1989 peer_addr, vdev_id, ret);
1990 }
1991
1992 mutex_unlock(&ar->conf_mutex);
1993 }
1994}
1995
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001996void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1997{
1998 struct sk_buff *skb;
1999
2000 for (;;) {
2001 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2002 if (!skb)
2003 break;
2004
2005 ieee80211_free_txskb(ar->hw, skb);
2006 }
2007}
2008
2009void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2010{
2011 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2012 struct sk_buff *skb;
2013 int ret;
2014
2015 for (;;) {
2016 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2017 if (!skb)
2018 break;
2019
2020 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002021 if (ret) {
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002022 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002023 ieee80211_free_txskb(ar->hw, skb);
2024 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002025 }
2026}
2027
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028/************/
2029/* Scanning */
2030/************/
2031
2032/*
2033 * This gets called if we dont get a heart-beat during scan.
2034 * This may indicate the FW has hung and we need to abort the
2035 * scan manually to prevent cancel_hw_scan() from deadlocking
2036 */
2037void ath10k_reset_scan(unsigned long ptr)
2038{
2039 struct ath10k *ar = (struct ath10k *)ptr;
2040
2041 spin_lock_bh(&ar->data_lock);
2042 if (!ar->scan.in_progress) {
2043 spin_unlock_bh(&ar->data_lock);
2044 return;
2045 }
2046
2047 ath10k_warn("scan timeout. resetting. fw issue?\n");
2048
2049 if (ar->scan.is_roc)
2050 ieee80211_remain_on_channel_expired(ar->hw);
2051 else
2052 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2053
2054 ar->scan.in_progress = false;
2055 complete_all(&ar->scan.completed);
2056 spin_unlock_bh(&ar->data_lock);
2057}
2058
2059static int ath10k_abort_scan(struct ath10k *ar)
2060{
2061 struct wmi_stop_scan_arg arg = {
2062 .req_id = 1, /* FIXME */
2063 .req_type = WMI_SCAN_STOP_ONE,
2064 .u.scan_id = ATH10K_SCAN_ID,
2065 };
2066 int ret;
2067
2068 lockdep_assert_held(&ar->conf_mutex);
2069
2070 del_timer_sync(&ar->scan.timeout);
2071
2072 spin_lock_bh(&ar->data_lock);
2073 if (!ar->scan.in_progress) {
2074 spin_unlock_bh(&ar->data_lock);
2075 return 0;
2076 }
2077
2078 ar->scan.aborting = true;
2079 spin_unlock_bh(&ar->data_lock);
2080
2081 ret = ath10k_wmi_stop_scan(ar, &arg);
2082 if (ret) {
2083 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03002084 spin_lock_bh(&ar->data_lock);
2085 ar->scan.in_progress = false;
2086 ath10k_offchan_tx_purge(ar);
2087 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002088 return -EIO;
2089 }
2090
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2092 if (ret == 0)
2093 ath10k_warn("timed out while waiting for scan to stop\n");
2094
2095 /* scan completion may be done right after we timeout here, so let's
2096 * check the in_progress and tell mac80211 scan is completed. if we
2097 * don't do that and FW fails to send us scan completion indication
2098 * then userspace won't be able to scan anymore */
2099 ret = 0;
2100
2101 spin_lock_bh(&ar->data_lock);
2102 if (ar->scan.in_progress) {
2103 ath10k_warn("could not stop scan. its still in progress\n");
2104 ar->scan.in_progress = false;
2105 ath10k_offchan_tx_purge(ar);
2106 ret = -ETIMEDOUT;
2107 }
2108 spin_unlock_bh(&ar->data_lock);
2109
2110 return ret;
2111}
2112
2113static int ath10k_start_scan(struct ath10k *ar,
2114 const struct wmi_start_scan_arg *arg)
2115{
2116 int ret;
2117
2118 lockdep_assert_held(&ar->conf_mutex);
2119
2120 ret = ath10k_wmi_start_scan(ar, arg);
2121 if (ret)
2122 return ret;
2123
Kalle Valo5e3dd152013-06-12 20:52:10 +03002124 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2125 if (ret == 0) {
2126 ath10k_abort_scan(ar);
2127 return ret;
2128 }
2129
2130 /* the scan can complete earlier, before we even
2131 * start the timer. in that case the timer handler
2132 * checks ar->scan.in_progress and bails out if its
2133 * false. Add a 200ms margin to account event/command
2134 * processing. */
2135 mod_timer(&ar->scan.timeout, jiffies +
2136 msecs_to_jiffies(arg->max_scan_time+200));
2137 return 0;
2138}
2139
2140/**********************/
2141/* mac80211 callbacks */
2142/**********************/
2143
2144static void ath10k_tx(struct ieee80211_hw *hw,
2145 struct ieee80211_tx_control *control,
2146 struct sk_buff *skb)
2147{
2148 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2149 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2150 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002151 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002152
2153 /* We should disable CCK RATE due to P2P */
2154 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2155 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2156
2157 /* we must calculate tid before we apply qos workaround
2158 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002159 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002160 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002161
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002162 /* it makes no sense to process injected frames like that */
2163 if (info->control.vif &&
2164 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2165 ath10k_tx_h_qos_workaround(hw, control, skb);
2166 ath10k_tx_h_update_wep_key(skb);
2167 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2168 ath10k_tx_h_seq_no(skb);
2169 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002171 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002172 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173 ATH10K_SKB_CB(skb)->htt.tid = tid;
2174
2175 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2176 spin_lock_bh(&ar->data_lock);
2177 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002178 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002179 spin_unlock_bh(&ar->data_lock);
2180
2181 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2182
2183 skb_queue_tail(&ar->offchan_tx_queue, skb);
2184 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2185 return;
2186 }
2187
2188 ath10k_tx_htt(ar, skb);
2189}
2190
2191/*
2192 * Initialize various parameters with default vaules.
2193 */
Michal Kazioraffd3212013-07-16 09:54:35 +02002194void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002195{
2196 lockdep_assert_held(&ar->conf_mutex);
2197
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002198 ath10k_stop_cac(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002199 del_timer_sync(&ar->scan.timeout);
2200 ath10k_offchan_tx_purge(ar);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002201 ath10k_mgmt_over_wmi_tx_purge(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002202 ath10k_peer_cleanup_all(ar);
2203 ath10k_core_stop(ar);
2204 ath10k_hif_power_down(ar);
2205
2206 spin_lock_bh(&ar->data_lock);
2207 if (ar->scan.in_progress) {
2208 del_timer(&ar->scan.timeout);
2209 ar->scan.in_progress = false;
2210 ieee80211_scan_completed(ar->hw, true);
2211 }
2212 spin_unlock_bh(&ar->data_lock);
2213}
2214
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215static int ath10k_start(struct ieee80211_hw *hw)
2216{
2217 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002218 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002219
Michal Kazior548db542013-07-05 16:15:15 +03002220 mutex_lock(&ar->conf_mutex);
2221
Michal Kazioraffd3212013-07-16 09:54:35 +02002222 if (ar->state != ATH10K_STATE_OFF &&
2223 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002224 ret = -EINVAL;
2225 goto exit;
2226 }
2227
2228 ret = ath10k_hif_power_up(ar);
2229 if (ret) {
2230 ath10k_err("could not init hif (%d)\n", ret);
2231 ar->state = ATH10K_STATE_OFF;
2232 goto exit;
2233 }
2234
2235 ret = ath10k_core_start(ar);
2236 if (ret) {
2237 ath10k_err("could not init core (%d)\n", ret);
2238 ath10k_hif_power_down(ar);
2239 ar->state = ATH10K_STATE_OFF;
2240 goto exit;
2241 }
2242
Michal Kazioraffd3212013-07-16 09:54:35 +02002243 if (ar->state == ATH10K_STATE_OFF)
2244 ar->state = ATH10K_STATE_ON;
2245 else if (ar->state == ATH10K_STATE_RESTARTING)
2246 ar->state = ATH10K_STATE_RESTARTED;
2247
Bartosz Markowski226a3392013-09-26 17:47:16 +02002248 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002249 if (ret)
2250 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2251 ret);
2252
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002253 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002254 if (ret)
2255 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2256 ret);
2257
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002258 /*
2259 * By default FW set ARP frames ac to voice (6). In that case ARP
2260 * exchange is not working properly for UAPSD enabled AP. ARP requests
2261 * which arrives with access category 0 are processed by network stack
2262 * and send back with access category 0, but FW changes access category
2263 * to 6. Set ARP frames access category to best effort (0) solves
2264 * this problem.
2265 */
2266
2267 ret = ath10k_wmi_pdev_set_param(ar,
2268 ar->wmi.pdev_param->arp_ac_override, 0);
2269 if (ret) {
2270 ath10k_warn("could not set arp ac override parameter: %d\n",
2271 ret);
2272 goto exit;
2273 }
2274
Michal Kaziorf7843d72013-07-16 09:38:52 +02002275 ath10k_regd_update(ar);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002276 ret = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002277
Michal Kazior818bdd12013-07-16 09:38:57 +02002278exit:
Michal Kazior548db542013-07-05 16:15:15 +03002279 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002280 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281}
2282
2283static void ath10k_stop(struct ieee80211_hw *hw)
2284{
2285 struct ath10k *ar = hw->priv;
2286
Michal Kazior548db542013-07-05 16:15:15 +03002287 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02002288 if (ar->state == ATH10K_STATE_ON ||
2289 ar->state == ATH10K_STATE_RESTARTED ||
2290 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02002291 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02002292
Michal Kaziorf7843d72013-07-16 09:38:52 +02002293 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03002294 mutex_unlock(&ar->conf_mutex);
2295
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002296 ath10k_mgmt_over_wmi_tx_purge(ar);
2297
Michal Kazior548db542013-07-05 16:15:15 +03002298 cancel_work_sync(&ar->offchan_tx_work);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002299 cancel_work_sync(&ar->wmi_mgmt_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02002300 cancel_work_sync(&ar->restart_work);
2301}
2302
Michal Kaziorad088bf2013-10-16 15:44:46 +03002303static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002304{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002305 struct ath10k_vif *arvif;
2306 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002307
2308 lockdep_assert_held(&ar->conf_mutex);
2309
Michal Kaziorad088bf2013-10-16 15:44:46 +03002310 list_for_each_entry(arvif, &ar->arvifs, list) {
2311 ret = ath10k_mac_vif_setup_ps(arvif);
2312 if (ret) {
2313 ath10k_warn("could not setup powersave (%d)\n", ret);
2314 break;
2315 }
2316 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002317
Michal Kaziorad088bf2013-10-16 15:44:46 +03002318 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319}
2320
Michal Kaziorc930f742014-01-23 11:38:25 +01002321static const char *chandef_get_width(enum nl80211_chan_width width)
2322{
2323 switch (width) {
2324 case NL80211_CHAN_WIDTH_20_NOHT:
2325 return "20 (noht)";
2326 case NL80211_CHAN_WIDTH_20:
2327 return "20";
2328 case NL80211_CHAN_WIDTH_40:
2329 return "40";
2330 case NL80211_CHAN_WIDTH_80:
2331 return "80";
2332 case NL80211_CHAN_WIDTH_80P80:
2333 return "80+80";
2334 case NL80211_CHAN_WIDTH_160:
2335 return "160";
2336 case NL80211_CHAN_WIDTH_5:
2337 return "5";
2338 case NL80211_CHAN_WIDTH_10:
2339 return "10";
2340 }
2341 return "?";
2342}
2343
2344static void ath10k_config_chan(struct ath10k *ar)
2345{
2346 struct ath10k_vif *arvif;
2347 bool monitor_was_enabled;
2348 int ret;
2349
2350 lockdep_assert_held(&ar->conf_mutex);
2351
2352 ath10k_dbg(ATH10K_DBG_MAC,
2353 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2354 ar->chandef.chan->center_freq,
2355 ar->chandef.center_freq1,
2356 ar->chandef.center_freq2,
2357 chandef_get_width(ar->chandef.width));
2358
2359 /* First stop monitor interface. Some FW versions crash if there's a
2360 * lone monitor interface. */
2361 monitor_was_enabled = ar->monitor_enabled;
2362
2363 if (ar->monitor_enabled)
2364 ath10k_monitor_stop(ar);
2365
2366 list_for_each_entry(arvif, &ar->arvifs, list) {
2367 if (!arvif->is_started)
2368 continue;
2369
2370 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2371 continue;
2372
2373 ret = ath10k_vdev_stop(arvif);
2374 if (ret) {
2375 ath10k_warn("could not stop vdev %d (%d)\n",
2376 arvif->vdev_id, ret);
2377 continue;
2378 }
2379 }
2380
2381 /* all vdevs are now stopped - now attempt to restart them */
2382
2383 list_for_each_entry(arvif, &ar->arvifs, list) {
2384 if (!arvif->is_started)
2385 continue;
2386
2387 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2388 continue;
2389
2390 ret = ath10k_vdev_start(arvif);
2391 if (ret) {
2392 ath10k_warn("could not start vdev %d (%d)\n",
2393 arvif->vdev_id, ret);
2394 continue;
2395 }
2396
2397 if (!arvif->is_up)
2398 continue;
2399
2400 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2401 arvif->bssid);
2402 if (ret) {
2403 ath10k_warn("could not bring vdev up %d (%d)\n",
2404 arvif->vdev_id, ret);
2405 continue;
2406 }
2407 }
2408
2409 if (monitor_was_enabled)
2410 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2411}
2412
Kalle Valo5e3dd152013-06-12 20:52:10 +03002413static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2414{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002415 struct ath10k *ar = hw->priv;
2416 struct ieee80211_conf *conf = &hw->conf;
2417 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002418 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002419
2420 mutex_lock(&ar->conf_mutex);
2421
2422 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002423 ath10k_dbg(ATH10K_DBG_MAC,
2424 "mac config channel %d mhz flags 0x%x\n",
2425 conf->chandef.chan->center_freq,
2426 conf->chandef.chan->flags);
2427
Kalle Valo5e3dd152013-06-12 20:52:10 +03002428 spin_lock_bh(&ar->data_lock);
2429 ar->rx_channel = conf->chandef.chan;
2430 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002431
2432 ath10k_config_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002433
2434 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2435 ar->chandef = conf->chandef;
2436 ath10k_config_chan(ar);
2437 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002438 }
2439
Michal Kazior5474efe2013-10-23 04:02:15 -07002440 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2441 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2442 hw->conf.power_level);
2443
2444 param = ar->wmi.pdev_param->txpower_limit2g;
2445 ret = ath10k_wmi_pdev_set_param(ar, param,
2446 hw->conf.power_level * 2);
2447 if (ret)
2448 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2449 hw->conf.power_level, ret);
2450
2451 param = ar->wmi.pdev_param->txpower_limit5g;
2452 ret = ath10k_wmi_pdev_set_param(ar, param,
2453 hw->conf.power_level * 2);
2454 if (ret)
2455 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2456 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457 }
2458
Michal Kazioraffd3212013-07-16 09:54:35 +02002459 if (changed & IEEE80211_CONF_CHANGE_PS)
2460 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461
2462 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2463 if (conf->flags & IEEE80211_CONF_MONITOR)
2464 ret = ath10k_monitor_create(ar);
2465 else
2466 ret = ath10k_monitor_destroy(ar);
2467 }
2468
2469 mutex_unlock(&ar->conf_mutex);
2470 return ret;
2471}
2472
2473/*
2474 * TODO:
2475 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2476 * because we will send mgmt frames without CCK. This requirement
2477 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2478 * in the TX packet.
2479 */
2480static int ath10k_add_interface(struct ieee80211_hw *hw,
2481 struct ieee80211_vif *vif)
2482{
2483 struct ath10k *ar = hw->priv;
2484 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2485 enum wmi_sta_powersave_param param;
2486 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002487 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002489 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490
2491 mutex_lock(&ar->conf_mutex);
2492
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002493 memset(arvif, 0, sizeof(*arvif));
2494
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495 arvif->ar = ar;
2496 arvif->vif = vif;
2497
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002498 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002499 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002500
Kalle Valo5e3dd152013-06-12 20:52:10 +03002501 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2502 ath10k_warn("Only one monitor interface allowed\n");
2503 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002504 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002505 }
2506
2507 bit = ffs(ar->free_vdev_map);
2508 if (bit == 0) {
2509 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002510 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002511 }
2512
2513 arvif->vdev_id = bit - 1;
2514 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515
2516 if (ar->p2p)
2517 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2518
2519 switch (vif->type) {
2520 case NL80211_IFTYPE_UNSPECIFIED:
2521 case NL80211_IFTYPE_STATION:
2522 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2523 if (vif->p2p)
2524 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2525 break;
2526 case NL80211_IFTYPE_ADHOC:
2527 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2528 break;
2529 case NL80211_IFTYPE_AP:
2530 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2531
2532 if (vif->p2p)
2533 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2534 break;
2535 case NL80211_IFTYPE_MONITOR:
2536 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2537 break;
2538 default:
2539 WARN_ON(1);
2540 break;
2541 }
2542
Kalle Valo60c3daa2013-09-08 17:56:07 +03002543 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002544 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2545
2546 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2547 arvif->vdev_subtype, vif->addr);
2548 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002549 ath10k_warn("WMI vdev %i create failed: ret %d\n",
2550 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002551 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 }
2553
Michal Kazior9dad14a2013-10-16 15:44:45 +03002554 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002555 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002556
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002557 vdev_param = ar->wmi.vdev_param->def_keyid;
2558 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002559 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002560 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002561 ath10k_warn("Failed to set vdev %i default keyid: %d\n",
2562 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002563 goto err_vdev_delete;
2564 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002565
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002566 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2567 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002569 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002570 if (ret && ret != -EOPNOTSUPP) {
Ben Greear69244e52014-02-27 18:50:00 +02002571 ath10k_warn("Failed to set vdev %i TX encap: %d\n",
2572 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002573 goto err_vdev_delete;
2574 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575
2576 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2577 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2578 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002579 ath10k_warn("Failed to create vdev %i peer for AP: %d\n",
2580 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002581 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002583
Kalle Valo5a13e762014-01-20 11:01:46 +02002584 ret = ath10k_mac_set_kickout(arvif);
2585 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002586 ath10k_warn("Failed to set vdev %i kickout parameters: %d\n",
2587 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002588 goto err_peer_delete;
2589 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590 }
2591
2592 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2593 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2594 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2595 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2596 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002597 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002598 ath10k_warn("Failed to set vdev %i RX wake policy: %d\n",
2599 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002600 goto err_peer_delete;
2601 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002602
2603 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2604 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2605 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2606 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002607 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002608 ath10k_warn("Failed to set vdev %i TX wake thresh: %d\n",
2609 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002610 goto err_peer_delete;
2611 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002612
2613 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2614 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2615 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2616 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002617 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002618 ath10k_warn("Failed to set vdev %i PSPOLL count: %d\n",
2619 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002620 goto err_peer_delete;
2621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622 }
2623
Michal Kazior424121c2013-07-22 14:13:31 +02002624 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002625 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002626 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2627 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002628 goto err_peer_delete;
2629 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002630
Michal Kazior424121c2013-07-22 14:13:31 +02002631 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002632 if (ret) {
Michal Kazior679c54a2013-07-05 16:15:04 +03002633 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2634 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002635 goto err_peer_delete;
2636 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002637
Kalle Valo5e3dd152013-06-12 20:52:10 +03002638 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2639 ar->monitor_present = true;
2640
Kalle Valo5e3dd152013-06-12 20:52:10 +03002641 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002642 return 0;
2643
2644err_peer_delete:
2645 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2646 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2647
2648err_vdev_delete:
2649 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2650 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002651 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002652
2653err:
2654 mutex_unlock(&ar->conf_mutex);
2655
Kalle Valo5e3dd152013-06-12 20:52:10 +03002656 return ret;
2657}
2658
2659static void ath10k_remove_interface(struct ieee80211_hw *hw,
2660 struct ieee80211_vif *vif)
2661{
2662 struct ath10k *ar = hw->priv;
2663 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2664 int ret;
2665
2666 mutex_lock(&ar->conf_mutex);
2667
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002668 cancel_work_sync(&arvif->wep_key_work);
2669
Michal Kaziored543882013-09-13 14:16:56 +02002670 spin_lock_bh(&ar->data_lock);
2671 if (arvif->beacon) {
2672 dev_kfree_skb_any(arvif->beacon);
2673 arvif->beacon = NULL;
2674 }
2675 spin_unlock_bh(&ar->data_lock);
2676
Kalle Valo5e3dd152013-06-12 20:52:10 +03002677 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002678 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679
2680 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2681 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2682 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002683 ath10k_warn("Failed to remove peer for AP vdev %i: %d\n",
2684 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002685
2686 kfree(arvif->u.ap.noa_data);
2687 }
2688
Ben Greear69244e52014-02-27 18:50:00 +02002689 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002690 arvif->vdev_id);
2691
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2693 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002694 ath10k_warn("WMI vdev %i delete failed: %d\n",
2695 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696
2697 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2698 ar->monitor_present = false;
2699
2700 ath10k_peer_cleanup(ar, arvif->vdev_id);
2701
2702 mutex_unlock(&ar->conf_mutex);
2703}
2704
2705/*
2706 * FIXME: Has to be verified.
2707 */
2708#define SUPPORTED_FILTERS \
2709 (FIF_PROMISC_IN_BSS | \
2710 FIF_ALLMULTI | \
2711 FIF_CONTROL | \
2712 FIF_PSPOLL | \
2713 FIF_OTHER_BSS | \
2714 FIF_BCN_PRBRESP_PROMISC | \
2715 FIF_PROBE_REQ | \
2716 FIF_FCSFAIL)
2717
2718static void ath10k_configure_filter(struct ieee80211_hw *hw,
2719 unsigned int changed_flags,
2720 unsigned int *total_flags,
2721 u64 multicast)
2722{
2723 struct ath10k *ar = hw->priv;
2724 int ret;
2725
2726 mutex_lock(&ar->conf_mutex);
2727
2728 changed_flags &= SUPPORTED_FILTERS;
2729 *total_flags &= SUPPORTED_FILTERS;
2730 ar->filter_flags = *total_flags;
2731
Michal Kaziorafd09222013-10-16 16:45:41 +03002732 /* Monitor must not be started if it wasn't created first.
2733 * Promiscuous mode may be started on a non-monitor interface - in
2734 * such case the monitor vdev is not created so starting the
2735 * monitor makes no sense. Since ath10k uses no special RX filters
2736 * (only BSS filter in STA mode) there's no need for any special
2737 * action here. */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002738 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002739 !ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002740 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2741 ar->monitor_vdev_id);
2742
Kalle Valo5e3dd152013-06-12 20:52:10 +03002743 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2744 if (ret)
2745 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002746 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
Michal Kaziorafd09222013-10-16 16:45:41 +03002747 ar->monitor_enabled && ar->monitor_present) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002748 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2749 ar->monitor_vdev_id);
2750
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751 ret = ath10k_monitor_stop(ar);
2752 if (ret)
2753 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 }
2755
2756 mutex_unlock(&ar->conf_mutex);
2757}
2758
2759static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2760 struct ieee80211_vif *vif,
2761 struct ieee80211_bss_conf *info,
2762 u32 changed)
2763{
2764 struct ath10k *ar = hw->priv;
2765 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2766 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002767 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002768
2769 mutex_lock(&ar->conf_mutex);
2770
2771 if (changed & BSS_CHANGED_IBSS)
2772 ath10k_control_ibss(arvif, info, vif->addr);
2773
2774 if (changed & BSS_CHANGED_BEACON_INT) {
2775 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002776 vdev_param = ar->wmi.vdev_param->beacon_interval;
2777 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002779 ath10k_dbg(ATH10K_DBG_MAC,
2780 "mac vdev %d beacon_interval %d\n",
2781 arvif->vdev_id, arvif->beacon_interval);
2782
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002784 ath10k_warn("Failed to set beacon interval for vdev %d: %i\n",
2785 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002786 }
2787
2788 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002789 ath10k_dbg(ATH10K_DBG_MAC,
2790 "vdev %d set beacon tx mode to staggered\n",
2791 arvif->vdev_id);
2792
Bartosz Markowski226a3392013-09-26 17:47:16 +02002793 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2794 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795 WMI_BEACON_STAGGERED_MODE);
2796 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002797 ath10k_warn("Failed to set beacon mode for vdev %d: %i\n",
2798 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002799 }
2800
John W. Linvilleb70727e2013-06-13 13:34:29 -04002801 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802 arvif->dtim_period = info->dtim_period;
2803
Kalle Valo60c3daa2013-09-08 17:56:07 +03002804 ath10k_dbg(ATH10K_DBG_MAC,
2805 "mac vdev %d dtim_period %d\n",
2806 arvif->vdev_id, arvif->dtim_period);
2807
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002808 vdev_param = ar->wmi.vdev_param->dtim_period;
2809 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002810 arvif->dtim_period);
2811 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002812 ath10k_warn("Failed to set dtim period for vdev %d: %i\n",
2813 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002814 }
2815
2816 if (changed & BSS_CHANGED_SSID &&
2817 vif->type == NL80211_IFTYPE_AP) {
2818 arvif->u.ap.ssid_len = info->ssid_len;
2819 if (info->ssid_len)
2820 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2821 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2822 }
2823
2824 if (changed & BSS_CHANGED_BSSID) {
2825 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002826 ath10k_dbg(ATH10K_DBG_MAC,
2827 "mac vdev %d create peer %pM\n",
2828 arvif->vdev_id, info->bssid);
2829
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830 ret = ath10k_peer_create(ar, arvif->vdev_id,
2831 info->bssid);
2832 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002833 ath10k_warn("Failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08002834 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835
2836 if (vif->type == NL80211_IFTYPE_STATION) {
2837 /*
2838 * this is never erased as we it for crypto key
2839 * clearing; this is FW requirement
2840 */
Michal Kaziorc930f742014-01-23 11:38:25 +01002841 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002842
Kalle Valo60c3daa2013-09-08 17:56:07 +03002843 ath10k_dbg(ATH10K_DBG_MAC,
2844 "mac vdev %d start %pM\n",
2845 arvif->vdev_id, info->bssid);
2846
Kalle Valo5e3dd152013-06-12 20:52:10 +03002847 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002848 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02002849 ath10k_warn("failed to start vdev %i: %d\n",
2850 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02002851 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01002852 }
2853
2854 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002855 }
2856
2857 /*
2858 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2859 * so driver need to store it. It is needed when leaving
2860 * IBSS in order to remove BSSID peer.
2861 */
2862 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01002863 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002864 ETH_ALEN);
2865 }
2866 }
2867
2868 if (changed & BSS_CHANGED_BEACON_ENABLED)
2869 ath10k_control_beaconing(arvif, info);
2870
2871 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2872 u32 cts_prot;
2873 if (info->use_cts_prot)
2874 cts_prot = 1;
2875 else
2876 cts_prot = 0;
2877
Kalle Valo60c3daa2013-09-08 17:56:07 +03002878 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2879 arvif->vdev_id, cts_prot);
2880
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002881 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2882 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002883 cts_prot);
2884 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002885 ath10k_warn("Failed to set CTS prot for vdev %d: %d\n",
2886 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002887 }
2888
2889 if (changed & BSS_CHANGED_ERP_SLOT) {
2890 u32 slottime;
2891 if (info->use_short_slot)
2892 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2893
2894 else
2895 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2896
Kalle Valo60c3daa2013-09-08 17:56:07 +03002897 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2898 arvif->vdev_id, slottime);
2899
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002900 vdev_param = ar->wmi.vdev_param->slot_time;
2901 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002902 slottime);
2903 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002904 ath10k_warn("Failed to set erp slot for vdev %d: %i\n",
2905 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906 }
2907
2908 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2909 u32 preamble;
2910 if (info->use_short_preamble)
2911 preamble = WMI_VDEV_PREAMBLE_SHORT;
2912 else
2913 preamble = WMI_VDEV_PREAMBLE_LONG;
2914
Kalle Valo60c3daa2013-09-08 17:56:07 +03002915 ath10k_dbg(ATH10K_DBG_MAC,
2916 "mac vdev %d preamble %dn",
2917 arvif->vdev_id, preamble);
2918
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002919 vdev_param = ar->wmi.vdev_param->preamble;
2920 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921 preamble);
2922 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02002923 ath10k_warn("Failed to set preamble for vdev %d: %i\n",
2924 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925 }
2926
2927 if (changed & BSS_CHANGED_ASSOC) {
2928 if (info->assoc)
2929 ath10k_bss_assoc(hw, vif, info);
2930 }
2931
Kalle Valo75459e32014-02-13 18:13:12 +02002932exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002933 mutex_unlock(&ar->conf_mutex);
2934}
2935
2936static int ath10k_hw_scan(struct ieee80211_hw *hw,
2937 struct ieee80211_vif *vif,
2938 struct cfg80211_scan_request *req)
2939{
2940 struct ath10k *ar = hw->priv;
2941 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2942 struct wmi_start_scan_arg arg;
2943 int ret = 0;
2944 int i;
2945
2946 mutex_lock(&ar->conf_mutex);
2947
2948 spin_lock_bh(&ar->data_lock);
2949 if (ar->scan.in_progress) {
2950 spin_unlock_bh(&ar->data_lock);
2951 ret = -EBUSY;
2952 goto exit;
2953 }
2954
Wolfram Sang16735d02013-11-14 14:32:02 -08002955 reinit_completion(&ar->scan.started);
2956 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002957 ar->scan.in_progress = true;
2958 ar->scan.aborting = false;
2959 ar->scan.is_roc = false;
2960 ar->scan.vdev_id = arvif->vdev_id;
2961 spin_unlock_bh(&ar->data_lock);
2962
2963 memset(&arg, 0, sizeof(arg));
2964 ath10k_wmi_start_scan_init(ar, &arg);
2965 arg.vdev_id = arvif->vdev_id;
2966 arg.scan_id = ATH10K_SCAN_ID;
2967
2968 if (!req->no_cck)
2969 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2970
2971 if (req->ie_len) {
2972 arg.ie_len = req->ie_len;
2973 memcpy(arg.ie, req->ie, arg.ie_len);
2974 }
2975
2976 if (req->n_ssids) {
2977 arg.n_ssids = req->n_ssids;
2978 for (i = 0; i < arg.n_ssids; i++) {
2979 arg.ssids[i].len = req->ssids[i].ssid_len;
2980 arg.ssids[i].ssid = req->ssids[i].ssid;
2981 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002982 } else {
2983 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002984 }
2985
2986 if (req->n_channels) {
2987 arg.n_channels = req->n_channels;
2988 for (i = 0; i < arg.n_channels; i++)
2989 arg.channels[i] = req->channels[i]->center_freq;
2990 }
2991
2992 ret = ath10k_start_scan(ar, &arg);
2993 if (ret) {
2994 ath10k_warn("could not start hw scan (%d)\n", ret);
2995 spin_lock_bh(&ar->data_lock);
2996 ar->scan.in_progress = false;
2997 spin_unlock_bh(&ar->data_lock);
2998 }
2999
3000exit:
3001 mutex_unlock(&ar->conf_mutex);
3002 return ret;
3003}
3004
3005static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif)
3007{
3008 struct ath10k *ar = hw->priv;
3009 int ret;
3010
3011 mutex_lock(&ar->conf_mutex);
3012 ret = ath10k_abort_scan(ar);
3013 if (ret) {
3014 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
3015 ret);
3016 ieee80211_scan_completed(hw, 1 /* aborted */);
3017 }
3018 mutex_unlock(&ar->conf_mutex);
3019}
3020
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003021static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3022 struct ath10k_vif *arvif,
3023 enum set_key_cmd cmd,
3024 struct ieee80211_key_conf *key)
3025{
3026 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3027 int ret;
3028
3029 /* 10.1 firmware branch requires default key index to be set to group
3030 * key index after installing it. Otherwise FW/HW Txes corrupted
3031 * frames with multi-vif APs. This is not required for main firmware
3032 * branch (e.g. 636).
3033 *
3034 * FIXME: This has been tested only in AP. It remains unknown if this
3035 * is required for multi-vif STA interfaces on 10.1 */
3036
3037 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3038 return;
3039
3040 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3041 return;
3042
3043 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3044 return;
3045
3046 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3047 return;
3048
3049 if (cmd != SET_KEY)
3050 return;
3051
3052 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3053 key->keyidx);
3054 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02003055 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3056 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003057}
3058
Kalle Valo5e3dd152013-06-12 20:52:10 +03003059static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3060 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3061 struct ieee80211_key_conf *key)
3062{
3063 struct ath10k *ar = hw->priv;
3064 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3065 struct ath10k_peer *peer;
3066 const u8 *peer_addr;
3067 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3068 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3069 int ret = 0;
3070
3071 if (key->keyidx > WMI_MAX_KEY_INDEX)
3072 return -ENOSPC;
3073
3074 mutex_lock(&ar->conf_mutex);
3075
3076 if (sta)
3077 peer_addr = sta->addr;
3078 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3079 peer_addr = vif->bss_conf.bssid;
3080 else
3081 peer_addr = vif->addr;
3082
3083 key->hw_key_idx = key->keyidx;
3084
3085 /* the peer should not disappear in mid-way (unless FW goes awry) since
3086 * we already hold conf_mutex. we just make sure its there now. */
3087 spin_lock_bh(&ar->data_lock);
3088 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3089 spin_unlock_bh(&ar->data_lock);
3090
3091 if (!peer) {
3092 if (cmd == SET_KEY) {
3093 ath10k_warn("cannot install key for non-existent peer %pM\n",
3094 peer_addr);
3095 ret = -EOPNOTSUPP;
3096 goto exit;
3097 } else {
3098 /* if the peer doesn't exist there is no key to disable
3099 * anymore */
3100 goto exit;
3101 }
3102 }
3103
3104 if (is_wep) {
3105 if (cmd == SET_KEY)
3106 arvif->wep_keys[key->keyidx] = key;
3107 else
3108 arvif->wep_keys[key->keyidx] = NULL;
3109
3110 if (cmd == DISABLE_KEY)
3111 ath10k_clear_vdev_key(arvif, key);
3112 }
3113
3114 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3115 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02003116 ath10k_warn("key installation failed for vdev %i peer %pM: %d\n",
3117 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003118 goto exit;
3119 }
3120
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003121 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3122
Kalle Valo5e3dd152013-06-12 20:52:10 +03003123 spin_lock_bh(&ar->data_lock);
3124 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3125 if (peer && cmd == SET_KEY)
3126 peer->keys[key->keyidx] = key;
3127 else if (peer && cmd == DISABLE_KEY)
3128 peer->keys[key->keyidx] = NULL;
3129 else if (peer == NULL)
3130 /* impossible unless FW goes crazy */
3131 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3132 spin_unlock_bh(&ar->data_lock);
3133
3134exit:
3135 mutex_unlock(&ar->conf_mutex);
3136 return ret;
3137}
3138
Michal Kazior9797feb2014-02-14 14:49:48 +01003139static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3140{
3141 struct ath10k *ar;
3142 struct ath10k_vif *arvif;
3143 struct ath10k_sta *arsta;
3144 struct ieee80211_sta *sta;
3145 u32 changed, bw, nss, smps;
3146 int err;
3147
3148 arsta = container_of(wk, struct ath10k_sta, update_wk);
3149 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3150 arvif = arsta->arvif;
3151 ar = arvif->ar;
3152
3153 spin_lock_bh(&ar->data_lock);
3154
3155 changed = arsta->changed;
3156 arsta->changed = 0;
3157
3158 bw = arsta->bw;
3159 nss = arsta->nss;
3160 smps = arsta->smps;
3161
3162 spin_unlock_bh(&ar->data_lock);
3163
3164 mutex_lock(&ar->conf_mutex);
3165
3166 if (changed & IEEE80211_RC_BW_CHANGED) {
3167 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3168 sta->addr, bw);
3169
3170 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3171 WMI_PEER_CHAN_WIDTH, bw);
3172 if (err)
3173 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3174 sta->addr, bw, err);
3175 }
3176
3177 if (changed & IEEE80211_RC_NSS_CHANGED) {
3178 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3179 sta->addr, nss);
3180
3181 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3182 WMI_PEER_NSS, nss);
3183 if (err)
3184 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3185 sta->addr, nss, err);
3186 }
3187
3188 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3189 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3190 sta->addr, smps);
3191
3192 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3193 WMI_PEER_SMPS_STATE, smps);
3194 if (err)
3195 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3196 sta->addr, smps, err);
3197 }
3198
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003199 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3200 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3201 sta->addr);
3202
3203 err = ath10k_station_assoc(ar, arvif, sta, true);
3204 if (err)
3205 ath10k_warn("Failed to reassociate station: %pM\n",
3206 sta->addr);
3207 }
3208
Michal Kazior9797feb2014-02-14 14:49:48 +01003209 mutex_unlock(&ar->conf_mutex);
3210}
3211
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212static int ath10k_sta_state(struct ieee80211_hw *hw,
3213 struct ieee80211_vif *vif,
3214 struct ieee80211_sta *sta,
3215 enum ieee80211_sta_state old_state,
3216 enum ieee80211_sta_state new_state)
3217{
3218 struct ath10k *ar = hw->priv;
3219 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003220 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003221 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003222 int ret = 0;
3223
Michal Kazior76f90022014-02-25 09:29:57 +02003224 if (old_state == IEEE80211_STA_NOTEXIST &&
3225 new_state == IEEE80211_STA_NONE) {
3226 memset(arsta, 0, sizeof(*arsta));
3227 arsta->arvif = arvif;
3228 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3229 }
3230
Michal Kazior9797feb2014-02-14 14:49:48 +01003231 /* cancel must be done outside the mutex to avoid deadlock */
3232 if ((old_state == IEEE80211_STA_NONE &&
3233 new_state == IEEE80211_STA_NOTEXIST))
3234 cancel_work_sync(&arsta->update_wk);
3235
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236 mutex_lock(&ar->conf_mutex);
3237
3238 if (old_state == IEEE80211_STA_NOTEXIST &&
3239 new_state == IEEE80211_STA_NONE &&
3240 vif->type != NL80211_IFTYPE_STATION) {
3241 /*
3242 * New station addition.
3243 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003244 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3245 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3246 else
3247 max_num_peers = TARGET_NUM_PEERS;
3248
3249 if (ar->num_peers >= max_num_peers) {
3250 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3251 ar->num_peers, max_num_peers);
3252 ret = -ENOBUFS;
3253 goto exit;
3254 }
3255
Kalle Valo60c3daa2013-09-08 17:56:07 +03003256 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003257 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3258 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003259
Kalle Valo5e3dd152013-06-12 20:52:10 +03003260 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3261 if (ret)
Ben Greear479398b2013-11-04 09:19:34 -08003262 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3263 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264 } else if ((old_state == IEEE80211_STA_NONE &&
3265 new_state == IEEE80211_STA_NOTEXIST)) {
3266 /*
3267 * Existing station deletion.
3268 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003269 ath10k_dbg(ATH10K_DBG_MAC,
3270 "mac vdev %d peer delete %pM (sta gone)\n",
3271 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3273 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02003274 ath10k_warn("Failed to delete peer %pM for vdev %d: %i\n",
3275 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003276
3277 if (vif->type == NL80211_IFTYPE_STATION)
3278 ath10k_bss_disassoc(hw, vif);
3279 } else if (old_state == IEEE80211_STA_AUTH &&
3280 new_state == IEEE80211_STA_ASSOC &&
3281 (vif->type == NL80211_IFTYPE_AP ||
3282 vif->type == NL80211_IFTYPE_ADHOC)) {
3283 /*
3284 * New association.
3285 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003286 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3287 sta->addr);
3288
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003289 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003290 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02003291 ath10k_warn("Failed to associate station %pM for vdev %i: %i\n",
3292 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003293 } else if (old_state == IEEE80211_STA_ASSOC &&
3294 new_state == IEEE80211_STA_AUTH &&
3295 (vif->type == NL80211_IFTYPE_AP ||
3296 vif->type == NL80211_IFTYPE_ADHOC)) {
3297 /*
3298 * Disassociation.
3299 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003300 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3301 sta->addr);
3302
Kalle Valo5e3dd152013-06-12 20:52:10 +03003303 ret = ath10k_station_disassoc(ar, arvif, sta);
3304 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02003305 ath10k_warn("Failed to disassociate station: %pM vdev %i ret %i\n",
3306 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003307 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003308exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309 mutex_unlock(&ar->conf_mutex);
3310 return ret;
3311}
3312
3313static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3314 u16 ac, bool enable)
3315{
3316 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3317 u32 value = 0;
3318 int ret = 0;
3319
Michal Kazior548db542013-07-05 16:15:15 +03003320 lockdep_assert_held(&ar->conf_mutex);
3321
Kalle Valo5e3dd152013-06-12 20:52:10 +03003322 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3323 return 0;
3324
3325 switch (ac) {
3326 case IEEE80211_AC_VO:
3327 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3328 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3329 break;
3330 case IEEE80211_AC_VI:
3331 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3332 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3333 break;
3334 case IEEE80211_AC_BE:
3335 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3336 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3337 break;
3338 case IEEE80211_AC_BK:
3339 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3340 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3341 break;
3342 }
3343
3344 if (enable)
3345 arvif->u.sta.uapsd |= value;
3346 else
3347 arvif->u.sta.uapsd &= ~value;
3348
3349 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3350 WMI_STA_PS_PARAM_UAPSD,
3351 arvif->u.sta.uapsd);
3352 if (ret) {
3353 ath10k_warn("could not set uapsd params %d\n", ret);
3354 goto exit;
3355 }
3356
3357 if (arvif->u.sta.uapsd)
3358 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3359 else
3360 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3361
3362 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3363 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3364 value);
3365 if (ret)
3366 ath10k_warn("could not set rx wake param %d\n", ret);
3367
3368exit:
3369 return ret;
3370}
3371
3372static int ath10k_conf_tx(struct ieee80211_hw *hw,
3373 struct ieee80211_vif *vif, u16 ac,
3374 const struct ieee80211_tx_queue_params *params)
3375{
3376 struct ath10k *ar = hw->priv;
3377 struct wmi_wmm_params_arg *p = NULL;
3378 int ret;
3379
3380 mutex_lock(&ar->conf_mutex);
3381
3382 switch (ac) {
3383 case IEEE80211_AC_VO:
3384 p = &ar->wmm_params.ac_vo;
3385 break;
3386 case IEEE80211_AC_VI:
3387 p = &ar->wmm_params.ac_vi;
3388 break;
3389 case IEEE80211_AC_BE:
3390 p = &ar->wmm_params.ac_be;
3391 break;
3392 case IEEE80211_AC_BK:
3393 p = &ar->wmm_params.ac_bk;
3394 break;
3395 }
3396
3397 if (WARN_ON(!p)) {
3398 ret = -EINVAL;
3399 goto exit;
3400 }
3401
3402 p->cwmin = params->cw_min;
3403 p->cwmax = params->cw_max;
3404 p->aifs = params->aifs;
3405
3406 /*
3407 * The channel time duration programmed in the HW is in absolute
3408 * microseconds, while mac80211 gives the txop in units of
3409 * 32 microseconds.
3410 */
3411 p->txop = params->txop * 32;
3412
3413 /* FIXME: FW accepts wmm params per hw, not per vif */
3414 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3415 if (ret) {
3416 ath10k_warn("could not set wmm params %d\n", ret);
3417 goto exit;
3418 }
3419
3420 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3421 if (ret)
3422 ath10k_warn("could not set sta uapsd %d\n", ret);
3423
3424exit:
3425 mutex_unlock(&ar->conf_mutex);
3426 return ret;
3427}
3428
3429#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3430
3431static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3432 struct ieee80211_vif *vif,
3433 struct ieee80211_channel *chan,
3434 int duration,
3435 enum ieee80211_roc_type type)
3436{
3437 struct ath10k *ar = hw->priv;
3438 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3439 struct wmi_start_scan_arg arg;
3440 int ret;
3441
3442 mutex_lock(&ar->conf_mutex);
3443
3444 spin_lock_bh(&ar->data_lock);
3445 if (ar->scan.in_progress) {
3446 spin_unlock_bh(&ar->data_lock);
3447 ret = -EBUSY;
3448 goto exit;
3449 }
3450
Wolfram Sang16735d02013-11-14 14:32:02 -08003451 reinit_completion(&ar->scan.started);
3452 reinit_completion(&ar->scan.completed);
3453 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003454 ar->scan.in_progress = true;
3455 ar->scan.aborting = false;
3456 ar->scan.is_roc = true;
3457 ar->scan.vdev_id = arvif->vdev_id;
3458 ar->scan.roc_freq = chan->center_freq;
3459 spin_unlock_bh(&ar->data_lock);
3460
3461 memset(&arg, 0, sizeof(arg));
3462 ath10k_wmi_start_scan_init(ar, &arg);
3463 arg.vdev_id = arvif->vdev_id;
3464 arg.scan_id = ATH10K_SCAN_ID;
3465 arg.n_channels = 1;
3466 arg.channels[0] = chan->center_freq;
3467 arg.dwell_time_active = duration;
3468 arg.dwell_time_passive = duration;
3469 arg.max_scan_time = 2 * duration;
3470 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3471 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3472
3473 ret = ath10k_start_scan(ar, &arg);
3474 if (ret) {
3475 ath10k_warn("could not start roc scan (%d)\n", ret);
3476 spin_lock_bh(&ar->data_lock);
3477 ar->scan.in_progress = false;
3478 spin_unlock_bh(&ar->data_lock);
3479 goto exit;
3480 }
3481
3482 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3483 if (ret == 0) {
3484 ath10k_warn("could not switch to channel for roc scan\n");
3485 ath10k_abort_scan(ar);
3486 ret = -ETIMEDOUT;
3487 goto exit;
3488 }
3489
3490 ret = 0;
3491exit:
3492 mutex_unlock(&ar->conf_mutex);
3493 return ret;
3494}
3495
3496static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3497{
3498 struct ath10k *ar = hw->priv;
3499
3500 mutex_lock(&ar->conf_mutex);
3501 ath10k_abort_scan(ar);
3502 mutex_unlock(&ar->conf_mutex);
3503
3504 return 0;
3505}
3506
3507/*
3508 * Both RTS and Fragmentation threshold are interface-specific
3509 * in ath10k, but device-specific in mac80211.
3510 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003511
3512static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3513{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003514 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003515 struct ath10k_vif *arvif;
3516 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003517
Michal Kaziorad088bf2013-10-16 15:44:46 +03003518 mutex_lock(&ar->conf_mutex);
3519 list_for_each_entry(arvif, &ar->arvifs, list) {
3520 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3521 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003522
Michal Kaziorad088bf2013-10-16 15:44:46 +03003523 ret = ath10k_mac_set_rts(arvif, value);
3524 if (ret) {
3525 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3526 arvif->vdev_id, ret);
3527 break;
3528 }
3529 }
3530 mutex_unlock(&ar->conf_mutex);
3531
3532 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003533}
3534
3535static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3536{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003537 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003538 struct ath10k_vif *arvif;
3539 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003542 list_for_each_entry(arvif, &ar->arvifs, list) {
3543 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3544 arvif->vdev_id, value);
3545
3546 ret = ath10k_mac_set_rts(arvif, value);
3547 if (ret) {
3548 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3549 arvif->vdev_id, ret);
3550 break;
3551 }
3552 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003553 mutex_unlock(&ar->conf_mutex);
3554
Michal Kaziorad088bf2013-10-16 15:44:46 +03003555 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003556}
3557
3558static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3559{
3560 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003561 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 int ret;
3563
3564 /* mac80211 doesn't care if we really xmit queued frames or not
3565 * we'll collect those frames either way if we stop/delete vdevs */
3566 if (drop)
3567 return;
3568
Michal Kazior548db542013-07-05 16:15:15 +03003569 mutex_lock(&ar->conf_mutex);
3570
Michal Kazioraffd3212013-07-16 09:54:35 +02003571 if (ar->state == ATH10K_STATE_WEDGED)
3572 goto skip;
3573
Michal Kazioredb82362013-07-05 16:15:14 +03003574 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003575 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003576
Michal Kazioredb82362013-07-05 16:15:14 +03003577 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003578 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003579 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003580
3581 skip = (ar->state == ATH10K_STATE_WEDGED);
3582
3583 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003584 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003585
3586 if (ret <= 0 || skip)
Ben Greear9ba4c782014-02-25 09:29:57 +02003587 ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n",
3588 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003589
Michal Kazioraffd3212013-07-16 09:54:35 +02003590skip:
Michal Kazior548db542013-07-05 16:15:15 +03003591 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592}
3593
3594/* TODO: Implement this function properly
3595 * For now it is needed to reply to Probe Requests in IBSS mode.
3596 * Propably we need this information from FW.
3597 */
3598static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3599{
3600 return 1;
3601}
3602
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003603#ifdef CONFIG_PM
3604static int ath10k_suspend(struct ieee80211_hw *hw,
3605 struct cfg80211_wowlan *wowlan)
3606{
3607 struct ath10k *ar = hw->priv;
3608 int ret;
3609
Marek Puzyniak9042e172014-02-10 17:14:23 +01003610 mutex_lock(&ar->conf_mutex);
3611
Marek Puzyniak00f54822014-02-10 17:14:24 +01003612 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003613 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003614 if (ret == -ETIMEDOUT)
3615 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003616 ret = 1;
3617 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003618 }
3619
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003620 ret = ath10k_hif_suspend(ar);
3621 if (ret) {
3622 ath10k_warn("could not suspend hif (%d)\n", ret);
3623 goto resume;
3624 }
3625
Marek Puzyniak9042e172014-02-10 17:14:23 +01003626 ret = 0;
3627 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003628resume:
3629 ret = ath10k_wmi_pdev_resume_target(ar);
3630 if (ret)
3631 ath10k_warn("could not resume target (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003632
3633 ret = 1;
3634exit:
3635 mutex_unlock(&ar->conf_mutex);
3636 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003637}
3638
3639static int ath10k_resume(struct ieee80211_hw *hw)
3640{
3641 struct ath10k *ar = hw->priv;
3642 int ret;
3643
Marek Puzyniak9042e172014-02-10 17:14:23 +01003644 mutex_lock(&ar->conf_mutex);
3645
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003646 ret = ath10k_hif_resume(ar);
3647 if (ret) {
3648 ath10k_warn("could not resume hif (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003649 ret = 1;
3650 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003651 }
3652
3653 ret = ath10k_wmi_pdev_resume_target(ar);
3654 if (ret) {
3655 ath10k_warn("could not resume target (%d)\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003656 ret = 1;
3657 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003658 }
3659
Marek Puzyniak9042e172014-02-10 17:14:23 +01003660 ret = 0;
3661exit:
3662 mutex_unlock(&ar->conf_mutex);
3663 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003664}
3665#endif
3666
Michal Kazioraffd3212013-07-16 09:54:35 +02003667static void ath10k_restart_complete(struct ieee80211_hw *hw)
3668{
3669 struct ath10k *ar = hw->priv;
3670
3671 mutex_lock(&ar->conf_mutex);
3672
3673 /* If device failed to restart it will be in a different state, e.g.
3674 * ATH10K_STATE_WEDGED */
3675 if (ar->state == ATH10K_STATE_RESTARTED) {
3676 ath10k_info("device successfully recovered\n");
3677 ar->state = ATH10K_STATE_ON;
3678 }
3679
3680 mutex_unlock(&ar->conf_mutex);
3681}
3682
Michal Kazior2e1dea42013-07-31 10:32:40 +02003683static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3684 struct survey_info *survey)
3685{
3686 struct ath10k *ar = hw->priv;
3687 struct ieee80211_supported_band *sband;
3688 struct survey_info *ar_survey = &ar->survey[idx];
3689 int ret = 0;
3690
3691 mutex_lock(&ar->conf_mutex);
3692
3693 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3694 if (sband && idx >= sband->n_channels) {
3695 idx -= sband->n_channels;
3696 sband = NULL;
3697 }
3698
3699 if (!sband)
3700 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3701
3702 if (!sband || idx >= sband->n_channels) {
3703 ret = -ENOENT;
3704 goto exit;
3705 }
3706
3707 spin_lock_bh(&ar->data_lock);
3708 memcpy(survey, ar_survey, sizeof(*survey));
3709 spin_unlock_bh(&ar->data_lock);
3710
3711 survey->channel = &sband->channels[idx];
3712
3713exit:
3714 mutex_unlock(&ar->conf_mutex);
3715 return ret;
3716}
3717
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003718/* Helper table for legacy fixed_rate/bitrate_mask */
3719static const u8 cck_ofdm_rate[] = {
3720 /* CCK */
3721 3, /* 1Mbps */
3722 2, /* 2Mbps */
3723 1, /* 5.5Mbps */
3724 0, /* 11Mbps */
3725 /* OFDM */
3726 3, /* 6Mbps */
3727 7, /* 9Mbps */
3728 2, /* 12Mbps */
3729 6, /* 18Mbps */
3730 1, /* 24Mbps */
3731 5, /* 36Mbps */
3732 0, /* 48Mbps */
3733 4, /* 54Mbps */
3734};
3735
3736/* Check if only one bit set */
3737static int ath10k_check_single_mask(u32 mask)
3738{
3739 int bit;
3740
3741 bit = ffs(mask);
3742 if (!bit)
3743 return 0;
3744
3745 mask &= ~BIT(bit - 1);
3746 if (mask)
3747 return 2;
3748
3749 return 1;
3750}
3751
3752static bool
3753ath10k_default_bitrate_mask(struct ath10k *ar,
3754 enum ieee80211_band band,
3755 const struct cfg80211_bitrate_mask *mask)
3756{
3757 u32 legacy = 0x00ff;
3758 u8 ht = 0xff, i;
3759 u16 vht = 0x3ff;
3760
3761 switch (band) {
3762 case IEEE80211_BAND_2GHZ:
3763 legacy = 0x00fff;
3764 vht = 0;
3765 break;
3766 case IEEE80211_BAND_5GHZ:
3767 break;
3768 default:
3769 return false;
3770 }
3771
3772 if (mask->control[band].legacy != legacy)
3773 return false;
3774
3775 for (i = 0; i < ar->num_rf_chains; i++)
3776 if (mask->control[band].ht_mcs[i] != ht)
3777 return false;
3778
3779 for (i = 0; i < ar->num_rf_chains; i++)
3780 if (mask->control[band].vht_mcs[i] != vht)
3781 return false;
3782
3783 return true;
3784}
3785
3786static bool
3787ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3788 enum ieee80211_band band,
3789 u8 *fixed_nss)
3790{
3791 int ht_nss = 0, vht_nss = 0, i;
3792
3793 /* check legacy */
3794 if (ath10k_check_single_mask(mask->control[band].legacy))
3795 return false;
3796
3797 /* check HT */
3798 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3799 if (mask->control[band].ht_mcs[i] == 0xff)
3800 continue;
3801 else if (mask->control[band].ht_mcs[i] == 0x00)
3802 break;
3803 else
3804 return false;
3805 }
3806
3807 ht_nss = i;
3808
3809 /* check VHT */
3810 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3811 if (mask->control[band].vht_mcs[i] == 0x03ff)
3812 continue;
3813 else if (mask->control[band].vht_mcs[i] == 0x0000)
3814 break;
3815 else
3816 return false;
3817 }
3818
3819 vht_nss = i;
3820
3821 if (ht_nss > 0 && vht_nss > 0)
3822 return false;
3823
3824 if (ht_nss)
3825 *fixed_nss = ht_nss;
3826 else if (vht_nss)
3827 *fixed_nss = vht_nss;
3828 else
3829 return false;
3830
3831 return true;
3832}
3833
3834static bool
3835ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3836 enum ieee80211_band band,
3837 enum wmi_rate_preamble *preamble)
3838{
3839 int legacy = 0, ht = 0, vht = 0, i;
3840
3841 *preamble = WMI_RATE_PREAMBLE_OFDM;
3842
3843 /* check legacy */
3844 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3845 if (legacy > 1)
3846 return false;
3847
3848 /* check HT */
3849 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3850 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3851 if (ht > 1)
3852 return false;
3853
3854 /* check VHT */
3855 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3856 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3857 if (vht > 1)
3858 return false;
3859
3860 /* Currently we support only one fixed_rate */
3861 if ((legacy + ht + vht) != 1)
3862 return false;
3863
3864 if (ht)
3865 *preamble = WMI_RATE_PREAMBLE_HT;
3866 else if (vht)
3867 *preamble = WMI_RATE_PREAMBLE_VHT;
3868
3869 return true;
3870}
3871
3872static bool
3873ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3874 enum ieee80211_band band,
3875 u8 *fixed_rate,
3876 u8 *fixed_nss)
3877{
3878 u8 rate = 0, pream = 0, nss = 0, i;
3879 enum wmi_rate_preamble preamble;
3880
3881 /* Check if single rate correct */
3882 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3883 return false;
3884
3885 pream = preamble;
3886
3887 switch (preamble) {
3888 case WMI_RATE_PREAMBLE_CCK:
3889 case WMI_RATE_PREAMBLE_OFDM:
3890 i = ffs(mask->control[band].legacy) - 1;
3891
3892 if (band == IEEE80211_BAND_2GHZ && i < 4)
3893 pream = WMI_RATE_PREAMBLE_CCK;
3894
3895 if (band == IEEE80211_BAND_5GHZ)
3896 i += 4;
3897
3898 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3899 return false;
3900
3901 rate = cck_ofdm_rate[i];
3902 break;
3903 case WMI_RATE_PREAMBLE_HT:
3904 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3905 if (mask->control[band].ht_mcs[i])
3906 break;
3907
3908 if (i == IEEE80211_HT_MCS_MASK_LEN)
3909 return false;
3910
3911 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3912 nss = i;
3913 break;
3914 case WMI_RATE_PREAMBLE_VHT:
3915 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3916 if (mask->control[band].vht_mcs[i])
3917 break;
3918
3919 if (i == NL80211_VHT_NSS_MAX)
3920 return false;
3921
3922 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3923 nss = i;
3924 break;
3925 }
3926
3927 *fixed_nss = nss + 1;
3928 nss <<= 4;
3929 pream <<= 6;
3930
3931 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3932 pream, nss, rate);
3933
3934 *fixed_rate = pream | nss | rate;
3935
3936 return true;
3937}
3938
3939static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3940 enum ieee80211_band band,
3941 u8 *fixed_rate,
3942 u8 *fixed_nss)
3943{
3944 /* First check full NSS mask, if we can simply limit NSS */
3945 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3946 return true;
3947
3948 /* Next Check single rate is set */
3949 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3950}
3951
3952static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3953 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003954 u8 fixed_nss,
3955 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003956{
3957 struct ath10k *ar = arvif->ar;
3958 u32 vdev_param;
3959 int ret = 0;
3960
3961 mutex_lock(&ar->conf_mutex);
3962
3963 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003964 arvif->fixed_nss == fixed_nss &&
3965 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003966 goto exit;
3967
3968 if (fixed_rate == WMI_FIXED_RATE_NONE)
3969 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3970
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003971 if (force_sgi)
3972 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
3973
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003974 vdev_param = ar->wmi.vdev_param->fixed_rate;
3975 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3976 vdev_param, fixed_rate);
3977 if (ret) {
3978 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3979 fixed_rate, ret);
3980 ret = -EINVAL;
3981 goto exit;
3982 }
3983
3984 arvif->fixed_rate = fixed_rate;
3985
3986 vdev_param = ar->wmi.vdev_param->nss;
3987 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3988 vdev_param, fixed_nss);
3989
3990 if (ret) {
3991 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3992 fixed_nss, ret);
3993 ret = -EINVAL;
3994 goto exit;
3995 }
3996
3997 arvif->fixed_nss = fixed_nss;
3998
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01003999 vdev_param = ar->wmi.vdev_param->sgi;
4000 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4001 force_sgi);
4002
4003 if (ret) {
4004 ath10k_warn("Could not set sgi param %d: %d\n",
4005 force_sgi, ret);
4006 ret = -EINVAL;
4007 goto exit;
4008 }
4009
4010 arvif->force_sgi = force_sgi;
4011
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004012exit:
4013 mutex_unlock(&ar->conf_mutex);
4014 return ret;
4015}
4016
4017static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4018 struct ieee80211_vif *vif,
4019 const struct cfg80211_bitrate_mask *mask)
4020{
4021 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4022 struct ath10k *ar = arvif->ar;
4023 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4024 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4025 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004026 u8 force_sgi;
4027
4028 force_sgi = mask->control[band].gi;
4029 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4030 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004031
4032 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4033 if (!ath10k_get_fixed_rate_nss(mask, band,
4034 &fixed_rate,
4035 &fixed_nss))
4036 return -EINVAL;
4037 }
4038
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004039 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4040 ath10k_warn("Could not force SGI usage for default rate settings\n");
4041 return -EINVAL;
4042 }
4043
4044 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4045 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004046}
4047
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004048static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
4049 struct ieee80211_vif *vif,
4050 struct cfg80211_chan_def *chandef)
4051{
4052 /* there's no need to do anything here. vif->csa_active is enough */
4053 return;
4054}
4055
Michal Kazior9797feb2014-02-14 14:49:48 +01004056static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4057 struct ieee80211_vif *vif,
4058 struct ieee80211_sta *sta,
4059 u32 changed)
4060{
4061 struct ath10k *ar = hw->priv;
4062 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4063 u32 bw, smps;
4064
4065 spin_lock_bh(&ar->data_lock);
4066
4067 ath10k_dbg(ATH10K_DBG_MAC,
4068 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4069 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4070 sta->smps_mode);
4071
4072 if (changed & IEEE80211_RC_BW_CHANGED) {
4073 bw = WMI_PEER_CHWIDTH_20MHZ;
4074
4075 switch (sta->bandwidth) {
4076 case IEEE80211_STA_RX_BW_20:
4077 bw = WMI_PEER_CHWIDTH_20MHZ;
4078 break;
4079 case IEEE80211_STA_RX_BW_40:
4080 bw = WMI_PEER_CHWIDTH_40MHZ;
4081 break;
4082 case IEEE80211_STA_RX_BW_80:
4083 bw = WMI_PEER_CHWIDTH_80MHZ;
4084 break;
4085 case IEEE80211_STA_RX_BW_160:
4086 ath10k_warn("mac sta rc update for %pM: invalid bw %d\n",
4087 sta->addr, sta->bandwidth);
4088 bw = WMI_PEER_CHWIDTH_20MHZ;
4089 break;
4090 }
4091
4092 arsta->bw = bw;
4093 }
4094
4095 if (changed & IEEE80211_RC_NSS_CHANGED)
4096 arsta->nss = sta->rx_nss;
4097
4098 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4099 smps = WMI_PEER_SMPS_PS_NONE;
4100
4101 switch (sta->smps_mode) {
4102 case IEEE80211_SMPS_AUTOMATIC:
4103 case IEEE80211_SMPS_OFF:
4104 smps = WMI_PEER_SMPS_PS_NONE;
4105 break;
4106 case IEEE80211_SMPS_STATIC:
4107 smps = WMI_PEER_SMPS_STATIC;
4108 break;
4109 case IEEE80211_SMPS_DYNAMIC:
4110 smps = WMI_PEER_SMPS_DYNAMIC;
4111 break;
4112 case IEEE80211_SMPS_NUM_MODES:
4113 ath10k_warn("mac sta rc update for %pM: invalid smps: %d\n",
4114 sta->addr, sta->smps_mode);
4115 smps = WMI_PEER_SMPS_PS_NONE;
4116 break;
4117 }
4118
4119 arsta->smps = smps;
4120 }
4121
Michal Kazior9797feb2014-02-14 14:49:48 +01004122 arsta->changed |= changed;
4123
4124 spin_unlock_bh(&ar->data_lock);
4125
4126 ieee80211_queue_work(hw, &arsta->update_wk);
4127}
4128
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004129static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4130{
4131 /*
4132 * FIXME: Return 0 for time being. Need to figure out whether FW
4133 * has the API to fetch 64-bit local TSF
4134 */
4135
4136 return 0;
4137}
4138
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139static const struct ieee80211_ops ath10k_ops = {
4140 .tx = ath10k_tx,
4141 .start = ath10k_start,
4142 .stop = ath10k_stop,
4143 .config = ath10k_config,
4144 .add_interface = ath10k_add_interface,
4145 .remove_interface = ath10k_remove_interface,
4146 .configure_filter = ath10k_configure_filter,
4147 .bss_info_changed = ath10k_bss_info_changed,
4148 .hw_scan = ath10k_hw_scan,
4149 .cancel_hw_scan = ath10k_cancel_hw_scan,
4150 .set_key = ath10k_set_key,
4151 .sta_state = ath10k_sta_state,
4152 .conf_tx = ath10k_conf_tx,
4153 .remain_on_channel = ath10k_remain_on_channel,
4154 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4155 .set_rts_threshold = ath10k_set_rts_threshold,
4156 .set_frag_threshold = ath10k_set_frag_threshold,
4157 .flush = ath10k_flush,
4158 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02004159 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004160 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004161 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004162 .channel_switch_beacon = ath10k_channel_switch_beacon,
Michal Kazior9797feb2014-02-14 14:49:48 +01004163 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004164 .get_tsf = ath10k_get_tsf,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004165#ifdef CONFIG_PM
4166 .suspend = ath10k_suspend,
4167 .resume = ath10k_resume,
4168#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004169};
4170
4171#define RATETAB_ENT(_rate, _rateid, _flags) { \
4172 .bitrate = (_rate), \
4173 .flags = (_flags), \
4174 .hw_value = (_rateid), \
4175}
4176
4177#define CHAN2G(_channel, _freq, _flags) { \
4178 .band = IEEE80211_BAND_2GHZ, \
4179 .hw_value = (_channel), \
4180 .center_freq = (_freq), \
4181 .flags = (_flags), \
4182 .max_antenna_gain = 0, \
4183 .max_power = 30, \
4184}
4185
4186#define CHAN5G(_channel, _freq, _flags) { \
4187 .band = IEEE80211_BAND_5GHZ, \
4188 .hw_value = (_channel), \
4189 .center_freq = (_freq), \
4190 .flags = (_flags), \
4191 .max_antenna_gain = 0, \
4192 .max_power = 30, \
4193}
4194
4195static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4196 CHAN2G(1, 2412, 0),
4197 CHAN2G(2, 2417, 0),
4198 CHAN2G(3, 2422, 0),
4199 CHAN2G(4, 2427, 0),
4200 CHAN2G(5, 2432, 0),
4201 CHAN2G(6, 2437, 0),
4202 CHAN2G(7, 2442, 0),
4203 CHAN2G(8, 2447, 0),
4204 CHAN2G(9, 2452, 0),
4205 CHAN2G(10, 2457, 0),
4206 CHAN2G(11, 2462, 0),
4207 CHAN2G(12, 2467, 0),
4208 CHAN2G(13, 2472, 0),
4209 CHAN2G(14, 2484, 0),
4210};
4211
4212static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004213 CHAN5G(36, 5180, 0),
4214 CHAN5G(40, 5200, 0),
4215 CHAN5G(44, 5220, 0),
4216 CHAN5G(48, 5240, 0),
4217 CHAN5G(52, 5260, 0),
4218 CHAN5G(56, 5280, 0),
4219 CHAN5G(60, 5300, 0),
4220 CHAN5G(64, 5320, 0),
4221 CHAN5G(100, 5500, 0),
4222 CHAN5G(104, 5520, 0),
4223 CHAN5G(108, 5540, 0),
4224 CHAN5G(112, 5560, 0),
4225 CHAN5G(116, 5580, 0),
4226 CHAN5G(120, 5600, 0),
4227 CHAN5G(124, 5620, 0),
4228 CHAN5G(128, 5640, 0),
4229 CHAN5G(132, 5660, 0),
4230 CHAN5G(136, 5680, 0),
4231 CHAN5G(140, 5700, 0),
4232 CHAN5G(149, 5745, 0),
4233 CHAN5G(153, 5765, 0),
4234 CHAN5G(157, 5785, 0),
4235 CHAN5G(161, 5805, 0),
4236 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004237};
4238
4239static struct ieee80211_rate ath10k_rates[] = {
4240 /* CCK */
4241 RATETAB_ENT(10, 0x82, 0),
4242 RATETAB_ENT(20, 0x84, 0),
4243 RATETAB_ENT(55, 0x8b, 0),
4244 RATETAB_ENT(110, 0x96, 0),
4245 /* OFDM */
4246 RATETAB_ENT(60, 0x0c, 0),
4247 RATETAB_ENT(90, 0x12, 0),
4248 RATETAB_ENT(120, 0x18, 0),
4249 RATETAB_ENT(180, 0x24, 0),
4250 RATETAB_ENT(240, 0x30, 0),
4251 RATETAB_ENT(360, 0x48, 0),
4252 RATETAB_ENT(480, 0x60, 0),
4253 RATETAB_ENT(540, 0x6c, 0),
4254};
4255
4256#define ath10k_a_rates (ath10k_rates + 4)
4257#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4258#define ath10k_g_rates (ath10k_rates + 0)
4259#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4260
4261struct ath10k *ath10k_mac_create(void)
4262{
4263 struct ieee80211_hw *hw;
4264 struct ath10k *ar;
4265
4266 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4267 if (!hw)
4268 return NULL;
4269
4270 ar = hw->priv;
4271 ar->hw = hw;
4272
4273 return ar;
4274}
4275
4276void ath10k_mac_destroy(struct ath10k *ar)
4277{
4278 ieee80211_free_hw(ar->hw);
4279}
4280
4281static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4282 {
4283 .max = 8,
4284 .types = BIT(NL80211_IFTYPE_STATION)
4285 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004286 },
4287 {
4288 .max = 3,
4289 .types = BIT(NL80211_IFTYPE_P2P_GO)
4290 },
4291 {
4292 .max = 7,
4293 .types = BIT(NL80211_IFTYPE_AP)
4294 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004295};
4296
Bartosz Markowskif2595092013-12-10 16:20:39 +01004297static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004298 {
4299 .max = 8,
4300 .types = BIT(NL80211_IFTYPE_AP)
4301 },
4302};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004303
4304static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4305 {
4306 .limits = ath10k_if_limits,
4307 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4308 .max_interfaces = 8,
4309 .num_different_channels = 1,
4310 .beacon_int_infra_match = true,
4311 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004312};
4313
4314static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004315 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004316 .limits = ath10k_10x_if_limits,
4317 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004318 .max_interfaces = 8,
4319 .num_different_channels = 1,
4320 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004321#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004322 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4323 BIT(NL80211_CHAN_WIDTH_20) |
4324 BIT(NL80211_CHAN_WIDTH_40) |
4325 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004326#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004327 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004328};
4329
4330static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4331{
4332 struct ieee80211_sta_vht_cap vht_cap = {0};
4333 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004334 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004335
4336 vht_cap.vht_supported = 1;
4337 vht_cap.cap = ar->vht_cap_info;
4338
Michal Kazior8865bee42013-07-24 12:36:46 +02004339 mcs_map = 0;
4340 for (i = 0; i < 8; i++) {
4341 if (i < ar->num_rf_chains)
4342 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4343 else
4344 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4345 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004346
4347 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4348 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4349
4350 return vht_cap;
4351}
4352
4353static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4354{
4355 int i;
4356 struct ieee80211_sta_ht_cap ht_cap = {0};
4357
4358 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4359 return ht_cap;
4360
4361 ht_cap.ht_supported = 1;
4362 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4363 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4364 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4365 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4366 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4367
4368 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4369 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4370
4371 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4372 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4373
4374 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4375 u32 smps;
4376
4377 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4378 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4379
4380 ht_cap.cap |= smps;
4381 }
4382
4383 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4384 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4385
4386 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4387 u32 stbc;
4388
4389 stbc = ar->ht_cap_info;
4390 stbc &= WMI_HT_CAP_RX_STBC;
4391 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4392 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4393 stbc &= IEEE80211_HT_CAP_RX_STBC;
4394
4395 ht_cap.cap |= stbc;
4396 }
4397
4398 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4399 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4400
4401 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4402 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4403
4404 /* max AMSDU is implicitly taken from vht_cap_info */
4405 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4406 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4407
Michal Kazior8865bee42013-07-24 12:36:46 +02004408 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004409 ht_cap.mcs.rx_mask[i] = 0xFF;
4410
4411 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4412
4413 return ht_cap;
4414}
4415
4416
4417static void ath10k_get_arvif_iter(void *data, u8 *mac,
4418 struct ieee80211_vif *vif)
4419{
4420 struct ath10k_vif_iter *arvif_iter = data;
4421 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4422
4423 if (arvif->vdev_id == arvif_iter->vdev_id)
4424 arvif_iter->arvif = arvif;
4425}
4426
4427struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4428{
4429 struct ath10k_vif_iter arvif_iter;
4430 u32 flags;
4431
4432 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4433 arvif_iter.vdev_id = vdev_id;
4434
4435 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4436 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4437 flags,
4438 ath10k_get_arvif_iter,
4439 &arvif_iter);
4440 if (!arvif_iter.arvif) {
Ben Greear69244e52014-02-27 18:50:00 +02004441 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004442 return NULL;
4443 }
4444
4445 return arvif_iter.arvif;
4446}
4447
4448int ath10k_mac_register(struct ath10k *ar)
4449{
4450 struct ieee80211_supported_band *band;
4451 struct ieee80211_sta_vht_cap vht_cap;
4452 struct ieee80211_sta_ht_cap ht_cap;
4453 void *channels;
4454 int ret;
4455
4456 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4457
4458 SET_IEEE80211_DEV(ar->hw, ar->dev);
4459
4460 ht_cap = ath10k_get_ht_cap(ar);
4461 vht_cap = ath10k_create_vht_cap(ar);
4462
4463 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4464 channels = kmemdup(ath10k_2ghz_channels,
4465 sizeof(ath10k_2ghz_channels),
4466 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004467 if (!channels) {
4468 ret = -ENOMEM;
4469 goto err_free;
4470 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004471
4472 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4473 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4474 band->channels = channels;
4475 band->n_bitrates = ath10k_g_rates_size;
4476 band->bitrates = ath10k_g_rates;
4477 band->ht_cap = ht_cap;
4478
4479 /* vht is not supported in 2.4 GHz */
4480
4481 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4482 }
4483
4484 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4485 channels = kmemdup(ath10k_5ghz_channels,
4486 sizeof(ath10k_5ghz_channels),
4487 GFP_KERNEL);
4488 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004489 ret = -ENOMEM;
4490 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004491 }
4492
4493 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4494 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4495 band->channels = channels;
4496 band->n_bitrates = ath10k_a_rates_size;
4497 band->bitrates = ath10k_a_rates;
4498 band->ht_cap = ht_cap;
4499 band->vht_cap = vht_cap;
4500 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4501 }
4502
4503 ar->hw->wiphy->interface_modes =
4504 BIT(NL80211_IFTYPE_STATION) |
4505 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004506 BIT(NL80211_IFTYPE_AP);
4507
4508 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4509 ar->hw->wiphy->interface_modes |=
4510 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4511 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004512
4513 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4514 IEEE80211_HW_SUPPORTS_PS |
4515 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4516 IEEE80211_HW_SUPPORTS_UAPSD |
4517 IEEE80211_HW_MFP_CAPABLE |
4518 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4519 IEEE80211_HW_HAS_RATE_CONTROL |
4520 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4521 IEEE80211_HW_WANT_MONITOR_VIF |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004522 IEEE80211_HW_AP_LINK_PS |
4523 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004524
Michal Kazior1f8bb152013-09-18 14:43:22 +02004525 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4526 * bytes is used for padding/alignment if necessary. */
4527 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4528
Kalle Valo5e3dd152013-06-12 20:52:10 +03004529 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4530 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4531
4532 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4533 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4534 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4535 }
4536
4537 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4538 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4539
4540 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004541 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004542
Kalle Valo5e3dd152013-06-12 20:52:10 +03004543 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4544
4545 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004546 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004547 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4548
4549 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4550 /*
4551 * on LL hardware queues are managed entirely by the FW
4552 * so we only advertise to mac we can do the queues thing
4553 */
4554 ar->hw->queues = 4;
4555
Bartosz Markowskif2595092013-12-10 16:20:39 +01004556 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4557 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4558 ar->hw->wiphy->n_iface_combinations =
4559 ARRAY_SIZE(ath10k_10x_if_comb);
4560 } else {
4561 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4562 ar->hw->wiphy->n_iface_combinations =
4563 ARRAY_SIZE(ath10k_if_comb);
4564 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004565
Michal Kazior7c199992013-07-31 10:47:57 +02004566 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4567
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004568 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4569 /* Init ath dfs pattern detector */
4570 ar->ath_common.debug_mask = ATH_DBG_DFS;
4571 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4572 NL80211_DFS_UNSET);
4573
4574 if (!ar->dfs_detector)
4575 ath10k_warn("dfs pattern detector init failed\n");
4576 }
4577
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4579 ath10k_reg_notifier);
4580 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02004581 ath10k_err("Regulatory initialization failed: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004582 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583 }
4584
4585 ret = ieee80211_register_hw(ar->hw);
4586 if (ret) {
4587 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004588 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004589 }
4590
4591 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4592 ret = regulatory_hint(ar->hw->wiphy,
4593 ar->ath_common.regulatory.alpha2);
4594 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004595 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004596 }
4597
4598 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004599
4600err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004601 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004602err_free:
4603 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4604 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4605
Kalle Valo5e3dd152013-06-12 20:52:10 +03004606 return ret;
4607}
4608
4609void ath10k_mac_unregister(struct ath10k *ar)
4610{
4611 ieee80211_unregister_hw(ar->hw);
4612
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004613 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4614 ar->dfs_detector->exit(ar->dfs_detector);
4615
Kalle Valo5e3dd152013-06-12 20:52:10 +03004616 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4617 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4618
4619 SET_IEEE80211_DEV(ar->hw, NULL);
4620}