blob: d8a8caa243e9d05a645421cea70d6f0426669c47 [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) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200611 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %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)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200658 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %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) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200927 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300928 arg.vdev_id, ret);
929 return ret;
930 }
931
Michal Kaziord6500972014-04-08 09:56:09 +0300932 ar->num_started_vdevs++;
933 ath10k_recalc_radar_detection(ar);
934
Michal Kazior72654fa2014-04-08 09:56:09 +0300935 return ret;
936}
937
Michal Kaziordc55e302014-07-29 12:53:36 +0300938static int ath10k_vdev_start(struct ath10k_vif *arvif)
939{
940 return ath10k_vdev_start_restart(arvif, false);
941}
942
943static int ath10k_vdev_restart(struct ath10k_vif *arvif)
944{
945 return ath10k_vdev_start_restart(arvif, true);
946}
947
Michal Kazior72654fa2014-04-08 09:56:09 +0300948static int ath10k_vdev_stop(struct ath10k_vif *arvif)
949{
950 struct ath10k *ar = arvif->ar;
951 int ret;
952
953 lockdep_assert_held(&ar->conf_mutex);
954
955 reinit_completion(&ar->vdev_setup_done);
956
957 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200959 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300960 arvif->vdev_id, ret);
961 return ret;
962 }
963
964 ret = ath10k_vdev_setup_sync(ar);
965 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200966 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300967 arvif->vdev_id, ret);
968 return ret;
969 }
970
Michal Kaziord6500972014-04-08 09:56:09 +0300971 WARN_ON(ar->num_started_vdevs == 0);
972
973 if (ar->num_started_vdevs != 0) {
974 ar->num_started_vdevs--;
975 ath10k_recalc_radar_detection(ar);
976 }
977
Michal Kazior72654fa2014-04-08 09:56:09 +0300978 return ret;
979}
980
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200981static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
982 struct sk_buff *bcn)
983{
984 struct ath10k *ar = arvif->ar;
985 struct ieee80211_mgmt *mgmt;
986 const u8 *p2p_ie;
987 int ret;
988
989 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
990 return 0;
991
992 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
993 return 0;
994
995 mgmt = (void *)bcn->data;
996 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
997 mgmt->u.beacon.variable,
998 bcn->len - (mgmt->u.beacon.variable -
999 bcn->data));
1000 if (!p2p_ie)
1001 return -ENOENT;
1002
1003 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1004 if (ret) {
1005 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1006 arvif->vdev_id, ret);
1007 return ret;
1008 }
1009
1010 return 0;
1011}
1012
1013static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1014 u8 oui_type, size_t ie_offset)
1015{
1016 size_t len;
1017 const u8 *next;
1018 const u8 *end;
1019 u8 *ie;
1020
1021 if (WARN_ON(skb->len < ie_offset))
1022 return -EINVAL;
1023
1024 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1025 skb->data + ie_offset,
1026 skb->len - ie_offset);
1027 if (!ie)
1028 return -ENOENT;
1029
1030 len = ie[1] + 2;
1031 end = skb->data + skb->len;
1032 next = ie + len;
1033
1034 if (WARN_ON(next > end))
1035 return -EINVAL;
1036
1037 memmove(ie, next, end - next);
1038 skb_trim(skb, skb->len - len);
1039
1040 return 0;
1041}
1042
1043static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1044{
1045 struct ath10k *ar = arvif->ar;
1046 struct ieee80211_hw *hw = ar->hw;
1047 struct ieee80211_vif *vif = arvif->vif;
1048 struct ieee80211_mutable_offsets offs = {};
1049 struct sk_buff *bcn;
1050 int ret;
1051
1052 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1053 return 0;
1054
1055 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1056 if (!bcn) {
1057 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1058 return -EPERM;
1059 }
1060
1061 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1062 if (ret) {
1063 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1064 kfree_skb(bcn);
1065 return ret;
1066 }
1067
1068 /* P2P IE is inserted by firmware automatically (as configured above)
1069 * so remove it from the base beacon template to avoid duplicate P2P
1070 * IEs in beacon frames.
1071 */
1072 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1073 offsetof(struct ieee80211_mgmt,
1074 u.beacon.variable));
1075
1076 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1077 0, NULL, 0);
1078 kfree_skb(bcn);
1079
1080 if (ret) {
1081 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1082 ret);
1083 return ret;
1084 }
1085
1086 return 0;
1087}
1088
1089static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1090{
1091 struct ath10k *ar = arvif->ar;
1092 struct ieee80211_hw *hw = ar->hw;
1093 struct ieee80211_vif *vif = arvif->vif;
1094 struct sk_buff *prb;
1095 int ret;
1096
1097 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1098 return 0;
1099
1100 prb = ieee80211_proberesp_get(hw, vif);
1101 if (!prb) {
1102 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1103 return -EPERM;
1104 }
1105
1106 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1107 kfree_skb(prb);
1108
1109 if (ret) {
1110 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1111 ret);
1112 return ret;
1113 }
1114
1115 return 0;
1116}
1117
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001119 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001120{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001121 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 int ret = 0;
1123
Michal Kazior548db542013-07-05 16:15:15 +03001124 lockdep_assert_held(&arvif->ar->conf_mutex);
1125
Kalle Valo5e3dd152013-06-12 20:52:10 +03001126 if (!info->enable_beacon) {
1127 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001128
1129 arvif->is_started = false;
1130 arvif->is_up = false;
1131
Michal Kazior748afc42014-01-23 12:48:21 +01001132 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001133 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001134 spin_unlock_bh(&arvif->ar->data_lock);
1135
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 return;
1137 }
1138
1139 arvif->tx_seq_no = 0x1000;
1140
1141 ret = ath10k_vdev_start(arvif);
1142 if (ret)
1143 return;
1144
Michal Kaziorc930f742014-01-23 11:38:25 +01001145 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001146 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001147
1148 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1149 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001150 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001151 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001152 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001153 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154 return;
1155 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001156
1157 arvif->is_started = true;
1158 arvif->is_up = true;
1159
Michal Kazior7aa7a722014-08-25 12:09:38 +02001160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161}
1162
1163static void ath10k_control_ibss(struct ath10k_vif *arvif,
1164 struct ieee80211_bss_conf *info,
1165 const u8 self_peer[ETH_ALEN])
1166{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001167 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001168 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169 int ret = 0;
1170
Michal Kazior548db542013-07-05 16:15:15 +03001171 lockdep_assert_held(&arvif->ar->conf_mutex);
1172
Kalle Valo5e3dd152013-06-12 20:52:10 +03001173 if (!info->ibss_joined) {
1174 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1175 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001176 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177 self_peer, arvif->vdev_id, ret);
1178
Michal Kaziorc930f742014-01-23 11:38:25 +01001179 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001180 return;
1181
Michal Kaziorc930f742014-01-23 11:38:25 +01001182 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001183
1184 return;
1185 }
1186
1187 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1188 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001189 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001190 self_peer, arvif->vdev_id, ret);
1191 return;
1192 }
1193
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001194 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1195 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001196 ATH10K_DEFAULT_ATIM);
1197 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001198 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001199 arvif->vdev_id, ret);
1200}
1201
Michal Kazior9f9b5742014-12-12 12:41:36 +01001202static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1203{
1204 struct ath10k *ar = arvif->ar;
1205 u32 param;
1206 u32 value;
1207 int ret;
1208
1209 lockdep_assert_held(&arvif->ar->conf_mutex);
1210
1211 if (arvif->u.sta.uapsd)
1212 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1213 else
1214 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1215
1216 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1217 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1218 if (ret) {
1219 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1220 value, arvif->vdev_id, ret);
1221 return ret;
1222 }
1223
1224 return 0;
1225}
1226
1227static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1228{
1229 struct ath10k *ar = arvif->ar;
1230 u32 param;
1231 u32 value;
1232 int ret;
1233
1234 lockdep_assert_held(&arvif->ar->conf_mutex);
1235
1236 if (arvif->u.sta.uapsd)
1237 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1238 else
1239 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1240
1241 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1242 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1243 param, value);
1244 if (ret) {
1245 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1246 value, arvif->vdev_id, ret);
1247 return ret;
1248 }
1249
1250 return 0;
1251}
1252
Michal Kaziorad088bf2013-10-16 15:44:46 +03001253static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001255 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001256 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001257 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 enum wmi_sta_powersave_param param;
1259 enum wmi_sta_ps_mode psmode;
1260 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001261 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262
Michal Kazior548db542013-07-05 16:15:15 +03001263 lockdep_assert_held(&arvif->ar->conf_mutex);
1264
Michal Kaziorad088bf2013-10-16 15:44:46 +03001265 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1266 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267
Michal Kaziorbf14e652014-12-12 12:41:38 +01001268 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001269 psmode = WMI_STA_PS_MODE_ENABLED;
1270 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1271
Michal Kazior526549a2014-12-12 12:41:37 +01001272 ps_timeout = conf->dynamic_ps_timeout;
1273 if (ps_timeout == 0) {
1274 /* Firmware doesn't like 0 */
1275 ps_timeout = ieee80211_tu_to_usec(
1276 vif->bss_conf.beacon_int) / 1000;
1277 }
1278
Michal Kaziorad088bf2013-10-16 15:44:46 +03001279 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001280 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001282 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001283 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001284 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001285 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286 } else {
1287 psmode = WMI_STA_PS_MODE_DISABLED;
1288 }
1289
Michal Kazior7aa7a722014-08-25 12:09:38 +02001290 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001291 arvif->vdev_id, psmode ? "enable" : "disable");
1292
Michal Kaziorad088bf2013-10-16 15:44:46 +03001293 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001295 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001296 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001297 return ret;
1298 }
1299
1300 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001301}
1302
Michal Kazior46725b152015-01-28 09:57:49 +02001303static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1304{
1305 struct ath10k *ar = arvif->ar;
1306 struct wmi_sta_keepalive_arg arg = {};
1307 int ret;
1308
1309 lockdep_assert_held(&arvif->ar->conf_mutex);
1310
1311 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1312 return 0;
1313
1314 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1315 return 0;
1316
1317 /* Some firmware revisions have a bug and ignore the `enabled` field.
1318 * Instead use the interval to disable the keepalive.
1319 */
1320 arg.vdev_id = arvif->vdev_id;
1321 arg.enabled = 1;
1322 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1323 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1324
1325 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1326 if (ret) {
1327 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1328 arvif->vdev_id, ret);
1329 return ret;
1330 }
1331
1332 return 0;
1333}
1334
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335/**********************/
1336/* Station management */
1337/**********************/
1338
Michal Kazior590922a2014-10-21 10:10:29 +03001339static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1340 struct ieee80211_vif *vif)
1341{
1342 /* Some firmware revisions have unstable STA powersave when listen
1343 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1344 * generate NullFunc frames properly even if buffered frames have been
1345 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1346 * buffered frames. Often pinging the device from AP would simply fail.
1347 *
1348 * As a workaround set it to 1.
1349 */
1350 if (vif->type == NL80211_IFTYPE_STATION)
1351 return 1;
1352
1353 return ar->hw->conf.listen_interval;
1354}
1355
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001357 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001358 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 struct wmi_peer_assoc_complete_arg *arg)
1360{
Michal Kazior590922a2014-10-21 10:10:29 +03001361 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1362
Michal Kazior548db542013-07-05 16:15:15 +03001363 lockdep_assert_held(&ar->conf_mutex);
1364
Kalle Valob25f32c2014-09-14 12:50:49 +03001365 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 arg->vdev_id = arvif->vdev_id;
1367 arg->peer_aid = sta->aid;
1368 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001369 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001370 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001371 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001372}
1373
1374static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001375 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001376 struct wmi_peer_assoc_complete_arg *arg)
1377{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001378 struct ieee80211_bss_conf *info = &vif->bss_conf;
1379 struct cfg80211_bss *bss;
1380 const u8 *rsnie = NULL;
1381 const u8 *wpaie = NULL;
1382
Michal Kazior548db542013-07-05 16:15:15 +03001383 lockdep_assert_held(&ar->conf_mutex);
1384
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1386 info->bssid, NULL, 0, 0, 0);
1387 if (bss) {
1388 const struct cfg80211_bss_ies *ies;
1389
1390 rcu_read_lock();
1391 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1392
1393 ies = rcu_dereference(bss->ies);
1394
1395 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001396 WLAN_OUI_TYPE_MICROSOFT_WPA,
1397 ies->data,
1398 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001399 rcu_read_unlock();
1400 cfg80211_put_bss(ar->hw->wiphy, bss);
1401 }
1402
1403 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1404 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001405 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001406 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1407 }
1408
1409 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001410 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001411 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1412 }
1413}
1414
1415static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1416 struct ieee80211_sta *sta,
1417 struct wmi_peer_assoc_complete_arg *arg)
1418{
1419 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1420 const struct ieee80211_supported_band *sband;
1421 const struct ieee80211_rate *rates;
1422 u32 ratemask;
1423 int i;
1424
Michal Kazior548db542013-07-05 16:15:15 +03001425 lockdep_assert_held(&ar->conf_mutex);
1426
Kalle Valo5e3dd152013-06-12 20:52:10 +03001427 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1428 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1429 rates = sband->bitrates;
1430
1431 rateset->num_rates = 0;
1432
1433 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1434 if (!(ratemask & 1))
1435 continue;
1436
1437 rateset->rates[rateset->num_rates] = rates->hw_value;
1438 rateset->num_rates++;
1439 }
1440}
1441
1442static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1443 struct ieee80211_sta *sta,
1444 struct wmi_peer_assoc_complete_arg *arg)
1445{
1446 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001448 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001449
Michal Kazior548db542013-07-05 16:15:15 +03001450 lockdep_assert_held(&ar->conf_mutex);
1451
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452 if (!ht_cap->ht_supported)
1453 return;
1454
1455 arg->peer_flags |= WMI_PEER_HT;
1456 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1457 ht_cap->ampdu_factor)) - 1;
1458
1459 arg->peer_mpdu_density =
1460 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1461
1462 arg->peer_ht_caps = ht_cap->cap;
1463 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1464
1465 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1466 arg->peer_flags |= WMI_PEER_LDPC;
1467
1468 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1469 arg->peer_flags |= WMI_PEER_40MHZ;
1470 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1471 }
1472
1473 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1474 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1475
1476 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1477 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1478
1479 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1480 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1481 arg->peer_flags |= WMI_PEER_STBC;
1482 }
1483
1484 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1486 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1487 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1488 arg->peer_rate_caps |= stbc;
1489 arg->peer_flags |= WMI_PEER_STBC;
1490 }
1491
Kalle Valo5e3dd152013-06-12 20:52:10 +03001492 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1493 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1494 else if (ht_cap->mcs.rx_mask[1])
1495 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1496
1497 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1498 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1499 arg->peer_ht_rates.rates[n++] = i;
1500
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001501 /*
1502 * This is a workaround for HT-enabled STAs which break the spec
1503 * and have no HT capabilities RX mask (no HT RX MCS map).
1504 *
1505 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1506 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1507 *
1508 * Firmware asserts if such situation occurs.
1509 */
1510 if (n == 0) {
1511 arg->peer_ht_rates.num_rates = 8;
1512 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1513 arg->peer_ht_rates.rates[i] = i;
1514 } else {
1515 arg->peer_ht_rates.num_rates = n;
1516 arg->peer_num_spatial_streams = sta->rx_nss;
1517 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518
Michal Kazior7aa7a722014-08-25 12:09:38 +02001519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001520 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001521 arg->peer_ht_rates.num_rates,
1522 arg->peer_num_spatial_streams);
1523}
1524
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001525static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1526 struct ath10k_vif *arvif,
1527 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528{
1529 u32 uapsd = 0;
1530 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001531 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001532
Michal Kazior548db542013-07-05 16:15:15 +03001533 lockdep_assert_held(&ar->conf_mutex);
1534
Kalle Valo5e3dd152013-06-12 20:52:10 +03001535 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001536 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001537 sta->uapsd_queues, sta->max_sp);
1538
Kalle Valo5e3dd152013-06-12 20:52:10 +03001539 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1540 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1541 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1542 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1543 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1544 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1545 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1546 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1547 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1548 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1549 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1550 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1551
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1553 max_sp = sta->max_sp;
1554
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001555 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1556 sta->addr,
1557 WMI_AP_PS_PEER_PARAM_UAPSD,
1558 uapsd);
1559 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001560 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001561 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001562 return ret;
1563 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001564
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001565 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1566 sta->addr,
1567 WMI_AP_PS_PEER_PARAM_MAX_SP,
1568 max_sp);
1569 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001570 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001571 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001572 return ret;
1573 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574
1575 /* TODO setup this based on STA listen interval and
1576 beacon interval. Currently we don't know
1577 sta->listen_interval - mac80211 patch required.
1578 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001579 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001580 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1581 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001583 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001584 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001585 return ret;
1586 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001589 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590}
1591
1592static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1593 struct ieee80211_sta *sta,
1594 struct wmi_peer_assoc_complete_arg *arg)
1595{
1596 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001597 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001598
1599 if (!vht_cap->vht_supported)
1600 return;
1601
1602 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001603
1604 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1605 arg->peer_flags |= WMI_PEER_VHT_2G;
1606
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 arg->peer_vht_caps = vht_cap->cap;
1608
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001609 ampdu_factor = (vht_cap->cap &
1610 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1611 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1612
1613 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1614 * zero in VHT IE. Using it would result in degraded throughput.
1615 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1616 * it if VHT max_mpdu is smaller. */
1617 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1618 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1619 ampdu_factor)) - 1);
1620
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1622 arg->peer_flags |= WMI_PEER_80MHZ;
1623
1624 arg->peer_vht_rates.rx_max_rate =
1625 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1626 arg->peer_vht_rates.rx_mcs_set =
1627 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1628 arg->peer_vht_rates.tx_max_rate =
1629 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1630 arg->peer_vht_rates.tx_mcs_set =
1631 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1632
Michal Kazior7aa7a722014-08-25 12:09:38 +02001633 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001634 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635}
1636
1637static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001638 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 struct wmi_peer_assoc_complete_arg *arg)
1641{
Michal Kazior590922a2014-10-21 10:10:29 +03001642 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1643
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 switch (arvif->vdev_type) {
1645 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001646 if (sta->wme)
1647 arg->peer_flags |= WMI_PEER_QOS;
1648
1649 if (sta->wme && sta->uapsd_queues) {
1650 arg->peer_flags |= WMI_PEER_APSD;
1651 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 break;
1654 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001655 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001656 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001657 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001658 case WMI_VDEV_TYPE_IBSS:
1659 if (sta->wme)
1660 arg->peer_flags |= WMI_PEER_QOS;
1661 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 default:
1663 break;
1664 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001665
1666 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1667 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668}
1669
Michal Kazior91b12082014-12-12 12:41:35 +01001670static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1671{
1672 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1673 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1674}
1675
Kalle Valo5e3dd152013-06-12 20:52:10 +03001676static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001677 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001678 struct ieee80211_sta *sta,
1679 struct wmi_peer_assoc_complete_arg *arg)
1680{
1681 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1682
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683 switch (ar->hw->conf.chandef.chan->band) {
1684 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001685 if (sta->vht_cap.vht_supported) {
1686 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1687 phymode = MODE_11AC_VHT40;
1688 else
1689 phymode = MODE_11AC_VHT20;
1690 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1692 phymode = MODE_11NG_HT40;
1693 else
1694 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001695 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001697 } else {
1698 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699 }
1700
1701 break;
1702 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001703 /*
1704 * Check VHT first.
1705 */
1706 if (sta->vht_cap.vht_supported) {
1707 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1708 phymode = MODE_11AC_VHT80;
1709 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1710 phymode = MODE_11AC_VHT40;
1711 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1712 phymode = MODE_11AC_VHT20;
1713 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001714 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1715 phymode = MODE_11NA_HT40;
1716 else
1717 phymode = MODE_11NA_HT20;
1718 } else {
1719 phymode = MODE_11A;
1720 }
1721
1722 break;
1723 default:
1724 break;
1725 }
1726
Michal Kazior7aa7a722014-08-25 12:09:38 +02001727 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001728 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001729
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 arg->peer_phymode = phymode;
1731 WARN_ON(phymode == MODE_UNKNOWN);
1732}
1733
Kalle Valob9ada652013-10-16 15:44:46 +03001734static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001735 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001736 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001737 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738{
Michal Kazior548db542013-07-05 16:15:15 +03001739 lockdep_assert_held(&ar->conf_mutex);
1740
Kalle Valob9ada652013-10-16 15:44:46 +03001741 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742
Michal Kazior590922a2014-10-21 10:10:29 +03001743 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1744 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001745 ath10k_peer_assoc_h_rates(ar, sta, arg);
1746 ath10k_peer_assoc_h_ht(ar, sta, arg);
1747 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001748 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1749 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750
Kalle Valob9ada652013-10-16 15:44:46 +03001751 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752}
1753
Michal Kazior90046f52014-02-14 14:45:51 +01001754static const u32 ath10k_smps_map[] = {
1755 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1756 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1757 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1758 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1759};
1760
1761static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1762 const u8 *addr,
1763 const struct ieee80211_sta_ht_cap *ht_cap)
1764{
1765 int smps;
1766
1767 if (!ht_cap->ht_supported)
1768 return 0;
1769
1770 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1771 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1772
1773 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1774 return -EINVAL;
1775
1776 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1777 WMI_PEER_SMPS_STATE,
1778 ath10k_smps_map[smps]);
1779}
1780
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781/* can be called only in mac80211 callbacks due to `key_count` usage */
1782static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1783 struct ieee80211_vif *vif,
1784 struct ieee80211_bss_conf *bss_conf)
1785{
1786 struct ath10k *ar = hw->priv;
1787 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001788 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001789 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 struct ieee80211_sta *ap_sta;
1791 int ret;
1792
Michal Kazior548db542013-07-05 16:15:15 +03001793 lockdep_assert_held(&ar->conf_mutex);
1794
Michal Kazior077efc82014-10-21 10:10:29 +03001795 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1796 arvif->vdev_id, arvif->bssid, arvif->aid);
1797
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 rcu_read_lock();
1799
1800 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1801 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001802 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001803 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001804 rcu_read_unlock();
1805 return;
1806 }
1807
Michal Kazior90046f52014-02-14 14:45:51 +01001808 /* ap_sta must be accessed only within rcu section which must be left
1809 * before calling ath10k_setup_peer_smps() which might sleep. */
1810 ht_cap = ap_sta->ht_cap;
1811
Michal Kazior590922a2014-10-21 10:10:29 +03001812 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001813 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001814 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001815 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816 rcu_read_unlock();
1817 return;
1818 }
1819
1820 rcu_read_unlock();
1821
Kalle Valob9ada652013-10-16 15:44:46 +03001822 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001824 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001825 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001826 return;
1827 }
1828
Michal Kazior90046f52014-02-14 14:45:51 +01001829 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1830 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001831 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001832 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001833 return;
1834 }
1835
Michal Kazior7aa7a722014-08-25 12:09:38 +02001836 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001837 "mac vdev %d up (associated) bssid %pM aid %d\n",
1838 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1839
Michal Kazior077efc82014-10-21 10:10:29 +03001840 WARN_ON(arvif->is_up);
1841
Michal Kaziorc930f742014-01-23 11:38:25 +01001842 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001843 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001844
1845 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1846 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001847 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001849 return;
1850 }
1851
1852 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853}
1854
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1856 struct ieee80211_vif *vif)
1857{
1858 struct ath10k *ar = hw->priv;
1859 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1860 int ret;
1861
Michal Kazior548db542013-07-05 16:15:15 +03001862 lockdep_assert_held(&ar->conf_mutex);
1863
Michal Kazior077efc82014-10-21 10:10:29 +03001864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1865 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001866
Kalle Valo5e3dd152013-06-12 20:52:10 +03001867 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001868 if (ret)
1869 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1870 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001872 arvif->def_wep_key_idx = -1;
1873
Michal Kaziorc930f742014-01-23 11:38:25 +01001874 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001875}
1876
Michal Kazior590922a2014-10-21 10:10:29 +03001877static int ath10k_station_assoc(struct ath10k *ar,
1878 struct ieee80211_vif *vif,
1879 struct ieee80211_sta *sta,
1880 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881{
Michal Kazior590922a2014-10-21 10:10:29 +03001882 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001883 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884 int ret = 0;
1885
Michal Kazior548db542013-07-05 16:15:15 +03001886 lockdep_assert_held(&ar->conf_mutex);
1887
Michal Kazior590922a2014-10-21 10:10:29 +03001888 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001890 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001891 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001892 return ret;
1893 }
1894
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001895 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001896 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1897 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001898 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001899 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001900 return ret;
1901 }
1902
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001903 /* Re-assoc is run only to update supported rates for given station. It
1904 * doesn't make much sense to reconfigure the peer completely.
1905 */
1906 if (!reassoc) {
1907 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1908 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001909 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001910 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001911 arvif->vdev_id, ret);
1912 return ret;
1913 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001914
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001915 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1916 if (ret) {
1917 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1918 sta->addr, arvif->vdev_id, ret);
1919 return ret;
1920 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001921
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001922 if (!sta->wme) {
1923 arvif->num_legacy_stations++;
1924 ret = ath10k_recalc_rtscts_prot(arvif);
1925 if (ret) {
1926 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1927 arvif->vdev_id, ret);
1928 return ret;
1929 }
1930 }
1931
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001932 /* Plumb cached keys only for static WEP */
1933 if (arvif->def_wep_key_idx != -1) {
1934 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1935 if (ret) {
1936 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1937 arvif->vdev_id, ret);
1938 return ret;
1939 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 }
1941 }
1942
Kalle Valo5e3dd152013-06-12 20:52:10 +03001943 return ret;
1944}
1945
Michal Kazior590922a2014-10-21 10:10:29 +03001946static int ath10k_station_disassoc(struct ath10k *ar,
1947 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 struct ieee80211_sta *sta)
1949{
Michal Kazior590922a2014-10-21 10:10:29 +03001950 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 int ret = 0;
1952
1953 lockdep_assert_held(&ar->conf_mutex);
1954
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001955 if (!sta->wme) {
1956 arvif->num_legacy_stations--;
1957 ret = ath10k_recalc_rtscts_prot(arvif);
1958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001959 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001960 arvif->vdev_id, ret);
1961 return ret;
1962 }
1963 }
1964
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1966 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001967 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001968 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969 return ret;
1970 }
1971
1972 return ret;
1973}
1974
1975/**************/
1976/* Regulatory */
1977/**************/
1978
1979static int ath10k_update_channel_list(struct ath10k *ar)
1980{
1981 struct ieee80211_hw *hw = ar->hw;
1982 struct ieee80211_supported_band **bands;
1983 enum ieee80211_band band;
1984 struct ieee80211_channel *channel;
1985 struct wmi_scan_chan_list_arg arg = {0};
1986 struct wmi_channel_arg *ch;
1987 bool passive;
1988 int len;
1989 int ret;
1990 int i;
1991
Michal Kazior548db542013-07-05 16:15:15 +03001992 lockdep_assert_held(&ar->conf_mutex);
1993
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 bands = hw->wiphy->bands;
1995 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1996 if (!bands[band])
1997 continue;
1998
1999 for (i = 0; i < bands[band]->n_channels; i++) {
2000 if (bands[band]->channels[i].flags &
2001 IEEE80211_CHAN_DISABLED)
2002 continue;
2003
2004 arg.n_channels++;
2005 }
2006 }
2007
2008 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2009 arg.channels = kzalloc(len, GFP_KERNEL);
2010 if (!arg.channels)
2011 return -ENOMEM;
2012
2013 ch = arg.channels;
2014 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2015 if (!bands[band])
2016 continue;
2017
2018 for (i = 0; i < bands[band]->n_channels; i++) {
2019 channel = &bands[band]->channels[i];
2020
2021 if (channel->flags & IEEE80211_CHAN_DISABLED)
2022 continue;
2023
2024 ch->allow_ht = true;
2025
2026 /* FIXME: when should we really allow VHT? */
2027 ch->allow_vht = true;
2028
2029 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002030 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002031
2032 ch->ht40plus =
2033 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2034
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002035 ch->chan_radar =
2036 !!(channel->flags & IEEE80211_CHAN_RADAR);
2037
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002038 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 ch->passive = passive;
2040
2041 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002042 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002043 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002044 ch->max_power = channel->max_power * 2;
2045 ch->max_reg_power = channel->max_reg_power * 2;
2046 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047 ch->reg_class_id = 0; /* FIXME */
2048
2049 /* FIXME: why use only legacy modes, why not any
2050 * HT/VHT modes? Would that even make any
2051 * difference? */
2052 if (channel->band == IEEE80211_BAND_2GHZ)
2053 ch->mode = MODE_11G;
2054 else
2055 ch->mode = MODE_11A;
2056
2057 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2058 continue;
2059
Michal Kazior7aa7a722014-08-25 12:09:38 +02002060 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002061 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2062 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002063 ch->freq, ch->max_power, ch->max_reg_power,
2064 ch->max_antenna_gain, ch->mode);
2065
2066 ch++;
2067 }
2068 }
2069
2070 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2071 kfree(arg.channels);
2072
2073 return ret;
2074}
2075
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002076static enum wmi_dfs_region
2077ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2078{
2079 switch (dfs_region) {
2080 case NL80211_DFS_UNSET:
2081 return WMI_UNINIT_DFS_DOMAIN;
2082 case NL80211_DFS_FCC:
2083 return WMI_FCC_DFS_DOMAIN;
2084 case NL80211_DFS_ETSI:
2085 return WMI_ETSI_DFS_DOMAIN;
2086 case NL80211_DFS_JP:
2087 return WMI_MKK4_DFS_DOMAIN;
2088 }
2089 return WMI_UNINIT_DFS_DOMAIN;
2090}
2091
Michal Kaziorf7843d72013-07-16 09:38:52 +02002092static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002096 enum wmi_dfs_region wmi_dfs_reg;
2097 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002098
Michal Kaziorf7843d72013-07-16 09:38:52 +02002099 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002100
2101 ret = ath10k_update_channel_list(ar);
2102 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002103 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104
2105 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002106
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002107 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2108 nl_dfs_reg = ar->dfs_detector->region;
2109 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2110 } else {
2111 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2112 }
2113
Kalle Valo5e3dd152013-06-12 20:52:10 +03002114 /* Target allows setting up per-band regdomain but ath_common provides
2115 * a combined one only */
2116 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002117 regpair->reg_domain,
2118 regpair->reg_domain, /* 2ghz */
2119 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002120 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002121 regpair->reg_5ghz_ctl,
2122 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002124 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002125}
Michal Kazior548db542013-07-05 16:15:15 +03002126
Michal Kaziorf7843d72013-07-16 09:38:52 +02002127static void ath10k_reg_notifier(struct wiphy *wiphy,
2128 struct regulatory_request *request)
2129{
2130 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2131 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002132 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002133
2134 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2135
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002136 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002137 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002138 request->dfs_region);
2139 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2140 request->dfs_region);
2141 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002142 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002143 request->dfs_region);
2144 }
2145
Michal Kaziorf7843d72013-07-16 09:38:52 +02002146 mutex_lock(&ar->conf_mutex);
2147 if (ar->state == ATH10K_STATE_ON)
2148 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002149 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150}
2151
2152/***************/
2153/* TX handlers */
2154/***************/
2155
Michal Kazior42c3aa62013-10-02 11:03:38 +02002156static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2157{
2158 if (ieee80211_is_mgmt(hdr->frame_control))
2159 return HTT_DATA_TX_EXT_TID_MGMT;
2160
2161 if (!ieee80211_is_data_qos(hdr->frame_control))
2162 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2163
2164 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2165 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2166
2167 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2168}
2169
Michal Kazior2b37c292014-09-02 11:00:22 +03002170static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002171{
Michal Kazior2b37c292014-09-02 11:00:22 +03002172 if (vif)
2173 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002174
Michal Kazior1bbc0972014-04-08 09:45:47 +03002175 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002176 return ar->monitor_vdev_id;
2177
Michal Kazior7aa7a722014-08-25 12:09:38 +02002178 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002179 return 0;
2180}
2181
Michal Kazior4b604552014-07-21 21:03:09 +03002182/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2183 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184 */
Michal Kazior4b604552014-07-21 21:03:09 +03002185static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186{
2187 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002188 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189 u8 *qos_ctl;
2190
2191 if (!ieee80211_is_data_qos(hdr->frame_control))
2192 return;
2193
2194 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002195 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2196 skb->data, (void *)qos_ctl - (void *)skb->data);
2197 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002198
2199 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2200 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2201 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2202 * it is safe to downgrade to NullFunc.
2203 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002204 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002205 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2206 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2207 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2208 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209}
2210
Michal Kazior4b604552014-07-21 21:03:09 +03002211static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2212 struct ieee80211_vif *vif,
2213 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214{
2215 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2217
2218 /* This is case only for P2P_GO */
2219 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2220 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2221 return;
2222
2223 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2224 spin_lock_bh(&ar->data_lock);
2225 if (arvif->u.ap.noa_data)
2226 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2227 GFP_ATOMIC))
2228 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2229 arvif->u.ap.noa_data,
2230 arvif->u.ap.noa_len);
2231 spin_unlock_bh(&ar->data_lock);
2232 }
2233}
2234
Michal Kazior8d6d3622014-11-24 14:58:31 +01002235static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2236{
2237 /* FIXME: Not really sure since when the behaviour changed. At some
2238 * point new firmware stopped requiring creation of peer entries for
2239 * offchannel tx (and actually creating them causes issues with wmi-htc
2240 * tx credit replenishment and reliability). Assuming it's at least 3.4
2241 * because that's when the `freq` was introduced to TX_FRM HTT command.
2242 */
2243 return !(ar->htt.target_version_major >= 3 &&
2244 ar->htt.target_version_minor >= 4);
2245}
2246
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2248{
2249 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002250 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002251
Michal Kazior961d4c32013-08-09 10:13:34 +02002252 if (ar->htt.target_version_major >= 3) {
2253 /* Since HTT 3.0 there is no separate mgmt tx command */
2254 ret = ath10k_htt_tx(&ar->htt, skb);
2255 goto exit;
2256 }
2257
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002258 if (ieee80211_is_mgmt(hdr->frame_control)) {
2259 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2260 ar->fw_features)) {
2261 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2262 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002263 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002264 ret = -EBUSY;
2265 goto exit;
2266 }
2267
2268 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2269 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2270 } else {
2271 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2272 }
2273 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2274 ar->fw_features) &&
2275 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 /* FW does not report tx status properly for NullFunc frames
2277 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002278 * those frames when it detects link/beacon loss and depends
2279 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002280 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002281 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002282 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284
Michal Kazior961d4c32013-08-09 10:13:34 +02002285exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002287 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2288 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289 ieee80211_free_txskb(ar->hw, skb);
2290 }
2291}
2292
2293void ath10k_offchan_tx_purge(struct ath10k *ar)
2294{
2295 struct sk_buff *skb;
2296
2297 for (;;) {
2298 skb = skb_dequeue(&ar->offchan_tx_queue);
2299 if (!skb)
2300 break;
2301
2302 ieee80211_free_txskb(ar->hw, skb);
2303 }
2304}
2305
2306void ath10k_offchan_tx_work(struct work_struct *work)
2307{
2308 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2309 struct ath10k_peer *peer;
2310 struct ieee80211_hdr *hdr;
2311 struct sk_buff *skb;
2312 const u8 *peer_addr;
2313 int vdev_id;
2314 int ret;
2315
2316 /* FW requirement: We must create a peer before FW will send out
2317 * an offchannel frame. Otherwise the frame will be stuck and
2318 * never transmitted. We delete the peer upon tx completion.
2319 * It is unlikely that a peer for offchannel tx will already be
2320 * present. However it may be in some rare cases so account for that.
2321 * Otherwise we might remove a legitimate peer and break stuff. */
2322
2323 for (;;) {
2324 skb = skb_dequeue(&ar->offchan_tx_queue);
2325 if (!skb)
2326 break;
2327
2328 mutex_lock(&ar->conf_mutex);
2329
Michal Kazior7aa7a722014-08-25 12:09:38 +02002330 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 skb);
2332
2333 hdr = (struct ieee80211_hdr *)skb->data;
2334 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002335 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336
2337 spin_lock_bh(&ar->data_lock);
2338 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2339 spin_unlock_bh(&ar->data_lock);
2340
2341 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002342 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002343 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344 peer_addr, vdev_id);
2345
2346 if (!peer) {
2347 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2348 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002349 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350 peer_addr, vdev_id, ret);
2351 }
2352
2353 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002354 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355 ar->offchan_tx_skb = skb;
2356 spin_unlock_bh(&ar->data_lock);
2357
2358 ath10k_tx_htt(ar, skb);
2359
2360 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2361 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002362 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002363 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002364 skb);
2365
2366 if (!peer) {
2367 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2368 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002369 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 peer_addr, vdev_id, ret);
2371 }
2372
2373 mutex_unlock(&ar->conf_mutex);
2374 }
2375}
2376
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002377void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2378{
2379 struct sk_buff *skb;
2380
2381 for (;;) {
2382 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2383 if (!skb)
2384 break;
2385
2386 ieee80211_free_txskb(ar->hw, skb);
2387 }
2388}
2389
2390void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2391{
2392 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2393 struct sk_buff *skb;
2394 int ret;
2395
2396 for (;;) {
2397 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2398 if (!skb)
2399 break;
2400
2401 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002402 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002403 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002404 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002405 ieee80211_free_txskb(ar->hw, skb);
2406 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002407 }
2408}
2409
Kalle Valo5e3dd152013-06-12 20:52:10 +03002410/************/
2411/* Scanning */
2412/************/
2413
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002414void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002415{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002416 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002417
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002418 switch (ar->scan.state) {
2419 case ATH10K_SCAN_IDLE:
2420 break;
2421 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002422 if (ar->scan.is_roc)
2423 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002424 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002425 case ATH10K_SCAN_ABORTING:
2426 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002427 ieee80211_scan_completed(ar->hw,
2428 (ar->scan.state ==
2429 ATH10K_SCAN_ABORTING));
2430 /* fall through */
2431 case ATH10K_SCAN_STARTING:
2432 ar->scan.state = ATH10K_SCAN_IDLE;
2433 ar->scan_channel = NULL;
2434 ath10k_offchan_tx_purge(ar);
2435 cancel_delayed_work(&ar->scan.timeout);
2436 complete_all(&ar->scan.completed);
2437 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002438 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002439}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002440
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002441void ath10k_scan_finish(struct ath10k *ar)
2442{
2443 spin_lock_bh(&ar->data_lock);
2444 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445 spin_unlock_bh(&ar->data_lock);
2446}
2447
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002448static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002449{
2450 struct wmi_stop_scan_arg arg = {
2451 .req_id = 1, /* FIXME */
2452 .req_type = WMI_SCAN_STOP_ONE,
2453 .u.scan_id = ATH10K_SCAN_ID,
2454 };
2455 int ret;
2456
2457 lockdep_assert_held(&ar->conf_mutex);
2458
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 ret = ath10k_wmi_stop_scan(ar, &arg);
2460 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002461 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002462 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002463 }
2464
Kalle Valo5e3dd152013-06-12 20:52:10 +03002465 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002466 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002467 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002469 } else if (ret > 0) {
2470 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002471 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002472
2473out:
2474 /* Scan state should be updated upon scan completion but in case
2475 * firmware fails to deliver the event (for whatever reason) it is
2476 * desired to clean up scan state anyway. Firmware may have just
2477 * dropped the scan completion event delivery due to transport pipe
2478 * being overflown with data and/or it can recover on its own before
2479 * next scan request is submitted.
2480 */
2481 spin_lock_bh(&ar->data_lock);
2482 if (ar->scan.state != ATH10K_SCAN_IDLE)
2483 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 spin_unlock_bh(&ar->data_lock);
2485
2486 return ret;
2487}
2488
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002489static void ath10k_scan_abort(struct ath10k *ar)
2490{
2491 int ret;
2492
2493 lockdep_assert_held(&ar->conf_mutex);
2494
2495 spin_lock_bh(&ar->data_lock);
2496
2497 switch (ar->scan.state) {
2498 case ATH10K_SCAN_IDLE:
2499 /* This can happen if timeout worker kicked in and called
2500 * abortion while scan completion was being processed.
2501 */
2502 break;
2503 case ATH10K_SCAN_STARTING:
2504 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002505 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002506 ath10k_scan_state_str(ar->scan.state),
2507 ar->scan.state);
2508 break;
2509 case ATH10K_SCAN_RUNNING:
2510 ar->scan.state = ATH10K_SCAN_ABORTING;
2511 spin_unlock_bh(&ar->data_lock);
2512
2513 ret = ath10k_scan_stop(ar);
2514 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002515 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002516
2517 spin_lock_bh(&ar->data_lock);
2518 break;
2519 }
2520
2521 spin_unlock_bh(&ar->data_lock);
2522}
2523
2524void ath10k_scan_timeout_work(struct work_struct *work)
2525{
2526 struct ath10k *ar = container_of(work, struct ath10k,
2527 scan.timeout.work);
2528
2529 mutex_lock(&ar->conf_mutex);
2530 ath10k_scan_abort(ar);
2531 mutex_unlock(&ar->conf_mutex);
2532}
2533
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534static int ath10k_start_scan(struct ath10k *ar,
2535 const struct wmi_start_scan_arg *arg)
2536{
2537 int ret;
2538
2539 lockdep_assert_held(&ar->conf_mutex);
2540
2541 ret = ath10k_wmi_start_scan(ar, arg);
2542 if (ret)
2543 return ret;
2544
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2546 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002547 ret = ath10k_scan_stop(ar);
2548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002549 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002550
2551 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 }
2553
Ben Greear2f9eec02015-02-15 16:50:38 +02002554 /* If we failed to start the scan, return error code at
2555 * this point. This is probably due to some issue in the
2556 * firmware, but no need to wedge the driver due to that...
2557 */
2558 spin_lock_bh(&ar->data_lock);
2559 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2560 spin_unlock_bh(&ar->data_lock);
2561 return -EINVAL;
2562 }
2563 spin_unlock_bh(&ar->data_lock);
2564
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002565 /* Add a 200ms margin to account for event/command processing */
2566 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2567 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 return 0;
2569}
2570
2571/**********************/
2572/* mac80211 callbacks */
2573/**********************/
2574
2575static void ath10k_tx(struct ieee80211_hw *hw,
2576 struct ieee80211_tx_control *control,
2577 struct sk_buff *skb)
2578{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002579 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002580 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2581 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002582 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583
2584 /* We should disable CCK RATE due to P2P */
2585 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002586 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587
Michal Kazior4b604552014-07-21 21:03:09 +03002588 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2589 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002590 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002591
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002592 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002593 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2594 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002595 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2596 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002597 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002598
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2600 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002601 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002602 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002603 spin_unlock_bh(&ar->data_lock);
2604
Michal Kazior8d6d3622014-11-24 14:58:31 +01002605 if (ath10k_mac_need_offchan_tx_work(ar)) {
2606 ATH10K_SKB_CB(skb)->htt.freq = 0;
2607 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002608
Michal Kazior8d6d3622014-11-24 14:58:31 +01002609 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2610 skb);
2611
2612 skb_queue_tail(&ar->offchan_tx_queue, skb);
2613 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2614 return;
2615 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002616 }
2617
2618 ath10k_tx_htt(ar, skb);
2619}
2620
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002621/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002622void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002623{
2624 /* make sure rcu-protected mac80211 tx path itself is drained */
2625 synchronize_net();
2626
2627 ath10k_offchan_tx_purge(ar);
2628 ath10k_mgmt_over_wmi_tx_purge(ar);
2629
2630 cancel_work_sync(&ar->offchan_tx_work);
2631 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2632}
2633
Michal Kazioraffd3212013-07-16 09:54:35 +02002634void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002635{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002636 struct ath10k_vif *arvif;
2637
Michal Kazior818bdd12013-07-16 09:38:57 +02002638 lockdep_assert_held(&ar->conf_mutex);
2639
Michal Kazior19337472014-08-28 12:58:16 +02002640 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2641 ar->filter_flags = 0;
2642 ar->monitor = false;
2643
2644 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002645 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002646
2647 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002648
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002649 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002650 ath10k_peer_cleanup_all(ar);
2651 ath10k_core_stop(ar);
2652 ath10k_hif_power_down(ar);
2653
2654 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002655 list_for_each_entry(arvif, &ar->arvifs, list)
2656 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002657 spin_unlock_bh(&ar->data_lock);
2658}
2659
Ben Greear46acf7b2014-05-16 17:15:38 +03002660static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2661{
2662 struct ath10k *ar = hw->priv;
2663
2664 mutex_lock(&ar->conf_mutex);
2665
2666 if (ar->cfg_tx_chainmask) {
2667 *tx_ant = ar->cfg_tx_chainmask;
2668 *rx_ant = ar->cfg_rx_chainmask;
2669 } else {
2670 *tx_ant = ar->supp_tx_chainmask;
2671 *rx_ant = ar->supp_rx_chainmask;
2672 }
2673
2674 mutex_unlock(&ar->conf_mutex);
2675
2676 return 0;
2677}
2678
Ben Greear5572a952014-11-24 16:22:10 +02002679static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2680{
2681 /* It is not clear that allowing gaps in chainmask
2682 * is helpful. Probably it will not do what user
2683 * is hoping for, so warn in that case.
2684 */
2685 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2686 return;
2687
2688 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2689 dbg, cm);
2690}
2691
Ben Greear46acf7b2014-05-16 17:15:38 +03002692static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2693{
2694 int ret;
2695
2696 lockdep_assert_held(&ar->conf_mutex);
2697
Ben Greear5572a952014-11-24 16:22:10 +02002698 ath10k_check_chain_mask(ar, tx_ant, "tx");
2699 ath10k_check_chain_mask(ar, rx_ant, "rx");
2700
Ben Greear46acf7b2014-05-16 17:15:38 +03002701 ar->cfg_tx_chainmask = tx_ant;
2702 ar->cfg_rx_chainmask = rx_ant;
2703
2704 if ((ar->state != ATH10K_STATE_ON) &&
2705 (ar->state != ATH10K_STATE_RESTARTED))
2706 return 0;
2707
2708 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2709 tx_ant);
2710 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002711 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002712 ret, tx_ant);
2713 return ret;
2714 }
2715
2716 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2717 rx_ant);
2718 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002719 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002720 ret, rx_ant);
2721 return ret;
2722 }
2723
2724 return 0;
2725}
2726
2727static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2728{
2729 struct ath10k *ar = hw->priv;
2730 int ret;
2731
2732 mutex_lock(&ar->conf_mutex);
2733 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2734 mutex_unlock(&ar->conf_mutex);
2735 return ret;
2736}
2737
Kalle Valo5e3dd152013-06-12 20:52:10 +03002738static int ath10k_start(struct ieee80211_hw *hw)
2739{
2740 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002741 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002742
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002743 /*
2744 * This makes sense only when restarting hw. It is harmless to call
2745 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2746 * commands will be submitted while restarting.
2747 */
2748 ath10k_drain_tx(ar);
2749
Michal Kazior548db542013-07-05 16:15:15 +03002750 mutex_lock(&ar->conf_mutex);
2751
Michal Kaziorc5058f52014-05-26 12:46:03 +03002752 switch (ar->state) {
2753 case ATH10K_STATE_OFF:
2754 ar->state = ATH10K_STATE_ON;
2755 break;
2756 case ATH10K_STATE_RESTARTING:
2757 ath10k_halt(ar);
2758 ar->state = ATH10K_STATE_RESTARTED;
2759 break;
2760 case ATH10K_STATE_ON:
2761 case ATH10K_STATE_RESTARTED:
2762 case ATH10K_STATE_WEDGED:
2763 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002764 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002765 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002766 case ATH10K_STATE_UTF:
2767 ret = -EBUSY;
2768 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002769 }
2770
2771 ret = ath10k_hif_power_up(ar);
2772 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002773 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002774 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002775 }
2776
Kalle Valo43d2a302014-09-10 18:23:30 +03002777 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002778 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002779 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002780 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002781 }
2782
Bartosz Markowski226a3392013-09-26 17:47:16 +02002783 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002784 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002785 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002786 goto err_core_stop;
2787 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002788
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002789 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002790 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002791 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002792 goto err_core_stop;
2793 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794
Ben Greear46acf7b2014-05-16 17:15:38 +03002795 if (ar->cfg_tx_chainmask)
2796 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2797 ar->cfg_rx_chainmask);
2798
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002799 /*
2800 * By default FW set ARP frames ac to voice (6). In that case ARP
2801 * exchange is not working properly for UAPSD enabled AP. ARP requests
2802 * which arrives with access category 0 are processed by network stack
2803 * and send back with access category 0, but FW changes access category
2804 * to 6. Set ARP frames access category to best effort (0) solves
2805 * this problem.
2806 */
2807
2808 ret = ath10k_wmi_pdev_set_param(ar,
2809 ar->wmi.pdev_param->arp_ac_override, 0);
2810 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002811 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002812 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002813 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002814 }
2815
Michal Kaziord6500972014-04-08 09:56:09 +03002816 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002817 ath10k_regd_update(ar);
2818
Simon Wunderlich855aed12014-08-02 09:12:54 +03002819 ath10k_spectral_start(ar);
2820
Michal Kaziorae254432014-05-26 12:46:02 +03002821 mutex_unlock(&ar->conf_mutex);
2822 return 0;
2823
2824err_core_stop:
2825 ath10k_core_stop(ar);
2826
2827err_power_down:
2828 ath10k_hif_power_down(ar);
2829
2830err_off:
2831 ar->state = ATH10K_STATE_OFF;
2832
2833err:
Michal Kazior548db542013-07-05 16:15:15 +03002834 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002835 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002836}
2837
2838static void ath10k_stop(struct ieee80211_hw *hw)
2839{
2840 struct ath10k *ar = hw->priv;
2841
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002842 ath10k_drain_tx(ar);
2843
Michal Kazior548db542013-07-05 16:15:15 +03002844 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002845 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002846 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002847 ar->state = ATH10K_STATE_OFF;
2848 }
Michal Kazior548db542013-07-05 16:15:15 +03002849 mutex_unlock(&ar->conf_mutex);
2850
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002851 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002852 cancel_work_sync(&ar->restart_work);
2853}
2854
Michal Kaziorad088bf2013-10-16 15:44:46 +03002855static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002856{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002857 struct ath10k_vif *arvif;
2858 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002859
2860 lockdep_assert_held(&ar->conf_mutex);
2861
Michal Kaziorad088bf2013-10-16 15:44:46 +03002862 list_for_each_entry(arvif, &ar->arvifs, list) {
2863 ret = ath10k_mac_vif_setup_ps(arvif);
2864 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002865 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002866 break;
2867 }
2868 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002869
Michal Kaziorad088bf2013-10-16 15:44:46 +03002870 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002871}
2872
Michal Kaziorc930f742014-01-23 11:38:25 +01002873static const char *chandef_get_width(enum nl80211_chan_width width)
2874{
2875 switch (width) {
2876 case NL80211_CHAN_WIDTH_20_NOHT:
2877 return "20 (noht)";
2878 case NL80211_CHAN_WIDTH_20:
2879 return "20";
2880 case NL80211_CHAN_WIDTH_40:
2881 return "40";
2882 case NL80211_CHAN_WIDTH_80:
2883 return "80";
2884 case NL80211_CHAN_WIDTH_80P80:
2885 return "80+80";
2886 case NL80211_CHAN_WIDTH_160:
2887 return "160";
2888 case NL80211_CHAN_WIDTH_5:
2889 return "5";
2890 case NL80211_CHAN_WIDTH_10:
2891 return "10";
2892 }
2893 return "?";
2894}
2895
2896static void ath10k_config_chan(struct ath10k *ar)
2897{
2898 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002899 int ret;
2900
2901 lockdep_assert_held(&ar->conf_mutex);
2902
Michal Kazior7aa7a722014-08-25 12:09:38 +02002903 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002904 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2905 ar->chandef.chan->center_freq,
2906 ar->chandef.center_freq1,
2907 ar->chandef.center_freq2,
2908 chandef_get_width(ar->chandef.width));
2909
2910 /* First stop monitor interface. Some FW versions crash if there's a
2911 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002912 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002913 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002914
2915 list_for_each_entry(arvif, &ar->arvifs, list) {
2916 if (!arvif->is_started)
2917 continue;
2918
Michal Kaziordc55e302014-07-29 12:53:36 +03002919 if (!arvif->is_up)
2920 continue;
2921
Michal Kaziorc930f742014-01-23 11:38:25 +01002922 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2923 continue;
2924
Michal Kaziordc55e302014-07-29 12:53:36 +03002925 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002926 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002927 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002928 arvif->vdev_id, ret);
2929 continue;
2930 }
2931 }
2932
Michal Kaziordc55e302014-07-29 12:53:36 +03002933 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002934
2935 list_for_each_entry(arvif, &ar->arvifs, list) {
2936 if (!arvif->is_started)
2937 continue;
2938
2939 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2940 continue;
2941
Michal Kaziordc55e302014-07-29 12:53:36 +03002942 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002943 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002945 arvif->vdev_id, ret);
2946 continue;
2947 }
2948
2949 if (!arvif->is_up)
2950 continue;
2951
2952 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2953 arvif->bssid);
2954 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002955 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002956 arvif->vdev_id, ret);
2957 continue;
2958 }
2959 }
2960
Michal Kazior19337472014-08-28 12:58:16 +02002961 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002962}
2963
Michal Kazior7d9d5582014-10-21 10:40:15 +03002964static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2965{
2966 int ret;
2967 u32 param;
2968
2969 lockdep_assert_held(&ar->conf_mutex);
2970
2971 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2972
2973 param = ar->wmi.pdev_param->txpower_limit2g;
2974 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2975 if (ret) {
2976 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2977 txpower, ret);
2978 return ret;
2979 }
2980
2981 param = ar->wmi.pdev_param->txpower_limit5g;
2982 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2983 if (ret) {
2984 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2985 txpower, ret);
2986 return ret;
2987 }
2988
2989 return 0;
2990}
2991
2992static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2993{
2994 struct ath10k_vif *arvif;
2995 int ret, txpower = -1;
2996
2997 lockdep_assert_held(&ar->conf_mutex);
2998
2999 list_for_each_entry(arvif, &ar->arvifs, list) {
3000 WARN_ON(arvif->txpower < 0);
3001
3002 if (txpower == -1)
3003 txpower = arvif->txpower;
3004 else
3005 txpower = min(txpower, arvif->txpower);
3006 }
3007
3008 if (WARN_ON(txpower == -1))
3009 return -EINVAL;
3010
3011 ret = ath10k_mac_txpower_setup(ar, txpower);
3012 if (ret) {
3013 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3014 txpower, ret);
3015 return ret;
3016 }
3017
3018 return 0;
3019}
3020
Kalle Valo5e3dd152013-06-12 20:52:10 +03003021static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3022{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003023 struct ath10k *ar = hw->priv;
3024 struct ieee80211_conf *conf = &hw->conf;
3025 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003026
3027 mutex_lock(&ar->conf_mutex);
3028
3029 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003030 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003031 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003032 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003033 conf->chandef.chan->flags,
3034 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003035
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036 spin_lock_bh(&ar->data_lock);
3037 ar->rx_channel = conf->chandef.chan;
3038 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003039
Michal Kaziord6500972014-04-08 09:56:09 +03003040 ar->radar_enabled = conf->radar_enabled;
3041 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003042
3043 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3044 ar->chandef = conf->chandef;
3045 ath10k_config_chan(ar);
3046 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047 }
3048
Michal Kazioraffd3212013-07-16 09:54:35 +02003049 if (changed & IEEE80211_CONF_CHANGE_PS)
3050 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003051
3052 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003053 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3054 ret = ath10k_monitor_recalc(ar);
3055 if (ret)
3056 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003057 }
3058
3059 mutex_unlock(&ar->conf_mutex);
3060 return ret;
3061}
3062
Ben Greear5572a952014-11-24 16:22:10 +02003063static u32 get_nss_from_chainmask(u16 chain_mask)
3064{
3065 if ((chain_mask & 0x15) == 0x15)
3066 return 4;
3067 else if ((chain_mask & 0x7) == 0x7)
3068 return 3;
3069 else if ((chain_mask & 0x3) == 0x3)
3070 return 2;
3071 return 1;
3072}
3073
Kalle Valo5e3dd152013-06-12 20:52:10 +03003074/*
3075 * TODO:
3076 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3077 * because we will send mgmt frames without CCK. This requirement
3078 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3079 * in the TX packet.
3080 */
3081static int ath10k_add_interface(struct ieee80211_hw *hw,
3082 struct ieee80211_vif *vif)
3083{
3084 struct ath10k *ar = hw->priv;
3085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3086 enum wmi_sta_powersave_param param;
3087 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003088 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003090 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003091
Johannes Berg848955c2014-11-11 12:48:42 +01003092 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3093
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094 mutex_lock(&ar->conf_mutex);
3095
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003096 memset(arvif, 0, sizeof(*arvif));
3097
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098 arvif->ar = ar;
3099 arvif->vif = vif;
3100
Ben Greeare63b33f2013-10-22 14:54:14 -07003101 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003102
Ben Greeara9aefb32014-08-12 11:02:19 +03003103 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003104 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003105 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003106 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003107 }
Ben Greear16c11172014-09-23 14:17:16 -07003108 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003109
Ben Greear16c11172014-09-23 14:17:16 -07003110 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3111 bit, ar->free_vdev_map);
3112
3113 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003114 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003117 case NL80211_IFTYPE_P2P_DEVICE:
3118 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3119 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3120 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003121 case NL80211_IFTYPE_UNSPECIFIED:
3122 case NL80211_IFTYPE_STATION:
3123 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3124 if (vif->p2p)
3125 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3126 break;
3127 case NL80211_IFTYPE_ADHOC:
3128 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3129 break;
3130 case NL80211_IFTYPE_AP:
3131 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3132
3133 if (vif->p2p)
3134 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3135 break;
3136 case NL80211_IFTYPE_MONITOR:
3137 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3138 break;
3139 default:
3140 WARN_ON(1);
3141 break;
3142 }
3143
Michal Kazior64badcb2014-09-18 11:18:02 +03003144 /* Some firmware revisions don't wait for beacon tx completion before
3145 * sending another SWBA event. This could lead to hardware using old
3146 * (freed) beacon data in some cases, e.g. tx credit starvation
3147 * combined with missed TBTT. This is very very rare.
3148 *
3149 * On non-IOMMU-enabled hosts this could be a possible security issue
3150 * because hw could beacon some random data on the air. On
3151 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3152 * device would crash.
3153 *
3154 * Since there are no beacon tx completions (implicit nor explicit)
3155 * propagated to host the only workaround for this is to allocate a
3156 * DMA-coherent buffer for a lifetime of a vif and use it for all
3157 * beacon tx commands. Worst case for this approach is some beacons may
3158 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3159 */
3160 if (vif->type == NL80211_IFTYPE_ADHOC ||
3161 vif->type == NL80211_IFTYPE_AP) {
3162 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3163 IEEE80211_MAX_FRAME_LEN,
3164 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303165 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003166 if (!arvif->beacon_buf) {
3167 ret = -ENOMEM;
3168 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3169 ret);
3170 goto err;
3171 }
3172 }
3173
3174 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3175 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3176 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003177
3178 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3179 arvif->vdev_subtype, vif->addr);
3180 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003181 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003182 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003183 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184 }
3185
Ben Greear16c11172014-09-23 14:17:16 -07003186 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003187 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003188
Michal Kazior46725b152015-01-28 09:57:49 +02003189 /* It makes no sense to have firmware do keepalives. mac80211 already
3190 * takes care of this with idle connection polling.
3191 */
3192 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003193 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003194 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003195 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003196 goto err_vdev_delete;
3197 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003198
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003199 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003200
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003201 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3202 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003203 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003204 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003205 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003206 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003207 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003208 goto err_vdev_delete;
3209 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210
Ben Greear5572a952014-11-24 16:22:10 +02003211 if (ar->cfg_tx_chainmask) {
3212 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3213
3214 vdev_param = ar->wmi.vdev_param->nss;
3215 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3216 nss);
3217 if (ret) {
3218 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3219 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3220 ret);
3221 goto err_vdev_delete;
3222 }
3223 }
3224
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3226 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3227 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003228 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003229 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003230 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003231 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003232
Kalle Valo5a13e762014-01-20 11:01:46 +02003233 ret = ath10k_mac_set_kickout(arvif);
3234 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003235 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003236 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003237 goto err_peer_delete;
3238 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003239 }
3240
3241 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3242 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3243 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3244 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3245 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003246 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003247 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003248 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003249 goto err_peer_delete;
3250 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003251
Michal Kazior9f9b5742014-12-12 12:41:36 +01003252 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003253 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003254 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003255 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003256 goto err_peer_delete;
3257 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003258
Michal Kazior9f9b5742014-12-12 12:41:36 +01003259 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003260 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003261 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003262 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003263 goto err_peer_delete;
3264 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003265 }
3266
Michal Kazior424121c2013-07-22 14:13:31 +02003267 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003268 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003269 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003270 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003271 goto err_peer_delete;
3272 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003273
Michal Kazior424121c2013-07-22 14:13:31 +02003274 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003275 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003276 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003277 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003278 goto err_peer_delete;
3279 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003280
Michal Kazior7d9d5582014-10-21 10:40:15 +03003281 arvif->txpower = vif->bss_conf.txpower;
3282 ret = ath10k_mac_txpower_recalc(ar);
3283 if (ret) {
3284 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3285 goto err_peer_delete;
3286 }
3287
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003289 return 0;
3290
3291err_peer_delete:
3292 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3293 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3294
3295err_vdev_delete:
3296 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003297 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003298 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003299
3300err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003301 if (arvif->beacon_buf) {
3302 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3303 arvif->beacon_buf, arvif->beacon_paddr);
3304 arvif->beacon_buf = NULL;
3305 }
3306
Michal Kazior9dad14a2013-10-16 15:44:45 +03003307 mutex_unlock(&ar->conf_mutex);
3308
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309 return ret;
3310}
3311
3312static void ath10k_remove_interface(struct ieee80211_hw *hw,
3313 struct ieee80211_vif *vif)
3314{
3315 struct ath10k *ar = hw->priv;
3316 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3317 int ret;
3318
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303319 mutex_lock(&ar->conf_mutex);
3320
Michal Kaziored543882013-09-13 14:16:56 +02003321 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003322 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003323 spin_unlock_bh(&ar->data_lock);
3324
Simon Wunderlich855aed12014-08-02 09:12:54 +03003325 ret = ath10k_spectral_vif_stop(arvif);
3326 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003327 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003328 arvif->vdev_id, ret);
3329
Ben Greear16c11172014-09-23 14:17:16 -07003330 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003331 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003332
3333 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3334 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3335 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003336 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003337 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003338
3339 kfree(arvif->u.ap.noa_data);
3340 }
3341
Michal Kazior7aa7a722014-08-25 12:09:38 +02003342 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003343 arvif->vdev_id);
3344
Kalle Valo5e3dd152013-06-12 20:52:10 +03003345 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3346 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003347 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003348 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003349
Kalle Valo5e3dd152013-06-12 20:52:10 +03003350 ath10k_peer_cleanup(ar, arvif->vdev_id);
3351
3352 mutex_unlock(&ar->conf_mutex);
3353}
3354
3355/*
3356 * FIXME: Has to be verified.
3357 */
3358#define SUPPORTED_FILTERS \
3359 (FIF_PROMISC_IN_BSS | \
3360 FIF_ALLMULTI | \
3361 FIF_CONTROL | \
3362 FIF_PSPOLL | \
3363 FIF_OTHER_BSS | \
3364 FIF_BCN_PRBRESP_PROMISC | \
3365 FIF_PROBE_REQ | \
3366 FIF_FCSFAIL)
3367
3368static void ath10k_configure_filter(struct ieee80211_hw *hw,
3369 unsigned int changed_flags,
3370 unsigned int *total_flags,
3371 u64 multicast)
3372{
3373 struct ath10k *ar = hw->priv;
3374 int ret;
3375
3376 mutex_lock(&ar->conf_mutex);
3377
3378 changed_flags &= SUPPORTED_FILTERS;
3379 *total_flags &= SUPPORTED_FILTERS;
3380 ar->filter_flags = *total_flags;
3381
Michal Kazior19337472014-08-28 12:58:16 +02003382 ret = ath10k_monitor_recalc(ar);
3383 if (ret)
3384 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385
3386 mutex_unlock(&ar->conf_mutex);
3387}
3388
3389static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3390 struct ieee80211_vif *vif,
3391 struct ieee80211_bss_conf *info,
3392 u32 changed)
3393{
3394 struct ath10k *ar = hw->priv;
3395 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3396 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003397 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398
3399 mutex_lock(&ar->conf_mutex);
3400
3401 if (changed & BSS_CHANGED_IBSS)
3402 ath10k_control_ibss(arvif, info, vif->addr);
3403
3404 if (changed & BSS_CHANGED_BEACON_INT) {
3405 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003406 vdev_param = ar->wmi.vdev_param->beacon_interval;
3407 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003409 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003410 "mac vdev %d beacon_interval %d\n",
3411 arvif->vdev_id, arvif->beacon_interval);
3412
Kalle Valo5e3dd152013-06-12 20:52:10 +03003413 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003414 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003415 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003416 }
3417
3418 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003419 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003420 "vdev %d set beacon tx mode to staggered\n",
3421 arvif->vdev_id);
3422
Bartosz Markowski226a3392013-09-26 17:47:16 +02003423 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3424 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425 WMI_BEACON_STAGGERED_MODE);
3426 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003427 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003428 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003429
3430 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3431 if (ret)
3432 ath10k_warn(ar, "failed to update beacon template: %d\n",
3433 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003434 }
3435
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003436 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3437 ret = ath10k_mac_setup_prb_tmpl(arvif);
3438 if (ret)
3439 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3440 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003441 }
3442
Michal Kaziorba2479f2015-01-24 12:14:51 +02003443 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003444 arvif->dtim_period = info->dtim_period;
3445
Michal Kazior7aa7a722014-08-25 12:09:38 +02003446 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003447 "mac vdev %d dtim_period %d\n",
3448 arvif->vdev_id, arvif->dtim_period);
3449
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003450 vdev_param = ar->wmi.vdev_param->dtim_period;
3451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452 arvif->dtim_period);
3453 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003454 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003455 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456 }
3457
3458 if (changed & BSS_CHANGED_SSID &&
3459 vif->type == NL80211_IFTYPE_AP) {
3460 arvif->u.ap.ssid_len = info->ssid_len;
3461 if (info->ssid_len)
3462 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3463 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3464 }
3465
Michal Kazior077efc82014-10-21 10:10:29 +03003466 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3467 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003468
3469 if (changed & BSS_CHANGED_BEACON_ENABLED)
3470 ath10k_control_beaconing(arvif, info);
3471
3472 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003473 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003474 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003475 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003476
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003477 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003479 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003480 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481 }
3482
3483 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003484 if (info->use_short_slot)
3485 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3486
3487 else
3488 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3489
Michal Kazior7aa7a722014-08-25 12:09:38 +02003490 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003491 arvif->vdev_id, slottime);
3492
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003493 vdev_param = ar->wmi.vdev_param->slot_time;
3494 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003495 slottime);
3496 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003497 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003498 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499 }
3500
3501 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003502 if (info->use_short_preamble)
3503 preamble = WMI_VDEV_PREAMBLE_SHORT;
3504 else
3505 preamble = WMI_VDEV_PREAMBLE_LONG;
3506
Michal Kazior7aa7a722014-08-25 12:09:38 +02003507 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003508 "mac vdev %d preamble %dn",
3509 arvif->vdev_id, preamble);
3510
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003511 vdev_param = ar->wmi.vdev_param->preamble;
3512 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 preamble);
3514 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003515 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003516 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517 }
3518
3519 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003520 if (info->assoc) {
3521 /* Workaround: Make sure monitor vdev is not running
3522 * when associating to prevent some firmware revisions
3523 * (e.g. 10.1 and 10.2) from crashing.
3524 */
3525 if (ar->monitor_started)
3526 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003527 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003528 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003529 } else {
3530 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003531 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003532 }
3533
Michal Kazior7d9d5582014-10-21 10:40:15 +03003534 if (changed & BSS_CHANGED_TXPOWER) {
3535 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3536 arvif->vdev_id, info->txpower);
3537
3538 arvif->txpower = info->txpower;
3539 ret = ath10k_mac_txpower_recalc(ar);
3540 if (ret)
3541 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3542 }
3543
Michal Kaziorbf14e652014-12-12 12:41:38 +01003544 if (changed & BSS_CHANGED_PS) {
3545 ret = ath10k_mac_vif_setup_ps(arvif);
3546 if (ret)
3547 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3548 arvif->vdev_id, ret);
3549 }
3550
Kalle Valo5e3dd152013-06-12 20:52:10 +03003551 mutex_unlock(&ar->conf_mutex);
3552}
3553
3554static int ath10k_hw_scan(struct ieee80211_hw *hw,
3555 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003556 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557{
3558 struct ath10k *ar = hw->priv;
3559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003560 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561 struct wmi_start_scan_arg arg;
3562 int ret = 0;
3563 int i;
3564
3565 mutex_lock(&ar->conf_mutex);
3566
3567 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003568 switch (ar->scan.state) {
3569 case ATH10K_SCAN_IDLE:
3570 reinit_completion(&ar->scan.started);
3571 reinit_completion(&ar->scan.completed);
3572 ar->scan.state = ATH10K_SCAN_STARTING;
3573 ar->scan.is_roc = false;
3574 ar->scan.vdev_id = arvif->vdev_id;
3575 ret = 0;
3576 break;
3577 case ATH10K_SCAN_STARTING:
3578 case ATH10K_SCAN_RUNNING:
3579 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003580 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003581 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003582 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003583 spin_unlock_bh(&ar->data_lock);
3584
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003585 if (ret)
3586 goto exit;
3587
Kalle Valo5e3dd152013-06-12 20:52:10 +03003588 memset(&arg, 0, sizeof(arg));
3589 ath10k_wmi_start_scan_init(ar, &arg);
3590 arg.vdev_id = arvif->vdev_id;
3591 arg.scan_id = ATH10K_SCAN_ID;
3592
3593 if (!req->no_cck)
3594 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3595
3596 if (req->ie_len) {
3597 arg.ie_len = req->ie_len;
3598 memcpy(arg.ie, req->ie, arg.ie_len);
3599 }
3600
3601 if (req->n_ssids) {
3602 arg.n_ssids = req->n_ssids;
3603 for (i = 0; i < arg.n_ssids; i++) {
3604 arg.ssids[i].len = req->ssids[i].ssid_len;
3605 arg.ssids[i].ssid = req->ssids[i].ssid;
3606 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003607 } else {
3608 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003609 }
3610
3611 if (req->n_channels) {
3612 arg.n_channels = req->n_channels;
3613 for (i = 0; i < arg.n_channels; i++)
3614 arg.channels[i] = req->channels[i]->center_freq;
3615 }
3616
3617 ret = ath10k_start_scan(ar, &arg);
3618 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003619 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003621 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003622 spin_unlock_bh(&ar->data_lock);
3623 }
3624
3625exit:
3626 mutex_unlock(&ar->conf_mutex);
3627 return ret;
3628}
3629
3630static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3631 struct ieee80211_vif *vif)
3632{
3633 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003634
3635 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003636 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003637 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003638
3639 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003640}
3641
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003642static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3643 struct ath10k_vif *arvif,
3644 enum set_key_cmd cmd,
3645 struct ieee80211_key_conf *key)
3646{
3647 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3648 int ret;
3649
3650 /* 10.1 firmware branch requires default key index to be set to group
3651 * key index after installing it. Otherwise FW/HW Txes corrupted
3652 * frames with multi-vif APs. This is not required for main firmware
3653 * branch (e.g. 636).
3654 *
3655 * FIXME: This has been tested only in AP. It remains unknown if this
3656 * is required for multi-vif STA interfaces on 10.1 */
3657
3658 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3659 return;
3660
3661 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3662 return;
3663
3664 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3665 return;
3666
3667 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3668 return;
3669
3670 if (cmd != SET_KEY)
3671 return;
3672
3673 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3674 key->keyidx);
3675 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003676 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003677 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003678}
3679
Kalle Valo5e3dd152013-06-12 20:52:10 +03003680static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3681 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3682 struct ieee80211_key_conf *key)
3683{
3684 struct ath10k *ar = hw->priv;
3685 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3686 struct ath10k_peer *peer;
3687 const u8 *peer_addr;
3688 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3689 key->cipher == WLAN_CIPHER_SUITE_WEP104;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003690 bool def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003691 int ret = 0;
3692
3693 if (key->keyidx > WMI_MAX_KEY_INDEX)
3694 return -ENOSPC;
3695
3696 mutex_lock(&ar->conf_mutex);
3697
3698 if (sta)
3699 peer_addr = sta->addr;
3700 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3701 peer_addr = vif->bss_conf.bssid;
3702 else
3703 peer_addr = vif->addr;
3704
3705 key->hw_key_idx = key->keyidx;
3706
3707 /* the peer should not disappear in mid-way (unless FW goes awry) since
3708 * we already hold conf_mutex. we just make sure its there now. */
3709 spin_lock_bh(&ar->data_lock);
3710 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3711 spin_unlock_bh(&ar->data_lock);
3712
3713 if (!peer) {
3714 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003715 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003716 peer_addr);
3717 ret = -EOPNOTSUPP;
3718 goto exit;
3719 } else {
3720 /* if the peer doesn't exist there is no key to disable
3721 * anymore */
3722 goto exit;
3723 }
3724 }
3725
3726 if (is_wep) {
3727 if (cmd == SET_KEY)
3728 arvif->wep_keys[key->keyidx] = key;
3729 else
3730 arvif->wep_keys[key->keyidx] = NULL;
3731
3732 if (cmd == DISABLE_KEY)
3733 ath10k_clear_vdev_key(arvif, key);
3734 }
3735
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003736 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3737 * static WEP, do not set this flag for the keys whose key id
3738 * is greater than default key id.
3739 */
3740 if (arvif->def_wep_key_idx == -1)
3741 def_idx = true;
3742
3743 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003745 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003746 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003747 goto exit;
3748 }
3749
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003750 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3751
Kalle Valo5e3dd152013-06-12 20:52:10 +03003752 spin_lock_bh(&ar->data_lock);
3753 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3754 if (peer && cmd == SET_KEY)
3755 peer->keys[key->keyidx] = key;
3756 else if (peer && cmd == DISABLE_KEY)
3757 peer->keys[key->keyidx] = NULL;
3758 else if (peer == NULL)
3759 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003760 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003761 spin_unlock_bh(&ar->data_lock);
3762
3763exit:
3764 mutex_unlock(&ar->conf_mutex);
3765 return ret;
3766}
3767
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003768static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3769 struct ieee80211_vif *vif,
3770 int keyidx)
3771{
3772 struct ath10k *ar = hw->priv;
3773 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3774 int ret;
3775
3776 mutex_lock(&arvif->ar->conf_mutex);
3777
3778 if (arvif->ar->state != ATH10K_STATE_ON)
3779 goto unlock;
3780
3781 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3782 arvif->vdev_id, keyidx);
3783
3784 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3785 arvif->vdev_id,
3786 arvif->ar->wmi.vdev_param->def_keyid,
3787 keyidx);
3788
3789 if (ret) {
3790 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3791 arvif->vdev_id,
3792 ret);
3793 goto unlock;
3794 }
3795
3796 arvif->def_wep_key_idx = keyidx;
3797unlock:
3798 mutex_unlock(&arvif->ar->conf_mutex);
3799}
3800
Michal Kazior9797feb2014-02-14 14:49:48 +01003801static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3802{
3803 struct ath10k *ar;
3804 struct ath10k_vif *arvif;
3805 struct ath10k_sta *arsta;
3806 struct ieee80211_sta *sta;
3807 u32 changed, bw, nss, smps;
3808 int err;
3809
3810 arsta = container_of(wk, struct ath10k_sta, update_wk);
3811 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3812 arvif = arsta->arvif;
3813 ar = arvif->ar;
3814
3815 spin_lock_bh(&ar->data_lock);
3816
3817 changed = arsta->changed;
3818 arsta->changed = 0;
3819
3820 bw = arsta->bw;
3821 nss = arsta->nss;
3822 smps = arsta->smps;
3823
3824 spin_unlock_bh(&ar->data_lock);
3825
3826 mutex_lock(&ar->conf_mutex);
3827
3828 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003829 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003830 sta->addr, bw);
3831
3832 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3833 WMI_PEER_CHAN_WIDTH, bw);
3834 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003835 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003836 sta->addr, bw, err);
3837 }
3838
3839 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003840 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003841 sta->addr, nss);
3842
3843 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3844 WMI_PEER_NSS, nss);
3845 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003846 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003847 sta->addr, nss, err);
3848 }
3849
3850 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003852 sta->addr, smps);
3853
3854 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3855 WMI_PEER_SMPS_STATE, smps);
3856 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003857 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003858 sta->addr, smps, err);
3859 }
3860
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003861 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3862 changed & IEEE80211_RC_NSS_CHANGED) {
3863 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003864 sta->addr);
3865
Michal Kazior590922a2014-10-21 10:10:29 +03003866 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003867 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003868 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003869 sta->addr);
3870 }
3871
Michal Kazior9797feb2014-02-14 14:49:48 +01003872 mutex_unlock(&ar->conf_mutex);
3873}
3874
Michal Kaziorcfd10612014-11-25 15:16:05 +01003875static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3876{
3877 struct ath10k *ar = arvif->ar;
3878
3879 lockdep_assert_held(&ar->conf_mutex);
3880
3881 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3882 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3883 return 0;
3884
3885 if (ar->num_stations >= ar->max_num_stations)
3886 return -ENOBUFS;
3887
3888 ar->num_stations++;
3889
3890 return 0;
3891}
3892
3893static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3894{
3895 struct ath10k *ar = arvif->ar;
3896
3897 lockdep_assert_held(&ar->conf_mutex);
3898
3899 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3900 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3901 return;
3902
3903 ar->num_stations--;
3904}
3905
Kalle Valo5e3dd152013-06-12 20:52:10 +03003906static int ath10k_sta_state(struct ieee80211_hw *hw,
3907 struct ieee80211_vif *vif,
3908 struct ieee80211_sta *sta,
3909 enum ieee80211_sta_state old_state,
3910 enum ieee80211_sta_state new_state)
3911{
3912 struct ath10k *ar = hw->priv;
3913 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003914 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915 int ret = 0;
3916
Michal Kazior76f90022014-02-25 09:29:57 +02003917 if (old_state == IEEE80211_STA_NOTEXIST &&
3918 new_state == IEEE80211_STA_NONE) {
3919 memset(arsta, 0, sizeof(*arsta));
3920 arsta->arvif = arvif;
3921 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3922 }
3923
Michal Kazior9797feb2014-02-14 14:49:48 +01003924 /* cancel must be done outside the mutex to avoid deadlock */
3925 if ((old_state == IEEE80211_STA_NONE &&
3926 new_state == IEEE80211_STA_NOTEXIST))
3927 cancel_work_sync(&arsta->update_wk);
3928
Kalle Valo5e3dd152013-06-12 20:52:10 +03003929 mutex_lock(&ar->conf_mutex);
3930
3931 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003932 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003933 /*
3934 * New station addition.
3935 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003936 ath10k_dbg(ar, ATH10K_DBG_MAC,
3937 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3938 arvif->vdev_id, sta->addr,
3939 ar->num_stations + 1, ar->max_num_stations,
3940 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003941
Michal Kaziorcfd10612014-11-25 15:16:05 +01003942 ret = ath10k_mac_inc_num_stations(arvif);
3943 if (ret) {
3944 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3945 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003946 goto exit;
3947 }
3948
Kalle Valo5e3dd152013-06-12 20:52:10 +03003949 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003951 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 -08003952 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003953 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003954 goto exit;
3955 }
Michal Kazior077efc82014-10-21 10:10:29 +03003956
3957 if (vif->type == NL80211_IFTYPE_STATION) {
3958 WARN_ON(arvif->is_started);
3959
3960 ret = ath10k_vdev_start(arvif);
3961 if (ret) {
3962 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3963 arvif->vdev_id, ret);
3964 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3965 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003966 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003967 goto exit;
3968 }
3969
3970 arvif->is_started = true;
3971 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003972 } else if ((old_state == IEEE80211_STA_NONE &&
3973 new_state == IEEE80211_STA_NOTEXIST)) {
3974 /*
3975 * Existing station deletion.
3976 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003977 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003978 "mac vdev %d peer delete %pM (sta gone)\n",
3979 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003980
3981 if (vif->type == NL80211_IFTYPE_STATION) {
3982 WARN_ON(!arvif->is_started);
3983
3984 ret = ath10k_vdev_stop(arvif);
3985 if (ret)
3986 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3987 arvif->vdev_id, ret);
3988
3989 arvif->is_started = false;
3990 }
3991
Kalle Valo5e3dd152013-06-12 20:52:10 +03003992 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3993 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003994 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003995 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003996
Michal Kaziorcfd10612014-11-25 15:16:05 +01003997 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003998 } else if (old_state == IEEE80211_STA_AUTH &&
3999 new_state == IEEE80211_STA_ASSOC &&
4000 (vif->type == NL80211_IFTYPE_AP ||
4001 vif->type == NL80211_IFTYPE_ADHOC)) {
4002 /*
4003 * New association.
4004 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004006 sta->addr);
4007
Michal Kazior590922a2014-10-21 10:10:29 +03004008 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004009 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004010 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004011 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012 } else if (old_state == IEEE80211_STA_ASSOC &&
4013 new_state == IEEE80211_STA_AUTH &&
4014 (vif->type == NL80211_IFTYPE_AP ||
4015 vif->type == NL80211_IFTYPE_ADHOC)) {
4016 /*
4017 * Disassociation.
4018 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004019 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004020 sta->addr);
4021
Michal Kazior590922a2014-10-21 10:10:29 +03004022 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004024 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004025 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004027exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028 mutex_unlock(&ar->conf_mutex);
4029 return ret;
4030}
4031
4032static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004033 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004034{
4035 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004036 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4037 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004038 u32 value = 0;
4039 int ret = 0;
4040
Michal Kazior548db542013-07-05 16:15:15 +03004041 lockdep_assert_held(&ar->conf_mutex);
4042
Kalle Valo5e3dd152013-06-12 20:52:10 +03004043 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4044 return 0;
4045
4046 switch (ac) {
4047 case IEEE80211_AC_VO:
4048 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4049 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004050 prio = 7;
4051 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004052 break;
4053 case IEEE80211_AC_VI:
4054 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4055 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004056 prio = 5;
4057 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004058 break;
4059 case IEEE80211_AC_BE:
4060 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4061 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004062 prio = 2;
4063 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004064 break;
4065 case IEEE80211_AC_BK:
4066 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4067 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004068 prio = 0;
4069 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004070 break;
4071 }
4072
4073 if (enable)
4074 arvif->u.sta.uapsd |= value;
4075 else
4076 arvif->u.sta.uapsd &= ~value;
4077
4078 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4079 WMI_STA_PS_PARAM_UAPSD,
4080 arvif->u.sta.uapsd);
4081 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004082 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083 goto exit;
4084 }
4085
4086 if (arvif->u.sta.uapsd)
4087 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4088 else
4089 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4090
4091 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4092 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4093 value);
4094 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004095 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004096
Michal Kazior9f9b5742014-12-12 12:41:36 +01004097 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4098 if (ret) {
4099 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4100 arvif->vdev_id, ret);
4101 return ret;
4102 }
4103
4104 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4105 if (ret) {
4106 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4107 arvif->vdev_id, ret);
4108 return ret;
4109 }
4110
Michal Kaziorb0e56152015-01-24 12:14:52 +02004111 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4112 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4113 /* Only userspace can make an educated decision when to send
4114 * trigger frame. The following effectively disables u-UAPSD
4115 * autotrigger in firmware (which is enabled by default
4116 * provided the autotrigger service is available).
4117 */
4118
4119 arg.wmm_ac = acc;
4120 arg.user_priority = prio;
4121 arg.service_interval = 0;
4122 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4123 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4124
4125 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4126 arvif->bssid, &arg, 1);
4127 if (ret) {
4128 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4129 ret);
4130 return ret;
4131 }
4132 }
4133
Kalle Valo5e3dd152013-06-12 20:52:10 +03004134exit:
4135 return ret;
4136}
4137
4138static int ath10k_conf_tx(struct ieee80211_hw *hw,
4139 struct ieee80211_vif *vif, u16 ac,
4140 const struct ieee80211_tx_queue_params *params)
4141{
4142 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004143 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004144 struct wmi_wmm_params_arg *p = NULL;
4145 int ret;
4146
4147 mutex_lock(&ar->conf_mutex);
4148
4149 switch (ac) {
4150 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004151 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004152 break;
4153 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004154 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004155 break;
4156 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004157 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004158 break;
4159 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004160 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 break;
4162 }
4163
4164 if (WARN_ON(!p)) {
4165 ret = -EINVAL;
4166 goto exit;
4167 }
4168
4169 p->cwmin = params->cw_min;
4170 p->cwmax = params->cw_max;
4171 p->aifs = params->aifs;
4172
4173 /*
4174 * The channel time duration programmed in the HW is in absolute
4175 * microseconds, while mac80211 gives the txop in units of
4176 * 32 microseconds.
4177 */
4178 p->txop = params->txop * 32;
4179
Michal Kazior7fc979a2015-01-28 09:57:28 +02004180 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4181 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4182 &arvif->wmm_params);
4183 if (ret) {
4184 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4185 arvif->vdev_id, ret);
4186 goto exit;
4187 }
4188 } else {
4189 /* This won't work well with multi-interface cases but it's
4190 * better than nothing.
4191 */
4192 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4193 if (ret) {
4194 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4195 goto exit;
4196 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004197 }
4198
4199 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4200 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004201 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004202
4203exit:
4204 mutex_unlock(&ar->conf_mutex);
4205 return ret;
4206}
4207
4208#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4209
4210static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4211 struct ieee80211_vif *vif,
4212 struct ieee80211_channel *chan,
4213 int duration,
4214 enum ieee80211_roc_type type)
4215{
4216 struct ath10k *ar = hw->priv;
4217 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4218 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004219 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004220
4221 mutex_lock(&ar->conf_mutex);
4222
4223 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004224 switch (ar->scan.state) {
4225 case ATH10K_SCAN_IDLE:
4226 reinit_completion(&ar->scan.started);
4227 reinit_completion(&ar->scan.completed);
4228 reinit_completion(&ar->scan.on_channel);
4229 ar->scan.state = ATH10K_SCAN_STARTING;
4230 ar->scan.is_roc = true;
4231 ar->scan.vdev_id = arvif->vdev_id;
4232 ar->scan.roc_freq = chan->center_freq;
4233 ret = 0;
4234 break;
4235 case ATH10K_SCAN_STARTING:
4236 case ATH10K_SCAN_RUNNING:
4237 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004238 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004239 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004240 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004241 spin_unlock_bh(&ar->data_lock);
4242
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004243 if (ret)
4244 goto exit;
4245
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004246 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4247
Kalle Valo5e3dd152013-06-12 20:52:10 +03004248 memset(&arg, 0, sizeof(arg));
4249 ath10k_wmi_start_scan_init(ar, &arg);
4250 arg.vdev_id = arvif->vdev_id;
4251 arg.scan_id = ATH10K_SCAN_ID;
4252 arg.n_channels = 1;
4253 arg.channels[0] = chan->center_freq;
4254 arg.dwell_time_active = duration;
4255 arg.dwell_time_passive = duration;
4256 arg.max_scan_time = 2 * duration;
4257 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4258 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4259
4260 ret = ath10k_start_scan(ar, &arg);
4261 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004262 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004263 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004264 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004265 spin_unlock_bh(&ar->data_lock);
4266 goto exit;
4267 }
4268
4269 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4270 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004271 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004272
4273 ret = ath10k_scan_stop(ar);
4274 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004275 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004276
Kalle Valo5e3dd152013-06-12 20:52:10 +03004277 ret = -ETIMEDOUT;
4278 goto exit;
4279 }
4280
4281 ret = 0;
4282exit:
4283 mutex_unlock(&ar->conf_mutex);
4284 return ret;
4285}
4286
4287static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4288{
4289 struct ath10k *ar = hw->priv;
4290
4291 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004292 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004293 mutex_unlock(&ar->conf_mutex);
4294
Michal Kazior4eb2e162014-10-28 10:23:09 +01004295 cancel_delayed_work_sync(&ar->scan.timeout);
4296
Kalle Valo5e3dd152013-06-12 20:52:10 +03004297 return 0;
4298}
4299
4300/*
4301 * Both RTS and Fragmentation threshold are interface-specific
4302 * in ath10k, but device-specific in mac80211.
4303 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304
4305static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4306{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004308 struct ath10k_vif *arvif;
4309 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004310
Michal Kaziorad088bf2013-10-16 15:44:46 +03004311 mutex_lock(&ar->conf_mutex);
4312 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004313 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004314 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004315
Michal Kaziorad088bf2013-10-16 15:44:46 +03004316 ret = ath10k_mac_set_rts(arvif, value);
4317 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004318 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004319 arvif->vdev_id, ret);
4320 break;
4321 }
4322 }
4323 mutex_unlock(&ar->conf_mutex);
4324
4325 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004326}
4327
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004328static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4329 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004330{
4331 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004332 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004333 int ret;
4334
4335 /* mac80211 doesn't care if we really xmit queued frames or not
4336 * we'll collect those frames either way if we stop/delete vdevs */
4337 if (drop)
4338 return;
4339
Michal Kazior548db542013-07-05 16:15:15 +03004340 mutex_lock(&ar->conf_mutex);
4341
Michal Kazioraffd3212013-07-16 09:54:35 +02004342 if (ar->state == ATH10K_STATE_WEDGED)
4343 goto skip;
4344
Michal Kazioredb82362013-07-05 16:15:14 +03004345 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004346 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004347
Michal Kazioredb82362013-07-05 16:15:14 +03004348 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004349 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004350 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004351
Michal Kazior7962b0d2014-10-28 10:34:38 +01004352 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4353 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4354 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004355
4356 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004357 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004358
4359 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004360 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004361 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004362
Michal Kazioraffd3212013-07-16 09:54:35 +02004363skip:
Michal Kazior548db542013-07-05 16:15:15 +03004364 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004365}
4366
4367/* TODO: Implement this function properly
4368 * For now it is needed to reply to Probe Requests in IBSS mode.
4369 * Propably we need this information from FW.
4370 */
4371static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4372{
4373 return 1;
4374}
4375
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004376#ifdef CONFIG_PM
4377static int ath10k_suspend(struct ieee80211_hw *hw,
4378 struct cfg80211_wowlan *wowlan)
4379{
4380 struct ath10k *ar = hw->priv;
4381 int ret;
4382
Marek Puzyniak9042e172014-02-10 17:14:23 +01004383 mutex_lock(&ar->conf_mutex);
4384
Marek Puzyniak00f54822014-02-10 17:14:24 +01004385 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004386 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004387 if (ret == -ETIMEDOUT)
4388 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004389 ret = 1;
4390 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004391 }
4392
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004393 ret = ath10k_hif_suspend(ar);
4394 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004395 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004396 goto resume;
4397 }
4398
Marek Puzyniak9042e172014-02-10 17:14:23 +01004399 ret = 0;
4400 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004401resume:
4402 ret = ath10k_wmi_pdev_resume_target(ar);
4403 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004404 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004405
4406 ret = 1;
4407exit:
4408 mutex_unlock(&ar->conf_mutex);
4409 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004410}
4411
4412static int ath10k_resume(struct ieee80211_hw *hw)
4413{
4414 struct ath10k *ar = hw->priv;
4415 int ret;
4416
Marek Puzyniak9042e172014-02-10 17:14:23 +01004417 mutex_lock(&ar->conf_mutex);
4418
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004419 ret = ath10k_hif_resume(ar);
4420 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004421 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004422 ret = 1;
4423 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004424 }
4425
4426 ret = ath10k_wmi_pdev_resume_target(ar);
4427 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004428 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004429 ret = 1;
4430 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004431 }
4432
Marek Puzyniak9042e172014-02-10 17:14:23 +01004433 ret = 0;
4434exit:
4435 mutex_unlock(&ar->conf_mutex);
4436 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004437}
4438#endif
4439
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004440static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4441 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004442{
4443 struct ath10k *ar = hw->priv;
4444
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004445 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4446 return;
4447
Michal Kazioraffd3212013-07-16 09:54:35 +02004448 mutex_lock(&ar->conf_mutex);
4449
4450 /* If device failed to restart it will be in a different state, e.g.
4451 * ATH10K_STATE_WEDGED */
4452 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004453 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004454 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004455 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004456 }
4457
4458 mutex_unlock(&ar->conf_mutex);
4459}
4460
Michal Kazior2e1dea42013-07-31 10:32:40 +02004461static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4462 struct survey_info *survey)
4463{
4464 struct ath10k *ar = hw->priv;
4465 struct ieee80211_supported_band *sband;
4466 struct survey_info *ar_survey = &ar->survey[idx];
4467 int ret = 0;
4468
4469 mutex_lock(&ar->conf_mutex);
4470
4471 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4472 if (sband && idx >= sband->n_channels) {
4473 idx -= sband->n_channels;
4474 sband = NULL;
4475 }
4476
4477 if (!sband)
4478 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4479
4480 if (!sband || idx >= sband->n_channels) {
4481 ret = -ENOENT;
4482 goto exit;
4483 }
4484
4485 spin_lock_bh(&ar->data_lock);
4486 memcpy(survey, ar_survey, sizeof(*survey));
4487 spin_unlock_bh(&ar->data_lock);
4488
4489 survey->channel = &sband->channels[idx];
4490
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004491 if (ar->rx_channel == survey->channel)
4492 survey->filled |= SURVEY_INFO_IN_USE;
4493
Michal Kazior2e1dea42013-07-31 10:32:40 +02004494exit:
4495 mutex_unlock(&ar->conf_mutex);
4496 return ret;
4497}
4498
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004499/* Helper table for legacy fixed_rate/bitrate_mask */
4500static const u8 cck_ofdm_rate[] = {
4501 /* CCK */
4502 3, /* 1Mbps */
4503 2, /* 2Mbps */
4504 1, /* 5.5Mbps */
4505 0, /* 11Mbps */
4506 /* OFDM */
4507 3, /* 6Mbps */
4508 7, /* 9Mbps */
4509 2, /* 12Mbps */
4510 6, /* 18Mbps */
4511 1, /* 24Mbps */
4512 5, /* 36Mbps */
4513 0, /* 48Mbps */
4514 4, /* 54Mbps */
4515};
4516
4517/* Check if only one bit set */
4518static int ath10k_check_single_mask(u32 mask)
4519{
4520 int bit;
4521
4522 bit = ffs(mask);
4523 if (!bit)
4524 return 0;
4525
4526 mask &= ~BIT(bit - 1);
4527 if (mask)
4528 return 2;
4529
4530 return 1;
4531}
4532
4533static bool
4534ath10k_default_bitrate_mask(struct ath10k *ar,
4535 enum ieee80211_band band,
4536 const struct cfg80211_bitrate_mask *mask)
4537{
4538 u32 legacy = 0x00ff;
4539 u8 ht = 0xff, i;
4540 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004541 u16 nrf = ar->num_rf_chains;
4542
4543 if (ar->cfg_tx_chainmask)
4544 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004545
4546 switch (band) {
4547 case IEEE80211_BAND_2GHZ:
4548 legacy = 0x00fff;
4549 vht = 0;
4550 break;
4551 case IEEE80211_BAND_5GHZ:
4552 break;
4553 default:
4554 return false;
4555 }
4556
4557 if (mask->control[band].legacy != legacy)
4558 return false;
4559
Ben Greearb116ea12014-11-24 16:22:10 +02004560 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004561 if (mask->control[band].ht_mcs[i] != ht)
4562 return false;
4563
Ben Greearb116ea12014-11-24 16:22:10 +02004564 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004565 if (mask->control[band].vht_mcs[i] != vht)
4566 return false;
4567
4568 return true;
4569}
4570
4571static bool
4572ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4573 enum ieee80211_band band,
4574 u8 *fixed_nss)
4575{
4576 int ht_nss = 0, vht_nss = 0, i;
4577
4578 /* check legacy */
4579 if (ath10k_check_single_mask(mask->control[band].legacy))
4580 return false;
4581
4582 /* check HT */
4583 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4584 if (mask->control[band].ht_mcs[i] == 0xff)
4585 continue;
4586 else if (mask->control[band].ht_mcs[i] == 0x00)
4587 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004588
4589 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004590 }
4591
4592 ht_nss = i;
4593
4594 /* check VHT */
4595 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4596 if (mask->control[band].vht_mcs[i] == 0x03ff)
4597 continue;
4598 else if (mask->control[band].vht_mcs[i] == 0x0000)
4599 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004600
4601 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004602 }
4603
4604 vht_nss = i;
4605
4606 if (ht_nss > 0 && vht_nss > 0)
4607 return false;
4608
4609 if (ht_nss)
4610 *fixed_nss = ht_nss;
4611 else if (vht_nss)
4612 *fixed_nss = vht_nss;
4613 else
4614 return false;
4615
4616 return true;
4617}
4618
4619static bool
4620ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4621 enum ieee80211_band band,
4622 enum wmi_rate_preamble *preamble)
4623{
4624 int legacy = 0, ht = 0, vht = 0, i;
4625
4626 *preamble = WMI_RATE_PREAMBLE_OFDM;
4627
4628 /* check legacy */
4629 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4630 if (legacy > 1)
4631 return false;
4632
4633 /* check HT */
4634 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4635 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4636 if (ht > 1)
4637 return false;
4638
4639 /* check VHT */
4640 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4641 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4642 if (vht > 1)
4643 return false;
4644
4645 /* Currently we support only one fixed_rate */
4646 if ((legacy + ht + vht) != 1)
4647 return false;
4648
4649 if (ht)
4650 *preamble = WMI_RATE_PREAMBLE_HT;
4651 else if (vht)
4652 *preamble = WMI_RATE_PREAMBLE_VHT;
4653
4654 return true;
4655}
4656
4657static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004658ath10k_bitrate_mask_rate(struct ath10k *ar,
4659 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004660 enum ieee80211_band band,
4661 u8 *fixed_rate,
4662 u8 *fixed_nss)
4663{
4664 u8 rate = 0, pream = 0, nss = 0, i;
4665 enum wmi_rate_preamble preamble;
4666
4667 /* Check if single rate correct */
4668 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4669 return false;
4670
4671 pream = preamble;
4672
4673 switch (preamble) {
4674 case WMI_RATE_PREAMBLE_CCK:
4675 case WMI_RATE_PREAMBLE_OFDM:
4676 i = ffs(mask->control[band].legacy) - 1;
4677
4678 if (band == IEEE80211_BAND_2GHZ && i < 4)
4679 pream = WMI_RATE_PREAMBLE_CCK;
4680
4681 if (band == IEEE80211_BAND_5GHZ)
4682 i += 4;
4683
4684 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4685 return false;
4686
4687 rate = cck_ofdm_rate[i];
4688 break;
4689 case WMI_RATE_PREAMBLE_HT:
4690 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4691 if (mask->control[band].ht_mcs[i])
4692 break;
4693
4694 if (i == IEEE80211_HT_MCS_MASK_LEN)
4695 return false;
4696
4697 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4698 nss = i;
4699 break;
4700 case WMI_RATE_PREAMBLE_VHT:
4701 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4702 if (mask->control[band].vht_mcs[i])
4703 break;
4704
4705 if (i == NL80211_VHT_NSS_MAX)
4706 return false;
4707
4708 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4709 nss = i;
4710 break;
4711 }
4712
4713 *fixed_nss = nss + 1;
4714 nss <<= 4;
4715 pream <<= 6;
4716
Michal Kazior7aa7a722014-08-25 12:09:38 +02004717 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 +01004718 pream, nss, rate);
4719
4720 *fixed_rate = pream | nss | rate;
4721
4722 return true;
4723}
4724
Michal Kazior7aa7a722014-08-25 12:09:38 +02004725static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4726 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004727 enum ieee80211_band band,
4728 u8 *fixed_rate,
4729 u8 *fixed_nss)
4730{
4731 /* First check full NSS mask, if we can simply limit NSS */
4732 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4733 return true;
4734
4735 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004736 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004737}
4738
4739static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4740 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004741 u8 fixed_nss,
4742 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004743{
4744 struct ath10k *ar = arvif->ar;
4745 u32 vdev_param;
4746 int ret = 0;
4747
4748 mutex_lock(&ar->conf_mutex);
4749
4750 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004751 arvif->fixed_nss == fixed_nss &&
4752 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004753 goto exit;
4754
4755 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004756 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004757
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004758 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004759 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004760
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004761 vdev_param = ar->wmi.vdev_param->fixed_rate;
4762 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4763 vdev_param, fixed_rate);
4764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004765 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004766 fixed_rate, ret);
4767 ret = -EINVAL;
4768 goto exit;
4769 }
4770
4771 arvif->fixed_rate = fixed_rate;
4772
4773 vdev_param = ar->wmi.vdev_param->nss;
4774 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4775 vdev_param, fixed_nss);
4776
4777 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004778 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004779 fixed_nss, ret);
4780 ret = -EINVAL;
4781 goto exit;
4782 }
4783
4784 arvif->fixed_nss = fixed_nss;
4785
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004786 vdev_param = ar->wmi.vdev_param->sgi;
4787 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4788 force_sgi);
4789
4790 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004791 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004792 force_sgi, ret);
4793 ret = -EINVAL;
4794 goto exit;
4795 }
4796
4797 arvif->force_sgi = force_sgi;
4798
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004799exit:
4800 mutex_unlock(&ar->conf_mutex);
4801 return ret;
4802}
4803
4804static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4805 struct ieee80211_vif *vif,
4806 const struct cfg80211_bitrate_mask *mask)
4807{
4808 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4809 struct ath10k *ar = arvif->ar;
4810 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4811 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4812 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004813 u8 force_sgi;
4814
Ben Greearb116ea12014-11-24 16:22:10 +02004815 if (ar->cfg_tx_chainmask)
4816 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4817
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004818 force_sgi = mask->control[band].gi;
4819 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4820 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004821
4822 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004823 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004824 &fixed_rate,
4825 &fixed_nss))
4826 return -EINVAL;
4827 }
4828
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004829 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004830 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004831 return -EINVAL;
4832 }
4833
4834 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4835 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004836}
4837
Michal Kazior9797feb2014-02-14 14:49:48 +01004838static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4839 struct ieee80211_vif *vif,
4840 struct ieee80211_sta *sta,
4841 u32 changed)
4842{
4843 struct ath10k *ar = hw->priv;
4844 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4845 u32 bw, smps;
4846
4847 spin_lock_bh(&ar->data_lock);
4848
Michal Kazior7aa7a722014-08-25 12:09:38 +02004849 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004850 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4851 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4852 sta->smps_mode);
4853
4854 if (changed & IEEE80211_RC_BW_CHANGED) {
4855 bw = WMI_PEER_CHWIDTH_20MHZ;
4856
4857 switch (sta->bandwidth) {
4858 case IEEE80211_STA_RX_BW_20:
4859 bw = WMI_PEER_CHWIDTH_20MHZ;
4860 break;
4861 case IEEE80211_STA_RX_BW_40:
4862 bw = WMI_PEER_CHWIDTH_40MHZ;
4863 break;
4864 case IEEE80211_STA_RX_BW_80:
4865 bw = WMI_PEER_CHWIDTH_80MHZ;
4866 break;
4867 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004868 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004869 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004870 bw = WMI_PEER_CHWIDTH_20MHZ;
4871 break;
4872 }
4873
4874 arsta->bw = bw;
4875 }
4876
4877 if (changed & IEEE80211_RC_NSS_CHANGED)
4878 arsta->nss = sta->rx_nss;
4879
4880 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4881 smps = WMI_PEER_SMPS_PS_NONE;
4882
4883 switch (sta->smps_mode) {
4884 case IEEE80211_SMPS_AUTOMATIC:
4885 case IEEE80211_SMPS_OFF:
4886 smps = WMI_PEER_SMPS_PS_NONE;
4887 break;
4888 case IEEE80211_SMPS_STATIC:
4889 smps = WMI_PEER_SMPS_STATIC;
4890 break;
4891 case IEEE80211_SMPS_DYNAMIC:
4892 smps = WMI_PEER_SMPS_DYNAMIC;
4893 break;
4894 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004895 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004896 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004897 smps = WMI_PEER_SMPS_PS_NONE;
4898 break;
4899 }
4900
4901 arsta->smps = smps;
4902 }
4903
Michal Kazior9797feb2014-02-14 14:49:48 +01004904 arsta->changed |= changed;
4905
4906 spin_unlock_bh(&ar->data_lock);
4907
4908 ieee80211_queue_work(hw, &arsta->update_wk);
4909}
4910
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004911static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4912{
4913 /*
4914 * FIXME: Return 0 for time being. Need to figure out whether FW
4915 * has the API to fetch 64-bit local TSF
4916 */
4917
4918 return 0;
4919}
4920
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004921static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4922 struct ieee80211_vif *vif,
4923 enum ieee80211_ampdu_mlme_action action,
4924 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4925 u8 buf_size)
4926{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004927 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004928 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4929
Michal Kazior7aa7a722014-08-25 12:09:38 +02004930 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 +02004931 arvif->vdev_id, sta->addr, tid, action);
4932
4933 switch (action) {
4934 case IEEE80211_AMPDU_RX_START:
4935 case IEEE80211_AMPDU_RX_STOP:
4936 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4937 * creation/removal. Do we need to verify this?
4938 */
4939 return 0;
4940 case IEEE80211_AMPDU_TX_START:
4941 case IEEE80211_AMPDU_TX_STOP_CONT:
4942 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4943 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4944 case IEEE80211_AMPDU_TX_OPERATIONAL:
4945 /* Firmware offloads Tx aggregation entirely so deny mac80211
4946 * Tx aggregation requests.
4947 */
4948 return -EOPNOTSUPP;
4949 }
4950
4951 return -EINVAL;
4952}
4953
Kalle Valo5e3dd152013-06-12 20:52:10 +03004954static const struct ieee80211_ops ath10k_ops = {
4955 .tx = ath10k_tx,
4956 .start = ath10k_start,
4957 .stop = ath10k_stop,
4958 .config = ath10k_config,
4959 .add_interface = ath10k_add_interface,
4960 .remove_interface = ath10k_remove_interface,
4961 .configure_filter = ath10k_configure_filter,
4962 .bss_info_changed = ath10k_bss_info_changed,
4963 .hw_scan = ath10k_hw_scan,
4964 .cancel_hw_scan = ath10k_cancel_hw_scan,
4965 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004966 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004967 .sta_state = ath10k_sta_state,
4968 .conf_tx = ath10k_conf_tx,
4969 .remain_on_channel = ath10k_remain_on_channel,
4970 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4971 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004972 .flush = ath10k_flush,
4973 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004974 .set_antenna = ath10k_set_antenna,
4975 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004976 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004977 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004978 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004979 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004980 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004981 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004982 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4983 .get_et_stats = ath10k_debug_get_et_stats,
4984 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004985
4986 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4987
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004988#ifdef CONFIG_PM
4989 .suspend = ath10k_suspend,
4990 .resume = ath10k_resume,
4991#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004992#ifdef CONFIG_MAC80211_DEBUGFS
4993 .sta_add_debugfs = ath10k_sta_add_debugfs,
4994#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004995};
4996
4997#define RATETAB_ENT(_rate, _rateid, _flags) { \
4998 .bitrate = (_rate), \
4999 .flags = (_flags), \
5000 .hw_value = (_rateid), \
5001}
5002
5003#define CHAN2G(_channel, _freq, _flags) { \
5004 .band = IEEE80211_BAND_2GHZ, \
5005 .hw_value = (_channel), \
5006 .center_freq = (_freq), \
5007 .flags = (_flags), \
5008 .max_antenna_gain = 0, \
5009 .max_power = 30, \
5010}
5011
5012#define CHAN5G(_channel, _freq, _flags) { \
5013 .band = IEEE80211_BAND_5GHZ, \
5014 .hw_value = (_channel), \
5015 .center_freq = (_freq), \
5016 .flags = (_flags), \
5017 .max_antenna_gain = 0, \
5018 .max_power = 30, \
5019}
5020
5021static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5022 CHAN2G(1, 2412, 0),
5023 CHAN2G(2, 2417, 0),
5024 CHAN2G(3, 2422, 0),
5025 CHAN2G(4, 2427, 0),
5026 CHAN2G(5, 2432, 0),
5027 CHAN2G(6, 2437, 0),
5028 CHAN2G(7, 2442, 0),
5029 CHAN2G(8, 2447, 0),
5030 CHAN2G(9, 2452, 0),
5031 CHAN2G(10, 2457, 0),
5032 CHAN2G(11, 2462, 0),
5033 CHAN2G(12, 2467, 0),
5034 CHAN2G(13, 2472, 0),
5035 CHAN2G(14, 2484, 0),
5036};
5037
5038static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005039 CHAN5G(36, 5180, 0),
5040 CHAN5G(40, 5200, 0),
5041 CHAN5G(44, 5220, 0),
5042 CHAN5G(48, 5240, 0),
5043 CHAN5G(52, 5260, 0),
5044 CHAN5G(56, 5280, 0),
5045 CHAN5G(60, 5300, 0),
5046 CHAN5G(64, 5320, 0),
5047 CHAN5G(100, 5500, 0),
5048 CHAN5G(104, 5520, 0),
5049 CHAN5G(108, 5540, 0),
5050 CHAN5G(112, 5560, 0),
5051 CHAN5G(116, 5580, 0),
5052 CHAN5G(120, 5600, 0),
5053 CHAN5G(124, 5620, 0),
5054 CHAN5G(128, 5640, 0),
5055 CHAN5G(132, 5660, 0),
5056 CHAN5G(136, 5680, 0),
5057 CHAN5G(140, 5700, 0),
5058 CHAN5G(149, 5745, 0),
5059 CHAN5G(153, 5765, 0),
5060 CHAN5G(157, 5785, 0),
5061 CHAN5G(161, 5805, 0),
5062 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005063};
5064
Michal Kazior91b12082014-12-12 12:41:35 +01005065/* Note: Be careful if you re-order these. There is code which depends on this
5066 * ordering.
5067 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005068static struct ieee80211_rate ath10k_rates[] = {
5069 /* CCK */
5070 RATETAB_ENT(10, 0x82, 0),
5071 RATETAB_ENT(20, 0x84, 0),
5072 RATETAB_ENT(55, 0x8b, 0),
5073 RATETAB_ENT(110, 0x96, 0),
5074 /* OFDM */
5075 RATETAB_ENT(60, 0x0c, 0),
5076 RATETAB_ENT(90, 0x12, 0),
5077 RATETAB_ENT(120, 0x18, 0),
5078 RATETAB_ENT(180, 0x24, 0),
5079 RATETAB_ENT(240, 0x30, 0),
5080 RATETAB_ENT(360, 0x48, 0),
5081 RATETAB_ENT(480, 0x60, 0),
5082 RATETAB_ENT(540, 0x6c, 0),
5083};
5084
5085#define ath10k_a_rates (ath10k_rates + 4)
5086#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5087#define ath10k_g_rates (ath10k_rates + 0)
5088#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5089
Michal Kaziore7b54192014-08-07 11:03:27 +02005090struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005091{
5092 struct ieee80211_hw *hw;
5093 struct ath10k *ar;
5094
Michal Kaziore7b54192014-08-07 11:03:27 +02005095 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005096 if (!hw)
5097 return NULL;
5098
5099 ar = hw->priv;
5100 ar->hw = hw;
5101
5102 return ar;
5103}
5104
5105void ath10k_mac_destroy(struct ath10k *ar)
5106{
5107 ieee80211_free_hw(ar->hw);
5108}
5109
5110static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5111 {
5112 .max = 8,
5113 .types = BIT(NL80211_IFTYPE_STATION)
5114 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005115 },
5116 {
5117 .max = 3,
5118 .types = BIT(NL80211_IFTYPE_P2P_GO)
5119 },
5120 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005121 .max = 1,
5122 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5123 },
5124 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005125 .max = 7,
5126 .types = BIT(NL80211_IFTYPE_AP)
5127 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005128};
5129
Bartosz Markowskif2595092013-12-10 16:20:39 +01005130static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005131 {
5132 .max = 8,
5133 .types = BIT(NL80211_IFTYPE_AP)
5134 },
5135};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005136
5137static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5138 {
5139 .limits = ath10k_if_limits,
5140 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5141 .max_interfaces = 8,
5142 .num_different_channels = 1,
5143 .beacon_int_infra_match = true,
5144 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005145};
5146
5147static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005148 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005149 .limits = ath10k_10x_if_limits,
5150 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005151 .max_interfaces = 8,
5152 .num_different_channels = 1,
5153 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005154#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005155 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5156 BIT(NL80211_CHAN_WIDTH_20) |
5157 BIT(NL80211_CHAN_WIDTH_40) |
5158 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005159#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005160 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005161};
5162
5163static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5164{
5165 struct ieee80211_sta_vht_cap vht_cap = {0};
5166 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005167 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005168
5169 vht_cap.vht_supported = 1;
5170 vht_cap.cap = ar->vht_cap_info;
5171
Michal Kazior8865bee42013-07-24 12:36:46 +02005172 mcs_map = 0;
5173 for (i = 0; i < 8; i++) {
5174 if (i < ar->num_rf_chains)
5175 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5176 else
5177 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5178 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005179
5180 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5181 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5182
5183 return vht_cap;
5184}
5185
5186static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5187{
5188 int i;
5189 struct ieee80211_sta_ht_cap ht_cap = {0};
5190
5191 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5192 return ht_cap;
5193
5194 ht_cap.ht_supported = 1;
5195 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5196 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5197 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5198 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5199 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5200
5201 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5202 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5203
5204 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5205 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5206
5207 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5208 u32 smps;
5209
5210 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5211 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5212
5213 ht_cap.cap |= smps;
5214 }
5215
5216 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5217 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5218
5219 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5220 u32 stbc;
5221
5222 stbc = ar->ht_cap_info;
5223 stbc &= WMI_HT_CAP_RX_STBC;
5224 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5225 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5226 stbc &= IEEE80211_HT_CAP_RX_STBC;
5227
5228 ht_cap.cap |= stbc;
5229 }
5230
5231 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5232 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5233
5234 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5235 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5236
5237 /* max AMSDU is implicitly taken from vht_cap_info */
5238 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5239 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5240
Michal Kazior8865bee42013-07-24 12:36:46 +02005241 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005242 ht_cap.mcs.rx_mask[i] = 0xFF;
5243
5244 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5245
5246 return ht_cap;
5247}
5248
Kalle Valo5e3dd152013-06-12 20:52:10 +03005249static void ath10k_get_arvif_iter(void *data, u8 *mac,
5250 struct ieee80211_vif *vif)
5251{
5252 struct ath10k_vif_iter *arvif_iter = data;
5253 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5254
5255 if (arvif->vdev_id == arvif_iter->vdev_id)
5256 arvif_iter->arvif = arvif;
5257}
5258
5259struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5260{
5261 struct ath10k_vif_iter arvif_iter;
5262 u32 flags;
5263
5264 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5265 arvif_iter.vdev_id = vdev_id;
5266
5267 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5268 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5269 flags,
5270 ath10k_get_arvif_iter,
5271 &arvif_iter);
5272 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005273 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005274 return NULL;
5275 }
5276
5277 return arvif_iter.arvif;
5278}
5279
5280int ath10k_mac_register(struct ath10k *ar)
5281{
5282 struct ieee80211_supported_band *band;
5283 struct ieee80211_sta_vht_cap vht_cap;
5284 struct ieee80211_sta_ht_cap ht_cap;
5285 void *channels;
5286 int ret;
5287
5288 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5289
5290 SET_IEEE80211_DEV(ar->hw, ar->dev);
5291
5292 ht_cap = ath10k_get_ht_cap(ar);
5293 vht_cap = ath10k_create_vht_cap(ar);
5294
5295 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5296 channels = kmemdup(ath10k_2ghz_channels,
5297 sizeof(ath10k_2ghz_channels),
5298 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005299 if (!channels) {
5300 ret = -ENOMEM;
5301 goto err_free;
5302 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005303
5304 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5305 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5306 band->channels = channels;
5307 band->n_bitrates = ath10k_g_rates_size;
5308 band->bitrates = ath10k_g_rates;
5309 band->ht_cap = ht_cap;
5310
Yanbo Lid68bb122015-01-23 08:18:20 +08005311 /* Enable the VHT support at 2.4 GHz */
5312 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005313
5314 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5315 }
5316
5317 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5318 channels = kmemdup(ath10k_5ghz_channels,
5319 sizeof(ath10k_5ghz_channels),
5320 GFP_KERNEL);
5321 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005322 ret = -ENOMEM;
5323 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005324 }
5325
5326 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5327 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5328 band->channels = channels;
5329 band->n_bitrates = ath10k_a_rates_size;
5330 band->bitrates = ath10k_a_rates;
5331 band->ht_cap = ht_cap;
5332 band->vht_cap = vht_cap;
5333 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5334 }
5335
5336 ar->hw->wiphy->interface_modes =
5337 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005338 BIT(NL80211_IFTYPE_AP);
5339
Ben Greear46acf7b2014-05-16 17:15:38 +03005340 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5341 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5342
Bartosz Markowskid3541812013-12-10 16:20:40 +01005343 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5344 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005345 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005346 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5347 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005348
5349 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5350 IEEE80211_HW_SUPPORTS_PS |
5351 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005352 IEEE80211_HW_MFP_CAPABLE |
5353 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5354 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005355 IEEE80211_HW_AP_LINK_PS |
5356 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005357
Eliad Peller0d8614b2014-09-10 14:07:36 +03005358 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5359
Kalle Valo5e3dd152013-06-12 20:52:10 +03005360 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005361 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005362
5363 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5364 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5365 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5366 }
5367
5368 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5369 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5370
5371 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005372 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005373
Kalle Valo5e3dd152013-06-12 20:52:10 +03005374 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5375
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005376 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5377 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5378
5379 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5380 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5381 * correct Probe Responses. This is more of a hack advert..
5382 */
5383 ar->hw->wiphy->probe_resp_offload |=
5384 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5385 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5386 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5387 }
5388
Kalle Valo5e3dd152013-06-12 20:52:10 +03005389 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005390 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5392
5393 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005394 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5395
Kalle Valo5e3dd152013-06-12 20:52:10 +03005396 /*
5397 * on LL hardware queues are managed entirely by the FW
5398 * so we only advertise to mac we can do the queues thing
5399 */
5400 ar->hw->queues = 4;
5401
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005402 switch (ar->wmi.op_version) {
5403 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5404 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005405 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5406 ar->hw->wiphy->n_iface_combinations =
5407 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005408 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005409 break;
5410 case ATH10K_FW_WMI_OP_VERSION_10_1:
5411 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005412 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005413 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5414 ar->hw->wiphy->n_iface_combinations =
5415 ARRAY_SIZE(ath10k_10x_if_comb);
5416 break;
5417 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5418 case ATH10K_FW_WMI_OP_VERSION_MAX:
5419 WARN_ON(1);
5420 ret = -EINVAL;
5421 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005422 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005423
Michal Kazior7c199992013-07-31 10:47:57 +02005424 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5425
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005426 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5427 /* Init ath dfs pattern detector */
5428 ar->ath_common.debug_mask = ATH_DBG_DFS;
5429 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5430 NL80211_DFS_UNSET);
5431
5432 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005433 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005434 }
5435
Kalle Valo5e3dd152013-06-12 20:52:10 +03005436 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5437 ath10k_reg_notifier);
5438 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005439 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005440 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005441 }
5442
5443 ret = ieee80211_register_hw(ar->hw);
5444 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005445 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005446 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005447 }
5448
5449 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5450 ret = regulatory_hint(ar->hw->wiphy,
5451 ar->ath_common.regulatory.alpha2);
5452 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005453 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005454 }
5455
5456 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005457
5458err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005459 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005460err_free:
5461 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5462 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5463
Kalle Valo5e3dd152013-06-12 20:52:10 +03005464 return ret;
5465}
5466
5467void ath10k_mac_unregister(struct ath10k *ar)
5468{
5469 ieee80211_unregister_hw(ar->hw);
5470
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005471 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5472 ar->dfs_detector->exit(ar->dfs_detector);
5473
Kalle Valo5e3dd152013-06-12 20:52:10 +03005474 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5475 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5476
5477 SET_IEEE80211_DEV(ar->hw, NULL);
5478}