blob: d0d882d632d1dd9eeb48d48d3bc49b480f7f06ca [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030032
33/**********/
34/* Crypto */
35/**********/
36
37static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
39 enum set_key_cmd cmd,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020040 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030041{
Michal Kazior7aa7a722014-08-25 12:09:38 +020042 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030043 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
47 .key_data = key->key,
48 .macaddr = macaddr,
49 };
50
Michal Kazior548db542013-07-05 16:15:15 +030051 lockdep_assert_held(&arvif->ar->conf_mutex);
52
Kalle Valo5e3dd152013-06-12 20:52:10 +030053 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
55 else
56 arg.key_flags = WMI_KEY_GROUP;
57
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020061 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020075
76 if (def_idx)
77 arg.key_flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 break;
79 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020080 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030081 return -EOPNOTSUPP;
82 }
83
84 if (cmd == DISABLE_KEY) {
85 arg.key_cipher = WMI_CIPHER_NONE;
86 arg.key_data = NULL;
87 }
88
89 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
90}
91
92static int ath10k_install_key(struct ath10k_vif *arvif,
93 struct ieee80211_key_conf *key,
94 enum set_key_cmd cmd,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +020095 const u8 *macaddr, bool def_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +030096{
97 struct ath10k *ar = arvif->ar;
98 int ret;
99
Michal Kazior548db542013-07-05 16:15:15 +0300100 lockdep_assert_held(&ar->conf_mutex);
101
Wolfram Sang16735d02013-11-14 14:32:02 -0800102 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300103
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200104 ret = ath10k_send_key(arvif, key, cmd, macaddr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300105 if (ret)
106 return ret;
107
108 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
109 if (ret == 0)
110 return -ETIMEDOUT;
111
112 return 0;
113}
114
115static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
116 const u8 *addr)
117{
118 struct ath10k *ar = arvif->ar;
119 struct ath10k_peer *peer;
120 int ret;
121 int i;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200122 bool def_idx;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300123
124 lockdep_assert_held(&ar->conf_mutex);
125
126 spin_lock_bh(&ar->data_lock);
127 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
128 spin_unlock_bh(&ar->data_lock);
129
130 if (!peer)
131 return -ENOENT;
132
133 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
134 if (arvif->wep_keys[i] == NULL)
135 continue;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200136 /* set TX_USAGE flag for default key id */
137 if (arvif->def_wep_key_idx == i)
138 def_idx = true;
139 else
140 def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300141
142 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200143 addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 if (ret)
145 return ret;
146
Sujith Manoharanae167132014-11-25 11:46:59 +0530147 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530149 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300150 }
151
152 return 0;
153}
154
155static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
156 const u8 *addr)
157{
158 struct ath10k *ar = arvif->ar;
159 struct ath10k_peer *peer;
160 int first_errno = 0;
161 int ret;
162 int i;
163
164 lockdep_assert_held(&ar->conf_mutex);
165
166 spin_lock_bh(&ar->data_lock);
167 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
168 spin_unlock_bh(&ar->data_lock);
169
170 if (!peer)
171 return -ENOENT;
172
173 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
174 if (peer->keys[i] == NULL)
175 continue;
176
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200177 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 ret = ath10k_install_key(arvif, peer->keys[i],
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200179 DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 if (ret && first_errno == 0)
181 first_errno = ret;
182
183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200184 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 i, ret);
186
Sujith Manoharanae167132014-11-25 11:46:59 +0530187 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530189 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300190 }
191
192 return first_errno;
193}
194
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530195bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
196 u8 keyidx)
197{
198 struct ath10k_peer *peer;
199 int i;
200
201 lockdep_assert_held(&ar->data_lock);
202
203 /* We don't know which vdev this peer belongs to,
204 * since WMI doesn't give us that information.
205 *
206 * FIXME: multi-bss needs to be handled.
207 */
208 peer = ath10k_peer_find(ar, 0, addr);
209 if (!peer)
210 return false;
211
212 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
213 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
214 return true;
215 }
216
217 return false;
218}
219
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
221 struct ieee80211_key_conf *key)
222{
223 struct ath10k *ar = arvif->ar;
224 struct ath10k_peer *peer;
225 u8 addr[ETH_ALEN];
226 int first_errno = 0;
227 int ret;
228 int i;
229
230 lockdep_assert_held(&ar->conf_mutex);
231
232 for (;;) {
233 /* since ath10k_install_key we can't hold data_lock all the
234 * time, so we try to remove the keys incrementally */
235 spin_lock_bh(&ar->data_lock);
236 i = 0;
237 list_for_each_entry(peer, &ar->peers, list) {
238 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
239 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300240 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300241 peer->keys[i] = NULL;
242 break;
243 }
244 }
245
246 if (i < ARRAY_SIZE(peer->keys))
247 break;
248 }
249 spin_unlock_bh(&ar->data_lock);
250
251 if (i == ARRAY_SIZE(peer->keys))
252 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200253 /* key flags are not required to delete the key */
254 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300255 if (ret && first_errno == 0)
256 first_errno = ret;
257
258 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200259 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200260 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300261 }
262
263 return first_errno;
264}
265
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266/*********************/
267/* General utilities */
268/*********************/
269
270static inline enum wmi_phy_mode
271chan_to_phymode(const struct cfg80211_chan_def *chandef)
272{
273 enum wmi_phy_mode phymode = MODE_UNKNOWN;
274
275 switch (chandef->chan->band) {
276 case IEEE80211_BAND_2GHZ:
277 switch (chandef->width) {
278 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800279 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
280 phymode = MODE_11B;
281 else
282 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300283 break;
284 case NL80211_CHAN_WIDTH_20:
285 phymode = MODE_11NG_HT20;
286 break;
287 case NL80211_CHAN_WIDTH_40:
288 phymode = MODE_11NG_HT40;
289 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400290 case NL80211_CHAN_WIDTH_5:
291 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300292 case NL80211_CHAN_WIDTH_80:
293 case NL80211_CHAN_WIDTH_80P80:
294 case NL80211_CHAN_WIDTH_160:
295 phymode = MODE_UNKNOWN;
296 break;
297 }
298 break;
299 case IEEE80211_BAND_5GHZ:
300 switch (chandef->width) {
301 case NL80211_CHAN_WIDTH_20_NOHT:
302 phymode = MODE_11A;
303 break;
304 case NL80211_CHAN_WIDTH_20:
305 phymode = MODE_11NA_HT20;
306 break;
307 case NL80211_CHAN_WIDTH_40:
308 phymode = MODE_11NA_HT40;
309 break;
310 case NL80211_CHAN_WIDTH_80:
311 phymode = MODE_11AC_VHT80;
312 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400313 case NL80211_CHAN_WIDTH_5:
314 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315 case NL80211_CHAN_WIDTH_80P80:
316 case NL80211_CHAN_WIDTH_160:
317 phymode = MODE_UNKNOWN;
318 break;
319 }
320 break;
321 default:
322 break;
323 }
324
325 WARN_ON(phymode == MODE_UNKNOWN);
326 return phymode;
327}
328
329static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
330{
331/*
332 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
333 * 0 for no restriction
334 * 1 for 1/4 us
335 * 2 for 1/2 us
336 * 3 for 1 us
337 * 4 for 2 us
338 * 5 for 4 us
339 * 6 for 8 us
340 * 7 for 16 us
341 */
342 switch (mpdudensity) {
343 case 0:
344 return 0;
345 case 1:
346 case 2:
347 case 3:
348 /* Our lower layer calculations limit our precision to
349 1 microsecond */
350 return 1;
351 case 4:
352 return 2;
353 case 5:
354 return 4;
355 case 6:
356 return 8;
357 case 7:
358 return 16;
359 default:
360 return 0;
361 }
362}
363
364static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
365{
366 int ret;
367
368 lockdep_assert_held(&ar->conf_mutex);
369
Michal Kaziorcfd10612014-11-25 15:16:05 +0100370 if (ar->num_peers >= ar->max_num_peers)
371 return -ENOBUFS;
372
Kalle Valo5e3dd152013-06-12 20:52:10 +0300373 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800374 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200375 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200376 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300377 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800378 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300379
380 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200382 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200383 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300384 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800385 }
Michal Kazior292a7532014-11-25 15:16:04 +0100386
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100387 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300388
389 return 0;
390}
391
Kalle Valo5a13e762014-01-20 11:01:46 +0200392static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
393{
394 struct ath10k *ar = arvif->ar;
395 u32 param;
396 int ret;
397
398 param = ar->wmi.pdev_param->sta_kickout_th;
399 ret = ath10k_wmi_pdev_set_param(ar, param,
400 ATH10K_KICKOUT_THRESHOLD);
401 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200402 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200403 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200404 return ret;
405 }
406
407 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
408 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
409 ATH10K_KEEPALIVE_MIN_IDLE);
410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200411 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200412 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200413 return ret;
414 }
415
416 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
417 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
418 ATH10K_KEEPALIVE_MAX_IDLE);
419 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200420 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200421 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200422 return ret;
423 }
424
425 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
426 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
427 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200429 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200430 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200431 return ret;
432 }
433
434 return 0;
435}
436
Vivek Natarajanacab6402014-11-26 09:06:12 +0200437static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200438{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200439 struct ath10k *ar = arvif->ar;
440 u32 vdev_param;
441
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200442 vdev_param = ar->wmi.vdev_param->rts_threshold;
443 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200444}
445
446static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
447{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200448 struct ath10k *ar = arvif->ar;
449 u32 vdev_param;
450
Michal Kazior424121c2013-07-22 14:13:31 +0200451 if (value != 0xFFFFFFFF)
452 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
453 ATH10K_FRAGMT_THRESHOLD_MIN,
454 ATH10K_FRAGMT_THRESHOLD_MAX);
455
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200456 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
457 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200458}
459
Kalle Valo5e3dd152013-06-12 20:52:10 +0300460static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
461{
462 int ret;
463
464 lockdep_assert_held(&ar->conf_mutex);
465
466 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
467 if (ret)
468 return ret;
469
470 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
471 if (ret)
472 return ret;
473
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100475
Kalle Valo5e3dd152013-06-12 20:52:10 +0300476 return 0;
477}
478
479static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
480{
481 struct ath10k_peer *peer, *tmp;
482
483 lockdep_assert_held(&ar->conf_mutex);
484
485 spin_lock_bh(&ar->data_lock);
486 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
487 if (peer->vdev_id != vdev_id)
488 continue;
489
Michal Kazior7aa7a722014-08-25 12:09:38 +0200490 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300491 peer->addr, vdev_id);
492
493 list_del(&peer->list);
494 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100495 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300496 }
497 spin_unlock_bh(&ar->data_lock);
498}
499
Michal Kaziora96d7742013-07-16 09:38:56 +0200500static void ath10k_peer_cleanup_all(struct ath10k *ar)
501{
502 struct ath10k_peer *peer, *tmp;
503
504 lockdep_assert_held(&ar->conf_mutex);
505
506 spin_lock_bh(&ar->data_lock);
507 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
508 list_del(&peer->list);
509 kfree(peer);
510 }
511 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100512
513 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100514 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200515}
516
Kalle Valo5e3dd152013-06-12 20:52:10 +0300517/************************/
518/* Interface management */
519/************************/
520
Michal Kazior64badcb2014-09-18 11:18:02 +0300521void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
522{
523 struct ath10k *ar = arvif->ar;
524
525 lockdep_assert_held(&ar->data_lock);
526
527 if (!arvif->beacon)
528 return;
529
530 if (!arvif->beacon_buf)
531 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
532 arvif->beacon->len, DMA_TO_DEVICE);
533
Michal Kazioraf213192015-01-29 14:29:52 +0200534 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
535 arvif->beacon_state != ATH10K_BEACON_SENT))
536 return;
537
Michal Kazior64badcb2014-09-18 11:18:02 +0300538 dev_kfree_skb_any(arvif->beacon);
539
540 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200541 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300542}
543
544static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
545{
546 struct ath10k *ar = arvif->ar;
547
548 lockdep_assert_held(&ar->data_lock);
549
550 ath10k_mac_vif_beacon_free(arvif);
551
552 if (arvif->beacon_buf) {
553 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
554 arvif->beacon_buf, arvif->beacon_paddr);
555 arvif->beacon_buf = NULL;
556 }
557}
558
Kalle Valo5e3dd152013-06-12 20:52:10 +0300559static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
560{
561 int ret;
562
Michal Kazior548db542013-07-05 16:15:15 +0300563 lockdep_assert_held(&ar->conf_mutex);
564
Michal Kazior7962b0d2014-10-28 10:34:38 +0100565 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
566 return -ESHUTDOWN;
567
Kalle Valo5e3dd152013-06-12 20:52:10 +0300568 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
569 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
570 if (ret == 0)
571 return -ETIMEDOUT;
572
573 return 0;
574}
575
Michal Kazior1bbc0972014-04-08 09:45:47 +0300576static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577{
Michal Kaziorc930f742014-01-23 11:38:25 +0100578 struct cfg80211_chan_def *chandef = &ar->chandef;
579 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 int ret = 0;
582
583 lockdep_assert_held(&ar->conf_mutex);
584
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585 arg.vdev_id = vdev_id;
586 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100587 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588
589 /* TODO setup this dynamically, what in case we
590 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100591 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200592 arg.channel.chan_radar =
593 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
Michal Kazior89c5c842013-10-23 04:02:13 -0700595 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700596 arg.channel.max_power = channel->max_power * 2;
597 arg.channel.max_reg_power = channel->max_reg_power * 2;
598 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599
Michal Kazior7962b0d2014-10-28 10:34:38 +0100600 reinit_completion(&ar->vdev_setup_done);
601
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 ret = ath10k_wmi_vdev_start(ar, &arg);
603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200604 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200605 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 return ret;
607 }
608
609 ret = ath10k_vdev_setup_sync(ar);
610 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200611 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200612 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return ret;
614 }
615
616 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 goto vdev_stop;
621 }
622
623 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624
Michal Kazior7aa7a722014-08-25 12:09:38 +0200625 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300626 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627 return 0;
628
629vdev_stop:
630 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200632 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200633 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634
635 return ret;
636}
637
Michal Kazior1bbc0972014-04-08 09:45:47 +0300638static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300639{
640 int ret = 0;
641
642 lockdep_assert_held(&ar->conf_mutex);
643
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200644 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
645 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200646 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200647 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648
Michal Kazior7962b0d2014-10-28 10:34:38 +0100649 reinit_completion(&ar->vdev_setup_done);
650
Kalle Valo5e3dd152013-06-12 20:52:10 +0300651 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
652 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200653 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200654 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655
656 ret = ath10k_vdev_setup_sync(ar);
657 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200658 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200659 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660
Michal Kazior7aa7a722014-08-25 12:09:38 +0200661 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300662 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 return ret;
664}
665
Michal Kazior1bbc0972014-04-08 09:45:47 +0300666static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667{
668 int bit, ret = 0;
669
670 lockdep_assert_held(&ar->conf_mutex);
671
Ben Greeara9aefb32014-08-12 11:02:19 +0300672 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200673 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 return -ENOMEM;
675 }
676
Ben Greear16c11172014-09-23 14:17:16 -0700677 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300678
Ben Greear16c11172014-09-23 14:17:16 -0700679 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
683 0, ar->mac_addr);
684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200685 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200686 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300687 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688 }
689
Ben Greear16c11172014-09-23 14:17:16 -0700690 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200691 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 ar->monitor_vdev_id);
693
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695}
696
Michal Kazior1bbc0972014-04-08 09:45:47 +0300697static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300698{
699 int ret = 0;
700
701 lockdep_assert_held(&ar->conf_mutex);
702
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200705 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200706 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707 return ret;
708 }
709
Ben Greear16c11172014-09-23 14:17:16 -0700710 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300711
Michal Kazior7aa7a722014-08-25 12:09:38 +0200712 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300713 ar->monitor_vdev_id);
714 return ret;
715}
716
Michal Kazior1bbc0972014-04-08 09:45:47 +0300717static int ath10k_monitor_start(struct ath10k *ar)
718{
719 int ret;
720
721 lockdep_assert_held(&ar->conf_mutex);
722
Michal Kazior1bbc0972014-04-08 09:45:47 +0300723 ret = ath10k_monitor_vdev_create(ar);
724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200725 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300726 return ret;
727 }
728
729 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
730 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200731 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300732 ath10k_monitor_vdev_delete(ar);
733 return ret;
734 }
735
736 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300738
739 return 0;
740}
741
Michal Kazior19337472014-08-28 12:58:16 +0200742static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300743{
744 int ret;
745
746 lockdep_assert_held(&ar->conf_mutex);
747
Michal Kazior1bbc0972014-04-08 09:45:47 +0300748 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200749 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200750 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200751 return ret;
752 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300753
754 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200755 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200756 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200757 return ret;
758 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300759
760 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200761 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200762
763 return 0;
764}
765
766static int ath10k_monitor_recalc(struct ath10k *ar)
767{
768 bool should_start;
769
770 lockdep_assert_held(&ar->conf_mutex);
771
772 should_start = ar->monitor ||
773 ar->filter_flags & FIF_PROMISC_IN_BSS ||
774 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
775
776 ath10k_dbg(ar, ATH10K_DBG_MAC,
777 "mac monitor recalc started? %d should? %d\n",
778 ar->monitor_started, should_start);
779
780 if (should_start == ar->monitor_started)
781 return 0;
782
783 if (should_start)
784 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300785
786 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300787}
788
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200789static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
790{
791 struct ath10k *ar = arvif->ar;
792 u32 vdev_param, rts_cts = 0;
793
794 lockdep_assert_held(&ar->conf_mutex);
795
796 vdev_param = ar->wmi.vdev_param->enable_rtscts;
797
798 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
799 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
800
801 if (arvif->num_legacy_stations > 0)
802 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
803 WMI_RTSCTS_PROFILE);
804
805 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
806 rts_cts);
807}
808
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200809static int ath10k_start_cac(struct ath10k *ar)
810{
811 int ret;
812
813 lockdep_assert_held(&ar->conf_mutex);
814
815 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
816
Michal Kazior19337472014-08-28 12:58:16 +0200817 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200819 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200820 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
821 return ret;
822 }
823
Michal Kazior7aa7a722014-08-25 12:09:38 +0200824 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200825 ar->monitor_vdev_id);
826
827 return 0;
828}
829
830static int ath10k_stop_cac(struct ath10k *ar)
831{
832 lockdep_assert_held(&ar->conf_mutex);
833
834 /* CAC is not running - do nothing */
835 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
836 return 0;
837
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300839 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200840
Michal Kazior7aa7a722014-08-25 12:09:38 +0200841 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200842
843 return 0;
844}
845
Michal Kaziord6500972014-04-08 09:56:09 +0300846static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200847{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200848 int ret;
849
850 lockdep_assert_held(&ar->conf_mutex);
851
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200852 ath10k_stop_cac(ar);
853
Michal Kaziord6500972014-04-08 09:56:09 +0300854 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200855 return;
856
Michal Kaziord6500972014-04-08 09:56:09 +0300857 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200858 return;
859
860 ret = ath10k_start_cac(ar);
861 if (ret) {
862 /*
863 * Not possible to start CAC on current channel so starting
864 * radiation is not allowed, make this channel DFS_UNAVAILABLE
865 * by indicating that radar was detected.
866 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200867 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200868 ieee80211_radar_detected(ar->hw);
869 }
870}
871
Michal Kaziordc55e302014-07-29 12:53:36 +0300872static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300873{
874 struct ath10k *ar = arvif->ar;
875 struct cfg80211_chan_def *chandef = &ar->chandef;
876 struct wmi_vdev_start_request_arg arg = {};
877 int ret = 0;
878
879 lockdep_assert_held(&ar->conf_mutex);
880
881 reinit_completion(&ar->vdev_setup_done);
882
883 arg.vdev_id = arvif->vdev_id;
884 arg.dtim_period = arvif->dtim_period;
885 arg.bcn_intval = arvif->beacon_interval;
886
887 arg.channel.freq = chandef->chan->center_freq;
888 arg.channel.band_center_freq1 = chandef->center_freq1;
889 arg.channel.mode = chan_to_phymode(chandef);
890
891 arg.channel.min_power = 0;
892 arg.channel.max_power = chandef->chan->max_power * 2;
893 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
894 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
895
896 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
897 arg.ssid = arvif->u.ap.ssid;
898 arg.ssid_len = arvif->u.ap.ssid_len;
899 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
900
901 /* For now allow DFS for AP mode */
902 arg.channel.chan_radar =
903 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
904 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
905 arg.ssid = arvif->vif->bss_conf.ssid;
906 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
907 }
908
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 "mac vdev %d start center_freq %d phymode %s\n",
911 arg.vdev_id, arg.channel.freq,
912 ath10k_wmi_phymode_str(arg.channel.mode));
913
Michal Kaziordc55e302014-07-29 12:53:36 +0300914 if (restart)
915 ret = ath10k_wmi_vdev_restart(ar, &arg);
916 else
917 ret = ath10k_wmi_vdev_start(ar, &arg);
918
Michal Kazior72654fa2014-04-08 09:56:09 +0300919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200920 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300921 arg.vdev_id, ret);
922 return ret;
923 }
924
925 ret = ath10k_vdev_setup_sync(ar);
926 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200927 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300928 arg.vdev_id, ret);
929 return ret;
930 }
931
Michal Kaziord6500972014-04-08 09:56:09 +0300932 ar->num_started_vdevs++;
933 ath10k_recalc_radar_detection(ar);
934
Michal Kazior72654fa2014-04-08 09:56:09 +0300935 return ret;
936}
937
Michal Kaziordc55e302014-07-29 12:53:36 +0300938static int ath10k_vdev_start(struct ath10k_vif *arvif)
939{
940 return ath10k_vdev_start_restart(arvif, false);
941}
942
943static int ath10k_vdev_restart(struct ath10k_vif *arvif)
944{
945 return ath10k_vdev_start_restart(arvif, true);
946}
947
Michal Kazior72654fa2014-04-08 09:56:09 +0300948static int ath10k_vdev_stop(struct ath10k_vif *arvif)
949{
950 struct ath10k *ar = arvif->ar;
951 int ret;
952
953 lockdep_assert_held(&ar->conf_mutex);
954
955 reinit_completion(&ar->vdev_setup_done);
956
957 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200959 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300960 arvif->vdev_id, ret);
961 return ret;
962 }
963
964 ret = ath10k_vdev_setup_sync(ar);
965 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200966 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300967 arvif->vdev_id, ret);
968 return ret;
969 }
970
Michal Kaziord6500972014-04-08 09:56:09 +0300971 WARN_ON(ar->num_started_vdevs == 0);
972
973 if (ar->num_started_vdevs != 0) {
974 ar->num_started_vdevs--;
975 ath10k_recalc_radar_detection(ar);
976 }
977
Michal Kazior72654fa2014-04-08 09:56:09 +0300978 return ret;
979}
980
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200981static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
982 struct sk_buff *bcn)
983{
984 struct ath10k *ar = arvif->ar;
985 struct ieee80211_mgmt *mgmt;
986 const u8 *p2p_ie;
987 int ret;
988
989 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
990 return 0;
991
992 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
993 return 0;
994
995 mgmt = (void *)bcn->data;
996 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
997 mgmt->u.beacon.variable,
998 bcn->len - (mgmt->u.beacon.variable -
999 bcn->data));
1000 if (!p2p_ie)
1001 return -ENOENT;
1002
1003 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1004 if (ret) {
1005 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1006 arvif->vdev_id, ret);
1007 return ret;
1008 }
1009
1010 return 0;
1011}
1012
1013static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1014 u8 oui_type, size_t ie_offset)
1015{
1016 size_t len;
1017 const u8 *next;
1018 const u8 *end;
1019 u8 *ie;
1020
1021 if (WARN_ON(skb->len < ie_offset))
1022 return -EINVAL;
1023
1024 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1025 skb->data + ie_offset,
1026 skb->len - ie_offset);
1027 if (!ie)
1028 return -ENOENT;
1029
1030 len = ie[1] + 2;
1031 end = skb->data + skb->len;
1032 next = ie + len;
1033
1034 if (WARN_ON(next > end))
1035 return -EINVAL;
1036
1037 memmove(ie, next, end - next);
1038 skb_trim(skb, skb->len - len);
1039
1040 return 0;
1041}
1042
1043static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1044{
1045 struct ath10k *ar = arvif->ar;
1046 struct ieee80211_hw *hw = ar->hw;
1047 struct ieee80211_vif *vif = arvif->vif;
1048 struct ieee80211_mutable_offsets offs = {};
1049 struct sk_buff *bcn;
1050 int ret;
1051
1052 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1053 return 0;
1054
1055 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1056 if (!bcn) {
1057 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1058 return -EPERM;
1059 }
1060
1061 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1062 if (ret) {
1063 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1064 kfree_skb(bcn);
1065 return ret;
1066 }
1067
1068 /* P2P IE is inserted by firmware automatically (as configured above)
1069 * so remove it from the base beacon template to avoid duplicate P2P
1070 * IEs in beacon frames.
1071 */
1072 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1073 offsetof(struct ieee80211_mgmt,
1074 u.beacon.variable));
1075
1076 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1077 0, NULL, 0);
1078 kfree_skb(bcn);
1079
1080 if (ret) {
1081 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1082 ret);
1083 return ret;
1084 }
1085
1086 return 0;
1087}
1088
1089static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1090{
1091 struct ath10k *ar = arvif->ar;
1092 struct ieee80211_hw *hw = ar->hw;
1093 struct ieee80211_vif *vif = arvif->vif;
1094 struct sk_buff *prb;
1095 int ret;
1096
1097 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1098 return 0;
1099
1100 prb = ieee80211_proberesp_get(hw, vif);
1101 if (!prb) {
1102 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1103 return -EPERM;
1104 }
1105
1106 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1107 kfree_skb(prb);
1108
1109 if (ret) {
1110 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1111 ret);
1112 return ret;
1113 }
1114
1115 return 0;
1116}
1117
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001119 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001120{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001121 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 int ret = 0;
1123
Michal Kazior548db542013-07-05 16:15:15 +03001124 lockdep_assert_held(&arvif->ar->conf_mutex);
1125
Kalle Valo5e3dd152013-06-12 20:52:10 +03001126 if (!info->enable_beacon) {
1127 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001128
1129 arvif->is_started = false;
1130 arvif->is_up = false;
1131
Michal Kazior748afc42014-01-23 12:48:21 +01001132 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001133 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001134 spin_unlock_bh(&arvif->ar->data_lock);
1135
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 return;
1137 }
1138
1139 arvif->tx_seq_no = 0x1000;
1140
1141 ret = ath10k_vdev_start(arvif);
1142 if (ret)
1143 return;
1144
Michal Kaziorc930f742014-01-23 11:38:25 +01001145 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001146 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001147
1148 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1149 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001150 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001151 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001152 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001153 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154 return;
1155 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001156
1157 arvif->is_started = true;
1158 arvif->is_up = true;
1159
Michal Kazior7aa7a722014-08-25 12:09:38 +02001160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161}
1162
1163static void ath10k_control_ibss(struct ath10k_vif *arvif,
1164 struct ieee80211_bss_conf *info,
1165 const u8 self_peer[ETH_ALEN])
1166{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001167 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001168 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169 int ret = 0;
1170
Michal Kazior548db542013-07-05 16:15:15 +03001171 lockdep_assert_held(&arvif->ar->conf_mutex);
1172
Kalle Valo5e3dd152013-06-12 20:52:10 +03001173 if (!info->ibss_joined) {
1174 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1175 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001176 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177 self_peer, arvif->vdev_id, ret);
1178
Michal Kaziorc930f742014-01-23 11:38:25 +01001179 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001180 return;
1181
Michal Kaziorc930f742014-01-23 11:38:25 +01001182 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001183
1184 return;
1185 }
1186
1187 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1188 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001189 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001190 self_peer, arvif->vdev_id, ret);
1191 return;
1192 }
1193
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001194 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1195 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001196 ATH10K_DEFAULT_ATIM);
1197 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001198 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001199 arvif->vdev_id, ret);
1200}
1201
Michal Kazior9f9b5742014-12-12 12:41:36 +01001202static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1203{
1204 struct ath10k *ar = arvif->ar;
1205 u32 param;
1206 u32 value;
1207 int ret;
1208
1209 lockdep_assert_held(&arvif->ar->conf_mutex);
1210
1211 if (arvif->u.sta.uapsd)
1212 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1213 else
1214 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1215
1216 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1217 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1218 if (ret) {
1219 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1220 value, arvif->vdev_id, ret);
1221 return ret;
1222 }
1223
1224 return 0;
1225}
1226
1227static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1228{
1229 struct ath10k *ar = arvif->ar;
1230 u32 param;
1231 u32 value;
1232 int ret;
1233
1234 lockdep_assert_held(&arvif->ar->conf_mutex);
1235
1236 if (arvif->u.sta.uapsd)
1237 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1238 else
1239 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1240
1241 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1242 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1243 param, value);
1244 if (ret) {
1245 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1246 value, arvif->vdev_id, ret);
1247 return ret;
1248 }
1249
1250 return 0;
1251}
1252
Michal Kaziorad088bf2013-10-16 15:44:46 +03001253static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001255 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001256 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001257 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258 enum wmi_sta_powersave_param param;
1259 enum wmi_sta_ps_mode psmode;
1260 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001261 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001262
Michal Kazior548db542013-07-05 16:15:15 +03001263 lockdep_assert_held(&arvif->ar->conf_mutex);
1264
Michal Kaziorad088bf2013-10-16 15:44:46 +03001265 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1266 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267
Michal Kaziorbf14e652014-12-12 12:41:38 +01001268 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001269 psmode = WMI_STA_PS_MODE_ENABLED;
1270 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1271
Michal Kazior526549a2014-12-12 12:41:37 +01001272 ps_timeout = conf->dynamic_ps_timeout;
1273 if (ps_timeout == 0) {
1274 /* Firmware doesn't like 0 */
1275 ps_timeout = ieee80211_tu_to_usec(
1276 vif->bss_conf.beacon_int) / 1000;
1277 }
1278
Michal Kaziorad088bf2013-10-16 15:44:46 +03001279 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001280 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001282 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001283 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001284 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001285 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286 } else {
1287 psmode = WMI_STA_PS_MODE_DISABLED;
1288 }
1289
Michal Kazior7aa7a722014-08-25 12:09:38 +02001290 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001291 arvif->vdev_id, psmode ? "enable" : "disable");
1292
Michal Kaziorad088bf2013-10-16 15:44:46 +03001293 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001295 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001296 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001297 return ret;
1298 }
1299
1300 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001301}
1302
Michal Kazior46725b12015-01-28 09:57:49 +02001303static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1304{
1305 struct ath10k *ar = arvif->ar;
1306 struct wmi_sta_keepalive_arg arg = {};
1307 int ret;
1308
1309 lockdep_assert_held(&arvif->ar->conf_mutex);
1310
1311 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1312 return 0;
1313
1314 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1315 return 0;
1316
1317 /* Some firmware revisions have a bug and ignore the `enabled` field.
1318 * Instead use the interval to disable the keepalive.
1319 */
1320 arg.vdev_id = arvif->vdev_id;
1321 arg.enabled = 1;
1322 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1323 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1324
1325 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1326 if (ret) {
1327 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1328 arvif->vdev_id, ret);
1329 return ret;
1330 }
1331
1332 return 0;
1333}
1334
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335/**********************/
1336/* Station management */
1337/**********************/
1338
Michal Kazior590922a2014-10-21 10:10:29 +03001339static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1340 struct ieee80211_vif *vif)
1341{
1342 /* Some firmware revisions have unstable STA powersave when listen
1343 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1344 * generate NullFunc frames properly even if buffered frames have been
1345 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1346 * buffered frames. Often pinging the device from AP would simply fail.
1347 *
1348 * As a workaround set it to 1.
1349 */
1350 if (vif->type == NL80211_IFTYPE_STATION)
1351 return 1;
1352
1353 return ar->hw->conf.listen_interval;
1354}
1355
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001357 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001358 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 struct wmi_peer_assoc_complete_arg *arg)
1360{
Michal Kazior590922a2014-10-21 10:10:29 +03001361 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1362
Michal Kazior548db542013-07-05 16:15:15 +03001363 lockdep_assert_held(&ar->conf_mutex);
1364
Kalle Valob25f32c2014-09-14 12:50:49 +03001365 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 arg->vdev_id = arvif->vdev_id;
1367 arg->peer_aid = sta->aid;
1368 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001369 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001370 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001371 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001372}
1373
1374static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001375 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001376 struct wmi_peer_assoc_complete_arg *arg)
1377{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001378 struct ieee80211_bss_conf *info = &vif->bss_conf;
1379 struct cfg80211_bss *bss;
1380 const u8 *rsnie = NULL;
1381 const u8 *wpaie = NULL;
1382
Michal Kazior548db542013-07-05 16:15:15 +03001383 lockdep_assert_held(&ar->conf_mutex);
1384
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1386 info->bssid, NULL, 0, 0, 0);
1387 if (bss) {
1388 const struct cfg80211_bss_ies *ies;
1389
1390 rcu_read_lock();
1391 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1392
1393 ies = rcu_dereference(bss->ies);
1394
1395 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001396 WLAN_OUI_TYPE_MICROSOFT_WPA,
1397 ies->data,
1398 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001399 rcu_read_unlock();
1400 cfg80211_put_bss(ar->hw->wiphy, bss);
1401 }
1402
1403 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1404 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001405 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001406 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1407 }
1408
1409 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001410 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001411 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1412 }
1413}
1414
1415static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1416 struct ieee80211_sta *sta,
1417 struct wmi_peer_assoc_complete_arg *arg)
1418{
1419 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1420 const struct ieee80211_supported_band *sband;
1421 const struct ieee80211_rate *rates;
1422 u32 ratemask;
1423 int i;
1424
Michal Kazior548db542013-07-05 16:15:15 +03001425 lockdep_assert_held(&ar->conf_mutex);
1426
Kalle Valo5e3dd152013-06-12 20:52:10 +03001427 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1428 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1429 rates = sband->bitrates;
1430
1431 rateset->num_rates = 0;
1432
1433 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1434 if (!(ratemask & 1))
1435 continue;
1436
1437 rateset->rates[rateset->num_rates] = rates->hw_value;
1438 rateset->num_rates++;
1439 }
1440}
1441
1442static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1443 struct ieee80211_sta *sta,
1444 struct wmi_peer_assoc_complete_arg *arg)
1445{
1446 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001448 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001449
Michal Kazior548db542013-07-05 16:15:15 +03001450 lockdep_assert_held(&ar->conf_mutex);
1451
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452 if (!ht_cap->ht_supported)
1453 return;
1454
1455 arg->peer_flags |= WMI_PEER_HT;
1456 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1457 ht_cap->ampdu_factor)) - 1;
1458
1459 arg->peer_mpdu_density =
1460 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1461
1462 arg->peer_ht_caps = ht_cap->cap;
1463 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1464
1465 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1466 arg->peer_flags |= WMI_PEER_LDPC;
1467
1468 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1469 arg->peer_flags |= WMI_PEER_40MHZ;
1470 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1471 }
1472
1473 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1474 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1475
1476 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1477 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1478
1479 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1480 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1481 arg->peer_flags |= WMI_PEER_STBC;
1482 }
1483
1484 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1486 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1487 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1488 arg->peer_rate_caps |= stbc;
1489 arg->peer_flags |= WMI_PEER_STBC;
1490 }
1491
Kalle Valo5e3dd152013-06-12 20:52:10 +03001492 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1493 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1494 else if (ht_cap->mcs.rx_mask[1])
1495 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1496
1497 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1498 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1499 arg->peer_ht_rates.rates[n++] = i;
1500
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001501 /*
1502 * This is a workaround for HT-enabled STAs which break the spec
1503 * and have no HT capabilities RX mask (no HT RX MCS map).
1504 *
1505 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1506 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1507 *
1508 * Firmware asserts if such situation occurs.
1509 */
1510 if (n == 0) {
1511 arg->peer_ht_rates.num_rates = 8;
1512 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1513 arg->peer_ht_rates.rates[i] = i;
1514 } else {
1515 arg->peer_ht_rates.num_rates = n;
1516 arg->peer_num_spatial_streams = sta->rx_nss;
1517 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518
Michal Kazior7aa7a722014-08-25 12:09:38 +02001519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001520 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001521 arg->peer_ht_rates.num_rates,
1522 arg->peer_num_spatial_streams);
1523}
1524
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001525static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1526 struct ath10k_vif *arvif,
1527 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528{
1529 u32 uapsd = 0;
1530 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001531 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001532
Michal Kazior548db542013-07-05 16:15:15 +03001533 lockdep_assert_held(&ar->conf_mutex);
1534
Kalle Valo5e3dd152013-06-12 20:52:10 +03001535 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001536 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001537 sta->uapsd_queues, sta->max_sp);
1538
Kalle Valo5e3dd152013-06-12 20:52:10 +03001539 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1540 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1541 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1542 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1543 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1544 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1545 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1546 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1547 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1548 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1549 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1550 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1551
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1553 max_sp = sta->max_sp;
1554
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001555 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1556 sta->addr,
1557 WMI_AP_PS_PEER_PARAM_UAPSD,
1558 uapsd);
1559 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001560 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001561 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001562 return ret;
1563 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001564
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001565 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1566 sta->addr,
1567 WMI_AP_PS_PEER_PARAM_MAX_SP,
1568 max_sp);
1569 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001570 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001571 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001572 return ret;
1573 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574
1575 /* TODO setup this based on STA listen interval and
1576 beacon interval. Currently we don't know
1577 sta->listen_interval - mac80211 patch required.
1578 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001579 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001580 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1581 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001583 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001584 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001585 return ret;
1586 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001589 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590}
1591
1592static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1593 struct ieee80211_sta *sta,
1594 struct wmi_peer_assoc_complete_arg *arg)
1595{
1596 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001597 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001598
1599 if (!vht_cap->vht_supported)
1600 return;
1601
1602 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001603
1604 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1605 arg->peer_flags |= WMI_PEER_VHT_2G;
1606
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 arg->peer_vht_caps = vht_cap->cap;
1608
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001609 ampdu_factor = (vht_cap->cap &
1610 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1611 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1612
1613 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1614 * zero in VHT IE. Using it would result in degraded throughput.
1615 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1616 * it if VHT max_mpdu is smaller. */
1617 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1618 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1619 ampdu_factor)) - 1);
1620
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1622 arg->peer_flags |= WMI_PEER_80MHZ;
1623
1624 arg->peer_vht_rates.rx_max_rate =
1625 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1626 arg->peer_vht_rates.rx_mcs_set =
1627 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1628 arg->peer_vht_rates.tx_max_rate =
1629 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1630 arg->peer_vht_rates.tx_mcs_set =
1631 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1632
Michal Kazior7aa7a722014-08-25 12:09:38 +02001633 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001634 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635}
1636
1637static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001638 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 struct wmi_peer_assoc_complete_arg *arg)
1641{
Michal Kazior590922a2014-10-21 10:10:29 +03001642 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1643
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 switch (arvif->vdev_type) {
1645 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001646 if (sta->wme)
1647 arg->peer_flags |= WMI_PEER_QOS;
1648
1649 if (sta->wme && sta->uapsd_queues) {
1650 arg->peer_flags |= WMI_PEER_APSD;
1651 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 break;
1654 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001655 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001656 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001657 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001658 case WMI_VDEV_TYPE_IBSS:
1659 if (sta->wme)
1660 arg->peer_flags |= WMI_PEER_QOS;
1661 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 default:
1663 break;
1664 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001665
1666 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1667 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668}
1669
Michal Kazior91b12082014-12-12 12:41:35 +01001670static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1671{
1672 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1673 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1674}
1675
Kalle Valo5e3dd152013-06-12 20:52:10 +03001676static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001677 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001678 struct ieee80211_sta *sta,
1679 struct wmi_peer_assoc_complete_arg *arg)
1680{
1681 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1682
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683 switch (ar->hw->conf.chandef.chan->band) {
1684 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001685 if (sta->vht_cap.vht_supported) {
1686 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1687 phymode = MODE_11AC_VHT40;
1688 else
1689 phymode = MODE_11AC_VHT20;
1690 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1692 phymode = MODE_11NG_HT40;
1693 else
1694 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001695 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001697 } else {
1698 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699 }
1700
1701 break;
1702 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001703 /*
1704 * Check VHT first.
1705 */
1706 if (sta->vht_cap.vht_supported) {
1707 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1708 phymode = MODE_11AC_VHT80;
1709 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1710 phymode = MODE_11AC_VHT40;
1711 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1712 phymode = MODE_11AC_VHT20;
1713 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001714 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1715 phymode = MODE_11NA_HT40;
1716 else
1717 phymode = MODE_11NA_HT20;
1718 } else {
1719 phymode = MODE_11A;
1720 }
1721
1722 break;
1723 default:
1724 break;
1725 }
1726
Michal Kazior7aa7a722014-08-25 12:09:38 +02001727 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001728 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001729
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 arg->peer_phymode = phymode;
1731 WARN_ON(phymode == MODE_UNKNOWN);
1732}
1733
Kalle Valob9ada652013-10-16 15:44:46 +03001734static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001735 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001736 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001737 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738{
Michal Kazior548db542013-07-05 16:15:15 +03001739 lockdep_assert_held(&ar->conf_mutex);
1740
Kalle Valob9ada652013-10-16 15:44:46 +03001741 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742
Michal Kazior590922a2014-10-21 10:10:29 +03001743 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1744 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001745 ath10k_peer_assoc_h_rates(ar, sta, arg);
1746 ath10k_peer_assoc_h_ht(ar, sta, arg);
1747 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001748 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1749 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750
Kalle Valob9ada652013-10-16 15:44:46 +03001751 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752}
1753
Michal Kazior90046f52014-02-14 14:45:51 +01001754static const u32 ath10k_smps_map[] = {
1755 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1756 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1757 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1758 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1759};
1760
1761static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1762 const u8 *addr,
1763 const struct ieee80211_sta_ht_cap *ht_cap)
1764{
1765 int smps;
1766
1767 if (!ht_cap->ht_supported)
1768 return 0;
1769
1770 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1771 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1772
1773 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1774 return -EINVAL;
1775
1776 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1777 WMI_PEER_SMPS_STATE,
1778 ath10k_smps_map[smps]);
1779}
1780
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781/* can be called only in mac80211 callbacks due to `key_count` usage */
1782static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1783 struct ieee80211_vif *vif,
1784 struct ieee80211_bss_conf *bss_conf)
1785{
1786 struct ath10k *ar = hw->priv;
1787 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001788 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001789 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 struct ieee80211_sta *ap_sta;
1791 int ret;
1792
Michal Kazior548db542013-07-05 16:15:15 +03001793 lockdep_assert_held(&ar->conf_mutex);
1794
Michal Kazior077efc82014-10-21 10:10:29 +03001795 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1796 arvif->vdev_id, arvif->bssid, arvif->aid);
1797
Kalle Valo5e3dd152013-06-12 20:52:10 +03001798 rcu_read_lock();
1799
1800 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1801 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001802 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001803 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001804 rcu_read_unlock();
1805 return;
1806 }
1807
Michal Kazior90046f52014-02-14 14:45:51 +01001808 /* ap_sta must be accessed only within rcu section which must be left
1809 * before calling ath10k_setup_peer_smps() which might sleep. */
1810 ht_cap = ap_sta->ht_cap;
1811
Michal Kazior590922a2014-10-21 10:10:29 +03001812 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001813 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001814 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001815 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816 rcu_read_unlock();
1817 return;
1818 }
1819
1820 rcu_read_unlock();
1821
Kalle Valob9ada652013-10-16 15:44:46 +03001822 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001824 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001825 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001826 return;
1827 }
1828
Michal Kazior90046f52014-02-14 14:45:51 +01001829 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1830 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001831 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001832 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001833 return;
1834 }
1835
Michal Kazior7aa7a722014-08-25 12:09:38 +02001836 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001837 "mac vdev %d up (associated) bssid %pM aid %d\n",
1838 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1839
Michal Kazior077efc82014-10-21 10:10:29 +03001840 WARN_ON(arvif->is_up);
1841
Michal Kaziorc930f742014-01-23 11:38:25 +01001842 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001843 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001844
1845 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1846 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001847 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001849 return;
1850 }
1851
1852 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853}
1854
Kalle Valo5e3dd152013-06-12 20:52:10 +03001855static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1856 struct ieee80211_vif *vif)
1857{
1858 struct ath10k *ar = hw->priv;
1859 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1860 int ret;
1861
Michal Kazior548db542013-07-05 16:15:15 +03001862 lockdep_assert_held(&ar->conf_mutex);
1863
Michal Kazior077efc82014-10-21 10:10:29 +03001864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1865 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001866
Kalle Valo5e3dd152013-06-12 20:52:10 +03001867 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001868 if (ret)
1869 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1870 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001872 arvif->def_wep_key_idx = -1;
1873
Michal Kaziorc930f742014-01-23 11:38:25 +01001874 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001875}
1876
Michal Kazior590922a2014-10-21 10:10:29 +03001877static int ath10k_station_assoc(struct ath10k *ar,
1878 struct ieee80211_vif *vif,
1879 struct ieee80211_sta *sta,
1880 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881{
Michal Kazior590922a2014-10-21 10:10:29 +03001882 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001883 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884 int ret = 0;
1885
Michal Kazior548db542013-07-05 16:15:15 +03001886 lockdep_assert_held(&ar->conf_mutex);
1887
Michal Kazior590922a2014-10-21 10:10:29 +03001888 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001890 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001891 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001892 return ret;
1893 }
1894
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001895 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001896 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1897 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001898 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001899 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001900 return ret;
1901 }
1902
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001903 /* Re-assoc is run only to update supported rates for given station. It
1904 * doesn't make much sense to reconfigure the peer completely.
1905 */
1906 if (!reassoc) {
1907 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1908 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001909 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001910 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001911 arvif->vdev_id, ret);
1912 return ret;
1913 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001914
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001915 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1916 if (ret) {
1917 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1918 sta->addr, arvif->vdev_id, ret);
1919 return ret;
1920 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001921
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001922 if (!sta->wme) {
1923 arvif->num_legacy_stations++;
1924 ret = ath10k_recalc_rtscts_prot(arvif);
1925 if (ret) {
1926 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1927 arvif->vdev_id, ret);
1928 return ret;
1929 }
1930 }
1931
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001932 /* Plumb cached keys only for static WEP */
1933 if (arvif->def_wep_key_idx != -1) {
1934 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1935 if (ret) {
1936 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1937 arvif->vdev_id, ret);
1938 return ret;
1939 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 }
1941 }
1942
Kalle Valo5e3dd152013-06-12 20:52:10 +03001943 return ret;
1944}
1945
Michal Kazior590922a2014-10-21 10:10:29 +03001946static int ath10k_station_disassoc(struct ath10k *ar,
1947 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 struct ieee80211_sta *sta)
1949{
Michal Kazior590922a2014-10-21 10:10:29 +03001950 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 int ret = 0;
1952
1953 lockdep_assert_held(&ar->conf_mutex);
1954
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001955 if (!sta->wme) {
1956 arvif->num_legacy_stations--;
1957 ret = ath10k_recalc_rtscts_prot(arvif);
1958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001959 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001960 arvif->vdev_id, ret);
1961 return ret;
1962 }
1963 }
1964
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1966 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001967 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001968 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969 return ret;
1970 }
1971
1972 return ret;
1973}
1974
1975/**************/
1976/* Regulatory */
1977/**************/
1978
1979static int ath10k_update_channel_list(struct ath10k *ar)
1980{
1981 struct ieee80211_hw *hw = ar->hw;
1982 struct ieee80211_supported_band **bands;
1983 enum ieee80211_band band;
1984 struct ieee80211_channel *channel;
1985 struct wmi_scan_chan_list_arg arg = {0};
1986 struct wmi_channel_arg *ch;
1987 bool passive;
1988 int len;
1989 int ret;
1990 int i;
1991
Michal Kazior548db542013-07-05 16:15:15 +03001992 lockdep_assert_held(&ar->conf_mutex);
1993
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 bands = hw->wiphy->bands;
1995 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1996 if (!bands[band])
1997 continue;
1998
1999 for (i = 0; i < bands[band]->n_channels; i++) {
2000 if (bands[band]->channels[i].flags &
2001 IEEE80211_CHAN_DISABLED)
2002 continue;
2003
2004 arg.n_channels++;
2005 }
2006 }
2007
2008 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2009 arg.channels = kzalloc(len, GFP_KERNEL);
2010 if (!arg.channels)
2011 return -ENOMEM;
2012
2013 ch = arg.channels;
2014 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2015 if (!bands[band])
2016 continue;
2017
2018 for (i = 0; i < bands[band]->n_channels; i++) {
2019 channel = &bands[band]->channels[i];
2020
2021 if (channel->flags & IEEE80211_CHAN_DISABLED)
2022 continue;
2023
2024 ch->allow_ht = true;
2025
2026 /* FIXME: when should we really allow VHT? */
2027 ch->allow_vht = true;
2028
2029 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002030 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002031
2032 ch->ht40plus =
2033 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2034
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002035 ch->chan_radar =
2036 !!(channel->flags & IEEE80211_CHAN_RADAR);
2037
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002038 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 ch->passive = passive;
2040
2041 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002042 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002043 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002044 ch->max_power = channel->max_power * 2;
2045 ch->max_reg_power = channel->max_reg_power * 2;
2046 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047 ch->reg_class_id = 0; /* FIXME */
2048
2049 /* FIXME: why use only legacy modes, why not any
2050 * HT/VHT modes? Would that even make any
2051 * difference? */
2052 if (channel->band == IEEE80211_BAND_2GHZ)
2053 ch->mode = MODE_11G;
2054 else
2055 ch->mode = MODE_11A;
2056
2057 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2058 continue;
2059
Michal Kazior7aa7a722014-08-25 12:09:38 +02002060 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002061 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2062 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002063 ch->freq, ch->max_power, ch->max_reg_power,
2064 ch->max_antenna_gain, ch->mode);
2065
2066 ch++;
2067 }
2068 }
2069
2070 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2071 kfree(arg.channels);
2072
2073 return ret;
2074}
2075
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002076static enum wmi_dfs_region
2077ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2078{
2079 switch (dfs_region) {
2080 case NL80211_DFS_UNSET:
2081 return WMI_UNINIT_DFS_DOMAIN;
2082 case NL80211_DFS_FCC:
2083 return WMI_FCC_DFS_DOMAIN;
2084 case NL80211_DFS_ETSI:
2085 return WMI_ETSI_DFS_DOMAIN;
2086 case NL80211_DFS_JP:
2087 return WMI_MKK4_DFS_DOMAIN;
2088 }
2089 return WMI_UNINIT_DFS_DOMAIN;
2090}
2091
Michal Kaziorf7843d72013-07-16 09:38:52 +02002092static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002096 enum wmi_dfs_region wmi_dfs_reg;
2097 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002098
Michal Kaziorf7843d72013-07-16 09:38:52 +02002099 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002100
2101 ret = ath10k_update_channel_list(ar);
2102 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002103 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104
2105 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002106
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002107 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2108 nl_dfs_reg = ar->dfs_detector->region;
2109 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2110 } else {
2111 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2112 }
2113
Kalle Valo5e3dd152013-06-12 20:52:10 +03002114 /* Target allows setting up per-band regdomain but ath_common provides
2115 * a combined one only */
2116 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002117 regpair->reg_domain,
2118 regpair->reg_domain, /* 2ghz */
2119 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002120 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002121 regpair->reg_5ghz_ctl,
2122 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002124 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002125}
Michal Kazior548db542013-07-05 16:15:15 +03002126
Michal Kaziorf7843d72013-07-16 09:38:52 +02002127static void ath10k_reg_notifier(struct wiphy *wiphy,
2128 struct regulatory_request *request)
2129{
2130 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2131 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002132 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002133
2134 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2135
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002136 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002137 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002138 request->dfs_region);
2139 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2140 request->dfs_region);
2141 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002142 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002143 request->dfs_region);
2144 }
2145
Michal Kaziorf7843d72013-07-16 09:38:52 +02002146 mutex_lock(&ar->conf_mutex);
2147 if (ar->state == ATH10K_STATE_ON)
2148 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002149 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150}
2151
2152/***************/
2153/* TX handlers */
2154/***************/
2155
Michal Kazior42c3aa62013-10-02 11:03:38 +02002156static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2157{
2158 if (ieee80211_is_mgmt(hdr->frame_control))
2159 return HTT_DATA_TX_EXT_TID_MGMT;
2160
2161 if (!ieee80211_is_data_qos(hdr->frame_control))
2162 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2163
2164 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2165 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2166
2167 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2168}
2169
Michal Kazior2b37c292014-09-02 11:00:22 +03002170static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002171{
Michal Kazior2b37c292014-09-02 11:00:22 +03002172 if (vif)
2173 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002174
Michal Kazior1bbc0972014-04-08 09:45:47 +03002175 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002176 return ar->monitor_vdev_id;
2177
Michal Kazior7aa7a722014-08-25 12:09:38 +02002178 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002179 return 0;
2180}
2181
Michal Kazior4b604552014-07-21 21:03:09 +03002182/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2183 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184 */
Michal Kazior4b604552014-07-21 21:03:09 +03002185static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186{
2187 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002188 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189 u8 *qos_ctl;
2190
2191 if (!ieee80211_is_data_qos(hdr->frame_control))
2192 return;
2193
2194 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002195 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2196 skb->data, (void *)qos_ctl - (void *)skb->data);
2197 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002198
2199 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2200 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2201 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2202 * it is safe to downgrade to NullFunc.
2203 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002204 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002205 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2206 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2207 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2208 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209}
2210
Michal Kazior4b604552014-07-21 21:03:09 +03002211static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2212 struct ieee80211_vif *vif,
2213 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214{
2215 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2217
2218 /* This is case only for P2P_GO */
2219 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2220 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2221 return;
2222
2223 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2224 spin_lock_bh(&ar->data_lock);
2225 if (arvif->u.ap.noa_data)
2226 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2227 GFP_ATOMIC))
2228 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2229 arvif->u.ap.noa_data,
2230 arvif->u.ap.noa_len);
2231 spin_unlock_bh(&ar->data_lock);
2232 }
2233}
2234
Michal Kazior8d6d3622014-11-24 14:58:31 +01002235static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2236{
2237 /* FIXME: Not really sure since when the behaviour changed. At some
2238 * point new firmware stopped requiring creation of peer entries for
2239 * offchannel tx (and actually creating them causes issues with wmi-htc
2240 * tx credit replenishment and reliability). Assuming it's at least 3.4
2241 * because that's when the `freq` was introduced to TX_FRM HTT command.
2242 */
2243 return !(ar->htt.target_version_major >= 3 &&
2244 ar->htt.target_version_minor >= 4);
2245}
2246
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2248{
2249 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002250 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002251
Michal Kazior961d4c32013-08-09 10:13:34 +02002252 if (ar->htt.target_version_major >= 3) {
2253 /* Since HTT 3.0 there is no separate mgmt tx command */
2254 ret = ath10k_htt_tx(&ar->htt, skb);
2255 goto exit;
2256 }
2257
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002258 if (ieee80211_is_mgmt(hdr->frame_control)) {
2259 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2260 ar->fw_features)) {
2261 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2262 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002263 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002264 ret = -EBUSY;
2265 goto exit;
2266 }
2267
2268 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2269 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2270 } else {
2271 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2272 }
2273 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2274 ar->fw_features) &&
2275 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 /* FW does not report tx status properly for NullFunc frames
2277 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002278 * those frames when it detects link/beacon loss and depends
2279 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002280 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002281 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002282 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284
Michal Kazior961d4c32013-08-09 10:13:34 +02002285exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002287 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2288 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289 ieee80211_free_txskb(ar->hw, skb);
2290 }
2291}
2292
2293void ath10k_offchan_tx_purge(struct ath10k *ar)
2294{
2295 struct sk_buff *skb;
2296
2297 for (;;) {
2298 skb = skb_dequeue(&ar->offchan_tx_queue);
2299 if (!skb)
2300 break;
2301
2302 ieee80211_free_txskb(ar->hw, skb);
2303 }
2304}
2305
2306void ath10k_offchan_tx_work(struct work_struct *work)
2307{
2308 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2309 struct ath10k_peer *peer;
2310 struct ieee80211_hdr *hdr;
2311 struct sk_buff *skb;
2312 const u8 *peer_addr;
2313 int vdev_id;
2314 int ret;
2315
2316 /* FW requirement: We must create a peer before FW will send out
2317 * an offchannel frame. Otherwise the frame will be stuck and
2318 * never transmitted. We delete the peer upon tx completion.
2319 * It is unlikely that a peer for offchannel tx will already be
2320 * present. However it may be in some rare cases so account for that.
2321 * Otherwise we might remove a legitimate peer and break stuff. */
2322
2323 for (;;) {
2324 skb = skb_dequeue(&ar->offchan_tx_queue);
2325 if (!skb)
2326 break;
2327
2328 mutex_lock(&ar->conf_mutex);
2329
Michal Kazior7aa7a722014-08-25 12:09:38 +02002330 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 skb);
2332
2333 hdr = (struct ieee80211_hdr *)skb->data;
2334 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002335 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336
2337 spin_lock_bh(&ar->data_lock);
2338 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2339 spin_unlock_bh(&ar->data_lock);
2340
2341 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002342 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002343 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344 peer_addr, vdev_id);
2345
2346 if (!peer) {
2347 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2348 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002349 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350 peer_addr, vdev_id, ret);
2351 }
2352
2353 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002354 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355 ar->offchan_tx_skb = skb;
2356 spin_unlock_bh(&ar->data_lock);
2357
2358 ath10k_tx_htt(ar, skb);
2359
2360 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2361 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002362 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002363 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002364 skb);
2365
2366 if (!peer) {
2367 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2368 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002369 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 peer_addr, vdev_id, ret);
2371 }
2372
2373 mutex_unlock(&ar->conf_mutex);
2374 }
2375}
2376
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002377void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2378{
2379 struct sk_buff *skb;
2380
2381 for (;;) {
2382 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2383 if (!skb)
2384 break;
2385
2386 ieee80211_free_txskb(ar->hw, skb);
2387 }
2388}
2389
2390void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2391{
2392 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2393 struct sk_buff *skb;
2394 int ret;
2395
2396 for (;;) {
2397 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2398 if (!skb)
2399 break;
2400
2401 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002402 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002403 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002404 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002405 ieee80211_free_txskb(ar->hw, skb);
2406 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002407 }
2408}
2409
Kalle Valo5e3dd152013-06-12 20:52:10 +03002410/************/
2411/* Scanning */
2412/************/
2413
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002414void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002415{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002416 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002417
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002418 switch (ar->scan.state) {
2419 case ATH10K_SCAN_IDLE:
2420 break;
2421 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002422 if (ar->scan.is_roc)
2423 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002424 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002425 case ATH10K_SCAN_ABORTING:
2426 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002427 ieee80211_scan_completed(ar->hw,
2428 (ar->scan.state ==
2429 ATH10K_SCAN_ABORTING));
2430 /* fall through */
2431 case ATH10K_SCAN_STARTING:
2432 ar->scan.state = ATH10K_SCAN_IDLE;
2433 ar->scan_channel = NULL;
2434 ath10k_offchan_tx_purge(ar);
2435 cancel_delayed_work(&ar->scan.timeout);
2436 complete_all(&ar->scan.completed);
2437 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002438 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002439}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002440
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002441void ath10k_scan_finish(struct ath10k *ar)
2442{
2443 spin_lock_bh(&ar->data_lock);
2444 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445 spin_unlock_bh(&ar->data_lock);
2446}
2447
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002448static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002449{
2450 struct wmi_stop_scan_arg arg = {
2451 .req_id = 1, /* FIXME */
2452 .req_type = WMI_SCAN_STOP_ONE,
2453 .u.scan_id = ATH10K_SCAN_ID,
2454 };
2455 int ret;
2456
2457 lockdep_assert_held(&ar->conf_mutex);
2458
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 ret = ath10k_wmi_stop_scan(ar, &arg);
2460 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002461 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002462 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002463 }
2464
Kalle Valo5e3dd152013-06-12 20:52:10 +03002465 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002466 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002467 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002469 } else if (ret > 0) {
2470 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002471 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002472
2473out:
2474 /* Scan state should be updated upon scan completion but in case
2475 * firmware fails to deliver the event (for whatever reason) it is
2476 * desired to clean up scan state anyway. Firmware may have just
2477 * dropped the scan completion event delivery due to transport pipe
2478 * being overflown with data and/or it can recover on its own before
2479 * next scan request is submitted.
2480 */
2481 spin_lock_bh(&ar->data_lock);
2482 if (ar->scan.state != ATH10K_SCAN_IDLE)
2483 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 spin_unlock_bh(&ar->data_lock);
2485
2486 return ret;
2487}
2488
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002489static void ath10k_scan_abort(struct ath10k *ar)
2490{
2491 int ret;
2492
2493 lockdep_assert_held(&ar->conf_mutex);
2494
2495 spin_lock_bh(&ar->data_lock);
2496
2497 switch (ar->scan.state) {
2498 case ATH10K_SCAN_IDLE:
2499 /* This can happen if timeout worker kicked in and called
2500 * abortion while scan completion was being processed.
2501 */
2502 break;
2503 case ATH10K_SCAN_STARTING:
2504 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002505 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002506 ath10k_scan_state_str(ar->scan.state),
2507 ar->scan.state);
2508 break;
2509 case ATH10K_SCAN_RUNNING:
2510 ar->scan.state = ATH10K_SCAN_ABORTING;
2511 spin_unlock_bh(&ar->data_lock);
2512
2513 ret = ath10k_scan_stop(ar);
2514 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002515 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002516
2517 spin_lock_bh(&ar->data_lock);
2518 break;
2519 }
2520
2521 spin_unlock_bh(&ar->data_lock);
2522}
2523
2524void ath10k_scan_timeout_work(struct work_struct *work)
2525{
2526 struct ath10k *ar = container_of(work, struct ath10k,
2527 scan.timeout.work);
2528
2529 mutex_lock(&ar->conf_mutex);
2530 ath10k_scan_abort(ar);
2531 mutex_unlock(&ar->conf_mutex);
2532}
2533
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534static int ath10k_start_scan(struct ath10k *ar,
2535 const struct wmi_start_scan_arg *arg)
2536{
2537 int ret;
2538
2539 lockdep_assert_held(&ar->conf_mutex);
2540
2541 ret = ath10k_wmi_start_scan(ar, arg);
2542 if (ret)
2543 return ret;
2544
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2546 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002547 ret = ath10k_scan_stop(ar);
2548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002549 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002550
2551 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 }
2553
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002554 /* Add a 200ms margin to account for event/command processing */
2555 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2556 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002557 return 0;
2558}
2559
2560/**********************/
2561/* mac80211 callbacks */
2562/**********************/
2563
2564static void ath10k_tx(struct ieee80211_hw *hw,
2565 struct ieee80211_tx_control *control,
2566 struct sk_buff *skb)
2567{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002569 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2570 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002571 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572
2573 /* We should disable CCK RATE due to P2P */
2574 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002575 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576
Michal Kazior4b604552014-07-21 21:03:09 +03002577 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2578 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002579 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002581 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002582 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2583 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002584 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2585 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002586 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2589 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002590 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002591 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002592 spin_unlock_bh(&ar->data_lock);
2593
Michal Kazior8d6d3622014-11-24 14:58:31 +01002594 if (ath10k_mac_need_offchan_tx_work(ar)) {
2595 ATH10K_SKB_CB(skb)->htt.freq = 0;
2596 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597
Michal Kazior8d6d3622014-11-24 14:58:31 +01002598 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2599 skb);
2600
2601 skb_queue_tail(&ar->offchan_tx_queue, skb);
2602 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2603 return;
2604 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002605 }
2606
2607 ath10k_tx_htt(ar, skb);
2608}
2609
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002610/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002611void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002612{
2613 /* make sure rcu-protected mac80211 tx path itself is drained */
2614 synchronize_net();
2615
2616 ath10k_offchan_tx_purge(ar);
2617 ath10k_mgmt_over_wmi_tx_purge(ar);
2618
2619 cancel_work_sync(&ar->offchan_tx_work);
2620 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2621}
2622
Michal Kazioraffd3212013-07-16 09:54:35 +02002623void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002624{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002625 struct ath10k_vif *arvif;
2626
Michal Kazior818bdd12013-07-16 09:38:57 +02002627 lockdep_assert_held(&ar->conf_mutex);
2628
Michal Kazior19337472014-08-28 12:58:16 +02002629 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2630 ar->filter_flags = 0;
2631 ar->monitor = false;
2632
2633 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002634 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002635
2636 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002637
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002638 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002639 ath10k_peer_cleanup_all(ar);
2640 ath10k_core_stop(ar);
2641 ath10k_hif_power_down(ar);
2642
2643 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002644 list_for_each_entry(arvif, &ar->arvifs, list)
2645 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002646 spin_unlock_bh(&ar->data_lock);
2647}
2648
Ben Greear46acf7b2014-05-16 17:15:38 +03002649static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2650{
2651 struct ath10k *ar = hw->priv;
2652
2653 mutex_lock(&ar->conf_mutex);
2654
2655 if (ar->cfg_tx_chainmask) {
2656 *tx_ant = ar->cfg_tx_chainmask;
2657 *rx_ant = ar->cfg_rx_chainmask;
2658 } else {
2659 *tx_ant = ar->supp_tx_chainmask;
2660 *rx_ant = ar->supp_rx_chainmask;
2661 }
2662
2663 mutex_unlock(&ar->conf_mutex);
2664
2665 return 0;
2666}
2667
Ben Greear5572a952014-11-24 16:22:10 +02002668static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2669{
2670 /* It is not clear that allowing gaps in chainmask
2671 * is helpful. Probably it will not do what user
2672 * is hoping for, so warn in that case.
2673 */
2674 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2675 return;
2676
2677 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2678 dbg, cm);
2679}
2680
Ben Greear46acf7b2014-05-16 17:15:38 +03002681static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2682{
2683 int ret;
2684
2685 lockdep_assert_held(&ar->conf_mutex);
2686
Ben Greear5572a952014-11-24 16:22:10 +02002687 ath10k_check_chain_mask(ar, tx_ant, "tx");
2688 ath10k_check_chain_mask(ar, rx_ant, "rx");
2689
Ben Greear46acf7b2014-05-16 17:15:38 +03002690 ar->cfg_tx_chainmask = tx_ant;
2691 ar->cfg_rx_chainmask = rx_ant;
2692
2693 if ((ar->state != ATH10K_STATE_ON) &&
2694 (ar->state != ATH10K_STATE_RESTARTED))
2695 return 0;
2696
2697 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2698 tx_ant);
2699 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002700 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002701 ret, tx_ant);
2702 return ret;
2703 }
2704
2705 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2706 rx_ant);
2707 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002708 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002709 ret, rx_ant);
2710 return ret;
2711 }
2712
2713 return 0;
2714}
2715
2716static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2717{
2718 struct ath10k *ar = hw->priv;
2719 int ret;
2720
2721 mutex_lock(&ar->conf_mutex);
2722 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2723 mutex_unlock(&ar->conf_mutex);
2724 return ret;
2725}
2726
Kalle Valo5e3dd152013-06-12 20:52:10 +03002727static int ath10k_start(struct ieee80211_hw *hw)
2728{
2729 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002730 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002732 /*
2733 * This makes sense only when restarting hw. It is harmless to call
2734 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2735 * commands will be submitted while restarting.
2736 */
2737 ath10k_drain_tx(ar);
2738
Michal Kazior548db542013-07-05 16:15:15 +03002739 mutex_lock(&ar->conf_mutex);
2740
Michal Kaziorc5058f52014-05-26 12:46:03 +03002741 switch (ar->state) {
2742 case ATH10K_STATE_OFF:
2743 ar->state = ATH10K_STATE_ON;
2744 break;
2745 case ATH10K_STATE_RESTARTING:
2746 ath10k_halt(ar);
2747 ar->state = ATH10K_STATE_RESTARTED;
2748 break;
2749 case ATH10K_STATE_ON:
2750 case ATH10K_STATE_RESTARTED:
2751 case ATH10K_STATE_WEDGED:
2752 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002753 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002754 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002755 case ATH10K_STATE_UTF:
2756 ret = -EBUSY;
2757 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002758 }
2759
2760 ret = ath10k_hif_power_up(ar);
2761 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002762 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002763 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002764 }
2765
Kalle Valo43d2a302014-09-10 18:23:30 +03002766 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002767 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002768 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002769 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002770 }
2771
Bartosz Markowski226a3392013-09-26 17:47:16 +02002772 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002774 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002775 goto err_core_stop;
2776 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002777
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002778 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002779 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002780 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002781 goto err_core_stop;
2782 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783
Ben Greear46acf7b2014-05-16 17:15:38 +03002784 if (ar->cfg_tx_chainmask)
2785 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2786 ar->cfg_rx_chainmask);
2787
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002788 /*
2789 * By default FW set ARP frames ac to voice (6). In that case ARP
2790 * exchange is not working properly for UAPSD enabled AP. ARP requests
2791 * which arrives with access category 0 are processed by network stack
2792 * and send back with access category 0, but FW changes access category
2793 * to 6. Set ARP frames access category to best effort (0) solves
2794 * this problem.
2795 */
2796
2797 ret = ath10k_wmi_pdev_set_param(ar,
2798 ar->wmi.pdev_param->arp_ac_override, 0);
2799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002800 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002801 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002802 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002803 }
2804
Michal Kaziord6500972014-04-08 09:56:09 +03002805 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002806 ath10k_regd_update(ar);
2807
Simon Wunderlich855aed12014-08-02 09:12:54 +03002808 ath10k_spectral_start(ar);
2809
Michal Kaziorae254432014-05-26 12:46:02 +03002810 mutex_unlock(&ar->conf_mutex);
2811 return 0;
2812
2813err_core_stop:
2814 ath10k_core_stop(ar);
2815
2816err_power_down:
2817 ath10k_hif_power_down(ar);
2818
2819err_off:
2820 ar->state = ATH10K_STATE_OFF;
2821
2822err:
Michal Kazior548db542013-07-05 16:15:15 +03002823 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002824 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002825}
2826
2827static void ath10k_stop(struct ieee80211_hw *hw)
2828{
2829 struct ath10k *ar = hw->priv;
2830
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002831 ath10k_drain_tx(ar);
2832
Michal Kazior548db542013-07-05 16:15:15 +03002833 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002834 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002835 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002836 ar->state = ATH10K_STATE_OFF;
2837 }
Michal Kazior548db542013-07-05 16:15:15 +03002838 mutex_unlock(&ar->conf_mutex);
2839
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002840 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002841 cancel_work_sync(&ar->restart_work);
2842}
2843
Michal Kaziorad088bf2013-10-16 15:44:46 +03002844static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002845{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002846 struct ath10k_vif *arvif;
2847 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002848
2849 lockdep_assert_held(&ar->conf_mutex);
2850
Michal Kaziorad088bf2013-10-16 15:44:46 +03002851 list_for_each_entry(arvif, &ar->arvifs, list) {
2852 ret = ath10k_mac_vif_setup_ps(arvif);
2853 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002854 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002855 break;
2856 }
2857 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002858
Michal Kaziorad088bf2013-10-16 15:44:46 +03002859 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002860}
2861
Michal Kaziorc930f742014-01-23 11:38:25 +01002862static const char *chandef_get_width(enum nl80211_chan_width width)
2863{
2864 switch (width) {
2865 case NL80211_CHAN_WIDTH_20_NOHT:
2866 return "20 (noht)";
2867 case NL80211_CHAN_WIDTH_20:
2868 return "20";
2869 case NL80211_CHAN_WIDTH_40:
2870 return "40";
2871 case NL80211_CHAN_WIDTH_80:
2872 return "80";
2873 case NL80211_CHAN_WIDTH_80P80:
2874 return "80+80";
2875 case NL80211_CHAN_WIDTH_160:
2876 return "160";
2877 case NL80211_CHAN_WIDTH_5:
2878 return "5";
2879 case NL80211_CHAN_WIDTH_10:
2880 return "10";
2881 }
2882 return "?";
2883}
2884
2885static void ath10k_config_chan(struct ath10k *ar)
2886{
2887 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002888 int ret;
2889
2890 lockdep_assert_held(&ar->conf_mutex);
2891
Michal Kazior7aa7a722014-08-25 12:09:38 +02002892 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002893 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2894 ar->chandef.chan->center_freq,
2895 ar->chandef.center_freq1,
2896 ar->chandef.center_freq2,
2897 chandef_get_width(ar->chandef.width));
2898
2899 /* First stop monitor interface. Some FW versions crash if there's a
2900 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002901 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002902 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002903
2904 list_for_each_entry(arvif, &ar->arvifs, list) {
2905 if (!arvif->is_started)
2906 continue;
2907
Michal Kaziordc55e302014-07-29 12:53:36 +03002908 if (!arvif->is_up)
2909 continue;
2910
Michal Kaziorc930f742014-01-23 11:38:25 +01002911 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2912 continue;
2913
Michal Kaziordc55e302014-07-29 12:53:36 +03002914 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002915 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002916 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002917 arvif->vdev_id, ret);
2918 continue;
2919 }
2920 }
2921
Michal Kaziordc55e302014-07-29 12:53:36 +03002922 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002923
2924 list_for_each_entry(arvif, &ar->arvifs, list) {
2925 if (!arvif->is_started)
2926 continue;
2927
2928 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2929 continue;
2930
Michal Kaziordc55e302014-07-29 12:53:36 +03002931 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002932 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002933 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002934 arvif->vdev_id, ret);
2935 continue;
2936 }
2937
2938 if (!arvif->is_up)
2939 continue;
2940
2941 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2942 arvif->bssid);
2943 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002945 arvif->vdev_id, ret);
2946 continue;
2947 }
2948 }
2949
Michal Kazior19337472014-08-28 12:58:16 +02002950 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002951}
2952
Michal Kazior7d9d5582014-10-21 10:40:15 +03002953static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2954{
2955 int ret;
2956 u32 param;
2957
2958 lockdep_assert_held(&ar->conf_mutex);
2959
2960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2961
2962 param = ar->wmi.pdev_param->txpower_limit2g;
2963 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2964 if (ret) {
2965 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2966 txpower, ret);
2967 return ret;
2968 }
2969
2970 param = ar->wmi.pdev_param->txpower_limit5g;
2971 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2972 if (ret) {
2973 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2974 txpower, ret);
2975 return ret;
2976 }
2977
2978 return 0;
2979}
2980
2981static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2982{
2983 struct ath10k_vif *arvif;
2984 int ret, txpower = -1;
2985
2986 lockdep_assert_held(&ar->conf_mutex);
2987
2988 list_for_each_entry(arvif, &ar->arvifs, list) {
2989 WARN_ON(arvif->txpower < 0);
2990
2991 if (txpower == -1)
2992 txpower = arvif->txpower;
2993 else
2994 txpower = min(txpower, arvif->txpower);
2995 }
2996
2997 if (WARN_ON(txpower == -1))
2998 return -EINVAL;
2999
3000 ret = ath10k_mac_txpower_setup(ar, txpower);
3001 if (ret) {
3002 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3003 txpower, ret);
3004 return ret;
3005 }
3006
3007 return 0;
3008}
3009
Kalle Valo5e3dd152013-06-12 20:52:10 +03003010static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3011{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003012 struct ath10k *ar = hw->priv;
3013 struct ieee80211_conf *conf = &hw->conf;
3014 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003015
3016 mutex_lock(&ar->conf_mutex);
3017
3018 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003019 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003020 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003021 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003022 conf->chandef.chan->flags,
3023 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003024
Kalle Valo5e3dd152013-06-12 20:52:10 +03003025 spin_lock_bh(&ar->data_lock);
3026 ar->rx_channel = conf->chandef.chan;
3027 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003028
Michal Kaziord6500972014-04-08 09:56:09 +03003029 ar->radar_enabled = conf->radar_enabled;
3030 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003031
3032 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3033 ar->chandef = conf->chandef;
3034 ath10k_config_chan(ar);
3035 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036 }
3037
Michal Kazioraffd3212013-07-16 09:54:35 +02003038 if (changed & IEEE80211_CONF_CHANGE_PS)
3039 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003040
3041 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003042 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3043 ret = ath10k_monitor_recalc(ar);
3044 if (ret)
3045 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003046 }
3047
3048 mutex_unlock(&ar->conf_mutex);
3049 return ret;
3050}
3051
Ben Greear5572a952014-11-24 16:22:10 +02003052static u32 get_nss_from_chainmask(u16 chain_mask)
3053{
3054 if ((chain_mask & 0x15) == 0x15)
3055 return 4;
3056 else if ((chain_mask & 0x7) == 0x7)
3057 return 3;
3058 else if ((chain_mask & 0x3) == 0x3)
3059 return 2;
3060 return 1;
3061}
3062
Kalle Valo5e3dd152013-06-12 20:52:10 +03003063/*
3064 * TODO:
3065 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3066 * because we will send mgmt frames without CCK. This requirement
3067 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3068 * in the TX packet.
3069 */
3070static int ath10k_add_interface(struct ieee80211_hw *hw,
3071 struct ieee80211_vif *vif)
3072{
3073 struct ath10k *ar = hw->priv;
3074 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3075 enum wmi_sta_powersave_param param;
3076 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003077 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003078 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003079 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003080
3081 mutex_lock(&ar->conf_mutex);
3082
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003083 memset(arvif, 0, sizeof(*arvif));
3084
Kalle Valo5e3dd152013-06-12 20:52:10 +03003085 arvif->ar = ar;
3086 arvif->vif = vif;
3087
Ben Greeare63b33f2013-10-22 14:54:14 -07003088 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003089
Ben Greeara9aefb32014-08-12 11:02:19 +03003090 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003091 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003092 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003093 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094 }
Ben Greear16c11172014-09-23 14:17:16 -07003095 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003096
Ben Greear16c11172014-09-23 14:17:16 -07003097 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3098 bit, ar->free_vdev_map);
3099
3100 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003101 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003102
Kalle Valo5e3dd152013-06-12 20:52:10 +03003103 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003104 case NL80211_IFTYPE_P2P_DEVICE:
3105 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3106 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3107 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003108 case NL80211_IFTYPE_UNSPECIFIED:
3109 case NL80211_IFTYPE_STATION:
3110 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3111 if (vif->p2p)
3112 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3113 break;
3114 case NL80211_IFTYPE_ADHOC:
3115 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3116 break;
3117 case NL80211_IFTYPE_AP:
3118 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3119
3120 if (vif->p2p)
3121 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3122 break;
3123 case NL80211_IFTYPE_MONITOR:
3124 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3125 break;
3126 default:
3127 WARN_ON(1);
3128 break;
3129 }
3130
Michal Kazior64badcb2014-09-18 11:18:02 +03003131 /* Some firmware revisions don't wait for beacon tx completion before
3132 * sending another SWBA event. This could lead to hardware using old
3133 * (freed) beacon data in some cases, e.g. tx credit starvation
3134 * combined with missed TBTT. This is very very rare.
3135 *
3136 * On non-IOMMU-enabled hosts this could be a possible security issue
3137 * because hw could beacon some random data on the air. On
3138 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3139 * device would crash.
3140 *
3141 * Since there are no beacon tx completions (implicit nor explicit)
3142 * propagated to host the only workaround for this is to allocate a
3143 * DMA-coherent buffer for a lifetime of a vif and use it for all
3144 * beacon tx commands. Worst case for this approach is some beacons may
3145 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3146 */
3147 if (vif->type == NL80211_IFTYPE_ADHOC ||
3148 vif->type == NL80211_IFTYPE_AP) {
3149 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3150 IEEE80211_MAX_FRAME_LEN,
3151 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303152 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003153 if (!arvif->beacon_buf) {
3154 ret = -ENOMEM;
3155 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3156 ret);
3157 goto err;
3158 }
3159 }
3160
3161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3162 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3163 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164
3165 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3166 arvif->vdev_subtype, vif->addr);
3167 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003168 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003169 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003170 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003171 }
3172
Ben Greear16c11172014-09-23 14:17:16 -07003173 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003174 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003175
Michal Kazior46725b12015-01-28 09:57:49 +02003176 /* It makes no sense to have firmware do keepalives. mac80211 already
3177 * takes care of this with idle connection polling.
3178 */
3179 ret = ath10k_mac_vif_disable_keepalive(arvif);
3180 if (ret) {
3181 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
3182 arvif->vdev_id, ret);
3183 goto err_vdev_delete;
3184 }
3185
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003186 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003188 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3189 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003191 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003192 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003193 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003194 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003195 goto err_vdev_delete;
3196 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197
Ben Greear5572a952014-11-24 16:22:10 +02003198 if (ar->cfg_tx_chainmask) {
3199 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3200
3201 vdev_param = ar->wmi.vdev_param->nss;
3202 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3203 nss);
3204 if (ret) {
3205 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3206 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3207 ret);
3208 goto err_vdev_delete;
3209 }
3210 }
3211
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3213 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3214 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003215 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003216 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003217 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003218 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003219
Kalle Valo5a13e762014-01-20 11:01:46 +02003220 ret = ath10k_mac_set_kickout(arvif);
3221 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003222 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003223 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003224 goto err_peer_delete;
3225 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003226 }
3227
3228 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3229 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3230 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3231 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3232 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003233 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003234 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003235 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003236 goto err_peer_delete;
3237 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003238
Michal Kazior9f9b5742014-12-12 12:41:36 +01003239 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003240 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003241 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003242 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003243 goto err_peer_delete;
3244 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003245
Michal Kazior9f9b5742014-12-12 12:41:36 +01003246 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003247 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003248 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003249 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003250 goto err_peer_delete;
3251 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003252 }
3253
Michal Kazior424121c2013-07-22 14:13:31 +02003254 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003255 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003256 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003257 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003258 goto err_peer_delete;
3259 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003260
Michal Kazior424121c2013-07-22 14:13:31 +02003261 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003262 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003263 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003264 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003265 goto err_peer_delete;
3266 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003267
Michal Kazior7d9d5582014-10-21 10:40:15 +03003268 arvif->txpower = vif->bss_conf.txpower;
3269 ret = ath10k_mac_txpower_recalc(ar);
3270 if (ret) {
3271 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3272 goto err_peer_delete;
3273 }
3274
Kalle Valo5e3dd152013-06-12 20:52:10 +03003275 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003276 return 0;
3277
3278err_peer_delete:
3279 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3280 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3281
3282err_vdev_delete:
3283 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003284 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003285 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003286
3287err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003288 if (arvif->beacon_buf) {
3289 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3290 arvif->beacon_buf, arvif->beacon_paddr);
3291 arvif->beacon_buf = NULL;
3292 }
3293
Michal Kazior9dad14a2013-10-16 15:44:45 +03003294 mutex_unlock(&ar->conf_mutex);
3295
Kalle Valo5e3dd152013-06-12 20:52:10 +03003296 return ret;
3297}
3298
3299static void ath10k_remove_interface(struct ieee80211_hw *hw,
3300 struct ieee80211_vif *vif)
3301{
3302 struct ath10k *ar = hw->priv;
3303 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3304 int ret;
3305
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303306 mutex_lock(&ar->conf_mutex);
3307
Michal Kaziored543882013-09-13 14:16:56 +02003308 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003309 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003310 spin_unlock_bh(&ar->data_lock);
3311
Simon Wunderlich855aed12014-08-02 09:12:54 +03003312 ret = ath10k_spectral_vif_stop(arvif);
3313 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003314 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003315 arvif->vdev_id, ret);
3316
Ben Greear16c11172014-09-23 14:17:16 -07003317 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003318 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003319
3320 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3321 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3322 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003323 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003324 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325
3326 kfree(arvif->u.ap.noa_data);
3327 }
3328
Michal Kazior7aa7a722014-08-25 12:09:38 +02003329 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003330 arvif->vdev_id);
3331
Kalle Valo5e3dd152013-06-12 20:52:10 +03003332 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3333 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003334 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003335 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003336
Kalle Valo5e3dd152013-06-12 20:52:10 +03003337 ath10k_peer_cleanup(ar, arvif->vdev_id);
3338
3339 mutex_unlock(&ar->conf_mutex);
3340}
3341
3342/*
3343 * FIXME: Has to be verified.
3344 */
3345#define SUPPORTED_FILTERS \
3346 (FIF_PROMISC_IN_BSS | \
3347 FIF_ALLMULTI | \
3348 FIF_CONTROL | \
3349 FIF_PSPOLL | \
3350 FIF_OTHER_BSS | \
3351 FIF_BCN_PRBRESP_PROMISC | \
3352 FIF_PROBE_REQ | \
3353 FIF_FCSFAIL)
3354
3355static void ath10k_configure_filter(struct ieee80211_hw *hw,
3356 unsigned int changed_flags,
3357 unsigned int *total_flags,
3358 u64 multicast)
3359{
3360 struct ath10k *ar = hw->priv;
3361 int ret;
3362
3363 mutex_lock(&ar->conf_mutex);
3364
3365 changed_flags &= SUPPORTED_FILTERS;
3366 *total_flags &= SUPPORTED_FILTERS;
3367 ar->filter_flags = *total_flags;
3368
Michal Kazior19337472014-08-28 12:58:16 +02003369 ret = ath10k_monitor_recalc(ar);
3370 if (ret)
3371 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372
3373 mutex_unlock(&ar->conf_mutex);
3374}
3375
3376static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3377 struct ieee80211_vif *vif,
3378 struct ieee80211_bss_conf *info,
3379 u32 changed)
3380{
3381 struct ath10k *ar = hw->priv;
3382 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3383 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003384 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385
3386 mutex_lock(&ar->conf_mutex);
3387
3388 if (changed & BSS_CHANGED_IBSS)
3389 ath10k_control_ibss(arvif, info, vif->addr);
3390
3391 if (changed & BSS_CHANGED_BEACON_INT) {
3392 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003393 vdev_param = ar->wmi.vdev_param->beacon_interval;
3394 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003396 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003397 "mac vdev %d beacon_interval %d\n",
3398 arvif->vdev_id, arvif->beacon_interval);
3399
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003401 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003402 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403 }
3404
3405 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003406 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003407 "vdev %d set beacon tx mode to staggered\n",
3408 arvif->vdev_id);
3409
Bartosz Markowski226a3392013-09-26 17:47:16 +02003410 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3411 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003412 WMI_BEACON_STAGGERED_MODE);
3413 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003414 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003415 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003416
3417 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3418 if (ret)
3419 ath10k_warn(ar, "failed to update beacon template: %d\n",
3420 ret);
3421 }
3422
3423 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3424 ret = ath10k_mac_setup_prb_tmpl(arvif);
3425 if (ret)
3426 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3427 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003428 }
3429
Michal Kaziorba2479f2015-01-24 12:14:51 +02003430 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003431 arvif->dtim_period = info->dtim_period;
3432
Michal Kazior7aa7a722014-08-25 12:09:38 +02003433 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003434 "mac vdev %d dtim_period %d\n",
3435 arvif->vdev_id, arvif->dtim_period);
3436
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003437 vdev_param = ar->wmi.vdev_param->dtim_period;
3438 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003439 arvif->dtim_period);
3440 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003441 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003442 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003443 }
3444
3445 if (changed & BSS_CHANGED_SSID &&
3446 vif->type == NL80211_IFTYPE_AP) {
3447 arvif->u.ap.ssid_len = info->ssid_len;
3448 if (info->ssid_len)
3449 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3450 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3451 }
3452
Michal Kazior077efc82014-10-21 10:10:29 +03003453 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3454 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003455
3456 if (changed & BSS_CHANGED_BEACON_ENABLED)
3457 ath10k_control_beaconing(arvif, info);
3458
3459 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003460 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003461 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003462 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003463
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003464 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003465 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003466 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003467 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003468 }
3469
3470 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003471 if (info->use_short_slot)
3472 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3473
3474 else
3475 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3476
Michal Kazior7aa7a722014-08-25 12:09:38 +02003477 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003478 arvif->vdev_id, slottime);
3479
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003480 vdev_param = ar->wmi.vdev_param->slot_time;
3481 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482 slottime);
3483 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003484 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003485 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003486 }
3487
3488 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003489 if (info->use_short_preamble)
3490 preamble = WMI_VDEV_PREAMBLE_SHORT;
3491 else
3492 preamble = WMI_VDEV_PREAMBLE_LONG;
3493
Michal Kazior7aa7a722014-08-25 12:09:38 +02003494 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003495 "mac vdev %d preamble %dn",
3496 arvif->vdev_id, preamble);
3497
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003498 vdev_param = ar->wmi.vdev_param->preamble;
3499 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500 preamble);
3501 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003502 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003503 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003504 }
3505
3506 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003507 if (info->assoc) {
3508 /* Workaround: Make sure monitor vdev is not running
3509 * when associating to prevent some firmware revisions
3510 * (e.g. 10.1 and 10.2) from crashing.
3511 */
3512 if (ar->monitor_started)
3513 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003514 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003515 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003516 } else {
3517 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003518 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003519 }
3520
Michal Kazior7d9d5582014-10-21 10:40:15 +03003521 if (changed & BSS_CHANGED_TXPOWER) {
3522 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3523 arvif->vdev_id, info->txpower);
3524
3525 arvif->txpower = info->txpower;
3526 ret = ath10k_mac_txpower_recalc(ar);
3527 if (ret)
3528 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3529 }
3530
Michal Kaziorbf14e652014-12-12 12:41:38 +01003531 if (changed & BSS_CHANGED_PS) {
3532 ret = ath10k_mac_vif_setup_ps(arvif);
3533 if (ret)
3534 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3535 arvif->vdev_id, ret);
3536 }
3537
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 mutex_unlock(&ar->conf_mutex);
3539}
3540
3541static int ath10k_hw_scan(struct ieee80211_hw *hw,
3542 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003543 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544{
3545 struct ath10k *ar = hw->priv;
3546 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003547 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003548 struct wmi_start_scan_arg arg;
3549 int ret = 0;
3550 int i;
3551
3552 mutex_lock(&ar->conf_mutex);
3553
3554 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003555 switch (ar->scan.state) {
3556 case ATH10K_SCAN_IDLE:
3557 reinit_completion(&ar->scan.started);
3558 reinit_completion(&ar->scan.completed);
3559 ar->scan.state = ATH10K_SCAN_STARTING;
3560 ar->scan.is_roc = false;
3561 ar->scan.vdev_id = arvif->vdev_id;
3562 ret = 0;
3563 break;
3564 case ATH10K_SCAN_STARTING:
3565 case ATH10K_SCAN_RUNNING:
3566 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003568 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003569 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003570 spin_unlock_bh(&ar->data_lock);
3571
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003572 if (ret)
3573 goto exit;
3574
Kalle Valo5e3dd152013-06-12 20:52:10 +03003575 memset(&arg, 0, sizeof(arg));
3576 ath10k_wmi_start_scan_init(ar, &arg);
3577 arg.vdev_id = arvif->vdev_id;
3578 arg.scan_id = ATH10K_SCAN_ID;
3579
3580 if (!req->no_cck)
3581 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3582
3583 if (req->ie_len) {
3584 arg.ie_len = req->ie_len;
3585 memcpy(arg.ie, req->ie, arg.ie_len);
3586 }
3587
3588 if (req->n_ssids) {
3589 arg.n_ssids = req->n_ssids;
3590 for (i = 0; i < arg.n_ssids; i++) {
3591 arg.ssids[i].len = req->ssids[i].ssid_len;
3592 arg.ssids[i].ssid = req->ssids[i].ssid;
3593 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003594 } else {
3595 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003596 }
3597
3598 if (req->n_channels) {
3599 arg.n_channels = req->n_channels;
3600 for (i = 0; i < arg.n_channels; i++)
3601 arg.channels[i] = req->channels[i]->center_freq;
3602 }
3603
3604 ret = ath10k_start_scan(ar, &arg);
3605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003606 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003607 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003608 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003609 spin_unlock_bh(&ar->data_lock);
3610 }
3611
3612exit:
3613 mutex_unlock(&ar->conf_mutex);
3614 return ret;
3615}
3616
3617static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3618 struct ieee80211_vif *vif)
3619{
3620 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621
3622 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003623 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003624 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003625
3626 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627}
3628
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003629static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3630 struct ath10k_vif *arvif,
3631 enum set_key_cmd cmd,
3632 struct ieee80211_key_conf *key)
3633{
3634 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3635 int ret;
3636
3637 /* 10.1 firmware branch requires default key index to be set to group
3638 * key index after installing it. Otherwise FW/HW Txes corrupted
3639 * frames with multi-vif APs. This is not required for main firmware
3640 * branch (e.g. 636).
3641 *
3642 * FIXME: This has been tested only in AP. It remains unknown if this
3643 * is required for multi-vif STA interfaces on 10.1 */
3644
3645 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3646 return;
3647
3648 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3649 return;
3650
3651 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3652 return;
3653
3654 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3655 return;
3656
3657 if (cmd != SET_KEY)
3658 return;
3659
3660 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3661 key->keyidx);
3662 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003663 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003664 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003665}
3666
Kalle Valo5e3dd152013-06-12 20:52:10 +03003667static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3668 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3669 struct ieee80211_key_conf *key)
3670{
3671 struct ath10k *ar = hw->priv;
3672 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3673 struct ath10k_peer *peer;
3674 const u8 *peer_addr;
3675 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3676 key->cipher == WLAN_CIPHER_SUITE_WEP104;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003677 bool def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003678 int ret = 0;
3679
3680 if (key->keyidx > WMI_MAX_KEY_INDEX)
3681 return -ENOSPC;
3682
3683 mutex_lock(&ar->conf_mutex);
3684
3685 if (sta)
3686 peer_addr = sta->addr;
3687 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3688 peer_addr = vif->bss_conf.bssid;
3689 else
3690 peer_addr = vif->addr;
3691
3692 key->hw_key_idx = key->keyidx;
3693
3694 /* the peer should not disappear in mid-way (unless FW goes awry) since
3695 * we already hold conf_mutex. we just make sure its there now. */
3696 spin_lock_bh(&ar->data_lock);
3697 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3698 spin_unlock_bh(&ar->data_lock);
3699
3700 if (!peer) {
3701 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003702 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003703 peer_addr);
3704 ret = -EOPNOTSUPP;
3705 goto exit;
3706 } else {
3707 /* if the peer doesn't exist there is no key to disable
3708 * anymore */
3709 goto exit;
3710 }
3711 }
3712
3713 if (is_wep) {
3714 if (cmd == SET_KEY)
3715 arvif->wep_keys[key->keyidx] = key;
3716 else
3717 arvif->wep_keys[key->keyidx] = NULL;
3718
3719 if (cmd == DISABLE_KEY)
3720 ath10k_clear_vdev_key(arvif, key);
3721 }
3722
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003723 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3724 * static WEP, do not set this flag for the keys whose key id
3725 * is greater than default key id.
3726 */
3727 if (arvif->def_wep_key_idx == -1)
3728 def_idx = true;
3729
3730 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003732 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003733 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003734 goto exit;
3735 }
3736
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003737 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3738
Kalle Valo5e3dd152013-06-12 20:52:10 +03003739 spin_lock_bh(&ar->data_lock);
3740 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3741 if (peer && cmd == SET_KEY)
3742 peer->keys[key->keyidx] = key;
3743 else if (peer && cmd == DISABLE_KEY)
3744 peer->keys[key->keyidx] = NULL;
3745 else if (peer == NULL)
3746 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003747 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748 spin_unlock_bh(&ar->data_lock);
3749
3750exit:
3751 mutex_unlock(&ar->conf_mutex);
3752 return ret;
3753}
3754
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003755static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3756 struct ieee80211_vif *vif,
3757 int keyidx)
3758{
3759 struct ath10k *ar = hw->priv;
3760 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3761 int ret;
3762
3763 mutex_lock(&arvif->ar->conf_mutex);
3764
3765 if (arvif->ar->state != ATH10K_STATE_ON)
3766 goto unlock;
3767
3768 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3769 arvif->vdev_id, keyidx);
3770
3771 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3772 arvif->vdev_id,
3773 arvif->ar->wmi.vdev_param->def_keyid,
3774 keyidx);
3775
3776 if (ret) {
3777 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3778 arvif->vdev_id,
3779 ret);
3780 goto unlock;
3781 }
3782
3783 arvif->def_wep_key_idx = keyidx;
3784unlock:
3785 mutex_unlock(&arvif->ar->conf_mutex);
3786}
3787
Michal Kazior9797feb2014-02-14 14:49:48 +01003788static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3789{
3790 struct ath10k *ar;
3791 struct ath10k_vif *arvif;
3792 struct ath10k_sta *arsta;
3793 struct ieee80211_sta *sta;
3794 u32 changed, bw, nss, smps;
3795 int err;
3796
3797 arsta = container_of(wk, struct ath10k_sta, update_wk);
3798 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3799 arvif = arsta->arvif;
3800 ar = arvif->ar;
3801
3802 spin_lock_bh(&ar->data_lock);
3803
3804 changed = arsta->changed;
3805 arsta->changed = 0;
3806
3807 bw = arsta->bw;
3808 nss = arsta->nss;
3809 smps = arsta->smps;
3810
3811 spin_unlock_bh(&ar->data_lock);
3812
3813 mutex_lock(&ar->conf_mutex);
3814
3815 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003816 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003817 sta->addr, bw);
3818
3819 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3820 WMI_PEER_CHAN_WIDTH, bw);
3821 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003822 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003823 sta->addr, bw, err);
3824 }
3825
3826 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003828 sta->addr, nss);
3829
3830 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3831 WMI_PEER_NSS, nss);
3832 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003833 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003834 sta->addr, nss, err);
3835 }
3836
3837 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003838 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003839 sta->addr, smps);
3840
3841 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3842 WMI_PEER_SMPS_STATE, smps);
3843 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003844 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003845 sta->addr, smps, err);
3846 }
3847
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003848 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3849 changed & IEEE80211_RC_NSS_CHANGED) {
3850 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003851 sta->addr);
3852
Michal Kazior590922a2014-10-21 10:10:29 +03003853 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003854 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003855 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003856 sta->addr);
3857 }
3858
Michal Kazior9797feb2014-02-14 14:49:48 +01003859 mutex_unlock(&ar->conf_mutex);
3860}
3861
Michal Kaziorcfd10612014-11-25 15:16:05 +01003862static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3863{
3864 struct ath10k *ar = arvif->ar;
3865
3866 lockdep_assert_held(&ar->conf_mutex);
3867
3868 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3869 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3870 return 0;
3871
3872 if (ar->num_stations >= ar->max_num_stations)
3873 return -ENOBUFS;
3874
3875 ar->num_stations++;
3876
3877 return 0;
3878}
3879
3880static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3881{
3882 struct ath10k *ar = arvif->ar;
3883
3884 lockdep_assert_held(&ar->conf_mutex);
3885
3886 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3887 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3888 return;
3889
3890 ar->num_stations--;
3891}
3892
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893static int ath10k_sta_state(struct ieee80211_hw *hw,
3894 struct ieee80211_vif *vif,
3895 struct ieee80211_sta *sta,
3896 enum ieee80211_sta_state old_state,
3897 enum ieee80211_sta_state new_state)
3898{
3899 struct ath10k *ar = hw->priv;
3900 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003901 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003902 int ret = 0;
3903
Michal Kazior76f90022014-02-25 09:29:57 +02003904 if (old_state == IEEE80211_STA_NOTEXIST &&
3905 new_state == IEEE80211_STA_NONE) {
3906 memset(arsta, 0, sizeof(*arsta));
3907 arsta->arvif = arvif;
3908 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3909 }
3910
Michal Kazior9797feb2014-02-14 14:49:48 +01003911 /* cancel must be done outside the mutex to avoid deadlock */
3912 if ((old_state == IEEE80211_STA_NONE &&
3913 new_state == IEEE80211_STA_NOTEXIST))
3914 cancel_work_sync(&arsta->update_wk);
3915
Kalle Valo5e3dd152013-06-12 20:52:10 +03003916 mutex_lock(&ar->conf_mutex);
3917
3918 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003919 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920 /*
3921 * New station addition.
3922 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003923 ath10k_dbg(ar, ATH10K_DBG_MAC,
3924 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3925 arvif->vdev_id, sta->addr,
3926 ar->num_stations + 1, ar->max_num_stations,
3927 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003928
Michal Kaziorcfd10612014-11-25 15:16:05 +01003929 ret = ath10k_mac_inc_num_stations(arvif);
3930 if (ret) {
3931 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3932 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003933 goto exit;
3934 }
3935
Kalle Valo5e3dd152013-06-12 20:52:10 +03003936 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003937 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003938 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 -08003939 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003940 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003941 goto exit;
3942 }
Michal Kazior077efc82014-10-21 10:10:29 +03003943
3944 if (vif->type == NL80211_IFTYPE_STATION) {
3945 WARN_ON(arvif->is_started);
3946
3947 ret = ath10k_vdev_start(arvif);
3948 if (ret) {
3949 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3950 arvif->vdev_id, ret);
3951 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3952 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003953 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003954 goto exit;
3955 }
3956
3957 arvif->is_started = true;
3958 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003959 } else if ((old_state == IEEE80211_STA_NONE &&
3960 new_state == IEEE80211_STA_NOTEXIST)) {
3961 /*
3962 * Existing station deletion.
3963 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003964 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003965 "mac vdev %d peer delete %pM (sta gone)\n",
3966 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003967
3968 if (vif->type == NL80211_IFTYPE_STATION) {
3969 WARN_ON(!arvif->is_started);
3970
3971 ret = ath10k_vdev_stop(arvif);
3972 if (ret)
3973 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3974 arvif->vdev_id, ret);
3975
3976 arvif->is_started = false;
3977 }
3978
Kalle Valo5e3dd152013-06-12 20:52:10 +03003979 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3980 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003981 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003982 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003983
Michal Kaziorcfd10612014-11-25 15:16:05 +01003984 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003985 } else if (old_state == IEEE80211_STA_AUTH &&
3986 new_state == IEEE80211_STA_ASSOC &&
3987 (vif->type == NL80211_IFTYPE_AP ||
3988 vif->type == NL80211_IFTYPE_ADHOC)) {
3989 /*
3990 * New association.
3991 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003992 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003993 sta->addr);
3994
Michal Kazior590922a2014-10-21 10:10:29 +03003995 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003996 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003997 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003998 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999 } else if (old_state == IEEE80211_STA_ASSOC &&
4000 new_state == IEEE80211_STA_AUTH &&
4001 (vif->type == NL80211_IFTYPE_AP ||
4002 vif->type == NL80211_IFTYPE_ADHOC)) {
4003 /*
4004 * Disassociation.
4005 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004006 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004007 sta->addr);
4008
Michal Kazior590922a2014-10-21 10:10:29 +03004009 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004011 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004012 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004013 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004014exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004015 mutex_unlock(&ar->conf_mutex);
4016 return ret;
4017}
4018
4019static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004020 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021{
4022 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004023 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4024 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004025 u32 value = 0;
4026 int ret = 0;
4027
Michal Kazior548db542013-07-05 16:15:15 +03004028 lockdep_assert_held(&ar->conf_mutex);
4029
Kalle Valo5e3dd152013-06-12 20:52:10 +03004030 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4031 return 0;
4032
4033 switch (ac) {
4034 case IEEE80211_AC_VO:
4035 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4036 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004037 prio = 7;
4038 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004039 break;
4040 case IEEE80211_AC_VI:
4041 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4042 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004043 prio = 5;
4044 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004045 break;
4046 case IEEE80211_AC_BE:
4047 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4048 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004049 prio = 2;
4050 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004051 break;
4052 case IEEE80211_AC_BK:
4053 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4054 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004055 prio = 0;
4056 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004057 break;
4058 }
4059
4060 if (enable)
4061 arvif->u.sta.uapsd |= value;
4062 else
4063 arvif->u.sta.uapsd &= ~value;
4064
4065 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4066 WMI_STA_PS_PARAM_UAPSD,
4067 arvif->u.sta.uapsd);
4068 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004069 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004070 goto exit;
4071 }
4072
4073 if (arvif->u.sta.uapsd)
4074 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4075 else
4076 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4077
4078 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4079 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4080 value);
4081 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004082 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083
Michal Kazior9f9b5742014-12-12 12:41:36 +01004084 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4085 if (ret) {
4086 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4087 arvif->vdev_id, ret);
4088 return ret;
4089 }
4090
4091 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4092 if (ret) {
4093 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4094 arvif->vdev_id, ret);
4095 return ret;
4096 }
4097
Michal Kaziorb0e56152015-01-24 12:14:52 +02004098 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4099 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4100 /* Only userspace can make an educated decision when to send
4101 * trigger frame. The following effectively disables u-UAPSD
4102 * autotrigger in firmware (which is enabled by default
4103 * provided the autotrigger service is available).
4104 */
4105
4106 arg.wmm_ac = acc;
4107 arg.user_priority = prio;
4108 arg.service_interval = 0;
4109 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4110 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4111
4112 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4113 arvif->bssid, &arg, 1);
4114 if (ret) {
4115 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4116 ret);
4117 return ret;
4118 }
4119 }
4120
Kalle Valo5e3dd152013-06-12 20:52:10 +03004121exit:
4122 return ret;
4123}
4124
4125static int ath10k_conf_tx(struct ieee80211_hw *hw,
4126 struct ieee80211_vif *vif, u16 ac,
4127 const struct ieee80211_tx_queue_params *params)
4128{
4129 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004130 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004131 struct wmi_wmm_params_arg *p = NULL;
4132 int ret;
4133
4134 mutex_lock(&ar->conf_mutex);
4135
4136 switch (ac) {
4137 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004138 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139 break;
4140 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004141 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142 break;
4143 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004144 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004145 break;
4146 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004147 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004148 break;
4149 }
4150
4151 if (WARN_ON(!p)) {
4152 ret = -EINVAL;
4153 goto exit;
4154 }
4155
4156 p->cwmin = params->cw_min;
4157 p->cwmax = params->cw_max;
4158 p->aifs = params->aifs;
4159
4160 /*
4161 * The channel time duration programmed in the HW is in absolute
4162 * microseconds, while mac80211 gives the txop in units of
4163 * 32 microseconds.
4164 */
4165 p->txop = params->txop * 32;
4166
Michal Kazior7fc979a2015-01-28 09:57:28 +02004167 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4168 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4169 &arvif->wmm_params);
4170 if (ret) {
4171 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4172 arvif->vdev_id, ret);
4173 goto exit;
4174 }
4175 } else {
4176 /* This won't work well with multi-interface cases but it's
4177 * better than nothing.
4178 */
4179 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4180 if (ret) {
4181 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4182 goto exit;
4183 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004184 }
4185
4186 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4187 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004188 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004189
4190exit:
4191 mutex_unlock(&ar->conf_mutex);
4192 return ret;
4193}
4194
4195#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4196
4197static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4198 struct ieee80211_vif *vif,
4199 struct ieee80211_channel *chan,
4200 int duration,
4201 enum ieee80211_roc_type type)
4202{
4203 struct ath10k *ar = hw->priv;
4204 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4205 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004206 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004207
4208 mutex_lock(&ar->conf_mutex);
4209
4210 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004211 switch (ar->scan.state) {
4212 case ATH10K_SCAN_IDLE:
4213 reinit_completion(&ar->scan.started);
4214 reinit_completion(&ar->scan.completed);
4215 reinit_completion(&ar->scan.on_channel);
4216 ar->scan.state = ATH10K_SCAN_STARTING;
4217 ar->scan.is_roc = true;
4218 ar->scan.vdev_id = arvif->vdev_id;
4219 ar->scan.roc_freq = chan->center_freq;
4220 ret = 0;
4221 break;
4222 case ATH10K_SCAN_STARTING:
4223 case ATH10K_SCAN_RUNNING:
4224 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004225 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004226 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004227 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004228 spin_unlock_bh(&ar->data_lock);
4229
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004230 if (ret)
4231 goto exit;
4232
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004233 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4234
Kalle Valo5e3dd152013-06-12 20:52:10 +03004235 memset(&arg, 0, sizeof(arg));
4236 ath10k_wmi_start_scan_init(ar, &arg);
4237 arg.vdev_id = arvif->vdev_id;
4238 arg.scan_id = ATH10K_SCAN_ID;
4239 arg.n_channels = 1;
4240 arg.channels[0] = chan->center_freq;
4241 arg.dwell_time_active = duration;
4242 arg.dwell_time_passive = duration;
4243 arg.max_scan_time = 2 * duration;
4244 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4245 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4246
4247 ret = ath10k_start_scan(ar, &arg);
4248 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004249 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004250 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004251 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004252 spin_unlock_bh(&ar->data_lock);
4253 goto exit;
4254 }
4255
4256 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4257 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004258 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004259
4260 ret = ath10k_scan_stop(ar);
4261 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004262 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004263
Kalle Valo5e3dd152013-06-12 20:52:10 +03004264 ret = -ETIMEDOUT;
4265 goto exit;
4266 }
4267
4268 ret = 0;
4269exit:
4270 mutex_unlock(&ar->conf_mutex);
4271 return ret;
4272}
4273
4274static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4275{
4276 struct ath10k *ar = hw->priv;
4277
4278 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004279 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004280 mutex_unlock(&ar->conf_mutex);
4281
Michal Kazior4eb2e162014-10-28 10:23:09 +01004282 cancel_delayed_work_sync(&ar->scan.timeout);
4283
Kalle Valo5e3dd152013-06-12 20:52:10 +03004284 return 0;
4285}
4286
4287/*
4288 * Both RTS and Fragmentation threshold are interface-specific
4289 * in ath10k, but device-specific in mac80211.
4290 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004291
4292static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4293{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004294 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004295 struct ath10k_vif *arvif;
4296 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004297
Michal Kaziorad088bf2013-10-16 15:44:46 +03004298 mutex_lock(&ar->conf_mutex);
4299 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004300 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004301 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004302
Michal Kaziorad088bf2013-10-16 15:44:46 +03004303 ret = ath10k_mac_set_rts(arvif, value);
4304 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004305 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004306 arvif->vdev_id, ret);
4307 break;
4308 }
4309 }
4310 mutex_unlock(&ar->conf_mutex);
4311
4312 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004313}
4314
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004315static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4316 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004317{
4318 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004319 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320 int ret;
4321
4322 /* mac80211 doesn't care if we really xmit queued frames or not
4323 * we'll collect those frames either way if we stop/delete vdevs */
4324 if (drop)
4325 return;
4326
Michal Kazior548db542013-07-05 16:15:15 +03004327 mutex_lock(&ar->conf_mutex);
4328
Michal Kazioraffd3212013-07-16 09:54:35 +02004329 if (ar->state == ATH10K_STATE_WEDGED)
4330 goto skip;
4331
Michal Kazioredb82362013-07-05 16:15:14 +03004332 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004333 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004334
Michal Kazioredb82362013-07-05 16:15:14 +03004335 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004336 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004337 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004338
Michal Kazior7962b0d2014-10-28 10:34:38 +01004339 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4340 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4341 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004342
4343 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004344 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004345
4346 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004347 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004348 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004349
Michal Kazioraffd3212013-07-16 09:54:35 +02004350skip:
Michal Kazior548db542013-07-05 16:15:15 +03004351 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004352}
4353
4354/* TODO: Implement this function properly
4355 * For now it is needed to reply to Probe Requests in IBSS mode.
4356 * Propably we need this information from FW.
4357 */
4358static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4359{
4360 return 1;
4361}
4362
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004363#ifdef CONFIG_PM
4364static int ath10k_suspend(struct ieee80211_hw *hw,
4365 struct cfg80211_wowlan *wowlan)
4366{
4367 struct ath10k *ar = hw->priv;
4368 int ret;
4369
Marek Puzyniak9042e172014-02-10 17:14:23 +01004370 mutex_lock(&ar->conf_mutex);
4371
Marek Puzyniak00f54822014-02-10 17:14:24 +01004372 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004373 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004374 if (ret == -ETIMEDOUT)
4375 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004376 ret = 1;
4377 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004378 }
4379
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004380 ret = ath10k_hif_suspend(ar);
4381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004382 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004383 goto resume;
4384 }
4385
Marek Puzyniak9042e172014-02-10 17:14:23 +01004386 ret = 0;
4387 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004388resume:
4389 ret = ath10k_wmi_pdev_resume_target(ar);
4390 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004391 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004392
4393 ret = 1;
4394exit:
4395 mutex_unlock(&ar->conf_mutex);
4396 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004397}
4398
4399static int ath10k_resume(struct ieee80211_hw *hw)
4400{
4401 struct ath10k *ar = hw->priv;
4402 int ret;
4403
Marek Puzyniak9042e172014-02-10 17:14:23 +01004404 mutex_lock(&ar->conf_mutex);
4405
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004406 ret = ath10k_hif_resume(ar);
4407 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004408 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004409 ret = 1;
4410 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004411 }
4412
4413 ret = ath10k_wmi_pdev_resume_target(ar);
4414 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004415 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004416 ret = 1;
4417 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004418 }
4419
Marek Puzyniak9042e172014-02-10 17:14:23 +01004420 ret = 0;
4421exit:
4422 mutex_unlock(&ar->conf_mutex);
4423 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004424}
4425#endif
4426
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004427static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4428 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004429{
4430 struct ath10k *ar = hw->priv;
4431
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004432 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4433 return;
4434
Michal Kazioraffd3212013-07-16 09:54:35 +02004435 mutex_lock(&ar->conf_mutex);
4436
4437 /* If device failed to restart it will be in a different state, e.g.
4438 * ATH10K_STATE_WEDGED */
4439 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004440 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004441 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004442 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004443 }
4444
4445 mutex_unlock(&ar->conf_mutex);
4446}
4447
Michal Kazior2e1dea42013-07-31 10:32:40 +02004448static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4449 struct survey_info *survey)
4450{
4451 struct ath10k *ar = hw->priv;
4452 struct ieee80211_supported_band *sband;
4453 struct survey_info *ar_survey = &ar->survey[idx];
4454 int ret = 0;
4455
4456 mutex_lock(&ar->conf_mutex);
4457
4458 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4459 if (sband && idx >= sband->n_channels) {
4460 idx -= sband->n_channels;
4461 sband = NULL;
4462 }
4463
4464 if (!sband)
4465 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4466
4467 if (!sband || idx >= sband->n_channels) {
4468 ret = -ENOENT;
4469 goto exit;
4470 }
4471
4472 spin_lock_bh(&ar->data_lock);
4473 memcpy(survey, ar_survey, sizeof(*survey));
4474 spin_unlock_bh(&ar->data_lock);
4475
4476 survey->channel = &sband->channels[idx];
4477
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004478 if (ar->rx_channel == survey->channel)
4479 survey->filled |= SURVEY_INFO_IN_USE;
4480
Michal Kazior2e1dea42013-07-31 10:32:40 +02004481exit:
4482 mutex_unlock(&ar->conf_mutex);
4483 return ret;
4484}
4485
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004486/* Helper table for legacy fixed_rate/bitrate_mask */
4487static const u8 cck_ofdm_rate[] = {
4488 /* CCK */
4489 3, /* 1Mbps */
4490 2, /* 2Mbps */
4491 1, /* 5.5Mbps */
4492 0, /* 11Mbps */
4493 /* OFDM */
4494 3, /* 6Mbps */
4495 7, /* 9Mbps */
4496 2, /* 12Mbps */
4497 6, /* 18Mbps */
4498 1, /* 24Mbps */
4499 5, /* 36Mbps */
4500 0, /* 48Mbps */
4501 4, /* 54Mbps */
4502};
4503
4504/* Check if only one bit set */
4505static int ath10k_check_single_mask(u32 mask)
4506{
4507 int bit;
4508
4509 bit = ffs(mask);
4510 if (!bit)
4511 return 0;
4512
4513 mask &= ~BIT(bit - 1);
4514 if (mask)
4515 return 2;
4516
4517 return 1;
4518}
4519
4520static bool
4521ath10k_default_bitrate_mask(struct ath10k *ar,
4522 enum ieee80211_band band,
4523 const struct cfg80211_bitrate_mask *mask)
4524{
4525 u32 legacy = 0x00ff;
4526 u8 ht = 0xff, i;
4527 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004528 u16 nrf = ar->num_rf_chains;
4529
4530 if (ar->cfg_tx_chainmask)
4531 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004532
4533 switch (band) {
4534 case IEEE80211_BAND_2GHZ:
4535 legacy = 0x00fff;
4536 vht = 0;
4537 break;
4538 case IEEE80211_BAND_5GHZ:
4539 break;
4540 default:
4541 return false;
4542 }
4543
4544 if (mask->control[band].legacy != legacy)
4545 return false;
4546
Ben Greearb116ea12014-11-24 16:22:10 +02004547 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004548 if (mask->control[band].ht_mcs[i] != ht)
4549 return false;
4550
Ben Greearb116ea12014-11-24 16:22:10 +02004551 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004552 if (mask->control[band].vht_mcs[i] != vht)
4553 return false;
4554
4555 return true;
4556}
4557
4558static bool
4559ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4560 enum ieee80211_band band,
4561 u8 *fixed_nss)
4562{
4563 int ht_nss = 0, vht_nss = 0, i;
4564
4565 /* check legacy */
4566 if (ath10k_check_single_mask(mask->control[band].legacy))
4567 return false;
4568
4569 /* check HT */
4570 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4571 if (mask->control[band].ht_mcs[i] == 0xff)
4572 continue;
4573 else if (mask->control[band].ht_mcs[i] == 0x00)
4574 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004575
4576 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004577 }
4578
4579 ht_nss = i;
4580
4581 /* check VHT */
4582 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4583 if (mask->control[band].vht_mcs[i] == 0x03ff)
4584 continue;
4585 else if (mask->control[band].vht_mcs[i] == 0x0000)
4586 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004587
4588 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004589 }
4590
4591 vht_nss = i;
4592
4593 if (ht_nss > 0 && vht_nss > 0)
4594 return false;
4595
4596 if (ht_nss)
4597 *fixed_nss = ht_nss;
4598 else if (vht_nss)
4599 *fixed_nss = vht_nss;
4600 else
4601 return false;
4602
4603 return true;
4604}
4605
4606static bool
4607ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4608 enum ieee80211_band band,
4609 enum wmi_rate_preamble *preamble)
4610{
4611 int legacy = 0, ht = 0, vht = 0, i;
4612
4613 *preamble = WMI_RATE_PREAMBLE_OFDM;
4614
4615 /* check legacy */
4616 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4617 if (legacy > 1)
4618 return false;
4619
4620 /* check HT */
4621 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4622 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4623 if (ht > 1)
4624 return false;
4625
4626 /* check VHT */
4627 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4628 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4629 if (vht > 1)
4630 return false;
4631
4632 /* Currently we support only one fixed_rate */
4633 if ((legacy + ht + vht) != 1)
4634 return false;
4635
4636 if (ht)
4637 *preamble = WMI_RATE_PREAMBLE_HT;
4638 else if (vht)
4639 *preamble = WMI_RATE_PREAMBLE_VHT;
4640
4641 return true;
4642}
4643
4644static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004645ath10k_bitrate_mask_rate(struct ath10k *ar,
4646 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004647 enum ieee80211_band band,
4648 u8 *fixed_rate,
4649 u8 *fixed_nss)
4650{
4651 u8 rate = 0, pream = 0, nss = 0, i;
4652 enum wmi_rate_preamble preamble;
4653
4654 /* Check if single rate correct */
4655 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4656 return false;
4657
4658 pream = preamble;
4659
4660 switch (preamble) {
4661 case WMI_RATE_PREAMBLE_CCK:
4662 case WMI_RATE_PREAMBLE_OFDM:
4663 i = ffs(mask->control[band].legacy) - 1;
4664
4665 if (band == IEEE80211_BAND_2GHZ && i < 4)
4666 pream = WMI_RATE_PREAMBLE_CCK;
4667
4668 if (band == IEEE80211_BAND_5GHZ)
4669 i += 4;
4670
4671 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4672 return false;
4673
4674 rate = cck_ofdm_rate[i];
4675 break;
4676 case WMI_RATE_PREAMBLE_HT:
4677 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4678 if (mask->control[band].ht_mcs[i])
4679 break;
4680
4681 if (i == IEEE80211_HT_MCS_MASK_LEN)
4682 return false;
4683
4684 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4685 nss = i;
4686 break;
4687 case WMI_RATE_PREAMBLE_VHT:
4688 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4689 if (mask->control[band].vht_mcs[i])
4690 break;
4691
4692 if (i == NL80211_VHT_NSS_MAX)
4693 return false;
4694
4695 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4696 nss = i;
4697 break;
4698 }
4699
4700 *fixed_nss = nss + 1;
4701 nss <<= 4;
4702 pream <<= 6;
4703
Michal Kazior7aa7a722014-08-25 12:09:38 +02004704 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 +01004705 pream, nss, rate);
4706
4707 *fixed_rate = pream | nss | rate;
4708
4709 return true;
4710}
4711
Michal Kazior7aa7a722014-08-25 12:09:38 +02004712static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4713 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004714 enum ieee80211_band band,
4715 u8 *fixed_rate,
4716 u8 *fixed_nss)
4717{
4718 /* First check full NSS mask, if we can simply limit NSS */
4719 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4720 return true;
4721
4722 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004723 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004724}
4725
4726static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4727 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004728 u8 fixed_nss,
4729 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004730{
4731 struct ath10k *ar = arvif->ar;
4732 u32 vdev_param;
4733 int ret = 0;
4734
4735 mutex_lock(&ar->conf_mutex);
4736
4737 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004738 arvif->fixed_nss == fixed_nss &&
4739 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004740 goto exit;
4741
4742 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004743 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004744
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004745 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004746 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004747
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004748 vdev_param = ar->wmi.vdev_param->fixed_rate;
4749 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4750 vdev_param, fixed_rate);
4751 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004752 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004753 fixed_rate, ret);
4754 ret = -EINVAL;
4755 goto exit;
4756 }
4757
4758 arvif->fixed_rate = fixed_rate;
4759
4760 vdev_param = ar->wmi.vdev_param->nss;
4761 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4762 vdev_param, fixed_nss);
4763
4764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004765 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004766 fixed_nss, ret);
4767 ret = -EINVAL;
4768 goto exit;
4769 }
4770
4771 arvif->fixed_nss = fixed_nss;
4772
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004773 vdev_param = ar->wmi.vdev_param->sgi;
4774 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4775 force_sgi);
4776
4777 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004778 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004779 force_sgi, ret);
4780 ret = -EINVAL;
4781 goto exit;
4782 }
4783
4784 arvif->force_sgi = force_sgi;
4785
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004786exit:
4787 mutex_unlock(&ar->conf_mutex);
4788 return ret;
4789}
4790
4791static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4792 struct ieee80211_vif *vif,
4793 const struct cfg80211_bitrate_mask *mask)
4794{
4795 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4796 struct ath10k *ar = arvif->ar;
4797 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4798 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4799 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004800 u8 force_sgi;
4801
Ben Greearb116ea12014-11-24 16:22:10 +02004802 if (ar->cfg_tx_chainmask)
4803 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4804
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004805 force_sgi = mask->control[band].gi;
4806 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4807 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004808
4809 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004810 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004811 &fixed_rate,
4812 &fixed_nss))
4813 return -EINVAL;
4814 }
4815
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004816 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004817 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004818 return -EINVAL;
4819 }
4820
4821 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4822 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004823}
4824
Michal Kazior9797feb2014-02-14 14:49:48 +01004825static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4826 struct ieee80211_vif *vif,
4827 struct ieee80211_sta *sta,
4828 u32 changed)
4829{
4830 struct ath10k *ar = hw->priv;
4831 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4832 u32 bw, smps;
4833
4834 spin_lock_bh(&ar->data_lock);
4835
Michal Kazior7aa7a722014-08-25 12:09:38 +02004836 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004837 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4838 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4839 sta->smps_mode);
4840
4841 if (changed & IEEE80211_RC_BW_CHANGED) {
4842 bw = WMI_PEER_CHWIDTH_20MHZ;
4843
4844 switch (sta->bandwidth) {
4845 case IEEE80211_STA_RX_BW_20:
4846 bw = WMI_PEER_CHWIDTH_20MHZ;
4847 break;
4848 case IEEE80211_STA_RX_BW_40:
4849 bw = WMI_PEER_CHWIDTH_40MHZ;
4850 break;
4851 case IEEE80211_STA_RX_BW_80:
4852 bw = WMI_PEER_CHWIDTH_80MHZ;
4853 break;
4854 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004855 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004856 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004857 bw = WMI_PEER_CHWIDTH_20MHZ;
4858 break;
4859 }
4860
4861 arsta->bw = bw;
4862 }
4863
4864 if (changed & IEEE80211_RC_NSS_CHANGED)
4865 arsta->nss = sta->rx_nss;
4866
4867 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4868 smps = WMI_PEER_SMPS_PS_NONE;
4869
4870 switch (sta->smps_mode) {
4871 case IEEE80211_SMPS_AUTOMATIC:
4872 case IEEE80211_SMPS_OFF:
4873 smps = WMI_PEER_SMPS_PS_NONE;
4874 break;
4875 case IEEE80211_SMPS_STATIC:
4876 smps = WMI_PEER_SMPS_STATIC;
4877 break;
4878 case IEEE80211_SMPS_DYNAMIC:
4879 smps = WMI_PEER_SMPS_DYNAMIC;
4880 break;
4881 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004882 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004883 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004884 smps = WMI_PEER_SMPS_PS_NONE;
4885 break;
4886 }
4887
4888 arsta->smps = smps;
4889 }
4890
Michal Kazior9797feb2014-02-14 14:49:48 +01004891 arsta->changed |= changed;
4892
4893 spin_unlock_bh(&ar->data_lock);
4894
4895 ieee80211_queue_work(hw, &arsta->update_wk);
4896}
4897
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004898static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4899{
4900 /*
4901 * FIXME: Return 0 for time being. Need to figure out whether FW
4902 * has the API to fetch 64-bit local TSF
4903 */
4904
4905 return 0;
4906}
4907
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004908static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4909 struct ieee80211_vif *vif,
4910 enum ieee80211_ampdu_mlme_action action,
4911 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4912 u8 buf_size)
4913{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004914 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004915 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4916
Michal Kazior7aa7a722014-08-25 12:09:38 +02004917 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 +02004918 arvif->vdev_id, sta->addr, tid, action);
4919
4920 switch (action) {
4921 case IEEE80211_AMPDU_RX_START:
4922 case IEEE80211_AMPDU_RX_STOP:
4923 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4924 * creation/removal. Do we need to verify this?
4925 */
4926 return 0;
4927 case IEEE80211_AMPDU_TX_START:
4928 case IEEE80211_AMPDU_TX_STOP_CONT:
4929 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4930 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4931 case IEEE80211_AMPDU_TX_OPERATIONAL:
4932 /* Firmware offloads Tx aggregation entirely so deny mac80211
4933 * Tx aggregation requests.
4934 */
4935 return -EOPNOTSUPP;
4936 }
4937
4938 return -EINVAL;
4939}
4940
Kalle Valo5e3dd152013-06-12 20:52:10 +03004941static const struct ieee80211_ops ath10k_ops = {
4942 .tx = ath10k_tx,
4943 .start = ath10k_start,
4944 .stop = ath10k_stop,
4945 .config = ath10k_config,
4946 .add_interface = ath10k_add_interface,
4947 .remove_interface = ath10k_remove_interface,
4948 .configure_filter = ath10k_configure_filter,
4949 .bss_info_changed = ath10k_bss_info_changed,
4950 .hw_scan = ath10k_hw_scan,
4951 .cancel_hw_scan = ath10k_cancel_hw_scan,
4952 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004953 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004954 .sta_state = ath10k_sta_state,
4955 .conf_tx = ath10k_conf_tx,
4956 .remain_on_channel = ath10k_remain_on_channel,
4957 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4958 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004959 .flush = ath10k_flush,
4960 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004961 .set_antenna = ath10k_set_antenna,
4962 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004963 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004964 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004965 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004966 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004967 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004968 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004969 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4970 .get_et_stats = ath10k_debug_get_et_stats,
4971 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004972
4973 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4974
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004975#ifdef CONFIG_PM
4976 .suspend = ath10k_suspend,
4977 .resume = ath10k_resume,
4978#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004979#ifdef CONFIG_MAC80211_DEBUGFS
4980 .sta_add_debugfs = ath10k_sta_add_debugfs,
4981#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004982};
4983
4984#define RATETAB_ENT(_rate, _rateid, _flags) { \
4985 .bitrate = (_rate), \
4986 .flags = (_flags), \
4987 .hw_value = (_rateid), \
4988}
4989
4990#define CHAN2G(_channel, _freq, _flags) { \
4991 .band = IEEE80211_BAND_2GHZ, \
4992 .hw_value = (_channel), \
4993 .center_freq = (_freq), \
4994 .flags = (_flags), \
4995 .max_antenna_gain = 0, \
4996 .max_power = 30, \
4997}
4998
4999#define CHAN5G(_channel, _freq, _flags) { \
5000 .band = IEEE80211_BAND_5GHZ, \
5001 .hw_value = (_channel), \
5002 .center_freq = (_freq), \
5003 .flags = (_flags), \
5004 .max_antenna_gain = 0, \
5005 .max_power = 30, \
5006}
5007
5008static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5009 CHAN2G(1, 2412, 0),
5010 CHAN2G(2, 2417, 0),
5011 CHAN2G(3, 2422, 0),
5012 CHAN2G(4, 2427, 0),
5013 CHAN2G(5, 2432, 0),
5014 CHAN2G(6, 2437, 0),
5015 CHAN2G(7, 2442, 0),
5016 CHAN2G(8, 2447, 0),
5017 CHAN2G(9, 2452, 0),
5018 CHAN2G(10, 2457, 0),
5019 CHAN2G(11, 2462, 0),
5020 CHAN2G(12, 2467, 0),
5021 CHAN2G(13, 2472, 0),
5022 CHAN2G(14, 2484, 0),
5023};
5024
5025static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005026 CHAN5G(36, 5180, 0),
5027 CHAN5G(40, 5200, 0),
5028 CHAN5G(44, 5220, 0),
5029 CHAN5G(48, 5240, 0),
5030 CHAN5G(52, 5260, 0),
5031 CHAN5G(56, 5280, 0),
5032 CHAN5G(60, 5300, 0),
5033 CHAN5G(64, 5320, 0),
5034 CHAN5G(100, 5500, 0),
5035 CHAN5G(104, 5520, 0),
5036 CHAN5G(108, 5540, 0),
5037 CHAN5G(112, 5560, 0),
5038 CHAN5G(116, 5580, 0),
5039 CHAN5G(120, 5600, 0),
5040 CHAN5G(124, 5620, 0),
5041 CHAN5G(128, 5640, 0),
5042 CHAN5G(132, 5660, 0),
5043 CHAN5G(136, 5680, 0),
5044 CHAN5G(140, 5700, 0),
5045 CHAN5G(149, 5745, 0),
5046 CHAN5G(153, 5765, 0),
5047 CHAN5G(157, 5785, 0),
5048 CHAN5G(161, 5805, 0),
5049 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005050};
5051
Michal Kazior91b12082014-12-12 12:41:35 +01005052/* Note: Be careful if you re-order these. There is code which depends on this
5053 * ordering.
5054 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005055static struct ieee80211_rate ath10k_rates[] = {
5056 /* CCK */
5057 RATETAB_ENT(10, 0x82, 0),
5058 RATETAB_ENT(20, 0x84, 0),
5059 RATETAB_ENT(55, 0x8b, 0),
5060 RATETAB_ENT(110, 0x96, 0),
5061 /* OFDM */
5062 RATETAB_ENT(60, 0x0c, 0),
5063 RATETAB_ENT(90, 0x12, 0),
5064 RATETAB_ENT(120, 0x18, 0),
5065 RATETAB_ENT(180, 0x24, 0),
5066 RATETAB_ENT(240, 0x30, 0),
5067 RATETAB_ENT(360, 0x48, 0),
5068 RATETAB_ENT(480, 0x60, 0),
5069 RATETAB_ENT(540, 0x6c, 0),
5070};
5071
5072#define ath10k_a_rates (ath10k_rates + 4)
5073#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5074#define ath10k_g_rates (ath10k_rates + 0)
5075#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5076
Michal Kaziore7b54192014-08-07 11:03:27 +02005077struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005078{
5079 struct ieee80211_hw *hw;
5080 struct ath10k *ar;
5081
Michal Kaziore7b54192014-08-07 11:03:27 +02005082 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005083 if (!hw)
5084 return NULL;
5085
5086 ar = hw->priv;
5087 ar->hw = hw;
5088
5089 return ar;
5090}
5091
5092void ath10k_mac_destroy(struct ath10k *ar)
5093{
5094 ieee80211_free_hw(ar->hw);
5095}
5096
5097static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5098 {
5099 .max = 8,
5100 .types = BIT(NL80211_IFTYPE_STATION)
5101 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005102 },
5103 {
5104 .max = 3,
5105 .types = BIT(NL80211_IFTYPE_P2P_GO)
5106 },
5107 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005108 .max = 1,
5109 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5110 },
5111 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005112 .max = 7,
5113 .types = BIT(NL80211_IFTYPE_AP)
5114 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005115};
5116
Bartosz Markowskif2595092013-12-10 16:20:39 +01005117static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005118 {
5119 .max = 8,
5120 .types = BIT(NL80211_IFTYPE_AP)
5121 },
5122};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005123
5124static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5125 {
5126 .limits = ath10k_if_limits,
5127 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5128 .max_interfaces = 8,
5129 .num_different_channels = 1,
5130 .beacon_int_infra_match = true,
5131 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005132};
5133
5134static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005135 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005136 .limits = ath10k_10x_if_limits,
5137 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005138 .max_interfaces = 8,
5139 .num_different_channels = 1,
5140 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005141#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005142 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5143 BIT(NL80211_CHAN_WIDTH_20) |
5144 BIT(NL80211_CHAN_WIDTH_40) |
5145 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005146#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005147 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005148};
5149
5150static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5151{
5152 struct ieee80211_sta_vht_cap vht_cap = {0};
5153 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005154 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005155
5156 vht_cap.vht_supported = 1;
5157 vht_cap.cap = ar->vht_cap_info;
5158
Michal Kazior8865bee42013-07-24 12:36:46 +02005159 mcs_map = 0;
5160 for (i = 0; i < 8; i++) {
5161 if (i < ar->num_rf_chains)
5162 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5163 else
5164 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5165 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005166
5167 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5168 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5169
5170 return vht_cap;
5171}
5172
5173static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5174{
5175 int i;
5176 struct ieee80211_sta_ht_cap ht_cap = {0};
5177
5178 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5179 return ht_cap;
5180
5181 ht_cap.ht_supported = 1;
5182 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5183 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5184 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5185 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5186 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5187
5188 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5189 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5190
5191 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5192 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5193
5194 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5195 u32 smps;
5196
5197 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5198 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5199
5200 ht_cap.cap |= smps;
5201 }
5202
5203 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5204 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5205
5206 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5207 u32 stbc;
5208
5209 stbc = ar->ht_cap_info;
5210 stbc &= WMI_HT_CAP_RX_STBC;
5211 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5212 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5213 stbc &= IEEE80211_HT_CAP_RX_STBC;
5214
5215 ht_cap.cap |= stbc;
5216 }
5217
5218 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5219 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5220
5221 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5222 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5223
5224 /* max AMSDU is implicitly taken from vht_cap_info */
5225 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5226 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5227
Michal Kazior8865bee42013-07-24 12:36:46 +02005228 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005229 ht_cap.mcs.rx_mask[i] = 0xFF;
5230
5231 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5232
5233 return ht_cap;
5234}
5235
Kalle Valo5e3dd152013-06-12 20:52:10 +03005236static void ath10k_get_arvif_iter(void *data, u8 *mac,
5237 struct ieee80211_vif *vif)
5238{
5239 struct ath10k_vif_iter *arvif_iter = data;
5240 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5241
5242 if (arvif->vdev_id == arvif_iter->vdev_id)
5243 arvif_iter->arvif = arvif;
5244}
5245
5246struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5247{
5248 struct ath10k_vif_iter arvif_iter;
5249 u32 flags;
5250
5251 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5252 arvif_iter.vdev_id = vdev_id;
5253
5254 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5255 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5256 flags,
5257 ath10k_get_arvif_iter,
5258 &arvif_iter);
5259 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005260 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005261 return NULL;
5262 }
5263
5264 return arvif_iter.arvif;
5265}
5266
5267int ath10k_mac_register(struct ath10k *ar)
5268{
5269 struct ieee80211_supported_band *band;
5270 struct ieee80211_sta_vht_cap vht_cap;
5271 struct ieee80211_sta_ht_cap ht_cap;
5272 void *channels;
5273 int ret;
5274
5275 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5276
5277 SET_IEEE80211_DEV(ar->hw, ar->dev);
5278
5279 ht_cap = ath10k_get_ht_cap(ar);
5280 vht_cap = ath10k_create_vht_cap(ar);
5281
5282 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5283 channels = kmemdup(ath10k_2ghz_channels,
5284 sizeof(ath10k_2ghz_channels),
5285 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005286 if (!channels) {
5287 ret = -ENOMEM;
5288 goto err_free;
5289 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005290
5291 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5292 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5293 band->channels = channels;
5294 band->n_bitrates = ath10k_g_rates_size;
5295 band->bitrates = ath10k_g_rates;
5296 band->ht_cap = ht_cap;
5297
Yanbo Lid68bb122015-01-23 08:18:20 +08005298 /* Enable the VHT support at 2.4 GHz */
5299 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005300
5301 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5302 }
5303
5304 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5305 channels = kmemdup(ath10k_5ghz_channels,
5306 sizeof(ath10k_5ghz_channels),
5307 GFP_KERNEL);
5308 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005309 ret = -ENOMEM;
5310 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311 }
5312
5313 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5314 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5315 band->channels = channels;
5316 band->n_bitrates = ath10k_a_rates_size;
5317 band->bitrates = ath10k_a_rates;
5318 band->ht_cap = ht_cap;
5319 band->vht_cap = vht_cap;
5320 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5321 }
5322
5323 ar->hw->wiphy->interface_modes =
5324 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005325 BIT(NL80211_IFTYPE_AP);
5326
Ben Greear46acf7b2014-05-16 17:15:38 +03005327 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5328 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5329
Bartosz Markowskid3541812013-12-10 16:20:40 +01005330 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5331 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005332 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005333 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5334 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005335
5336 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5337 IEEE80211_HW_SUPPORTS_PS |
5338 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5339 IEEE80211_HW_SUPPORTS_UAPSD |
5340 IEEE80211_HW_MFP_CAPABLE |
5341 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5342 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005343 IEEE80211_HW_AP_LINK_PS |
5344 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005345
Eliad Peller0d8614b2014-09-10 14:07:36 +03005346 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5347
Kalle Valo5e3dd152013-06-12 20:52:10 +03005348 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005349 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005350
5351 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5352 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5353 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5354 }
5355
5356 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5357 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5358
5359 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005360 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005361
Kalle Valo5e3dd152013-06-12 20:52:10 +03005362 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5363
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005364 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5365 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5366
5367 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5368 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5369 * correct Probe Responses. This is more of a hack advert..
5370 */
5371 ar->hw->wiphy->probe_resp_offload |=
5372 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5373 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5374 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5375 }
5376
Kalle Valo5e3dd152013-06-12 20:52:10 +03005377 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005378 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005379 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5380
5381 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005382 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5383
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384 /*
5385 * on LL hardware queues are managed entirely by the FW
5386 * so we only advertise to mac we can do the queues thing
5387 */
5388 ar->hw->queues = 4;
5389
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005390 switch (ar->wmi.op_version) {
5391 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5392 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005393 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5394 ar->hw->wiphy->n_iface_combinations =
5395 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005396 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005397 break;
5398 case ATH10K_FW_WMI_OP_VERSION_10_1:
5399 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005400 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005401 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5402 ar->hw->wiphy->n_iface_combinations =
5403 ARRAY_SIZE(ath10k_10x_if_comb);
5404 break;
5405 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5406 case ATH10K_FW_WMI_OP_VERSION_MAX:
5407 WARN_ON(1);
5408 ret = -EINVAL;
5409 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005410 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005411
Michal Kazior7c199992013-07-31 10:47:57 +02005412 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5413
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005414 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5415 /* Init ath dfs pattern detector */
5416 ar->ath_common.debug_mask = ATH_DBG_DFS;
5417 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5418 NL80211_DFS_UNSET);
5419
5420 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005421 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005422 }
5423
Kalle Valo5e3dd152013-06-12 20:52:10 +03005424 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5425 ath10k_reg_notifier);
5426 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005427 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005428 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005429 }
5430
5431 ret = ieee80211_register_hw(ar->hw);
5432 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005433 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005434 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005435 }
5436
5437 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5438 ret = regulatory_hint(ar->hw->wiphy,
5439 ar->ath_common.regulatory.alpha2);
5440 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005441 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005442 }
5443
5444 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005445
5446err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005447 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005448err_free:
5449 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5450 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5451
Kalle Valo5e3dd152013-06-12 20:52:10 +03005452 return ret;
5453}
5454
5455void ath10k_mac_unregister(struct ath10k *ar)
5456{
5457 ieee80211_unregister_hw(ar->hw);
5458
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005459 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5460 ar->dfs_detector->exit(ar->dfs_detector);
5461
Kalle Valo5e3dd152013-06-12 20:52:10 +03005462 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5463 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5464
5465 SET_IEEE80211_DEV(ar->hw, NULL);
5466}