blob: e3a3bbd41966e20b1429d9b6d767542bdef2f389 [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"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030032
33/**********/
34/* Crypto */
35/**********/
36
37static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
39 enum set_key_cmd cmd,
40 const u8 *macaddr)
41{
Michal Kazior7aa7a722014-08-25 12:09:38 +020042 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030043 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
47 .key_data = key->key,
48 .macaddr = macaddr,
49 };
50
Michal Kazior548db542013-07-05 16:15:15 +030051 lockdep_assert_held(&arvif->ar->conf_mutex);
52
Kalle Valo5e3dd152013-06-12 20:52:10 +030053 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
55 else
56 arg.key_flags = WMI_KEY_GROUP;
57
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030061 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
62 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
63 else
64 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030065 break;
66 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030067 arg.key_cipher = WMI_CIPHER_TKIP;
68 arg.key_txmic_len = 8;
69 arg.key_rxmic_len = 8;
70 break;
71 case WLAN_CIPHER_SUITE_WEP40:
72 case WLAN_CIPHER_SUITE_WEP104:
73 arg.key_cipher = WMI_CIPHER_WEP;
74 /* AP/IBSS mode requires self-key to be groupwise
75 * Otherwise pairwise key must be set */
76 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
77 arg.key_flags = WMI_KEY_PAIRWISE;
78 break;
79 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020080 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030081 return -EOPNOTSUPP;
82 }
83
84 if (cmd == DISABLE_KEY) {
85 arg.key_cipher = WMI_CIPHER_NONE;
86 arg.key_data = NULL;
87 }
88
89 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
90}
91
92static int ath10k_install_key(struct ath10k_vif *arvif,
93 struct ieee80211_key_conf *key,
94 enum set_key_cmd cmd,
95 const u8 *macaddr)
96{
97 struct ath10k *ar = arvif->ar;
98 int ret;
99
Michal Kazior548db542013-07-05 16:15:15 +0300100 lockdep_assert_held(&ar->conf_mutex);
101
Wolfram Sang16735d02013-11-14 14:32:02 -0800102 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300103
104 ret = ath10k_send_key(arvif, key, cmd, macaddr);
105 if (ret)
106 return ret;
107
108 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
109 if (ret == 0)
110 return -ETIMEDOUT;
111
112 return 0;
113}
114
115static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
116 const u8 *addr)
117{
118 struct ath10k *ar = arvif->ar;
119 struct ath10k_peer *peer;
120 int ret;
121 int i;
122
123 lockdep_assert_held(&ar->conf_mutex);
124
125 spin_lock_bh(&ar->data_lock);
126 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
127 spin_unlock_bh(&ar->data_lock);
128
129 if (!peer)
130 return -ENOENT;
131
132 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
133 if (arvif->wep_keys[i] == NULL)
134 continue;
135
136 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
137 addr);
138 if (ret)
139 return ret;
140
Sujith Manoharanae167132014-11-25 11:46:59 +0530141 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300142 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530143 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 }
145
146 return 0;
147}
148
149static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
150 const u8 *addr)
151{
152 struct ath10k *ar = arvif->ar;
153 struct ath10k_peer *peer;
154 int first_errno = 0;
155 int ret;
156 int i;
157
158 lockdep_assert_held(&ar->conf_mutex);
159
160 spin_lock_bh(&ar->data_lock);
161 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
162 spin_unlock_bh(&ar->data_lock);
163
164 if (!peer)
165 return -ENOENT;
166
167 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
168 if (peer->keys[i] == NULL)
169 continue;
170
171 ret = ath10k_install_key(arvif, peer->keys[i],
172 DISABLE_KEY, addr);
173 if (ret && first_errno == 0)
174 first_errno = ret;
175
176 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200177 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 i, ret);
179
Sujith Manoharanae167132014-11-25 11:46:59 +0530180 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300181 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530182 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300183 }
184
185 return first_errno;
186}
187
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530188bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
189 u8 keyidx)
190{
191 struct ath10k_peer *peer;
192 int i;
193
194 lockdep_assert_held(&ar->data_lock);
195
196 /* We don't know which vdev this peer belongs to,
197 * since WMI doesn't give us that information.
198 *
199 * FIXME: multi-bss needs to be handled.
200 */
201 peer = ath10k_peer_find(ar, 0, addr);
202 if (!peer)
203 return false;
204
205 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
206 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
207 return true;
208 }
209
210 return false;
211}
212
Kalle Valo5e3dd152013-06-12 20:52:10 +0300213static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
214 struct ieee80211_key_conf *key)
215{
216 struct ath10k *ar = arvif->ar;
217 struct ath10k_peer *peer;
218 u8 addr[ETH_ALEN];
219 int first_errno = 0;
220 int ret;
221 int i;
222
223 lockdep_assert_held(&ar->conf_mutex);
224
225 for (;;) {
226 /* since ath10k_install_key we can't hold data_lock all the
227 * time, so we try to remove the keys incrementally */
228 spin_lock_bh(&ar->data_lock);
229 i = 0;
230 list_for_each_entry(peer, &ar->peers, list) {
231 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
232 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300233 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300234 peer->keys[i] = NULL;
235 break;
236 }
237 }
238
239 if (i < ARRAY_SIZE(peer->keys))
240 break;
241 }
242 spin_unlock_bh(&ar->data_lock);
243
244 if (i == ARRAY_SIZE(peer->keys))
245 break;
246
247 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
248 if (ret && first_errno == 0)
249 first_errno = ret;
250
251 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200252 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200253 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300254 }
255
256 return first_errno;
257}
258
Kalle Valo5e3dd152013-06-12 20:52:10 +0300259/*********************/
260/* General utilities */
261/*********************/
262
263static inline enum wmi_phy_mode
264chan_to_phymode(const struct cfg80211_chan_def *chandef)
265{
266 enum wmi_phy_mode phymode = MODE_UNKNOWN;
267
268 switch (chandef->chan->band) {
269 case IEEE80211_BAND_2GHZ:
270 switch (chandef->width) {
271 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800272 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
273 phymode = MODE_11B;
274 else
275 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300276 break;
277 case NL80211_CHAN_WIDTH_20:
278 phymode = MODE_11NG_HT20;
279 break;
280 case NL80211_CHAN_WIDTH_40:
281 phymode = MODE_11NG_HT40;
282 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400283 case NL80211_CHAN_WIDTH_5:
284 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300285 case NL80211_CHAN_WIDTH_80:
286 case NL80211_CHAN_WIDTH_80P80:
287 case NL80211_CHAN_WIDTH_160:
288 phymode = MODE_UNKNOWN;
289 break;
290 }
291 break;
292 case IEEE80211_BAND_5GHZ:
293 switch (chandef->width) {
294 case NL80211_CHAN_WIDTH_20_NOHT:
295 phymode = MODE_11A;
296 break;
297 case NL80211_CHAN_WIDTH_20:
298 phymode = MODE_11NA_HT20;
299 break;
300 case NL80211_CHAN_WIDTH_40:
301 phymode = MODE_11NA_HT40;
302 break;
303 case NL80211_CHAN_WIDTH_80:
304 phymode = MODE_11AC_VHT80;
305 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400306 case NL80211_CHAN_WIDTH_5:
307 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300308 case NL80211_CHAN_WIDTH_80P80:
309 case NL80211_CHAN_WIDTH_160:
310 phymode = MODE_UNKNOWN;
311 break;
312 }
313 break;
314 default:
315 break;
316 }
317
318 WARN_ON(phymode == MODE_UNKNOWN);
319 return phymode;
320}
321
322static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
323{
324/*
325 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
326 * 0 for no restriction
327 * 1 for 1/4 us
328 * 2 for 1/2 us
329 * 3 for 1 us
330 * 4 for 2 us
331 * 5 for 4 us
332 * 6 for 8 us
333 * 7 for 16 us
334 */
335 switch (mpdudensity) {
336 case 0:
337 return 0;
338 case 1:
339 case 2:
340 case 3:
341 /* Our lower layer calculations limit our precision to
342 1 microsecond */
343 return 1;
344 case 4:
345 return 2;
346 case 5:
347 return 4;
348 case 6:
349 return 8;
350 case 7:
351 return 16;
352 default:
353 return 0;
354 }
355}
356
357static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
358{
359 int ret;
360
361 lockdep_assert_held(&ar->conf_mutex);
362
Michal Kaziorcfd10612014-11-25 15:16:05 +0100363 if (ar->num_peers >= ar->max_num_peers)
364 return -ENOBUFS;
365
Kalle Valo5e3dd152013-06-12 20:52:10 +0300366 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300370 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800371 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300372
373 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800374 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200375 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200376 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300377 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800378 }
Michal Kazior292a7532014-11-25 15:16:04 +0100379
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100380 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300381
382 return 0;
383}
384
Kalle Valo5a13e762014-01-20 11:01:46 +0200385static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
386{
387 struct ath10k *ar = arvif->ar;
388 u32 param;
389 int ret;
390
391 param = ar->wmi.pdev_param->sta_kickout_th;
392 ret = ath10k_wmi_pdev_set_param(ar, param,
393 ATH10K_KICKOUT_THRESHOLD);
394 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200395 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200396 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200397 return ret;
398 }
399
400 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
401 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
402 ATH10K_KEEPALIVE_MIN_IDLE);
403 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200404 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200405 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200406 return ret;
407 }
408
409 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
410 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
411 ATH10K_KEEPALIVE_MAX_IDLE);
412 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200413 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200414 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200415 return ret;
416 }
417
418 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
419 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
420 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
421 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200422 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200423 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200424 return ret;
425 }
426
427 return 0;
428}
429
Vivek Natarajanacab6402014-11-26 09:06:12 +0200430static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200431{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200432 struct ath10k *ar = arvif->ar;
433 u32 vdev_param;
434
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200435 vdev_param = ar->wmi.vdev_param->rts_threshold;
436 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200437}
438
439static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
440{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200441 struct ath10k *ar = arvif->ar;
442 u32 vdev_param;
443
Michal Kazior424121c2013-07-22 14:13:31 +0200444 if (value != 0xFFFFFFFF)
445 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
446 ATH10K_FRAGMT_THRESHOLD_MIN,
447 ATH10K_FRAGMT_THRESHOLD_MAX);
448
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200449 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
450 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200451}
452
Kalle Valo5e3dd152013-06-12 20:52:10 +0300453static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
454{
455 int ret;
456
457 lockdep_assert_held(&ar->conf_mutex);
458
459 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
460 if (ret)
461 return ret;
462
463 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
464 if (ret)
465 return ret;
466
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100467 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100468
Kalle Valo5e3dd152013-06-12 20:52:10 +0300469 return 0;
470}
471
472static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
473{
474 struct ath10k_peer *peer, *tmp;
475
476 lockdep_assert_held(&ar->conf_mutex);
477
478 spin_lock_bh(&ar->data_lock);
479 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
480 if (peer->vdev_id != vdev_id)
481 continue;
482
Michal Kazior7aa7a722014-08-25 12:09:38 +0200483 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300484 peer->addr, vdev_id);
485
486 list_del(&peer->list);
487 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100488 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300489 }
490 spin_unlock_bh(&ar->data_lock);
491}
492
Michal Kaziora96d7742013-07-16 09:38:56 +0200493static void ath10k_peer_cleanup_all(struct ath10k *ar)
494{
495 struct ath10k_peer *peer, *tmp;
496
497 lockdep_assert_held(&ar->conf_mutex);
498
499 spin_lock_bh(&ar->data_lock);
500 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
501 list_del(&peer->list);
502 kfree(peer);
503 }
504 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100505
506 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100507 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200508}
509
Kalle Valo5e3dd152013-06-12 20:52:10 +0300510/************************/
511/* Interface management */
512/************************/
513
Michal Kazior64badcb2014-09-18 11:18:02 +0300514void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
515{
516 struct ath10k *ar = arvif->ar;
517
518 lockdep_assert_held(&ar->data_lock);
519
520 if (!arvif->beacon)
521 return;
522
523 if (!arvif->beacon_buf)
524 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
525 arvif->beacon->len, DMA_TO_DEVICE);
526
527 dev_kfree_skb_any(arvif->beacon);
528
529 arvif->beacon = NULL;
530 arvif->beacon_sent = false;
531}
532
533static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
534{
535 struct ath10k *ar = arvif->ar;
536
537 lockdep_assert_held(&ar->data_lock);
538
539 ath10k_mac_vif_beacon_free(arvif);
540
541 if (arvif->beacon_buf) {
542 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
543 arvif->beacon_buf, arvif->beacon_paddr);
544 arvif->beacon_buf = NULL;
545 }
546}
547
Kalle Valo5e3dd152013-06-12 20:52:10 +0300548static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
549{
550 int ret;
551
Michal Kazior548db542013-07-05 16:15:15 +0300552 lockdep_assert_held(&ar->conf_mutex);
553
Michal Kazior7962b0d2014-10-28 10:34:38 +0100554 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
555 return -ESHUTDOWN;
556
Kalle Valo5e3dd152013-06-12 20:52:10 +0300557 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
558 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
559 if (ret == 0)
560 return -ETIMEDOUT;
561
562 return 0;
563}
564
Michal Kazior1bbc0972014-04-08 09:45:47 +0300565static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300566{
Michal Kaziorc930f742014-01-23 11:38:25 +0100567 struct cfg80211_chan_def *chandef = &ar->chandef;
568 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300569 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570 int ret = 0;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
Kalle Valo5e3dd152013-06-12 20:52:10 +0300574 arg.vdev_id = vdev_id;
575 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100576 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577
578 /* TODO setup this dynamically, what in case we
579 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100580 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200581 arg.channel.chan_radar =
582 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583
Michal Kazior89c5c842013-10-23 04:02:13 -0700584 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700585 arg.channel.max_power = channel->max_power * 2;
586 arg.channel.max_reg_power = channel->max_reg_power * 2;
587 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588
Michal Kazior7962b0d2014-10-28 10:34:38 +0100589 reinit_completion(&ar->vdev_setup_done);
590
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591 ret = ath10k_wmi_vdev_start(ar, &arg);
592 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200593 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200594 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595 return ret;
596 }
597
598 ret = ath10k_vdev_setup_sync(ar);
599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200600 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200601 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 return ret;
603 }
604
605 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200607 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200608 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609 goto vdev_stop;
610 }
611
612 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613
Michal Kazior7aa7a722014-08-25 12:09:38 +0200614 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300615 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616 return 0;
617
618vdev_stop:
619 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
620 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200621 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200622 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623
624 return ret;
625}
626
Michal Kazior1bbc0972014-04-08 09:45:47 +0300627static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300628{
629 int ret = 0;
630
631 lockdep_assert_held(&ar->conf_mutex);
632
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200633 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
634 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200635 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200636 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637
Michal Kazior7962b0d2014-10-28 10:34:38 +0100638 reinit_completion(&ar->vdev_setup_done);
639
Kalle Valo5e3dd152013-06-12 20:52:10 +0300640 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
641 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200642 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200643 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300644
645 ret = ath10k_vdev_setup_sync(ar);
646 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200647 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200648 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649
Michal Kazior7aa7a722014-08-25 12:09:38 +0200650 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300651 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300652 return ret;
653}
654
Michal Kazior1bbc0972014-04-08 09:45:47 +0300655static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300656{
657 int bit, ret = 0;
658
659 lockdep_assert_held(&ar->conf_mutex);
660
Ben Greeara9aefb32014-08-12 11:02:19 +0300661 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200662 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 return -ENOMEM;
664 }
665
Ben Greear16c11172014-09-23 14:17:16 -0700666 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300667
Ben Greear16c11172014-09-23 14:17:16 -0700668 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300669
670 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
671 WMI_VDEV_TYPE_MONITOR,
672 0, ar->mac_addr);
673 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200674 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200675 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300676 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300677 }
678
Ben Greear16c11172014-09-23 14:17:16 -0700679 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200680 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300681 ar->monitor_vdev_id);
682
Kalle Valo5e3dd152013-06-12 20:52:10 +0300683 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300684}
685
Michal Kazior1bbc0972014-04-08 09:45:47 +0300686static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300687{
688 int ret = 0;
689
690 lockdep_assert_held(&ar->conf_mutex);
691
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
693 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200695 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300696 return ret;
697 }
698
Ben Greear16c11172014-09-23 14:17:16 -0700699 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300700
Michal Kazior7aa7a722014-08-25 12:09:38 +0200701 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300702 ar->monitor_vdev_id);
703 return ret;
704}
705
Michal Kazior1bbc0972014-04-08 09:45:47 +0300706static int ath10k_monitor_start(struct ath10k *ar)
707{
708 int ret;
709
710 lockdep_assert_held(&ar->conf_mutex);
711
Michal Kazior1bbc0972014-04-08 09:45:47 +0300712 ret = ath10k_monitor_vdev_create(ar);
713 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200714 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300715 return ret;
716 }
717
718 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
719 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200720 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300721 ath10k_monitor_vdev_delete(ar);
722 return ret;
723 }
724
725 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200726 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300727
728 return 0;
729}
730
Michal Kazior19337472014-08-28 12:58:16 +0200731static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300732{
733 int ret;
734
735 lockdep_assert_held(&ar->conf_mutex);
736
Michal Kazior1bbc0972014-04-08 09:45:47 +0300737 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200739 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200740 return ret;
741 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300742
743 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200745 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200746 return ret;
747 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300748
749 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200750 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200751
752 return 0;
753}
754
755static int ath10k_monitor_recalc(struct ath10k *ar)
756{
757 bool should_start;
758
759 lockdep_assert_held(&ar->conf_mutex);
760
761 should_start = ar->monitor ||
762 ar->filter_flags & FIF_PROMISC_IN_BSS ||
763 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
764
765 ath10k_dbg(ar, ATH10K_DBG_MAC,
766 "mac monitor recalc started? %d should? %d\n",
767 ar->monitor_started, should_start);
768
769 if (should_start == ar->monitor_started)
770 return 0;
771
772 if (should_start)
773 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300774
775 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300776}
777
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200778static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
779{
780 struct ath10k *ar = arvif->ar;
781 u32 vdev_param, rts_cts = 0;
782
783 lockdep_assert_held(&ar->conf_mutex);
784
785 vdev_param = ar->wmi.vdev_param->enable_rtscts;
786
787 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
788 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
789
790 if (arvif->num_legacy_stations > 0)
791 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
792 WMI_RTSCTS_PROFILE);
793
794 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
795 rts_cts);
796}
797
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200798static int ath10k_start_cac(struct ath10k *ar)
799{
800 int ret;
801
802 lockdep_assert_held(&ar->conf_mutex);
803
804 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
805
Michal Kazior19337472014-08-28 12:58:16 +0200806 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200807 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200808 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200809 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
810 return ret;
811 }
812
Michal Kazior7aa7a722014-08-25 12:09:38 +0200813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200814 ar->monitor_vdev_id);
815
816 return 0;
817}
818
819static int ath10k_stop_cac(struct ath10k *ar)
820{
821 lockdep_assert_held(&ar->conf_mutex);
822
823 /* CAC is not running - do nothing */
824 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
825 return 0;
826
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200827 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300828 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200829
Michal Kazior7aa7a722014-08-25 12:09:38 +0200830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200831
832 return 0;
833}
834
Michal Kaziord6500972014-04-08 09:56:09 +0300835static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200836{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200837 int ret;
838
839 lockdep_assert_held(&ar->conf_mutex);
840
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200841 ath10k_stop_cac(ar);
842
Michal Kaziord6500972014-04-08 09:56:09 +0300843 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200844 return;
845
Michal Kaziord6500972014-04-08 09:56:09 +0300846 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200847 return;
848
849 ret = ath10k_start_cac(ar);
850 if (ret) {
851 /*
852 * Not possible to start CAC on current channel so starting
853 * radiation is not allowed, make this channel DFS_UNAVAILABLE
854 * by indicating that radar was detected.
855 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200856 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200857 ieee80211_radar_detected(ar->hw);
858 }
859}
860
Michal Kaziordc55e302014-07-29 12:53:36 +0300861static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300862{
863 struct ath10k *ar = arvif->ar;
864 struct cfg80211_chan_def *chandef = &ar->chandef;
865 struct wmi_vdev_start_request_arg arg = {};
866 int ret = 0;
867
868 lockdep_assert_held(&ar->conf_mutex);
869
870 reinit_completion(&ar->vdev_setup_done);
871
872 arg.vdev_id = arvif->vdev_id;
873 arg.dtim_period = arvif->dtim_period;
874 arg.bcn_intval = arvif->beacon_interval;
875
876 arg.channel.freq = chandef->chan->center_freq;
877 arg.channel.band_center_freq1 = chandef->center_freq1;
878 arg.channel.mode = chan_to_phymode(chandef);
879
880 arg.channel.min_power = 0;
881 arg.channel.max_power = chandef->chan->max_power * 2;
882 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
883 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
884
885 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
886 arg.ssid = arvif->u.ap.ssid;
887 arg.ssid_len = arvif->u.ap.ssid_len;
888 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
889
890 /* For now allow DFS for AP mode */
891 arg.channel.chan_radar =
892 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
893 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
894 arg.ssid = arvif->vif->bss_conf.ssid;
895 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
896 }
897
Michal Kazior7aa7a722014-08-25 12:09:38 +0200898 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300899 "mac vdev %d start center_freq %d phymode %s\n",
900 arg.vdev_id, arg.channel.freq,
901 ath10k_wmi_phymode_str(arg.channel.mode));
902
Michal Kaziordc55e302014-07-29 12:53:36 +0300903 if (restart)
904 ret = ath10k_wmi_vdev_restart(ar, &arg);
905 else
906 ret = ath10k_wmi_vdev_start(ar, &arg);
907
Michal Kazior72654fa2014-04-08 09:56:09 +0300908 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 arg.vdev_id, ret);
911 return ret;
912 }
913
914 ret = ath10k_vdev_setup_sync(ar);
915 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200916 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300917 arg.vdev_id, ret);
918 return ret;
919 }
920
Michal Kaziord6500972014-04-08 09:56:09 +0300921 ar->num_started_vdevs++;
922 ath10k_recalc_radar_detection(ar);
923
Michal Kazior72654fa2014-04-08 09:56:09 +0300924 return ret;
925}
926
Michal Kaziordc55e302014-07-29 12:53:36 +0300927static int ath10k_vdev_start(struct ath10k_vif *arvif)
928{
929 return ath10k_vdev_start_restart(arvif, false);
930}
931
932static int ath10k_vdev_restart(struct ath10k_vif *arvif)
933{
934 return ath10k_vdev_start_restart(arvif, true);
935}
936
Michal Kazior72654fa2014-04-08 09:56:09 +0300937static int ath10k_vdev_stop(struct ath10k_vif *arvif)
938{
939 struct ath10k *ar = arvif->ar;
940 int ret;
941
942 lockdep_assert_held(&ar->conf_mutex);
943
944 reinit_completion(&ar->vdev_setup_done);
945
946 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
947 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200948 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300949 arvif->vdev_id, ret);
950 return ret;
951 }
952
953 ret = ath10k_vdev_setup_sync(ar);
954 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200955 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300956 arvif->vdev_id, ret);
957 return ret;
958 }
959
Michal Kaziord6500972014-04-08 09:56:09 +0300960 WARN_ON(ar->num_started_vdevs == 0);
961
962 if (ar->num_started_vdevs != 0) {
963 ar->num_started_vdevs--;
964 ath10k_recalc_radar_detection(ar);
965 }
966
Michal Kazior72654fa2014-04-08 09:56:09 +0300967 return ret;
968}
969
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200970static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
971 struct sk_buff *bcn)
972{
973 struct ath10k *ar = arvif->ar;
974 struct ieee80211_mgmt *mgmt;
975 const u8 *p2p_ie;
976 int ret;
977
978 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
979 return 0;
980
981 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
982 return 0;
983
984 mgmt = (void *)bcn->data;
985 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
986 mgmt->u.beacon.variable,
987 bcn->len - (mgmt->u.beacon.variable -
988 bcn->data));
989 if (!p2p_ie)
990 return -ENOENT;
991
992 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
993 if (ret) {
994 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
995 arvif->vdev_id, ret);
996 return ret;
997 }
998
999 return 0;
1000}
1001
1002static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1003 u8 oui_type, size_t ie_offset)
1004{
1005 size_t len;
1006 const u8 *next;
1007 const u8 *end;
1008 u8 *ie;
1009
1010 if (WARN_ON(skb->len < ie_offset))
1011 return -EINVAL;
1012
1013 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1014 skb->data + ie_offset,
1015 skb->len - ie_offset);
1016 if (!ie)
1017 return -ENOENT;
1018
1019 len = ie[1] + 2;
1020 end = skb->data + skb->len;
1021 next = ie + len;
1022
1023 if (WARN_ON(next > end))
1024 return -EINVAL;
1025
1026 memmove(ie, next, end - next);
1027 skb_trim(skb, skb->len - len);
1028
1029 return 0;
1030}
1031
1032static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1033{
1034 struct ath10k *ar = arvif->ar;
1035 struct ieee80211_hw *hw = ar->hw;
1036 struct ieee80211_vif *vif = arvif->vif;
1037 struct ieee80211_mutable_offsets offs = {};
1038 struct sk_buff *bcn;
1039 int ret;
1040
1041 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1042 return 0;
1043
1044 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1045 if (!bcn) {
1046 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1047 return -EPERM;
1048 }
1049
1050 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1051 if (ret) {
1052 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1053 kfree_skb(bcn);
1054 return ret;
1055 }
1056
1057 /* P2P IE is inserted by firmware automatically (as configured above)
1058 * so remove it from the base beacon template to avoid duplicate P2P
1059 * IEs in beacon frames.
1060 */
1061 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1062 offsetof(struct ieee80211_mgmt,
1063 u.beacon.variable));
1064
1065 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1066 0, NULL, 0);
1067 kfree_skb(bcn);
1068
1069 if (ret) {
1070 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1071 ret);
1072 return ret;
1073 }
1074
1075 return 0;
1076}
1077
1078static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1079{
1080 struct ath10k *ar = arvif->ar;
1081 struct ieee80211_hw *hw = ar->hw;
1082 struct ieee80211_vif *vif = arvif->vif;
1083 struct sk_buff *prb;
1084 int ret;
1085
1086 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1087 return 0;
1088
1089 prb = ieee80211_proberesp_get(hw, vif);
1090 if (!prb) {
1091 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1092 return -EPERM;
1093 }
1094
1095 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1096 kfree_skb(prb);
1097
1098 if (ret) {
1099 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1100 ret);
1101 return ret;
1102 }
1103
1104 return 0;
1105}
1106
Kalle Valo5e3dd152013-06-12 20:52:10 +03001107static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001108 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001109{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001110 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001111 int ret = 0;
1112
Michal Kazior548db542013-07-05 16:15:15 +03001113 lockdep_assert_held(&arvif->ar->conf_mutex);
1114
Kalle Valo5e3dd152013-06-12 20:52:10 +03001115 if (!info->enable_beacon) {
1116 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001117
1118 arvif->is_started = false;
1119 arvif->is_up = false;
1120
Michal Kazior748afc42014-01-23 12:48:21 +01001121 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001122 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001123 spin_unlock_bh(&arvif->ar->data_lock);
1124
Kalle Valo5e3dd152013-06-12 20:52:10 +03001125 return;
1126 }
1127
1128 arvif->tx_seq_no = 0x1000;
1129
1130 ret = ath10k_vdev_start(arvif);
1131 if (ret)
1132 return;
1133
Michal Kaziorc930f742014-01-23 11:38:25 +01001134 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001135 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001136
1137 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1138 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001139 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001140 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001141 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001142 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001143 return;
1144 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001145
1146 arvif->is_started = true;
1147 arvif->is_up = true;
1148
Michal Kazior7aa7a722014-08-25 12:09:38 +02001149 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001150}
1151
1152static void ath10k_control_ibss(struct ath10k_vif *arvif,
1153 struct ieee80211_bss_conf *info,
1154 const u8 self_peer[ETH_ALEN])
1155{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001156 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001157 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001158 int ret = 0;
1159
Michal Kazior548db542013-07-05 16:15:15 +03001160 lockdep_assert_held(&arvif->ar->conf_mutex);
1161
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162 if (!info->ibss_joined) {
1163 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1164 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001165 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001166 self_peer, arvif->vdev_id, ret);
1167
Michal Kaziorc930f742014-01-23 11:38:25 +01001168 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169 return;
1170
Michal Kaziorc930f742014-01-23 11:38:25 +01001171 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001172
1173 return;
1174 }
1175
1176 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1177 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001178 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001179 self_peer, arvif->vdev_id, ret);
1180 return;
1181 }
1182
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001183 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1184 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001185 ATH10K_DEFAULT_ATIM);
1186 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001187 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001188 arvif->vdev_id, ret);
1189}
1190
Michal Kazior9f9b5742014-12-12 12:41:36 +01001191static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1192{
1193 struct ath10k *ar = arvif->ar;
1194 u32 param;
1195 u32 value;
1196 int ret;
1197
1198 lockdep_assert_held(&arvif->ar->conf_mutex);
1199
1200 if (arvif->u.sta.uapsd)
1201 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1202 else
1203 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1204
1205 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1206 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1207 if (ret) {
1208 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1209 value, arvif->vdev_id, ret);
1210 return ret;
1211 }
1212
1213 return 0;
1214}
1215
1216static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1217{
1218 struct ath10k *ar = arvif->ar;
1219 u32 param;
1220 u32 value;
1221 int ret;
1222
1223 lockdep_assert_held(&arvif->ar->conf_mutex);
1224
1225 if (arvif->u.sta.uapsd)
1226 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1227 else
1228 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1229
1230 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1231 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1232 param, value);
1233 if (ret) {
1234 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1235 value, arvif->vdev_id, ret);
1236 return ret;
1237 }
1238
1239 return 0;
1240}
1241
Michal Kaziorad088bf2013-10-16 15:44:46 +03001242static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001244 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001245 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001246 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001247 enum wmi_sta_powersave_param param;
1248 enum wmi_sta_ps_mode psmode;
1249 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001250 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001251
Michal Kazior548db542013-07-05 16:15:15 +03001252 lockdep_assert_held(&arvif->ar->conf_mutex);
1253
Michal Kaziorad088bf2013-10-16 15:44:46 +03001254 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1255 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001256
Michal Kaziorbf14e652014-12-12 12:41:38 +01001257 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 psmode = WMI_STA_PS_MODE_ENABLED;
1259 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1260
Michal Kazior526549a2014-12-12 12:41:37 +01001261 ps_timeout = conf->dynamic_ps_timeout;
1262 if (ps_timeout == 0) {
1263 /* Firmware doesn't like 0 */
1264 ps_timeout = ieee80211_tu_to_usec(
1265 vif->bss_conf.beacon_int) / 1000;
1266 }
1267
Michal Kaziorad088bf2013-10-16 15:44:46 +03001268 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001269 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001271 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001272 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001273 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001274 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001275 } else {
1276 psmode = WMI_STA_PS_MODE_DISABLED;
1277 }
1278
Michal Kazior7aa7a722014-08-25 12:09:38 +02001279 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001280 arvif->vdev_id, psmode ? "enable" : "disable");
1281
Michal Kaziorad088bf2013-10-16 15:44:46 +03001282 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1283 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001284 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001285 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001286 return ret;
1287 }
1288
1289 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001290}
1291
1292/**********************/
1293/* Station management */
1294/**********************/
1295
Michal Kazior590922a2014-10-21 10:10:29 +03001296static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1297 struct ieee80211_vif *vif)
1298{
1299 /* Some firmware revisions have unstable STA powersave when listen
1300 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1301 * generate NullFunc frames properly even if buffered frames have been
1302 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1303 * buffered frames. Often pinging the device from AP would simply fail.
1304 *
1305 * As a workaround set it to 1.
1306 */
1307 if (vif->type == NL80211_IFTYPE_STATION)
1308 return 1;
1309
1310 return ar->hw->conf.listen_interval;
1311}
1312
Kalle Valo5e3dd152013-06-12 20:52:10 +03001313static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001314 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001315 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001316 struct wmi_peer_assoc_complete_arg *arg)
1317{
Michal Kazior590922a2014-10-21 10:10:29 +03001318 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1319
Michal Kazior548db542013-07-05 16:15:15 +03001320 lockdep_assert_held(&ar->conf_mutex);
1321
Kalle Valob25f32c2014-09-14 12:50:49 +03001322 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001323 arg->vdev_id = arvif->vdev_id;
1324 arg->peer_aid = sta->aid;
1325 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001326 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001327 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001328 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001329}
1330
1331static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001332 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001333 struct wmi_peer_assoc_complete_arg *arg)
1334{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335 struct ieee80211_bss_conf *info = &vif->bss_conf;
1336 struct cfg80211_bss *bss;
1337 const u8 *rsnie = NULL;
1338 const u8 *wpaie = NULL;
1339
Michal Kazior548db542013-07-05 16:15:15 +03001340 lockdep_assert_held(&ar->conf_mutex);
1341
Kalle Valo5e3dd152013-06-12 20:52:10 +03001342 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1343 info->bssid, NULL, 0, 0, 0);
1344 if (bss) {
1345 const struct cfg80211_bss_ies *ies;
1346
1347 rcu_read_lock();
1348 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1349
1350 ies = rcu_dereference(bss->ies);
1351
1352 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001353 WLAN_OUI_TYPE_MICROSOFT_WPA,
1354 ies->data,
1355 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356 rcu_read_unlock();
1357 cfg80211_put_bss(ar->hw->wiphy, bss);
1358 }
1359
1360 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1361 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001362 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001363 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1364 }
1365
1366 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001367 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1369 }
1370}
1371
1372static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1373 struct ieee80211_sta *sta,
1374 struct wmi_peer_assoc_complete_arg *arg)
1375{
1376 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1377 const struct ieee80211_supported_band *sband;
1378 const struct ieee80211_rate *rates;
1379 u32 ratemask;
1380 int i;
1381
Michal Kazior548db542013-07-05 16:15:15 +03001382 lockdep_assert_held(&ar->conf_mutex);
1383
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1385 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1386 rates = sband->bitrates;
1387
1388 rateset->num_rates = 0;
1389
1390 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1391 if (!(ratemask & 1))
1392 continue;
1393
1394 rateset->rates[rateset->num_rates] = rates->hw_value;
1395 rateset->num_rates++;
1396 }
1397}
1398
1399static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1400 struct ieee80211_sta *sta,
1401 struct wmi_peer_assoc_complete_arg *arg)
1402{
1403 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001404 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001405 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001406
Michal Kazior548db542013-07-05 16:15:15 +03001407 lockdep_assert_held(&ar->conf_mutex);
1408
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 if (!ht_cap->ht_supported)
1410 return;
1411
1412 arg->peer_flags |= WMI_PEER_HT;
1413 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1414 ht_cap->ampdu_factor)) - 1;
1415
1416 arg->peer_mpdu_density =
1417 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1418
1419 arg->peer_ht_caps = ht_cap->cap;
1420 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1421
1422 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1423 arg->peer_flags |= WMI_PEER_LDPC;
1424
1425 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1426 arg->peer_flags |= WMI_PEER_40MHZ;
1427 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1428 }
1429
1430 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1431 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1432
1433 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1434 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1435
1436 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1437 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1438 arg->peer_flags |= WMI_PEER_STBC;
1439 }
1440
1441 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001442 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1443 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1444 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1445 arg->peer_rate_caps |= stbc;
1446 arg->peer_flags |= WMI_PEER_STBC;
1447 }
1448
Kalle Valo5e3dd152013-06-12 20:52:10 +03001449 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1450 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1451 else if (ht_cap->mcs.rx_mask[1])
1452 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1453
1454 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1455 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1456 arg->peer_ht_rates.rates[n++] = i;
1457
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001458 /*
1459 * This is a workaround for HT-enabled STAs which break the spec
1460 * and have no HT capabilities RX mask (no HT RX MCS map).
1461 *
1462 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1463 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1464 *
1465 * Firmware asserts if such situation occurs.
1466 */
1467 if (n == 0) {
1468 arg->peer_ht_rates.num_rates = 8;
1469 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1470 arg->peer_ht_rates.rates[i] = i;
1471 } else {
1472 arg->peer_ht_rates.num_rates = n;
1473 arg->peer_num_spatial_streams = sta->rx_nss;
1474 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001475
Michal Kazior7aa7a722014-08-25 12:09:38 +02001476 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001477 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478 arg->peer_ht_rates.num_rates,
1479 arg->peer_num_spatial_streams);
1480}
1481
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001482static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1483 struct ath10k_vif *arvif,
1484 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485{
1486 u32 uapsd = 0;
1487 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001488 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001489
Michal Kazior548db542013-07-05 16:15:15 +03001490 lockdep_assert_held(&ar->conf_mutex);
1491
Kalle Valo5e3dd152013-06-12 20:52:10 +03001492 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001493 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001494 sta->uapsd_queues, sta->max_sp);
1495
Kalle Valo5e3dd152013-06-12 20:52:10 +03001496 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1497 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1498 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1499 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1500 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1501 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1502 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1503 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1504 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1505 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1506 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1507 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1508
Kalle Valo5e3dd152013-06-12 20:52:10 +03001509 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1510 max_sp = sta->max_sp;
1511
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001512 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1513 sta->addr,
1514 WMI_AP_PS_PEER_PARAM_UAPSD,
1515 uapsd);
1516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001517 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001518 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001519 return ret;
1520 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001521
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001522 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1523 sta->addr,
1524 WMI_AP_PS_PEER_PARAM_MAX_SP,
1525 max_sp);
1526 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001527 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001528 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001529 return ret;
1530 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001531
1532 /* TODO setup this based on STA listen interval and
1533 beacon interval. Currently we don't know
1534 sta->listen_interval - mac80211 patch required.
1535 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001536 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001537 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1538 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001539 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001540 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001541 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001542 return ret;
1543 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001544 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001545
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001546 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001547}
1548
1549static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1550 struct ieee80211_sta *sta,
1551 struct wmi_peer_assoc_complete_arg *arg)
1552{
1553 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001554 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555
1556 if (!vht_cap->vht_supported)
1557 return;
1558
1559 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560 arg->peer_vht_caps = vht_cap->cap;
1561
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001562 ampdu_factor = (vht_cap->cap &
1563 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1564 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1565
1566 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1567 * zero in VHT IE. Using it would result in degraded throughput.
1568 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1569 * it if VHT max_mpdu is smaller. */
1570 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1571 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1572 ampdu_factor)) - 1);
1573
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1575 arg->peer_flags |= WMI_PEER_80MHZ;
1576
1577 arg->peer_vht_rates.rx_max_rate =
1578 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1579 arg->peer_vht_rates.rx_mcs_set =
1580 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1581 arg->peer_vht_rates.tx_max_rate =
1582 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1583 arg->peer_vht_rates.tx_mcs_set =
1584 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1585
Michal Kazior7aa7a722014-08-25 12:09:38 +02001586 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001587 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588}
1589
1590static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001591 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001593 struct wmi_peer_assoc_complete_arg *arg)
1594{
Michal Kazior590922a2014-10-21 10:10:29 +03001595 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1596
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597 switch (arvif->vdev_type) {
1598 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001599 if (sta->wme)
1600 arg->peer_flags |= WMI_PEER_QOS;
1601
1602 if (sta->wme && sta->uapsd_queues) {
1603 arg->peer_flags |= WMI_PEER_APSD;
1604 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1605 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 break;
1607 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001608 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001609 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001610 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001611 case WMI_VDEV_TYPE_IBSS:
1612 if (sta->wme)
1613 arg->peer_flags |= WMI_PEER_QOS;
1614 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 default:
1616 break;
1617 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001618
1619 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1620 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621}
1622
Michal Kazior91b12082014-12-12 12:41:35 +01001623static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1624{
1625 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1626 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1627}
1628
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001630 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 struct ieee80211_sta *sta,
1632 struct wmi_peer_assoc_complete_arg *arg)
1633{
1634 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1635
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 switch (ar->hw->conf.chandef.chan->band) {
1637 case IEEE80211_BAND_2GHZ:
1638 if (sta->ht_cap.ht_supported) {
1639 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1640 phymode = MODE_11NG_HT40;
1641 else
1642 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001643 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001645 } else {
1646 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 }
1648
1649 break;
1650 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001651 /*
1652 * Check VHT first.
1653 */
1654 if (sta->vht_cap.vht_supported) {
1655 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1656 phymode = MODE_11AC_VHT80;
1657 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1658 phymode = MODE_11AC_VHT40;
1659 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1660 phymode = MODE_11AC_VHT20;
1661 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1663 phymode = MODE_11NA_HT40;
1664 else
1665 phymode = MODE_11NA_HT20;
1666 } else {
1667 phymode = MODE_11A;
1668 }
1669
1670 break;
1671 default:
1672 break;
1673 }
1674
Michal Kazior7aa7a722014-08-25 12:09:38 +02001675 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001676 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001677
Kalle Valo5e3dd152013-06-12 20:52:10 +03001678 arg->peer_phymode = phymode;
1679 WARN_ON(phymode == MODE_UNKNOWN);
1680}
1681
Kalle Valob9ada652013-10-16 15:44:46 +03001682static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001683 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001684 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001685 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001686{
Michal Kazior548db542013-07-05 16:15:15 +03001687 lockdep_assert_held(&ar->conf_mutex);
1688
Kalle Valob9ada652013-10-16 15:44:46 +03001689 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690
Michal Kazior590922a2014-10-21 10:10:29 +03001691 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1692 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001693 ath10k_peer_assoc_h_rates(ar, sta, arg);
1694 ath10k_peer_assoc_h_ht(ar, sta, arg);
1695 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001696 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1697 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001698
Kalle Valob9ada652013-10-16 15:44:46 +03001699 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700}
1701
Michal Kazior90046f52014-02-14 14:45:51 +01001702static const u32 ath10k_smps_map[] = {
1703 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1704 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1705 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1706 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1707};
1708
1709static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1710 const u8 *addr,
1711 const struct ieee80211_sta_ht_cap *ht_cap)
1712{
1713 int smps;
1714
1715 if (!ht_cap->ht_supported)
1716 return 0;
1717
1718 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1719 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1720
1721 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1722 return -EINVAL;
1723
1724 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1725 WMI_PEER_SMPS_STATE,
1726 ath10k_smps_map[smps]);
1727}
1728
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729/* can be called only in mac80211 callbacks due to `key_count` usage */
1730static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1731 struct ieee80211_vif *vif,
1732 struct ieee80211_bss_conf *bss_conf)
1733{
1734 struct ath10k *ar = hw->priv;
1735 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001736 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001737 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738 struct ieee80211_sta *ap_sta;
1739 int ret;
1740
Michal Kazior548db542013-07-05 16:15:15 +03001741 lockdep_assert_held(&ar->conf_mutex);
1742
Michal Kazior077efc82014-10-21 10:10:29 +03001743 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1744 arvif->vdev_id, arvif->bssid, arvif->aid);
1745
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746 rcu_read_lock();
1747
1748 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1749 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001750 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001751 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752 rcu_read_unlock();
1753 return;
1754 }
1755
Michal Kazior90046f52014-02-14 14:45:51 +01001756 /* ap_sta must be accessed only within rcu section which must be left
1757 * before calling ath10k_setup_peer_smps() which might sleep. */
1758 ht_cap = ap_sta->ht_cap;
1759
Michal Kazior590922a2014-10-21 10:10:29 +03001760 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001761 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001762 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001763 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001764 rcu_read_unlock();
1765 return;
1766 }
1767
1768 rcu_read_unlock();
1769
Kalle Valob9ada652013-10-16 15:44:46 +03001770 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001772 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001773 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001774 return;
1775 }
1776
Michal Kazior90046f52014-02-14 14:45:51 +01001777 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1778 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001779 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001780 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001781 return;
1782 }
1783
Michal Kazior7aa7a722014-08-25 12:09:38 +02001784 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001785 "mac vdev %d up (associated) bssid %pM aid %d\n",
1786 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1787
Michal Kazior077efc82014-10-21 10:10:29 +03001788 WARN_ON(arvif->is_up);
1789
Michal Kaziorc930f742014-01-23 11:38:25 +01001790 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001791 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001792
1793 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1794 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001795 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001796 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001797 return;
1798 }
1799
1800 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001801}
1802
Kalle Valo5e3dd152013-06-12 20:52:10 +03001803static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1804 struct ieee80211_vif *vif)
1805{
1806 struct ath10k *ar = hw->priv;
1807 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1808 int ret;
1809
Michal Kazior548db542013-07-05 16:15:15 +03001810 lockdep_assert_held(&ar->conf_mutex);
1811
Michal Kazior077efc82014-10-21 10:10:29 +03001812 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1813 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001814
Kalle Valo5e3dd152013-06-12 20:52:10 +03001815 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001816 if (ret)
1817 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1818 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001820 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001821 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001822}
1823
Michal Kazior590922a2014-10-21 10:10:29 +03001824static int ath10k_station_assoc(struct ath10k *ar,
1825 struct ieee80211_vif *vif,
1826 struct ieee80211_sta *sta,
1827 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001828{
Michal Kazior590922a2014-10-21 10:10:29 +03001829 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001830 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001831 int ret = 0;
1832
Michal Kazior548db542013-07-05 16:15:15 +03001833 lockdep_assert_held(&ar->conf_mutex);
1834
Michal Kazior590922a2014-10-21 10:10:29 +03001835 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001837 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001838 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001839 return ret;
1840 }
1841
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001842 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001843 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1844 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001845 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001846 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001847 return ret;
1848 }
1849
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001850 /* Re-assoc is run only to update supported rates for given station. It
1851 * doesn't make much sense to reconfigure the peer completely.
1852 */
1853 if (!reassoc) {
1854 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1855 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001856 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001857 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001858 arvif->vdev_id, ret);
1859 return ret;
1860 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001861
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001862 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1863 if (ret) {
1864 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1865 sta->addr, arvif->vdev_id, ret);
1866 return ret;
1867 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001868
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001869 if (!sta->wme) {
1870 arvif->num_legacy_stations++;
1871 ret = ath10k_recalc_rtscts_prot(arvif);
1872 if (ret) {
1873 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1874 arvif->vdev_id, ret);
1875 return ret;
1876 }
1877 }
1878
1879 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1880 if (ret) {
1881 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001882 arvif->vdev_id, ret);
1883 return ret;
1884 }
1885 }
1886
Kalle Valo5e3dd152013-06-12 20:52:10 +03001887 return ret;
1888}
1889
Michal Kazior590922a2014-10-21 10:10:29 +03001890static int ath10k_station_disassoc(struct ath10k *ar,
1891 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892 struct ieee80211_sta *sta)
1893{
Michal Kazior590922a2014-10-21 10:10:29 +03001894 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001895 int ret = 0;
1896
1897 lockdep_assert_held(&ar->conf_mutex);
1898
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001899 if (!sta->wme) {
1900 arvif->num_legacy_stations--;
1901 ret = ath10k_recalc_rtscts_prot(arvif);
1902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001903 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001904 arvif->vdev_id, ret);
1905 return ret;
1906 }
1907 }
1908
Kalle Valo5e3dd152013-06-12 20:52:10 +03001909 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1910 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001911 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001912 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001913 return ret;
1914 }
1915
1916 return ret;
1917}
1918
1919/**************/
1920/* Regulatory */
1921/**************/
1922
1923static int ath10k_update_channel_list(struct ath10k *ar)
1924{
1925 struct ieee80211_hw *hw = ar->hw;
1926 struct ieee80211_supported_band **bands;
1927 enum ieee80211_band band;
1928 struct ieee80211_channel *channel;
1929 struct wmi_scan_chan_list_arg arg = {0};
1930 struct wmi_channel_arg *ch;
1931 bool passive;
1932 int len;
1933 int ret;
1934 int i;
1935
Michal Kazior548db542013-07-05 16:15:15 +03001936 lockdep_assert_held(&ar->conf_mutex);
1937
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 bands = hw->wiphy->bands;
1939 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1940 if (!bands[band])
1941 continue;
1942
1943 for (i = 0; i < bands[band]->n_channels; i++) {
1944 if (bands[band]->channels[i].flags &
1945 IEEE80211_CHAN_DISABLED)
1946 continue;
1947
1948 arg.n_channels++;
1949 }
1950 }
1951
1952 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1953 arg.channels = kzalloc(len, GFP_KERNEL);
1954 if (!arg.channels)
1955 return -ENOMEM;
1956
1957 ch = arg.channels;
1958 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1959 if (!bands[band])
1960 continue;
1961
1962 for (i = 0; i < bands[band]->n_channels; i++) {
1963 channel = &bands[band]->channels[i];
1964
1965 if (channel->flags & IEEE80211_CHAN_DISABLED)
1966 continue;
1967
1968 ch->allow_ht = true;
1969
1970 /* FIXME: when should we really allow VHT? */
1971 ch->allow_vht = true;
1972
1973 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001974 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001975
1976 ch->ht40plus =
1977 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1978
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001979 ch->chan_radar =
1980 !!(channel->flags & IEEE80211_CHAN_RADAR);
1981
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001982 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001983 ch->passive = passive;
1984
1985 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001986 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001987 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001988 ch->max_power = channel->max_power * 2;
1989 ch->max_reg_power = channel->max_reg_power * 2;
1990 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001991 ch->reg_class_id = 0; /* FIXME */
1992
1993 /* FIXME: why use only legacy modes, why not any
1994 * HT/VHT modes? Would that even make any
1995 * difference? */
1996 if (channel->band == IEEE80211_BAND_2GHZ)
1997 ch->mode = MODE_11G;
1998 else
1999 ch->mode = MODE_11A;
2000
2001 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2002 continue;
2003
Michal Kazior7aa7a722014-08-25 12:09:38 +02002004 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002005 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2006 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002007 ch->freq, ch->max_power, ch->max_reg_power,
2008 ch->max_antenna_gain, ch->mode);
2009
2010 ch++;
2011 }
2012 }
2013
2014 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2015 kfree(arg.channels);
2016
2017 return ret;
2018}
2019
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002020static enum wmi_dfs_region
2021ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2022{
2023 switch (dfs_region) {
2024 case NL80211_DFS_UNSET:
2025 return WMI_UNINIT_DFS_DOMAIN;
2026 case NL80211_DFS_FCC:
2027 return WMI_FCC_DFS_DOMAIN;
2028 case NL80211_DFS_ETSI:
2029 return WMI_ETSI_DFS_DOMAIN;
2030 case NL80211_DFS_JP:
2031 return WMI_MKK4_DFS_DOMAIN;
2032 }
2033 return WMI_UNINIT_DFS_DOMAIN;
2034}
2035
Michal Kaziorf7843d72013-07-16 09:38:52 +02002036static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002037{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002040 enum wmi_dfs_region wmi_dfs_reg;
2041 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002042
Michal Kaziorf7843d72013-07-16 09:38:52 +02002043 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002044
2045 ret = ath10k_update_channel_list(ar);
2046 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002047 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002048
2049 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002050
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002051 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2052 nl_dfs_reg = ar->dfs_detector->region;
2053 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2054 } else {
2055 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2056 }
2057
Kalle Valo5e3dd152013-06-12 20:52:10 +03002058 /* Target allows setting up per-band regdomain but ath_common provides
2059 * a combined one only */
2060 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002061 regpair->reg_domain,
2062 regpair->reg_domain, /* 2ghz */
2063 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002064 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002065 regpair->reg_5ghz_ctl,
2066 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002067 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002068 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002069}
Michal Kazior548db542013-07-05 16:15:15 +03002070
Michal Kaziorf7843d72013-07-16 09:38:52 +02002071static void ath10k_reg_notifier(struct wiphy *wiphy,
2072 struct regulatory_request *request)
2073{
2074 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2075 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002076 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002077
2078 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2079
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002080 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002081 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002082 request->dfs_region);
2083 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2084 request->dfs_region);
2085 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002086 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002087 request->dfs_region);
2088 }
2089
Michal Kaziorf7843d72013-07-16 09:38:52 +02002090 mutex_lock(&ar->conf_mutex);
2091 if (ar->state == ATH10K_STATE_ON)
2092 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002093 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094}
2095
2096/***************/
2097/* TX handlers */
2098/***************/
2099
Michal Kazior42c3aa62013-10-02 11:03:38 +02002100static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2101{
2102 if (ieee80211_is_mgmt(hdr->frame_control))
2103 return HTT_DATA_TX_EXT_TID_MGMT;
2104
2105 if (!ieee80211_is_data_qos(hdr->frame_control))
2106 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2107
2108 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2109 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2110
2111 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2112}
2113
Michal Kazior2b37c292014-09-02 11:00:22 +03002114static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002115{
Michal Kazior2b37c292014-09-02 11:00:22 +03002116 if (vif)
2117 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002118
Michal Kazior1bbc0972014-04-08 09:45:47 +03002119 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002120 return ar->monitor_vdev_id;
2121
Michal Kazior7aa7a722014-08-25 12:09:38 +02002122 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002123 return 0;
2124}
2125
Michal Kazior4b604552014-07-21 21:03:09 +03002126/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2127 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128 */
Michal Kazior4b604552014-07-21 21:03:09 +03002129static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130{
2131 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002132 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 u8 *qos_ctl;
2134
2135 if (!ieee80211_is_data_qos(hdr->frame_control))
2136 return;
2137
2138 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002139 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2140 skb->data, (void *)qos_ctl - (void *)skb->data);
2141 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002142
2143 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2144 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2145 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2146 * it is safe to downgrade to NullFunc.
2147 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002148 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002149 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2150 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2151 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2152 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153}
2154
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002155static void ath10k_tx_wep_key_work(struct work_struct *work)
2156{
2157 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2158 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02002159 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002160 int ret, keyidx = arvif->def_wep_key_newidx;
2161
Michal Kazior911e6c02014-05-26 12:46:03 +03002162 mutex_lock(&arvif->ar->conf_mutex);
2163
2164 if (arvif->ar->state != ATH10K_STATE_ON)
2165 goto unlock;
2166
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002167 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03002168 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002169
Michal Kazior7aa7a722014-08-25 12:09:38 +02002170 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002171 arvif->vdev_id, keyidx);
2172
2173 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2174 arvif->vdev_id,
2175 arvif->ar->wmi.vdev_param->def_keyid,
2176 keyidx);
2177 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002178 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002179 arvif->vdev_id,
2180 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03002181 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002182 }
2183
2184 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03002185
2186unlock:
2187 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002188}
2189
Michal Kazior4b604552014-07-21 21:03:09 +03002190static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2191 struct ieee80211_key_conf *key,
2192 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002194 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2195 struct ath10k *ar = arvif->ar;
2196 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198 if (!ieee80211_has_protected(hdr->frame_control))
2199 return;
2200
2201 if (!key)
2202 return;
2203
2204 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2205 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2206 return;
2207
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002208 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 return;
2210
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002211 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2212 * queueing frames until key index is updated is not an option because
2213 * sk_buff may need more processing to be done, e.g. offchannel */
2214 arvif->def_wep_key_newidx = key->keyidx;
2215 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216}
2217
Michal Kazior4b604552014-07-21 21:03:09 +03002218static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2219 struct ieee80211_vif *vif,
2220 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002221{
2222 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2224
2225 /* This is case only for P2P_GO */
2226 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2227 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2228 return;
2229
2230 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2231 spin_lock_bh(&ar->data_lock);
2232 if (arvif->u.ap.noa_data)
2233 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2234 GFP_ATOMIC))
2235 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2236 arvif->u.ap.noa_data,
2237 arvif->u.ap.noa_len);
2238 spin_unlock_bh(&ar->data_lock);
2239 }
2240}
2241
Michal Kazior8d6d3622014-11-24 14:58:31 +01002242static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2243{
2244 /* FIXME: Not really sure since when the behaviour changed. At some
2245 * point new firmware stopped requiring creation of peer entries for
2246 * offchannel tx (and actually creating them causes issues with wmi-htc
2247 * tx credit replenishment and reliability). Assuming it's at least 3.4
2248 * because that's when the `freq` was introduced to TX_FRM HTT command.
2249 */
2250 return !(ar->htt.target_version_major >= 3 &&
2251 ar->htt.target_version_minor >= 4);
2252}
2253
Kalle Valo5e3dd152013-06-12 20:52:10 +03002254static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2255{
2256 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002257 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002258
Michal Kazior961d4c32013-08-09 10:13:34 +02002259 if (ar->htt.target_version_major >= 3) {
2260 /* Since HTT 3.0 there is no separate mgmt tx command */
2261 ret = ath10k_htt_tx(&ar->htt, skb);
2262 goto exit;
2263 }
2264
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002265 if (ieee80211_is_mgmt(hdr->frame_control)) {
2266 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2267 ar->fw_features)) {
2268 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2269 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002270 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002271 ret = -EBUSY;
2272 goto exit;
2273 }
2274
2275 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2276 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2277 } else {
2278 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2279 }
2280 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2281 ar->fw_features) &&
2282 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 /* FW does not report tx status properly for NullFunc frames
2284 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002285 * those frames when it detects link/beacon loss and depends
2286 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002287 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002288 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002289 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002290 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291
Michal Kazior961d4c32013-08-09 10:13:34 +02002292exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002293 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002294 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2295 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002296 ieee80211_free_txskb(ar->hw, skb);
2297 }
2298}
2299
2300void ath10k_offchan_tx_purge(struct ath10k *ar)
2301{
2302 struct sk_buff *skb;
2303
2304 for (;;) {
2305 skb = skb_dequeue(&ar->offchan_tx_queue);
2306 if (!skb)
2307 break;
2308
2309 ieee80211_free_txskb(ar->hw, skb);
2310 }
2311}
2312
2313void ath10k_offchan_tx_work(struct work_struct *work)
2314{
2315 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2316 struct ath10k_peer *peer;
2317 struct ieee80211_hdr *hdr;
2318 struct sk_buff *skb;
2319 const u8 *peer_addr;
2320 int vdev_id;
2321 int ret;
2322
2323 /* FW requirement: We must create a peer before FW will send out
2324 * an offchannel frame. Otherwise the frame will be stuck and
2325 * never transmitted. We delete the peer upon tx completion.
2326 * It is unlikely that a peer for offchannel tx will already be
2327 * present. However it may be in some rare cases so account for that.
2328 * Otherwise we might remove a legitimate peer and break stuff. */
2329
2330 for (;;) {
2331 skb = skb_dequeue(&ar->offchan_tx_queue);
2332 if (!skb)
2333 break;
2334
2335 mutex_lock(&ar->conf_mutex);
2336
Michal Kazior7aa7a722014-08-25 12:09:38 +02002337 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338 skb);
2339
2340 hdr = (struct ieee80211_hdr *)skb->data;
2341 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002342 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343
2344 spin_lock_bh(&ar->data_lock);
2345 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2346 spin_unlock_bh(&ar->data_lock);
2347
2348 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002349 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002350 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002351 peer_addr, vdev_id);
2352
2353 if (!peer) {
2354 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2355 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002356 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 peer_addr, vdev_id, ret);
2358 }
2359
2360 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002361 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362 ar->offchan_tx_skb = skb;
2363 spin_unlock_bh(&ar->data_lock);
2364
2365 ath10k_tx_htt(ar, skb);
2366
2367 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2368 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002369 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002370 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002371 skb);
2372
2373 if (!peer) {
2374 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2375 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002376 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002377 peer_addr, vdev_id, ret);
2378 }
2379
2380 mutex_unlock(&ar->conf_mutex);
2381 }
2382}
2383
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002384void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2385{
2386 struct sk_buff *skb;
2387
2388 for (;;) {
2389 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2390 if (!skb)
2391 break;
2392
2393 ieee80211_free_txskb(ar->hw, skb);
2394 }
2395}
2396
2397void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2398{
2399 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2400 struct sk_buff *skb;
2401 int ret;
2402
2403 for (;;) {
2404 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2405 if (!skb)
2406 break;
2407
2408 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002409 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002410 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002411 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002412 ieee80211_free_txskb(ar->hw, skb);
2413 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002414 }
2415}
2416
Kalle Valo5e3dd152013-06-12 20:52:10 +03002417/************/
2418/* Scanning */
2419/************/
2420
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002421void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002422{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002423 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002424
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002425 switch (ar->scan.state) {
2426 case ATH10K_SCAN_IDLE:
2427 break;
2428 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002429 if (ar->scan.is_roc)
2430 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002431 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002432 case ATH10K_SCAN_ABORTING:
2433 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002434 ieee80211_scan_completed(ar->hw,
2435 (ar->scan.state ==
2436 ATH10K_SCAN_ABORTING));
2437 /* fall through */
2438 case ATH10K_SCAN_STARTING:
2439 ar->scan.state = ATH10K_SCAN_IDLE;
2440 ar->scan_channel = NULL;
2441 ath10k_offchan_tx_purge(ar);
2442 cancel_delayed_work(&ar->scan.timeout);
2443 complete_all(&ar->scan.completed);
2444 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002446}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002447
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002448void ath10k_scan_finish(struct ath10k *ar)
2449{
2450 spin_lock_bh(&ar->data_lock);
2451 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002452 spin_unlock_bh(&ar->data_lock);
2453}
2454
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002455static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456{
2457 struct wmi_stop_scan_arg arg = {
2458 .req_id = 1, /* FIXME */
2459 .req_type = WMI_SCAN_STOP_ONE,
2460 .u.scan_id = ATH10K_SCAN_ID,
2461 };
2462 int ret;
2463
2464 lockdep_assert_held(&ar->conf_mutex);
2465
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466 ret = ath10k_wmi_stop_scan(ar, &arg);
2467 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002468 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002469 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002470 }
2471
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002473 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002474 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002476 } else if (ret > 0) {
2477 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002478 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002479
2480out:
2481 /* Scan state should be updated upon scan completion but in case
2482 * firmware fails to deliver the event (for whatever reason) it is
2483 * desired to clean up scan state anyway. Firmware may have just
2484 * dropped the scan completion event delivery due to transport pipe
2485 * being overflown with data and/or it can recover on its own before
2486 * next scan request is submitted.
2487 */
2488 spin_lock_bh(&ar->data_lock);
2489 if (ar->scan.state != ATH10K_SCAN_IDLE)
2490 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002491 spin_unlock_bh(&ar->data_lock);
2492
2493 return ret;
2494}
2495
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002496static void ath10k_scan_abort(struct ath10k *ar)
2497{
2498 int ret;
2499
2500 lockdep_assert_held(&ar->conf_mutex);
2501
2502 spin_lock_bh(&ar->data_lock);
2503
2504 switch (ar->scan.state) {
2505 case ATH10K_SCAN_IDLE:
2506 /* This can happen if timeout worker kicked in and called
2507 * abortion while scan completion was being processed.
2508 */
2509 break;
2510 case ATH10K_SCAN_STARTING:
2511 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002512 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002513 ath10k_scan_state_str(ar->scan.state),
2514 ar->scan.state);
2515 break;
2516 case ATH10K_SCAN_RUNNING:
2517 ar->scan.state = ATH10K_SCAN_ABORTING;
2518 spin_unlock_bh(&ar->data_lock);
2519
2520 ret = ath10k_scan_stop(ar);
2521 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002522 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002523
2524 spin_lock_bh(&ar->data_lock);
2525 break;
2526 }
2527
2528 spin_unlock_bh(&ar->data_lock);
2529}
2530
2531void ath10k_scan_timeout_work(struct work_struct *work)
2532{
2533 struct ath10k *ar = container_of(work, struct ath10k,
2534 scan.timeout.work);
2535
2536 mutex_lock(&ar->conf_mutex);
2537 ath10k_scan_abort(ar);
2538 mutex_unlock(&ar->conf_mutex);
2539}
2540
Kalle Valo5e3dd152013-06-12 20:52:10 +03002541static int ath10k_start_scan(struct ath10k *ar,
2542 const struct wmi_start_scan_arg *arg)
2543{
2544 int ret;
2545
2546 lockdep_assert_held(&ar->conf_mutex);
2547
2548 ret = ath10k_wmi_start_scan(ar, arg);
2549 if (ret)
2550 return ret;
2551
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2553 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002554 ret = ath10k_scan_stop(ar);
2555 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002556 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002557
2558 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002559 }
2560
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002561 /* Add a 200ms margin to account for event/command processing */
2562 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2563 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002564 return 0;
2565}
2566
2567/**********************/
2568/* mac80211 callbacks */
2569/**********************/
2570
2571static void ath10k_tx(struct ieee80211_hw *hw,
2572 struct ieee80211_tx_control *control,
2573 struct sk_buff *skb)
2574{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002576 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2577 struct ieee80211_vif *vif = info->control.vif;
2578 struct ieee80211_key_conf *key = info->control.hw_key;
2579 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580
2581 /* We should disable CCK RATE due to P2P */
2582 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002583 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584
Michal Kazior4b604552014-07-21 21:03:09 +03002585 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2586 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002587 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002589 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002590 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2591 ath10k_tx_h_nwifi(hw, skb);
2592 ath10k_tx_h_update_wep_key(vif, key, skb);
2593 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2594 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002595 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002596
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2598 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002599 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002600 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601 spin_unlock_bh(&ar->data_lock);
2602
Michal Kazior8d6d3622014-11-24 14:58:31 +01002603 if (ath10k_mac_need_offchan_tx_work(ar)) {
2604 ATH10K_SKB_CB(skb)->htt.freq = 0;
2605 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002606
Michal Kazior8d6d3622014-11-24 14:58:31 +01002607 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2608 skb);
2609
2610 skb_queue_tail(&ar->offchan_tx_queue, skb);
2611 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2612 return;
2613 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002614 }
2615
2616 ath10k_tx_htt(ar, skb);
2617}
2618
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002619/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002620void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002621{
2622 /* make sure rcu-protected mac80211 tx path itself is drained */
2623 synchronize_net();
2624
2625 ath10k_offchan_tx_purge(ar);
2626 ath10k_mgmt_over_wmi_tx_purge(ar);
2627
2628 cancel_work_sync(&ar->offchan_tx_work);
2629 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2630}
2631
Michal Kazioraffd3212013-07-16 09:54:35 +02002632void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002633{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002634 struct ath10k_vif *arvif;
2635
Michal Kazior818bdd12013-07-16 09:38:57 +02002636 lockdep_assert_held(&ar->conf_mutex);
2637
Michal Kazior19337472014-08-28 12:58:16 +02002638 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2639 ar->filter_flags = 0;
2640 ar->monitor = false;
2641
2642 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002643 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002644
2645 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002646
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002647 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002648 ath10k_peer_cleanup_all(ar);
2649 ath10k_core_stop(ar);
2650 ath10k_hif_power_down(ar);
2651
2652 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002653 list_for_each_entry(arvif, &ar->arvifs, list)
2654 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002655 spin_unlock_bh(&ar->data_lock);
2656}
2657
Ben Greear46acf7bb2014-05-16 17:15:38 +03002658static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2659{
2660 struct ath10k *ar = hw->priv;
2661
2662 mutex_lock(&ar->conf_mutex);
2663
2664 if (ar->cfg_tx_chainmask) {
2665 *tx_ant = ar->cfg_tx_chainmask;
2666 *rx_ant = ar->cfg_rx_chainmask;
2667 } else {
2668 *tx_ant = ar->supp_tx_chainmask;
2669 *rx_ant = ar->supp_rx_chainmask;
2670 }
2671
2672 mutex_unlock(&ar->conf_mutex);
2673
2674 return 0;
2675}
2676
Ben Greear5572a952014-11-24 16:22:10 +02002677static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2678{
2679 /* It is not clear that allowing gaps in chainmask
2680 * is helpful. Probably it will not do what user
2681 * is hoping for, so warn in that case.
2682 */
2683 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2684 return;
2685
2686 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2687 dbg, cm);
2688}
2689
Ben Greear46acf7bb2014-05-16 17:15:38 +03002690static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2691{
2692 int ret;
2693
2694 lockdep_assert_held(&ar->conf_mutex);
2695
Ben Greear5572a952014-11-24 16:22:10 +02002696 ath10k_check_chain_mask(ar, tx_ant, "tx");
2697 ath10k_check_chain_mask(ar, rx_ant, "rx");
2698
Ben Greear46acf7bb2014-05-16 17:15:38 +03002699 ar->cfg_tx_chainmask = tx_ant;
2700 ar->cfg_rx_chainmask = rx_ant;
2701
2702 if ((ar->state != ATH10K_STATE_ON) &&
2703 (ar->state != ATH10K_STATE_RESTARTED))
2704 return 0;
2705
2706 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2707 tx_ant);
2708 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002710 ret, tx_ant);
2711 return ret;
2712 }
2713
2714 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2715 rx_ant);
2716 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002717 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002718 ret, rx_ant);
2719 return ret;
2720 }
2721
2722 return 0;
2723}
2724
2725static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2726{
2727 struct ath10k *ar = hw->priv;
2728 int ret;
2729
2730 mutex_lock(&ar->conf_mutex);
2731 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2732 mutex_unlock(&ar->conf_mutex);
2733 return ret;
2734}
2735
Kalle Valo5e3dd152013-06-12 20:52:10 +03002736static int ath10k_start(struct ieee80211_hw *hw)
2737{
2738 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002739 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002740
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002741 /*
2742 * This makes sense only when restarting hw. It is harmless to call
2743 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2744 * commands will be submitted while restarting.
2745 */
2746 ath10k_drain_tx(ar);
2747
Michal Kazior548db542013-07-05 16:15:15 +03002748 mutex_lock(&ar->conf_mutex);
2749
Michal Kaziorc5058f52014-05-26 12:46:03 +03002750 switch (ar->state) {
2751 case ATH10K_STATE_OFF:
2752 ar->state = ATH10K_STATE_ON;
2753 break;
2754 case ATH10K_STATE_RESTARTING:
2755 ath10k_halt(ar);
2756 ar->state = ATH10K_STATE_RESTARTED;
2757 break;
2758 case ATH10K_STATE_ON:
2759 case ATH10K_STATE_RESTARTED:
2760 case ATH10K_STATE_WEDGED:
2761 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002762 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002763 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002764 case ATH10K_STATE_UTF:
2765 ret = -EBUSY;
2766 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002767 }
2768
2769 ret = ath10k_hif_power_up(ar);
2770 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002771 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002772 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002773 }
2774
Kalle Valo43d2a302014-09-10 18:23:30 +03002775 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002776 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002777 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002778 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002779 }
2780
Bartosz Markowski226a3392013-09-26 17:47:16 +02002781 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002782 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002783 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002784 goto err_core_stop;
2785 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002786
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002787 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002788 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002789 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002790 goto err_core_stop;
2791 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792
Ben Greear46acf7bb2014-05-16 17:15:38 +03002793 if (ar->cfg_tx_chainmask)
2794 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2795 ar->cfg_rx_chainmask);
2796
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002797 /*
2798 * By default FW set ARP frames ac to voice (6). In that case ARP
2799 * exchange is not working properly for UAPSD enabled AP. ARP requests
2800 * which arrives with access category 0 are processed by network stack
2801 * and send back with access category 0, but FW changes access category
2802 * to 6. Set ARP frames access category to best effort (0) solves
2803 * this problem.
2804 */
2805
2806 ret = ath10k_wmi_pdev_set_param(ar,
2807 ar->wmi.pdev_param->arp_ac_override, 0);
2808 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002809 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002810 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002811 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002812 }
2813
Michal Kaziord6500972014-04-08 09:56:09 +03002814 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002815 ath10k_regd_update(ar);
2816
Simon Wunderlich855aed12014-08-02 09:12:54 +03002817 ath10k_spectral_start(ar);
2818
Michal Kaziorae254432014-05-26 12:46:02 +03002819 mutex_unlock(&ar->conf_mutex);
2820 return 0;
2821
2822err_core_stop:
2823 ath10k_core_stop(ar);
2824
2825err_power_down:
2826 ath10k_hif_power_down(ar);
2827
2828err_off:
2829 ar->state = ATH10K_STATE_OFF;
2830
2831err:
Michal Kazior548db542013-07-05 16:15:15 +03002832 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002833 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002834}
2835
2836static void ath10k_stop(struct ieee80211_hw *hw)
2837{
2838 struct ath10k *ar = hw->priv;
2839
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002840 ath10k_drain_tx(ar);
2841
Michal Kazior548db542013-07-05 16:15:15 +03002842 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002843 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002844 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002845 ar->state = ATH10K_STATE_OFF;
2846 }
Michal Kazior548db542013-07-05 16:15:15 +03002847 mutex_unlock(&ar->conf_mutex);
2848
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002849 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002850 cancel_work_sync(&ar->restart_work);
2851}
2852
Michal Kaziorad088bf2013-10-16 15:44:46 +03002853static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002854{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002855 struct ath10k_vif *arvif;
2856 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002857
2858 lockdep_assert_held(&ar->conf_mutex);
2859
Michal Kaziorad088bf2013-10-16 15:44:46 +03002860 list_for_each_entry(arvif, &ar->arvifs, list) {
2861 ret = ath10k_mac_vif_setup_ps(arvif);
2862 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002863 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002864 break;
2865 }
2866 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002867
Michal Kaziorad088bf2013-10-16 15:44:46 +03002868 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869}
2870
Michal Kaziorc930f742014-01-23 11:38:25 +01002871static const char *chandef_get_width(enum nl80211_chan_width width)
2872{
2873 switch (width) {
2874 case NL80211_CHAN_WIDTH_20_NOHT:
2875 return "20 (noht)";
2876 case NL80211_CHAN_WIDTH_20:
2877 return "20";
2878 case NL80211_CHAN_WIDTH_40:
2879 return "40";
2880 case NL80211_CHAN_WIDTH_80:
2881 return "80";
2882 case NL80211_CHAN_WIDTH_80P80:
2883 return "80+80";
2884 case NL80211_CHAN_WIDTH_160:
2885 return "160";
2886 case NL80211_CHAN_WIDTH_5:
2887 return "5";
2888 case NL80211_CHAN_WIDTH_10:
2889 return "10";
2890 }
2891 return "?";
2892}
2893
2894static void ath10k_config_chan(struct ath10k *ar)
2895{
2896 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002897 int ret;
2898
2899 lockdep_assert_held(&ar->conf_mutex);
2900
Michal Kazior7aa7a722014-08-25 12:09:38 +02002901 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002902 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2903 ar->chandef.chan->center_freq,
2904 ar->chandef.center_freq1,
2905 ar->chandef.center_freq2,
2906 chandef_get_width(ar->chandef.width));
2907
2908 /* First stop monitor interface. Some FW versions crash if there's a
2909 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002910 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002911 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002912
2913 list_for_each_entry(arvif, &ar->arvifs, list) {
2914 if (!arvif->is_started)
2915 continue;
2916
Michal Kaziordc55e302014-07-29 12:53:36 +03002917 if (!arvif->is_up)
2918 continue;
2919
Michal Kaziorc930f742014-01-23 11:38:25 +01002920 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2921 continue;
2922
Michal Kaziordc55e302014-07-29 12:53:36 +03002923 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002924 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002925 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002926 arvif->vdev_id, ret);
2927 continue;
2928 }
2929 }
2930
Michal Kaziordc55e302014-07-29 12:53:36 +03002931 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002932
2933 list_for_each_entry(arvif, &ar->arvifs, list) {
2934 if (!arvif->is_started)
2935 continue;
2936
2937 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2938 continue;
2939
Michal Kaziordc55e302014-07-29 12:53:36 +03002940 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002941 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002942 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002943 arvif->vdev_id, ret);
2944 continue;
2945 }
2946
2947 if (!arvif->is_up)
2948 continue;
2949
2950 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2951 arvif->bssid);
2952 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002953 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002954 arvif->vdev_id, ret);
2955 continue;
2956 }
2957 }
2958
Michal Kazior19337472014-08-28 12:58:16 +02002959 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002960}
2961
Michal Kazior7d9d5582014-10-21 10:40:15 +03002962static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2963{
2964 int ret;
2965 u32 param;
2966
2967 lockdep_assert_held(&ar->conf_mutex);
2968
2969 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2970
2971 param = ar->wmi.pdev_param->txpower_limit2g;
2972 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2973 if (ret) {
2974 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2975 txpower, ret);
2976 return ret;
2977 }
2978
2979 param = ar->wmi.pdev_param->txpower_limit5g;
2980 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2981 if (ret) {
2982 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2983 txpower, ret);
2984 return ret;
2985 }
2986
2987 return 0;
2988}
2989
2990static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2991{
2992 struct ath10k_vif *arvif;
2993 int ret, txpower = -1;
2994
2995 lockdep_assert_held(&ar->conf_mutex);
2996
2997 list_for_each_entry(arvif, &ar->arvifs, list) {
2998 WARN_ON(arvif->txpower < 0);
2999
3000 if (txpower == -1)
3001 txpower = arvif->txpower;
3002 else
3003 txpower = min(txpower, arvif->txpower);
3004 }
3005
3006 if (WARN_ON(txpower == -1))
3007 return -EINVAL;
3008
3009 ret = ath10k_mac_txpower_setup(ar, txpower);
3010 if (ret) {
3011 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3012 txpower, ret);
3013 return ret;
3014 }
3015
3016 return 0;
3017}
3018
Kalle Valo5e3dd152013-06-12 20:52:10 +03003019static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3020{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003021 struct ath10k *ar = hw->priv;
3022 struct ieee80211_conf *conf = &hw->conf;
3023 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003024
3025 mutex_lock(&ar->conf_mutex);
3026
3027 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003028 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003029 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003030 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003031 conf->chandef.chan->flags,
3032 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003033
Kalle Valo5e3dd152013-06-12 20:52:10 +03003034 spin_lock_bh(&ar->data_lock);
3035 ar->rx_channel = conf->chandef.chan;
3036 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003037
Michal Kaziord6500972014-04-08 09:56:09 +03003038 ar->radar_enabled = conf->radar_enabled;
3039 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003040
3041 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3042 ar->chandef = conf->chandef;
3043 ath10k_config_chan(ar);
3044 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045 }
3046
Michal Kazioraffd3212013-07-16 09:54:35 +02003047 if (changed & IEEE80211_CONF_CHANGE_PS)
3048 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003049
3050 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003051 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3052 ret = ath10k_monitor_recalc(ar);
3053 if (ret)
3054 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003055 }
3056
3057 mutex_unlock(&ar->conf_mutex);
3058 return ret;
3059}
3060
Ben Greear5572a952014-11-24 16:22:10 +02003061static u32 get_nss_from_chainmask(u16 chain_mask)
3062{
3063 if ((chain_mask & 0x15) == 0x15)
3064 return 4;
3065 else if ((chain_mask & 0x7) == 0x7)
3066 return 3;
3067 else if ((chain_mask & 0x3) == 0x3)
3068 return 2;
3069 return 1;
3070}
3071
Kalle Valo5e3dd152013-06-12 20:52:10 +03003072/*
3073 * TODO:
3074 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3075 * because we will send mgmt frames without CCK. This requirement
3076 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3077 * in the TX packet.
3078 */
3079static int ath10k_add_interface(struct ieee80211_hw *hw,
3080 struct ieee80211_vif *vif)
3081{
3082 struct ath10k *ar = hw->priv;
3083 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3084 enum wmi_sta_powersave_param param;
3085 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003086 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003087 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003088 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089
3090 mutex_lock(&ar->conf_mutex);
3091
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003092 memset(arvif, 0, sizeof(*arvif));
3093
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094 arvif->ar = ar;
3095 arvif->vif = vif;
3096
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003097 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07003098 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003099
Ben Greeara9aefb32014-08-12 11:02:19 +03003100 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003101 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003102 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003103 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003104 }
Ben Greear16c11172014-09-23 14:17:16 -07003105 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003106
Ben Greear16c11172014-09-23 14:17:16 -07003107 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3108 bit, ar->free_vdev_map);
3109
3110 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003111 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003112
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003114 case NL80211_IFTYPE_P2P_DEVICE:
3115 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3116 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3117 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003118 case NL80211_IFTYPE_UNSPECIFIED:
3119 case NL80211_IFTYPE_STATION:
3120 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3121 if (vif->p2p)
3122 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3123 break;
3124 case NL80211_IFTYPE_ADHOC:
3125 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3126 break;
3127 case NL80211_IFTYPE_AP:
3128 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3129
3130 if (vif->p2p)
3131 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3132 break;
3133 case NL80211_IFTYPE_MONITOR:
3134 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3135 break;
3136 default:
3137 WARN_ON(1);
3138 break;
3139 }
3140
Michal Kazior64badcb2014-09-18 11:18:02 +03003141 /* Some firmware revisions don't wait for beacon tx completion before
3142 * sending another SWBA event. This could lead to hardware using old
3143 * (freed) beacon data in some cases, e.g. tx credit starvation
3144 * combined with missed TBTT. This is very very rare.
3145 *
3146 * On non-IOMMU-enabled hosts this could be a possible security issue
3147 * because hw could beacon some random data on the air. On
3148 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3149 * device would crash.
3150 *
3151 * Since there are no beacon tx completions (implicit nor explicit)
3152 * propagated to host the only workaround for this is to allocate a
3153 * DMA-coherent buffer for a lifetime of a vif and use it for all
3154 * beacon tx commands. Worst case for this approach is some beacons may
3155 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3156 */
3157 if (vif->type == NL80211_IFTYPE_ADHOC ||
3158 vif->type == NL80211_IFTYPE_AP) {
3159 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3160 IEEE80211_MAX_FRAME_LEN,
3161 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303162 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003163 if (!arvif->beacon_buf) {
3164 ret = -ENOMEM;
3165 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3166 ret);
3167 goto err;
3168 }
3169 }
3170
3171 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3172 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3173 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003174
3175 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3176 arvif->vdev_subtype, vif->addr);
3177 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003178 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003179 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003180 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 }
3182
Ben Greear16c11172014-09-23 14:17:16 -07003183 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003184 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003185
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003186 vdev_param = ar->wmi.vdev_param->def_keyid;
3187 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003188 arvif->def_wep_key_idx);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003190 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003191 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003192 goto err_vdev_delete;
3193 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003194
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003195 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3196 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003198 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003199 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003200 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003201 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003202 goto err_vdev_delete;
3203 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003204
Ben Greear5572a952014-11-24 16:22:10 +02003205 if (ar->cfg_tx_chainmask) {
3206 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3207
3208 vdev_param = ar->wmi.vdev_param->nss;
3209 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3210 nss);
3211 if (ret) {
3212 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3213 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3214 ret);
3215 goto err_vdev_delete;
3216 }
3217 }
3218
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3220 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3221 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003222 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003223 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003224 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003226
Kalle Valo5a13e762014-01-20 11:01:46 +02003227 ret = ath10k_mac_set_kickout(arvif);
3228 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003229 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003230 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003231 goto err_peer_delete;
3232 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233 }
3234
3235 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3236 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3237 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3238 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3239 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003240 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003241 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003242 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003243 goto err_peer_delete;
3244 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003245
Michal Kazior9f9b5742014-12-12 12:41:36 +01003246 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003247 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003248 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003249 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003250 goto err_peer_delete;
3251 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003252
Michal Kazior9f9b5742014-12-12 12:41:36 +01003253 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003254 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003255 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003256 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003257 goto err_peer_delete;
3258 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259 }
3260
Michal Kazior424121c2013-07-22 14:13:31 +02003261 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003262 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003263 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003264 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003265 goto err_peer_delete;
3266 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003267
Michal Kazior424121c2013-07-22 14:13:31 +02003268 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003269 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003270 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003271 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003272 goto err_peer_delete;
3273 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003274
Michal Kazior7d9d5582014-10-21 10:40:15 +03003275 arvif->txpower = vif->bss_conf.txpower;
3276 ret = ath10k_mac_txpower_recalc(ar);
3277 if (ret) {
3278 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3279 goto err_peer_delete;
3280 }
3281
Kalle Valo5e3dd152013-06-12 20:52:10 +03003282 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003283 return 0;
3284
3285err_peer_delete:
3286 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3287 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3288
3289err_vdev_delete:
3290 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003291 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003292 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003293
3294err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003295 if (arvif->beacon_buf) {
3296 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3297 arvif->beacon_buf, arvif->beacon_paddr);
3298 arvif->beacon_buf = NULL;
3299 }
3300
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003301 mutex_unlock(&ar->conf_mutex);
3302
Kalle Valo5e3dd152013-06-12 20:52:10 +03003303 return ret;
3304}
3305
3306static void ath10k_remove_interface(struct ieee80211_hw *hw,
3307 struct ieee80211_vif *vif)
3308{
3309 struct ath10k *ar = hw->priv;
3310 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3311 int ret;
3312
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003313 cancel_work_sync(&arvif->wep_key_work);
3314
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303315 mutex_lock(&ar->conf_mutex);
3316
Michal Kaziored543882013-09-13 14:16:56 +02003317 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003318 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003319 spin_unlock_bh(&ar->data_lock);
3320
Simon Wunderlich855aed12014-08-02 09:12:54 +03003321 ret = ath10k_spectral_vif_stop(arvif);
3322 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003323 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003324 arvif->vdev_id, ret);
3325
Ben Greear16c11172014-09-23 14:17:16 -07003326 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003327 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003328
3329 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3330 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3331 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003332 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003333 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003334
3335 kfree(arvif->u.ap.noa_data);
3336 }
3337
Michal Kazior7aa7a722014-08-25 12:09:38 +02003338 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003339 arvif->vdev_id);
3340
Kalle Valo5e3dd152013-06-12 20:52:10 +03003341 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3342 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003343 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003344 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003345
Kalle Valo5e3dd152013-06-12 20:52:10 +03003346 ath10k_peer_cleanup(ar, arvif->vdev_id);
3347
3348 mutex_unlock(&ar->conf_mutex);
3349}
3350
3351/*
3352 * FIXME: Has to be verified.
3353 */
3354#define SUPPORTED_FILTERS \
3355 (FIF_PROMISC_IN_BSS | \
3356 FIF_ALLMULTI | \
3357 FIF_CONTROL | \
3358 FIF_PSPOLL | \
3359 FIF_OTHER_BSS | \
3360 FIF_BCN_PRBRESP_PROMISC | \
3361 FIF_PROBE_REQ | \
3362 FIF_FCSFAIL)
3363
3364static void ath10k_configure_filter(struct ieee80211_hw *hw,
3365 unsigned int changed_flags,
3366 unsigned int *total_flags,
3367 u64 multicast)
3368{
3369 struct ath10k *ar = hw->priv;
3370 int ret;
3371
3372 mutex_lock(&ar->conf_mutex);
3373
3374 changed_flags &= SUPPORTED_FILTERS;
3375 *total_flags &= SUPPORTED_FILTERS;
3376 ar->filter_flags = *total_flags;
3377
Michal Kazior19337472014-08-28 12:58:16 +02003378 ret = ath10k_monitor_recalc(ar);
3379 if (ret)
3380 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003381
3382 mutex_unlock(&ar->conf_mutex);
3383}
3384
3385static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3386 struct ieee80211_vif *vif,
3387 struct ieee80211_bss_conf *info,
3388 u32 changed)
3389{
3390 struct ath10k *ar = hw->priv;
3391 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3392 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003393 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003394
3395 mutex_lock(&ar->conf_mutex);
3396
3397 if (changed & BSS_CHANGED_IBSS)
3398 ath10k_control_ibss(arvif, info, vif->addr);
3399
3400 if (changed & BSS_CHANGED_BEACON_INT) {
3401 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003402 vdev_param = ar->wmi.vdev_param->beacon_interval;
3403 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003404 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003405 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003406 "mac vdev %d beacon_interval %d\n",
3407 arvif->vdev_id, arvif->beacon_interval);
3408
Kalle Valo5e3dd152013-06-12 20:52:10 +03003409 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003410 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003411 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003412 }
3413
3414 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003415 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003416 "vdev %d set beacon tx mode to staggered\n",
3417 arvif->vdev_id);
3418
Bartosz Markowski226a3392013-09-26 17:47:16 +02003419 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3420 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003421 WMI_BEACON_STAGGERED_MODE);
3422 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003423 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003424 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003425
3426 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3427 if (ret)
3428 ath10k_warn(ar, "failed to update beacon template: %d\n",
3429 ret);
3430 }
3431
3432 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3433 ret = ath10k_mac_setup_prb_tmpl(arvif);
3434 if (ret)
3435 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3436 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003437 }
3438
Michal Kaziorba2479f2015-01-24 12:14:51 +02003439 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003440 arvif->dtim_period = info->dtim_period;
3441
Michal Kazior7aa7a722014-08-25 12:09:38 +02003442 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003443 "mac vdev %d dtim_period %d\n",
3444 arvif->vdev_id, arvif->dtim_period);
3445
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003446 vdev_param = ar->wmi.vdev_param->dtim_period;
3447 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448 arvif->dtim_period);
3449 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003450 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003451 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452 }
3453
3454 if (changed & BSS_CHANGED_SSID &&
3455 vif->type == NL80211_IFTYPE_AP) {
3456 arvif->u.ap.ssid_len = info->ssid_len;
3457 if (info->ssid_len)
3458 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3459 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3460 }
3461
Michal Kazior077efc82014-10-21 10:10:29 +03003462 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3463 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003464
3465 if (changed & BSS_CHANGED_BEACON_ENABLED)
3466 ath10k_control_beaconing(arvif, info);
3467
3468 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003469 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003470 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003471 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003472
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003473 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003474 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003475 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003476 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003477 }
3478
3479 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003480 if (info->use_short_slot)
3481 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3482
3483 else
3484 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3485
Michal Kazior7aa7a722014-08-25 12:09:38 +02003486 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003487 arvif->vdev_id, slottime);
3488
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003489 vdev_param = ar->wmi.vdev_param->slot_time;
3490 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003491 slottime);
3492 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003493 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003494 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003495 }
3496
3497 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003498 if (info->use_short_preamble)
3499 preamble = WMI_VDEV_PREAMBLE_SHORT;
3500 else
3501 preamble = WMI_VDEV_PREAMBLE_LONG;
3502
Michal Kazior7aa7a722014-08-25 12:09:38 +02003503 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003504 "mac vdev %d preamble %dn",
3505 arvif->vdev_id, preamble);
3506
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003507 vdev_param = ar->wmi.vdev_param->preamble;
3508 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003509 preamble);
3510 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003511 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003512 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 }
3514
3515 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003516 if (info->assoc) {
3517 /* Workaround: Make sure monitor vdev is not running
3518 * when associating to prevent some firmware revisions
3519 * (e.g. 10.1 and 10.2) from crashing.
3520 */
3521 if (ar->monitor_started)
3522 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003523 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003524 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003525 } else {
3526 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003527 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003528 }
3529
Michal Kazior7d9d5582014-10-21 10:40:15 +03003530 if (changed & BSS_CHANGED_TXPOWER) {
3531 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3532 arvif->vdev_id, info->txpower);
3533
3534 arvif->txpower = info->txpower;
3535 ret = ath10k_mac_txpower_recalc(ar);
3536 if (ret)
3537 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3538 }
3539
Michal Kaziorbf14e652014-12-12 12:41:38 +01003540 if (changed & BSS_CHANGED_PS) {
3541 ret = ath10k_mac_vif_setup_ps(arvif);
3542 if (ret)
3543 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3544 arvif->vdev_id, ret);
3545 }
3546
Kalle Valo5e3dd152013-06-12 20:52:10 +03003547 mutex_unlock(&ar->conf_mutex);
3548}
3549
3550static int ath10k_hw_scan(struct ieee80211_hw *hw,
3551 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003552 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003553{
3554 struct ath10k *ar = hw->priv;
3555 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003556 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 struct wmi_start_scan_arg arg;
3558 int ret = 0;
3559 int i;
3560
3561 mutex_lock(&ar->conf_mutex);
3562
3563 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003564 switch (ar->scan.state) {
3565 case ATH10K_SCAN_IDLE:
3566 reinit_completion(&ar->scan.started);
3567 reinit_completion(&ar->scan.completed);
3568 ar->scan.state = ATH10K_SCAN_STARTING;
3569 ar->scan.is_roc = false;
3570 ar->scan.vdev_id = arvif->vdev_id;
3571 ret = 0;
3572 break;
3573 case ATH10K_SCAN_STARTING:
3574 case ATH10K_SCAN_RUNNING:
3575 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003577 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003578 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003579 spin_unlock_bh(&ar->data_lock);
3580
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003581 if (ret)
3582 goto exit;
3583
Kalle Valo5e3dd152013-06-12 20:52:10 +03003584 memset(&arg, 0, sizeof(arg));
3585 ath10k_wmi_start_scan_init(ar, &arg);
3586 arg.vdev_id = arvif->vdev_id;
3587 arg.scan_id = ATH10K_SCAN_ID;
3588
3589 if (!req->no_cck)
3590 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3591
3592 if (req->ie_len) {
3593 arg.ie_len = req->ie_len;
3594 memcpy(arg.ie, req->ie, arg.ie_len);
3595 }
3596
3597 if (req->n_ssids) {
3598 arg.n_ssids = req->n_ssids;
3599 for (i = 0; i < arg.n_ssids; i++) {
3600 arg.ssids[i].len = req->ssids[i].ssid_len;
3601 arg.ssids[i].ssid = req->ssids[i].ssid;
3602 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003603 } else {
3604 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 }
3606
3607 if (req->n_channels) {
3608 arg.n_channels = req->n_channels;
3609 for (i = 0; i < arg.n_channels; i++)
3610 arg.channels[i] = req->channels[i]->center_freq;
3611 }
3612
3613 ret = ath10k_start_scan(ar, &arg);
3614 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003615 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003616 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003617 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618 spin_unlock_bh(&ar->data_lock);
3619 }
3620
3621exit:
3622 mutex_unlock(&ar->conf_mutex);
3623 return ret;
3624}
3625
3626static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3627 struct ieee80211_vif *vif)
3628{
3629 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003630
3631 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003632 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003633 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003634
3635 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003636}
3637
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003638static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3639 struct ath10k_vif *arvif,
3640 enum set_key_cmd cmd,
3641 struct ieee80211_key_conf *key)
3642{
3643 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3644 int ret;
3645
3646 /* 10.1 firmware branch requires default key index to be set to group
3647 * key index after installing it. Otherwise FW/HW Txes corrupted
3648 * frames with multi-vif APs. This is not required for main firmware
3649 * branch (e.g. 636).
3650 *
3651 * FIXME: This has been tested only in AP. It remains unknown if this
3652 * is required for multi-vif STA interfaces on 10.1 */
3653
3654 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3655 return;
3656
3657 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3658 return;
3659
3660 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3661 return;
3662
3663 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3664 return;
3665
3666 if (cmd != SET_KEY)
3667 return;
3668
3669 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3670 key->keyidx);
3671 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003672 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003673 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003674}
3675
Kalle Valo5e3dd152013-06-12 20:52:10 +03003676static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3677 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3678 struct ieee80211_key_conf *key)
3679{
3680 struct ath10k *ar = hw->priv;
3681 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3682 struct ath10k_peer *peer;
3683 const u8 *peer_addr;
3684 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3685 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3686 int ret = 0;
3687
3688 if (key->keyidx > WMI_MAX_KEY_INDEX)
3689 return -ENOSPC;
3690
3691 mutex_lock(&ar->conf_mutex);
3692
3693 if (sta)
3694 peer_addr = sta->addr;
3695 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3696 peer_addr = vif->bss_conf.bssid;
3697 else
3698 peer_addr = vif->addr;
3699
3700 key->hw_key_idx = key->keyidx;
3701
3702 /* the peer should not disappear in mid-way (unless FW goes awry) since
3703 * we already hold conf_mutex. we just make sure its there now. */
3704 spin_lock_bh(&ar->data_lock);
3705 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3706 spin_unlock_bh(&ar->data_lock);
3707
3708 if (!peer) {
3709 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003710 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003711 peer_addr);
3712 ret = -EOPNOTSUPP;
3713 goto exit;
3714 } else {
3715 /* if the peer doesn't exist there is no key to disable
3716 * anymore */
3717 goto exit;
3718 }
3719 }
3720
3721 if (is_wep) {
3722 if (cmd == SET_KEY)
3723 arvif->wep_keys[key->keyidx] = key;
3724 else
3725 arvif->wep_keys[key->keyidx] = NULL;
3726
3727 if (cmd == DISABLE_KEY)
3728 ath10k_clear_vdev_key(arvif, key);
3729 }
3730
3731 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3732 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003733 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003734 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735 goto exit;
3736 }
3737
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003738 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3739
Kalle Valo5e3dd152013-06-12 20:52:10 +03003740 spin_lock_bh(&ar->data_lock);
3741 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3742 if (peer && cmd == SET_KEY)
3743 peer->keys[key->keyidx] = key;
3744 else if (peer && cmd == DISABLE_KEY)
3745 peer->keys[key->keyidx] = NULL;
3746 else if (peer == NULL)
3747 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003748 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003749 spin_unlock_bh(&ar->data_lock);
3750
3751exit:
3752 mutex_unlock(&ar->conf_mutex);
3753 return ret;
3754}
3755
Michal Kazior9797feb2014-02-14 14:49:48 +01003756static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3757{
3758 struct ath10k *ar;
3759 struct ath10k_vif *arvif;
3760 struct ath10k_sta *arsta;
3761 struct ieee80211_sta *sta;
3762 u32 changed, bw, nss, smps;
3763 int err;
3764
3765 arsta = container_of(wk, struct ath10k_sta, update_wk);
3766 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3767 arvif = arsta->arvif;
3768 ar = arvif->ar;
3769
3770 spin_lock_bh(&ar->data_lock);
3771
3772 changed = arsta->changed;
3773 arsta->changed = 0;
3774
3775 bw = arsta->bw;
3776 nss = arsta->nss;
3777 smps = arsta->smps;
3778
3779 spin_unlock_bh(&ar->data_lock);
3780
3781 mutex_lock(&ar->conf_mutex);
3782
3783 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003784 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003785 sta->addr, bw);
3786
3787 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3788 WMI_PEER_CHAN_WIDTH, bw);
3789 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003790 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003791 sta->addr, bw, err);
3792 }
3793
3794 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003795 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003796 sta->addr, nss);
3797
3798 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3799 WMI_PEER_NSS, nss);
3800 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003801 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003802 sta->addr, nss, err);
3803 }
3804
3805 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003807 sta->addr, smps);
3808
3809 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3810 WMI_PEER_SMPS_STATE, smps);
3811 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003812 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003813 sta->addr, smps, err);
3814 }
3815
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003816 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3817 changed & IEEE80211_RC_NSS_CHANGED) {
3818 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003819 sta->addr);
3820
Michal Kazior590922a2014-10-21 10:10:29 +03003821 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003822 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003824 sta->addr);
3825 }
3826
Michal Kazior9797feb2014-02-14 14:49:48 +01003827 mutex_unlock(&ar->conf_mutex);
3828}
3829
Michal Kaziorcfd10612014-11-25 15:16:05 +01003830static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3831{
3832 struct ath10k *ar = arvif->ar;
3833
3834 lockdep_assert_held(&ar->conf_mutex);
3835
3836 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3837 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3838 return 0;
3839
3840 if (ar->num_stations >= ar->max_num_stations)
3841 return -ENOBUFS;
3842
3843 ar->num_stations++;
3844
3845 return 0;
3846}
3847
3848static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3849{
3850 struct ath10k *ar = arvif->ar;
3851
3852 lockdep_assert_held(&ar->conf_mutex);
3853
3854 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3855 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3856 return;
3857
3858 ar->num_stations--;
3859}
3860
Kalle Valo5e3dd152013-06-12 20:52:10 +03003861static int ath10k_sta_state(struct ieee80211_hw *hw,
3862 struct ieee80211_vif *vif,
3863 struct ieee80211_sta *sta,
3864 enum ieee80211_sta_state old_state,
3865 enum ieee80211_sta_state new_state)
3866{
3867 struct ath10k *ar = hw->priv;
3868 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003869 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003870 int ret = 0;
3871
Michal Kazior76f90022014-02-25 09:29:57 +02003872 if (old_state == IEEE80211_STA_NOTEXIST &&
3873 new_state == IEEE80211_STA_NONE) {
3874 memset(arsta, 0, sizeof(*arsta));
3875 arsta->arvif = arvif;
3876 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3877 }
3878
Michal Kazior9797feb2014-02-14 14:49:48 +01003879 /* cancel must be done outside the mutex to avoid deadlock */
3880 if ((old_state == IEEE80211_STA_NONE &&
3881 new_state == IEEE80211_STA_NOTEXIST))
3882 cancel_work_sync(&arsta->update_wk);
3883
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884 mutex_lock(&ar->conf_mutex);
3885
3886 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003887 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003888 /*
3889 * New station addition.
3890 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003891 ath10k_dbg(ar, ATH10K_DBG_MAC,
3892 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3893 arvif->vdev_id, sta->addr,
3894 ar->num_stations + 1, ar->max_num_stations,
3895 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003896
Michal Kaziorcfd10612014-11-25 15:16:05 +01003897 ret = ath10k_mac_inc_num_stations(arvif);
3898 if (ret) {
3899 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3900 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003901 goto exit;
3902 }
3903
Kalle Valo5e3dd152013-06-12 20:52:10 +03003904 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003905 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003906 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003907 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003908 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003909 goto exit;
3910 }
Michal Kazior077efc82014-10-21 10:10:29 +03003911
3912 if (vif->type == NL80211_IFTYPE_STATION) {
3913 WARN_ON(arvif->is_started);
3914
3915 ret = ath10k_vdev_start(arvif);
3916 if (ret) {
3917 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3918 arvif->vdev_id, ret);
3919 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3920 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003921 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003922 goto exit;
3923 }
3924
3925 arvif->is_started = true;
3926 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927 } else if ((old_state == IEEE80211_STA_NONE &&
3928 new_state == IEEE80211_STA_NOTEXIST)) {
3929 /*
3930 * Existing station deletion.
3931 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003932 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003933 "mac vdev %d peer delete %pM (sta gone)\n",
3934 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003935
3936 if (vif->type == NL80211_IFTYPE_STATION) {
3937 WARN_ON(!arvif->is_started);
3938
3939 ret = ath10k_vdev_stop(arvif);
3940 if (ret)
3941 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3942 arvif->vdev_id, ret);
3943
3944 arvif->is_started = false;
3945 }
3946
Kalle Valo5e3dd152013-06-12 20:52:10 +03003947 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3948 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003949 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003950 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003951
Michal Kaziorcfd10612014-11-25 15:16:05 +01003952 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003953 } else if (old_state == IEEE80211_STA_AUTH &&
3954 new_state == IEEE80211_STA_ASSOC &&
3955 (vif->type == NL80211_IFTYPE_AP ||
3956 vif->type == NL80211_IFTYPE_ADHOC)) {
3957 /*
3958 * New association.
3959 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003961 sta->addr);
3962
Michal Kazior590922a2014-10-21 10:10:29 +03003963 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003964 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003965 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003966 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003967 } else if (old_state == IEEE80211_STA_ASSOC &&
3968 new_state == IEEE80211_STA_AUTH &&
3969 (vif->type == NL80211_IFTYPE_AP ||
3970 vif->type == NL80211_IFTYPE_ADHOC)) {
3971 /*
3972 * Disassociation.
3973 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003974 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003975 sta->addr);
3976
Michal Kazior590922a2014-10-21 10:10:29 +03003977 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003979 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003980 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003981 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003982exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003983 mutex_unlock(&ar->conf_mutex);
3984 return ret;
3985}
3986
3987static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003988 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003989{
3990 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02003991 struct wmi_sta_uapsd_auto_trig_arg arg = {};
3992 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003993 u32 value = 0;
3994 int ret = 0;
3995
Michal Kazior548db542013-07-05 16:15:15 +03003996 lockdep_assert_held(&ar->conf_mutex);
3997
Kalle Valo5e3dd152013-06-12 20:52:10 +03003998 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3999 return 0;
4000
4001 switch (ac) {
4002 case IEEE80211_AC_VO:
4003 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4004 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004005 prio = 7;
4006 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004007 break;
4008 case IEEE80211_AC_VI:
4009 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4010 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004011 prio = 5;
4012 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004013 break;
4014 case IEEE80211_AC_BE:
4015 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4016 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004017 prio = 2;
4018 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019 break;
4020 case IEEE80211_AC_BK:
4021 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4022 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004023 prio = 0;
4024 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004025 break;
4026 }
4027
4028 if (enable)
4029 arvif->u.sta.uapsd |= value;
4030 else
4031 arvif->u.sta.uapsd &= ~value;
4032
4033 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4034 WMI_STA_PS_PARAM_UAPSD,
4035 arvif->u.sta.uapsd);
4036 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004037 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004038 goto exit;
4039 }
4040
4041 if (arvif->u.sta.uapsd)
4042 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4043 else
4044 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4045
4046 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4047 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4048 value);
4049 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004050 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004051
Michal Kazior9f9b5742014-12-12 12:41:36 +01004052 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4053 if (ret) {
4054 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4055 arvif->vdev_id, ret);
4056 return ret;
4057 }
4058
4059 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4060 if (ret) {
4061 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4062 arvif->vdev_id, ret);
4063 return ret;
4064 }
4065
Michal Kaziorb0e56152015-01-24 12:14:52 +02004066 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4067 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4068 /* Only userspace can make an educated decision when to send
4069 * trigger frame. The following effectively disables u-UAPSD
4070 * autotrigger in firmware (which is enabled by default
4071 * provided the autotrigger service is available).
4072 */
4073
4074 arg.wmm_ac = acc;
4075 arg.user_priority = prio;
4076 arg.service_interval = 0;
4077 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4078 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4079
4080 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4081 arvif->bssid, &arg, 1);
4082 if (ret) {
4083 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4084 ret);
4085 return ret;
4086 }
4087 }
4088
Kalle Valo5e3dd152013-06-12 20:52:10 +03004089exit:
4090 return ret;
4091}
4092
4093static int ath10k_conf_tx(struct ieee80211_hw *hw,
4094 struct ieee80211_vif *vif, u16 ac,
4095 const struct ieee80211_tx_queue_params *params)
4096{
4097 struct ath10k *ar = hw->priv;
4098 struct wmi_wmm_params_arg *p = NULL;
4099 int ret;
4100
4101 mutex_lock(&ar->conf_mutex);
4102
4103 switch (ac) {
4104 case IEEE80211_AC_VO:
4105 p = &ar->wmm_params.ac_vo;
4106 break;
4107 case IEEE80211_AC_VI:
4108 p = &ar->wmm_params.ac_vi;
4109 break;
4110 case IEEE80211_AC_BE:
4111 p = &ar->wmm_params.ac_be;
4112 break;
4113 case IEEE80211_AC_BK:
4114 p = &ar->wmm_params.ac_bk;
4115 break;
4116 }
4117
4118 if (WARN_ON(!p)) {
4119 ret = -EINVAL;
4120 goto exit;
4121 }
4122
4123 p->cwmin = params->cw_min;
4124 p->cwmax = params->cw_max;
4125 p->aifs = params->aifs;
4126
4127 /*
4128 * The channel time duration programmed in the HW is in absolute
4129 * microseconds, while mac80211 gives the txop in units of
4130 * 32 microseconds.
4131 */
4132 p->txop = params->txop * 32;
4133
4134 /* FIXME: FW accepts wmm params per hw, not per vif */
4135 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
4136 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004137 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004138 goto exit;
4139 }
4140
4141 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4142 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004143 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004144
4145exit:
4146 mutex_unlock(&ar->conf_mutex);
4147 return ret;
4148}
4149
4150#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4151
4152static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4153 struct ieee80211_vif *vif,
4154 struct ieee80211_channel *chan,
4155 int duration,
4156 enum ieee80211_roc_type type)
4157{
4158 struct ath10k *ar = hw->priv;
4159 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4160 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004161 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004162
4163 mutex_lock(&ar->conf_mutex);
4164
4165 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004166 switch (ar->scan.state) {
4167 case ATH10K_SCAN_IDLE:
4168 reinit_completion(&ar->scan.started);
4169 reinit_completion(&ar->scan.completed);
4170 reinit_completion(&ar->scan.on_channel);
4171 ar->scan.state = ATH10K_SCAN_STARTING;
4172 ar->scan.is_roc = true;
4173 ar->scan.vdev_id = arvif->vdev_id;
4174 ar->scan.roc_freq = chan->center_freq;
4175 ret = 0;
4176 break;
4177 case ATH10K_SCAN_STARTING:
4178 case ATH10K_SCAN_RUNNING:
4179 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004180 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004181 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004182 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004183 spin_unlock_bh(&ar->data_lock);
4184
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004185 if (ret)
4186 goto exit;
4187
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004188 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4189
Kalle Valo5e3dd152013-06-12 20:52:10 +03004190 memset(&arg, 0, sizeof(arg));
4191 ath10k_wmi_start_scan_init(ar, &arg);
4192 arg.vdev_id = arvif->vdev_id;
4193 arg.scan_id = ATH10K_SCAN_ID;
4194 arg.n_channels = 1;
4195 arg.channels[0] = chan->center_freq;
4196 arg.dwell_time_active = duration;
4197 arg.dwell_time_passive = duration;
4198 arg.max_scan_time = 2 * duration;
4199 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4200 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4201
4202 ret = ath10k_start_scan(ar, &arg);
4203 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004204 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004205 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004206 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004207 spin_unlock_bh(&ar->data_lock);
4208 goto exit;
4209 }
4210
4211 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4212 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004213 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004214
4215 ret = ath10k_scan_stop(ar);
4216 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004217 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004218
Kalle Valo5e3dd152013-06-12 20:52:10 +03004219 ret = -ETIMEDOUT;
4220 goto exit;
4221 }
4222
4223 ret = 0;
4224exit:
4225 mutex_unlock(&ar->conf_mutex);
4226 return ret;
4227}
4228
4229static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4230{
4231 struct ath10k *ar = hw->priv;
4232
4233 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004234 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004235 mutex_unlock(&ar->conf_mutex);
4236
Michal Kazior4eb2e162014-10-28 10:23:09 +01004237 cancel_delayed_work_sync(&ar->scan.timeout);
4238
Kalle Valo5e3dd152013-06-12 20:52:10 +03004239 return 0;
4240}
4241
4242/*
4243 * Both RTS and Fragmentation threshold are interface-specific
4244 * in ath10k, but device-specific in mac80211.
4245 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004246
4247static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4248{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004249 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004250 struct ath10k_vif *arvif;
4251 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004252
Michal Kaziorad088bf2013-10-16 15:44:46 +03004253 mutex_lock(&ar->conf_mutex);
4254 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004255 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004256 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004257
Michal Kaziorad088bf2013-10-16 15:44:46 +03004258 ret = ath10k_mac_set_rts(arvif, value);
4259 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004260 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004261 arvif->vdev_id, ret);
4262 break;
4263 }
4264 }
4265 mutex_unlock(&ar->conf_mutex);
4266
4267 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004268}
4269
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004270static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4271 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004272{
4273 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004274 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004275 int ret;
4276
4277 /* mac80211 doesn't care if we really xmit queued frames or not
4278 * we'll collect those frames either way if we stop/delete vdevs */
4279 if (drop)
4280 return;
4281
Michal Kazior548db542013-07-05 16:15:15 +03004282 mutex_lock(&ar->conf_mutex);
4283
Michal Kazioraffd3212013-07-16 09:54:35 +02004284 if (ar->state == ATH10K_STATE_WEDGED)
4285 goto skip;
4286
Michal Kazioredb82362013-07-05 16:15:14 +03004287 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004288 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004289
Michal Kazioredb82362013-07-05 16:15:14 +03004290 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004291 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004292 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004293
Michal Kazior7962b0d2014-10-28 10:34:38 +01004294 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4295 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4296 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004297
4298 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004300
4301 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004302 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004303 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004304
Michal Kazioraffd3212013-07-16 09:54:35 +02004305skip:
Michal Kazior548db542013-07-05 16:15:15 +03004306 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307}
4308
4309/* TODO: Implement this function properly
4310 * For now it is needed to reply to Probe Requests in IBSS mode.
4311 * Propably we need this information from FW.
4312 */
4313static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4314{
4315 return 1;
4316}
4317
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004318#ifdef CONFIG_PM
4319static int ath10k_suspend(struct ieee80211_hw *hw,
4320 struct cfg80211_wowlan *wowlan)
4321{
4322 struct ath10k *ar = hw->priv;
4323 int ret;
4324
Marek Puzyniak9042e172014-02-10 17:14:23 +01004325 mutex_lock(&ar->conf_mutex);
4326
Marek Puzyniak00f54822014-02-10 17:14:24 +01004327 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004328 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004329 if (ret == -ETIMEDOUT)
4330 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004331 ret = 1;
4332 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004333 }
4334
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004335 ret = ath10k_hif_suspend(ar);
4336 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004337 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004338 goto resume;
4339 }
4340
Marek Puzyniak9042e172014-02-10 17:14:23 +01004341 ret = 0;
4342 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004343resume:
4344 ret = ath10k_wmi_pdev_resume_target(ar);
4345 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004346 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004347
4348 ret = 1;
4349exit:
4350 mutex_unlock(&ar->conf_mutex);
4351 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004352}
4353
4354static int ath10k_resume(struct ieee80211_hw *hw)
4355{
4356 struct ath10k *ar = hw->priv;
4357 int ret;
4358
Marek Puzyniak9042e172014-02-10 17:14:23 +01004359 mutex_lock(&ar->conf_mutex);
4360
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004361 ret = ath10k_hif_resume(ar);
4362 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004363 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004364 ret = 1;
4365 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004366 }
4367
4368 ret = ath10k_wmi_pdev_resume_target(ar);
4369 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004370 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004371 ret = 1;
4372 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004373 }
4374
Marek Puzyniak9042e172014-02-10 17:14:23 +01004375 ret = 0;
4376exit:
4377 mutex_unlock(&ar->conf_mutex);
4378 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004379}
4380#endif
4381
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004382static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4383 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004384{
4385 struct ath10k *ar = hw->priv;
4386
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004387 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4388 return;
4389
Michal Kazioraffd3212013-07-16 09:54:35 +02004390 mutex_lock(&ar->conf_mutex);
4391
4392 /* If device failed to restart it will be in a different state, e.g.
4393 * ATH10K_STATE_WEDGED */
4394 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004395 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004396 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004397 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004398 }
4399
4400 mutex_unlock(&ar->conf_mutex);
4401}
4402
Michal Kazior2e1dea42013-07-31 10:32:40 +02004403static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4404 struct survey_info *survey)
4405{
4406 struct ath10k *ar = hw->priv;
4407 struct ieee80211_supported_band *sband;
4408 struct survey_info *ar_survey = &ar->survey[idx];
4409 int ret = 0;
4410
4411 mutex_lock(&ar->conf_mutex);
4412
4413 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4414 if (sband && idx >= sband->n_channels) {
4415 idx -= sband->n_channels;
4416 sband = NULL;
4417 }
4418
4419 if (!sband)
4420 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4421
4422 if (!sband || idx >= sband->n_channels) {
4423 ret = -ENOENT;
4424 goto exit;
4425 }
4426
4427 spin_lock_bh(&ar->data_lock);
4428 memcpy(survey, ar_survey, sizeof(*survey));
4429 spin_unlock_bh(&ar->data_lock);
4430
4431 survey->channel = &sband->channels[idx];
4432
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004433 if (ar->rx_channel == survey->channel)
4434 survey->filled |= SURVEY_INFO_IN_USE;
4435
Michal Kazior2e1dea42013-07-31 10:32:40 +02004436exit:
4437 mutex_unlock(&ar->conf_mutex);
4438 return ret;
4439}
4440
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004441/* Helper table for legacy fixed_rate/bitrate_mask */
4442static const u8 cck_ofdm_rate[] = {
4443 /* CCK */
4444 3, /* 1Mbps */
4445 2, /* 2Mbps */
4446 1, /* 5.5Mbps */
4447 0, /* 11Mbps */
4448 /* OFDM */
4449 3, /* 6Mbps */
4450 7, /* 9Mbps */
4451 2, /* 12Mbps */
4452 6, /* 18Mbps */
4453 1, /* 24Mbps */
4454 5, /* 36Mbps */
4455 0, /* 48Mbps */
4456 4, /* 54Mbps */
4457};
4458
4459/* Check if only one bit set */
4460static int ath10k_check_single_mask(u32 mask)
4461{
4462 int bit;
4463
4464 bit = ffs(mask);
4465 if (!bit)
4466 return 0;
4467
4468 mask &= ~BIT(bit - 1);
4469 if (mask)
4470 return 2;
4471
4472 return 1;
4473}
4474
4475static bool
4476ath10k_default_bitrate_mask(struct ath10k *ar,
4477 enum ieee80211_band band,
4478 const struct cfg80211_bitrate_mask *mask)
4479{
4480 u32 legacy = 0x00ff;
4481 u8 ht = 0xff, i;
4482 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004483 u16 nrf = ar->num_rf_chains;
4484
4485 if (ar->cfg_tx_chainmask)
4486 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004487
4488 switch (band) {
4489 case IEEE80211_BAND_2GHZ:
4490 legacy = 0x00fff;
4491 vht = 0;
4492 break;
4493 case IEEE80211_BAND_5GHZ:
4494 break;
4495 default:
4496 return false;
4497 }
4498
4499 if (mask->control[band].legacy != legacy)
4500 return false;
4501
Ben Greearb116ea12014-11-24 16:22:10 +02004502 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004503 if (mask->control[band].ht_mcs[i] != ht)
4504 return false;
4505
Ben Greearb116ea12014-11-24 16:22:10 +02004506 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004507 if (mask->control[band].vht_mcs[i] != vht)
4508 return false;
4509
4510 return true;
4511}
4512
4513static bool
4514ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4515 enum ieee80211_band band,
4516 u8 *fixed_nss)
4517{
4518 int ht_nss = 0, vht_nss = 0, i;
4519
4520 /* check legacy */
4521 if (ath10k_check_single_mask(mask->control[band].legacy))
4522 return false;
4523
4524 /* check HT */
4525 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4526 if (mask->control[band].ht_mcs[i] == 0xff)
4527 continue;
4528 else if (mask->control[band].ht_mcs[i] == 0x00)
4529 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004530
4531 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004532 }
4533
4534 ht_nss = i;
4535
4536 /* check VHT */
4537 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4538 if (mask->control[band].vht_mcs[i] == 0x03ff)
4539 continue;
4540 else if (mask->control[band].vht_mcs[i] == 0x0000)
4541 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004542
4543 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004544 }
4545
4546 vht_nss = i;
4547
4548 if (ht_nss > 0 && vht_nss > 0)
4549 return false;
4550
4551 if (ht_nss)
4552 *fixed_nss = ht_nss;
4553 else if (vht_nss)
4554 *fixed_nss = vht_nss;
4555 else
4556 return false;
4557
4558 return true;
4559}
4560
4561static bool
4562ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4563 enum ieee80211_band band,
4564 enum wmi_rate_preamble *preamble)
4565{
4566 int legacy = 0, ht = 0, vht = 0, i;
4567
4568 *preamble = WMI_RATE_PREAMBLE_OFDM;
4569
4570 /* check legacy */
4571 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4572 if (legacy > 1)
4573 return false;
4574
4575 /* check HT */
4576 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4577 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4578 if (ht > 1)
4579 return false;
4580
4581 /* check VHT */
4582 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4583 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4584 if (vht > 1)
4585 return false;
4586
4587 /* Currently we support only one fixed_rate */
4588 if ((legacy + ht + vht) != 1)
4589 return false;
4590
4591 if (ht)
4592 *preamble = WMI_RATE_PREAMBLE_HT;
4593 else if (vht)
4594 *preamble = WMI_RATE_PREAMBLE_VHT;
4595
4596 return true;
4597}
4598
4599static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004600ath10k_bitrate_mask_rate(struct ath10k *ar,
4601 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004602 enum ieee80211_band band,
4603 u8 *fixed_rate,
4604 u8 *fixed_nss)
4605{
4606 u8 rate = 0, pream = 0, nss = 0, i;
4607 enum wmi_rate_preamble preamble;
4608
4609 /* Check if single rate correct */
4610 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4611 return false;
4612
4613 pream = preamble;
4614
4615 switch (preamble) {
4616 case WMI_RATE_PREAMBLE_CCK:
4617 case WMI_RATE_PREAMBLE_OFDM:
4618 i = ffs(mask->control[band].legacy) - 1;
4619
4620 if (band == IEEE80211_BAND_2GHZ && i < 4)
4621 pream = WMI_RATE_PREAMBLE_CCK;
4622
4623 if (band == IEEE80211_BAND_5GHZ)
4624 i += 4;
4625
4626 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4627 return false;
4628
4629 rate = cck_ofdm_rate[i];
4630 break;
4631 case WMI_RATE_PREAMBLE_HT:
4632 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4633 if (mask->control[band].ht_mcs[i])
4634 break;
4635
4636 if (i == IEEE80211_HT_MCS_MASK_LEN)
4637 return false;
4638
4639 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4640 nss = i;
4641 break;
4642 case WMI_RATE_PREAMBLE_VHT:
4643 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4644 if (mask->control[band].vht_mcs[i])
4645 break;
4646
4647 if (i == NL80211_VHT_NSS_MAX)
4648 return false;
4649
4650 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4651 nss = i;
4652 break;
4653 }
4654
4655 *fixed_nss = nss + 1;
4656 nss <<= 4;
4657 pream <<= 6;
4658
Michal Kazior7aa7a722014-08-25 12:09:38 +02004659 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004660 pream, nss, rate);
4661
4662 *fixed_rate = pream | nss | rate;
4663
4664 return true;
4665}
4666
Michal Kazior7aa7a722014-08-25 12:09:38 +02004667static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4668 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004669 enum ieee80211_band band,
4670 u8 *fixed_rate,
4671 u8 *fixed_nss)
4672{
4673 /* First check full NSS mask, if we can simply limit NSS */
4674 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4675 return true;
4676
4677 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004678 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004679}
4680
4681static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4682 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004683 u8 fixed_nss,
4684 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004685{
4686 struct ath10k *ar = arvif->ar;
4687 u32 vdev_param;
4688 int ret = 0;
4689
4690 mutex_lock(&ar->conf_mutex);
4691
4692 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004693 arvif->fixed_nss == fixed_nss &&
4694 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004695 goto exit;
4696
4697 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004698 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004699
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004700 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004701 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004702
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004703 vdev_param = ar->wmi.vdev_param->fixed_rate;
4704 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4705 vdev_param, fixed_rate);
4706 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004707 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004708 fixed_rate, ret);
4709 ret = -EINVAL;
4710 goto exit;
4711 }
4712
4713 arvif->fixed_rate = fixed_rate;
4714
4715 vdev_param = ar->wmi.vdev_param->nss;
4716 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4717 vdev_param, fixed_nss);
4718
4719 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004720 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004721 fixed_nss, ret);
4722 ret = -EINVAL;
4723 goto exit;
4724 }
4725
4726 arvif->fixed_nss = fixed_nss;
4727
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004728 vdev_param = ar->wmi.vdev_param->sgi;
4729 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4730 force_sgi);
4731
4732 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004733 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004734 force_sgi, ret);
4735 ret = -EINVAL;
4736 goto exit;
4737 }
4738
4739 arvif->force_sgi = force_sgi;
4740
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004741exit:
4742 mutex_unlock(&ar->conf_mutex);
4743 return ret;
4744}
4745
4746static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4747 struct ieee80211_vif *vif,
4748 const struct cfg80211_bitrate_mask *mask)
4749{
4750 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4751 struct ath10k *ar = arvif->ar;
4752 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4753 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4754 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004755 u8 force_sgi;
4756
Ben Greearb116ea12014-11-24 16:22:10 +02004757 if (ar->cfg_tx_chainmask)
4758 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4759
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004760 force_sgi = mask->control[band].gi;
4761 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4762 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004763
4764 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004765 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004766 &fixed_rate,
4767 &fixed_nss))
4768 return -EINVAL;
4769 }
4770
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004771 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004772 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004773 return -EINVAL;
4774 }
4775
4776 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4777 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004778}
4779
Michal Kazior9797feb2014-02-14 14:49:48 +01004780static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4781 struct ieee80211_vif *vif,
4782 struct ieee80211_sta *sta,
4783 u32 changed)
4784{
4785 struct ath10k *ar = hw->priv;
4786 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4787 u32 bw, smps;
4788
4789 spin_lock_bh(&ar->data_lock);
4790
Michal Kazior7aa7a722014-08-25 12:09:38 +02004791 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004792 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4793 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4794 sta->smps_mode);
4795
4796 if (changed & IEEE80211_RC_BW_CHANGED) {
4797 bw = WMI_PEER_CHWIDTH_20MHZ;
4798
4799 switch (sta->bandwidth) {
4800 case IEEE80211_STA_RX_BW_20:
4801 bw = WMI_PEER_CHWIDTH_20MHZ;
4802 break;
4803 case IEEE80211_STA_RX_BW_40:
4804 bw = WMI_PEER_CHWIDTH_40MHZ;
4805 break;
4806 case IEEE80211_STA_RX_BW_80:
4807 bw = WMI_PEER_CHWIDTH_80MHZ;
4808 break;
4809 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004810 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004811 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004812 bw = WMI_PEER_CHWIDTH_20MHZ;
4813 break;
4814 }
4815
4816 arsta->bw = bw;
4817 }
4818
4819 if (changed & IEEE80211_RC_NSS_CHANGED)
4820 arsta->nss = sta->rx_nss;
4821
4822 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4823 smps = WMI_PEER_SMPS_PS_NONE;
4824
4825 switch (sta->smps_mode) {
4826 case IEEE80211_SMPS_AUTOMATIC:
4827 case IEEE80211_SMPS_OFF:
4828 smps = WMI_PEER_SMPS_PS_NONE;
4829 break;
4830 case IEEE80211_SMPS_STATIC:
4831 smps = WMI_PEER_SMPS_STATIC;
4832 break;
4833 case IEEE80211_SMPS_DYNAMIC:
4834 smps = WMI_PEER_SMPS_DYNAMIC;
4835 break;
4836 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004837 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004838 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004839 smps = WMI_PEER_SMPS_PS_NONE;
4840 break;
4841 }
4842
4843 arsta->smps = smps;
4844 }
4845
Michal Kazior9797feb2014-02-14 14:49:48 +01004846 arsta->changed |= changed;
4847
4848 spin_unlock_bh(&ar->data_lock);
4849
4850 ieee80211_queue_work(hw, &arsta->update_wk);
4851}
4852
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004853static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4854{
4855 /*
4856 * FIXME: Return 0 for time being. Need to figure out whether FW
4857 * has the API to fetch 64-bit local TSF
4858 */
4859
4860 return 0;
4861}
4862
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004863static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4864 struct ieee80211_vif *vif,
4865 enum ieee80211_ampdu_mlme_action action,
4866 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4867 u8 buf_size)
4868{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004869 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004870 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4871
Michal Kazior7aa7a722014-08-25 12:09:38 +02004872 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004873 arvif->vdev_id, sta->addr, tid, action);
4874
4875 switch (action) {
4876 case IEEE80211_AMPDU_RX_START:
4877 case IEEE80211_AMPDU_RX_STOP:
4878 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4879 * creation/removal. Do we need to verify this?
4880 */
4881 return 0;
4882 case IEEE80211_AMPDU_TX_START:
4883 case IEEE80211_AMPDU_TX_STOP_CONT:
4884 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4885 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4886 case IEEE80211_AMPDU_TX_OPERATIONAL:
4887 /* Firmware offloads Tx aggregation entirely so deny mac80211
4888 * Tx aggregation requests.
4889 */
4890 return -EOPNOTSUPP;
4891 }
4892
4893 return -EINVAL;
4894}
4895
Kalle Valo5e3dd152013-06-12 20:52:10 +03004896static const struct ieee80211_ops ath10k_ops = {
4897 .tx = ath10k_tx,
4898 .start = ath10k_start,
4899 .stop = ath10k_stop,
4900 .config = ath10k_config,
4901 .add_interface = ath10k_add_interface,
4902 .remove_interface = ath10k_remove_interface,
4903 .configure_filter = ath10k_configure_filter,
4904 .bss_info_changed = ath10k_bss_info_changed,
4905 .hw_scan = ath10k_hw_scan,
4906 .cancel_hw_scan = ath10k_cancel_hw_scan,
4907 .set_key = ath10k_set_key,
4908 .sta_state = ath10k_sta_state,
4909 .conf_tx = ath10k_conf_tx,
4910 .remain_on_channel = ath10k_remain_on_channel,
4911 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4912 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004913 .flush = ath10k_flush,
4914 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03004915 .set_antenna = ath10k_set_antenna,
4916 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004917 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004918 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004919 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004920 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004921 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004922 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004923 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4924 .get_et_stats = ath10k_debug_get_et_stats,
4925 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004926
4927 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4928
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004929#ifdef CONFIG_PM
4930 .suspend = ath10k_suspend,
4931 .resume = ath10k_resume,
4932#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004933#ifdef CONFIG_MAC80211_DEBUGFS
4934 .sta_add_debugfs = ath10k_sta_add_debugfs,
4935#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004936};
4937
4938#define RATETAB_ENT(_rate, _rateid, _flags) { \
4939 .bitrate = (_rate), \
4940 .flags = (_flags), \
4941 .hw_value = (_rateid), \
4942}
4943
4944#define CHAN2G(_channel, _freq, _flags) { \
4945 .band = IEEE80211_BAND_2GHZ, \
4946 .hw_value = (_channel), \
4947 .center_freq = (_freq), \
4948 .flags = (_flags), \
4949 .max_antenna_gain = 0, \
4950 .max_power = 30, \
4951}
4952
4953#define CHAN5G(_channel, _freq, _flags) { \
4954 .band = IEEE80211_BAND_5GHZ, \
4955 .hw_value = (_channel), \
4956 .center_freq = (_freq), \
4957 .flags = (_flags), \
4958 .max_antenna_gain = 0, \
4959 .max_power = 30, \
4960}
4961
4962static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4963 CHAN2G(1, 2412, 0),
4964 CHAN2G(2, 2417, 0),
4965 CHAN2G(3, 2422, 0),
4966 CHAN2G(4, 2427, 0),
4967 CHAN2G(5, 2432, 0),
4968 CHAN2G(6, 2437, 0),
4969 CHAN2G(7, 2442, 0),
4970 CHAN2G(8, 2447, 0),
4971 CHAN2G(9, 2452, 0),
4972 CHAN2G(10, 2457, 0),
4973 CHAN2G(11, 2462, 0),
4974 CHAN2G(12, 2467, 0),
4975 CHAN2G(13, 2472, 0),
4976 CHAN2G(14, 2484, 0),
4977};
4978
4979static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004980 CHAN5G(36, 5180, 0),
4981 CHAN5G(40, 5200, 0),
4982 CHAN5G(44, 5220, 0),
4983 CHAN5G(48, 5240, 0),
4984 CHAN5G(52, 5260, 0),
4985 CHAN5G(56, 5280, 0),
4986 CHAN5G(60, 5300, 0),
4987 CHAN5G(64, 5320, 0),
4988 CHAN5G(100, 5500, 0),
4989 CHAN5G(104, 5520, 0),
4990 CHAN5G(108, 5540, 0),
4991 CHAN5G(112, 5560, 0),
4992 CHAN5G(116, 5580, 0),
4993 CHAN5G(120, 5600, 0),
4994 CHAN5G(124, 5620, 0),
4995 CHAN5G(128, 5640, 0),
4996 CHAN5G(132, 5660, 0),
4997 CHAN5G(136, 5680, 0),
4998 CHAN5G(140, 5700, 0),
4999 CHAN5G(149, 5745, 0),
5000 CHAN5G(153, 5765, 0),
5001 CHAN5G(157, 5785, 0),
5002 CHAN5G(161, 5805, 0),
5003 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005004};
5005
Michal Kazior91b12082014-12-12 12:41:35 +01005006/* Note: Be careful if you re-order these. There is code which depends on this
5007 * ordering.
5008 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005009static struct ieee80211_rate ath10k_rates[] = {
5010 /* CCK */
5011 RATETAB_ENT(10, 0x82, 0),
5012 RATETAB_ENT(20, 0x84, 0),
5013 RATETAB_ENT(55, 0x8b, 0),
5014 RATETAB_ENT(110, 0x96, 0),
5015 /* OFDM */
5016 RATETAB_ENT(60, 0x0c, 0),
5017 RATETAB_ENT(90, 0x12, 0),
5018 RATETAB_ENT(120, 0x18, 0),
5019 RATETAB_ENT(180, 0x24, 0),
5020 RATETAB_ENT(240, 0x30, 0),
5021 RATETAB_ENT(360, 0x48, 0),
5022 RATETAB_ENT(480, 0x60, 0),
5023 RATETAB_ENT(540, 0x6c, 0),
5024};
5025
5026#define ath10k_a_rates (ath10k_rates + 4)
5027#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5028#define ath10k_g_rates (ath10k_rates + 0)
5029#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5030
Michal Kaziore7b54192014-08-07 11:03:27 +02005031struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005032{
5033 struct ieee80211_hw *hw;
5034 struct ath10k *ar;
5035
Michal Kaziore7b54192014-08-07 11:03:27 +02005036 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005037 if (!hw)
5038 return NULL;
5039
5040 ar = hw->priv;
5041 ar->hw = hw;
5042
5043 return ar;
5044}
5045
5046void ath10k_mac_destroy(struct ath10k *ar)
5047{
5048 ieee80211_free_hw(ar->hw);
5049}
5050
5051static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5052 {
5053 .max = 8,
5054 .types = BIT(NL80211_IFTYPE_STATION)
5055 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005056 },
5057 {
5058 .max = 3,
5059 .types = BIT(NL80211_IFTYPE_P2P_GO)
5060 },
5061 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005062 .max = 1,
5063 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5064 },
5065 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005066 .max = 7,
5067 .types = BIT(NL80211_IFTYPE_AP)
5068 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005069};
5070
Bartosz Markowskif2595092013-12-10 16:20:39 +01005071static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005072 {
5073 .max = 8,
5074 .types = BIT(NL80211_IFTYPE_AP)
5075 },
5076};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005077
5078static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5079 {
5080 .limits = ath10k_if_limits,
5081 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5082 .max_interfaces = 8,
5083 .num_different_channels = 1,
5084 .beacon_int_infra_match = true,
5085 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005086};
5087
5088static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005089 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005090 .limits = ath10k_10x_if_limits,
5091 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005092 .max_interfaces = 8,
5093 .num_different_channels = 1,
5094 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005095#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005096 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5097 BIT(NL80211_CHAN_WIDTH_20) |
5098 BIT(NL80211_CHAN_WIDTH_40) |
5099 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005100#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005101 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005102};
5103
5104static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5105{
5106 struct ieee80211_sta_vht_cap vht_cap = {0};
5107 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005108 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005109
5110 vht_cap.vht_supported = 1;
5111 vht_cap.cap = ar->vht_cap_info;
5112
Michal Kazior8865bee42013-07-24 12:36:46 +02005113 mcs_map = 0;
5114 for (i = 0; i < 8; i++) {
5115 if (i < ar->num_rf_chains)
5116 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5117 else
5118 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5119 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005120
5121 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5122 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5123
5124 return vht_cap;
5125}
5126
5127static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5128{
5129 int i;
5130 struct ieee80211_sta_ht_cap ht_cap = {0};
5131
5132 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5133 return ht_cap;
5134
5135 ht_cap.ht_supported = 1;
5136 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5137 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5138 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5139 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5140 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5141
5142 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5143 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5144
5145 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5146 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5147
5148 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5149 u32 smps;
5150
5151 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5152 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5153
5154 ht_cap.cap |= smps;
5155 }
5156
5157 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5158 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5159
5160 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5161 u32 stbc;
5162
5163 stbc = ar->ht_cap_info;
5164 stbc &= WMI_HT_CAP_RX_STBC;
5165 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5166 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5167 stbc &= IEEE80211_HT_CAP_RX_STBC;
5168
5169 ht_cap.cap |= stbc;
5170 }
5171
5172 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5173 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5174
5175 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5176 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5177
5178 /* max AMSDU is implicitly taken from vht_cap_info */
5179 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5180 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5181
Michal Kazior8865bee42013-07-24 12:36:46 +02005182 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005183 ht_cap.mcs.rx_mask[i] = 0xFF;
5184
5185 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5186
5187 return ht_cap;
5188}
5189
Kalle Valo5e3dd152013-06-12 20:52:10 +03005190static void ath10k_get_arvif_iter(void *data, u8 *mac,
5191 struct ieee80211_vif *vif)
5192{
5193 struct ath10k_vif_iter *arvif_iter = data;
5194 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5195
5196 if (arvif->vdev_id == arvif_iter->vdev_id)
5197 arvif_iter->arvif = arvif;
5198}
5199
5200struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5201{
5202 struct ath10k_vif_iter arvif_iter;
5203 u32 flags;
5204
5205 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5206 arvif_iter.vdev_id = vdev_id;
5207
5208 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5209 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5210 flags,
5211 ath10k_get_arvif_iter,
5212 &arvif_iter);
5213 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005214 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005215 return NULL;
5216 }
5217
5218 return arvif_iter.arvif;
5219}
5220
5221int ath10k_mac_register(struct ath10k *ar)
5222{
5223 struct ieee80211_supported_band *band;
5224 struct ieee80211_sta_vht_cap vht_cap;
5225 struct ieee80211_sta_ht_cap ht_cap;
5226 void *channels;
5227 int ret;
5228
5229 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5230
5231 SET_IEEE80211_DEV(ar->hw, ar->dev);
5232
5233 ht_cap = ath10k_get_ht_cap(ar);
5234 vht_cap = ath10k_create_vht_cap(ar);
5235
5236 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5237 channels = kmemdup(ath10k_2ghz_channels,
5238 sizeof(ath10k_2ghz_channels),
5239 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005240 if (!channels) {
5241 ret = -ENOMEM;
5242 goto err_free;
5243 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005244
5245 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5246 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5247 band->channels = channels;
5248 band->n_bitrates = ath10k_g_rates_size;
5249 band->bitrates = ath10k_g_rates;
5250 band->ht_cap = ht_cap;
5251
5252 /* vht is not supported in 2.4 GHz */
5253
5254 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5255 }
5256
5257 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5258 channels = kmemdup(ath10k_5ghz_channels,
5259 sizeof(ath10k_5ghz_channels),
5260 GFP_KERNEL);
5261 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005262 ret = -ENOMEM;
5263 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005264 }
5265
5266 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5267 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5268 band->channels = channels;
5269 band->n_bitrates = ath10k_a_rates_size;
5270 band->bitrates = ath10k_a_rates;
5271 band->ht_cap = ht_cap;
5272 band->vht_cap = vht_cap;
5273 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5274 }
5275
5276 ar->hw->wiphy->interface_modes =
5277 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005278 BIT(NL80211_IFTYPE_AP);
5279
Ben Greear46acf7bb2014-05-16 17:15:38 +03005280 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5281 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5282
Bartosz Markowskid3541812013-12-10 16:20:40 +01005283 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5284 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005285 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005286 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5287 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005288
5289 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5290 IEEE80211_HW_SUPPORTS_PS |
5291 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5292 IEEE80211_HW_SUPPORTS_UAPSD |
5293 IEEE80211_HW_MFP_CAPABLE |
5294 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5295 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005296 IEEE80211_HW_AP_LINK_PS |
5297 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005298
Eliad Peller0d8614b2014-09-10 14:07:36 +03005299 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5300
Kalle Valo5e3dd152013-06-12 20:52:10 +03005301 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005302 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005303
5304 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5305 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5306 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5307 }
5308
5309 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5310 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5311
5312 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005313 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314
Kalle Valo5e3dd152013-06-12 20:52:10 +03005315 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5316
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005317 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5318 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5319
5320 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5321 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5322 * correct Probe Responses. This is more of a hack advert..
5323 */
5324 ar->hw->wiphy->probe_resp_offload |=
5325 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5326 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5327 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5328 }
5329
Kalle Valo5e3dd152013-06-12 20:52:10 +03005330 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005331 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005332 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5333
5334 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005335 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5336
Kalle Valo5e3dd152013-06-12 20:52:10 +03005337 /*
5338 * on LL hardware queues are managed entirely by the FW
5339 * so we only advertise to mac we can do the queues thing
5340 */
5341 ar->hw->queues = 4;
5342
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005343 switch (ar->wmi.op_version) {
5344 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5345 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005346 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5347 ar->hw->wiphy->n_iface_combinations =
5348 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005349 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005350 break;
5351 case ATH10K_FW_WMI_OP_VERSION_10_1:
5352 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005353 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005354 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5355 ar->hw->wiphy->n_iface_combinations =
5356 ARRAY_SIZE(ath10k_10x_if_comb);
5357 break;
5358 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5359 case ATH10K_FW_WMI_OP_VERSION_MAX:
5360 WARN_ON(1);
5361 ret = -EINVAL;
5362 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005363 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005364
Michal Kazior7c199992013-07-31 10:47:57 +02005365 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5366
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005367 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5368 /* Init ath dfs pattern detector */
5369 ar->ath_common.debug_mask = ATH_DBG_DFS;
5370 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5371 NL80211_DFS_UNSET);
5372
5373 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005374 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005375 }
5376
Kalle Valo5e3dd152013-06-12 20:52:10 +03005377 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5378 ath10k_reg_notifier);
5379 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005380 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005381 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005382 }
5383
5384 ret = ieee80211_register_hw(ar->hw);
5385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005386 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005387 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005388 }
5389
5390 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5391 ret = regulatory_hint(ar->hw->wiphy,
5392 ar->ath_common.regulatory.alpha2);
5393 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005394 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005395 }
5396
5397 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005398
5399err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005400 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005401err_free:
5402 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5403 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5404
Kalle Valo5e3dd152013-06-12 20:52:10 +03005405 return ret;
5406}
5407
5408void ath10k_mac_unregister(struct ath10k *ar)
5409{
5410 ieee80211_unregister_hw(ar->hw);
5411
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005412 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5413 ar->dfs_detector->exit(ar->dfs_detector);
5414
Kalle Valo5e3dd152013-06-12 20:52:10 +03005415 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5416 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5417
5418 SET_IEEE80211_DEV(ar->hw, NULL);
5419}