blob: 51838ed26eabe5b90fc27319c2bd63c26c6b707c [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,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020040 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030041{
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 Kwaczynskie4e82e92015-01-24 12:14:53 +020061 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020075
76 if (def_idx)
77 arg.key_flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 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,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020095 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030096{
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
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200104 ret = ath10k_send_key(arvif, key, cmd, macaddr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300105 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;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200122 bool def_idx;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300123
124 lockdep_assert_held(&ar->conf_mutex);
125
126 spin_lock_bh(&ar->data_lock);
127 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
128 spin_unlock_bh(&ar->data_lock);
129
130 if (!peer)
131 return -ENOENT;
132
133 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
134 if (arvif->wep_keys[i] == NULL)
135 continue;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200136 /* set TX_USAGE flag for default key id */
137 if (arvif->def_wep_key_idx == i)
138 def_idx = true;
139 else
140 def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300141
142 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200143 addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 if (ret)
145 return ret;
146
Sujith Manoharanae167132014-11-25 11:46:59 +0530147 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530149 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300150 }
151
152 return 0;
153}
154
155static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
156 const u8 *addr)
157{
158 struct ath10k *ar = arvif->ar;
159 struct ath10k_peer *peer;
160 int first_errno = 0;
161 int ret;
162 int i;
163
164 lockdep_assert_held(&ar->conf_mutex);
165
166 spin_lock_bh(&ar->data_lock);
167 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
168 spin_unlock_bh(&ar->data_lock);
169
170 if (!peer)
171 return -ENOENT;
172
173 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
174 if (peer->keys[i] == NULL)
175 continue;
176
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200177 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 ret = ath10k_install_key(arvif, peer->keys[i],
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200179 DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 if (ret && first_errno == 0)
181 first_errno = ret;
182
183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200184 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 i, ret);
186
Sujith Manoharanae167132014-11-25 11:46:59 +0530187 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530189 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300190 }
191
192 return first_errno;
193}
194
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530195bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
196 u8 keyidx)
197{
198 struct ath10k_peer *peer;
199 int i;
200
201 lockdep_assert_held(&ar->data_lock);
202
203 /* We don't know which vdev this peer belongs to,
204 * since WMI doesn't give us that information.
205 *
206 * FIXME: multi-bss needs to be handled.
207 */
208 peer = ath10k_peer_find(ar, 0, addr);
209 if (!peer)
210 return false;
211
212 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
213 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
214 return true;
215 }
216
217 return false;
218}
219
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
221 struct ieee80211_key_conf *key)
222{
223 struct ath10k *ar = arvif->ar;
224 struct ath10k_peer *peer;
225 u8 addr[ETH_ALEN];
226 int first_errno = 0;
227 int ret;
228 int i;
229
230 lockdep_assert_held(&ar->conf_mutex);
231
232 for (;;) {
233 /* since ath10k_install_key we can't hold data_lock all the
234 * time, so we try to remove the keys incrementally */
235 spin_lock_bh(&ar->data_lock);
236 i = 0;
237 list_for_each_entry(peer, &ar->peers, list) {
238 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
239 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300240 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300241 peer->keys[i] = NULL;
242 break;
243 }
244 }
245
246 if (i < ARRAY_SIZE(peer->keys))
247 break;
248 }
249 spin_unlock_bh(&ar->data_lock);
250
251 if (i == ARRAY_SIZE(peer->keys))
252 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200253 /* key flags are not required to delete the key */
254 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300255 if (ret && first_errno == 0)
256 first_errno = ret;
257
258 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200259 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200260 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300261 }
262
263 return first_errno;
264}
265
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266/*********************/
267/* General utilities */
268/*********************/
269
270static inline enum wmi_phy_mode
271chan_to_phymode(const struct cfg80211_chan_def *chandef)
272{
273 enum wmi_phy_mode phymode = MODE_UNKNOWN;
274
275 switch (chandef->chan->band) {
276 case IEEE80211_BAND_2GHZ:
277 switch (chandef->width) {
278 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800279 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
280 phymode = MODE_11B;
281 else
282 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283 break;
284 case NL80211_CHAN_WIDTH_20:
285 phymode = MODE_11NG_HT20;
286 break;
287 case NL80211_CHAN_WIDTH_40:
288 phymode = MODE_11NG_HT40;
289 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400290 case NL80211_CHAN_WIDTH_5:
291 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300292 case NL80211_CHAN_WIDTH_80:
293 case NL80211_CHAN_WIDTH_80P80:
294 case NL80211_CHAN_WIDTH_160:
295 phymode = MODE_UNKNOWN;
296 break;
297 }
298 break;
299 case IEEE80211_BAND_5GHZ:
300 switch (chandef->width) {
301 case NL80211_CHAN_WIDTH_20_NOHT:
302 phymode = MODE_11A;
303 break;
304 case NL80211_CHAN_WIDTH_20:
305 phymode = MODE_11NA_HT20;
306 break;
307 case NL80211_CHAN_WIDTH_40:
308 phymode = MODE_11NA_HT40;
309 break;
310 case NL80211_CHAN_WIDTH_80:
311 phymode = MODE_11AC_VHT80;
312 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400313 case NL80211_CHAN_WIDTH_5:
314 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315 case NL80211_CHAN_WIDTH_80P80:
316 case NL80211_CHAN_WIDTH_160:
317 phymode = MODE_UNKNOWN;
318 break;
319 }
320 break;
321 default:
322 break;
323 }
324
325 WARN_ON(phymode == MODE_UNKNOWN);
326 return phymode;
327}
328
329static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
330{
331/*
332 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
333 * 0 for no restriction
334 * 1 for 1/4 us
335 * 2 for 1/2 us
336 * 3 for 1 us
337 * 4 for 2 us
338 * 5 for 4 us
339 * 6 for 8 us
340 * 7 for 16 us
341 */
342 switch (mpdudensity) {
343 case 0:
344 return 0;
345 case 1:
346 case 2:
347 case 3:
348 /* Our lower layer calculations limit our precision to
349 1 microsecond */
350 return 1;
351 case 4:
352 return 2;
353 case 5:
354 return 4;
355 case 6:
356 return 8;
357 case 7:
358 return 16;
359 default:
360 return 0;
361 }
362}
363
364static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
365{
366 int ret;
367
368 lockdep_assert_held(&ar->conf_mutex);
369
Michal Kaziorcfd10612014-11-25 15:16:05 +0100370 if (ar->num_peers >= ar->max_num_peers)
371 return -ENOBUFS;
372
Kalle Valo5e3dd152013-06-12 20:52:10 +0300373 ret = ath10k_wmi_peer_create(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 create 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 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300379
380 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200382 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200383 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300384 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800385 }
Michal Kazior292a7532014-11-25 15:16:04 +0100386
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100387 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300388
389 return 0;
390}
391
Kalle Valo5a13e762014-01-20 11:01:46 +0200392static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
393{
394 struct ath10k *ar = arvif->ar;
395 u32 param;
396 int ret;
397
398 param = ar->wmi.pdev_param->sta_kickout_th;
399 ret = ath10k_wmi_pdev_set_param(ar, param,
400 ATH10K_KICKOUT_THRESHOLD);
401 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200402 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200403 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200404 return ret;
405 }
406
407 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
408 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
409 ATH10K_KEEPALIVE_MIN_IDLE);
410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200411 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200412 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200413 return ret;
414 }
415
416 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
417 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
418 ATH10K_KEEPALIVE_MAX_IDLE);
419 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200420 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200421 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200422 return ret;
423 }
424
425 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
426 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
427 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200429 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200430 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200431 return ret;
432 }
433
434 return 0;
435}
436
Vivek Natarajanacab6402014-11-26 09:06:12 +0200437static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200438{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200439 struct ath10k *ar = arvif->ar;
440 u32 vdev_param;
441
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200442 vdev_param = ar->wmi.vdev_param->rts_threshold;
443 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200444}
445
446static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
447{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200448 struct ath10k *ar = arvif->ar;
449 u32 vdev_param;
450
Michal Kazior424121c2013-07-22 14:13:31 +0200451 if (value != 0xFFFFFFFF)
452 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
453 ATH10K_FRAGMT_THRESHOLD_MIN,
454 ATH10K_FRAGMT_THRESHOLD_MAX);
455
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200456 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
457 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200458}
459
Kalle Valo5e3dd152013-06-12 20:52:10 +0300460static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
461{
462 int ret;
463
464 lockdep_assert_held(&ar->conf_mutex);
465
466 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
467 if (ret)
468 return ret;
469
470 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
471 if (ret)
472 return ret;
473
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100475
Kalle Valo5e3dd152013-06-12 20:52:10 +0300476 return 0;
477}
478
479static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
480{
481 struct ath10k_peer *peer, *tmp;
482
483 lockdep_assert_held(&ar->conf_mutex);
484
485 spin_lock_bh(&ar->data_lock);
486 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
487 if (peer->vdev_id != vdev_id)
488 continue;
489
Michal Kazior7aa7a722014-08-25 12:09:38 +0200490 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300491 peer->addr, vdev_id);
492
493 list_del(&peer->list);
494 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100495 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300496 }
497 spin_unlock_bh(&ar->data_lock);
498}
499
Michal Kaziora96d7742013-07-16 09:38:56 +0200500static void ath10k_peer_cleanup_all(struct ath10k *ar)
501{
502 struct ath10k_peer *peer, *tmp;
503
504 lockdep_assert_held(&ar->conf_mutex);
505
506 spin_lock_bh(&ar->data_lock);
507 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
508 list_del(&peer->list);
509 kfree(peer);
510 }
511 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100512
513 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100514 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200515}
516
Kalle Valo5e3dd152013-06-12 20:52:10 +0300517/************************/
518/* Interface management */
519/************************/
520
Michal Kazior64badcb2014-09-18 11:18:02 +0300521void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
522{
523 struct ath10k *ar = arvif->ar;
524
525 lockdep_assert_held(&ar->data_lock);
526
527 if (!arvif->beacon)
528 return;
529
530 if (!arvif->beacon_buf)
531 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
532 arvif->beacon->len, DMA_TO_DEVICE);
533
Michal Kazioraf213192015-01-29 14:29:52 +0200534 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
535 arvif->beacon_state != ATH10K_BEACON_SENT))
536 return;
537
Michal Kazior64badcb2014-09-18 11:18:02 +0300538 dev_kfree_skb_any(arvif->beacon);
539
540 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200541 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300542}
543
544static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
545{
546 struct ath10k *ar = arvif->ar;
547
548 lockdep_assert_held(&ar->data_lock);
549
550 ath10k_mac_vif_beacon_free(arvif);
551
552 if (arvif->beacon_buf) {
553 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
554 arvif->beacon_buf, arvif->beacon_paddr);
555 arvif->beacon_buf = NULL;
556 }
557}
558
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
560{
561 int ret;
562
Michal Kazior548db542013-07-05 16:15:15 +0300563 lockdep_assert_held(&ar->conf_mutex);
564
Michal Kazior7962b0d2014-10-28 10:34:38 +0100565 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
566 return -ESHUTDOWN;
567
Kalle Valo5e3dd152013-06-12 20:52:10 +0300568 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
569 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
570 if (ret == 0)
571 return -ETIMEDOUT;
572
573 return 0;
574}
575
Michal Kazior1bbc0972014-04-08 09:45:47 +0300576static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577{
Michal Kaziorc930f742014-01-23 11:38:25 +0100578 struct cfg80211_chan_def *chandef = &ar->chandef;
579 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 int ret = 0;
582
583 lockdep_assert_held(&ar->conf_mutex);
584
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585 arg.vdev_id = vdev_id;
586 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100587 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588
589 /* TODO setup this dynamically, what in case we
590 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100591 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200592 arg.channel.chan_radar =
593 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
Michal Kazior89c5c842013-10-23 04:02:13 -0700595 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700596 arg.channel.max_power = channel->max_power * 2;
597 arg.channel.max_reg_power = channel->max_reg_power * 2;
598 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599
Michal Kazior7962b0d2014-10-28 10:34:38 +0100600 reinit_completion(&ar->vdev_setup_done);
601
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 ret = ath10k_wmi_vdev_start(ar, &arg);
603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200604 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200605 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 return ret;
607 }
608
609 ret = ath10k_vdev_setup_sync(ar);
610 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200611 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200612 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return ret;
614 }
615
616 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 goto vdev_stop;
621 }
622
623 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624
Michal Kazior7aa7a722014-08-25 12:09:38 +0200625 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300626 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627 return 0;
628
629vdev_stop:
630 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200632 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200633 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634
635 return ret;
636}
637
Michal Kazior1bbc0972014-04-08 09:45:47 +0300638static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300639{
640 int ret = 0;
641
642 lockdep_assert_held(&ar->conf_mutex);
643
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200644 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
645 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200646 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200647 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648
Michal Kazior7962b0d2014-10-28 10:34:38 +0100649 reinit_completion(&ar->vdev_setup_done);
650
Kalle Valo5e3dd152013-06-12 20:52:10 +0300651 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
652 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200653 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200654 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655
656 ret = ath10k_vdev_setup_sync(ar);
657 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200658 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200659 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660
Michal Kazior7aa7a722014-08-25 12:09:38 +0200661 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300662 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 return ret;
664}
665
Michal Kazior1bbc0972014-04-08 09:45:47 +0300666static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667{
668 int bit, ret = 0;
669
670 lockdep_assert_held(&ar->conf_mutex);
671
Ben Greeara9aefb32014-08-12 11:02:19 +0300672 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200673 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 return -ENOMEM;
675 }
676
Ben Greear16c11172014-09-23 14:17:16 -0700677 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300678
Ben Greear16c11172014-09-23 14:17:16 -0700679 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr);
684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200685 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200686 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300687 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688 }
689
Ben Greear16c11172014-09-23 14:17:16 -0700690 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200691 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 ar->monitor_vdev_id);
693
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695}
696
Michal Kazior1bbc0972014-04-08 09:45:47 +0300697static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300698{
699 int ret = 0;
700
701 lockdep_assert_held(&ar->conf_mutex);
702
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200705 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200706 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707 return ret;
708 }
709
Ben Greear16c11172014-09-23 14:17:16 -0700710 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300711
Michal Kazior7aa7a722014-08-25 12:09:38 +0200712 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300713 ar->monitor_vdev_id);
714 return ret;
715}
716
Michal Kazior1bbc0972014-04-08 09:45:47 +0300717static int ath10k_monitor_start(struct ath10k *ar)
718{
719 int ret;
720
721 lockdep_assert_held(&ar->conf_mutex);
722
Michal Kazior1bbc0972014-04-08 09:45:47 +0300723 ret = ath10k_monitor_vdev_create(ar);
724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200725 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300726 return ret;
727 }
728
729 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
730 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200731 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300732 ath10k_monitor_vdev_delete(ar);
733 return ret;
734 }
735
736 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300738
739 return 0;
740}
741
Michal Kazior19337472014-08-28 12:58:16 +0200742static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300743{
744 int ret;
745
746 lockdep_assert_held(&ar->conf_mutex);
747
Michal Kazior1bbc0972014-04-08 09:45:47 +0300748 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200749 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200750 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200751 return ret;
752 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300753
754 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200755 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200756 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200757 return ret;
758 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300759
760 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200761 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200762
763 return 0;
764}
765
766static int ath10k_monitor_recalc(struct ath10k *ar)
767{
768 bool should_start;
769
770 lockdep_assert_held(&ar->conf_mutex);
771
772 should_start = ar->monitor ||
773 ar->filter_flags & FIF_PROMISC_IN_BSS ||
774 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
775
776 ath10k_dbg(ar, ATH10K_DBG_MAC,
777 "mac monitor recalc started? %d should? %d\n",
778 ar->monitor_started, should_start);
779
780 if (should_start == ar->monitor_started)
781 return 0;
782
783 if (should_start)
784 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300785
786 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300787}
788
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200789static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
790{
791 struct ath10k *ar = arvif->ar;
792 u32 vdev_param, rts_cts = 0;
793
794 lockdep_assert_held(&ar->conf_mutex);
795
796 vdev_param = ar->wmi.vdev_param->enable_rtscts;
797
798 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
799 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
800
801 if (arvif->num_legacy_stations > 0)
802 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
803 WMI_RTSCTS_PROFILE);
804
805 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
806 rts_cts);
807}
808
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200809static int ath10k_start_cac(struct ath10k *ar)
810{
811 int ret;
812
813 lockdep_assert_held(&ar->conf_mutex);
814
815 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
816
Michal Kazior19337472014-08-28 12:58:16 +0200817 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200819 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200820 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
821 return ret;
822 }
823
Michal Kazior7aa7a722014-08-25 12:09:38 +0200824 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200825 ar->monitor_vdev_id);
826
827 return 0;
828}
829
830static int ath10k_stop_cac(struct ath10k *ar)
831{
832 lockdep_assert_held(&ar->conf_mutex);
833
834 /* CAC is not running - do nothing */
835 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
836 return 0;
837
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300839 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200840
Michal Kazior7aa7a722014-08-25 12:09:38 +0200841 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200842
843 return 0;
844}
845
Michal Kaziord6500972014-04-08 09:56:09 +0300846static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200847{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200848 int ret;
849
850 lockdep_assert_held(&ar->conf_mutex);
851
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200852 ath10k_stop_cac(ar);
853
Michal Kaziord6500972014-04-08 09:56:09 +0300854 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200855 return;
856
Michal Kaziord6500972014-04-08 09:56:09 +0300857 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200858 return;
859
860 ret = ath10k_start_cac(ar);
861 if (ret) {
862 /*
863 * Not possible to start CAC on current channel so starting
864 * radiation is not allowed, make this channel DFS_UNAVAILABLE
865 * by indicating that radar was detected.
866 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200867 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200868 ieee80211_radar_detected(ar->hw);
869 }
870}
871
Michal Kaziordc55e302014-07-29 12:53:36 +0300872static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300873{
874 struct ath10k *ar = arvif->ar;
875 struct cfg80211_chan_def *chandef = &ar->chandef;
876 struct wmi_vdev_start_request_arg arg = {};
877 int ret = 0;
878
879 lockdep_assert_held(&ar->conf_mutex);
880
881 reinit_completion(&ar->vdev_setup_done);
882
883 arg.vdev_id = arvif->vdev_id;
884 arg.dtim_period = arvif->dtim_period;
885 arg.bcn_intval = arvif->beacon_interval;
886
887 arg.channel.freq = chandef->chan->center_freq;
888 arg.channel.band_center_freq1 = chandef->center_freq1;
889 arg.channel.mode = chan_to_phymode(chandef);
890
891 arg.channel.min_power = 0;
892 arg.channel.max_power = chandef->chan->max_power * 2;
893 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
894 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
895
896 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
897 arg.ssid = arvif->u.ap.ssid;
898 arg.ssid_len = arvif->u.ap.ssid_len;
899 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
900
901 /* For now allow DFS for AP mode */
902 arg.channel.chan_radar =
903 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
904 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
905 arg.ssid = arvif->vif->bss_conf.ssid;
906 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
907 }
908
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 "mac vdev %d start center_freq %d phymode %s\n",
911 arg.vdev_id, arg.channel.freq,
912 ath10k_wmi_phymode_str(arg.channel.mode));
913
Michal Kaziordc55e302014-07-29 12:53:36 +0300914 if (restart)
915 ret = ath10k_wmi_vdev_restart(ar, &arg);
916 else
917 ret = ath10k_wmi_vdev_start(ar, &arg);
918
Michal Kazior72654fa2014-04-08 09:56:09 +0300919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200920 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300921 arg.vdev_id, ret);
922 return ret;
923 }
924
925 ret = ath10k_vdev_setup_sync(ar);
926 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200927 ath10k_warn(ar,
928 "failed to synchronize setup for vdev %i restart %d: %d\n",
929 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +0300930 return ret;
931 }
932
Michal Kaziord6500972014-04-08 09:56:09 +0300933 ar->num_started_vdevs++;
934 ath10k_recalc_radar_detection(ar);
935
Michal Kazior72654fa2014-04-08 09:56:09 +0300936 return ret;
937}
938
Michal Kaziordc55e302014-07-29 12:53:36 +0300939static int ath10k_vdev_start(struct ath10k_vif *arvif)
940{
941 return ath10k_vdev_start_restart(arvif, false);
942}
943
944static int ath10k_vdev_restart(struct ath10k_vif *arvif)
945{
946 return ath10k_vdev_start_restart(arvif, true);
947}
948
Michal Kazior72654fa2014-04-08 09:56:09 +0300949static int ath10k_vdev_stop(struct ath10k_vif *arvif)
950{
951 struct ath10k *ar = arvif->ar;
952 int ret;
953
954 lockdep_assert_held(&ar->conf_mutex);
955
956 reinit_completion(&ar->vdev_setup_done);
957
958 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
959 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300961 arvif->vdev_id, ret);
962 return ret;
963 }
964
965 ret = ath10k_vdev_setup_sync(ar);
966 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200967 ath10k_warn(ar, "failed to synchronize setup for vdev %i stop: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300968 arvif->vdev_id, ret);
969 return ret;
970 }
971
Michal Kaziord6500972014-04-08 09:56:09 +0300972 WARN_ON(ar->num_started_vdevs == 0);
973
974 if (ar->num_started_vdevs != 0) {
975 ar->num_started_vdevs--;
976 ath10k_recalc_radar_detection(ar);
977 }
978
Michal Kazior72654fa2014-04-08 09:56:09 +0300979 return ret;
980}
981
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200982static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
983 struct sk_buff *bcn)
984{
985 struct ath10k *ar = arvif->ar;
986 struct ieee80211_mgmt *mgmt;
987 const u8 *p2p_ie;
988 int ret;
989
990 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
991 return 0;
992
993 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
994 return 0;
995
996 mgmt = (void *)bcn->data;
997 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
998 mgmt->u.beacon.variable,
999 bcn->len - (mgmt->u.beacon.variable -
1000 bcn->data));
1001 if (!p2p_ie)
1002 return -ENOENT;
1003
1004 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1005 if (ret) {
1006 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1007 arvif->vdev_id, ret);
1008 return ret;
1009 }
1010
1011 return 0;
1012}
1013
1014static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1015 u8 oui_type, size_t ie_offset)
1016{
1017 size_t len;
1018 const u8 *next;
1019 const u8 *end;
1020 u8 *ie;
1021
1022 if (WARN_ON(skb->len < ie_offset))
1023 return -EINVAL;
1024
1025 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1026 skb->data + ie_offset,
1027 skb->len - ie_offset);
1028 if (!ie)
1029 return -ENOENT;
1030
1031 len = ie[1] + 2;
1032 end = skb->data + skb->len;
1033 next = ie + len;
1034
1035 if (WARN_ON(next > end))
1036 return -EINVAL;
1037
1038 memmove(ie, next, end - next);
1039 skb_trim(skb, skb->len - len);
1040
1041 return 0;
1042}
1043
1044static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1045{
1046 struct ath10k *ar = arvif->ar;
1047 struct ieee80211_hw *hw = ar->hw;
1048 struct ieee80211_vif *vif = arvif->vif;
1049 struct ieee80211_mutable_offsets offs = {};
1050 struct sk_buff *bcn;
1051 int ret;
1052
1053 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1054 return 0;
1055
1056 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1057 if (!bcn) {
1058 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1059 return -EPERM;
1060 }
1061
1062 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1063 if (ret) {
1064 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1065 kfree_skb(bcn);
1066 return ret;
1067 }
1068
1069 /* P2P IE is inserted by firmware automatically (as configured above)
1070 * so remove it from the base beacon template to avoid duplicate P2P
1071 * IEs in beacon frames.
1072 */
1073 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1074 offsetof(struct ieee80211_mgmt,
1075 u.beacon.variable));
1076
1077 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1078 0, NULL, 0);
1079 kfree_skb(bcn);
1080
1081 if (ret) {
1082 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1083 ret);
1084 return ret;
1085 }
1086
1087 return 0;
1088}
1089
1090static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1091{
1092 struct ath10k *ar = arvif->ar;
1093 struct ieee80211_hw *hw = ar->hw;
1094 struct ieee80211_vif *vif = arvif->vif;
1095 struct sk_buff *prb;
1096 int ret;
1097
1098 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1099 return 0;
1100
1101 prb = ieee80211_proberesp_get(hw, vif);
1102 if (!prb) {
1103 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1104 return -EPERM;
1105 }
1106
1107 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1108 kfree_skb(prb);
1109
1110 if (ret) {
1111 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1112 ret);
1113 return ret;
1114 }
1115
1116 return 0;
1117}
1118
Kalle Valo5e3dd152013-06-12 20:52:10 +03001119static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001120 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001121{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001122 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 int ret = 0;
1124
Michal Kazior548db542013-07-05 16:15:15 +03001125 lockdep_assert_held(&arvif->ar->conf_mutex);
1126
Kalle Valo5e3dd152013-06-12 20:52:10 +03001127 if (!info->enable_beacon) {
1128 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001129
1130 arvif->is_started = false;
1131 arvif->is_up = false;
1132
Michal Kazior748afc42014-01-23 12:48:21 +01001133 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001134 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001135 spin_unlock_bh(&arvif->ar->data_lock);
1136
Kalle Valo5e3dd152013-06-12 20:52:10 +03001137 return;
1138 }
1139
1140 arvif->tx_seq_no = 0x1000;
1141
1142 ret = ath10k_vdev_start(arvif);
1143 if (ret)
1144 return;
1145
Michal Kaziorc930f742014-01-23 11:38:25 +01001146 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001147 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001148
1149 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1150 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001152 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001153 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001154 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001155 return;
1156 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001157
1158 arvif->is_started = true;
1159 arvif->is_up = true;
1160
Michal Kazior7aa7a722014-08-25 12:09:38 +02001161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162}
1163
1164static void ath10k_control_ibss(struct ath10k_vif *arvif,
1165 struct ieee80211_bss_conf *info,
1166 const u8 self_peer[ETH_ALEN])
1167{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001168 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001169 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001170 int ret = 0;
1171
Michal Kazior548db542013-07-05 16:15:15 +03001172 lockdep_assert_held(&arvif->ar->conf_mutex);
1173
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174 if (!info->ibss_joined) {
1175 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1176 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001177 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001178 self_peer, arvif->vdev_id, ret);
1179
Michal Kaziorc930f742014-01-23 11:38:25 +01001180 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001181 return;
1182
Michal Kaziorc930f742014-01-23 11:38:25 +01001183 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001184
1185 return;
1186 }
1187
1188 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001190 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001191 self_peer, arvif->vdev_id, ret);
1192 return;
1193 }
1194
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001195 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1196 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197 ATH10K_DEFAULT_ATIM);
1198 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001199 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001200 arvif->vdev_id, ret);
1201}
1202
Michal Kazior9f9b5742014-12-12 12:41:36 +01001203static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1204{
1205 struct ath10k *ar = arvif->ar;
1206 u32 param;
1207 u32 value;
1208 int ret;
1209
1210 lockdep_assert_held(&arvif->ar->conf_mutex);
1211
1212 if (arvif->u.sta.uapsd)
1213 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1214 else
1215 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1216
1217 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1218 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1219 if (ret) {
1220 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1221 value, arvif->vdev_id, ret);
1222 return ret;
1223 }
1224
1225 return 0;
1226}
1227
1228static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1229{
1230 struct ath10k *ar = arvif->ar;
1231 u32 param;
1232 u32 value;
1233 int ret;
1234
1235 lockdep_assert_held(&arvif->ar->conf_mutex);
1236
1237 if (arvif->u.sta.uapsd)
1238 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1239 else
1240 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1241
1242 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1243 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1244 param, value);
1245 if (ret) {
1246 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1247 value, arvif->vdev_id, ret);
1248 return ret;
1249 }
1250
1251 return 0;
1252}
1253
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001254static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1255{
1256 struct ath10k_vif *arvif;
1257 int num = 0;
1258
1259 lockdep_assert_held(&ar->conf_mutex);
1260
1261 list_for_each_entry(arvif, &ar->arvifs, list)
1262 if (arvif->ps)
1263 num++;
1264
1265 return num;
1266}
1267
Michal Kaziorad088bf2013-10-16 15:44:46 +03001268static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001269{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001270 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001271 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001272 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001273 enum wmi_sta_powersave_param param;
1274 enum wmi_sta_ps_mode psmode;
1275 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001276 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001277 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001278
Michal Kazior548db542013-07-05 16:15:15 +03001279 lockdep_assert_held(&arvif->ar->conf_mutex);
1280
Michal Kaziorad088bf2013-10-16 15:44:46 +03001281 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1282 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001284 enable_ps = arvif->ps;
1285
1286 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1287 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1288 ar->fw_features)) {
1289 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1290 arvif->vdev_id);
1291 enable_ps = false;
1292 }
1293
1294 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295 psmode = WMI_STA_PS_MODE_ENABLED;
1296 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1297
Michal Kazior526549a2014-12-12 12:41:37 +01001298 ps_timeout = conf->dynamic_ps_timeout;
1299 if (ps_timeout == 0) {
1300 /* Firmware doesn't like 0 */
1301 ps_timeout = ieee80211_tu_to_usec(
1302 vif->bss_conf.beacon_int) / 1000;
1303 }
1304
Michal Kaziorad088bf2013-10-16 15:44:46 +03001305 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001306 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001307 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001308 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001309 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001310 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001311 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312 } else {
1313 psmode = WMI_STA_PS_MODE_DISABLED;
1314 }
1315
Michal Kazior7aa7a722014-08-25 12:09:38 +02001316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001317 arvif->vdev_id, psmode ? "enable" : "disable");
1318
Michal Kaziorad088bf2013-10-16 15:44:46 +03001319 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1320 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001321 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001322 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001323 return ret;
1324 }
1325
1326 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001327}
1328
Michal Kazior46725b152015-01-28 09:57:49 +02001329static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1330{
1331 struct ath10k *ar = arvif->ar;
1332 struct wmi_sta_keepalive_arg arg = {};
1333 int ret;
1334
1335 lockdep_assert_held(&arvif->ar->conf_mutex);
1336
1337 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1338 return 0;
1339
1340 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1341 return 0;
1342
1343 /* Some firmware revisions have a bug and ignore the `enabled` field.
1344 * Instead use the interval to disable the keepalive.
1345 */
1346 arg.vdev_id = arvif->vdev_id;
1347 arg.enabled = 1;
1348 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1349 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1350
1351 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1352 if (ret) {
1353 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1354 arvif->vdev_id, ret);
1355 return ret;
1356 }
1357
1358 return 0;
1359}
1360
Kalle Valo5e3dd152013-06-12 20:52:10 +03001361/**********************/
1362/* Station management */
1363/**********************/
1364
Michal Kazior590922a2014-10-21 10:10:29 +03001365static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1366 struct ieee80211_vif *vif)
1367{
1368 /* Some firmware revisions have unstable STA powersave when listen
1369 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1370 * generate NullFunc frames properly even if buffered frames have been
1371 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1372 * buffered frames. Often pinging the device from AP would simply fail.
1373 *
1374 * As a workaround set it to 1.
1375 */
1376 if (vif->type == NL80211_IFTYPE_STATION)
1377 return 1;
1378
1379 return ar->hw->conf.listen_interval;
1380}
1381
Kalle Valo5e3dd152013-06-12 20:52:10 +03001382static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001383 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 struct wmi_peer_assoc_complete_arg *arg)
1386{
Michal Kazior590922a2014-10-21 10:10:29 +03001387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1388
Michal Kazior548db542013-07-05 16:15:15 +03001389 lockdep_assert_held(&ar->conf_mutex);
1390
Kalle Valob25f32c2014-09-14 12:50:49 +03001391 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001392 arg->vdev_id = arvif->vdev_id;
1393 arg->peer_aid = sta->aid;
1394 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001395 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001396 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001397 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398}
1399
1400static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001401 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001402 struct wmi_peer_assoc_complete_arg *arg)
1403{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001404 struct ieee80211_bss_conf *info = &vif->bss_conf;
1405 struct cfg80211_bss *bss;
1406 const u8 *rsnie = NULL;
1407 const u8 *wpaie = NULL;
1408
Michal Kazior548db542013-07-05 16:15:15 +03001409 lockdep_assert_held(&ar->conf_mutex);
1410
Kalle Valo5e3dd152013-06-12 20:52:10 +03001411 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1412 info->bssid, NULL, 0, 0, 0);
1413 if (bss) {
1414 const struct cfg80211_bss_ies *ies;
1415
1416 rcu_read_lock();
1417 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1418
1419 ies = rcu_dereference(bss->ies);
1420
1421 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001422 WLAN_OUI_TYPE_MICROSOFT_WPA,
1423 ies->data,
1424 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001425 rcu_read_unlock();
1426 cfg80211_put_bss(ar->hw->wiphy, bss);
1427 }
1428
1429 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1430 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001431 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001432 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1433 }
1434
1435 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001436 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001437 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1438 }
1439}
1440
1441static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1442 struct ieee80211_sta *sta,
1443 struct wmi_peer_assoc_complete_arg *arg)
1444{
1445 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1446 const struct ieee80211_supported_band *sband;
1447 const struct ieee80211_rate *rates;
1448 u32 ratemask;
1449 int i;
1450
Michal Kazior548db542013-07-05 16:15:15 +03001451 lockdep_assert_held(&ar->conf_mutex);
1452
Kalle Valo5e3dd152013-06-12 20:52:10 +03001453 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1454 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1455 rates = sband->bitrates;
1456
1457 rateset->num_rates = 0;
1458
1459 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1460 if (!(ratemask & 1))
1461 continue;
1462
1463 rateset->rates[rateset->num_rates] = rates->hw_value;
1464 rateset->num_rates++;
1465 }
1466}
1467
1468static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1469 struct ieee80211_sta *sta,
1470 struct wmi_peer_assoc_complete_arg *arg)
1471{
1472 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001473 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001474 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001475
Michal Kazior548db542013-07-05 16:15:15 +03001476 lockdep_assert_held(&ar->conf_mutex);
1477
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478 if (!ht_cap->ht_supported)
1479 return;
1480
1481 arg->peer_flags |= WMI_PEER_HT;
1482 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1483 ht_cap->ampdu_factor)) - 1;
1484
1485 arg->peer_mpdu_density =
1486 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1487
1488 arg->peer_ht_caps = ht_cap->cap;
1489 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1490
1491 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1492 arg->peer_flags |= WMI_PEER_LDPC;
1493
1494 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1495 arg->peer_flags |= WMI_PEER_40MHZ;
1496 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1497 }
1498
1499 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1500 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1501
1502 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1503 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1504
1505 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1506 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1507 arg->peer_flags |= WMI_PEER_STBC;
1508 }
1509
1510 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001511 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1512 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1513 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1514 arg->peer_rate_caps |= stbc;
1515 arg->peer_flags |= WMI_PEER_STBC;
1516 }
1517
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1519 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1520 else if (ht_cap->mcs.rx_mask[1])
1521 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1522
1523 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1524 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1525 arg->peer_ht_rates.rates[n++] = i;
1526
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001527 /*
1528 * This is a workaround for HT-enabled STAs which break the spec
1529 * and have no HT capabilities RX mask (no HT RX MCS map).
1530 *
1531 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1532 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1533 *
1534 * Firmware asserts if such situation occurs.
1535 */
1536 if (n == 0) {
1537 arg->peer_ht_rates.num_rates = 8;
1538 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1539 arg->peer_ht_rates.rates[i] = i;
1540 } else {
1541 arg->peer_ht_rates.num_rates = n;
1542 arg->peer_num_spatial_streams = sta->rx_nss;
1543 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001544
Michal Kazior7aa7a722014-08-25 12:09:38 +02001545 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001546 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001547 arg->peer_ht_rates.num_rates,
1548 arg->peer_num_spatial_streams);
1549}
1550
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001551static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1552 struct ath10k_vif *arvif,
1553 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554{
1555 u32 uapsd = 0;
1556 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001557 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558
Michal Kazior548db542013-07-05 16:15:15 +03001559 lockdep_assert_held(&ar->conf_mutex);
1560
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001562 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001563 sta->uapsd_queues, sta->max_sp);
1564
Kalle Valo5e3dd152013-06-12 20:52:10 +03001565 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1566 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1567 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1568 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1569 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1570 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1571 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1572 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1573 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1574 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1575 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1576 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1577
Kalle Valo5e3dd152013-06-12 20:52:10 +03001578 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1579 max_sp = sta->max_sp;
1580
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001581 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1582 sta->addr,
1583 WMI_AP_PS_PEER_PARAM_UAPSD,
1584 uapsd);
1585 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001586 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001587 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001588 return ret;
1589 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001591 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1592 sta->addr,
1593 WMI_AP_PS_PEER_PARAM_MAX_SP,
1594 max_sp);
1595 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001596 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001597 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001598 return ret;
1599 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600
1601 /* TODO setup this based on STA listen interval and
1602 beacon interval. Currently we don't know
1603 sta->listen_interval - mac80211 patch required.
1604 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001605 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001606 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1607 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001609 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001610 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001611 return ret;
1612 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001613 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001614
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001615 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616}
1617
1618static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1619 struct ieee80211_sta *sta,
1620 struct wmi_peer_assoc_complete_arg *arg)
1621{
1622 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001623 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624
1625 if (!vht_cap->vht_supported)
1626 return;
1627
1628 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001629
1630 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1631 arg->peer_flags |= WMI_PEER_VHT_2G;
1632
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 arg->peer_vht_caps = vht_cap->cap;
1634
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001635 ampdu_factor = (vht_cap->cap &
1636 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1637 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1638
1639 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1640 * zero in VHT IE. Using it would result in degraded throughput.
1641 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1642 * it if VHT max_mpdu is smaller. */
1643 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1644 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1645 ampdu_factor)) - 1);
1646
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1648 arg->peer_flags |= WMI_PEER_80MHZ;
1649
1650 arg->peer_vht_rates.rx_max_rate =
1651 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1652 arg->peer_vht_rates.rx_mcs_set =
1653 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1654 arg->peer_vht_rates.tx_max_rate =
1655 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1656 arg->peer_vht_rates.tx_mcs_set =
1657 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1658
Michal Kazior7aa7a722014-08-25 12:09:38 +02001659 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001660 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661}
1662
1663static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001664 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001665 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666 struct wmi_peer_assoc_complete_arg *arg)
1667{
Michal Kazior590922a2014-10-21 10:10:29 +03001668 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1669
Kalle Valo5e3dd152013-06-12 20:52:10 +03001670 switch (arvif->vdev_type) {
1671 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001672 if (sta->wme)
1673 arg->peer_flags |= WMI_PEER_QOS;
1674
1675 if (sta->wme && sta->uapsd_queues) {
1676 arg->peer_flags |= WMI_PEER_APSD;
1677 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1678 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 break;
1680 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001681 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001682 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001684 case WMI_VDEV_TYPE_IBSS:
1685 if (sta->wme)
1686 arg->peer_flags |= WMI_PEER_QOS;
1687 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001688 default:
1689 break;
1690 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001691
1692 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1693 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001694}
1695
Michal Kazior91b12082014-12-12 12:41:35 +01001696static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1697{
1698 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1699 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1700}
1701
Kalle Valo5e3dd152013-06-12 20:52:10 +03001702static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001703 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001704 struct ieee80211_sta *sta,
1705 struct wmi_peer_assoc_complete_arg *arg)
1706{
1707 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1708
Kalle Valo5e3dd152013-06-12 20:52:10 +03001709 switch (ar->hw->conf.chandef.chan->band) {
1710 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001711 if (sta->vht_cap.vht_supported) {
1712 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1713 phymode = MODE_11AC_VHT40;
1714 else
1715 phymode = MODE_11AC_VHT20;
1716 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001717 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1718 phymode = MODE_11NG_HT40;
1719 else
1720 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001721 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001723 } else {
1724 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001725 }
1726
1727 break;
1728 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001729 /*
1730 * Check VHT first.
1731 */
1732 if (sta->vht_cap.vht_supported) {
1733 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1734 phymode = MODE_11AC_VHT80;
1735 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1736 phymode = MODE_11AC_VHT40;
1737 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1738 phymode = MODE_11AC_VHT20;
1739 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001740 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1741 phymode = MODE_11NA_HT40;
1742 else
1743 phymode = MODE_11NA_HT20;
1744 } else {
1745 phymode = MODE_11A;
1746 }
1747
1748 break;
1749 default:
1750 break;
1751 }
1752
Michal Kazior7aa7a722014-08-25 12:09:38 +02001753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001754 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001755
Kalle Valo5e3dd152013-06-12 20:52:10 +03001756 arg->peer_phymode = phymode;
1757 WARN_ON(phymode == MODE_UNKNOWN);
1758}
1759
Kalle Valob9ada652013-10-16 15:44:46 +03001760static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001761 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001762 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001763 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001764{
Michal Kazior548db542013-07-05 16:15:15 +03001765 lockdep_assert_held(&ar->conf_mutex);
1766
Kalle Valob9ada652013-10-16 15:44:46 +03001767 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001768
Michal Kazior590922a2014-10-21 10:10:29 +03001769 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1770 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001771 ath10k_peer_assoc_h_rates(ar, sta, arg);
1772 ath10k_peer_assoc_h_ht(ar, sta, arg);
1773 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001774 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1775 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776
Kalle Valob9ada652013-10-16 15:44:46 +03001777 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778}
1779
Michal Kazior90046f52014-02-14 14:45:51 +01001780static const u32 ath10k_smps_map[] = {
1781 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1782 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1783 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1784 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1785};
1786
1787static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1788 const u8 *addr,
1789 const struct ieee80211_sta_ht_cap *ht_cap)
1790{
1791 int smps;
1792
1793 if (!ht_cap->ht_supported)
1794 return 0;
1795
1796 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1797 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1798
1799 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1800 return -EINVAL;
1801
1802 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1803 WMI_PEER_SMPS_STATE,
1804 ath10k_smps_map[smps]);
1805}
1806
Michal Kazior139e1702015-02-15 16:50:42 +02001807static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1808 struct ieee80211_vif *vif,
1809 struct ieee80211_sta_vht_cap vht_cap)
1810{
1811 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1812 int ret;
1813 u32 param;
1814 u32 value;
1815
1816 if (!(ar->vht_cap_info &
1817 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1818 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1819 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1820 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1821 return 0;
1822
1823 param = ar->wmi.vdev_param->txbf;
1824 value = 0;
1825
1826 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1827 return 0;
1828
1829 /* The following logic is correct. If a remote STA advertises support
1830 * for being a beamformer then we should enable us being a beamformee.
1831 */
1832
1833 if (ar->vht_cap_info &
1834 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1835 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1836 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1837 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1838
1839 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1840 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1841 }
1842
1843 if (ar->vht_cap_info &
1844 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1845 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1846 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1847 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1848
1849 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
1850 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
1851 }
1852
1853 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
1854 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1855
1856 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
1857 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1858
1859 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
1860 if (ret) {
1861 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
1862 value, ret);
1863 return ret;
1864 }
1865
1866 return 0;
1867}
1868
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869/* can be called only in mac80211 callbacks due to `key_count` usage */
1870static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1871 struct ieee80211_vif *vif,
1872 struct ieee80211_bss_conf *bss_conf)
1873{
1874 struct ath10k *ar = hw->priv;
1875 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001876 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001877 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001878 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001879 struct ieee80211_sta *ap_sta;
1880 int ret;
1881
Michal Kazior548db542013-07-05 16:15:15 +03001882 lockdep_assert_held(&ar->conf_mutex);
1883
Michal Kazior077efc82014-10-21 10:10:29 +03001884 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1885 arvif->vdev_id, arvif->bssid, arvif->aid);
1886
Kalle Valo5e3dd152013-06-12 20:52:10 +03001887 rcu_read_lock();
1888
1889 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1890 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001891 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001892 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001893 rcu_read_unlock();
1894 return;
1895 }
1896
Michal Kazior90046f52014-02-14 14:45:51 +01001897 /* ap_sta must be accessed only within rcu section which must be left
1898 * before calling ath10k_setup_peer_smps() which might sleep. */
1899 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001900 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01001901
Michal Kazior590922a2014-10-21 10:10:29 +03001902 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001904 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001905 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001906 rcu_read_unlock();
1907 return;
1908 }
1909
1910 rcu_read_unlock();
1911
Kalle Valob9ada652013-10-16 15:44:46 +03001912 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1913 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001914 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001915 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001916 return;
1917 }
1918
Michal Kazior90046f52014-02-14 14:45:51 +01001919 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1920 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001921 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001922 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001923 return;
1924 }
1925
Michal Kazior139e1702015-02-15 16:50:42 +02001926 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1927 if (ret) {
1928 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
1929 arvif->vdev_id, bss_conf->bssid, ret);
1930 return;
1931 }
1932
Michal Kazior7aa7a722014-08-25 12:09:38 +02001933 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001934 "mac vdev %d up (associated) bssid %pM aid %d\n",
1935 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1936
Michal Kazior077efc82014-10-21 10:10:29 +03001937 WARN_ON(arvif->is_up);
1938
Michal Kaziorc930f742014-01-23 11:38:25 +01001939 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001940 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001941
1942 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1943 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001944 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001946 return;
1947 }
1948
1949 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01001950
1951 /* Workaround: Some firmware revisions (tested with qca6174
1952 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
1953 * poked with peer param command.
1954 */
1955 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
1956 WMI_PEER_DUMMY_VAR, 1);
1957 if (ret) {
1958 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
1959 arvif->bssid, arvif->vdev_id, ret);
1960 return;
1961 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962}
1963
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1965 struct ieee80211_vif *vif)
1966{
1967 struct ath10k *ar = hw->priv;
1968 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02001969 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03001970 int ret;
1971
Michal Kazior548db542013-07-05 16:15:15 +03001972 lockdep_assert_held(&ar->conf_mutex);
1973
Michal Kazior077efc82014-10-21 10:10:29 +03001974 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1975 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001976
Kalle Valo5e3dd152013-06-12 20:52:10 +03001977 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001978 if (ret)
1979 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1980 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001982 arvif->def_wep_key_idx = -1;
1983
Michal Kazior139e1702015-02-15 16:50:42 +02001984 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1985 if (ret) {
1986 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
1987 arvif->vdev_id, ret);
1988 return;
1989 }
1990
Michal Kaziorc930f742014-01-23 11:38:25 +01001991 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992}
1993
Michal Kazior590922a2014-10-21 10:10:29 +03001994static int ath10k_station_assoc(struct ath10k *ar,
1995 struct ieee80211_vif *vif,
1996 struct ieee80211_sta *sta,
1997 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998{
Michal Kazior590922a2014-10-21 10:10:29 +03001999 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002000 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 int ret = 0;
2002
Michal Kazior548db542013-07-05 16:15:15 +03002003 lockdep_assert_held(&ar->conf_mutex);
2004
Michal Kazior590922a2014-10-21 10:10:29 +03002005 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002007 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002008 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002009 return ret;
2010 }
2011
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002012 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002013 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2014 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002015 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002016 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 return ret;
2018 }
2019
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002020 /* Re-assoc is run only to update supported rates for given station. It
2021 * doesn't make much sense to reconfigure the peer completely.
2022 */
2023 if (!reassoc) {
2024 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2025 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002026 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002027 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002028 arvif->vdev_id, ret);
2029 return ret;
2030 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002031
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002032 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2033 if (ret) {
2034 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2035 sta->addr, arvif->vdev_id, ret);
2036 return ret;
2037 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002039 if (!sta->wme) {
2040 arvif->num_legacy_stations++;
2041 ret = ath10k_recalc_rtscts_prot(arvif);
2042 if (ret) {
2043 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2044 arvif->vdev_id, ret);
2045 return ret;
2046 }
2047 }
2048
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002049 /* Plumb cached keys only for static WEP */
2050 if (arvif->def_wep_key_idx != -1) {
2051 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2052 if (ret) {
2053 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2054 arvif->vdev_id, ret);
2055 return ret;
2056 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 }
2058 }
2059
Kalle Valo5e3dd152013-06-12 20:52:10 +03002060 return ret;
2061}
2062
Michal Kazior590922a2014-10-21 10:10:29 +03002063static int ath10k_station_disassoc(struct ath10k *ar,
2064 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002065 struct ieee80211_sta *sta)
2066{
Michal Kazior590922a2014-10-21 10:10:29 +03002067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 int ret = 0;
2069
2070 lockdep_assert_held(&ar->conf_mutex);
2071
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002072 if (!sta->wme) {
2073 arvif->num_legacy_stations--;
2074 ret = ath10k_recalc_rtscts_prot(arvif);
2075 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002076 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002077 arvif->vdev_id, ret);
2078 return ret;
2079 }
2080 }
2081
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2083 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002084 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002085 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002086 return ret;
2087 }
2088
2089 return ret;
2090}
2091
2092/**************/
2093/* Regulatory */
2094/**************/
2095
2096static int ath10k_update_channel_list(struct ath10k *ar)
2097{
2098 struct ieee80211_hw *hw = ar->hw;
2099 struct ieee80211_supported_band **bands;
2100 enum ieee80211_band band;
2101 struct ieee80211_channel *channel;
2102 struct wmi_scan_chan_list_arg arg = {0};
2103 struct wmi_channel_arg *ch;
2104 bool passive;
2105 int len;
2106 int ret;
2107 int i;
2108
Michal Kazior548db542013-07-05 16:15:15 +03002109 lockdep_assert_held(&ar->conf_mutex);
2110
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111 bands = hw->wiphy->bands;
2112 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2113 if (!bands[band])
2114 continue;
2115
2116 for (i = 0; i < bands[band]->n_channels; i++) {
2117 if (bands[band]->channels[i].flags &
2118 IEEE80211_CHAN_DISABLED)
2119 continue;
2120
2121 arg.n_channels++;
2122 }
2123 }
2124
2125 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2126 arg.channels = kzalloc(len, GFP_KERNEL);
2127 if (!arg.channels)
2128 return -ENOMEM;
2129
2130 ch = arg.channels;
2131 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2132 if (!bands[band])
2133 continue;
2134
2135 for (i = 0; i < bands[band]->n_channels; i++) {
2136 channel = &bands[band]->channels[i];
2137
2138 if (channel->flags & IEEE80211_CHAN_DISABLED)
2139 continue;
2140
2141 ch->allow_ht = true;
2142
2143 /* FIXME: when should we really allow VHT? */
2144 ch->allow_vht = true;
2145
2146 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002147 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002148
2149 ch->ht40plus =
2150 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2151
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002152 ch->chan_radar =
2153 !!(channel->flags & IEEE80211_CHAN_RADAR);
2154
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002155 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156 ch->passive = passive;
2157
2158 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002159 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002160 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002161 ch->max_power = channel->max_power * 2;
2162 ch->max_reg_power = channel->max_reg_power * 2;
2163 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002164 ch->reg_class_id = 0; /* FIXME */
2165
2166 /* FIXME: why use only legacy modes, why not any
2167 * HT/VHT modes? Would that even make any
2168 * difference? */
2169 if (channel->band == IEEE80211_BAND_2GHZ)
2170 ch->mode = MODE_11G;
2171 else
2172 ch->mode = MODE_11A;
2173
2174 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2175 continue;
2176
Michal Kazior7aa7a722014-08-25 12:09:38 +02002177 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002178 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2179 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180 ch->freq, ch->max_power, ch->max_reg_power,
2181 ch->max_antenna_gain, ch->mode);
2182
2183 ch++;
2184 }
2185 }
2186
2187 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2188 kfree(arg.channels);
2189
2190 return ret;
2191}
2192
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002193static enum wmi_dfs_region
2194ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2195{
2196 switch (dfs_region) {
2197 case NL80211_DFS_UNSET:
2198 return WMI_UNINIT_DFS_DOMAIN;
2199 case NL80211_DFS_FCC:
2200 return WMI_FCC_DFS_DOMAIN;
2201 case NL80211_DFS_ETSI:
2202 return WMI_ETSI_DFS_DOMAIN;
2203 case NL80211_DFS_JP:
2204 return WMI_MKK4_DFS_DOMAIN;
2205 }
2206 return WMI_UNINIT_DFS_DOMAIN;
2207}
2208
Michal Kaziorf7843d72013-07-16 09:38:52 +02002209static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002212 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002213 enum wmi_dfs_region wmi_dfs_reg;
2214 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215
Michal Kaziorf7843d72013-07-16 09:38:52 +02002216 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002217
2218 ret = ath10k_update_channel_list(ar);
2219 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002220 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002221
2222 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002223
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002224 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2225 nl_dfs_reg = ar->dfs_detector->region;
2226 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2227 } else {
2228 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2229 }
2230
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231 /* Target allows setting up per-band regdomain but ath_common provides
2232 * a combined one only */
2233 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002234 regpair->reg_domain,
2235 regpair->reg_domain, /* 2ghz */
2236 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002237 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002238 regpair->reg_5ghz_ctl,
2239 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002240 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002241 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002242}
Michal Kazior548db542013-07-05 16:15:15 +03002243
Michal Kaziorf7843d72013-07-16 09:38:52 +02002244static void ath10k_reg_notifier(struct wiphy *wiphy,
2245 struct regulatory_request *request)
2246{
2247 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2248 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002249 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002250
2251 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2252
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002253 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002254 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002255 request->dfs_region);
2256 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2257 request->dfs_region);
2258 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002259 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002260 request->dfs_region);
2261 }
2262
Michal Kaziorf7843d72013-07-16 09:38:52 +02002263 mutex_lock(&ar->conf_mutex);
2264 if (ar->state == ATH10K_STATE_ON)
2265 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002266 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002267}
2268
2269/***************/
2270/* TX handlers */
2271/***************/
2272
Michal Kazior42c3aa62013-10-02 11:03:38 +02002273static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2274{
2275 if (ieee80211_is_mgmt(hdr->frame_control))
2276 return HTT_DATA_TX_EXT_TID_MGMT;
2277
2278 if (!ieee80211_is_data_qos(hdr->frame_control))
2279 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2280
2281 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2282 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2283
2284 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2285}
2286
Michal Kazior2b37c292014-09-02 11:00:22 +03002287static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002288{
Michal Kazior2b37c292014-09-02 11:00:22 +03002289 if (vif)
2290 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002291
Michal Kazior1bbc0972014-04-08 09:45:47 +03002292 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002293 return ar->monitor_vdev_id;
2294
Michal Kazior7aa7a722014-08-25 12:09:38 +02002295 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002296 return 0;
2297}
2298
Michal Kazior4b604552014-07-21 21:03:09 +03002299/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2300 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301 */
Michal Kazior4b604552014-07-21 21:03:09 +03002302static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303{
2304 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002305 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 u8 *qos_ctl;
2307
2308 if (!ieee80211_is_data_qos(hdr->frame_control))
2309 return;
2310
2311 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002312 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2313 skb->data, (void *)qos_ctl - (void *)skb->data);
2314 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002315
2316 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2317 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2318 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2319 * it is safe to downgrade to NullFunc.
2320 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002321 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002322 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2323 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2324 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2325 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002326}
2327
Michal Kazior4b604552014-07-21 21:03:09 +03002328static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2329 struct ieee80211_vif *vif,
2330 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331{
2332 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2334
2335 /* This is case only for P2P_GO */
2336 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2337 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2338 return;
2339
2340 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2341 spin_lock_bh(&ar->data_lock);
2342 if (arvif->u.ap.noa_data)
2343 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2344 GFP_ATOMIC))
2345 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2346 arvif->u.ap.noa_data,
2347 arvif->u.ap.noa_len);
2348 spin_unlock_bh(&ar->data_lock);
2349 }
2350}
2351
Michal Kazior8d6d3622014-11-24 14:58:31 +01002352static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2353{
2354 /* FIXME: Not really sure since when the behaviour changed. At some
2355 * point new firmware stopped requiring creation of peer entries for
2356 * offchannel tx (and actually creating them causes issues with wmi-htc
2357 * tx credit replenishment and reliability). Assuming it's at least 3.4
2358 * because that's when the `freq` was introduced to TX_FRM HTT command.
2359 */
2360 return !(ar->htt.target_version_major >= 3 &&
2361 ar->htt.target_version_minor >= 4);
2362}
2363
Kalle Valo5e3dd152013-06-12 20:52:10 +03002364static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2365{
2366 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002367 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368
Michal Kazior961d4c32013-08-09 10:13:34 +02002369 if (ar->htt.target_version_major >= 3) {
2370 /* Since HTT 3.0 there is no separate mgmt tx command */
2371 ret = ath10k_htt_tx(&ar->htt, skb);
2372 goto exit;
2373 }
2374
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002375 if (ieee80211_is_mgmt(hdr->frame_control)) {
2376 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2377 ar->fw_features)) {
2378 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2379 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002380 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002381 ret = -EBUSY;
2382 goto exit;
2383 }
2384
2385 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2386 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2387 } else {
2388 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2389 }
2390 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2391 ar->fw_features) &&
2392 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002393 /* FW does not report tx status properly for NullFunc frames
2394 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002395 * those frames when it detects link/beacon loss and depends
2396 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002397 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002398 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002399 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002400 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002401
Michal Kazior961d4c32013-08-09 10:13:34 +02002402exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002403 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002404 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2405 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002406 ieee80211_free_txskb(ar->hw, skb);
2407 }
2408}
2409
2410void ath10k_offchan_tx_purge(struct ath10k *ar)
2411{
2412 struct sk_buff *skb;
2413
2414 for (;;) {
2415 skb = skb_dequeue(&ar->offchan_tx_queue);
2416 if (!skb)
2417 break;
2418
2419 ieee80211_free_txskb(ar->hw, skb);
2420 }
2421}
2422
2423void ath10k_offchan_tx_work(struct work_struct *work)
2424{
2425 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2426 struct ath10k_peer *peer;
2427 struct ieee80211_hdr *hdr;
2428 struct sk_buff *skb;
2429 const u8 *peer_addr;
2430 int vdev_id;
2431 int ret;
2432
2433 /* FW requirement: We must create a peer before FW will send out
2434 * an offchannel frame. Otherwise the frame will be stuck and
2435 * never transmitted. We delete the peer upon tx completion.
2436 * It is unlikely that a peer for offchannel tx will already be
2437 * present. However it may be in some rare cases so account for that.
2438 * Otherwise we might remove a legitimate peer and break stuff. */
2439
2440 for (;;) {
2441 skb = skb_dequeue(&ar->offchan_tx_queue);
2442 if (!skb)
2443 break;
2444
2445 mutex_lock(&ar->conf_mutex);
2446
Michal Kazior7aa7a722014-08-25 12:09:38 +02002447 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002448 skb);
2449
2450 hdr = (struct ieee80211_hdr *)skb->data;
2451 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002452 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453
2454 spin_lock_bh(&ar->data_lock);
2455 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2456 spin_unlock_bh(&ar->data_lock);
2457
2458 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002459 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002460 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461 peer_addr, vdev_id);
2462
2463 if (!peer) {
2464 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2465 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002466 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002467 peer_addr, vdev_id, ret);
2468 }
2469
2470 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002471 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472 ar->offchan_tx_skb = skb;
2473 spin_unlock_bh(&ar->data_lock);
2474
2475 ath10k_tx_htt(ar, skb);
2476
2477 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2478 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002479 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002480 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002481 skb);
2482
2483 if (!peer) {
2484 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2485 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002486 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002487 peer_addr, vdev_id, ret);
2488 }
2489
2490 mutex_unlock(&ar->conf_mutex);
2491 }
2492}
2493
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002494void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2495{
2496 struct sk_buff *skb;
2497
2498 for (;;) {
2499 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2500 if (!skb)
2501 break;
2502
2503 ieee80211_free_txskb(ar->hw, skb);
2504 }
2505}
2506
2507void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2508{
2509 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2510 struct sk_buff *skb;
2511 int ret;
2512
2513 for (;;) {
2514 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2515 if (!skb)
2516 break;
2517
2518 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002519 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002520 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002521 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002522 ieee80211_free_txskb(ar->hw, skb);
2523 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002524 }
2525}
2526
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527/************/
2528/* Scanning */
2529/************/
2530
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002531void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002532{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002533 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002535 switch (ar->scan.state) {
2536 case ATH10K_SCAN_IDLE:
2537 break;
2538 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002539 if (ar->scan.is_roc)
2540 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002541 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002542 case ATH10K_SCAN_ABORTING:
2543 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002544 ieee80211_scan_completed(ar->hw,
2545 (ar->scan.state ==
2546 ATH10K_SCAN_ABORTING));
2547 /* fall through */
2548 case ATH10K_SCAN_STARTING:
2549 ar->scan.state = ATH10K_SCAN_IDLE;
2550 ar->scan_channel = NULL;
2551 ath10k_offchan_tx_purge(ar);
2552 cancel_delayed_work(&ar->scan.timeout);
2553 complete_all(&ar->scan.completed);
2554 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002556}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002557
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002558void ath10k_scan_finish(struct ath10k *ar)
2559{
2560 spin_lock_bh(&ar->data_lock);
2561 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562 spin_unlock_bh(&ar->data_lock);
2563}
2564
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002565static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002566{
2567 struct wmi_stop_scan_arg arg = {
2568 .req_id = 1, /* FIXME */
2569 .req_type = WMI_SCAN_STOP_ONE,
2570 .u.scan_id = ATH10K_SCAN_ID,
2571 };
2572 int ret;
2573
2574 lockdep_assert_held(&ar->conf_mutex);
2575
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576 ret = ath10k_wmi_stop_scan(ar, &arg);
2577 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002578 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002579 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580 }
2581
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002583 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002584 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002585 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002586 } else if (ret > 0) {
2587 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002589
2590out:
2591 /* Scan state should be updated upon scan completion but in case
2592 * firmware fails to deliver the event (for whatever reason) it is
2593 * desired to clean up scan state anyway. Firmware may have just
2594 * dropped the scan completion event delivery due to transport pipe
2595 * being overflown with data and/or it can recover on its own before
2596 * next scan request is submitted.
2597 */
2598 spin_lock_bh(&ar->data_lock);
2599 if (ar->scan.state != ATH10K_SCAN_IDLE)
2600 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601 spin_unlock_bh(&ar->data_lock);
2602
2603 return ret;
2604}
2605
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002606static void ath10k_scan_abort(struct ath10k *ar)
2607{
2608 int ret;
2609
2610 lockdep_assert_held(&ar->conf_mutex);
2611
2612 spin_lock_bh(&ar->data_lock);
2613
2614 switch (ar->scan.state) {
2615 case ATH10K_SCAN_IDLE:
2616 /* This can happen if timeout worker kicked in and called
2617 * abortion while scan completion was being processed.
2618 */
2619 break;
2620 case ATH10K_SCAN_STARTING:
2621 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002622 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002623 ath10k_scan_state_str(ar->scan.state),
2624 ar->scan.state);
2625 break;
2626 case ATH10K_SCAN_RUNNING:
2627 ar->scan.state = ATH10K_SCAN_ABORTING;
2628 spin_unlock_bh(&ar->data_lock);
2629
2630 ret = ath10k_scan_stop(ar);
2631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002632 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002633
2634 spin_lock_bh(&ar->data_lock);
2635 break;
2636 }
2637
2638 spin_unlock_bh(&ar->data_lock);
2639}
2640
2641void ath10k_scan_timeout_work(struct work_struct *work)
2642{
2643 struct ath10k *ar = container_of(work, struct ath10k,
2644 scan.timeout.work);
2645
2646 mutex_lock(&ar->conf_mutex);
2647 ath10k_scan_abort(ar);
2648 mutex_unlock(&ar->conf_mutex);
2649}
2650
Kalle Valo5e3dd152013-06-12 20:52:10 +03002651static int ath10k_start_scan(struct ath10k *ar,
2652 const struct wmi_start_scan_arg *arg)
2653{
2654 int ret;
2655
2656 lockdep_assert_held(&ar->conf_mutex);
2657
2658 ret = ath10k_wmi_start_scan(ar, arg);
2659 if (ret)
2660 return ret;
2661
Kalle Valo5e3dd152013-06-12 20:52:10 +03002662 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2663 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002664 ret = ath10k_scan_stop(ar);
2665 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002666 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002667
2668 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669 }
2670
Ben Greear2f9eec02015-02-15 16:50:38 +02002671 /* If we failed to start the scan, return error code at
2672 * this point. This is probably due to some issue in the
2673 * firmware, but no need to wedge the driver due to that...
2674 */
2675 spin_lock_bh(&ar->data_lock);
2676 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2677 spin_unlock_bh(&ar->data_lock);
2678 return -EINVAL;
2679 }
2680 spin_unlock_bh(&ar->data_lock);
2681
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002682 /* Add a 200ms margin to account for event/command processing */
2683 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2684 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002685 return 0;
2686}
2687
2688/**********************/
2689/* mac80211 callbacks */
2690/**********************/
2691
2692static void ath10k_tx(struct ieee80211_hw *hw,
2693 struct ieee80211_tx_control *control,
2694 struct sk_buff *skb)
2695{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002697 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2698 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002699 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700
2701 /* We should disable CCK RATE due to P2P */
2702 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002703 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704
Michal Kazior4b604552014-07-21 21:03:09 +03002705 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2706 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002707 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002709 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002710 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2711 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002712 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2713 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002714 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002715
Kalle Valo5e3dd152013-06-12 20:52:10 +03002716 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2717 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002718 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002719 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002720 spin_unlock_bh(&ar->data_lock);
2721
Michal Kazior8d6d3622014-11-24 14:58:31 +01002722 if (ath10k_mac_need_offchan_tx_work(ar)) {
2723 ATH10K_SKB_CB(skb)->htt.freq = 0;
2724 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002725
Michal Kazior8d6d3622014-11-24 14:58:31 +01002726 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2727 skb);
2728
2729 skb_queue_tail(&ar->offchan_tx_queue, skb);
2730 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2731 return;
2732 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002733 }
2734
2735 ath10k_tx_htt(ar, skb);
2736}
2737
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002738/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002739void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002740{
2741 /* make sure rcu-protected mac80211 tx path itself is drained */
2742 synchronize_net();
2743
2744 ath10k_offchan_tx_purge(ar);
2745 ath10k_mgmt_over_wmi_tx_purge(ar);
2746
2747 cancel_work_sync(&ar->offchan_tx_work);
2748 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2749}
2750
Michal Kazioraffd3212013-07-16 09:54:35 +02002751void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002752{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002753 struct ath10k_vif *arvif;
2754
Michal Kazior818bdd12013-07-16 09:38:57 +02002755 lockdep_assert_held(&ar->conf_mutex);
2756
Michal Kazior19337472014-08-28 12:58:16 +02002757 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2758 ar->filter_flags = 0;
2759 ar->monitor = false;
2760
2761 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002762 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002763
2764 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002765
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002766 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002767 ath10k_peer_cleanup_all(ar);
2768 ath10k_core_stop(ar);
2769 ath10k_hif_power_down(ar);
2770
2771 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002772 list_for_each_entry(arvif, &ar->arvifs, list)
2773 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002774 spin_unlock_bh(&ar->data_lock);
2775}
2776
Ben Greear46acf7bb2014-05-16 17:15:38 +03002777static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2778{
2779 struct ath10k *ar = hw->priv;
2780
2781 mutex_lock(&ar->conf_mutex);
2782
2783 if (ar->cfg_tx_chainmask) {
2784 *tx_ant = ar->cfg_tx_chainmask;
2785 *rx_ant = ar->cfg_rx_chainmask;
2786 } else {
2787 *tx_ant = ar->supp_tx_chainmask;
2788 *rx_ant = ar->supp_rx_chainmask;
2789 }
2790
2791 mutex_unlock(&ar->conf_mutex);
2792
2793 return 0;
2794}
2795
Ben Greear5572a952014-11-24 16:22:10 +02002796static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2797{
2798 /* It is not clear that allowing gaps in chainmask
2799 * is helpful. Probably it will not do what user
2800 * is hoping for, so warn in that case.
2801 */
2802 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2803 return;
2804
2805 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2806 dbg, cm);
2807}
2808
Ben Greear46acf7bb2014-05-16 17:15:38 +03002809static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2810{
2811 int ret;
2812
2813 lockdep_assert_held(&ar->conf_mutex);
2814
Ben Greear5572a952014-11-24 16:22:10 +02002815 ath10k_check_chain_mask(ar, tx_ant, "tx");
2816 ath10k_check_chain_mask(ar, rx_ant, "rx");
2817
Ben Greear46acf7bb2014-05-16 17:15:38 +03002818 ar->cfg_tx_chainmask = tx_ant;
2819 ar->cfg_rx_chainmask = rx_ant;
2820
2821 if ((ar->state != ATH10K_STATE_ON) &&
2822 (ar->state != ATH10K_STATE_RESTARTED))
2823 return 0;
2824
2825 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2826 tx_ant);
2827 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002828 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002829 ret, tx_ant);
2830 return ret;
2831 }
2832
2833 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2834 rx_ant);
2835 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002836 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002837 ret, rx_ant);
2838 return ret;
2839 }
2840
2841 return 0;
2842}
2843
2844static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2845{
2846 struct ath10k *ar = hw->priv;
2847 int ret;
2848
2849 mutex_lock(&ar->conf_mutex);
2850 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2851 mutex_unlock(&ar->conf_mutex);
2852 return ret;
2853}
2854
Kalle Valo5e3dd152013-06-12 20:52:10 +03002855static int ath10k_start(struct ieee80211_hw *hw)
2856{
2857 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002858 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002860 /*
2861 * This makes sense only when restarting hw. It is harmless to call
2862 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2863 * commands will be submitted while restarting.
2864 */
2865 ath10k_drain_tx(ar);
2866
Michal Kazior548db542013-07-05 16:15:15 +03002867 mutex_lock(&ar->conf_mutex);
2868
Michal Kaziorc5058f52014-05-26 12:46:03 +03002869 switch (ar->state) {
2870 case ATH10K_STATE_OFF:
2871 ar->state = ATH10K_STATE_ON;
2872 break;
2873 case ATH10K_STATE_RESTARTING:
2874 ath10k_halt(ar);
2875 ar->state = ATH10K_STATE_RESTARTED;
2876 break;
2877 case ATH10K_STATE_ON:
2878 case ATH10K_STATE_RESTARTED:
2879 case ATH10K_STATE_WEDGED:
2880 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002881 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002882 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002883 case ATH10K_STATE_UTF:
2884 ret = -EBUSY;
2885 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002886 }
2887
2888 ret = ath10k_hif_power_up(ar);
2889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002890 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002891 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002892 }
2893
Kalle Valo43d2a302014-09-10 18:23:30 +03002894 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002896 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002897 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002898 }
2899
Bartosz Markowski226a3392013-09-26 17:47:16 +02002900 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002902 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002903 goto err_core_stop;
2904 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002906 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002907 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002908 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002909 goto err_core_stop;
2910 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911
Ben Greear46acf7bb2014-05-16 17:15:38 +03002912 if (ar->cfg_tx_chainmask)
2913 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2914 ar->cfg_rx_chainmask);
2915
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002916 /*
2917 * By default FW set ARP frames ac to voice (6). In that case ARP
2918 * exchange is not working properly for UAPSD enabled AP. ARP requests
2919 * which arrives with access category 0 are processed by network stack
2920 * and send back with access category 0, but FW changes access category
2921 * to 6. Set ARP frames access category to best effort (0) solves
2922 * this problem.
2923 */
2924
2925 ret = ath10k_wmi_pdev_set_param(ar,
2926 ar->wmi.pdev_param->arp_ac_override, 0);
2927 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002928 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002929 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002930 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002931 }
2932
Michal Kaziord6500972014-04-08 09:56:09 +03002933 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002934 ath10k_regd_update(ar);
2935
Simon Wunderlich855aed12014-08-02 09:12:54 +03002936 ath10k_spectral_start(ar);
2937
Michal Kaziorae254432014-05-26 12:46:02 +03002938 mutex_unlock(&ar->conf_mutex);
2939 return 0;
2940
2941err_core_stop:
2942 ath10k_core_stop(ar);
2943
2944err_power_down:
2945 ath10k_hif_power_down(ar);
2946
2947err_off:
2948 ar->state = ATH10K_STATE_OFF;
2949
2950err:
Michal Kazior548db542013-07-05 16:15:15 +03002951 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002952 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002953}
2954
2955static void ath10k_stop(struct ieee80211_hw *hw)
2956{
2957 struct ath10k *ar = hw->priv;
2958
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002959 ath10k_drain_tx(ar);
2960
Michal Kazior548db542013-07-05 16:15:15 +03002961 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002962 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002963 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002964 ar->state = ATH10K_STATE_OFF;
2965 }
Michal Kazior548db542013-07-05 16:15:15 +03002966 mutex_unlock(&ar->conf_mutex);
2967
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002968 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002969 cancel_work_sync(&ar->restart_work);
2970}
2971
Michal Kaziorad088bf2013-10-16 15:44:46 +03002972static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002973{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002974 struct ath10k_vif *arvif;
2975 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002976
2977 lockdep_assert_held(&ar->conf_mutex);
2978
Michal Kaziorad088bf2013-10-16 15:44:46 +03002979 list_for_each_entry(arvif, &ar->arvifs, list) {
2980 ret = ath10k_mac_vif_setup_ps(arvif);
2981 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002982 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002983 break;
2984 }
2985 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002986
Michal Kaziorad088bf2013-10-16 15:44:46 +03002987 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002988}
2989
Michal Kaziorc930f742014-01-23 11:38:25 +01002990static const char *chandef_get_width(enum nl80211_chan_width width)
2991{
2992 switch (width) {
2993 case NL80211_CHAN_WIDTH_20_NOHT:
2994 return "20 (noht)";
2995 case NL80211_CHAN_WIDTH_20:
2996 return "20";
2997 case NL80211_CHAN_WIDTH_40:
2998 return "40";
2999 case NL80211_CHAN_WIDTH_80:
3000 return "80";
3001 case NL80211_CHAN_WIDTH_80P80:
3002 return "80+80";
3003 case NL80211_CHAN_WIDTH_160:
3004 return "160";
3005 case NL80211_CHAN_WIDTH_5:
3006 return "5";
3007 case NL80211_CHAN_WIDTH_10:
3008 return "10";
3009 }
3010 return "?";
3011}
3012
3013static void ath10k_config_chan(struct ath10k *ar)
3014{
3015 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003016 int ret;
3017
3018 lockdep_assert_held(&ar->conf_mutex);
3019
Michal Kazior7aa7a722014-08-25 12:09:38 +02003020 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003021 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3022 ar->chandef.chan->center_freq,
3023 ar->chandef.center_freq1,
3024 ar->chandef.center_freq2,
3025 chandef_get_width(ar->chandef.width));
3026
3027 /* First stop monitor interface. Some FW versions crash if there's a
3028 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003029 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003030 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003031
3032 list_for_each_entry(arvif, &ar->arvifs, list) {
3033 if (!arvif->is_started)
3034 continue;
3035
Michal Kaziordc55e302014-07-29 12:53:36 +03003036 if (!arvif->is_up)
3037 continue;
3038
Michal Kaziorc930f742014-01-23 11:38:25 +01003039 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3040 continue;
3041
Michal Kaziordc55e302014-07-29 12:53:36 +03003042 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003043 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003044 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003045 arvif->vdev_id, ret);
3046 continue;
3047 }
3048 }
3049
Michal Kaziordc55e302014-07-29 12:53:36 +03003050 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003051
3052 list_for_each_entry(arvif, &ar->arvifs, list) {
3053 if (!arvif->is_started)
3054 continue;
3055
3056 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3057 continue;
3058
Michal Kaziordc55e302014-07-29 12:53:36 +03003059 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003060 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003061 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003062 arvif->vdev_id, ret);
3063 continue;
3064 }
3065
3066 if (!arvif->is_up)
3067 continue;
3068
3069 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3070 arvif->bssid);
3071 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003072 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003073 arvif->vdev_id, ret);
3074 continue;
3075 }
3076 }
3077
Michal Kazior19337472014-08-28 12:58:16 +02003078 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003079}
3080
Michal Kazior7d9d5582014-10-21 10:40:15 +03003081static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3082{
3083 int ret;
3084 u32 param;
3085
3086 lockdep_assert_held(&ar->conf_mutex);
3087
3088 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3089
3090 param = ar->wmi.pdev_param->txpower_limit2g;
3091 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3092 if (ret) {
3093 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3094 txpower, ret);
3095 return ret;
3096 }
3097
3098 param = ar->wmi.pdev_param->txpower_limit5g;
3099 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3100 if (ret) {
3101 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3102 txpower, ret);
3103 return ret;
3104 }
3105
3106 return 0;
3107}
3108
3109static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3110{
3111 struct ath10k_vif *arvif;
3112 int ret, txpower = -1;
3113
3114 lockdep_assert_held(&ar->conf_mutex);
3115
3116 list_for_each_entry(arvif, &ar->arvifs, list) {
3117 WARN_ON(arvif->txpower < 0);
3118
3119 if (txpower == -1)
3120 txpower = arvif->txpower;
3121 else
3122 txpower = min(txpower, arvif->txpower);
3123 }
3124
3125 if (WARN_ON(txpower == -1))
3126 return -EINVAL;
3127
3128 ret = ath10k_mac_txpower_setup(ar, txpower);
3129 if (ret) {
3130 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3131 txpower, ret);
3132 return ret;
3133 }
3134
3135 return 0;
3136}
3137
Kalle Valo5e3dd152013-06-12 20:52:10 +03003138static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3139{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003140 struct ath10k *ar = hw->priv;
3141 struct ieee80211_conf *conf = &hw->conf;
3142 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003143
3144 mutex_lock(&ar->conf_mutex);
3145
3146 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003147 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003148 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003149 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003150 conf->chandef.chan->flags,
3151 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003152
Kalle Valo5e3dd152013-06-12 20:52:10 +03003153 spin_lock_bh(&ar->data_lock);
3154 ar->rx_channel = conf->chandef.chan;
3155 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003156
Michal Kaziord6500972014-04-08 09:56:09 +03003157 ar->radar_enabled = conf->radar_enabled;
3158 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003159
3160 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3161 ar->chandef = conf->chandef;
3162 ath10k_config_chan(ar);
3163 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164 }
3165
Michal Kazioraffd3212013-07-16 09:54:35 +02003166 if (changed & IEEE80211_CONF_CHANGE_PS)
3167 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168
3169 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003170 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3171 ret = ath10k_monitor_recalc(ar);
3172 if (ret)
3173 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003174 }
3175
3176 mutex_unlock(&ar->conf_mutex);
3177 return ret;
3178}
3179
Ben Greear5572a952014-11-24 16:22:10 +02003180static u32 get_nss_from_chainmask(u16 chain_mask)
3181{
3182 if ((chain_mask & 0x15) == 0x15)
3183 return 4;
3184 else if ((chain_mask & 0x7) == 0x7)
3185 return 3;
3186 else if ((chain_mask & 0x3) == 0x3)
3187 return 2;
3188 return 1;
3189}
3190
Kalle Valo5e3dd152013-06-12 20:52:10 +03003191/*
3192 * TODO:
3193 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3194 * because we will send mgmt frames without CCK. This requirement
3195 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3196 * in the TX packet.
3197 */
3198static int ath10k_add_interface(struct ieee80211_hw *hw,
3199 struct ieee80211_vif *vif)
3200{
3201 struct ath10k *ar = hw->priv;
3202 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3203 enum wmi_sta_powersave_param param;
3204 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003205 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003206 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003207 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208
Johannes Berg848955c2014-11-11 12:48:42 +01003209 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3210
Kalle Valo5e3dd152013-06-12 20:52:10 +03003211 mutex_lock(&ar->conf_mutex);
3212
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003213 memset(arvif, 0, sizeof(*arvif));
3214
Kalle Valo5e3dd152013-06-12 20:52:10 +03003215 arvif->ar = ar;
3216 arvif->vif = vif;
3217
Ben Greeare63b33f2013-10-22 14:54:14 -07003218 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003219
Ben Greeara9aefb32014-08-12 11:02:19 +03003220 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003221 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003222 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003223 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003224 }
Ben Greear16c11172014-09-23 14:17:16 -07003225 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003226
Ben Greear16c11172014-09-23 14:17:16 -07003227 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3228 bit, ar->free_vdev_map);
3229
3230 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003231 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003232
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003234 case NL80211_IFTYPE_P2P_DEVICE:
3235 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3236 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3237 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003238 case NL80211_IFTYPE_UNSPECIFIED:
3239 case NL80211_IFTYPE_STATION:
3240 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3241 if (vif->p2p)
3242 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3243 break;
3244 case NL80211_IFTYPE_ADHOC:
3245 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3246 break;
3247 case NL80211_IFTYPE_AP:
3248 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3249
3250 if (vif->p2p)
3251 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3252 break;
3253 case NL80211_IFTYPE_MONITOR:
3254 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3255 break;
3256 default:
3257 WARN_ON(1);
3258 break;
3259 }
3260
Michal Kazior64badcb2014-09-18 11:18:02 +03003261 /* Some firmware revisions don't wait for beacon tx completion before
3262 * sending another SWBA event. This could lead to hardware using old
3263 * (freed) beacon data in some cases, e.g. tx credit starvation
3264 * combined with missed TBTT. This is very very rare.
3265 *
3266 * On non-IOMMU-enabled hosts this could be a possible security issue
3267 * because hw could beacon some random data on the air. On
3268 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3269 * device would crash.
3270 *
3271 * Since there are no beacon tx completions (implicit nor explicit)
3272 * propagated to host the only workaround for this is to allocate a
3273 * DMA-coherent buffer for a lifetime of a vif and use it for all
3274 * beacon tx commands. Worst case for this approach is some beacons may
3275 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3276 */
3277 if (vif->type == NL80211_IFTYPE_ADHOC ||
3278 vif->type == NL80211_IFTYPE_AP) {
3279 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3280 IEEE80211_MAX_FRAME_LEN,
3281 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303282 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003283 if (!arvif->beacon_buf) {
3284 ret = -ENOMEM;
3285 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3286 ret);
3287 goto err;
3288 }
3289 }
3290
3291 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3292 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3293 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294
3295 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3296 arvif->vdev_subtype, vif->addr);
3297 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003298 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003299 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003300 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003301 }
3302
Ben Greear16c11172014-09-23 14:17:16 -07003303 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003304 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003305
Michal Kazior46725b152015-01-28 09:57:49 +02003306 /* It makes no sense to have firmware do keepalives. mac80211 already
3307 * takes care of this with idle connection polling.
3308 */
3309 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003310 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003311 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003312 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003313 goto err_vdev_delete;
3314 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003316 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003318 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3319 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003321 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003322 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003323 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003324 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003325 goto err_vdev_delete;
3326 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003327
Ben Greear5572a952014-11-24 16:22:10 +02003328 if (ar->cfg_tx_chainmask) {
3329 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3330
3331 vdev_param = ar->wmi.vdev_param->nss;
3332 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3333 nss);
3334 if (ret) {
3335 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3336 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3337 ret);
3338 goto err_vdev_delete;
3339 }
3340 }
3341
Kalle Valo5e3dd152013-06-12 20:52:10 +03003342 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3343 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3344 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003345 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003346 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003347 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003348 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003349
Kalle Valo5a13e762014-01-20 11:01:46 +02003350 ret = ath10k_mac_set_kickout(arvif);
3351 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003352 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003353 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003354 goto err_peer_delete;
3355 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003356 }
3357
3358 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3359 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3360 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3361 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3362 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003363 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003364 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003365 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003366 goto err_peer_delete;
3367 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003368
Michal Kazior9f9b5742014-12-12 12:41:36 +01003369 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003370 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003371 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003372 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003373 goto err_peer_delete;
3374 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003375
Michal Kazior9f9b5742014-12-12 12:41:36 +01003376 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003377 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003378 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003379 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003380 goto err_peer_delete;
3381 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003382 }
3383
Michal Kazior424121c2013-07-22 14:13:31 +02003384 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003386 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003387 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003388 goto err_peer_delete;
3389 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003390
Michal Kazior424121c2013-07-22 14:13:31 +02003391 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003392 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003393 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003394 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003395 goto err_peer_delete;
3396 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003397
Michal Kazior7d9d5582014-10-21 10:40:15 +03003398 arvif->txpower = vif->bss_conf.txpower;
3399 ret = ath10k_mac_txpower_recalc(ar);
3400 if (ret) {
3401 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3402 goto err_peer_delete;
3403 }
3404
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003406 return 0;
3407
3408err_peer_delete:
3409 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3410 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3411
3412err_vdev_delete:
3413 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003414 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003415 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003416
3417err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003418 if (arvif->beacon_buf) {
3419 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3420 arvif->beacon_buf, arvif->beacon_paddr);
3421 arvif->beacon_buf = NULL;
3422 }
3423
Michal Kazior9dad14ae2013-10-16 15:44:45 +03003424 mutex_unlock(&ar->conf_mutex);
3425
Kalle Valo5e3dd152013-06-12 20:52:10 +03003426 return ret;
3427}
3428
3429static void ath10k_remove_interface(struct ieee80211_hw *hw,
3430 struct ieee80211_vif *vif)
3431{
3432 struct ath10k *ar = hw->priv;
3433 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3434 int ret;
3435
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303436 mutex_lock(&ar->conf_mutex);
3437
Michal Kaziored543882013-09-13 14:16:56 +02003438 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003439 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003440 spin_unlock_bh(&ar->data_lock);
3441
Simon Wunderlich855aed12014-08-02 09:12:54 +03003442 ret = ath10k_spectral_vif_stop(arvif);
3443 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003444 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003445 arvif->vdev_id, ret);
3446
Ben Greear16c11172014-09-23 14:17:16 -07003447 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003448 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003449
3450 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003451 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3452 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003453 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003454 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003455 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456
3457 kfree(arvif->u.ap.noa_data);
3458 }
3459
Michal Kazior7aa7a722014-08-25 12:09:38 +02003460 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003461 arvif->vdev_id);
3462
Kalle Valo5e3dd152013-06-12 20:52:10 +03003463 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3464 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003465 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003466 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467
Michal Kazior2c512052015-02-15 16:50:40 +02003468 /* Some firmware revisions don't notify host about self-peer removal
3469 * until after associated vdev is deleted.
3470 */
3471 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3472 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3473 vif->addr);
3474 if (ret)
3475 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3476 arvif->vdev_id, ret);
3477
3478 spin_lock_bh(&ar->data_lock);
3479 ar->num_peers--;
3480 spin_unlock_bh(&ar->data_lock);
3481 }
3482
Kalle Valo5e3dd152013-06-12 20:52:10 +03003483 ath10k_peer_cleanup(ar, arvif->vdev_id);
3484
3485 mutex_unlock(&ar->conf_mutex);
3486}
3487
3488/*
3489 * FIXME: Has to be verified.
3490 */
3491#define SUPPORTED_FILTERS \
3492 (FIF_PROMISC_IN_BSS | \
3493 FIF_ALLMULTI | \
3494 FIF_CONTROL | \
3495 FIF_PSPOLL | \
3496 FIF_OTHER_BSS | \
3497 FIF_BCN_PRBRESP_PROMISC | \
3498 FIF_PROBE_REQ | \
3499 FIF_FCSFAIL)
3500
3501static void ath10k_configure_filter(struct ieee80211_hw *hw,
3502 unsigned int changed_flags,
3503 unsigned int *total_flags,
3504 u64 multicast)
3505{
3506 struct ath10k *ar = hw->priv;
3507 int ret;
3508
3509 mutex_lock(&ar->conf_mutex);
3510
3511 changed_flags &= SUPPORTED_FILTERS;
3512 *total_flags &= SUPPORTED_FILTERS;
3513 ar->filter_flags = *total_flags;
3514
Michal Kazior19337472014-08-28 12:58:16 +02003515 ret = ath10k_monitor_recalc(ar);
3516 if (ret)
3517 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518
3519 mutex_unlock(&ar->conf_mutex);
3520}
3521
3522static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3523 struct ieee80211_vif *vif,
3524 struct ieee80211_bss_conf *info,
3525 u32 changed)
3526{
3527 struct ath10k *ar = hw->priv;
3528 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3529 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003530 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003531
3532 mutex_lock(&ar->conf_mutex);
3533
3534 if (changed & BSS_CHANGED_IBSS)
3535 ath10k_control_ibss(arvif, info, vif->addr);
3536
3537 if (changed & BSS_CHANGED_BEACON_INT) {
3538 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003539 vdev_param = ar->wmi.vdev_param->beacon_interval;
3540 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003542 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003543 "mac vdev %d beacon_interval %d\n",
3544 arvif->vdev_id, arvif->beacon_interval);
3545
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003547 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003548 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003549 }
3550
3551 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003552 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003553 "vdev %d set beacon tx mode to staggered\n",
3554 arvif->vdev_id);
3555
Bartosz Markowski226a3392013-09-26 17:47:16 +02003556 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3557 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003558 WMI_BEACON_STAGGERED_MODE);
3559 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003560 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003561 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003562
3563 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3564 if (ret)
3565 ath10k_warn(ar, "failed to update beacon template: %d\n",
3566 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567 }
3568
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003569 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3570 ret = ath10k_mac_setup_prb_tmpl(arvif);
3571 if (ret)
3572 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3573 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003574 }
3575
Michal Kaziorba2479f2015-01-24 12:14:51 +02003576 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577 arvif->dtim_period = info->dtim_period;
3578
Michal Kazior7aa7a722014-08-25 12:09:38 +02003579 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003580 "mac vdev %d dtim_period %d\n",
3581 arvif->vdev_id, arvif->dtim_period);
3582
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003583 vdev_param = ar->wmi.vdev_param->dtim_period;
3584 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003585 arvif->dtim_period);
3586 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003587 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003588 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589 }
3590
3591 if (changed & BSS_CHANGED_SSID &&
3592 vif->type == NL80211_IFTYPE_AP) {
3593 arvif->u.ap.ssid_len = info->ssid_len;
3594 if (info->ssid_len)
3595 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3596 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3597 }
3598
Michal Kazior077efc82014-10-21 10:10:29 +03003599 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3600 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003601
3602 if (changed & BSS_CHANGED_BEACON_ENABLED)
3603 ath10k_control_beaconing(arvif, info);
3604
3605 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003606 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003608 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003609
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003610 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003611 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003612 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003613 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003614 }
3615
3616 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617 if (info->use_short_slot)
3618 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3619
3620 else
3621 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3622
Michal Kazior7aa7a722014-08-25 12:09:38 +02003623 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003624 arvif->vdev_id, slottime);
3625
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003626 vdev_param = ar->wmi.vdev_param->slot_time;
3627 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003628 slottime);
3629 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003630 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003631 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632 }
3633
3634 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003635 if (info->use_short_preamble)
3636 preamble = WMI_VDEV_PREAMBLE_SHORT;
3637 else
3638 preamble = WMI_VDEV_PREAMBLE_LONG;
3639
Michal Kazior7aa7a722014-08-25 12:09:38 +02003640 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003641 "mac vdev %d preamble %dn",
3642 arvif->vdev_id, preamble);
3643
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003644 vdev_param = ar->wmi.vdev_param->preamble;
3645 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003646 preamble);
3647 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003648 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003649 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650 }
3651
3652 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003653 if (info->assoc) {
3654 /* Workaround: Make sure monitor vdev is not running
3655 * when associating to prevent some firmware revisions
3656 * (e.g. 10.1 and 10.2) from crashing.
3657 */
3658 if (ar->monitor_started)
3659 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003660 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003661 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003662 } else {
3663 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003664 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003665 }
3666
Michal Kazior7d9d5582014-10-21 10:40:15 +03003667 if (changed & BSS_CHANGED_TXPOWER) {
3668 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3669 arvif->vdev_id, info->txpower);
3670
3671 arvif->txpower = info->txpower;
3672 ret = ath10k_mac_txpower_recalc(ar);
3673 if (ret)
3674 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3675 }
3676
Michal Kaziorbf14e652014-12-12 12:41:38 +01003677 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003678 arvif->ps = vif->bss_conf.ps;
3679
3680 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003681 if (ret)
3682 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3683 arvif->vdev_id, ret);
3684 }
3685
Kalle Valo5e3dd152013-06-12 20:52:10 +03003686 mutex_unlock(&ar->conf_mutex);
3687}
3688
3689static int ath10k_hw_scan(struct ieee80211_hw *hw,
3690 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003691 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003692{
3693 struct ath10k *ar = hw->priv;
3694 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003695 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003696 struct wmi_start_scan_arg arg;
3697 int ret = 0;
3698 int i;
3699
3700 mutex_lock(&ar->conf_mutex);
3701
3702 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003703 switch (ar->scan.state) {
3704 case ATH10K_SCAN_IDLE:
3705 reinit_completion(&ar->scan.started);
3706 reinit_completion(&ar->scan.completed);
3707 ar->scan.state = ATH10K_SCAN_STARTING;
3708 ar->scan.is_roc = false;
3709 ar->scan.vdev_id = arvif->vdev_id;
3710 ret = 0;
3711 break;
3712 case ATH10K_SCAN_STARTING:
3713 case ATH10K_SCAN_RUNNING:
3714 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003716 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003717 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003718 spin_unlock_bh(&ar->data_lock);
3719
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003720 if (ret)
3721 goto exit;
3722
Kalle Valo5e3dd152013-06-12 20:52:10 +03003723 memset(&arg, 0, sizeof(arg));
3724 ath10k_wmi_start_scan_init(ar, &arg);
3725 arg.vdev_id = arvif->vdev_id;
3726 arg.scan_id = ATH10K_SCAN_ID;
3727
3728 if (!req->no_cck)
3729 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3730
3731 if (req->ie_len) {
3732 arg.ie_len = req->ie_len;
3733 memcpy(arg.ie, req->ie, arg.ie_len);
3734 }
3735
3736 if (req->n_ssids) {
3737 arg.n_ssids = req->n_ssids;
3738 for (i = 0; i < arg.n_ssids; i++) {
3739 arg.ssids[i].len = req->ssids[i].ssid_len;
3740 arg.ssids[i].ssid = req->ssids[i].ssid;
3741 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003742 } else {
3743 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744 }
3745
3746 if (req->n_channels) {
3747 arg.n_channels = req->n_channels;
3748 for (i = 0; i < arg.n_channels; i++)
3749 arg.channels[i] = req->channels[i]->center_freq;
3750 }
3751
3752 ret = ath10k_start_scan(ar, &arg);
3753 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003754 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003755 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003756 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003757 spin_unlock_bh(&ar->data_lock);
3758 }
3759
3760exit:
3761 mutex_unlock(&ar->conf_mutex);
3762 return ret;
3763}
3764
3765static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3766 struct ieee80211_vif *vif)
3767{
3768 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003769
3770 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003771 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003772 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003773
3774 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003775}
3776
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003777static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3778 struct ath10k_vif *arvif,
3779 enum set_key_cmd cmd,
3780 struct ieee80211_key_conf *key)
3781{
3782 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3783 int ret;
3784
3785 /* 10.1 firmware branch requires default key index to be set to group
3786 * key index after installing it. Otherwise FW/HW Txes corrupted
3787 * frames with multi-vif APs. This is not required for main firmware
3788 * branch (e.g. 636).
3789 *
3790 * FIXME: This has been tested only in AP. It remains unknown if this
3791 * is required for multi-vif STA interfaces on 10.1 */
3792
3793 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3794 return;
3795
3796 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3797 return;
3798
3799 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3800 return;
3801
3802 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3803 return;
3804
3805 if (cmd != SET_KEY)
3806 return;
3807
3808 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3809 key->keyidx);
3810 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003811 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003812 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003813}
3814
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3816 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3817 struct ieee80211_key_conf *key)
3818{
3819 struct ath10k *ar = hw->priv;
3820 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3821 struct ath10k_peer *peer;
3822 const u8 *peer_addr;
3823 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3824 key->cipher == WLAN_CIPHER_SUITE_WEP104;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003825 bool def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003826 int ret = 0;
3827
3828 if (key->keyidx > WMI_MAX_KEY_INDEX)
3829 return -ENOSPC;
3830
3831 mutex_lock(&ar->conf_mutex);
3832
3833 if (sta)
3834 peer_addr = sta->addr;
3835 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3836 peer_addr = vif->bss_conf.bssid;
3837 else
3838 peer_addr = vif->addr;
3839
3840 key->hw_key_idx = key->keyidx;
3841
3842 /* the peer should not disappear in mid-way (unless FW goes awry) since
3843 * we already hold conf_mutex. we just make sure its there now. */
3844 spin_lock_bh(&ar->data_lock);
3845 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3846 spin_unlock_bh(&ar->data_lock);
3847
3848 if (!peer) {
3849 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003850 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003851 peer_addr);
3852 ret = -EOPNOTSUPP;
3853 goto exit;
3854 } else {
3855 /* if the peer doesn't exist there is no key to disable
3856 * anymore */
3857 goto exit;
3858 }
3859 }
3860
3861 if (is_wep) {
3862 if (cmd == SET_KEY)
3863 arvif->wep_keys[key->keyidx] = key;
3864 else
3865 arvif->wep_keys[key->keyidx] = NULL;
3866
3867 if (cmd == DISABLE_KEY)
3868 ath10k_clear_vdev_key(arvif, key);
3869 }
3870
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003871 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3872 * static WEP, do not set this flag for the keys whose key id
3873 * is greater than default key id.
3874 */
3875 if (arvif->def_wep_key_idx == -1)
3876 def_idx = true;
3877
3878 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003880 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003881 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003882 goto exit;
3883 }
3884
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003885 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3886
Kalle Valo5e3dd152013-06-12 20:52:10 +03003887 spin_lock_bh(&ar->data_lock);
3888 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3889 if (peer && cmd == SET_KEY)
3890 peer->keys[key->keyidx] = key;
3891 else if (peer && cmd == DISABLE_KEY)
3892 peer->keys[key->keyidx] = NULL;
3893 else if (peer == NULL)
3894 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003895 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003896 spin_unlock_bh(&ar->data_lock);
3897
3898exit:
3899 mutex_unlock(&ar->conf_mutex);
3900 return ret;
3901}
3902
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003903static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3904 struct ieee80211_vif *vif,
3905 int keyidx)
3906{
3907 struct ath10k *ar = hw->priv;
3908 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3909 int ret;
3910
3911 mutex_lock(&arvif->ar->conf_mutex);
3912
3913 if (arvif->ar->state != ATH10K_STATE_ON)
3914 goto unlock;
3915
3916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3917 arvif->vdev_id, keyidx);
3918
3919 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3920 arvif->vdev_id,
3921 arvif->ar->wmi.vdev_param->def_keyid,
3922 keyidx);
3923
3924 if (ret) {
3925 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3926 arvif->vdev_id,
3927 ret);
3928 goto unlock;
3929 }
3930
3931 arvif->def_wep_key_idx = keyidx;
3932unlock:
3933 mutex_unlock(&arvif->ar->conf_mutex);
3934}
3935
Michal Kazior9797feb2014-02-14 14:49:48 +01003936static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3937{
3938 struct ath10k *ar;
3939 struct ath10k_vif *arvif;
3940 struct ath10k_sta *arsta;
3941 struct ieee80211_sta *sta;
3942 u32 changed, bw, nss, smps;
3943 int err;
3944
3945 arsta = container_of(wk, struct ath10k_sta, update_wk);
3946 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3947 arvif = arsta->arvif;
3948 ar = arvif->ar;
3949
3950 spin_lock_bh(&ar->data_lock);
3951
3952 changed = arsta->changed;
3953 arsta->changed = 0;
3954
3955 bw = arsta->bw;
3956 nss = arsta->nss;
3957 smps = arsta->smps;
3958
3959 spin_unlock_bh(&ar->data_lock);
3960
3961 mutex_lock(&ar->conf_mutex);
3962
3963 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003964 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003965 sta->addr, bw);
3966
3967 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3968 WMI_PEER_CHAN_WIDTH, bw);
3969 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003970 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003971 sta->addr, bw, err);
3972 }
3973
3974 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003975 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003976 sta->addr, nss);
3977
3978 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3979 WMI_PEER_NSS, nss);
3980 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003981 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003982 sta->addr, nss, err);
3983 }
3984
3985 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003986 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003987 sta->addr, smps);
3988
3989 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3990 WMI_PEER_SMPS_STATE, smps);
3991 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003992 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003993 sta->addr, smps, err);
3994 }
3995
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003996 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3997 changed & IEEE80211_RC_NSS_CHANGED) {
3998 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003999 sta->addr);
4000
Michal Kazior590922a2014-10-21 10:10:29 +03004001 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004002 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004003 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004004 sta->addr);
4005 }
4006
Michal Kazior9797feb2014-02-14 14:49:48 +01004007 mutex_unlock(&ar->conf_mutex);
4008}
4009
Michal Kaziorcfd10612014-11-25 15:16:05 +01004010static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4011{
4012 struct ath10k *ar = arvif->ar;
4013
4014 lockdep_assert_held(&ar->conf_mutex);
4015
4016 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4017 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4018 return 0;
4019
4020 if (ar->num_stations >= ar->max_num_stations)
4021 return -ENOBUFS;
4022
4023 ar->num_stations++;
4024
4025 return 0;
4026}
4027
4028static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4029{
4030 struct ath10k *ar = arvif->ar;
4031
4032 lockdep_assert_held(&ar->conf_mutex);
4033
4034 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4035 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4036 return;
4037
4038 ar->num_stations--;
4039}
4040
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041static int ath10k_sta_state(struct ieee80211_hw *hw,
4042 struct ieee80211_vif *vif,
4043 struct ieee80211_sta *sta,
4044 enum ieee80211_sta_state old_state,
4045 enum ieee80211_sta_state new_state)
4046{
4047 struct ath10k *ar = hw->priv;
4048 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004049 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004050 int ret = 0;
4051
Michal Kazior76f90022014-02-25 09:29:57 +02004052 if (old_state == IEEE80211_STA_NOTEXIST &&
4053 new_state == IEEE80211_STA_NONE) {
4054 memset(arsta, 0, sizeof(*arsta));
4055 arsta->arvif = arvif;
4056 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4057 }
4058
Michal Kazior9797feb2014-02-14 14:49:48 +01004059 /* cancel must be done outside the mutex to avoid deadlock */
4060 if ((old_state == IEEE80211_STA_NONE &&
4061 new_state == IEEE80211_STA_NOTEXIST))
4062 cancel_work_sync(&arsta->update_wk);
4063
Kalle Valo5e3dd152013-06-12 20:52:10 +03004064 mutex_lock(&ar->conf_mutex);
4065
4066 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004067 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004068 /*
4069 * New station addition.
4070 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004071 ath10k_dbg(ar, ATH10K_DBG_MAC,
4072 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4073 arvif->vdev_id, sta->addr,
4074 ar->num_stations + 1, ar->max_num_stations,
4075 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004076
Michal Kaziorcfd10612014-11-25 15:16:05 +01004077 ret = ath10k_mac_inc_num_stations(arvif);
4078 if (ret) {
4079 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4080 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004081 goto exit;
4082 }
4083
Kalle Valo5e3dd152013-06-12 20:52:10 +03004084 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004085 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004086 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 -08004087 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004088 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004089 goto exit;
4090 }
Michal Kazior077efc82014-10-21 10:10:29 +03004091
4092 if (vif->type == NL80211_IFTYPE_STATION) {
4093 WARN_ON(arvif->is_started);
4094
4095 ret = ath10k_vdev_start(arvif);
4096 if (ret) {
4097 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4098 arvif->vdev_id, ret);
4099 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4100 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004101 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004102 goto exit;
4103 }
4104
4105 arvif->is_started = true;
4106 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004107 } else if ((old_state == IEEE80211_STA_NONE &&
4108 new_state == IEEE80211_STA_NOTEXIST)) {
4109 /*
4110 * Existing station deletion.
4111 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004112 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004113 "mac vdev %d peer delete %pM (sta gone)\n",
4114 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004115
4116 if (vif->type == NL80211_IFTYPE_STATION) {
4117 WARN_ON(!arvif->is_started);
4118
4119 ret = ath10k_vdev_stop(arvif);
4120 if (ret)
4121 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4122 arvif->vdev_id, ret);
4123
4124 arvif->is_started = false;
4125 }
4126
Kalle Valo5e3dd152013-06-12 20:52:10 +03004127 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4128 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004129 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004130 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004131
Michal Kaziorcfd10612014-11-25 15:16:05 +01004132 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004133 } else if (old_state == IEEE80211_STA_AUTH &&
4134 new_state == IEEE80211_STA_ASSOC &&
4135 (vif->type == NL80211_IFTYPE_AP ||
4136 vif->type == NL80211_IFTYPE_ADHOC)) {
4137 /*
4138 * New association.
4139 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004140 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004141 sta->addr);
4142
Michal Kazior590922a2014-10-21 10:10:29 +03004143 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004144 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004145 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004146 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004147 } else if (old_state == IEEE80211_STA_ASSOC &&
4148 new_state == IEEE80211_STA_AUTH &&
4149 (vif->type == NL80211_IFTYPE_AP ||
4150 vif->type == NL80211_IFTYPE_ADHOC)) {
4151 /*
4152 * Disassociation.
4153 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004154 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004155 sta->addr);
4156
Michal Kazior590922a2014-10-21 10:10:29 +03004157 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004158 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004159 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004160 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004162exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004163 mutex_unlock(&ar->conf_mutex);
4164 return ret;
4165}
4166
4167static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004168 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004169{
4170 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004171 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4172 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004173 u32 value = 0;
4174 int ret = 0;
4175
Michal Kazior548db542013-07-05 16:15:15 +03004176 lockdep_assert_held(&ar->conf_mutex);
4177
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4179 return 0;
4180
4181 switch (ac) {
4182 case IEEE80211_AC_VO:
4183 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4184 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004185 prio = 7;
4186 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004187 break;
4188 case IEEE80211_AC_VI:
4189 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4190 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004191 prio = 5;
4192 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004193 break;
4194 case IEEE80211_AC_BE:
4195 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4196 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004197 prio = 2;
4198 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004199 break;
4200 case IEEE80211_AC_BK:
4201 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4202 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004203 prio = 0;
4204 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004205 break;
4206 }
4207
4208 if (enable)
4209 arvif->u.sta.uapsd |= value;
4210 else
4211 arvif->u.sta.uapsd &= ~value;
4212
4213 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4214 WMI_STA_PS_PARAM_UAPSD,
4215 arvif->u.sta.uapsd);
4216 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004217 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004218 goto exit;
4219 }
4220
4221 if (arvif->u.sta.uapsd)
4222 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4223 else
4224 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4225
4226 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4227 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4228 value);
4229 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004230 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004231
Michal Kazior9f9b5742014-12-12 12:41:36 +01004232 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4233 if (ret) {
4234 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4235 arvif->vdev_id, ret);
4236 return ret;
4237 }
4238
4239 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4240 if (ret) {
4241 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4242 arvif->vdev_id, ret);
4243 return ret;
4244 }
4245
Michal Kaziorb0e56152015-01-24 12:14:52 +02004246 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4247 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4248 /* Only userspace can make an educated decision when to send
4249 * trigger frame. The following effectively disables u-UAPSD
4250 * autotrigger in firmware (which is enabled by default
4251 * provided the autotrigger service is available).
4252 */
4253
4254 arg.wmm_ac = acc;
4255 arg.user_priority = prio;
4256 arg.service_interval = 0;
4257 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4258 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4259
4260 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4261 arvif->bssid, &arg, 1);
4262 if (ret) {
4263 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4264 ret);
4265 return ret;
4266 }
4267 }
4268
Kalle Valo5e3dd152013-06-12 20:52:10 +03004269exit:
4270 return ret;
4271}
4272
4273static int ath10k_conf_tx(struct ieee80211_hw *hw,
4274 struct ieee80211_vif *vif, u16 ac,
4275 const struct ieee80211_tx_queue_params *params)
4276{
4277 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004278 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004279 struct wmi_wmm_params_arg *p = NULL;
4280 int ret;
4281
4282 mutex_lock(&ar->conf_mutex);
4283
4284 switch (ac) {
4285 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004286 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004287 break;
4288 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004289 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004290 break;
4291 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004292 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004293 break;
4294 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004295 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004296 break;
4297 }
4298
4299 if (WARN_ON(!p)) {
4300 ret = -EINVAL;
4301 goto exit;
4302 }
4303
4304 p->cwmin = params->cw_min;
4305 p->cwmax = params->cw_max;
4306 p->aifs = params->aifs;
4307
4308 /*
4309 * The channel time duration programmed in the HW is in absolute
4310 * microseconds, while mac80211 gives the txop in units of
4311 * 32 microseconds.
4312 */
4313 p->txop = params->txop * 32;
4314
Michal Kazior7fc979a2015-01-28 09:57:28 +02004315 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4316 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4317 &arvif->wmm_params);
4318 if (ret) {
4319 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4320 arvif->vdev_id, ret);
4321 goto exit;
4322 }
4323 } else {
4324 /* This won't work well with multi-interface cases but it's
4325 * better than nothing.
4326 */
4327 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4328 if (ret) {
4329 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4330 goto exit;
4331 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004332 }
4333
4334 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4335 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004336 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004337
4338exit:
4339 mutex_unlock(&ar->conf_mutex);
4340 return ret;
4341}
4342
4343#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4344
4345static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4346 struct ieee80211_vif *vif,
4347 struct ieee80211_channel *chan,
4348 int duration,
4349 enum ieee80211_roc_type type)
4350{
4351 struct ath10k *ar = hw->priv;
4352 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4353 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004354 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004355
4356 mutex_lock(&ar->conf_mutex);
4357
4358 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004359 switch (ar->scan.state) {
4360 case ATH10K_SCAN_IDLE:
4361 reinit_completion(&ar->scan.started);
4362 reinit_completion(&ar->scan.completed);
4363 reinit_completion(&ar->scan.on_channel);
4364 ar->scan.state = ATH10K_SCAN_STARTING;
4365 ar->scan.is_roc = true;
4366 ar->scan.vdev_id = arvif->vdev_id;
4367 ar->scan.roc_freq = chan->center_freq;
4368 ret = 0;
4369 break;
4370 case ATH10K_SCAN_STARTING:
4371 case ATH10K_SCAN_RUNNING:
4372 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004374 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004375 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004376 spin_unlock_bh(&ar->data_lock);
4377
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004378 if (ret)
4379 goto exit;
4380
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004381 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4382
Kalle Valo5e3dd152013-06-12 20:52:10 +03004383 memset(&arg, 0, sizeof(arg));
4384 ath10k_wmi_start_scan_init(ar, &arg);
4385 arg.vdev_id = arvif->vdev_id;
4386 arg.scan_id = ATH10K_SCAN_ID;
4387 arg.n_channels = 1;
4388 arg.channels[0] = chan->center_freq;
4389 arg.dwell_time_active = duration;
4390 arg.dwell_time_passive = duration;
4391 arg.max_scan_time = 2 * duration;
4392 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4393 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4394
4395 ret = ath10k_start_scan(ar, &arg);
4396 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004397 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004398 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004399 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004400 spin_unlock_bh(&ar->data_lock);
4401 goto exit;
4402 }
4403
4404 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4405 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004406 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004407
4408 ret = ath10k_scan_stop(ar);
4409 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004410 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004411
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412 ret = -ETIMEDOUT;
4413 goto exit;
4414 }
4415
4416 ret = 0;
4417exit:
4418 mutex_unlock(&ar->conf_mutex);
4419 return ret;
4420}
4421
4422static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4423{
4424 struct ath10k *ar = hw->priv;
4425
4426 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004427 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004428 mutex_unlock(&ar->conf_mutex);
4429
Michal Kazior4eb2e162014-10-28 10:23:09 +01004430 cancel_delayed_work_sync(&ar->scan.timeout);
4431
Kalle Valo5e3dd152013-06-12 20:52:10 +03004432 return 0;
4433}
4434
4435/*
4436 * Both RTS and Fragmentation threshold are interface-specific
4437 * in ath10k, but device-specific in mac80211.
4438 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004439
4440static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4441{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004442 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004443 struct ath10k_vif *arvif;
4444 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004445
Michal Kaziorad088bf2013-10-16 15:44:46 +03004446 mutex_lock(&ar->conf_mutex);
4447 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004448 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004449 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004450
Michal Kaziorad088bf2013-10-16 15:44:46 +03004451 ret = ath10k_mac_set_rts(arvif, value);
4452 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004453 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004454 arvif->vdev_id, ret);
4455 break;
4456 }
4457 }
4458 mutex_unlock(&ar->conf_mutex);
4459
4460 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004461}
4462
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004463static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4464 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004465{
4466 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004467 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004468 int ret;
4469
4470 /* mac80211 doesn't care if we really xmit queued frames or not
4471 * we'll collect those frames either way if we stop/delete vdevs */
4472 if (drop)
4473 return;
4474
Michal Kazior548db542013-07-05 16:15:15 +03004475 mutex_lock(&ar->conf_mutex);
4476
Michal Kazioraffd3212013-07-16 09:54:35 +02004477 if (ar->state == ATH10K_STATE_WEDGED)
4478 goto skip;
4479
Michal Kazioredb82362013-07-05 16:15:14 +03004480 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004481 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004482
Michal Kazioredb82362013-07-05 16:15:14 +03004483 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004484 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004485 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004486
Michal Kazior7962b0d2014-10-28 10:34:38 +01004487 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4488 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4489 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004490
4491 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004492 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004493
4494 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004495 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004496 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004497
Michal Kazioraffd3212013-07-16 09:54:35 +02004498skip:
Michal Kazior548db542013-07-05 16:15:15 +03004499 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004500}
4501
4502/* TODO: Implement this function properly
4503 * For now it is needed to reply to Probe Requests in IBSS mode.
4504 * Propably we need this information from FW.
4505 */
4506static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4507{
4508 return 1;
4509}
4510
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004511#ifdef CONFIG_PM
4512static int ath10k_suspend(struct ieee80211_hw *hw,
4513 struct cfg80211_wowlan *wowlan)
4514{
4515 struct ath10k *ar = hw->priv;
4516 int ret;
4517
Marek Puzyniak9042e172014-02-10 17:14:23 +01004518 mutex_lock(&ar->conf_mutex);
4519
Marek Puzyniak00f54822014-02-10 17:14:24 +01004520 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004521 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004522 if (ret == -ETIMEDOUT)
4523 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004524 ret = 1;
4525 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004526 }
4527
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004528 ret = ath10k_hif_suspend(ar);
4529 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004530 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004531 goto resume;
4532 }
4533
Marek Puzyniak9042e172014-02-10 17:14:23 +01004534 ret = 0;
4535 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004536resume:
4537 ret = ath10k_wmi_pdev_resume_target(ar);
4538 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004539 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004540
4541 ret = 1;
4542exit:
4543 mutex_unlock(&ar->conf_mutex);
4544 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004545}
4546
4547static int ath10k_resume(struct ieee80211_hw *hw)
4548{
4549 struct ath10k *ar = hw->priv;
4550 int ret;
4551
Marek Puzyniak9042e172014-02-10 17:14:23 +01004552 mutex_lock(&ar->conf_mutex);
4553
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004554 ret = ath10k_hif_resume(ar);
4555 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004556 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004557 ret = 1;
4558 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004559 }
4560
4561 ret = ath10k_wmi_pdev_resume_target(ar);
4562 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004563 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004564 ret = 1;
4565 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004566 }
4567
Marek Puzyniak9042e172014-02-10 17:14:23 +01004568 ret = 0;
4569exit:
4570 mutex_unlock(&ar->conf_mutex);
4571 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004572}
4573#endif
4574
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004575static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4576 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004577{
4578 struct ath10k *ar = hw->priv;
4579
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004580 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4581 return;
4582
Michal Kazioraffd3212013-07-16 09:54:35 +02004583 mutex_lock(&ar->conf_mutex);
4584
4585 /* If device failed to restart it will be in a different state, e.g.
4586 * ATH10K_STATE_WEDGED */
4587 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004588 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004589 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004590 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004591 }
4592
4593 mutex_unlock(&ar->conf_mutex);
4594}
4595
Michal Kazior2e1dea42013-07-31 10:32:40 +02004596static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4597 struct survey_info *survey)
4598{
4599 struct ath10k *ar = hw->priv;
4600 struct ieee80211_supported_band *sband;
4601 struct survey_info *ar_survey = &ar->survey[idx];
4602 int ret = 0;
4603
4604 mutex_lock(&ar->conf_mutex);
4605
4606 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4607 if (sband && idx >= sband->n_channels) {
4608 idx -= sband->n_channels;
4609 sband = NULL;
4610 }
4611
4612 if (!sband)
4613 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4614
4615 if (!sband || idx >= sband->n_channels) {
4616 ret = -ENOENT;
4617 goto exit;
4618 }
4619
4620 spin_lock_bh(&ar->data_lock);
4621 memcpy(survey, ar_survey, sizeof(*survey));
4622 spin_unlock_bh(&ar->data_lock);
4623
4624 survey->channel = &sband->channels[idx];
4625
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004626 if (ar->rx_channel == survey->channel)
4627 survey->filled |= SURVEY_INFO_IN_USE;
4628
Michal Kazior2e1dea42013-07-31 10:32:40 +02004629exit:
4630 mutex_unlock(&ar->conf_mutex);
4631 return ret;
4632}
4633
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004634/* Helper table for legacy fixed_rate/bitrate_mask */
4635static const u8 cck_ofdm_rate[] = {
4636 /* CCK */
4637 3, /* 1Mbps */
4638 2, /* 2Mbps */
4639 1, /* 5.5Mbps */
4640 0, /* 11Mbps */
4641 /* OFDM */
4642 3, /* 6Mbps */
4643 7, /* 9Mbps */
4644 2, /* 12Mbps */
4645 6, /* 18Mbps */
4646 1, /* 24Mbps */
4647 5, /* 36Mbps */
4648 0, /* 48Mbps */
4649 4, /* 54Mbps */
4650};
4651
4652/* Check if only one bit set */
4653static int ath10k_check_single_mask(u32 mask)
4654{
4655 int bit;
4656
4657 bit = ffs(mask);
4658 if (!bit)
4659 return 0;
4660
4661 mask &= ~BIT(bit - 1);
4662 if (mask)
4663 return 2;
4664
4665 return 1;
4666}
4667
4668static bool
4669ath10k_default_bitrate_mask(struct ath10k *ar,
4670 enum ieee80211_band band,
4671 const struct cfg80211_bitrate_mask *mask)
4672{
4673 u32 legacy = 0x00ff;
4674 u8 ht = 0xff, i;
4675 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004676 u16 nrf = ar->num_rf_chains;
4677
4678 if (ar->cfg_tx_chainmask)
4679 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004680
4681 switch (band) {
4682 case IEEE80211_BAND_2GHZ:
4683 legacy = 0x00fff;
4684 vht = 0;
4685 break;
4686 case IEEE80211_BAND_5GHZ:
4687 break;
4688 default:
4689 return false;
4690 }
4691
4692 if (mask->control[band].legacy != legacy)
4693 return false;
4694
Ben Greearb116ea12014-11-24 16:22:10 +02004695 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004696 if (mask->control[band].ht_mcs[i] != ht)
4697 return false;
4698
Ben Greearb116ea12014-11-24 16:22:10 +02004699 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004700 if (mask->control[band].vht_mcs[i] != vht)
4701 return false;
4702
4703 return true;
4704}
4705
4706static bool
4707ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4708 enum ieee80211_band band,
4709 u8 *fixed_nss)
4710{
4711 int ht_nss = 0, vht_nss = 0, i;
4712
4713 /* check legacy */
4714 if (ath10k_check_single_mask(mask->control[band].legacy))
4715 return false;
4716
4717 /* check HT */
4718 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4719 if (mask->control[band].ht_mcs[i] == 0xff)
4720 continue;
4721 else if (mask->control[band].ht_mcs[i] == 0x00)
4722 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004723
4724 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004725 }
4726
4727 ht_nss = i;
4728
4729 /* check VHT */
4730 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4731 if (mask->control[band].vht_mcs[i] == 0x03ff)
4732 continue;
4733 else if (mask->control[band].vht_mcs[i] == 0x0000)
4734 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004735
4736 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004737 }
4738
4739 vht_nss = i;
4740
4741 if (ht_nss > 0 && vht_nss > 0)
4742 return false;
4743
4744 if (ht_nss)
4745 *fixed_nss = ht_nss;
4746 else if (vht_nss)
4747 *fixed_nss = vht_nss;
4748 else
4749 return false;
4750
4751 return true;
4752}
4753
4754static bool
4755ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4756 enum ieee80211_band band,
4757 enum wmi_rate_preamble *preamble)
4758{
4759 int legacy = 0, ht = 0, vht = 0, i;
4760
4761 *preamble = WMI_RATE_PREAMBLE_OFDM;
4762
4763 /* check legacy */
4764 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4765 if (legacy > 1)
4766 return false;
4767
4768 /* check HT */
4769 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4770 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4771 if (ht > 1)
4772 return false;
4773
4774 /* check VHT */
4775 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4776 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4777 if (vht > 1)
4778 return false;
4779
4780 /* Currently we support only one fixed_rate */
4781 if ((legacy + ht + vht) != 1)
4782 return false;
4783
4784 if (ht)
4785 *preamble = WMI_RATE_PREAMBLE_HT;
4786 else if (vht)
4787 *preamble = WMI_RATE_PREAMBLE_VHT;
4788
4789 return true;
4790}
4791
4792static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004793ath10k_bitrate_mask_rate(struct ath10k *ar,
4794 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004795 enum ieee80211_band band,
4796 u8 *fixed_rate,
4797 u8 *fixed_nss)
4798{
4799 u8 rate = 0, pream = 0, nss = 0, i;
4800 enum wmi_rate_preamble preamble;
4801
4802 /* Check if single rate correct */
4803 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4804 return false;
4805
4806 pream = preamble;
4807
4808 switch (preamble) {
4809 case WMI_RATE_PREAMBLE_CCK:
4810 case WMI_RATE_PREAMBLE_OFDM:
4811 i = ffs(mask->control[band].legacy) - 1;
4812
4813 if (band == IEEE80211_BAND_2GHZ && i < 4)
4814 pream = WMI_RATE_PREAMBLE_CCK;
4815
4816 if (band == IEEE80211_BAND_5GHZ)
4817 i += 4;
4818
4819 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4820 return false;
4821
4822 rate = cck_ofdm_rate[i];
4823 break;
4824 case WMI_RATE_PREAMBLE_HT:
4825 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4826 if (mask->control[band].ht_mcs[i])
4827 break;
4828
4829 if (i == IEEE80211_HT_MCS_MASK_LEN)
4830 return false;
4831
4832 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4833 nss = i;
4834 break;
4835 case WMI_RATE_PREAMBLE_VHT:
4836 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4837 if (mask->control[band].vht_mcs[i])
4838 break;
4839
4840 if (i == NL80211_VHT_NSS_MAX)
4841 return false;
4842
4843 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4844 nss = i;
4845 break;
4846 }
4847
4848 *fixed_nss = nss + 1;
4849 nss <<= 4;
4850 pream <<= 6;
4851
Michal Kazior7aa7a722014-08-25 12:09:38 +02004852 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 +01004853 pream, nss, rate);
4854
4855 *fixed_rate = pream | nss | rate;
4856
4857 return true;
4858}
4859
Michal Kazior7aa7a722014-08-25 12:09:38 +02004860static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4861 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004862 enum ieee80211_band band,
4863 u8 *fixed_rate,
4864 u8 *fixed_nss)
4865{
4866 /* First check full NSS mask, if we can simply limit NSS */
4867 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4868 return true;
4869
4870 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004871 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004872}
4873
4874static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4875 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004876 u8 fixed_nss,
4877 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004878{
4879 struct ath10k *ar = arvif->ar;
4880 u32 vdev_param;
4881 int ret = 0;
4882
4883 mutex_lock(&ar->conf_mutex);
4884
4885 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004886 arvif->fixed_nss == fixed_nss &&
4887 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004888 goto exit;
4889
4890 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004891 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004892
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004893 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004894 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004895
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004896 vdev_param = ar->wmi.vdev_param->fixed_rate;
4897 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4898 vdev_param, fixed_rate);
4899 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004900 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004901 fixed_rate, ret);
4902 ret = -EINVAL;
4903 goto exit;
4904 }
4905
4906 arvif->fixed_rate = fixed_rate;
4907
4908 vdev_param = ar->wmi.vdev_param->nss;
4909 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4910 vdev_param, fixed_nss);
4911
4912 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004913 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004914 fixed_nss, ret);
4915 ret = -EINVAL;
4916 goto exit;
4917 }
4918
4919 arvif->fixed_nss = fixed_nss;
4920
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004921 vdev_param = ar->wmi.vdev_param->sgi;
4922 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4923 force_sgi);
4924
4925 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004926 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004927 force_sgi, ret);
4928 ret = -EINVAL;
4929 goto exit;
4930 }
4931
4932 arvif->force_sgi = force_sgi;
4933
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004934exit:
4935 mutex_unlock(&ar->conf_mutex);
4936 return ret;
4937}
4938
4939static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4940 struct ieee80211_vif *vif,
4941 const struct cfg80211_bitrate_mask *mask)
4942{
4943 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4944 struct ath10k *ar = arvif->ar;
4945 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4946 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4947 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004948 u8 force_sgi;
4949
Ben Greearb116ea12014-11-24 16:22:10 +02004950 if (ar->cfg_tx_chainmask)
4951 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4952
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004953 force_sgi = mask->control[band].gi;
4954 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4955 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004956
4957 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004958 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004959 &fixed_rate,
4960 &fixed_nss))
4961 return -EINVAL;
4962 }
4963
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004964 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004965 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004966 return -EINVAL;
4967 }
4968
4969 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4970 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004971}
4972
Michal Kazior9797feb2014-02-14 14:49:48 +01004973static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4974 struct ieee80211_vif *vif,
4975 struct ieee80211_sta *sta,
4976 u32 changed)
4977{
4978 struct ath10k *ar = hw->priv;
4979 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4980 u32 bw, smps;
4981
4982 spin_lock_bh(&ar->data_lock);
4983
Michal Kazior7aa7a722014-08-25 12:09:38 +02004984 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004985 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4986 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4987 sta->smps_mode);
4988
4989 if (changed & IEEE80211_RC_BW_CHANGED) {
4990 bw = WMI_PEER_CHWIDTH_20MHZ;
4991
4992 switch (sta->bandwidth) {
4993 case IEEE80211_STA_RX_BW_20:
4994 bw = WMI_PEER_CHWIDTH_20MHZ;
4995 break;
4996 case IEEE80211_STA_RX_BW_40:
4997 bw = WMI_PEER_CHWIDTH_40MHZ;
4998 break;
4999 case IEEE80211_STA_RX_BW_80:
5000 bw = WMI_PEER_CHWIDTH_80MHZ;
5001 break;
5002 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005003 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005004 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005005 bw = WMI_PEER_CHWIDTH_20MHZ;
5006 break;
5007 }
5008
5009 arsta->bw = bw;
5010 }
5011
5012 if (changed & IEEE80211_RC_NSS_CHANGED)
5013 arsta->nss = sta->rx_nss;
5014
5015 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5016 smps = WMI_PEER_SMPS_PS_NONE;
5017
5018 switch (sta->smps_mode) {
5019 case IEEE80211_SMPS_AUTOMATIC:
5020 case IEEE80211_SMPS_OFF:
5021 smps = WMI_PEER_SMPS_PS_NONE;
5022 break;
5023 case IEEE80211_SMPS_STATIC:
5024 smps = WMI_PEER_SMPS_STATIC;
5025 break;
5026 case IEEE80211_SMPS_DYNAMIC:
5027 smps = WMI_PEER_SMPS_DYNAMIC;
5028 break;
5029 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005030 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005031 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005032 smps = WMI_PEER_SMPS_PS_NONE;
5033 break;
5034 }
5035
5036 arsta->smps = smps;
5037 }
5038
Michal Kazior9797feb2014-02-14 14:49:48 +01005039 arsta->changed |= changed;
5040
5041 spin_unlock_bh(&ar->data_lock);
5042
5043 ieee80211_queue_work(hw, &arsta->update_wk);
5044}
5045
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005046static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5047{
5048 /*
5049 * FIXME: Return 0 for time being. Need to figure out whether FW
5050 * has the API to fetch 64-bit local TSF
5051 */
5052
5053 return 0;
5054}
5055
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005056static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5057 struct ieee80211_vif *vif,
5058 enum ieee80211_ampdu_mlme_action action,
5059 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5060 u8 buf_size)
5061{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005062 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005063 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5064
Michal Kazior7aa7a722014-08-25 12:09:38 +02005065 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 +02005066 arvif->vdev_id, sta->addr, tid, action);
5067
5068 switch (action) {
5069 case IEEE80211_AMPDU_RX_START:
5070 case IEEE80211_AMPDU_RX_STOP:
5071 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5072 * creation/removal. Do we need to verify this?
5073 */
5074 return 0;
5075 case IEEE80211_AMPDU_TX_START:
5076 case IEEE80211_AMPDU_TX_STOP_CONT:
5077 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5078 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5079 case IEEE80211_AMPDU_TX_OPERATIONAL:
5080 /* Firmware offloads Tx aggregation entirely so deny mac80211
5081 * Tx aggregation requests.
5082 */
5083 return -EOPNOTSUPP;
5084 }
5085
5086 return -EINVAL;
5087}
5088
Kalle Valo5e3dd152013-06-12 20:52:10 +03005089static const struct ieee80211_ops ath10k_ops = {
5090 .tx = ath10k_tx,
5091 .start = ath10k_start,
5092 .stop = ath10k_stop,
5093 .config = ath10k_config,
5094 .add_interface = ath10k_add_interface,
5095 .remove_interface = ath10k_remove_interface,
5096 .configure_filter = ath10k_configure_filter,
5097 .bss_info_changed = ath10k_bss_info_changed,
5098 .hw_scan = ath10k_hw_scan,
5099 .cancel_hw_scan = ath10k_cancel_hw_scan,
5100 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005101 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005102 .sta_state = ath10k_sta_state,
5103 .conf_tx = ath10k_conf_tx,
5104 .remain_on_channel = ath10k_remain_on_channel,
5105 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5106 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005107 .flush = ath10k_flush,
5108 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03005109 .set_antenna = ath10k_set_antenna,
5110 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005111 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005112 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005113 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005114 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005115 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005116 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005117 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5118 .get_et_stats = ath10k_debug_get_et_stats,
5119 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005120
5121 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5122
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005123#ifdef CONFIG_PM
5124 .suspend = ath10k_suspend,
5125 .resume = ath10k_resume,
5126#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005127#ifdef CONFIG_MAC80211_DEBUGFS
5128 .sta_add_debugfs = ath10k_sta_add_debugfs,
5129#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005130};
5131
5132#define RATETAB_ENT(_rate, _rateid, _flags) { \
5133 .bitrate = (_rate), \
5134 .flags = (_flags), \
5135 .hw_value = (_rateid), \
5136}
5137
5138#define CHAN2G(_channel, _freq, _flags) { \
5139 .band = IEEE80211_BAND_2GHZ, \
5140 .hw_value = (_channel), \
5141 .center_freq = (_freq), \
5142 .flags = (_flags), \
5143 .max_antenna_gain = 0, \
5144 .max_power = 30, \
5145}
5146
5147#define CHAN5G(_channel, _freq, _flags) { \
5148 .band = IEEE80211_BAND_5GHZ, \
5149 .hw_value = (_channel), \
5150 .center_freq = (_freq), \
5151 .flags = (_flags), \
5152 .max_antenna_gain = 0, \
5153 .max_power = 30, \
5154}
5155
5156static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5157 CHAN2G(1, 2412, 0),
5158 CHAN2G(2, 2417, 0),
5159 CHAN2G(3, 2422, 0),
5160 CHAN2G(4, 2427, 0),
5161 CHAN2G(5, 2432, 0),
5162 CHAN2G(6, 2437, 0),
5163 CHAN2G(7, 2442, 0),
5164 CHAN2G(8, 2447, 0),
5165 CHAN2G(9, 2452, 0),
5166 CHAN2G(10, 2457, 0),
5167 CHAN2G(11, 2462, 0),
5168 CHAN2G(12, 2467, 0),
5169 CHAN2G(13, 2472, 0),
5170 CHAN2G(14, 2484, 0),
5171};
5172
5173static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005174 CHAN5G(36, 5180, 0),
5175 CHAN5G(40, 5200, 0),
5176 CHAN5G(44, 5220, 0),
5177 CHAN5G(48, 5240, 0),
5178 CHAN5G(52, 5260, 0),
5179 CHAN5G(56, 5280, 0),
5180 CHAN5G(60, 5300, 0),
5181 CHAN5G(64, 5320, 0),
5182 CHAN5G(100, 5500, 0),
5183 CHAN5G(104, 5520, 0),
5184 CHAN5G(108, 5540, 0),
5185 CHAN5G(112, 5560, 0),
5186 CHAN5G(116, 5580, 0),
5187 CHAN5G(120, 5600, 0),
5188 CHAN5G(124, 5620, 0),
5189 CHAN5G(128, 5640, 0),
5190 CHAN5G(132, 5660, 0),
5191 CHAN5G(136, 5680, 0),
5192 CHAN5G(140, 5700, 0),
5193 CHAN5G(149, 5745, 0),
5194 CHAN5G(153, 5765, 0),
5195 CHAN5G(157, 5785, 0),
5196 CHAN5G(161, 5805, 0),
5197 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005198};
5199
Michal Kazior91b12082014-12-12 12:41:35 +01005200/* Note: Be careful if you re-order these. There is code which depends on this
5201 * ordering.
5202 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005203static struct ieee80211_rate ath10k_rates[] = {
5204 /* CCK */
5205 RATETAB_ENT(10, 0x82, 0),
5206 RATETAB_ENT(20, 0x84, 0),
5207 RATETAB_ENT(55, 0x8b, 0),
5208 RATETAB_ENT(110, 0x96, 0),
5209 /* OFDM */
5210 RATETAB_ENT(60, 0x0c, 0),
5211 RATETAB_ENT(90, 0x12, 0),
5212 RATETAB_ENT(120, 0x18, 0),
5213 RATETAB_ENT(180, 0x24, 0),
5214 RATETAB_ENT(240, 0x30, 0),
5215 RATETAB_ENT(360, 0x48, 0),
5216 RATETAB_ENT(480, 0x60, 0),
5217 RATETAB_ENT(540, 0x6c, 0),
5218};
5219
5220#define ath10k_a_rates (ath10k_rates + 4)
5221#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5222#define ath10k_g_rates (ath10k_rates + 0)
5223#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5224
Michal Kaziore7b54192014-08-07 11:03:27 +02005225struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005226{
5227 struct ieee80211_hw *hw;
5228 struct ath10k *ar;
5229
Michal Kaziore7b54192014-08-07 11:03:27 +02005230 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005231 if (!hw)
5232 return NULL;
5233
5234 ar = hw->priv;
5235 ar->hw = hw;
5236
5237 return ar;
5238}
5239
5240void ath10k_mac_destroy(struct ath10k *ar)
5241{
5242 ieee80211_free_hw(ar->hw);
5243}
5244
5245static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5246 {
5247 .max = 8,
5248 .types = BIT(NL80211_IFTYPE_STATION)
5249 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005250 },
5251 {
5252 .max = 3,
5253 .types = BIT(NL80211_IFTYPE_P2P_GO)
5254 },
5255 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005256 .max = 1,
5257 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5258 },
5259 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005260 .max = 7,
5261 .types = BIT(NL80211_IFTYPE_AP)
5262 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005263};
5264
Bartosz Markowskif2595092013-12-10 16:20:39 +01005265static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005266 {
5267 .max = 8,
5268 .types = BIT(NL80211_IFTYPE_AP)
5269 },
5270};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005271
5272static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5273 {
5274 .limits = ath10k_if_limits,
5275 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5276 .max_interfaces = 8,
5277 .num_different_channels = 1,
5278 .beacon_int_infra_match = true,
5279 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005280};
5281
5282static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005283 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005284 .limits = ath10k_10x_if_limits,
5285 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005286 .max_interfaces = 8,
5287 .num_different_channels = 1,
5288 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005289#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005290 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5291 BIT(NL80211_CHAN_WIDTH_20) |
5292 BIT(NL80211_CHAN_WIDTH_40) |
5293 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005294#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005295 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005296};
5297
5298static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5299{
5300 struct ieee80211_sta_vht_cap vht_cap = {0};
5301 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005302 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005303
5304 vht_cap.vht_supported = 1;
5305 vht_cap.cap = ar->vht_cap_info;
5306
Michal Kazior8865bee42013-07-24 12:36:46 +02005307 mcs_map = 0;
5308 for (i = 0; i < 8; i++) {
5309 if (i < ar->num_rf_chains)
5310 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5311 else
5312 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5313 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314
5315 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5316 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5317
5318 return vht_cap;
5319}
5320
5321static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5322{
5323 int i;
5324 struct ieee80211_sta_ht_cap ht_cap = {0};
5325
5326 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5327 return ht_cap;
5328
5329 ht_cap.ht_supported = 1;
5330 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5331 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5332 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5333 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5334 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5335
5336 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5337 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5338
5339 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5340 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5341
5342 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5343 u32 smps;
5344
5345 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5346 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5347
5348 ht_cap.cap |= smps;
5349 }
5350
5351 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5352 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5353
5354 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5355 u32 stbc;
5356
5357 stbc = ar->ht_cap_info;
5358 stbc &= WMI_HT_CAP_RX_STBC;
5359 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5360 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5361 stbc &= IEEE80211_HT_CAP_RX_STBC;
5362
5363 ht_cap.cap |= stbc;
5364 }
5365
5366 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5367 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5368
5369 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5370 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5371
5372 /* max AMSDU is implicitly taken from vht_cap_info */
5373 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5374 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5375
Michal Kazior8865bee42013-07-24 12:36:46 +02005376 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005377 ht_cap.mcs.rx_mask[i] = 0xFF;
5378
5379 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5380
5381 return ht_cap;
5382}
5383
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384static void ath10k_get_arvif_iter(void *data, u8 *mac,
5385 struct ieee80211_vif *vif)
5386{
5387 struct ath10k_vif_iter *arvif_iter = data;
5388 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5389
5390 if (arvif->vdev_id == arvif_iter->vdev_id)
5391 arvif_iter->arvif = arvif;
5392}
5393
5394struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5395{
5396 struct ath10k_vif_iter arvif_iter;
5397 u32 flags;
5398
5399 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5400 arvif_iter.vdev_id = vdev_id;
5401
5402 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5403 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5404 flags,
5405 ath10k_get_arvif_iter,
5406 &arvif_iter);
5407 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005408 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005409 return NULL;
5410 }
5411
5412 return arvif_iter.arvif;
5413}
5414
5415int ath10k_mac_register(struct ath10k *ar)
5416{
5417 struct ieee80211_supported_band *band;
5418 struct ieee80211_sta_vht_cap vht_cap;
5419 struct ieee80211_sta_ht_cap ht_cap;
5420 void *channels;
5421 int ret;
5422
5423 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5424
5425 SET_IEEE80211_DEV(ar->hw, ar->dev);
5426
5427 ht_cap = ath10k_get_ht_cap(ar);
5428 vht_cap = ath10k_create_vht_cap(ar);
5429
5430 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5431 channels = kmemdup(ath10k_2ghz_channels,
5432 sizeof(ath10k_2ghz_channels),
5433 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005434 if (!channels) {
5435 ret = -ENOMEM;
5436 goto err_free;
5437 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438
5439 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5440 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5441 band->channels = channels;
5442 band->n_bitrates = ath10k_g_rates_size;
5443 band->bitrates = ath10k_g_rates;
5444 band->ht_cap = ht_cap;
5445
Yanbo Lid68bb122015-01-23 08:18:20 +08005446 /* Enable the VHT support at 2.4 GHz */
5447 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005448
5449 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5450 }
5451
5452 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5453 channels = kmemdup(ath10k_5ghz_channels,
5454 sizeof(ath10k_5ghz_channels),
5455 GFP_KERNEL);
5456 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005457 ret = -ENOMEM;
5458 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005459 }
5460
5461 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5462 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5463 band->channels = channels;
5464 band->n_bitrates = ath10k_a_rates_size;
5465 band->bitrates = ath10k_a_rates;
5466 band->ht_cap = ht_cap;
5467 band->vht_cap = vht_cap;
5468 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5469 }
5470
5471 ar->hw->wiphy->interface_modes =
5472 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005473 BIT(NL80211_IFTYPE_AP);
5474
Ben Greear46acf7bb2014-05-16 17:15:38 +03005475 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5476 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5477
Bartosz Markowskid3541812013-12-10 16:20:40 +01005478 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5479 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005480 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005481 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5482 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005483
5484 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5485 IEEE80211_HW_SUPPORTS_PS |
5486 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005487 IEEE80211_HW_MFP_CAPABLE |
5488 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5489 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005490 IEEE80211_HW_AP_LINK_PS |
5491 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005492
Eliad Peller0d8614b2014-09-10 14:07:36 +03005493 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5494
Kalle Valo5e3dd152013-06-12 20:52:10 +03005495 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005496 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497
5498 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5499 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5500 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5501 }
5502
5503 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5504 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5505
5506 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005507 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005508
Kalle Valo5e3dd152013-06-12 20:52:10 +03005509 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5510
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005511 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5512 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5513
5514 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5515 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5516 * correct Probe Responses. This is more of a hack advert..
5517 */
5518 ar->hw->wiphy->probe_resp_offload |=
5519 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5520 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5521 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5522 }
5523
Kalle Valo5e3dd152013-06-12 20:52:10 +03005524 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005525 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005526 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5527
5528 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005529 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5530
Kalle Valo5e3dd152013-06-12 20:52:10 +03005531 /*
5532 * on LL hardware queues are managed entirely by the FW
5533 * so we only advertise to mac we can do the queues thing
5534 */
5535 ar->hw->queues = 4;
5536
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005537 switch (ar->wmi.op_version) {
5538 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5539 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005540 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5541 ar->hw->wiphy->n_iface_combinations =
5542 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005543 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005544 break;
5545 case ATH10K_FW_WMI_OP_VERSION_10_1:
5546 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005547 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005548 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5549 ar->hw->wiphy->n_iface_combinations =
5550 ARRAY_SIZE(ath10k_10x_if_comb);
5551 break;
5552 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5553 case ATH10K_FW_WMI_OP_VERSION_MAX:
5554 WARN_ON(1);
5555 ret = -EINVAL;
5556 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005557 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005558
Michal Kazior7c199992013-07-31 10:47:57 +02005559 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5560
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005561 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5562 /* Init ath dfs pattern detector */
5563 ar->ath_common.debug_mask = ATH_DBG_DFS;
5564 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5565 NL80211_DFS_UNSET);
5566
5567 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005568 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005569 }
5570
Kalle Valo5e3dd152013-06-12 20:52:10 +03005571 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5572 ath10k_reg_notifier);
5573 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005574 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005575 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005576 }
5577
5578 ret = ieee80211_register_hw(ar->hw);
5579 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005580 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005581 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005582 }
5583
5584 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5585 ret = regulatory_hint(ar->hw->wiphy,
5586 ar->ath_common.regulatory.alpha2);
5587 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005588 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005589 }
5590
5591 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005592
5593err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005594 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005595err_free:
5596 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5597 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5598
Kalle Valo5e3dd152013-06-12 20:52:10 +03005599 return ret;
5600}
5601
5602void ath10k_mac_unregister(struct ath10k *ar)
5603{
5604 ieee80211_unregister_hw(ar->hw);
5605
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005606 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5607 ar->dfs_detector->exit(ar->dfs_detector);
5608
Kalle Valo5e3dd152013-06-12 20:52:10 +03005609 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5610 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5611
5612 SET_IEEE80211_DEV(ar->hw, NULL);
5613}