blob: 943e8909ea82e110fd00c704fea77a4611f0e7d4 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030032
33/**********/
34/* Crypto */
35/**********/
36
37static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
39 enum set_key_cmd cmd,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020040 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030041{
Michal Kazior7aa7a722014-08-25 12:09:38 +020042 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030043 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
47 .key_data = key->key,
48 .macaddr = macaddr,
49 };
50
Michal Kazior548db542013-07-05 16:15:15 +030051 lockdep_assert_held(&arvif->ar->conf_mutex);
52
Kalle Valo5e3dd152013-06-12 20:52:10 +030053 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
55 else
56 arg.key_flags = WMI_KEY_GROUP;
57
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020061 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020075
76 if (def_idx)
77 arg.key_flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 break;
79 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020080 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030081 return -EOPNOTSUPP;
82 }
83
84 if (cmd == DISABLE_KEY) {
85 arg.key_cipher = WMI_CIPHER_NONE;
86 arg.key_data = NULL;
87 }
88
89 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
90}
91
92static int ath10k_install_key(struct ath10k_vif *arvif,
93 struct ieee80211_key_conf *key,
94 enum set_key_cmd cmd,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020095 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030096{
97 struct ath10k *ar = arvif->ar;
98 int ret;
99
Michal Kazior548db542013-07-05 16:15:15 +0300100 lockdep_assert_held(&ar->conf_mutex);
101
Wolfram Sang16735d02013-11-14 14:32:02 -0800102 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300103
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200104 ret = ath10k_send_key(arvif, key, cmd, macaddr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300105 if (ret)
106 return ret;
107
108 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
109 if (ret == 0)
110 return -ETIMEDOUT;
111
112 return 0;
113}
114
115static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
116 const u8 *addr)
117{
118 struct ath10k *ar = arvif->ar;
119 struct ath10k_peer *peer;
120 int ret;
121 int i;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200122 bool def_idx;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300123
124 lockdep_assert_held(&ar->conf_mutex);
125
126 spin_lock_bh(&ar->data_lock);
127 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
128 spin_unlock_bh(&ar->data_lock);
129
130 if (!peer)
131 return -ENOENT;
132
133 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
134 if (arvif->wep_keys[i] == NULL)
135 continue;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200136 /* set TX_USAGE flag for default key id */
137 if (arvif->def_wep_key_idx == i)
138 def_idx = true;
139 else
140 def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300141
142 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200143 addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 if (ret)
145 return ret;
146
Sujith Manoharanae167132014-11-25 11:46:59 +0530147 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530149 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300150 }
151
152 return 0;
153}
154
155static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
156 const u8 *addr)
157{
158 struct ath10k *ar = arvif->ar;
159 struct ath10k_peer *peer;
160 int first_errno = 0;
161 int ret;
162 int i;
163
164 lockdep_assert_held(&ar->conf_mutex);
165
166 spin_lock_bh(&ar->data_lock);
167 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
168 spin_unlock_bh(&ar->data_lock);
169
170 if (!peer)
171 return -ENOENT;
172
173 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
174 if (peer->keys[i] == NULL)
175 continue;
176
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200177 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 ret = ath10k_install_key(arvif, peer->keys[i],
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200179 DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 if (ret && first_errno == 0)
181 first_errno = ret;
182
183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200184 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 i, ret);
186
Sujith Manoharanae167132014-11-25 11:46:59 +0530187 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530189 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300190 }
191
192 return first_errno;
193}
194
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530195bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
196 u8 keyidx)
197{
198 struct ath10k_peer *peer;
199 int i;
200
201 lockdep_assert_held(&ar->data_lock);
202
203 /* We don't know which vdev this peer belongs to,
204 * since WMI doesn't give us that information.
205 *
206 * FIXME: multi-bss needs to be handled.
207 */
208 peer = ath10k_peer_find(ar, 0, addr);
209 if (!peer)
210 return false;
211
212 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
213 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
214 return true;
215 }
216
217 return false;
218}
219
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
221 struct ieee80211_key_conf *key)
222{
223 struct ath10k *ar = arvif->ar;
224 struct ath10k_peer *peer;
225 u8 addr[ETH_ALEN];
226 int first_errno = 0;
227 int ret;
228 int i;
229
230 lockdep_assert_held(&ar->conf_mutex);
231
232 for (;;) {
233 /* since ath10k_install_key we can't hold data_lock all the
234 * time, so we try to remove the keys incrementally */
235 spin_lock_bh(&ar->data_lock);
236 i = 0;
237 list_for_each_entry(peer, &ar->peers, list) {
238 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
239 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300240 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300241 peer->keys[i] = NULL;
242 break;
243 }
244 }
245
246 if (i < ARRAY_SIZE(peer->keys))
247 break;
248 }
249 spin_unlock_bh(&ar->data_lock);
250
251 if (i == ARRAY_SIZE(peer->keys))
252 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200253 /* key flags are not required to delete the key */
254 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300255 if (ret && first_errno == 0)
256 first_errno = ret;
257
258 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200259 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200260 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300261 }
262
263 return first_errno;
264}
265
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266/*********************/
267/* General utilities */
268/*********************/
269
270static inline enum wmi_phy_mode
271chan_to_phymode(const struct cfg80211_chan_def *chandef)
272{
273 enum wmi_phy_mode phymode = MODE_UNKNOWN;
274
275 switch (chandef->chan->band) {
276 case IEEE80211_BAND_2GHZ:
277 switch (chandef->width) {
278 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800279 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
280 phymode = MODE_11B;
281 else
282 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283 break;
284 case NL80211_CHAN_WIDTH_20:
285 phymode = MODE_11NG_HT20;
286 break;
287 case NL80211_CHAN_WIDTH_40:
288 phymode = MODE_11NG_HT40;
289 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400290 case NL80211_CHAN_WIDTH_5:
291 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300292 case NL80211_CHAN_WIDTH_80:
293 case NL80211_CHAN_WIDTH_80P80:
294 case NL80211_CHAN_WIDTH_160:
295 phymode = MODE_UNKNOWN;
296 break;
297 }
298 break;
299 case IEEE80211_BAND_5GHZ:
300 switch (chandef->width) {
301 case NL80211_CHAN_WIDTH_20_NOHT:
302 phymode = MODE_11A;
303 break;
304 case NL80211_CHAN_WIDTH_20:
305 phymode = MODE_11NA_HT20;
306 break;
307 case NL80211_CHAN_WIDTH_40:
308 phymode = MODE_11NA_HT40;
309 break;
310 case NL80211_CHAN_WIDTH_80:
311 phymode = MODE_11AC_VHT80;
312 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400313 case NL80211_CHAN_WIDTH_5:
314 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315 case NL80211_CHAN_WIDTH_80P80:
316 case NL80211_CHAN_WIDTH_160:
317 phymode = MODE_UNKNOWN;
318 break;
319 }
320 break;
321 default:
322 break;
323 }
324
325 WARN_ON(phymode == MODE_UNKNOWN);
326 return phymode;
327}
328
329static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
330{
331/*
332 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
333 * 0 for no restriction
334 * 1 for 1/4 us
335 * 2 for 1/2 us
336 * 3 for 1 us
337 * 4 for 2 us
338 * 5 for 4 us
339 * 6 for 8 us
340 * 7 for 16 us
341 */
342 switch (mpdudensity) {
343 case 0:
344 return 0;
345 case 1:
346 case 2:
347 case 3:
348 /* Our lower layer calculations limit our precision to
349 1 microsecond */
350 return 1;
351 case 4:
352 return 2;
353 case 5:
354 return 4;
355 case 6:
356 return 8;
357 case 7:
358 return 16;
359 default:
360 return 0;
361 }
362}
363
364static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
365{
366 int ret;
367
368 lockdep_assert_held(&ar->conf_mutex);
369
Michal Kaziorcfd10612014-11-25 15:16:05 +0100370 if (ar->num_peers >= ar->max_num_peers)
371 return -ENOBUFS;
372
Kalle Valo5e3dd152013-06-12 20:52:10 +0300373 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800374 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200375 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200376 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300377 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800378 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300379
380 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200382 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200383 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300384 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800385 }
Michal Kazior292a7532014-11-25 15:16:04 +0100386
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100387 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300388
389 return 0;
390}
391
Kalle Valo5a13e762014-01-20 11:01:46 +0200392static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
393{
394 struct ath10k *ar = arvif->ar;
395 u32 param;
396 int ret;
397
398 param = ar->wmi.pdev_param->sta_kickout_th;
399 ret = ath10k_wmi_pdev_set_param(ar, param,
400 ATH10K_KICKOUT_THRESHOLD);
401 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200402 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200403 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200404 return ret;
405 }
406
407 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
408 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
409 ATH10K_KEEPALIVE_MIN_IDLE);
410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200411 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200412 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200413 return ret;
414 }
415
416 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
417 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
418 ATH10K_KEEPALIVE_MAX_IDLE);
419 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200420 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200421 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200422 return ret;
423 }
424
425 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
426 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
427 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200429 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200430 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200431 return ret;
432 }
433
434 return 0;
435}
436
Vivek Natarajanacab6402014-11-26 09:06:12 +0200437static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200438{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200439 struct ath10k *ar = arvif->ar;
440 u32 vdev_param;
441
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200442 vdev_param = ar->wmi.vdev_param->rts_threshold;
443 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200444}
445
446static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
447{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200448 struct ath10k *ar = arvif->ar;
449 u32 vdev_param;
450
Michal Kazior424121c2013-07-22 14:13:31 +0200451 if (value != 0xFFFFFFFF)
452 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
453 ATH10K_FRAGMT_THRESHOLD_MIN,
454 ATH10K_FRAGMT_THRESHOLD_MAX);
455
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200456 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
457 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200458}
459
Kalle Valo5e3dd152013-06-12 20:52:10 +0300460static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
461{
462 int ret;
463
464 lockdep_assert_held(&ar->conf_mutex);
465
466 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
467 if (ret)
468 return ret;
469
470 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
471 if (ret)
472 return ret;
473
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100475
Kalle Valo5e3dd152013-06-12 20:52:10 +0300476 return 0;
477}
478
479static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
480{
481 struct ath10k_peer *peer, *tmp;
482
483 lockdep_assert_held(&ar->conf_mutex);
484
485 spin_lock_bh(&ar->data_lock);
486 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
487 if (peer->vdev_id != vdev_id)
488 continue;
489
Michal Kazior7aa7a722014-08-25 12:09:38 +0200490 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300491 peer->addr, vdev_id);
492
493 list_del(&peer->list);
494 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100495 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300496 }
497 spin_unlock_bh(&ar->data_lock);
498}
499
Michal Kaziora96d7742013-07-16 09:38:56 +0200500static void ath10k_peer_cleanup_all(struct ath10k *ar)
501{
502 struct ath10k_peer *peer, *tmp;
503
504 lockdep_assert_held(&ar->conf_mutex);
505
506 spin_lock_bh(&ar->data_lock);
507 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
508 list_del(&peer->list);
509 kfree(peer);
510 }
511 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100512
513 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100514 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200515}
516
Kalle Valo5e3dd152013-06-12 20:52:10 +0300517/************************/
518/* Interface management */
519/************************/
520
Michal Kazior64badcb2014-09-18 11:18:02 +0300521void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
522{
523 struct ath10k *ar = arvif->ar;
524
525 lockdep_assert_held(&ar->data_lock);
526
527 if (!arvif->beacon)
528 return;
529
530 if (!arvif->beacon_buf)
531 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
532 arvif->beacon->len, DMA_TO_DEVICE);
533
Michal Kazioraf213192015-01-29 14:29:52 +0200534 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
535 arvif->beacon_state != ATH10K_BEACON_SENT))
536 return;
537
Michal Kazior64badcb2014-09-18 11:18:02 +0300538 dev_kfree_skb_any(arvif->beacon);
539
540 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200541 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300542}
543
544static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
545{
546 struct ath10k *ar = arvif->ar;
547
548 lockdep_assert_held(&ar->data_lock);
549
550 ath10k_mac_vif_beacon_free(arvif);
551
552 if (arvif->beacon_buf) {
553 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
554 arvif->beacon_buf, arvif->beacon_paddr);
555 arvif->beacon_buf = NULL;
556 }
557}
558
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
560{
561 int ret;
562
Michal Kazior548db542013-07-05 16:15:15 +0300563 lockdep_assert_held(&ar->conf_mutex);
564
Michal Kazior7962b0d2014-10-28 10:34:38 +0100565 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
566 return -ESHUTDOWN;
567
Kalle Valo5e3dd152013-06-12 20:52:10 +0300568 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
569 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
570 if (ret == 0)
571 return -ETIMEDOUT;
572
573 return 0;
574}
575
Michal Kazior1bbc0972014-04-08 09:45:47 +0300576static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577{
Michal Kaziorc930f742014-01-23 11:38:25 +0100578 struct cfg80211_chan_def *chandef = &ar->chandef;
579 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 int ret = 0;
582
583 lockdep_assert_held(&ar->conf_mutex);
584
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585 arg.vdev_id = vdev_id;
586 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100587 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588
589 /* TODO setup this dynamically, what in case we
590 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100591 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200592 arg.channel.chan_radar =
593 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
Michal Kazior89c5c842013-10-23 04:02:13 -0700595 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700596 arg.channel.max_power = channel->max_power * 2;
597 arg.channel.max_reg_power = channel->max_reg_power * 2;
598 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599
Michal Kazior7962b0d2014-10-28 10:34:38 +0100600 reinit_completion(&ar->vdev_setup_done);
601
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 ret = ath10k_wmi_vdev_start(ar, &arg);
603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200604 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200605 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 return ret;
607 }
608
609 ret = ath10k_vdev_setup_sync(ar);
610 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200611 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200612 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return ret;
614 }
615
616 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 goto vdev_stop;
621 }
622
623 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624
Michal Kazior7aa7a722014-08-25 12:09:38 +0200625 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300626 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627 return 0;
628
629vdev_stop:
630 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200632 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200633 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634
635 return ret;
636}
637
Michal Kazior1bbc0972014-04-08 09:45:47 +0300638static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300639{
640 int ret = 0;
641
642 lockdep_assert_held(&ar->conf_mutex);
643
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200644 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
645 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200646 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200647 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648
Michal Kazior7962b0d2014-10-28 10:34:38 +0100649 reinit_completion(&ar->vdev_setup_done);
650
Kalle Valo5e3dd152013-06-12 20:52:10 +0300651 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
652 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200653 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200654 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655
656 ret = ath10k_vdev_setup_sync(ar);
657 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200658 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200659 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660
Michal Kazior7aa7a722014-08-25 12:09:38 +0200661 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300662 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 return ret;
664}
665
Michal Kazior1bbc0972014-04-08 09:45:47 +0300666static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667{
668 int bit, ret = 0;
669
670 lockdep_assert_held(&ar->conf_mutex);
671
Ben Greeara9aefb32014-08-12 11:02:19 +0300672 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200673 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 return -ENOMEM;
675 }
676
Ben Greear16c11172014-09-23 14:17:16 -0700677 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300678
Ben Greear16c11172014-09-23 14:17:16 -0700679 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr);
684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200685 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200686 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300687 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688 }
689
Ben Greear16c11172014-09-23 14:17:16 -0700690 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200691 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 ar->monitor_vdev_id);
693
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695}
696
Michal Kazior1bbc0972014-04-08 09:45:47 +0300697static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300698{
699 int ret = 0;
700
701 lockdep_assert_held(&ar->conf_mutex);
702
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200705 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200706 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707 return ret;
708 }
709
Ben Greear16c11172014-09-23 14:17:16 -0700710 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300711
Michal Kazior7aa7a722014-08-25 12:09:38 +0200712 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300713 ar->monitor_vdev_id);
714 return ret;
715}
716
Michal Kazior1bbc0972014-04-08 09:45:47 +0300717static int ath10k_monitor_start(struct ath10k *ar)
718{
719 int ret;
720
721 lockdep_assert_held(&ar->conf_mutex);
722
Michal Kazior1bbc0972014-04-08 09:45:47 +0300723 ret = ath10k_monitor_vdev_create(ar);
724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200725 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300726 return ret;
727 }
728
729 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
730 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200731 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300732 ath10k_monitor_vdev_delete(ar);
733 return ret;
734 }
735
736 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300738
739 return 0;
740}
741
Michal Kazior19337472014-08-28 12:58:16 +0200742static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300743{
744 int ret;
745
746 lockdep_assert_held(&ar->conf_mutex);
747
Michal Kazior1bbc0972014-04-08 09:45:47 +0300748 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200749 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200750 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200751 return ret;
752 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300753
754 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200755 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200756 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200757 return ret;
758 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300759
760 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200761 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200762
763 return 0;
764}
765
766static int ath10k_monitor_recalc(struct ath10k *ar)
767{
768 bool should_start;
769
770 lockdep_assert_held(&ar->conf_mutex);
771
772 should_start = ar->monitor ||
773 ar->filter_flags & FIF_PROMISC_IN_BSS ||
774 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
775
776 ath10k_dbg(ar, ATH10K_DBG_MAC,
777 "mac monitor recalc started? %d should? %d\n",
778 ar->monitor_started, should_start);
779
780 if (should_start == ar->monitor_started)
781 return 0;
782
783 if (should_start)
784 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300785
786 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300787}
788
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200789static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
790{
791 struct ath10k *ar = arvif->ar;
792 u32 vdev_param, rts_cts = 0;
793
794 lockdep_assert_held(&ar->conf_mutex);
795
796 vdev_param = ar->wmi.vdev_param->enable_rtscts;
797
798 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
799 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
800
801 if (arvif->num_legacy_stations > 0)
802 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
803 WMI_RTSCTS_PROFILE);
804
805 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
806 rts_cts);
807}
808
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200809static int ath10k_start_cac(struct ath10k *ar)
810{
811 int ret;
812
813 lockdep_assert_held(&ar->conf_mutex);
814
815 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
816
Michal Kazior19337472014-08-28 12:58:16 +0200817 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200819 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200820 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
821 return ret;
822 }
823
Michal Kazior7aa7a722014-08-25 12:09:38 +0200824 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200825 ar->monitor_vdev_id);
826
827 return 0;
828}
829
830static int ath10k_stop_cac(struct ath10k *ar)
831{
832 lockdep_assert_held(&ar->conf_mutex);
833
834 /* CAC is not running - do nothing */
835 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
836 return 0;
837
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300839 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200840
Michal Kazior7aa7a722014-08-25 12:09:38 +0200841 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200842
843 return 0;
844}
845
Michal Kaziord6500972014-04-08 09:56:09 +0300846static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200847{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200848 int ret;
849
850 lockdep_assert_held(&ar->conf_mutex);
851
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200852 ath10k_stop_cac(ar);
853
Michal Kaziord6500972014-04-08 09:56:09 +0300854 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200855 return;
856
Michal Kaziord6500972014-04-08 09:56:09 +0300857 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200858 return;
859
860 ret = ath10k_start_cac(ar);
861 if (ret) {
862 /*
863 * Not possible to start CAC on current channel so starting
864 * radiation is not allowed, make this channel DFS_UNAVAILABLE
865 * by indicating that radar was detected.
866 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200867 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200868 ieee80211_radar_detected(ar->hw);
869 }
870}
871
Michal Kaziordc55e302014-07-29 12:53:36 +0300872static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300873{
874 struct ath10k *ar = arvif->ar;
875 struct cfg80211_chan_def *chandef = &ar->chandef;
876 struct wmi_vdev_start_request_arg arg = {};
877 int ret = 0;
878
879 lockdep_assert_held(&ar->conf_mutex);
880
881 reinit_completion(&ar->vdev_setup_done);
882
883 arg.vdev_id = arvif->vdev_id;
884 arg.dtim_period = arvif->dtim_period;
885 arg.bcn_intval = arvif->beacon_interval;
886
887 arg.channel.freq = chandef->chan->center_freq;
888 arg.channel.band_center_freq1 = chandef->center_freq1;
889 arg.channel.mode = chan_to_phymode(chandef);
890
891 arg.channel.min_power = 0;
892 arg.channel.max_power = chandef->chan->max_power * 2;
893 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
894 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
895
896 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
897 arg.ssid = arvif->u.ap.ssid;
898 arg.ssid_len = arvif->u.ap.ssid_len;
899 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
900
901 /* For now allow DFS for AP mode */
902 arg.channel.chan_radar =
903 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
904 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
905 arg.ssid = arvif->vif->bss_conf.ssid;
906 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
907 }
908
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 "mac vdev %d start center_freq %d phymode %s\n",
911 arg.vdev_id, arg.channel.freq,
912 ath10k_wmi_phymode_str(arg.channel.mode));
913
Michal Kaziordc55e302014-07-29 12:53:36 +0300914 if (restart)
915 ret = ath10k_wmi_vdev_restart(ar, &arg);
916 else
917 ret = ath10k_wmi_vdev_start(ar, &arg);
918
Michal Kazior72654fa2014-04-08 09:56:09 +0300919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200920 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300921 arg.vdev_id, ret);
922 return ret;
923 }
924
925 ret = ath10k_vdev_setup_sync(ar);
926 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200927 ath10k_warn(ar,
928 "failed to synchronize setup for vdev %i restart %d: %d\n",
929 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +0300930 return ret;
931 }
932
Michal Kaziord6500972014-04-08 09:56:09 +0300933 ar->num_started_vdevs++;
934 ath10k_recalc_radar_detection(ar);
935
Michal Kazior72654fa2014-04-08 09:56:09 +0300936 return ret;
937}
938
Michal Kaziordc55e302014-07-29 12:53:36 +0300939static int ath10k_vdev_start(struct ath10k_vif *arvif)
940{
941 return ath10k_vdev_start_restart(arvif, false);
942}
943
944static int ath10k_vdev_restart(struct ath10k_vif *arvif)
945{
946 return ath10k_vdev_start_restart(arvif, true);
947}
948
Michal Kazior72654fa2014-04-08 09:56:09 +0300949static int ath10k_vdev_stop(struct ath10k_vif *arvif)
950{
951 struct ath10k *ar = arvif->ar;
952 int ret;
953
954 lockdep_assert_held(&ar->conf_mutex);
955
956 reinit_completion(&ar->vdev_setup_done);
957
958 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
959 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300961 arvif->vdev_id, ret);
962 return ret;
963 }
964
965 ret = ath10k_vdev_setup_sync(ar);
966 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200967 ath10k_warn(ar, "failed to synchronize setup for vdev %i stop: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300968 arvif->vdev_id, ret);
969 return ret;
970 }
971
Michal Kaziord6500972014-04-08 09:56:09 +0300972 WARN_ON(ar->num_started_vdevs == 0);
973
974 if (ar->num_started_vdevs != 0) {
975 ar->num_started_vdevs--;
976 ath10k_recalc_radar_detection(ar);
977 }
978
Michal Kazior72654fa2014-04-08 09:56:09 +0300979 return ret;
980}
981
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200982static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
983 struct sk_buff *bcn)
984{
985 struct ath10k *ar = arvif->ar;
986 struct ieee80211_mgmt *mgmt;
987 const u8 *p2p_ie;
988 int ret;
989
990 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
991 return 0;
992
993 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
994 return 0;
995
996 mgmt = (void *)bcn->data;
997 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
998 mgmt->u.beacon.variable,
999 bcn->len - (mgmt->u.beacon.variable -
1000 bcn->data));
1001 if (!p2p_ie)
1002 return -ENOENT;
1003
1004 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1005 if (ret) {
1006 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1007 arvif->vdev_id, ret);
1008 return ret;
1009 }
1010
1011 return 0;
1012}
1013
1014static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1015 u8 oui_type, size_t ie_offset)
1016{
1017 size_t len;
1018 const u8 *next;
1019 const u8 *end;
1020 u8 *ie;
1021
1022 if (WARN_ON(skb->len < ie_offset))
1023 return -EINVAL;
1024
1025 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1026 skb->data + ie_offset,
1027 skb->len - ie_offset);
1028 if (!ie)
1029 return -ENOENT;
1030
1031 len = ie[1] + 2;
1032 end = skb->data + skb->len;
1033 next = ie + len;
1034
1035 if (WARN_ON(next > end))
1036 return -EINVAL;
1037
1038 memmove(ie, next, end - next);
1039 skb_trim(skb, skb->len - len);
1040
1041 return 0;
1042}
1043
1044static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1045{
1046 struct ath10k *ar = arvif->ar;
1047 struct ieee80211_hw *hw = ar->hw;
1048 struct ieee80211_vif *vif = arvif->vif;
1049 struct ieee80211_mutable_offsets offs = {};
1050 struct sk_buff *bcn;
1051 int ret;
1052
1053 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1054 return 0;
1055
1056 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1057 if (!bcn) {
1058 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1059 return -EPERM;
1060 }
1061
1062 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1063 if (ret) {
1064 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1065 kfree_skb(bcn);
1066 return ret;
1067 }
1068
1069 /* P2P IE is inserted by firmware automatically (as configured above)
1070 * so remove it from the base beacon template to avoid duplicate P2P
1071 * IEs in beacon frames.
1072 */
1073 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1074 offsetof(struct ieee80211_mgmt,
1075 u.beacon.variable));
1076
1077 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1078 0, NULL, 0);
1079 kfree_skb(bcn);
1080
1081 if (ret) {
1082 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1083 ret);
1084 return ret;
1085 }
1086
1087 return 0;
1088}
1089
1090static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1091{
1092 struct ath10k *ar = arvif->ar;
1093 struct ieee80211_hw *hw = ar->hw;
1094 struct ieee80211_vif *vif = arvif->vif;
1095 struct sk_buff *prb;
1096 int ret;
1097
1098 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1099 return 0;
1100
1101 prb = ieee80211_proberesp_get(hw, vif);
1102 if (!prb) {
1103 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1104 return -EPERM;
1105 }
1106
1107 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1108 kfree_skb(prb);
1109
1110 if (ret) {
1111 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1112 ret);
1113 return ret;
1114 }
1115
1116 return 0;
1117}
1118
Kalle Valo5e3dd152013-06-12 20:52:10 +03001119static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001120 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001121{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001122 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 int ret = 0;
1124
Michal Kazior548db542013-07-05 16:15:15 +03001125 lockdep_assert_held(&arvif->ar->conf_mutex);
1126
Kalle Valo5e3dd152013-06-12 20:52:10 +03001127 if (!info->enable_beacon) {
1128 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001129
1130 arvif->is_started = false;
1131 arvif->is_up = false;
1132
Michal Kazior748afc42014-01-23 12:48:21 +01001133 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001134 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001135 spin_unlock_bh(&arvif->ar->data_lock);
1136
Kalle Valo5e3dd152013-06-12 20:52:10 +03001137 return;
1138 }
1139
1140 arvif->tx_seq_no = 0x1000;
1141
1142 ret = ath10k_vdev_start(arvif);
1143 if (ret)
1144 return;
1145
Michal Kaziorc930f742014-01-23 11:38:25 +01001146 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001147 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001148
1149 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1150 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001152 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001153 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001154 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001155 return;
1156 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001157
1158 arvif->is_started = true;
1159 arvif->is_up = true;
1160
Michal Kazior7aa7a722014-08-25 12:09:38 +02001161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162}
1163
1164static void ath10k_control_ibss(struct ath10k_vif *arvif,
1165 struct ieee80211_bss_conf *info,
1166 const u8 self_peer[ETH_ALEN])
1167{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001168 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001169 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001170 int ret = 0;
1171
Michal Kazior548db542013-07-05 16:15:15 +03001172 lockdep_assert_held(&arvif->ar->conf_mutex);
1173
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174 if (!info->ibss_joined) {
1175 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1176 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001177 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001178 self_peer, arvif->vdev_id, ret);
1179
Michal Kaziorc930f742014-01-23 11:38:25 +01001180 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001181 return;
1182
Michal Kaziorc930f742014-01-23 11:38:25 +01001183 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001184
1185 return;
1186 }
1187
1188 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001190 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001191 self_peer, arvif->vdev_id, ret);
1192 return;
1193 }
1194
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001195 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1196 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197 ATH10K_DEFAULT_ATIM);
1198 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001199 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001200 arvif->vdev_id, ret);
1201}
1202
Michal Kazior9f9b5742014-12-12 12:41:36 +01001203static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1204{
1205 struct ath10k *ar = arvif->ar;
1206 u32 param;
1207 u32 value;
1208 int ret;
1209
1210 lockdep_assert_held(&arvif->ar->conf_mutex);
1211
1212 if (arvif->u.sta.uapsd)
1213 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1214 else
1215 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1216
1217 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1218 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1219 if (ret) {
1220 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1221 value, arvif->vdev_id, ret);
1222 return ret;
1223 }
1224
1225 return 0;
1226}
1227
1228static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1229{
1230 struct ath10k *ar = arvif->ar;
1231 u32 param;
1232 u32 value;
1233 int ret;
1234
1235 lockdep_assert_held(&arvif->ar->conf_mutex);
1236
1237 if (arvif->u.sta.uapsd)
1238 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1239 else
1240 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1241
1242 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1243 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1244 param, value);
1245 if (ret) {
1246 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1247 value, arvif->vdev_id, ret);
1248 return ret;
1249 }
1250
1251 return 0;
1252}
1253
Michal Kaziorad088bf2013-10-16 15:44:46 +03001254static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001255{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001256 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001257 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001258 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259 enum wmi_sta_powersave_param param;
1260 enum wmi_sta_ps_mode psmode;
1261 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001262 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263
Michal Kazior548db542013-07-05 16:15:15 +03001264 lockdep_assert_held(&arvif->ar->conf_mutex);
1265
Michal Kaziorad088bf2013-10-16 15:44:46 +03001266 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1267 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001268
Michal Kaziorbf14e652014-12-12 12:41:38 +01001269 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270 psmode = WMI_STA_PS_MODE_ENABLED;
1271 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1272
Michal Kazior526549a2014-12-12 12:41:37 +01001273 ps_timeout = conf->dynamic_ps_timeout;
1274 if (ps_timeout == 0) {
1275 /* Firmware doesn't like 0 */
1276 ps_timeout = ieee80211_tu_to_usec(
1277 vif->bss_conf.beacon_int) / 1000;
1278 }
1279
Michal Kaziorad088bf2013-10-16 15:44:46 +03001280 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001281 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001282 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001283 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001284 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001285 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287 } else {
1288 psmode = WMI_STA_PS_MODE_DISABLED;
1289 }
1290
Michal Kazior7aa7a722014-08-25 12:09:38 +02001291 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001292 arvif->vdev_id, psmode ? "enable" : "disable");
1293
Michal Kaziorad088bf2013-10-16 15:44:46 +03001294 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1295 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001296 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001297 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001298 return ret;
1299 }
1300
1301 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302}
1303
Michal Kazior46725b152015-01-28 09:57:49 +02001304static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1305{
1306 struct ath10k *ar = arvif->ar;
1307 struct wmi_sta_keepalive_arg arg = {};
1308 int ret;
1309
1310 lockdep_assert_held(&arvif->ar->conf_mutex);
1311
1312 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1313 return 0;
1314
1315 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1316 return 0;
1317
1318 /* Some firmware revisions have a bug and ignore the `enabled` field.
1319 * Instead use the interval to disable the keepalive.
1320 */
1321 arg.vdev_id = arvif->vdev_id;
1322 arg.enabled = 1;
1323 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1324 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1325
1326 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1327 if (ret) {
1328 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1329 arvif->vdev_id, ret);
1330 return ret;
1331 }
1332
1333 return 0;
1334}
1335
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336/**********************/
1337/* Station management */
1338/**********************/
1339
Michal Kazior590922a2014-10-21 10:10:29 +03001340static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1341 struct ieee80211_vif *vif)
1342{
1343 /* Some firmware revisions have unstable STA powersave when listen
1344 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1345 * generate NullFunc frames properly even if buffered frames have been
1346 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1347 * buffered frames. Often pinging the device from AP would simply fail.
1348 *
1349 * As a workaround set it to 1.
1350 */
1351 if (vif->type == NL80211_IFTYPE_STATION)
1352 return 1;
1353
1354 return ar->hw->conf.listen_interval;
1355}
1356
Kalle Valo5e3dd152013-06-12 20:52:10 +03001357static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001358 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001360 struct wmi_peer_assoc_complete_arg *arg)
1361{
Michal Kazior590922a2014-10-21 10:10:29 +03001362 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1363
Michal Kazior548db542013-07-05 16:15:15 +03001364 lockdep_assert_held(&ar->conf_mutex);
1365
Kalle Valob25f32c2014-09-14 12:50:49 +03001366 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367 arg->vdev_id = arvif->vdev_id;
1368 arg->peer_aid = sta->aid;
1369 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001370 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001372 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373}
1374
1375static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001376 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 struct wmi_peer_assoc_complete_arg *arg)
1378{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 struct ieee80211_bss_conf *info = &vif->bss_conf;
1380 struct cfg80211_bss *bss;
1381 const u8 *rsnie = NULL;
1382 const u8 *wpaie = NULL;
1383
Michal Kazior548db542013-07-05 16:15:15 +03001384 lockdep_assert_held(&ar->conf_mutex);
1385
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1387 info->bssid, NULL, 0, 0, 0);
1388 if (bss) {
1389 const struct cfg80211_bss_ies *ies;
1390
1391 rcu_read_lock();
1392 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1393
1394 ies = rcu_dereference(bss->ies);
1395
1396 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001397 WLAN_OUI_TYPE_MICROSOFT_WPA,
1398 ies->data,
1399 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400 rcu_read_unlock();
1401 cfg80211_put_bss(ar->hw->wiphy, bss);
1402 }
1403
1404 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1405 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001406 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001407 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1408 }
1409
1410 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001411 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1413 }
1414}
1415
1416static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1417 struct ieee80211_sta *sta,
1418 struct wmi_peer_assoc_complete_arg *arg)
1419{
1420 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1421 const struct ieee80211_supported_band *sband;
1422 const struct ieee80211_rate *rates;
1423 u32 ratemask;
1424 int i;
1425
Michal Kazior548db542013-07-05 16:15:15 +03001426 lockdep_assert_held(&ar->conf_mutex);
1427
Kalle Valo5e3dd152013-06-12 20:52:10 +03001428 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1429 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1430 rates = sband->bitrates;
1431
1432 rateset->num_rates = 0;
1433
1434 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1435 if (!(ratemask & 1))
1436 continue;
1437
1438 rateset->rates[rateset->num_rates] = rates->hw_value;
1439 rateset->num_rates++;
1440 }
1441}
1442
1443static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1444 struct ieee80211_sta *sta,
1445 struct wmi_peer_assoc_complete_arg *arg)
1446{
1447 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001448 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001449 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001450
Michal Kazior548db542013-07-05 16:15:15 +03001451 lockdep_assert_held(&ar->conf_mutex);
1452
Kalle Valo5e3dd152013-06-12 20:52:10 +03001453 if (!ht_cap->ht_supported)
1454 return;
1455
1456 arg->peer_flags |= WMI_PEER_HT;
1457 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1458 ht_cap->ampdu_factor)) - 1;
1459
1460 arg->peer_mpdu_density =
1461 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1462
1463 arg->peer_ht_caps = ht_cap->cap;
1464 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1465
1466 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1467 arg->peer_flags |= WMI_PEER_LDPC;
1468
1469 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1470 arg->peer_flags |= WMI_PEER_40MHZ;
1471 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1472 }
1473
1474 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1475 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1476
1477 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1478 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1479
1480 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1481 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1482 arg->peer_flags |= WMI_PEER_STBC;
1483 }
1484
1485 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001486 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1487 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1488 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1489 arg->peer_rate_caps |= stbc;
1490 arg->peer_flags |= WMI_PEER_STBC;
1491 }
1492
Kalle Valo5e3dd152013-06-12 20:52:10 +03001493 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1494 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1495 else if (ht_cap->mcs.rx_mask[1])
1496 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1497
1498 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1499 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1500 arg->peer_ht_rates.rates[n++] = i;
1501
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001502 /*
1503 * This is a workaround for HT-enabled STAs which break the spec
1504 * and have no HT capabilities RX mask (no HT RX MCS map).
1505 *
1506 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1507 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1508 *
1509 * Firmware asserts if such situation occurs.
1510 */
1511 if (n == 0) {
1512 arg->peer_ht_rates.num_rates = 8;
1513 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1514 arg->peer_ht_rates.rates[i] = i;
1515 } else {
1516 arg->peer_ht_rates.num_rates = n;
1517 arg->peer_num_spatial_streams = sta->rx_nss;
1518 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001519
Michal Kazior7aa7a722014-08-25 12:09:38 +02001520 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001521 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001522 arg->peer_ht_rates.num_rates,
1523 arg->peer_num_spatial_streams);
1524}
1525
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001526static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1527 struct ath10k_vif *arvif,
1528 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001529{
1530 u32 uapsd = 0;
1531 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001532 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533
Michal Kazior548db542013-07-05 16:15:15 +03001534 lockdep_assert_held(&ar->conf_mutex);
1535
Kalle Valo5e3dd152013-06-12 20:52:10 +03001536 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001537 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001538 sta->uapsd_queues, sta->max_sp);
1539
Kalle Valo5e3dd152013-06-12 20:52:10 +03001540 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1541 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1542 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1543 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1544 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1545 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1546 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1547 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1548 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1549 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1550 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1551 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1552
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1554 max_sp = sta->max_sp;
1555
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001556 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1557 sta->addr,
1558 WMI_AP_PS_PEER_PARAM_UAPSD,
1559 uapsd);
1560 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001561 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001562 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001563 return ret;
1564 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001565
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001566 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1567 sta->addr,
1568 WMI_AP_PS_PEER_PARAM_MAX_SP,
1569 max_sp);
1570 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001571 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001572 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001573 return ret;
1574 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575
1576 /* TODO setup this based on STA listen interval and
1577 beacon interval. Currently we don't know
1578 sta->listen_interval - mac80211 patch required.
1579 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001580 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001581 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1582 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001583 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001584 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001585 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001586 return ret;
1587 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001589
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001590 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591}
1592
1593static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1594 struct ieee80211_sta *sta,
1595 struct wmi_peer_assoc_complete_arg *arg)
1596{
1597 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001598 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599
1600 if (!vht_cap->vht_supported)
1601 return;
1602
1603 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001604
1605 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1606 arg->peer_flags |= WMI_PEER_VHT_2G;
1607
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 arg->peer_vht_caps = vht_cap->cap;
1609
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001610 ampdu_factor = (vht_cap->cap &
1611 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1612 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1613
1614 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1615 * zero in VHT IE. Using it would result in degraded throughput.
1616 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1617 * it if VHT max_mpdu is smaller. */
1618 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1619 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1620 ampdu_factor)) - 1);
1621
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1623 arg->peer_flags |= WMI_PEER_80MHZ;
1624
1625 arg->peer_vht_rates.rx_max_rate =
1626 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1627 arg->peer_vht_rates.rx_mcs_set =
1628 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1629 arg->peer_vht_rates.tx_max_rate =
1630 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1631 arg->peer_vht_rates.tx_mcs_set =
1632 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1633
Michal Kazior7aa7a722014-08-25 12:09:38 +02001634 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001635 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636}
1637
1638static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001639 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001641 struct wmi_peer_assoc_complete_arg *arg)
1642{
Michal Kazior590922a2014-10-21 10:10:29 +03001643 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1644
Kalle Valo5e3dd152013-06-12 20:52:10 +03001645 switch (arvif->vdev_type) {
1646 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001647 if (sta->wme)
1648 arg->peer_flags |= WMI_PEER_QOS;
1649
1650 if (sta->wme && sta->uapsd_queues) {
1651 arg->peer_flags |= WMI_PEER_APSD;
1652 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1653 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001654 break;
1655 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001656 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001657 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001659 case WMI_VDEV_TYPE_IBSS:
1660 if (sta->wme)
1661 arg->peer_flags |= WMI_PEER_QOS;
1662 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001663 default:
1664 break;
1665 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001666
1667 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1668 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001669}
1670
Michal Kazior91b12082014-12-12 12:41:35 +01001671static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1672{
1673 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1674 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1675}
1676
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001678 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 struct ieee80211_sta *sta,
1680 struct wmi_peer_assoc_complete_arg *arg)
1681{
1682 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1683
Kalle Valo5e3dd152013-06-12 20:52:10 +03001684 switch (ar->hw->conf.chandef.chan->band) {
1685 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001686 if (sta->vht_cap.vht_supported) {
1687 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1688 phymode = MODE_11AC_VHT40;
1689 else
1690 phymode = MODE_11AC_VHT20;
1691 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1693 phymode = MODE_11NG_HT40;
1694 else
1695 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001696 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001698 } else {
1699 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700 }
1701
1702 break;
1703 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001704 /*
1705 * Check VHT first.
1706 */
1707 if (sta->vht_cap.vht_supported) {
1708 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1709 phymode = MODE_11AC_VHT80;
1710 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1711 phymode = MODE_11AC_VHT40;
1712 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1713 phymode = MODE_11AC_VHT20;
1714 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001715 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1716 phymode = MODE_11NA_HT40;
1717 else
1718 phymode = MODE_11NA_HT20;
1719 } else {
1720 phymode = MODE_11A;
1721 }
1722
1723 break;
1724 default:
1725 break;
1726 }
1727
Michal Kazior7aa7a722014-08-25 12:09:38 +02001728 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001729 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001730
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 arg->peer_phymode = phymode;
1732 WARN_ON(phymode == MODE_UNKNOWN);
1733}
1734
Kalle Valob9ada652013-10-16 15:44:46 +03001735static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001736 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001737 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001738 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001739{
Michal Kazior548db542013-07-05 16:15:15 +03001740 lockdep_assert_held(&ar->conf_mutex);
1741
Kalle Valob9ada652013-10-16 15:44:46 +03001742 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743
Michal Kazior590922a2014-10-21 10:10:29 +03001744 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1745 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001746 ath10k_peer_assoc_h_rates(ar, sta, arg);
1747 ath10k_peer_assoc_h_ht(ar, sta, arg);
1748 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001749 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1750 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001751
Kalle Valob9ada652013-10-16 15:44:46 +03001752 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001753}
1754
Michal Kazior90046f52014-02-14 14:45:51 +01001755static const u32 ath10k_smps_map[] = {
1756 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1757 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1758 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1759 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1760};
1761
1762static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1763 const u8 *addr,
1764 const struct ieee80211_sta_ht_cap *ht_cap)
1765{
1766 int smps;
1767
1768 if (!ht_cap->ht_supported)
1769 return 0;
1770
1771 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1772 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1773
1774 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1775 return -EINVAL;
1776
1777 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1778 WMI_PEER_SMPS_STATE,
1779 ath10k_smps_map[smps]);
1780}
1781
Michal Kazior139e1702015-02-15 16:50:42 +02001782static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1783 struct ieee80211_vif *vif,
1784 struct ieee80211_sta_vht_cap vht_cap)
1785{
1786 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1787 int ret;
1788 u32 param;
1789 u32 value;
1790
1791 if (!(ar->vht_cap_info &
1792 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1793 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1794 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1795 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1796 return 0;
1797
1798 param = ar->wmi.vdev_param->txbf;
1799 value = 0;
1800
1801 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1802 return 0;
1803
1804 /* The following logic is correct. If a remote STA advertises support
1805 * for being a beamformer then we should enable us being a beamformee.
1806 */
1807
1808 if (ar->vht_cap_info &
1809 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1810 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1811 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1812 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1813
1814 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1815 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1816 }
1817
1818 if (ar->vht_cap_info &
1819 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1820 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1821 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1822 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1823
1824 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
1825 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
1826 }
1827
1828 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
1829 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1830
1831 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
1832 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1833
1834 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
1835 if (ret) {
1836 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
1837 value, ret);
1838 return ret;
1839 }
1840
1841 return 0;
1842}
1843
Kalle Valo5e3dd152013-06-12 20:52:10 +03001844/* can be called only in mac80211 callbacks due to `key_count` usage */
1845static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1846 struct ieee80211_vif *vif,
1847 struct ieee80211_bss_conf *bss_conf)
1848{
1849 struct ath10k *ar = hw->priv;
1850 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001851 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001852 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001853 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001854 struct ieee80211_sta *ap_sta;
1855 int ret;
1856
Michal Kazior548db542013-07-05 16:15:15 +03001857 lockdep_assert_held(&ar->conf_mutex);
1858
Michal Kazior077efc82014-10-21 10:10:29 +03001859 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1860 arvif->vdev_id, arvif->bssid, arvif->aid);
1861
Kalle Valo5e3dd152013-06-12 20:52:10 +03001862 rcu_read_lock();
1863
1864 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1865 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001866 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001867 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001868 rcu_read_unlock();
1869 return;
1870 }
1871
Michal Kazior90046f52014-02-14 14:45:51 +01001872 /* ap_sta must be accessed only within rcu section which must be left
1873 * before calling ath10k_setup_peer_smps() which might sleep. */
1874 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001875 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01001876
Michal Kazior590922a2014-10-21 10:10:29 +03001877 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001879 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001880 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881 rcu_read_unlock();
1882 return;
1883 }
1884
1885 rcu_read_unlock();
1886
Kalle Valob9ada652013-10-16 15:44:46 +03001887 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1888 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001889 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001890 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001891 return;
1892 }
1893
Michal Kazior90046f52014-02-14 14:45:51 +01001894 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001896 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001897 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001898 return;
1899 }
1900
Michal Kazior139e1702015-02-15 16:50:42 +02001901 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1902 if (ret) {
1903 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
1904 arvif->vdev_id, bss_conf->bssid, ret);
1905 return;
1906 }
1907
Michal Kazior7aa7a722014-08-25 12:09:38 +02001908 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001909 "mac vdev %d up (associated) bssid %pM aid %d\n",
1910 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1911
Michal Kazior077efc82014-10-21 10:10:29 +03001912 WARN_ON(arvif->is_up);
1913
Michal Kaziorc930f742014-01-23 11:38:25 +01001914 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001915 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001916
1917 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1918 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001919 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001920 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001921 return;
1922 }
1923
1924 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01001925
1926 /* Workaround: Some firmware revisions (tested with qca6174
1927 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
1928 * poked with peer param command.
1929 */
1930 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
1931 WMI_PEER_DUMMY_VAR, 1);
1932 if (ret) {
1933 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
1934 arvif->bssid, arvif->vdev_id, ret);
1935 return;
1936 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937}
1938
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1940 struct ieee80211_vif *vif)
1941{
1942 struct ath10k *ar = hw->priv;
1943 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02001944 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945 int ret;
1946
Michal Kazior548db542013-07-05 16:15:15 +03001947 lockdep_assert_held(&ar->conf_mutex);
1948
Michal Kazior077efc82014-10-21 10:10:29 +03001949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1950 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001951
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001953 if (ret)
1954 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1955 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001956
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001957 arvif->def_wep_key_idx = -1;
1958
Michal Kazior139e1702015-02-15 16:50:42 +02001959 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1960 if (ret) {
1961 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
1962 arvif->vdev_id, ret);
1963 return;
1964 }
1965
Michal Kaziorc930f742014-01-23 11:38:25 +01001966 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967}
1968
Michal Kazior590922a2014-10-21 10:10:29 +03001969static int ath10k_station_assoc(struct ath10k *ar,
1970 struct ieee80211_vif *vif,
1971 struct ieee80211_sta *sta,
1972 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001973{
Michal Kazior590922a2014-10-21 10:10:29 +03001974 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001975 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 int ret = 0;
1977
Michal Kazior548db542013-07-05 16:15:15 +03001978 lockdep_assert_held(&ar->conf_mutex);
1979
Michal Kazior590922a2014-10-21 10:10:29 +03001980 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001981 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001982 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001983 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001984 return ret;
1985 }
1986
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001987 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001988 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1989 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001990 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001991 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992 return ret;
1993 }
1994
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001995 /* Re-assoc is run only to update supported rates for given station. It
1996 * doesn't make much sense to reconfigure the peer completely.
1997 */
1998 if (!reassoc) {
1999 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2000 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002001 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002002 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002003 arvif->vdev_id, ret);
2004 return ret;
2005 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002006
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002007 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2008 if (ret) {
2009 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2010 sta->addr, arvif->vdev_id, ret);
2011 return ret;
2012 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002014 if (!sta->wme) {
2015 arvif->num_legacy_stations++;
2016 ret = ath10k_recalc_rtscts_prot(arvif);
2017 if (ret) {
2018 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2019 arvif->vdev_id, ret);
2020 return ret;
2021 }
2022 }
2023
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002024 /* Plumb cached keys only for static WEP */
2025 if (arvif->def_wep_key_idx != -1) {
2026 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2027 if (ret) {
2028 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2029 arvif->vdev_id, ret);
2030 return ret;
2031 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002032 }
2033 }
2034
Kalle Valo5e3dd152013-06-12 20:52:10 +03002035 return ret;
2036}
2037
Michal Kazior590922a2014-10-21 10:10:29 +03002038static int ath10k_station_disassoc(struct ath10k *ar,
2039 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002040 struct ieee80211_sta *sta)
2041{
Michal Kazior590922a2014-10-21 10:10:29 +03002042 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 int ret = 0;
2044
2045 lockdep_assert_held(&ar->conf_mutex);
2046
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002047 if (!sta->wme) {
2048 arvif->num_legacy_stations--;
2049 ret = ath10k_recalc_rtscts_prot(arvif);
2050 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002051 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002052 arvif->vdev_id, ret);
2053 return ret;
2054 }
2055 }
2056
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002059 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002060 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002061 return ret;
2062 }
2063
2064 return ret;
2065}
2066
2067/**************/
2068/* Regulatory */
2069/**************/
2070
2071static int ath10k_update_channel_list(struct ath10k *ar)
2072{
2073 struct ieee80211_hw *hw = ar->hw;
2074 struct ieee80211_supported_band **bands;
2075 enum ieee80211_band band;
2076 struct ieee80211_channel *channel;
2077 struct wmi_scan_chan_list_arg arg = {0};
2078 struct wmi_channel_arg *ch;
2079 bool passive;
2080 int len;
2081 int ret;
2082 int i;
2083
Michal Kazior548db542013-07-05 16:15:15 +03002084 lockdep_assert_held(&ar->conf_mutex);
2085
Kalle Valo5e3dd152013-06-12 20:52:10 +03002086 bands = hw->wiphy->bands;
2087 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2088 if (!bands[band])
2089 continue;
2090
2091 for (i = 0; i < bands[band]->n_channels; i++) {
2092 if (bands[band]->channels[i].flags &
2093 IEEE80211_CHAN_DISABLED)
2094 continue;
2095
2096 arg.n_channels++;
2097 }
2098 }
2099
2100 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2101 arg.channels = kzalloc(len, GFP_KERNEL);
2102 if (!arg.channels)
2103 return -ENOMEM;
2104
2105 ch = arg.channels;
2106 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2107 if (!bands[band])
2108 continue;
2109
2110 for (i = 0; i < bands[band]->n_channels; i++) {
2111 channel = &bands[band]->channels[i];
2112
2113 if (channel->flags & IEEE80211_CHAN_DISABLED)
2114 continue;
2115
2116 ch->allow_ht = true;
2117
2118 /* FIXME: when should we really allow VHT? */
2119 ch->allow_vht = true;
2120
2121 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002122 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123
2124 ch->ht40plus =
2125 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2126
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002127 ch->chan_radar =
2128 !!(channel->flags & IEEE80211_CHAN_RADAR);
2129
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002130 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131 ch->passive = passive;
2132
2133 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002134 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002135 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002136 ch->max_power = channel->max_power * 2;
2137 ch->max_reg_power = channel->max_reg_power * 2;
2138 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002139 ch->reg_class_id = 0; /* FIXME */
2140
2141 /* FIXME: why use only legacy modes, why not any
2142 * HT/VHT modes? Would that even make any
2143 * difference? */
2144 if (channel->band == IEEE80211_BAND_2GHZ)
2145 ch->mode = MODE_11G;
2146 else
2147 ch->mode = MODE_11A;
2148
2149 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2150 continue;
2151
Michal Kazior7aa7a722014-08-25 12:09:38 +02002152 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002153 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2154 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155 ch->freq, ch->max_power, ch->max_reg_power,
2156 ch->max_antenna_gain, ch->mode);
2157
2158 ch++;
2159 }
2160 }
2161
2162 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2163 kfree(arg.channels);
2164
2165 return ret;
2166}
2167
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002168static enum wmi_dfs_region
2169ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2170{
2171 switch (dfs_region) {
2172 case NL80211_DFS_UNSET:
2173 return WMI_UNINIT_DFS_DOMAIN;
2174 case NL80211_DFS_FCC:
2175 return WMI_FCC_DFS_DOMAIN;
2176 case NL80211_DFS_ETSI:
2177 return WMI_ETSI_DFS_DOMAIN;
2178 case NL80211_DFS_JP:
2179 return WMI_MKK4_DFS_DOMAIN;
2180 }
2181 return WMI_UNINIT_DFS_DOMAIN;
2182}
2183
Michal Kaziorf7843d72013-07-16 09:38:52 +02002184static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002188 enum wmi_dfs_region wmi_dfs_reg;
2189 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190
Michal Kaziorf7843d72013-07-16 09:38:52 +02002191 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192
2193 ret = ath10k_update_channel_list(ar);
2194 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002195 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002196
2197 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002198
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002199 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2200 nl_dfs_reg = ar->dfs_detector->region;
2201 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2202 } else {
2203 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2204 }
2205
Kalle Valo5e3dd152013-06-12 20:52:10 +03002206 /* Target allows setting up per-band regdomain but ath_common provides
2207 * a combined one only */
2208 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002209 regpair->reg_domain,
2210 regpair->reg_domain, /* 2ghz */
2211 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002212 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002213 regpair->reg_5ghz_ctl,
2214 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002216 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002217}
Michal Kazior548db542013-07-05 16:15:15 +03002218
Michal Kaziorf7843d72013-07-16 09:38:52 +02002219static void ath10k_reg_notifier(struct wiphy *wiphy,
2220 struct regulatory_request *request)
2221{
2222 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2223 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002224 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002225
2226 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2227
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002228 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002229 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002230 request->dfs_region);
2231 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2232 request->dfs_region);
2233 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002234 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002235 request->dfs_region);
2236 }
2237
Michal Kaziorf7843d72013-07-16 09:38:52 +02002238 mutex_lock(&ar->conf_mutex);
2239 if (ar->state == ATH10K_STATE_ON)
2240 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002241 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242}
2243
2244/***************/
2245/* TX handlers */
2246/***************/
2247
Michal Kazior42c3aa62013-10-02 11:03:38 +02002248static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2249{
2250 if (ieee80211_is_mgmt(hdr->frame_control))
2251 return HTT_DATA_TX_EXT_TID_MGMT;
2252
2253 if (!ieee80211_is_data_qos(hdr->frame_control))
2254 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2255
2256 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2257 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2258
2259 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2260}
2261
Michal Kazior2b37c292014-09-02 11:00:22 +03002262static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002263{
Michal Kazior2b37c292014-09-02 11:00:22 +03002264 if (vif)
2265 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002266
Michal Kazior1bbc0972014-04-08 09:45:47 +03002267 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002268 return ar->monitor_vdev_id;
2269
Michal Kazior7aa7a722014-08-25 12:09:38 +02002270 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002271 return 0;
2272}
2273
Michal Kazior4b604552014-07-21 21:03:09 +03002274/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2275 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 */
Michal Kazior4b604552014-07-21 21:03:09 +03002277static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002278{
2279 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002280 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 u8 *qos_ctl;
2282
2283 if (!ieee80211_is_data_qos(hdr->frame_control))
2284 return;
2285
2286 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002287 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2288 skb->data, (void *)qos_ctl - (void *)skb->data);
2289 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002290
2291 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2292 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2293 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2294 * it is safe to downgrade to NullFunc.
2295 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002296 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002297 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2298 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2299 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2300 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301}
2302
Michal Kazior4b604552014-07-21 21:03:09 +03002303static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2304 struct ieee80211_vif *vif,
2305 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306{
2307 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2309
2310 /* This is case only for P2P_GO */
2311 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2312 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2313 return;
2314
2315 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2316 spin_lock_bh(&ar->data_lock);
2317 if (arvif->u.ap.noa_data)
2318 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2319 GFP_ATOMIC))
2320 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2321 arvif->u.ap.noa_data,
2322 arvif->u.ap.noa_len);
2323 spin_unlock_bh(&ar->data_lock);
2324 }
2325}
2326
Michal Kazior8d6d3622014-11-24 14:58:31 +01002327static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2328{
2329 /* FIXME: Not really sure since when the behaviour changed. At some
2330 * point new firmware stopped requiring creation of peer entries for
2331 * offchannel tx (and actually creating them causes issues with wmi-htc
2332 * tx credit replenishment and reliability). Assuming it's at least 3.4
2333 * because that's when the `freq` was introduced to TX_FRM HTT command.
2334 */
2335 return !(ar->htt.target_version_major >= 3 &&
2336 ar->htt.target_version_minor >= 4);
2337}
2338
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2340{
2341 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002342 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343
Michal Kazior961d4c32013-08-09 10:13:34 +02002344 if (ar->htt.target_version_major >= 3) {
2345 /* Since HTT 3.0 there is no separate mgmt tx command */
2346 ret = ath10k_htt_tx(&ar->htt, skb);
2347 goto exit;
2348 }
2349
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002350 if (ieee80211_is_mgmt(hdr->frame_control)) {
2351 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2352 ar->fw_features)) {
2353 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2354 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002355 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002356 ret = -EBUSY;
2357 goto exit;
2358 }
2359
2360 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2361 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2362 } else {
2363 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2364 }
2365 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2366 ar->fw_features) &&
2367 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368 /* FW does not report tx status properly for NullFunc frames
2369 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002370 * those frames when it detects link/beacon loss and depends
2371 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002372 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002373 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002374 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002375 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376
Michal Kazior961d4c32013-08-09 10:13:34 +02002377exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002379 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2380 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002381 ieee80211_free_txskb(ar->hw, skb);
2382 }
2383}
2384
2385void ath10k_offchan_tx_purge(struct ath10k *ar)
2386{
2387 struct sk_buff *skb;
2388
2389 for (;;) {
2390 skb = skb_dequeue(&ar->offchan_tx_queue);
2391 if (!skb)
2392 break;
2393
2394 ieee80211_free_txskb(ar->hw, skb);
2395 }
2396}
2397
2398void ath10k_offchan_tx_work(struct work_struct *work)
2399{
2400 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2401 struct ath10k_peer *peer;
2402 struct ieee80211_hdr *hdr;
2403 struct sk_buff *skb;
2404 const u8 *peer_addr;
2405 int vdev_id;
2406 int ret;
2407
2408 /* FW requirement: We must create a peer before FW will send out
2409 * an offchannel frame. Otherwise the frame will be stuck and
2410 * never transmitted. We delete the peer upon tx completion.
2411 * It is unlikely that a peer for offchannel tx will already be
2412 * present. However it may be in some rare cases so account for that.
2413 * Otherwise we might remove a legitimate peer and break stuff. */
2414
2415 for (;;) {
2416 skb = skb_dequeue(&ar->offchan_tx_queue);
2417 if (!skb)
2418 break;
2419
2420 mutex_lock(&ar->conf_mutex);
2421
Michal Kazior7aa7a722014-08-25 12:09:38 +02002422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002423 skb);
2424
2425 hdr = (struct ieee80211_hdr *)skb->data;
2426 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002427 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002428
2429 spin_lock_bh(&ar->data_lock);
2430 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2431 spin_unlock_bh(&ar->data_lock);
2432
2433 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002434 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002435 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002436 peer_addr, vdev_id);
2437
2438 if (!peer) {
2439 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2440 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002441 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002442 peer_addr, vdev_id, ret);
2443 }
2444
2445 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002446 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002447 ar->offchan_tx_skb = skb;
2448 spin_unlock_bh(&ar->data_lock);
2449
2450 ath10k_tx_htt(ar, skb);
2451
2452 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2453 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002454 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002455 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456 skb);
2457
2458 if (!peer) {
2459 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2460 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002461 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002462 peer_addr, vdev_id, ret);
2463 }
2464
2465 mutex_unlock(&ar->conf_mutex);
2466 }
2467}
2468
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002469void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2470{
2471 struct sk_buff *skb;
2472
2473 for (;;) {
2474 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2475 if (!skb)
2476 break;
2477
2478 ieee80211_free_txskb(ar->hw, skb);
2479 }
2480}
2481
2482void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2483{
2484 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2485 struct sk_buff *skb;
2486 int ret;
2487
2488 for (;;) {
2489 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2490 if (!skb)
2491 break;
2492
2493 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002496 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002497 ieee80211_free_txskb(ar->hw, skb);
2498 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002499 }
2500}
2501
Kalle Valo5e3dd152013-06-12 20:52:10 +03002502/************/
2503/* Scanning */
2504/************/
2505
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002506void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002508 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002510 switch (ar->scan.state) {
2511 case ATH10K_SCAN_IDLE:
2512 break;
2513 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002514 if (ar->scan.is_roc)
2515 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002516 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002517 case ATH10K_SCAN_ABORTING:
2518 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002519 ieee80211_scan_completed(ar->hw,
2520 (ar->scan.state ==
2521 ATH10K_SCAN_ABORTING));
2522 /* fall through */
2523 case ATH10K_SCAN_STARTING:
2524 ar->scan.state = ATH10K_SCAN_IDLE;
2525 ar->scan_channel = NULL;
2526 ath10k_offchan_tx_purge(ar);
2527 cancel_delayed_work(&ar->scan.timeout);
2528 complete_all(&ar->scan.completed);
2529 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002530 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002531}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002532
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002533void ath10k_scan_finish(struct ath10k *ar)
2534{
2535 spin_lock_bh(&ar->data_lock);
2536 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002537 spin_unlock_bh(&ar->data_lock);
2538}
2539
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002540static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002541{
2542 struct wmi_stop_scan_arg arg = {
2543 .req_id = 1, /* FIXME */
2544 .req_type = WMI_SCAN_STOP_ONE,
2545 .u.scan_id = ATH10K_SCAN_ID,
2546 };
2547 int ret;
2548
2549 lockdep_assert_held(&ar->conf_mutex);
2550
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551 ret = ath10k_wmi_stop_scan(ar, &arg);
2552 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002553 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002554 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555 }
2556
Kalle Valo5e3dd152013-06-12 20:52:10 +03002557 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002558 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002559 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002560 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002561 } else if (ret > 0) {
2562 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002563 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002564
2565out:
2566 /* Scan state should be updated upon scan completion but in case
2567 * firmware fails to deliver the event (for whatever reason) it is
2568 * desired to clean up scan state anyway. Firmware may have just
2569 * dropped the scan completion event delivery due to transport pipe
2570 * being overflown with data and/or it can recover on its own before
2571 * next scan request is submitted.
2572 */
2573 spin_lock_bh(&ar->data_lock);
2574 if (ar->scan.state != ATH10K_SCAN_IDLE)
2575 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576 spin_unlock_bh(&ar->data_lock);
2577
2578 return ret;
2579}
2580
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002581static void ath10k_scan_abort(struct ath10k *ar)
2582{
2583 int ret;
2584
2585 lockdep_assert_held(&ar->conf_mutex);
2586
2587 spin_lock_bh(&ar->data_lock);
2588
2589 switch (ar->scan.state) {
2590 case ATH10K_SCAN_IDLE:
2591 /* This can happen if timeout worker kicked in and called
2592 * abortion while scan completion was being processed.
2593 */
2594 break;
2595 case ATH10K_SCAN_STARTING:
2596 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002597 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002598 ath10k_scan_state_str(ar->scan.state),
2599 ar->scan.state);
2600 break;
2601 case ATH10K_SCAN_RUNNING:
2602 ar->scan.state = ATH10K_SCAN_ABORTING;
2603 spin_unlock_bh(&ar->data_lock);
2604
2605 ret = ath10k_scan_stop(ar);
2606 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002607 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002608
2609 spin_lock_bh(&ar->data_lock);
2610 break;
2611 }
2612
2613 spin_unlock_bh(&ar->data_lock);
2614}
2615
2616void ath10k_scan_timeout_work(struct work_struct *work)
2617{
2618 struct ath10k *ar = container_of(work, struct ath10k,
2619 scan.timeout.work);
2620
2621 mutex_lock(&ar->conf_mutex);
2622 ath10k_scan_abort(ar);
2623 mutex_unlock(&ar->conf_mutex);
2624}
2625
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626static int ath10k_start_scan(struct ath10k *ar,
2627 const struct wmi_start_scan_arg *arg)
2628{
2629 int ret;
2630
2631 lockdep_assert_held(&ar->conf_mutex);
2632
2633 ret = ath10k_wmi_start_scan(ar, arg);
2634 if (ret)
2635 return ret;
2636
Kalle Valo5e3dd152013-06-12 20:52:10 +03002637 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2638 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002639 ret = ath10k_scan_stop(ar);
2640 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002641 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002642
2643 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644 }
2645
Ben Greear2f9eec02015-02-15 16:50:38 +02002646 /* If we failed to start the scan, return error code at
2647 * this point. This is probably due to some issue in the
2648 * firmware, but no need to wedge the driver due to that...
2649 */
2650 spin_lock_bh(&ar->data_lock);
2651 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2652 spin_unlock_bh(&ar->data_lock);
2653 return -EINVAL;
2654 }
2655 spin_unlock_bh(&ar->data_lock);
2656
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002657 /* Add a 200ms margin to account for event/command processing */
2658 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2659 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660 return 0;
2661}
2662
2663/**********************/
2664/* mac80211 callbacks */
2665/**********************/
2666
2667static void ath10k_tx(struct ieee80211_hw *hw,
2668 struct ieee80211_tx_control *control,
2669 struct sk_buff *skb)
2670{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002671 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002672 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2673 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002674 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002675
2676 /* We should disable CCK RATE due to P2P */
2677 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002678 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679
Michal Kazior4b604552014-07-21 21:03:09 +03002680 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2681 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002682 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002684 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002685 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2686 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002687 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2688 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002689 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690
Kalle Valo5e3dd152013-06-12 20:52:10 +03002691 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2692 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002693 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002694 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 spin_unlock_bh(&ar->data_lock);
2696
Michal Kazior8d6d3622014-11-24 14:58:31 +01002697 if (ath10k_mac_need_offchan_tx_work(ar)) {
2698 ATH10K_SKB_CB(skb)->htt.freq = 0;
2699 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700
Michal Kazior8d6d3622014-11-24 14:58:31 +01002701 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2702 skb);
2703
2704 skb_queue_tail(&ar->offchan_tx_queue, skb);
2705 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2706 return;
2707 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708 }
2709
2710 ath10k_tx_htt(ar, skb);
2711}
2712
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002713/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002714void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002715{
2716 /* make sure rcu-protected mac80211 tx path itself is drained */
2717 synchronize_net();
2718
2719 ath10k_offchan_tx_purge(ar);
2720 ath10k_mgmt_over_wmi_tx_purge(ar);
2721
2722 cancel_work_sync(&ar->offchan_tx_work);
2723 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2724}
2725
Michal Kazioraffd3212013-07-16 09:54:35 +02002726void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002727{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002728 struct ath10k_vif *arvif;
2729
Michal Kazior818bdd12013-07-16 09:38:57 +02002730 lockdep_assert_held(&ar->conf_mutex);
2731
Michal Kazior19337472014-08-28 12:58:16 +02002732 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2733 ar->filter_flags = 0;
2734 ar->monitor = false;
2735
2736 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002737 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002738
2739 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002740
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002741 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002742 ath10k_peer_cleanup_all(ar);
2743 ath10k_core_stop(ar);
2744 ath10k_hif_power_down(ar);
2745
2746 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002747 list_for_each_entry(arvif, &ar->arvifs, list)
2748 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002749 spin_unlock_bh(&ar->data_lock);
2750}
2751
Ben Greear46acf7b2014-05-16 17:15:38 +03002752static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2753{
2754 struct ath10k *ar = hw->priv;
2755
2756 mutex_lock(&ar->conf_mutex);
2757
2758 if (ar->cfg_tx_chainmask) {
2759 *tx_ant = ar->cfg_tx_chainmask;
2760 *rx_ant = ar->cfg_rx_chainmask;
2761 } else {
2762 *tx_ant = ar->supp_tx_chainmask;
2763 *rx_ant = ar->supp_rx_chainmask;
2764 }
2765
2766 mutex_unlock(&ar->conf_mutex);
2767
2768 return 0;
2769}
2770
Ben Greear5572a952014-11-24 16:22:10 +02002771static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2772{
2773 /* It is not clear that allowing gaps in chainmask
2774 * is helpful. Probably it will not do what user
2775 * is hoping for, so warn in that case.
2776 */
2777 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2778 return;
2779
2780 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2781 dbg, cm);
2782}
2783
Ben Greear46acf7b2014-05-16 17:15:38 +03002784static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2785{
2786 int ret;
2787
2788 lockdep_assert_held(&ar->conf_mutex);
2789
Ben Greear5572a952014-11-24 16:22:10 +02002790 ath10k_check_chain_mask(ar, tx_ant, "tx");
2791 ath10k_check_chain_mask(ar, rx_ant, "rx");
2792
Ben Greear46acf7b2014-05-16 17:15:38 +03002793 ar->cfg_tx_chainmask = tx_ant;
2794 ar->cfg_rx_chainmask = rx_ant;
2795
2796 if ((ar->state != ATH10K_STATE_ON) &&
2797 (ar->state != ATH10K_STATE_RESTARTED))
2798 return 0;
2799
2800 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2801 tx_ant);
2802 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002803 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002804 ret, tx_ant);
2805 return ret;
2806 }
2807
2808 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2809 rx_ant);
2810 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002811 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002812 ret, rx_ant);
2813 return ret;
2814 }
2815
2816 return 0;
2817}
2818
2819static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2820{
2821 struct ath10k *ar = hw->priv;
2822 int ret;
2823
2824 mutex_lock(&ar->conf_mutex);
2825 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2826 mutex_unlock(&ar->conf_mutex);
2827 return ret;
2828}
2829
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830static int ath10k_start(struct ieee80211_hw *hw)
2831{
2832 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002833 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002834
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002835 /*
2836 * This makes sense only when restarting hw. It is harmless to call
2837 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2838 * commands will be submitted while restarting.
2839 */
2840 ath10k_drain_tx(ar);
2841
Michal Kazior548db542013-07-05 16:15:15 +03002842 mutex_lock(&ar->conf_mutex);
2843
Michal Kaziorc5058f52014-05-26 12:46:03 +03002844 switch (ar->state) {
2845 case ATH10K_STATE_OFF:
2846 ar->state = ATH10K_STATE_ON;
2847 break;
2848 case ATH10K_STATE_RESTARTING:
2849 ath10k_halt(ar);
2850 ar->state = ATH10K_STATE_RESTARTED;
2851 break;
2852 case ATH10K_STATE_ON:
2853 case ATH10K_STATE_RESTARTED:
2854 case ATH10K_STATE_WEDGED:
2855 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002856 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002857 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002858 case ATH10K_STATE_UTF:
2859 ret = -EBUSY;
2860 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002861 }
2862
2863 ret = ath10k_hif_power_up(ar);
2864 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002865 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002866 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002867 }
2868
Kalle Valo43d2a302014-09-10 18:23:30 +03002869 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002870 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002871 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002872 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002873 }
2874
Bartosz Markowski226a3392013-09-26 17:47:16 +02002875 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002876 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002877 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002878 goto err_core_stop;
2879 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002880
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002881 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002882 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002883 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002884 goto err_core_stop;
2885 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002886
Ben Greear46acf7b2014-05-16 17:15:38 +03002887 if (ar->cfg_tx_chainmask)
2888 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2889 ar->cfg_rx_chainmask);
2890
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002891 /*
2892 * By default FW set ARP frames ac to voice (6). In that case ARP
2893 * exchange is not working properly for UAPSD enabled AP. ARP requests
2894 * which arrives with access category 0 are processed by network stack
2895 * and send back with access category 0, but FW changes access category
2896 * to 6. Set ARP frames access category to best effort (0) solves
2897 * this problem.
2898 */
2899
2900 ret = ath10k_wmi_pdev_set_param(ar,
2901 ar->wmi.pdev_param->arp_ac_override, 0);
2902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002903 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002904 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002905 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002906 }
2907
Michal Kaziord6500972014-04-08 09:56:09 +03002908 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002909 ath10k_regd_update(ar);
2910
Simon Wunderlich855aed12014-08-02 09:12:54 +03002911 ath10k_spectral_start(ar);
2912
Michal Kaziorae254432014-05-26 12:46:02 +03002913 mutex_unlock(&ar->conf_mutex);
2914 return 0;
2915
2916err_core_stop:
2917 ath10k_core_stop(ar);
2918
2919err_power_down:
2920 ath10k_hif_power_down(ar);
2921
2922err_off:
2923 ar->state = ATH10K_STATE_OFF;
2924
2925err:
Michal Kazior548db542013-07-05 16:15:15 +03002926 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002927 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928}
2929
2930static void ath10k_stop(struct ieee80211_hw *hw)
2931{
2932 struct ath10k *ar = hw->priv;
2933
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002934 ath10k_drain_tx(ar);
2935
Michal Kazior548db542013-07-05 16:15:15 +03002936 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002937 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002938 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002939 ar->state = ATH10K_STATE_OFF;
2940 }
Michal Kazior548db542013-07-05 16:15:15 +03002941 mutex_unlock(&ar->conf_mutex);
2942
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002943 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002944 cancel_work_sync(&ar->restart_work);
2945}
2946
Michal Kaziorad088bf2013-10-16 15:44:46 +03002947static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002948{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002949 struct ath10k_vif *arvif;
2950 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002951
2952 lockdep_assert_held(&ar->conf_mutex);
2953
Michal Kaziorad088bf2013-10-16 15:44:46 +03002954 list_for_each_entry(arvif, &ar->arvifs, list) {
2955 ret = ath10k_mac_vif_setup_ps(arvif);
2956 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002957 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002958 break;
2959 }
2960 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002961
Michal Kaziorad088bf2013-10-16 15:44:46 +03002962 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002963}
2964
Michal Kaziorc930f742014-01-23 11:38:25 +01002965static const char *chandef_get_width(enum nl80211_chan_width width)
2966{
2967 switch (width) {
2968 case NL80211_CHAN_WIDTH_20_NOHT:
2969 return "20 (noht)";
2970 case NL80211_CHAN_WIDTH_20:
2971 return "20";
2972 case NL80211_CHAN_WIDTH_40:
2973 return "40";
2974 case NL80211_CHAN_WIDTH_80:
2975 return "80";
2976 case NL80211_CHAN_WIDTH_80P80:
2977 return "80+80";
2978 case NL80211_CHAN_WIDTH_160:
2979 return "160";
2980 case NL80211_CHAN_WIDTH_5:
2981 return "5";
2982 case NL80211_CHAN_WIDTH_10:
2983 return "10";
2984 }
2985 return "?";
2986}
2987
2988static void ath10k_config_chan(struct ath10k *ar)
2989{
2990 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002991 int ret;
2992
2993 lockdep_assert_held(&ar->conf_mutex);
2994
Michal Kazior7aa7a722014-08-25 12:09:38 +02002995 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002996 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2997 ar->chandef.chan->center_freq,
2998 ar->chandef.center_freq1,
2999 ar->chandef.center_freq2,
3000 chandef_get_width(ar->chandef.width));
3001
3002 /* First stop monitor interface. Some FW versions crash if there's a
3003 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003004 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003005 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003006
3007 list_for_each_entry(arvif, &ar->arvifs, list) {
3008 if (!arvif->is_started)
3009 continue;
3010
Michal Kaziordc55e302014-07-29 12:53:36 +03003011 if (!arvif->is_up)
3012 continue;
3013
Michal Kaziorc930f742014-01-23 11:38:25 +01003014 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3015 continue;
3016
Michal Kaziordc55e302014-07-29 12:53:36 +03003017 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003018 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003019 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003020 arvif->vdev_id, ret);
3021 continue;
3022 }
3023 }
3024
Michal Kaziordc55e302014-07-29 12:53:36 +03003025 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003026
3027 list_for_each_entry(arvif, &ar->arvifs, list) {
3028 if (!arvif->is_started)
3029 continue;
3030
3031 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3032 continue;
3033
Michal Kaziordc55e302014-07-29 12:53:36 +03003034 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003035 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003036 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003037 arvif->vdev_id, ret);
3038 continue;
3039 }
3040
3041 if (!arvif->is_up)
3042 continue;
3043
3044 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3045 arvif->bssid);
3046 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003047 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003048 arvif->vdev_id, ret);
3049 continue;
3050 }
3051 }
3052
Michal Kazior19337472014-08-28 12:58:16 +02003053 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003054}
3055
Michal Kazior7d9d5582014-10-21 10:40:15 +03003056static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3057{
3058 int ret;
3059 u32 param;
3060
3061 lockdep_assert_held(&ar->conf_mutex);
3062
3063 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3064
3065 param = ar->wmi.pdev_param->txpower_limit2g;
3066 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3067 if (ret) {
3068 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3069 txpower, ret);
3070 return ret;
3071 }
3072
3073 param = ar->wmi.pdev_param->txpower_limit5g;
3074 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3075 if (ret) {
3076 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3077 txpower, ret);
3078 return ret;
3079 }
3080
3081 return 0;
3082}
3083
3084static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3085{
3086 struct ath10k_vif *arvif;
3087 int ret, txpower = -1;
3088
3089 lockdep_assert_held(&ar->conf_mutex);
3090
3091 list_for_each_entry(arvif, &ar->arvifs, list) {
3092 WARN_ON(arvif->txpower < 0);
3093
3094 if (txpower == -1)
3095 txpower = arvif->txpower;
3096 else
3097 txpower = min(txpower, arvif->txpower);
3098 }
3099
3100 if (WARN_ON(txpower == -1))
3101 return -EINVAL;
3102
3103 ret = ath10k_mac_txpower_setup(ar, txpower);
3104 if (ret) {
3105 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3106 txpower, ret);
3107 return ret;
3108 }
3109
3110 return 0;
3111}
3112
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3114{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115 struct ath10k *ar = hw->priv;
3116 struct ieee80211_conf *conf = &hw->conf;
3117 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003118
3119 mutex_lock(&ar->conf_mutex);
3120
3121 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003122 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003123 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003124 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003125 conf->chandef.chan->flags,
3126 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003127
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128 spin_lock_bh(&ar->data_lock);
3129 ar->rx_channel = conf->chandef.chan;
3130 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003131
Michal Kaziord6500972014-04-08 09:56:09 +03003132 ar->radar_enabled = conf->radar_enabled;
3133 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003134
3135 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3136 ar->chandef = conf->chandef;
3137 ath10k_config_chan(ar);
3138 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139 }
3140
Michal Kazioraffd3212013-07-16 09:54:35 +02003141 if (changed & IEEE80211_CONF_CHANGE_PS)
3142 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003143
3144 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003145 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3146 ret = ath10k_monitor_recalc(ar);
3147 if (ret)
3148 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003149 }
3150
3151 mutex_unlock(&ar->conf_mutex);
3152 return ret;
3153}
3154
Ben Greear5572a952014-11-24 16:22:10 +02003155static u32 get_nss_from_chainmask(u16 chain_mask)
3156{
3157 if ((chain_mask & 0x15) == 0x15)
3158 return 4;
3159 else if ((chain_mask & 0x7) == 0x7)
3160 return 3;
3161 else if ((chain_mask & 0x3) == 0x3)
3162 return 2;
3163 return 1;
3164}
3165
Kalle Valo5e3dd152013-06-12 20:52:10 +03003166/*
3167 * TODO:
3168 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3169 * because we will send mgmt frames without CCK. This requirement
3170 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3171 * in the TX packet.
3172 */
3173static int ath10k_add_interface(struct ieee80211_hw *hw,
3174 struct ieee80211_vif *vif)
3175{
3176 struct ath10k *ar = hw->priv;
3177 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3178 enum wmi_sta_powersave_param param;
3179 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003180 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003182 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003183
Johannes Berg848955c2014-11-11 12:48:42 +01003184 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3185
Kalle Valo5e3dd152013-06-12 20:52:10 +03003186 mutex_lock(&ar->conf_mutex);
3187
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003188 memset(arvif, 0, sizeof(*arvif));
3189
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 arvif->ar = ar;
3191 arvif->vif = vif;
3192
Ben Greeare63b33f2013-10-22 14:54:14 -07003193 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003194
Ben Greeara9aefb32014-08-12 11:02:19 +03003195 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003196 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003198 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003199 }
Ben Greear16c11172014-09-23 14:17:16 -07003200 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003201
Ben Greear16c11172014-09-23 14:17:16 -07003202 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3203 bit, ar->free_vdev_map);
3204
3205 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003206 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003207
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003209 case NL80211_IFTYPE_P2P_DEVICE:
3210 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3211 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3212 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003213 case NL80211_IFTYPE_UNSPECIFIED:
3214 case NL80211_IFTYPE_STATION:
3215 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3216 if (vif->p2p)
3217 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3218 break;
3219 case NL80211_IFTYPE_ADHOC:
3220 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3221 break;
3222 case NL80211_IFTYPE_AP:
3223 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3224
3225 if (vif->p2p)
3226 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3227 break;
3228 case NL80211_IFTYPE_MONITOR:
3229 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3230 break;
3231 default:
3232 WARN_ON(1);
3233 break;
3234 }
3235
Michal Kazior64badcb2014-09-18 11:18:02 +03003236 /* Some firmware revisions don't wait for beacon tx completion before
3237 * sending another SWBA event. This could lead to hardware using old
3238 * (freed) beacon data in some cases, e.g. tx credit starvation
3239 * combined with missed TBTT. This is very very rare.
3240 *
3241 * On non-IOMMU-enabled hosts this could be a possible security issue
3242 * because hw could beacon some random data on the air. On
3243 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3244 * device would crash.
3245 *
3246 * Since there are no beacon tx completions (implicit nor explicit)
3247 * propagated to host the only workaround for this is to allocate a
3248 * DMA-coherent buffer for a lifetime of a vif and use it for all
3249 * beacon tx commands. Worst case for this approach is some beacons may
3250 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3251 */
3252 if (vif->type == NL80211_IFTYPE_ADHOC ||
3253 vif->type == NL80211_IFTYPE_AP) {
3254 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3255 IEEE80211_MAX_FRAME_LEN,
3256 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303257 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003258 if (!arvif->beacon_buf) {
3259 ret = -ENOMEM;
3260 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3261 ret);
3262 goto err;
3263 }
3264 }
3265
3266 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3267 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3268 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269
3270 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3271 arvif->vdev_subtype, vif->addr);
3272 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003273 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003274 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003275 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003276 }
3277
Ben Greear16c11172014-09-23 14:17:16 -07003278 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003279 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003280
Michal Kazior46725b152015-01-28 09:57:49 +02003281 /* It makes no sense to have firmware do keepalives. mac80211 already
3282 * takes care of this with idle connection polling.
3283 */
3284 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003285 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003286 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003287 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003288 goto err_vdev_delete;
3289 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003290
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003291 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003292
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003293 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3294 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003295 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003296 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003297 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003298 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003299 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003300 goto err_vdev_delete;
3301 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003302
Ben Greear5572a952014-11-24 16:22:10 +02003303 if (ar->cfg_tx_chainmask) {
3304 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3305
3306 vdev_param = ar->wmi.vdev_param->nss;
3307 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3308 nss);
3309 if (ret) {
3310 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3311 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3312 ret);
3313 goto err_vdev_delete;
3314 }
3315 }
3316
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3318 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3319 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003320 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003321 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003322 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003323 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003324
Kalle Valo5a13e762014-01-20 11:01:46 +02003325 ret = ath10k_mac_set_kickout(arvif);
3326 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003327 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003328 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003329 goto err_peer_delete;
3330 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003331 }
3332
3333 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3334 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3335 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3336 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3337 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003338 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003339 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003340 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003341 goto err_peer_delete;
3342 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003343
Michal Kazior9f9b5742014-12-12 12:41:36 +01003344 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003345 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003346 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003347 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003348 goto err_peer_delete;
3349 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003350
Michal Kazior9f9b5742014-12-12 12:41:36 +01003351 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003352 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003353 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003354 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003355 goto err_peer_delete;
3356 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003357 }
3358
Michal Kazior424121c2013-07-22 14:13:31 +02003359 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003360 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003361 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003362 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003363 goto err_peer_delete;
3364 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003365
Michal Kazior424121c2013-07-22 14:13:31 +02003366 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003368 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003369 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003370 goto err_peer_delete;
3371 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003372
Michal Kazior7d9d5582014-10-21 10:40:15 +03003373 arvif->txpower = vif->bss_conf.txpower;
3374 ret = ath10k_mac_txpower_recalc(ar);
3375 if (ret) {
3376 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3377 goto err_peer_delete;
3378 }
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003381 return 0;
3382
3383err_peer_delete:
3384 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3385 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3386
3387err_vdev_delete:
3388 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003389 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003390 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003391
3392err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003393 if (arvif->beacon_buf) {
3394 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3395 arvif->beacon_buf, arvif->beacon_paddr);
3396 arvif->beacon_buf = NULL;
3397 }
3398
Michal Kazior9dad14a2013-10-16 15:44:45 +03003399 mutex_unlock(&ar->conf_mutex);
3400
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401 return ret;
3402}
3403
3404static void ath10k_remove_interface(struct ieee80211_hw *hw,
3405 struct ieee80211_vif *vif)
3406{
3407 struct ath10k *ar = hw->priv;
3408 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3409 int ret;
3410
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303411 mutex_lock(&ar->conf_mutex);
3412
Michal Kaziored543882013-09-13 14:16:56 +02003413 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003414 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003415 spin_unlock_bh(&ar->data_lock);
3416
Simon Wunderlich855aed12014-08-02 09:12:54 +03003417 ret = ath10k_spectral_vif_stop(arvif);
3418 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003419 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003420 arvif->vdev_id, ret);
3421
Ben Greear16c11172014-09-23 14:17:16 -07003422 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003423 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003424
3425 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003426 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3427 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003428 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003429 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003430 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003431
3432 kfree(arvif->u.ap.noa_data);
3433 }
3434
Michal Kazior7aa7a722014-08-25 12:09:38 +02003435 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003436 arvif->vdev_id);
3437
Kalle Valo5e3dd152013-06-12 20:52:10 +03003438 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3439 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003440 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003441 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003442
Michal Kazior2c512052015-02-15 16:50:40 +02003443 /* Some firmware revisions don't notify host about self-peer removal
3444 * until after associated vdev is deleted.
3445 */
3446 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3447 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3448 vif->addr);
3449 if (ret)
3450 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3451 arvif->vdev_id, ret);
3452
3453 spin_lock_bh(&ar->data_lock);
3454 ar->num_peers--;
3455 spin_unlock_bh(&ar->data_lock);
3456 }
3457
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458 ath10k_peer_cleanup(ar, arvif->vdev_id);
3459
3460 mutex_unlock(&ar->conf_mutex);
3461}
3462
3463/*
3464 * FIXME: Has to be verified.
3465 */
3466#define SUPPORTED_FILTERS \
3467 (FIF_PROMISC_IN_BSS | \
3468 FIF_ALLMULTI | \
3469 FIF_CONTROL | \
3470 FIF_PSPOLL | \
3471 FIF_OTHER_BSS | \
3472 FIF_BCN_PRBRESP_PROMISC | \
3473 FIF_PROBE_REQ | \
3474 FIF_FCSFAIL)
3475
3476static void ath10k_configure_filter(struct ieee80211_hw *hw,
3477 unsigned int changed_flags,
3478 unsigned int *total_flags,
3479 u64 multicast)
3480{
3481 struct ath10k *ar = hw->priv;
3482 int ret;
3483
3484 mutex_lock(&ar->conf_mutex);
3485
3486 changed_flags &= SUPPORTED_FILTERS;
3487 *total_flags &= SUPPORTED_FILTERS;
3488 ar->filter_flags = *total_flags;
3489
Michal Kazior19337472014-08-28 12:58:16 +02003490 ret = ath10k_monitor_recalc(ar);
3491 if (ret)
3492 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003493
3494 mutex_unlock(&ar->conf_mutex);
3495}
3496
3497static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3498 struct ieee80211_vif *vif,
3499 struct ieee80211_bss_conf *info,
3500 u32 changed)
3501{
3502 struct ath10k *ar = hw->priv;
3503 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3504 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003505 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003506
3507 mutex_lock(&ar->conf_mutex);
3508
3509 if (changed & BSS_CHANGED_IBSS)
3510 ath10k_control_ibss(arvif, info, vif->addr);
3511
3512 if (changed & BSS_CHANGED_BEACON_INT) {
3513 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003514 vdev_param = ar->wmi.vdev_param->beacon_interval;
3515 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003517 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003518 "mac vdev %d beacon_interval %d\n",
3519 arvif->vdev_id, arvif->beacon_interval);
3520
Kalle Valo5e3dd152013-06-12 20:52:10 +03003521 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003522 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003523 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003524 }
3525
3526 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003527 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003528 "vdev %d set beacon tx mode to staggered\n",
3529 arvif->vdev_id);
3530
Bartosz Markowski226a3392013-09-26 17:47:16 +02003531 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3532 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003533 WMI_BEACON_STAGGERED_MODE);
3534 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003535 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003536 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003537
3538 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3539 if (ret)
3540 ath10k_warn(ar, "failed to update beacon template: %d\n",
3541 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003542 }
3543
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003544 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3545 ret = ath10k_mac_setup_prb_tmpl(arvif);
3546 if (ret)
3547 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3548 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003549 }
3550
Michal Kaziorba2479f2015-01-24 12:14:51 +02003551 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003552 arvif->dtim_period = info->dtim_period;
3553
Michal Kazior7aa7a722014-08-25 12:09:38 +02003554 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003555 "mac vdev %d dtim_period %d\n",
3556 arvif->vdev_id, arvif->dtim_period);
3557
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003558 vdev_param = ar->wmi.vdev_param->dtim_period;
3559 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560 arvif->dtim_period);
3561 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003562 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003563 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003564 }
3565
3566 if (changed & BSS_CHANGED_SSID &&
3567 vif->type == NL80211_IFTYPE_AP) {
3568 arvif->u.ap.ssid_len = info->ssid_len;
3569 if (info->ssid_len)
3570 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3571 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3572 }
3573
Michal Kazior077efc82014-10-21 10:10:29 +03003574 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3575 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576
3577 if (changed & BSS_CHANGED_BEACON_ENABLED)
3578 ath10k_control_beaconing(arvif, info);
3579
3580 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003581 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003582 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003583 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003584
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003585 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003587 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003588 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589 }
3590
3591 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592 if (info->use_short_slot)
3593 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3594
3595 else
3596 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3597
Michal Kazior7aa7a722014-08-25 12:09:38 +02003598 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003599 arvif->vdev_id, slottime);
3600
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003601 vdev_param = ar->wmi.vdev_param->slot_time;
3602 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003603 slottime);
3604 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003605 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003606 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003607 }
3608
3609 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003610 if (info->use_short_preamble)
3611 preamble = WMI_VDEV_PREAMBLE_SHORT;
3612 else
3613 preamble = WMI_VDEV_PREAMBLE_LONG;
3614
Michal Kazior7aa7a722014-08-25 12:09:38 +02003615 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003616 "mac vdev %d preamble %dn",
3617 arvif->vdev_id, preamble);
3618
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003619 vdev_param = ar->wmi.vdev_param->preamble;
3620 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621 preamble);
3622 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003623 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003624 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003625 }
3626
3627 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003628 if (info->assoc) {
3629 /* Workaround: Make sure monitor vdev is not running
3630 * when associating to prevent some firmware revisions
3631 * (e.g. 10.1 and 10.2) from crashing.
3632 */
3633 if (ar->monitor_started)
3634 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003635 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003636 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003637 } else {
3638 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003639 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003640 }
3641
Michal Kazior7d9d5582014-10-21 10:40:15 +03003642 if (changed & BSS_CHANGED_TXPOWER) {
3643 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3644 arvif->vdev_id, info->txpower);
3645
3646 arvif->txpower = info->txpower;
3647 ret = ath10k_mac_txpower_recalc(ar);
3648 if (ret)
3649 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3650 }
3651
Michal Kaziorbf14e652014-12-12 12:41:38 +01003652 if (changed & BSS_CHANGED_PS) {
3653 ret = ath10k_mac_vif_setup_ps(arvif);
3654 if (ret)
3655 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3656 arvif->vdev_id, ret);
3657 }
3658
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659 mutex_unlock(&ar->conf_mutex);
3660}
3661
3662static int ath10k_hw_scan(struct ieee80211_hw *hw,
3663 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003664 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003665{
3666 struct ath10k *ar = hw->priv;
3667 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003668 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669 struct wmi_start_scan_arg arg;
3670 int ret = 0;
3671 int i;
3672
3673 mutex_lock(&ar->conf_mutex);
3674
3675 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003676 switch (ar->scan.state) {
3677 case ATH10K_SCAN_IDLE:
3678 reinit_completion(&ar->scan.started);
3679 reinit_completion(&ar->scan.completed);
3680 ar->scan.state = ATH10K_SCAN_STARTING;
3681 ar->scan.is_roc = false;
3682 ar->scan.vdev_id = arvif->vdev_id;
3683 ret = 0;
3684 break;
3685 case ATH10K_SCAN_STARTING:
3686 case ATH10K_SCAN_RUNNING:
3687 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003688 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003689 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003690 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003691 spin_unlock_bh(&ar->data_lock);
3692
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003693 if (ret)
3694 goto exit;
3695
Kalle Valo5e3dd152013-06-12 20:52:10 +03003696 memset(&arg, 0, sizeof(arg));
3697 ath10k_wmi_start_scan_init(ar, &arg);
3698 arg.vdev_id = arvif->vdev_id;
3699 arg.scan_id = ATH10K_SCAN_ID;
3700
3701 if (!req->no_cck)
3702 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3703
3704 if (req->ie_len) {
3705 arg.ie_len = req->ie_len;
3706 memcpy(arg.ie, req->ie, arg.ie_len);
3707 }
3708
3709 if (req->n_ssids) {
3710 arg.n_ssids = req->n_ssids;
3711 for (i = 0; i < arg.n_ssids; i++) {
3712 arg.ssids[i].len = req->ssids[i].ssid_len;
3713 arg.ssids[i].ssid = req->ssids[i].ssid;
3714 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003715 } else {
3716 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003717 }
3718
3719 if (req->n_channels) {
3720 arg.n_channels = req->n_channels;
3721 for (i = 0; i < arg.n_channels; i++)
3722 arg.channels[i] = req->channels[i]->center_freq;
3723 }
3724
3725 ret = ath10k_start_scan(ar, &arg);
3726 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003727 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003728 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003729 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003730 spin_unlock_bh(&ar->data_lock);
3731 }
3732
3733exit:
3734 mutex_unlock(&ar->conf_mutex);
3735 return ret;
3736}
3737
3738static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3739 struct ieee80211_vif *vif)
3740{
3741 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003742
3743 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003744 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003745 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003746
3747 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748}
3749
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003750static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3751 struct ath10k_vif *arvif,
3752 enum set_key_cmd cmd,
3753 struct ieee80211_key_conf *key)
3754{
3755 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3756 int ret;
3757
3758 /* 10.1 firmware branch requires default key index to be set to group
3759 * key index after installing it. Otherwise FW/HW Txes corrupted
3760 * frames with multi-vif APs. This is not required for main firmware
3761 * branch (e.g. 636).
3762 *
3763 * FIXME: This has been tested only in AP. It remains unknown if this
3764 * is required for multi-vif STA interfaces on 10.1 */
3765
3766 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3767 return;
3768
3769 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3770 return;
3771
3772 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3773 return;
3774
3775 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3776 return;
3777
3778 if (cmd != SET_KEY)
3779 return;
3780
3781 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3782 key->keyidx);
3783 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003784 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003785 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003786}
3787
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3789 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3790 struct ieee80211_key_conf *key)
3791{
3792 struct ath10k *ar = hw->priv;
3793 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3794 struct ath10k_peer *peer;
3795 const u8 *peer_addr;
3796 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3797 key->cipher == WLAN_CIPHER_SUITE_WEP104;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003798 bool def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003799 int ret = 0;
3800
3801 if (key->keyidx > WMI_MAX_KEY_INDEX)
3802 return -ENOSPC;
3803
3804 mutex_lock(&ar->conf_mutex);
3805
3806 if (sta)
3807 peer_addr = sta->addr;
3808 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3809 peer_addr = vif->bss_conf.bssid;
3810 else
3811 peer_addr = vif->addr;
3812
3813 key->hw_key_idx = key->keyidx;
3814
3815 /* the peer should not disappear in mid-way (unless FW goes awry) since
3816 * we already hold conf_mutex. we just make sure its there now. */
3817 spin_lock_bh(&ar->data_lock);
3818 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3819 spin_unlock_bh(&ar->data_lock);
3820
3821 if (!peer) {
3822 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003824 peer_addr);
3825 ret = -EOPNOTSUPP;
3826 goto exit;
3827 } else {
3828 /* if the peer doesn't exist there is no key to disable
3829 * anymore */
3830 goto exit;
3831 }
3832 }
3833
3834 if (is_wep) {
3835 if (cmd == SET_KEY)
3836 arvif->wep_keys[key->keyidx] = key;
3837 else
3838 arvif->wep_keys[key->keyidx] = NULL;
3839
3840 if (cmd == DISABLE_KEY)
3841 ath10k_clear_vdev_key(arvif, key);
3842 }
3843
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003844 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3845 * static WEP, do not set this flag for the keys whose key id
3846 * is greater than default key id.
3847 */
3848 if (arvif->def_wep_key_idx == -1)
3849 def_idx = true;
3850
3851 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003852 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003853 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003854 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003855 goto exit;
3856 }
3857
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003858 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3859
Kalle Valo5e3dd152013-06-12 20:52:10 +03003860 spin_lock_bh(&ar->data_lock);
3861 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3862 if (peer && cmd == SET_KEY)
3863 peer->keys[key->keyidx] = key;
3864 else if (peer && cmd == DISABLE_KEY)
3865 peer->keys[key->keyidx] = NULL;
3866 else if (peer == NULL)
3867 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003868 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869 spin_unlock_bh(&ar->data_lock);
3870
3871exit:
3872 mutex_unlock(&ar->conf_mutex);
3873 return ret;
3874}
3875
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003876static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3877 struct ieee80211_vif *vif,
3878 int keyidx)
3879{
3880 struct ath10k *ar = hw->priv;
3881 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3882 int ret;
3883
3884 mutex_lock(&arvif->ar->conf_mutex);
3885
3886 if (arvif->ar->state != ATH10K_STATE_ON)
3887 goto unlock;
3888
3889 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3890 arvif->vdev_id, keyidx);
3891
3892 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3893 arvif->vdev_id,
3894 arvif->ar->wmi.vdev_param->def_keyid,
3895 keyidx);
3896
3897 if (ret) {
3898 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3899 arvif->vdev_id,
3900 ret);
3901 goto unlock;
3902 }
3903
3904 arvif->def_wep_key_idx = keyidx;
3905unlock:
3906 mutex_unlock(&arvif->ar->conf_mutex);
3907}
3908
Michal Kazior9797feb2014-02-14 14:49:48 +01003909static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3910{
3911 struct ath10k *ar;
3912 struct ath10k_vif *arvif;
3913 struct ath10k_sta *arsta;
3914 struct ieee80211_sta *sta;
3915 u32 changed, bw, nss, smps;
3916 int err;
3917
3918 arsta = container_of(wk, struct ath10k_sta, update_wk);
3919 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3920 arvif = arsta->arvif;
3921 ar = arvif->ar;
3922
3923 spin_lock_bh(&ar->data_lock);
3924
3925 changed = arsta->changed;
3926 arsta->changed = 0;
3927
3928 bw = arsta->bw;
3929 nss = arsta->nss;
3930 smps = arsta->smps;
3931
3932 spin_unlock_bh(&ar->data_lock);
3933
3934 mutex_lock(&ar->conf_mutex);
3935
3936 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003937 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003938 sta->addr, bw);
3939
3940 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3941 WMI_PEER_CHAN_WIDTH, bw);
3942 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003943 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003944 sta->addr, bw, err);
3945 }
3946
3947 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003948 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003949 sta->addr, nss);
3950
3951 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3952 WMI_PEER_NSS, nss);
3953 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003954 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003955 sta->addr, nss, err);
3956 }
3957
3958 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003959 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003960 sta->addr, smps);
3961
3962 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3963 WMI_PEER_SMPS_STATE, smps);
3964 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003965 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003966 sta->addr, smps, err);
3967 }
3968
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003969 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3970 changed & IEEE80211_RC_NSS_CHANGED) {
3971 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003972 sta->addr);
3973
Michal Kazior590922a2014-10-21 10:10:29 +03003974 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003975 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003976 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003977 sta->addr);
3978 }
3979
Michal Kazior9797feb2014-02-14 14:49:48 +01003980 mutex_unlock(&ar->conf_mutex);
3981}
3982
Michal Kaziorcfd10612014-11-25 15:16:05 +01003983static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3984{
3985 struct ath10k *ar = arvif->ar;
3986
3987 lockdep_assert_held(&ar->conf_mutex);
3988
3989 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3990 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3991 return 0;
3992
3993 if (ar->num_stations >= ar->max_num_stations)
3994 return -ENOBUFS;
3995
3996 ar->num_stations++;
3997
3998 return 0;
3999}
4000
4001static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4002{
4003 struct ath10k *ar = arvif->ar;
4004
4005 lockdep_assert_held(&ar->conf_mutex);
4006
4007 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4008 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4009 return;
4010
4011 ar->num_stations--;
4012}
4013
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014static int ath10k_sta_state(struct ieee80211_hw *hw,
4015 struct ieee80211_vif *vif,
4016 struct ieee80211_sta *sta,
4017 enum ieee80211_sta_state old_state,
4018 enum ieee80211_sta_state new_state)
4019{
4020 struct ath10k *ar = hw->priv;
4021 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004022 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023 int ret = 0;
4024
Michal Kazior76f90022014-02-25 09:29:57 +02004025 if (old_state == IEEE80211_STA_NOTEXIST &&
4026 new_state == IEEE80211_STA_NONE) {
4027 memset(arsta, 0, sizeof(*arsta));
4028 arsta->arvif = arvif;
4029 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4030 }
4031
Michal Kazior9797feb2014-02-14 14:49:48 +01004032 /* cancel must be done outside the mutex to avoid deadlock */
4033 if ((old_state == IEEE80211_STA_NONE &&
4034 new_state == IEEE80211_STA_NOTEXIST))
4035 cancel_work_sync(&arsta->update_wk);
4036
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037 mutex_lock(&ar->conf_mutex);
4038
4039 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004040 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041 /*
4042 * New station addition.
4043 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004044 ath10k_dbg(ar, ATH10K_DBG_MAC,
4045 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4046 arvif->vdev_id, sta->addr,
4047 ar->num_stations + 1, ar->max_num_stations,
4048 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004049
Michal Kaziorcfd10612014-11-25 15:16:05 +01004050 ret = ath10k_mac_inc_num_stations(arvif);
4051 if (ret) {
4052 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4053 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004054 goto exit;
4055 }
4056
Kalle Valo5e3dd152013-06-12 20:52:10 +03004057 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004059 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 -08004060 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004061 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004062 goto exit;
4063 }
Michal Kazior077efc82014-10-21 10:10:29 +03004064
4065 if (vif->type == NL80211_IFTYPE_STATION) {
4066 WARN_ON(arvif->is_started);
4067
4068 ret = ath10k_vdev_start(arvif);
4069 if (ret) {
4070 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4071 arvif->vdev_id, ret);
4072 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4073 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004074 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004075 goto exit;
4076 }
4077
4078 arvif->is_started = true;
4079 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004080 } else if ((old_state == IEEE80211_STA_NONE &&
4081 new_state == IEEE80211_STA_NOTEXIST)) {
4082 /*
4083 * Existing station deletion.
4084 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004085 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004086 "mac vdev %d peer delete %pM (sta gone)\n",
4087 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004088
4089 if (vif->type == NL80211_IFTYPE_STATION) {
4090 WARN_ON(!arvif->is_started);
4091
4092 ret = ath10k_vdev_stop(arvif);
4093 if (ret)
4094 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4095 arvif->vdev_id, ret);
4096
4097 arvif->is_started = false;
4098 }
4099
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4101 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004102 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004103 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004104
Michal Kaziorcfd10612014-11-25 15:16:05 +01004105 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004106 } else if (old_state == IEEE80211_STA_AUTH &&
4107 new_state == IEEE80211_STA_ASSOC &&
4108 (vif->type == NL80211_IFTYPE_AP ||
4109 vif->type == NL80211_IFTYPE_ADHOC)) {
4110 /*
4111 * New association.
4112 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004113 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004114 sta->addr);
4115
Michal Kazior590922a2014-10-21 10:10:29 +03004116 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004118 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004119 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004120 } else if (old_state == IEEE80211_STA_ASSOC &&
4121 new_state == IEEE80211_STA_AUTH &&
4122 (vif->type == NL80211_IFTYPE_AP ||
4123 vif->type == NL80211_IFTYPE_ADHOC)) {
4124 /*
4125 * Disassociation.
4126 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004127 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004128 sta->addr);
4129
Michal Kazior590922a2014-10-21 10:10:29 +03004130 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004131 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004132 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004133 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004134 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004135exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004136 mutex_unlock(&ar->conf_mutex);
4137 return ret;
4138}
4139
4140static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004141 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142{
4143 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004144 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4145 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004146 u32 value = 0;
4147 int ret = 0;
4148
Michal Kazior548db542013-07-05 16:15:15 +03004149 lockdep_assert_held(&ar->conf_mutex);
4150
Kalle Valo5e3dd152013-06-12 20:52:10 +03004151 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4152 return 0;
4153
4154 switch (ac) {
4155 case IEEE80211_AC_VO:
4156 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4157 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004158 prio = 7;
4159 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160 break;
4161 case IEEE80211_AC_VI:
4162 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4163 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004164 prio = 5;
4165 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004166 break;
4167 case IEEE80211_AC_BE:
4168 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4169 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004170 prio = 2;
4171 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004172 break;
4173 case IEEE80211_AC_BK:
4174 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4175 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004176 prio = 0;
4177 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178 break;
4179 }
4180
4181 if (enable)
4182 arvif->u.sta.uapsd |= value;
4183 else
4184 arvif->u.sta.uapsd &= ~value;
4185
4186 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4187 WMI_STA_PS_PARAM_UAPSD,
4188 arvif->u.sta.uapsd);
4189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004190 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004191 goto exit;
4192 }
4193
4194 if (arvif->u.sta.uapsd)
4195 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4196 else
4197 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4198
4199 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4200 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4201 value);
4202 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004203 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204
Michal Kazior9f9b5742014-12-12 12:41:36 +01004205 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4206 if (ret) {
4207 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4208 arvif->vdev_id, ret);
4209 return ret;
4210 }
4211
4212 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4213 if (ret) {
4214 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4215 arvif->vdev_id, ret);
4216 return ret;
4217 }
4218
Michal Kaziorb0e56152015-01-24 12:14:52 +02004219 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4220 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4221 /* Only userspace can make an educated decision when to send
4222 * trigger frame. The following effectively disables u-UAPSD
4223 * autotrigger in firmware (which is enabled by default
4224 * provided the autotrigger service is available).
4225 */
4226
4227 arg.wmm_ac = acc;
4228 arg.user_priority = prio;
4229 arg.service_interval = 0;
4230 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4231 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4232
4233 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4234 arvif->bssid, &arg, 1);
4235 if (ret) {
4236 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4237 ret);
4238 return ret;
4239 }
4240 }
4241
Kalle Valo5e3dd152013-06-12 20:52:10 +03004242exit:
4243 return ret;
4244}
4245
4246static int ath10k_conf_tx(struct ieee80211_hw *hw,
4247 struct ieee80211_vif *vif, u16 ac,
4248 const struct ieee80211_tx_queue_params *params)
4249{
4250 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004251 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004252 struct wmi_wmm_params_arg *p = NULL;
4253 int ret;
4254
4255 mutex_lock(&ar->conf_mutex);
4256
4257 switch (ac) {
4258 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004259 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004260 break;
4261 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004262 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004263 break;
4264 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004265 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266 break;
4267 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004268 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004269 break;
4270 }
4271
4272 if (WARN_ON(!p)) {
4273 ret = -EINVAL;
4274 goto exit;
4275 }
4276
4277 p->cwmin = params->cw_min;
4278 p->cwmax = params->cw_max;
4279 p->aifs = params->aifs;
4280
4281 /*
4282 * The channel time duration programmed in the HW is in absolute
4283 * microseconds, while mac80211 gives the txop in units of
4284 * 32 microseconds.
4285 */
4286 p->txop = params->txop * 32;
4287
Michal Kazior7fc979a2015-01-28 09:57:28 +02004288 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4289 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4290 &arvif->wmm_params);
4291 if (ret) {
4292 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4293 arvif->vdev_id, ret);
4294 goto exit;
4295 }
4296 } else {
4297 /* This won't work well with multi-interface cases but it's
4298 * better than nothing.
4299 */
4300 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4301 if (ret) {
4302 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4303 goto exit;
4304 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004305 }
4306
4307 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4308 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004309 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004310
4311exit:
4312 mutex_unlock(&ar->conf_mutex);
4313 return ret;
4314}
4315
4316#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4317
4318static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4319 struct ieee80211_vif *vif,
4320 struct ieee80211_channel *chan,
4321 int duration,
4322 enum ieee80211_roc_type type)
4323{
4324 struct ath10k *ar = hw->priv;
4325 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4326 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004327 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004328
4329 mutex_lock(&ar->conf_mutex);
4330
4331 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004332 switch (ar->scan.state) {
4333 case ATH10K_SCAN_IDLE:
4334 reinit_completion(&ar->scan.started);
4335 reinit_completion(&ar->scan.completed);
4336 reinit_completion(&ar->scan.on_channel);
4337 ar->scan.state = ATH10K_SCAN_STARTING;
4338 ar->scan.is_roc = true;
4339 ar->scan.vdev_id = arvif->vdev_id;
4340 ar->scan.roc_freq = chan->center_freq;
4341 ret = 0;
4342 break;
4343 case ATH10K_SCAN_STARTING:
4344 case ATH10K_SCAN_RUNNING:
4345 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004346 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004347 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004348 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004349 spin_unlock_bh(&ar->data_lock);
4350
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004351 if (ret)
4352 goto exit;
4353
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004354 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4355
Kalle Valo5e3dd152013-06-12 20:52:10 +03004356 memset(&arg, 0, sizeof(arg));
4357 ath10k_wmi_start_scan_init(ar, &arg);
4358 arg.vdev_id = arvif->vdev_id;
4359 arg.scan_id = ATH10K_SCAN_ID;
4360 arg.n_channels = 1;
4361 arg.channels[0] = chan->center_freq;
4362 arg.dwell_time_active = duration;
4363 arg.dwell_time_passive = duration;
4364 arg.max_scan_time = 2 * duration;
4365 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4366 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4367
4368 ret = ath10k_start_scan(ar, &arg);
4369 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004370 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004371 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004372 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 spin_unlock_bh(&ar->data_lock);
4374 goto exit;
4375 }
4376
4377 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4378 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004379 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004380
4381 ret = ath10k_scan_stop(ar);
4382 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004383 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004384
Kalle Valo5e3dd152013-06-12 20:52:10 +03004385 ret = -ETIMEDOUT;
4386 goto exit;
4387 }
4388
4389 ret = 0;
4390exit:
4391 mutex_unlock(&ar->conf_mutex);
4392 return ret;
4393}
4394
4395static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4396{
4397 struct ath10k *ar = hw->priv;
4398
4399 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004400 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004401 mutex_unlock(&ar->conf_mutex);
4402
Michal Kazior4eb2e162014-10-28 10:23:09 +01004403 cancel_delayed_work_sync(&ar->scan.timeout);
4404
Kalle Valo5e3dd152013-06-12 20:52:10 +03004405 return 0;
4406}
4407
4408/*
4409 * Both RTS and Fragmentation threshold are interface-specific
4410 * in ath10k, but device-specific in mac80211.
4411 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412
4413static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4414{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004415 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004416 struct ath10k_vif *arvif;
4417 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004418
Michal Kaziorad088bf2013-10-16 15:44:46 +03004419 mutex_lock(&ar->conf_mutex);
4420 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004421 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004422 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004423
Michal Kaziorad088bf2013-10-16 15:44:46 +03004424 ret = ath10k_mac_set_rts(arvif, value);
4425 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004426 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004427 arvif->vdev_id, ret);
4428 break;
4429 }
4430 }
4431 mutex_unlock(&ar->conf_mutex);
4432
4433 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004434}
4435
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004436static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4437 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004438{
4439 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004440 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004441 int ret;
4442
4443 /* mac80211 doesn't care if we really xmit queued frames or not
4444 * we'll collect those frames either way if we stop/delete vdevs */
4445 if (drop)
4446 return;
4447
Michal Kazior548db542013-07-05 16:15:15 +03004448 mutex_lock(&ar->conf_mutex);
4449
Michal Kazioraffd3212013-07-16 09:54:35 +02004450 if (ar->state == ATH10K_STATE_WEDGED)
4451 goto skip;
4452
Michal Kazioredb82362013-07-05 16:15:14 +03004453 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004454 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004455
Michal Kazioredb82362013-07-05 16:15:14 +03004456 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004457 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004458 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004459
Michal Kazior7962b0d2014-10-28 10:34:38 +01004460 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4461 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4462 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004463
4464 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004465 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004466
4467 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004468 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004469 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004470
Michal Kazioraffd3212013-07-16 09:54:35 +02004471skip:
Michal Kazior548db542013-07-05 16:15:15 +03004472 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004473}
4474
4475/* TODO: Implement this function properly
4476 * For now it is needed to reply to Probe Requests in IBSS mode.
4477 * Propably we need this information from FW.
4478 */
4479static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4480{
4481 return 1;
4482}
4483
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004484#ifdef CONFIG_PM
4485static int ath10k_suspend(struct ieee80211_hw *hw,
4486 struct cfg80211_wowlan *wowlan)
4487{
4488 struct ath10k *ar = hw->priv;
4489 int ret;
4490
Marek Puzyniak9042e172014-02-10 17:14:23 +01004491 mutex_lock(&ar->conf_mutex);
4492
Marek Puzyniak00f54822014-02-10 17:14:24 +01004493 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004494 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004495 if (ret == -ETIMEDOUT)
4496 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004497 ret = 1;
4498 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004499 }
4500
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004501 ret = ath10k_hif_suspend(ar);
4502 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004503 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004504 goto resume;
4505 }
4506
Marek Puzyniak9042e172014-02-10 17:14:23 +01004507 ret = 0;
4508 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004509resume:
4510 ret = ath10k_wmi_pdev_resume_target(ar);
4511 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004512 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004513
4514 ret = 1;
4515exit:
4516 mutex_unlock(&ar->conf_mutex);
4517 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004518}
4519
4520static int ath10k_resume(struct ieee80211_hw *hw)
4521{
4522 struct ath10k *ar = hw->priv;
4523 int ret;
4524
Marek Puzyniak9042e172014-02-10 17:14:23 +01004525 mutex_lock(&ar->conf_mutex);
4526
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004527 ret = ath10k_hif_resume(ar);
4528 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004529 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004530 ret = 1;
4531 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004532 }
4533
4534 ret = ath10k_wmi_pdev_resume_target(ar);
4535 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004536 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004537 ret = 1;
4538 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004539 }
4540
Marek Puzyniak9042e172014-02-10 17:14:23 +01004541 ret = 0;
4542exit:
4543 mutex_unlock(&ar->conf_mutex);
4544 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004545}
4546#endif
4547
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004548static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4549 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004550{
4551 struct ath10k *ar = hw->priv;
4552
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004553 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4554 return;
4555
Michal Kazioraffd3212013-07-16 09:54:35 +02004556 mutex_lock(&ar->conf_mutex);
4557
4558 /* If device failed to restart it will be in a different state, e.g.
4559 * ATH10K_STATE_WEDGED */
4560 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004561 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004562 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004563 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004564 }
4565
4566 mutex_unlock(&ar->conf_mutex);
4567}
4568
Michal Kazior2e1dea42013-07-31 10:32:40 +02004569static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4570 struct survey_info *survey)
4571{
4572 struct ath10k *ar = hw->priv;
4573 struct ieee80211_supported_band *sband;
4574 struct survey_info *ar_survey = &ar->survey[idx];
4575 int ret = 0;
4576
4577 mutex_lock(&ar->conf_mutex);
4578
4579 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4580 if (sband && idx >= sband->n_channels) {
4581 idx -= sband->n_channels;
4582 sband = NULL;
4583 }
4584
4585 if (!sband)
4586 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4587
4588 if (!sband || idx >= sband->n_channels) {
4589 ret = -ENOENT;
4590 goto exit;
4591 }
4592
4593 spin_lock_bh(&ar->data_lock);
4594 memcpy(survey, ar_survey, sizeof(*survey));
4595 spin_unlock_bh(&ar->data_lock);
4596
4597 survey->channel = &sband->channels[idx];
4598
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004599 if (ar->rx_channel == survey->channel)
4600 survey->filled |= SURVEY_INFO_IN_USE;
4601
Michal Kazior2e1dea42013-07-31 10:32:40 +02004602exit:
4603 mutex_unlock(&ar->conf_mutex);
4604 return ret;
4605}
4606
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004607/* Helper table for legacy fixed_rate/bitrate_mask */
4608static const u8 cck_ofdm_rate[] = {
4609 /* CCK */
4610 3, /* 1Mbps */
4611 2, /* 2Mbps */
4612 1, /* 5.5Mbps */
4613 0, /* 11Mbps */
4614 /* OFDM */
4615 3, /* 6Mbps */
4616 7, /* 9Mbps */
4617 2, /* 12Mbps */
4618 6, /* 18Mbps */
4619 1, /* 24Mbps */
4620 5, /* 36Mbps */
4621 0, /* 48Mbps */
4622 4, /* 54Mbps */
4623};
4624
4625/* Check if only one bit set */
4626static int ath10k_check_single_mask(u32 mask)
4627{
4628 int bit;
4629
4630 bit = ffs(mask);
4631 if (!bit)
4632 return 0;
4633
4634 mask &= ~BIT(bit - 1);
4635 if (mask)
4636 return 2;
4637
4638 return 1;
4639}
4640
4641static bool
4642ath10k_default_bitrate_mask(struct ath10k *ar,
4643 enum ieee80211_band band,
4644 const struct cfg80211_bitrate_mask *mask)
4645{
4646 u32 legacy = 0x00ff;
4647 u8 ht = 0xff, i;
4648 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004649 u16 nrf = ar->num_rf_chains;
4650
4651 if (ar->cfg_tx_chainmask)
4652 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004653
4654 switch (band) {
4655 case IEEE80211_BAND_2GHZ:
4656 legacy = 0x00fff;
4657 vht = 0;
4658 break;
4659 case IEEE80211_BAND_5GHZ:
4660 break;
4661 default:
4662 return false;
4663 }
4664
4665 if (mask->control[band].legacy != legacy)
4666 return false;
4667
Ben Greearb116ea12014-11-24 16:22:10 +02004668 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004669 if (mask->control[band].ht_mcs[i] != ht)
4670 return false;
4671
Ben Greearb116ea12014-11-24 16:22:10 +02004672 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004673 if (mask->control[band].vht_mcs[i] != vht)
4674 return false;
4675
4676 return true;
4677}
4678
4679static bool
4680ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4681 enum ieee80211_band band,
4682 u8 *fixed_nss)
4683{
4684 int ht_nss = 0, vht_nss = 0, i;
4685
4686 /* check legacy */
4687 if (ath10k_check_single_mask(mask->control[band].legacy))
4688 return false;
4689
4690 /* check HT */
4691 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4692 if (mask->control[band].ht_mcs[i] == 0xff)
4693 continue;
4694 else if (mask->control[band].ht_mcs[i] == 0x00)
4695 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004696
4697 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004698 }
4699
4700 ht_nss = i;
4701
4702 /* check VHT */
4703 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4704 if (mask->control[band].vht_mcs[i] == 0x03ff)
4705 continue;
4706 else if (mask->control[band].vht_mcs[i] == 0x0000)
4707 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004708
4709 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004710 }
4711
4712 vht_nss = i;
4713
4714 if (ht_nss > 0 && vht_nss > 0)
4715 return false;
4716
4717 if (ht_nss)
4718 *fixed_nss = ht_nss;
4719 else if (vht_nss)
4720 *fixed_nss = vht_nss;
4721 else
4722 return false;
4723
4724 return true;
4725}
4726
4727static bool
4728ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4729 enum ieee80211_band band,
4730 enum wmi_rate_preamble *preamble)
4731{
4732 int legacy = 0, ht = 0, vht = 0, i;
4733
4734 *preamble = WMI_RATE_PREAMBLE_OFDM;
4735
4736 /* check legacy */
4737 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4738 if (legacy > 1)
4739 return false;
4740
4741 /* check HT */
4742 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4743 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4744 if (ht > 1)
4745 return false;
4746
4747 /* check VHT */
4748 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4749 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4750 if (vht > 1)
4751 return false;
4752
4753 /* Currently we support only one fixed_rate */
4754 if ((legacy + ht + vht) != 1)
4755 return false;
4756
4757 if (ht)
4758 *preamble = WMI_RATE_PREAMBLE_HT;
4759 else if (vht)
4760 *preamble = WMI_RATE_PREAMBLE_VHT;
4761
4762 return true;
4763}
4764
4765static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004766ath10k_bitrate_mask_rate(struct ath10k *ar,
4767 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004768 enum ieee80211_band band,
4769 u8 *fixed_rate,
4770 u8 *fixed_nss)
4771{
4772 u8 rate = 0, pream = 0, nss = 0, i;
4773 enum wmi_rate_preamble preamble;
4774
4775 /* Check if single rate correct */
4776 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4777 return false;
4778
4779 pream = preamble;
4780
4781 switch (preamble) {
4782 case WMI_RATE_PREAMBLE_CCK:
4783 case WMI_RATE_PREAMBLE_OFDM:
4784 i = ffs(mask->control[band].legacy) - 1;
4785
4786 if (band == IEEE80211_BAND_2GHZ && i < 4)
4787 pream = WMI_RATE_PREAMBLE_CCK;
4788
4789 if (band == IEEE80211_BAND_5GHZ)
4790 i += 4;
4791
4792 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4793 return false;
4794
4795 rate = cck_ofdm_rate[i];
4796 break;
4797 case WMI_RATE_PREAMBLE_HT:
4798 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4799 if (mask->control[band].ht_mcs[i])
4800 break;
4801
4802 if (i == IEEE80211_HT_MCS_MASK_LEN)
4803 return false;
4804
4805 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4806 nss = i;
4807 break;
4808 case WMI_RATE_PREAMBLE_VHT:
4809 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4810 if (mask->control[band].vht_mcs[i])
4811 break;
4812
4813 if (i == NL80211_VHT_NSS_MAX)
4814 return false;
4815
4816 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4817 nss = i;
4818 break;
4819 }
4820
4821 *fixed_nss = nss + 1;
4822 nss <<= 4;
4823 pream <<= 6;
4824
Michal Kazior7aa7a722014-08-25 12:09:38 +02004825 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 +01004826 pream, nss, rate);
4827
4828 *fixed_rate = pream | nss | rate;
4829
4830 return true;
4831}
4832
Michal Kazior7aa7a722014-08-25 12:09:38 +02004833static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4834 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004835 enum ieee80211_band band,
4836 u8 *fixed_rate,
4837 u8 *fixed_nss)
4838{
4839 /* First check full NSS mask, if we can simply limit NSS */
4840 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4841 return true;
4842
4843 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004844 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004845}
4846
4847static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4848 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004849 u8 fixed_nss,
4850 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004851{
4852 struct ath10k *ar = arvif->ar;
4853 u32 vdev_param;
4854 int ret = 0;
4855
4856 mutex_lock(&ar->conf_mutex);
4857
4858 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004859 arvif->fixed_nss == fixed_nss &&
4860 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004861 goto exit;
4862
4863 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004865
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004866 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004867 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004868
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004869 vdev_param = ar->wmi.vdev_param->fixed_rate;
4870 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4871 vdev_param, fixed_rate);
4872 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004873 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004874 fixed_rate, ret);
4875 ret = -EINVAL;
4876 goto exit;
4877 }
4878
4879 arvif->fixed_rate = fixed_rate;
4880
4881 vdev_param = ar->wmi.vdev_param->nss;
4882 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4883 vdev_param, fixed_nss);
4884
4885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004886 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004887 fixed_nss, ret);
4888 ret = -EINVAL;
4889 goto exit;
4890 }
4891
4892 arvif->fixed_nss = fixed_nss;
4893
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004894 vdev_param = ar->wmi.vdev_param->sgi;
4895 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4896 force_sgi);
4897
4898 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004899 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004900 force_sgi, ret);
4901 ret = -EINVAL;
4902 goto exit;
4903 }
4904
4905 arvif->force_sgi = force_sgi;
4906
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004907exit:
4908 mutex_unlock(&ar->conf_mutex);
4909 return ret;
4910}
4911
4912static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4913 struct ieee80211_vif *vif,
4914 const struct cfg80211_bitrate_mask *mask)
4915{
4916 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4917 struct ath10k *ar = arvif->ar;
4918 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4919 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4920 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004921 u8 force_sgi;
4922
Ben Greearb116ea12014-11-24 16:22:10 +02004923 if (ar->cfg_tx_chainmask)
4924 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4925
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004926 force_sgi = mask->control[band].gi;
4927 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4928 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004929
4930 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004931 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004932 &fixed_rate,
4933 &fixed_nss))
4934 return -EINVAL;
4935 }
4936
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004937 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004938 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004939 return -EINVAL;
4940 }
4941
4942 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4943 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004944}
4945
Michal Kazior9797feb2014-02-14 14:49:48 +01004946static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4947 struct ieee80211_vif *vif,
4948 struct ieee80211_sta *sta,
4949 u32 changed)
4950{
4951 struct ath10k *ar = hw->priv;
4952 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4953 u32 bw, smps;
4954
4955 spin_lock_bh(&ar->data_lock);
4956
Michal Kazior7aa7a722014-08-25 12:09:38 +02004957 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004958 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4959 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4960 sta->smps_mode);
4961
4962 if (changed & IEEE80211_RC_BW_CHANGED) {
4963 bw = WMI_PEER_CHWIDTH_20MHZ;
4964
4965 switch (sta->bandwidth) {
4966 case IEEE80211_STA_RX_BW_20:
4967 bw = WMI_PEER_CHWIDTH_20MHZ;
4968 break;
4969 case IEEE80211_STA_RX_BW_40:
4970 bw = WMI_PEER_CHWIDTH_40MHZ;
4971 break;
4972 case IEEE80211_STA_RX_BW_80:
4973 bw = WMI_PEER_CHWIDTH_80MHZ;
4974 break;
4975 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004976 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004977 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004978 bw = WMI_PEER_CHWIDTH_20MHZ;
4979 break;
4980 }
4981
4982 arsta->bw = bw;
4983 }
4984
4985 if (changed & IEEE80211_RC_NSS_CHANGED)
4986 arsta->nss = sta->rx_nss;
4987
4988 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4989 smps = WMI_PEER_SMPS_PS_NONE;
4990
4991 switch (sta->smps_mode) {
4992 case IEEE80211_SMPS_AUTOMATIC:
4993 case IEEE80211_SMPS_OFF:
4994 smps = WMI_PEER_SMPS_PS_NONE;
4995 break;
4996 case IEEE80211_SMPS_STATIC:
4997 smps = WMI_PEER_SMPS_STATIC;
4998 break;
4999 case IEEE80211_SMPS_DYNAMIC:
5000 smps = WMI_PEER_SMPS_DYNAMIC;
5001 break;
5002 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005003 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005004 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005005 smps = WMI_PEER_SMPS_PS_NONE;
5006 break;
5007 }
5008
5009 arsta->smps = smps;
5010 }
5011
Michal Kazior9797feb2014-02-14 14:49:48 +01005012 arsta->changed |= changed;
5013
5014 spin_unlock_bh(&ar->data_lock);
5015
5016 ieee80211_queue_work(hw, &arsta->update_wk);
5017}
5018
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005019static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5020{
5021 /*
5022 * FIXME: Return 0 for time being. Need to figure out whether FW
5023 * has the API to fetch 64-bit local TSF
5024 */
5025
5026 return 0;
5027}
5028
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005029static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5030 struct ieee80211_vif *vif,
5031 enum ieee80211_ampdu_mlme_action action,
5032 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5033 u8 buf_size)
5034{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005035 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005036 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5037
Michal Kazior7aa7a722014-08-25 12:09:38 +02005038 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 +02005039 arvif->vdev_id, sta->addr, tid, action);
5040
5041 switch (action) {
5042 case IEEE80211_AMPDU_RX_START:
5043 case IEEE80211_AMPDU_RX_STOP:
5044 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5045 * creation/removal. Do we need to verify this?
5046 */
5047 return 0;
5048 case IEEE80211_AMPDU_TX_START:
5049 case IEEE80211_AMPDU_TX_STOP_CONT:
5050 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5051 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5052 case IEEE80211_AMPDU_TX_OPERATIONAL:
5053 /* Firmware offloads Tx aggregation entirely so deny mac80211
5054 * Tx aggregation requests.
5055 */
5056 return -EOPNOTSUPP;
5057 }
5058
5059 return -EINVAL;
5060}
5061
Kalle Valo5e3dd152013-06-12 20:52:10 +03005062static const struct ieee80211_ops ath10k_ops = {
5063 .tx = ath10k_tx,
5064 .start = ath10k_start,
5065 .stop = ath10k_stop,
5066 .config = ath10k_config,
5067 .add_interface = ath10k_add_interface,
5068 .remove_interface = ath10k_remove_interface,
5069 .configure_filter = ath10k_configure_filter,
5070 .bss_info_changed = ath10k_bss_info_changed,
5071 .hw_scan = ath10k_hw_scan,
5072 .cancel_hw_scan = ath10k_cancel_hw_scan,
5073 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005074 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005075 .sta_state = ath10k_sta_state,
5076 .conf_tx = ath10k_conf_tx,
5077 .remain_on_channel = ath10k_remain_on_channel,
5078 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5079 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005080 .flush = ath10k_flush,
5081 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005082 .set_antenna = ath10k_set_antenna,
5083 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005084 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005085 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005086 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005087 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005088 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005089 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005090 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5091 .get_et_stats = ath10k_debug_get_et_stats,
5092 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005093
5094 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5095
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005096#ifdef CONFIG_PM
5097 .suspend = ath10k_suspend,
5098 .resume = ath10k_resume,
5099#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005100#ifdef CONFIG_MAC80211_DEBUGFS
5101 .sta_add_debugfs = ath10k_sta_add_debugfs,
5102#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005103};
5104
5105#define RATETAB_ENT(_rate, _rateid, _flags) { \
5106 .bitrate = (_rate), \
5107 .flags = (_flags), \
5108 .hw_value = (_rateid), \
5109}
5110
5111#define CHAN2G(_channel, _freq, _flags) { \
5112 .band = IEEE80211_BAND_2GHZ, \
5113 .hw_value = (_channel), \
5114 .center_freq = (_freq), \
5115 .flags = (_flags), \
5116 .max_antenna_gain = 0, \
5117 .max_power = 30, \
5118}
5119
5120#define CHAN5G(_channel, _freq, _flags) { \
5121 .band = IEEE80211_BAND_5GHZ, \
5122 .hw_value = (_channel), \
5123 .center_freq = (_freq), \
5124 .flags = (_flags), \
5125 .max_antenna_gain = 0, \
5126 .max_power = 30, \
5127}
5128
5129static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5130 CHAN2G(1, 2412, 0),
5131 CHAN2G(2, 2417, 0),
5132 CHAN2G(3, 2422, 0),
5133 CHAN2G(4, 2427, 0),
5134 CHAN2G(5, 2432, 0),
5135 CHAN2G(6, 2437, 0),
5136 CHAN2G(7, 2442, 0),
5137 CHAN2G(8, 2447, 0),
5138 CHAN2G(9, 2452, 0),
5139 CHAN2G(10, 2457, 0),
5140 CHAN2G(11, 2462, 0),
5141 CHAN2G(12, 2467, 0),
5142 CHAN2G(13, 2472, 0),
5143 CHAN2G(14, 2484, 0),
5144};
5145
5146static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005147 CHAN5G(36, 5180, 0),
5148 CHAN5G(40, 5200, 0),
5149 CHAN5G(44, 5220, 0),
5150 CHAN5G(48, 5240, 0),
5151 CHAN5G(52, 5260, 0),
5152 CHAN5G(56, 5280, 0),
5153 CHAN5G(60, 5300, 0),
5154 CHAN5G(64, 5320, 0),
5155 CHAN5G(100, 5500, 0),
5156 CHAN5G(104, 5520, 0),
5157 CHAN5G(108, 5540, 0),
5158 CHAN5G(112, 5560, 0),
5159 CHAN5G(116, 5580, 0),
5160 CHAN5G(120, 5600, 0),
5161 CHAN5G(124, 5620, 0),
5162 CHAN5G(128, 5640, 0),
5163 CHAN5G(132, 5660, 0),
5164 CHAN5G(136, 5680, 0),
5165 CHAN5G(140, 5700, 0),
5166 CHAN5G(149, 5745, 0),
5167 CHAN5G(153, 5765, 0),
5168 CHAN5G(157, 5785, 0),
5169 CHAN5G(161, 5805, 0),
5170 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005171};
5172
Michal Kazior91b12082014-12-12 12:41:35 +01005173/* Note: Be careful if you re-order these. There is code which depends on this
5174 * ordering.
5175 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005176static struct ieee80211_rate ath10k_rates[] = {
5177 /* CCK */
5178 RATETAB_ENT(10, 0x82, 0),
5179 RATETAB_ENT(20, 0x84, 0),
5180 RATETAB_ENT(55, 0x8b, 0),
5181 RATETAB_ENT(110, 0x96, 0),
5182 /* OFDM */
5183 RATETAB_ENT(60, 0x0c, 0),
5184 RATETAB_ENT(90, 0x12, 0),
5185 RATETAB_ENT(120, 0x18, 0),
5186 RATETAB_ENT(180, 0x24, 0),
5187 RATETAB_ENT(240, 0x30, 0),
5188 RATETAB_ENT(360, 0x48, 0),
5189 RATETAB_ENT(480, 0x60, 0),
5190 RATETAB_ENT(540, 0x6c, 0),
5191};
5192
5193#define ath10k_a_rates (ath10k_rates + 4)
5194#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5195#define ath10k_g_rates (ath10k_rates + 0)
5196#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5197
Michal Kaziore7b54192014-08-07 11:03:27 +02005198struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005199{
5200 struct ieee80211_hw *hw;
5201 struct ath10k *ar;
5202
Michal Kaziore7b54192014-08-07 11:03:27 +02005203 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005204 if (!hw)
5205 return NULL;
5206
5207 ar = hw->priv;
5208 ar->hw = hw;
5209
5210 return ar;
5211}
5212
5213void ath10k_mac_destroy(struct ath10k *ar)
5214{
5215 ieee80211_free_hw(ar->hw);
5216}
5217
5218static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5219 {
5220 .max = 8,
5221 .types = BIT(NL80211_IFTYPE_STATION)
5222 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005223 },
5224 {
5225 .max = 3,
5226 .types = BIT(NL80211_IFTYPE_P2P_GO)
5227 },
5228 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005229 .max = 1,
5230 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5231 },
5232 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005233 .max = 7,
5234 .types = BIT(NL80211_IFTYPE_AP)
5235 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005236};
5237
Bartosz Markowskif2595092013-12-10 16:20:39 +01005238static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005239 {
5240 .max = 8,
5241 .types = BIT(NL80211_IFTYPE_AP)
5242 },
5243};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005244
5245static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5246 {
5247 .limits = ath10k_if_limits,
5248 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5249 .max_interfaces = 8,
5250 .num_different_channels = 1,
5251 .beacon_int_infra_match = true,
5252 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005253};
5254
5255static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005256 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005257 .limits = ath10k_10x_if_limits,
5258 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005259 .max_interfaces = 8,
5260 .num_different_channels = 1,
5261 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005262#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005263 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5264 BIT(NL80211_CHAN_WIDTH_20) |
5265 BIT(NL80211_CHAN_WIDTH_40) |
5266 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005267#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005268 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005269};
5270
5271static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5272{
5273 struct ieee80211_sta_vht_cap vht_cap = {0};
5274 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005275 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005276
5277 vht_cap.vht_supported = 1;
5278 vht_cap.cap = ar->vht_cap_info;
5279
Michal Kazior8865bee42013-07-24 12:36:46 +02005280 mcs_map = 0;
5281 for (i = 0; i < 8; i++) {
5282 if (i < ar->num_rf_chains)
5283 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5284 else
5285 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5286 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005287
5288 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5289 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5290
5291 return vht_cap;
5292}
5293
5294static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5295{
5296 int i;
5297 struct ieee80211_sta_ht_cap ht_cap = {0};
5298
5299 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5300 return ht_cap;
5301
5302 ht_cap.ht_supported = 1;
5303 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5304 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5305 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5306 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5307 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5308
5309 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5310 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5311
5312 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5313 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5314
5315 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5316 u32 smps;
5317
5318 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5319 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5320
5321 ht_cap.cap |= smps;
5322 }
5323
5324 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5325 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5326
5327 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5328 u32 stbc;
5329
5330 stbc = ar->ht_cap_info;
5331 stbc &= WMI_HT_CAP_RX_STBC;
5332 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5333 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5334 stbc &= IEEE80211_HT_CAP_RX_STBC;
5335
5336 ht_cap.cap |= stbc;
5337 }
5338
5339 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5340 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5341
5342 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5343 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5344
5345 /* max AMSDU is implicitly taken from vht_cap_info */
5346 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5347 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5348
Michal Kazior8865bee42013-07-24 12:36:46 +02005349 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005350 ht_cap.mcs.rx_mask[i] = 0xFF;
5351
5352 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5353
5354 return ht_cap;
5355}
5356
Kalle Valo5e3dd152013-06-12 20:52:10 +03005357static void ath10k_get_arvif_iter(void *data, u8 *mac,
5358 struct ieee80211_vif *vif)
5359{
5360 struct ath10k_vif_iter *arvif_iter = data;
5361 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5362
5363 if (arvif->vdev_id == arvif_iter->vdev_id)
5364 arvif_iter->arvif = arvif;
5365}
5366
5367struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5368{
5369 struct ath10k_vif_iter arvif_iter;
5370 u32 flags;
5371
5372 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5373 arvif_iter.vdev_id = vdev_id;
5374
5375 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5376 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5377 flags,
5378 ath10k_get_arvif_iter,
5379 &arvif_iter);
5380 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005381 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005382 return NULL;
5383 }
5384
5385 return arvif_iter.arvif;
5386}
5387
5388int ath10k_mac_register(struct ath10k *ar)
5389{
5390 struct ieee80211_supported_band *band;
5391 struct ieee80211_sta_vht_cap vht_cap;
5392 struct ieee80211_sta_ht_cap ht_cap;
5393 void *channels;
5394 int ret;
5395
5396 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5397
5398 SET_IEEE80211_DEV(ar->hw, ar->dev);
5399
5400 ht_cap = ath10k_get_ht_cap(ar);
5401 vht_cap = ath10k_create_vht_cap(ar);
5402
5403 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5404 channels = kmemdup(ath10k_2ghz_channels,
5405 sizeof(ath10k_2ghz_channels),
5406 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005407 if (!channels) {
5408 ret = -ENOMEM;
5409 goto err_free;
5410 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005411
5412 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5413 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5414 band->channels = channels;
5415 band->n_bitrates = ath10k_g_rates_size;
5416 band->bitrates = ath10k_g_rates;
5417 band->ht_cap = ht_cap;
5418
Yanbo Lid68bb122015-01-23 08:18:20 +08005419 /* Enable the VHT support at 2.4 GHz */
5420 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005421
5422 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5423 }
5424
5425 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5426 channels = kmemdup(ath10k_5ghz_channels,
5427 sizeof(ath10k_5ghz_channels),
5428 GFP_KERNEL);
5429 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005430 ret = -ENOMEM;
5431 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005432 }
5433
5434 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5435 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5436 band->channels = channels;
5437 band->n_bitrates = ath10k_a_rates_size;
5438 band->bitrates = ath10k_a_rates;
5439 band->ht_cap = ht_cap;
5440 band->vht_cap = vht_cap;
5441 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5442 }
5443
5444 ar->hw->wiphy->interface_modes =
5445 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005446 BIT(NL80211_IFTYPE_AP);
5447
Ben Greear46acf7b2014-05-16 17:15:38 +03005448 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5449 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5450
Bartosz Markowskid3541812013-12-10 16:20:40 +01005451 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5452 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005453 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005454 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5455 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005456
5457 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5458 IEEE80211_HW_SUPPORTS_PS |
5459 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005460 IEEE80211_HW_MFP_CAPABLE |
5461 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5462 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005463 IEEE80211_HW_AP_LINK_PS |
5464 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005465
Eliad Peller0d8614b2014-09-10 14:07:36 +03005466 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5467
Kalle Valo5e3dd152013-06-12 20:52:10 +03005468 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005469 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005470
5471 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5472 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5473 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5474 }
5475
5476 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5477 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5478
5479 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005480 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005481
Kalle Valo5e3dd152013-06-12 20:52:10 +03005482 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5483
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005484 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5485 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5486
5487 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5488 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5489 * correct Probe Responses. This is more of a hack advert..
5490 */
5491 ar->hw->wiphy->probe_resp_offload |=
5492 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5493 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5494 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5495 }
5496
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005498 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005499 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5500
5501 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005502 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5503
Kalle Valo5e3dd152013-06-12 20:52:10 +03005504 /*
5505 * on LL hardware queues are managed entirely by the FW
5506 * so we only advertise to mac we can do the queues thing
5507 */
5508 ar->hw->queues = 4;
5509
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005510 switch (ar->wmi.op_version) {
5511 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5512 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005513 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5514 ar->hw->wiphy->n_iface_combinations =
5515 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005516 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005517 break;
5518 case ATH10K_FW_WMI_OP_VERSION_10_1:
5519 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005520 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005521 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5522 ar->hw->wiphy->n_iface_combinations =
5523 ARRAY_SIZE(ath10k_10x_if_comb);
5524 break;
5525 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5526 case ATH10K_FW_WMI_OP_VERSION_MAX:
5527 WARN_ON(1);
5528 ret = -EINVAL;
5529 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005530 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005531
Michal Kazior7c199992013-07-31 10:47:57 +02005532 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5533
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005534 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5535 /* Init ath dfs pattern detector */
5536 ar->ath_common.debug_mask = ATH_DBG_DFS;
5537 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5538 NL80211_DFS_UNSET);
5539
5540 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005541 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005542 }
5543
Kalle Valo5e3dd152013-06-12 20:52:10 +03005544 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5545 ath10k_reg_notifier);
5546 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005547 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005548 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005549 }
5550
5551 ret = ieee80211_register_hw(ar->hw);
5552 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005553 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005554 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005555 }
5556
5557 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5558 ret = regulatory_hint(ar->hw->wiphy,
5559 ar->ath_common.regulatory.alpha2);
5560 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005561 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005562 }
5563
5564 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005565
5566err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005567 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005568err_free:
5569 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5570 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5571
Kalle Valo5e3dd152013-06-12 20:52:10 +03005572 return ret;
5573}
5574
5575void ath10k_mac_unregister(struct ath10k *ar)
5576{
5577 ieee80211_unregister_hw(ar->hw);
5578
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005579 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5580 ar->dfs_detector->exit(ar->dfs_detector);
5581
Kalle Valo5e3dd152013-06-12 20:52:10 +03005582 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5583 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5584
5585 SET_IEEE80211_DEV(ar->hw, NULL);
5586}