blob: d3fe1a378e8bf12bf29158e29b4ed610598a38d6 [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
534 dev_kfree_skb_any(arvif->beacon);
535
536 arvif->beacon = NULL;
537 arvif->beacon_sent = false;
538}
539
540static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
541{
542 struct ath10k *ar = arvif->ar;
543
544 lockdep_assert_held(&ar->data_lock);
545
546 ath10k_mac_vif_beacon_free(arvif);
547
548 if (arvif->beacon_buf) {
549 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
550 arvif->beacon_buf, arvif->beacon_paddr);
551 arvif->beacon_buf = NULL;
552 }
553}
554
Kalle Valo5e3dd152013-06-12 20:52:10 +0300555static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
556{
557 int ret;
558
Michal Kazior548db542013-07-05 16:15:15 +0300559 lockdep_assert_held(&ar->conf_mutex);
560
Michal Kazior7962b0d2014-10-28 10:34:38 +0100561 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
562 return -ESHUTDOWN;
563
Kalle Valo5e3dd152013-06-12 20:52:10 +0300564 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
565 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
566 if (ret == 0)
567 return -ETIMEDOUT;
568
569 return 0;
570}
571
Michal Kazior1bbc0972014-04-08 09:45:47 +0300572static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300573{
Michal Kaziorc930f742014-01-23 11:38:25 +0100574 struct cfg80211_chan_def *chandef = &ar->chandef;
575 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300576 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300577 int ret = 0;
578
579 lockdep_assert_held(&ar->conf_mutex);
580
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581 arg.vdev_id = vdev_id;
582 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100583 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584
585 /* TODO setup this dynamically, what in case we
586 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100587 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200588 arg.channel.chan_radar =
589 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300590
Michal Kazior89c5c842013-10-23 04:02:13 -0700591 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700592 arg.channel.max_power = channel->max_power * 2;
593 arg.channel.max_reg_power = channel->max_reg_power * 2;
594 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595
Michal Kazior7962b0d2014-10-28 10:34:38 +0100596 reinit_completion(&ar->vdev_setup_done);
597
Kalle Valo5e3dd152013-06-12 20:52:10 +0300598 ret = ath10k_wmi_vdev_start(ar, &arg);
599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200600 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200601 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 return ret;
603 }
604
605 ret = ath10k_vdev_setup_sync(ar);
606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200607 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200608 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609 return ret;
610 }
611
612 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
613 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200614 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200615 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616 goto vdev_stop;
617 }
618
619 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620
Michal Kazior7aa7a722014-08-25 12:09:38 +0200621 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300622 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623 return 0;
624
625vdev_stop:
626 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
627 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200628 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200629 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300630
631 return ret;
632}
633
Michal Kazior1bbc0972014-04-08 09:45:47 +0300634static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300635{
636 int ret = 0;
637
638 lockdep_assert_held(&ar->conf_mutex);
639
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200640 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
641 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200642 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200643 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300644
Michal Kazior7962b0d2014-10-28 10:34:38 +0100645 reinit_completion(&ar->vdev_setup_done);
646
Kalle Valo5e3dd152013-06-12 20:52:10 +0300647 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
648 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200649 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200650 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300651
652 ret = ath10k_vdev_setup_sync(ar);
653 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200654 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200655 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300656
Michal Kazior7aa7a722014-08-25 12:09:38 +0200657 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300658 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300659 return ret;
660}
661
Michal Kazior1bbc0972014-04-08 09:45:47 +0300662static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663{
664 int bit, ret = 0;
665
666 lockdep_assert_held(&ar->conf_mutex);
667
Ben Greeara9aefb32014-08-12 11:02:19 +0300668 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200669 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670 return -ENOMEM;
671 }
672
Ben Greear16c11172014-09-23 14:17:16 -0700673 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300674
Ben Greear16c11172014-09-23 14:17:16 -0700675 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300676
677 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
678 WMI_VDEV_TYPE_MONITOR,
679 0, ar->mac_addr);
680 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200681 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200682 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300683 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300684 }
685
Ben Greear16c11172014-09-23 14:17:16 -0700686 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200687 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688 ar->monitor_vdev_id);
689
Kalle Valo5e3dd152013-06-12 20:52:10 +0300690 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300691}
692
Michal Kazior1bbc0972014-04-08 09:45:47 +0300693static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694{
695 int ret = 0;
696
697 lockdep_assert_held(&ar->conf_mutex);
698
Kalle Valo5e3dd152013-06-12 20:52:10 +0300699 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
700 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200701 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200702 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 return ret;
704 }
705
Ben Greear16c11172014-09-23 14:17:16 -0700706 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707
Michal Kazior7aa7a722014-08-25 12:09:38 +0200708 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300709 ar->monitor_vdev_id);
710 return ret;
711}
712
Michal Kazior1bbc0972014-04-08 09:45:47 +0300713static int ath10k_monitor_start(struct ath10k *ar)
714{
715 int ret;
716
717 lockdep_assert_held(&ar->conf_mutex);
718
Michal Kazior1bbc0972014-04-08 09:45:47 +0300719 ret = ath10k_monitor_vdev_create(ar);
720 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200721 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300722 return ret;
723 }
724
725 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
726 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200727 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300728 ath10k_monitor_vdev_delete(ar);
729 return ret;
730 }
731
732 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200733 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300734
735 return 0;
736}
737
Michal Kazior19337472014-08-28 12:58:16 +0200738static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300739{
740 int ret;
741
742 lockdep_assert_held(&ar->conf_mutex);
743
Michal Kazior1bbc0972014-04-08 09:45:47 +0300744 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200746 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200747 return ret;
748 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300749
750 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200751 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200752 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200753 return ret;
754 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300755
756 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200758
759 return 0;
760}
761
762static int ath10k_monitor_recalc(struct ath10k *ar)
763{
764 bool should_start;
765
766 lockdep_assert_held(&ar->conf_mutex);
767
768 should_start = ar->monitor ||
769 ar->filter_flags & FIF_PROMISC_IN_BSS ||
770 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
771
772 ath10k_dbg(ar, ATH10K_DBG_MAC,
773 "mac monitor recalc started? %d should? %d\n",
774 ar->monitor_started, should_start);
775
776 if (should_start == ar->monitor_started)
777 return 0;
778
779 if (should_start)
780 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300781
782 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300783}
784
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200785static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
786{
787 struct ath10k *ar = arvif->ar;
788 u32 vdev_param, rts_cts = 0;
789
790 lockdep_assert_held(&ar->conf_mutex);
791
792 vdev_param = ar->wmi.vdev_param->enable_rtscts;
793
794 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
795 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
796
797 if (arvif->num_legacy_stations > 0)
798 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
799 WMI_RTSCTS_PROFILE);
800
801 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
802 rts_cts);
803}
804
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200805static int ath10k_start_cac(struct ath10k *ar)
806{
807 int ret;
808
809 lockdep_assert_held(&ar->conf_mutex);
810
811 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
812
Michal Kazior19337472014-08-28 12:58:16 +0200813 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200814 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200815 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200816 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
817 return ret;
818 }
819
Michal Kazior7aa7a722014-08-25 12:09:38 +0200820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200821 ar->monitor_vdev_id);
822
823 return 0;
824}
825
826static int ath10k_stop_cac(struct ath10k *ar)
827{
828 lockdep_assert_held(&ar->conf_mutex);
829
830 /* CAC is not running - do nothing */
831 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
832 return 0;
833
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200834 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300835 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200836
Michal Kazior7aa7a722014-08-25 12:09:38 +0200837 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838
839 return 0;
840}
841
Michal Kaziord6500972014-04-08 09:56:09 +0300842static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200843{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200844 int ret;
845
846 lockdep_assert_held(&ar->conf_mutex);
847
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200848 ath10k_stop_cac(ar);
849
Michal Kaziord6500972014-04-08 09:56:09 +0300850 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200851 return;
852
Michal Kaziord6500972014-04-08 09:56:09 +0300853 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200854 return;
855
856 ret = ath10k_start_cac(ar);
857 if (ret) {
858 /*
859 * Not possible to start CAC on current channel so starting
860 * radiation is not allowed, make this channel DFS_UNAVAILABLE
861 * by indicating that radar was detected.
862 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200863 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200864 ieee80211_radar_detected(ar->hw);
865 }
866}
867
Michal Kaziordc55e302014-07-29 12:53:36 +0300868static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300869{
870 struct ath10k *ar = arvif->ar;
871 struct cfg80211_chan_def *chandef = &ar->chandef;
872 struct wmi_vdev_start_request_arg arg = {};
873 int ret = 0;
874
875 lockdep_assert_held(&ar->conf_mutex);
876
877 reinit_completion(&ar->vdev_setup_done);
878
879 arg.vdev_id = arvif->vdev_id;
880 arg.dtim_period = arvif->dtim_period;
881 arg.bcn_intval = arvif->beacon_interval;
882
883 arg.channel.freq = chandef->chan->center_freq;
884 arg.channel.band_center_freq1 = chandef->center_freq1;
885 arg.channel.mode = chan_to_phymode(chandef);
886
887 arg.channel.min_power = 0;
888 arg.channel.max_power = chandef->chan->max_power * 2;
889 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
890 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
891
892 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
893 arg.ssid = arvif->u.ap.ssid;
894 arg.ssid_len = arvif->u.ap.ssid_len;
895 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
896
897 /* For now allow DFS for AP mode */
898 arg.channel.chan_radar =
899 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
900 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
901 arg.ssid = arvif->vif->bss_conf.ssid;
902 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
903 }
904
Michal Kazior7aa7a722014-08-25 12:09:38 +0200905 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300906 "mac vdev %d start center_freq %d phymode %s\n",
907 arg.vdev_id, arg.channel.freq,
908 ath10k_wmi_phymode_str(arg.channel.mode));
909
Michal Kaziordc55e302014-07-29 12:53:36 +0300910 if (restart)
911 ret = ath10k_wmi_vdev_restart(ar, &arg);
912 else
913 ret = ath10k_wmi_vdev_start(ar, &arg);
914
Michal Kazior72654fa2014-04-08 09:56:09 +0300915 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200916 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300917 arg.vdev_id, ret);
918 return ret;
919 }
920
921 ret = ath10k_vdev_setup_sync(ar);
922 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200923 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300924 arg.vdev_id, ret);
925 return ret;
926 }
927
Michal Kaziord6500972014-04-08 09:56:09 +0300928 ar->num_started_vdevs++;
929 ath10k_recalc_radar_detection(ar);
930
Michal Kazior72654fa2014-04-08 09:56:09 +0300931 return ret;
932}
933
Michal Kaziordc55e302014-07-29 12:53:36 +0300934static int ath10k_vdev_start(struct ath10k_vif *arvif)
935{
936 return ath10k_vdev_start_restart(arvif, false);
937}
938
939static int ath10k_vdev_restart(struct ath10k_vif *arvif)
940{
941 return ath10k_vdev_start_restart(arvif, true);
942}
943
Michal Kazior72654fa2014-04-08 09:56:09 +0300944static int ath10k_vdev_stop(struct ath10k_vif *arvif)
945{
946 struct ath10k *ar = arvif->ar;
947 int ret;
948
949 lockdep_assert_held(&ar->conf_mutex);
950
951 reinit_completion(&ar->vdev_setup_done);
952
953 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
954 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200955 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300956 arvif->vdev_id, ret);
957 return ret;
958 }
959
960 ret = ath10k_vdev_setup_sync(ar);
961 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200962 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300963 arvif->vdev_id, ret);
964 return ret;
965 }
966
Michal Kaziord6500972014-04-08 09:56:09 +0300967 WARN_ON(ar->num_started_vdevs == 0);
968
969 if (ar->num_started_vdevs != 0) {
970 ar->num_started_vdevs--;
971 ath10k_recalc_radar_detection(ar);
972 }
973
Michal Kazior72654fa2014-04-08 09:56:09 +0300974 return ret;
975}
976
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200977static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
978 struct sk_buff *bcn)
979{
980 struct ath10k *ar = arvif->ar;
981 struct ieee80211_mgmt *mgmt;
982 const u8 *p2p_ie;
983 int ret;
984
985 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
986 return 0;
987
988 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
989 return 0;
990
991 mgmt = (void *)bcn->data;
992 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
993 mgmt->u.beacon.variable,
994 bcn->len - (mgmt->u.beacon.variable -
995 bcn->data));
996 if (!p2p_ie)
997 return -ENOENT;
998
999 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1000 if (ret) {
1001 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1002 arvif->vdev_id, ret);
1003 return ret;
1004 }
1005
1006 return 0;
1007}
1008
1009static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1010 u8 oui_type, size_t ie_offset)
1011{
1012 size_t len;
1013 const u8 *next;
1014 const u8 *end;
1015 u8 *ie;
1016
1017 if (WARN_ON(skb->len < ie_offset))
1018 return -EINVAL;
1019
1020 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1021 skb->data + ie_offset,
1022 skb->len - ie_offset);
1023 if (!ie)
1024 return -ENOENT;
1025
1026 len = ie[1] + 2;
1027 end = skb->data + skb->len;
1028 next = ie + len;
1029
1030 if (WARN_ON(next > end))
1031 return -EINVAL;
1032
1033 memmove(ie, next, end - next);
1034 skb_trim(skb, skb->len - len);
1035
1036 return 0;
1037}
1038
1039static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1040{
1041 struct ath10k *ar = arvif->ar;
1042 struct ieee80211_hw *hw = ar->hw;
1043 struct ieee80211_vif *vif = arvif->vif;
1044 struct ieee80211_mutable_offsets offs = {};
1045 struct sk_buff *bcn;
1046 int ret;
1047
1048 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1049 return 0;
1050
1051 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1052 if (!bcn) {
1053 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1054 return -EPERM;
1055 }
1056
1057 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1058 if (ret) {
1059 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1060 kfree_skb(bcn);
1061 return ret;
1062 }
1063
1064 /* P2P IE is inserted by firmware automatically (as configured above)
1065 * so remove it from the base beacon template to avoid duplicate P2P
1066 * IEs in beacon frames.
1067 */
1068 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1069 offsetof(struct ieee80211_mgmt,
1070 u.beacon.variable));
1071
1072 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1073 0, NULL, 0);
1074 kfree_skb(bcn);
1075
1076 if (ret) {
1077 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1078 ret);
1079 return ret;
1080 }
1081
1082 return 0;
1083}
1084
1085static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1086{
1087 struct ath10k *ar = arvif->ar;
1088 struct ieee80211_hw *hw = ar->hw;
1089 struct ieee80211_vif *vif = arvif->vif;
1090 struct sk_buff *prb;
1091 int ret;
1092
1093 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1094 return 0;
1095
1096 prb = ieee80211_proberesp_get(hw, vif);
1097 if (!prb) {
1098 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1099 return -EPERM;
1100 }
1101
1102 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1103 kfree_skb(prb);
1104
1105 if (ret) {
1106 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1107 ret);
1108 return ret;
1109 }
1110
1111 return 0;
1112}
1113
Kalle Valo5e3dd152013-06-12 20:52:10 +03001114static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001115 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001116{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001117 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118 int ret = 0;
1119
Michal Kazior548db542013-07-05 16:15:15 +03001120 lockdep_assert_held(&arvif->ar->conf_mutex);
1121
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 if (!info->enable_beacon) {
1123 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001124
1125 arvif->is_started = false;
1126 arvif->is_up = false;
1127
Michal Kazior748afc42014-01-23 12:48:21 +01001128 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001129 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001130 spin_unlock_bh(&arvif->ar->data_lock);
1131
Kalle Valo5e3dd152013-06-12 20:52:10 +03001132 return;
1133 }
1134
1135 arvif->tx_seq_no = 0x1000;
1136
1137 ret = ath10k_vdev_start(arvif);
1138 if (ret)
1139 return;
1140
Michal Kaziorc930f742014-01-23 11:38:25 +01001141 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001142 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001143
1144 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1145 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001146 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001147 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001148 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001149 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001150 return;
1151 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001152
1153 arvif->is_started = true;
1154 arvif->is_up = true;
1155
Michal Kazior7aa7a722014-08-25 12:09:38 +02001156 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001157}
1158
1159static void ath10k_control_ibss(struct ath10k_vif *arvif,
1160 struct ieee80211_bss_conf *info,
1161 const u8 self_peer[ETH_ALEN])
1162{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001163 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001164 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001165 int ret = 0;
1166
Michal Kazior548db542013-07-05 16:15:15 +03001167 lockdep_assert_held(&arvif->ar->conf_mutex);
1168
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169 if (!info->ibss_joined) {
1170 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1171 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001172 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001173 self_peer, arvif->vdev_id, ret);
1174
Michal Kaziorc930f742014-01-23 11:38:25 +01001175 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001176 return;
1177
Michal Kaziorc930f742014-01-23 11:38:25 +01001178 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001179
1180 return;
1181 }
1182
1183 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1184 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001185 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001186 self_peer, arvif->vdev_id, ret);
1187 return;
1188 }
1189
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001190 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1191 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001192 ATH10K_DEFAULT_ATIM);
1193 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001194 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195 arvif->vdev_id, ret);
1196}
1197
Michal Kazior9f9b5742014-12-12 12:41:36 +01001198static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1199{
1200 struct ath10k *ar = arvif->ar;
1201 u32 param;
1202 u32 value;
1203 int ret;
1204
1205 lockdep_assert_held(&arvif->ar->conf_mutex);
1206
1207 if (arvif->u.sta.uapsd)
1208 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1209 else
1210 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1211
1212 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1213 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1214 if (ret) {
1215 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1216 value, arvif->vdev_id, ret);
1217 return ret;
1218 }
1219
1220 return 0;
1221}
1222
1223static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1224{
1225 struct ath10k *ar = arvif->ar;
1226 u32 param;
1227 u32 value;
1228 int ret;
1229
1230 lockdep_assert_held(&arvif->ar->conf_mutex);
1231
1232 if (arvif->u.sta.uapsd)
1233 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1234 else
1235 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1236
1237 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1238 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1239 param, value);
1240 if (ret) {
1241 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1242 value, arvif->vdev_id, ret);
1243 return ret;
1244 }
1245
1246 return 0;
1247}
1248
Michal Kaziorad088bf2013-10-16 15:44:46 +03001249static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001250{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001251 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001252 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001253 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254 enum wmi_sta_powersave_param param;
1255 enum wmi_sta_ps_mode psmode;
1256 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001257 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001258
Michal Kazior548db542013-07-05 16:15:15 +03001259 lockdep_assert_held(&arvif->ar->conf_mutex);
1260
Michal Kaziorad088bf2013-10-16 15:44:46 +03001261 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1262 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263
Michal Kaziorbf14e652014-12-12 12:41:38 +01001264 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001265 psmode = WMI_STA_PS_MODE_ENABLED;
1266 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1267
Michal Kazior526549a2014-12-12 12:41:37 +01001268 ps_timeout = conf->dynamic_ps_timeout;
1269 if (ps_timeout == 0) {
1270 /* Firmware doesn't like 0 */
1271 ps_timeout = ieee80211_tu_to_usec(
1272 vif->bss_conf.beacon_int) / 1000;
1273 }
1274
Michal Kaziorad088bf2013-10-16 15:44:46 +03001275 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001276 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001278 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001279 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001280 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001281 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001282 } else {
1283 psmode = WMI_STA_PS_MODE_DISABLED;
1284 }
1285
Michal Kazior7aa7a722014-08-25 12:09:38 +02001286 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001287 arvif->vdev_id, psmode ? "enable" : "disable");
1288
Michal Kaziorad088bf2013-10-16 15:44:46 +03001289 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1290 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001291 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001292 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001293 return ret;
1294 }
1295
1296 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297}
1298
Michal Kazior46725b12015-01-28 09:57:49 +02001299static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1300{
1301 struct ath10k *ar = arvif->ar;
1302 struct wmi_sta_keepalive_arg arg = {};
1303 int ret;
1304
1305 lockdep_assert_held(&arvif->ar->conf_mutex);
1306
1307 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1308 return 0;
1309
1310 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1311 return 0;
1312
1313 /* Some firmware revisions have a bug and ignore the `enabled` field.
1314 * Instead use the interval to disable the keepalive.
1315 */
1316 arg.vdev_id = arvif->vdev_id;
1317 arg.enabled = 1;
1318 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1319 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1320
1321 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1322 if (ret) {
1323 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1324 arvif->vdev_id, ret);
1325 return ret;
1326 }
1327
1328 return 0;
1329}
1330
Kalle Valo5e3dd152013-06-12 20:52:10 +03001331/**********************/
1332/* Station management */
1333/**********************/
1334
Michal Kazior590922a2014-10-21 10:10:29 +03001335static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1336 struct ieee80211_vif *vif)
1337{
1338 /* Some firmware revisions have unstable STA powersave when listen
1339 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1340 * generate NullFunc frames properly even if buffered frames have been
1341 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1342 * buffered frames. Often pinging the device from AP would simply fail.
1343 *
1344 * As a workaround set it to 1.
1345 */
1346 if (vif->type == NL80211_IFTYPE_STATION)
1347 return 1;
1348
1349 return ar->hw->conf.listen_interval;
1350}
1351
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001353 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001354 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355 struct wmi_peer_assoc_complete_arg *arg)
1356{
Michal Kazior590922a2014-10-21 10:10:29 +03001357 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1358
Michal Kazior548db542013-07-05 16:15:15 +03001359 lockdep_assert_held(&ar->conf_mutex);
1360
Kalle Valob25f32c2014-09-14 12:50:49 +03001361 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362 arg->vdev_id = arvif->vdev_id;
1363 arg->peer_aid = sta->aid;
1364 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001365 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001367 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368}
1369
1370static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001371 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001372 struct wmi_peer_assoc_complete_arg *arg)
1373{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001374 struct ieee80211_bss_conf *info = &vif->bss_conf;
1375 struct cfg80211_bss *bss;
1376 const u8 *rsnie = NULL;
1377 const u8 *wpaie = NULL;
1378
Michal Kazior548db542013-07-05 16:15:15 +03001379 lockdep_assert_held(&ar->conf_mutex);
1380
Kalle Valo5e3dd152013-06-12 20:52:10 +03001381 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1382 info->bssid, NULL, 0, 0, 0);
1383 if (bss) {
1384 const struct cfg80211_bss_ies *ies;
1385
1386 rcu_read_lock();
1387 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1388
1389 ies = rcu_dereference(bss->ies);
1390
1391 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001392 WLAN_OUI_TYPE_MICROSOFT_WPA,
1393 ies->data,
1394 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001395 rcu_read_unlock();
1396 cfg80211_put_bss(ar->hw->wiphy, bss);
1397 }
1398
1399 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1400 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001401 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001402 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1403 }
1404
1405 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001406 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001407 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1408 }
1409}
1410
1411static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1412 struct ieee80211_sta *sta,
1413 struct wmi_peer_assoc_complete_arg *arg)
1414{
1415 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1416 const struct ieee80211_supported_band *sband;
1417 const struct ieee80211_rate *rates;
1418 u32 ratemask;
1419 int i;
1420
Michal Kazior548db542013-07-05 16:15:15 +03001421 lockdep_assert_held(&ar->conf_mutex);
1422
Kalle Valo5e3dd152013-06-12 20:52:10 +03001423 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1424 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1425 rates = sband->bitrates;
1426
1427 rateset->num_rates = 0;
1428
1429 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1430 if (!(ratemask & 1))
1431 continue;
1432
1433 rateset->rates[rateset->num_rates] = rates->hw_value;
1434 rateset->num_rates++;
1435 }
1436}
1437
1438static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1439 struct ieee80211_sta *sta,
1440 struct wmi_peer_assoc_complete_arg *arg)
1441{
1442 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001443 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001444 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001445
Michal Kazior548db542013-07-05 16:15:15 +03001446 lockdep_assert_held(&ar->conf_mutex);
1447
Kalle Valo5e3dd152013-06-12 20:52:10 +03001448 if (!ht_cap->ht_supported)
1449 return;
1450
1451 arg->peer_flags |= WMI_PEER_HT;
1452 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1453 ht_cap->ampdu_factor)) - 1;
1454
1455 arg->peer_mpdu_density =
1456 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1457
1458 arg->peer_ht_caps = ht_cap->cap;
1459 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1460
1461 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1462 arg->peer_flags |= WMI_PEER_LDPC;
1463
1464 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1465 arg->peer_flags |= WMI_PEER_40MHZ;
1466 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1467 }
1468
1469 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1470 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1471
1472 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1473 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1474
1475 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1476 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1477 arg->peer_flags |= WMI_PEER_STBC;
1478 }
1479
1480 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1482 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1483 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1484 arg->peer_rate_caps |= stbc;
1485 arg->peer_flags |= WMI_PEER_STBC;
1486 }
1487
Kalle Valo5e3dd152013-06-12 20:52:10 +03001488 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1489 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1490 else if (ht_cap->mcs.rx_mask[1])
1491 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1492
1493 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1494 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1495 arg->peer_ht_rates.rates[n++] = i;
1496
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001497 /*
1498 * This is a workaround for HT-enabled STAs which break the spec
1499 * and have no HT capabilities RX mask (no HT RX MCS map).
1500 *
1501 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1502 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1503 *
1504 * Firmware asserts if such situation occurs.
1505 */
1506 if (n == 0) {
1507 arg->peer_ht_rates.num_rates = 8;
1508 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1509 arg->peer_ht_rates.rates[i] = i;
1510 } else {
1511 arg->peer_ht_rates.num_rates = n;
1512 arg->peer_num_spatial_streams = sta->rx_nss;
1513 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001514
Michal Kazior7aa7a722014-08-25 12:09:38 +02001515 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001516 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001517 arg->peer_ht_rates.num_rates,
1518 arg->peer_num_spatial_streams);
1519}
1520
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001521static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1522 struct ath10k_vif *arvif,
1523 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001524{
1525 u32 uapsd = 0;
1526 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001527 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528
Michal Kazior548db542013-07-05 16:15:15 +03001529 lockdep_assert_held(&ar->conf_mutex);
1530
Kalle Valo5e3dd152013-06-12 20:52:10 +03001531 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001532 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533 sta->uapsd_queues, sta->max_sp);
1534
Kalle Valo5e3dd152013-06-12 20:52:10 +03001535 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1536 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1537 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1538 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1539 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1540 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1541 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1542 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1543 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1544 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1545 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1546 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1547
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1549 max_sp = sta->max_sp;
1550
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001551 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1552 sta->addr,
1553 WMI_AP_PS_PEER_PARAM_UAPSD,
1554 uapsd);
1555 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001557 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001558 return ret;
1559 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001561 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1562 sta->addr,
1563 WMI_AP_PS_PEER_PARAM_MAX_SP,
1564 max_sp);
1565 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001566 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001567 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001568 return ret;
1569 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001570
1571 /* TODO setup this based on STA listen interval and
1572 beacon interval. Currently we don't know
1573 sta->listen_interval - mac80211 patch required.
1574 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001575 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001576 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1577 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001578 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001579 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001580 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001581 return ret;
1582 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001585 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586}
1587
1588static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1589 struct ieee80211_sta *sta,
1590 struct wmi_peer_assoc_complete_arg *arg)
1591{
1592 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001593 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001594
1595 if (!vht_cap->vht_supported)
1596 return;
1597
1598 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001599
1600 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1601 arg->peer_flags |= WMI_PEER_VHT_2G;
1602
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 arg->peer_vht_caps = vht_cap->cap;
1604
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001605 ampdu_factor = (vht_cap->cap &
1606 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1607 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1608
1609 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1610 * zero in VHT IE. Using it would result in degraded throughput.
1611 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1612 * it if VHT max_mpdu is smaller. */
1613 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1614 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1615 ampdu_factor)) - 1);
1616
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1618 arg->peer_flags |= WMI_PEER_80MHZ;
1619
1620 arg->peer_vht_rates.rx_max_rate =
1621 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1622 arg->peer_vht_rates.rx_mcs_set =
1623 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1624 arg->peer_vht_rates.tx_max_rate =
1625 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1626 arg->peer_vht_rates.tx_mcs_set =
1627 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1628
Michal Kazior7aa7a722014-08-25 12:09:38 +02001629 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001630 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631}
1632
1633static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001634 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 struct wmi_peer_assoc_complete_arg *arg)
1637{
Michal Kazior590922a2014-10-21 10:10:29 +03001638 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1639
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 switch (arvif->vdev_type) {
1641 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001642 if (sta->wme)
1643 arg->peer_flags |= WMI_PEER_QOS;
1644
1645 if (sta->wme && sta->uapsd_queues) {
1646 arg->peer_flags |= WMI_PEER_APSD;
1647 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1648 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001649 break;
1650 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001651 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001652 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001654 case WMI_VDEV_TYPE_IBSS:
1655 if (sta->wme)
1656 arg->peer_flags |= WMI_PEER_QOS;
1657 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658 default:
1659 break;
1660 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001661
1662 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1663 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001664}
1665
Michal Kazior91b12082014-12-12 12:41:35 +01001666static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1667{
1668 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1669 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1670}
1671
Kalle Valo5e3dd152013-06-12 20:52:10 +03001672static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001673 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001674 struct ieee80211_sta *sta,
1675 struct wmi_peer_assoc_complete_arg *arg)
1676{
1677 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1678
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 switch (ar->hw->conf.chandef.chan->band) {
1680 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001681 if (sta->vht_cap.vht_supported) {
1682 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1683 phymode = MODE_11AC_VHT40;
1684 else
1685 phymode = MODE_11AC_VHT20;
1686 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001687 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1688 phymode = MODE_11NG_HT40;
1689 else
1690 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001691 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001692 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001693 } else {
1694 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695 }
1696
1697 break;
1698 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001699 /*
1700 * Check VHT first.
1701 */
1702 if (sta->vht_cap.vht_supported) {
1703 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1704 phymode = MODE_11AC_VHT80;
1705 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1706 phymode = MODE_11AC_VHT40;
1707 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1708 phymode = MODE_11AC_VHT20;
1709 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001710 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1711 phymode = MODE_11NA_HT40;
1712 else
1713 phymode = MODE_11NA_HT20;
1714 } else {
1715 phymode = MODE_11A;
1716 }
1717
1718 break;
1719 default:
1720 break;
1721 }
1722
Michal Kazior7aa7a722014-08-25 12:09:38 +02001723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001724 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001725
Kalle Valo5e3dd152013-06-12 20:52:10 +03001726 arg->peer_phymode = phymode;
1727 WARN_ON(phymode == MODE_UNKNOWN);
1728}
1729
Kalle Valob9ada652013-10-16 15:44:46 +03001730static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001731 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001732 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001733 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001734{
Michal Kazior548db542013-07-05 16:15:15 +03001735 lockdep_assert_held(&ar->conf_mutex);
1736
Kalle Valob9ada652013-10-16 15:44:46 +03001737 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738
Michal Kazior590922a2014-10-21 10:10:29 +03001739 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1740 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001741 ath10k_peer_assoc_h_rates(ar, sta, arg);
1742 ath10k_peer_assoc_h_ht(ar, sta, arg);
1743 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001744 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1745 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746
Kalle Valob9ada652013-10-16 15:44:46 +03001747 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001748}
1749
Michal Kazior90046f52014-02-14 14:45:51 +01001750static const u32 ath10k_smps_map[] = {
1751 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1752 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1753 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1754 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1755};
1756
1757static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1758 const u8 *addr,
1759 const struct ieee80211_sta_ht_cap *ht_cap)
1760{
1761 int smps;
1762
1763 if (!ht_cap->ht_supported)
1764 return 0;
1765
1766 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1767 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1768
1769 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1770 return -EINVAL;
1771
1772 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1773 WMI_PEER_SMPS_STATE,
1774 ath10k_smps_map[smps]);
1775}
1776
Kalle Valo5e3dd152013-06-12 20:52:10 +03001777/* can be called only in mac80211 callbacks due to `key_count` usage */
1778static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1779 struct ieee80211_vif *vif,
1780 struct ieee80211_bss_conf *bss_conf)
1781{
1782 struct ath10k *ar = hw->priv;
1783 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001784 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001785 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786 struct ieee80211_sta *ap_sta;
1787 int ret;
1788
Michal Kazior548db542013-07-05 16:15:15 +03001789 lockdep_assert_held(&ar->conf_mutex);
1790
Michal Kazior077efc82014-10-21 10:10:29 +03001791 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1792 arvif->vdev_id, arvif->bssid, arvif->aid);
1793
Kalle Valo5e3dd152013-06-12 20:52:10 +03001794 rcu_read_lock();
1795
1796 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1797 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001798 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001799 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800 rcu_read_unlock();
1801 return;
1802 }
1803
Michal Kazior90046f52014-02-14 14:45:51 +01001804 /* ap_sta must be accessed only within rcu section which must be left
1805 * before calling ath10k_setup_peer_smps() which might sleep. */
1806 ht_cap = ap_sta->ht_cap;
1807
Michal Kazior590922a2014-10-21 10:10:29 +03001808 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001809 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001810 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001811 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001812 rcu_read_unlock();
1813 return;
1814 }
1815
1816 rcu_read_unlock();
1817
Kalle Valob9ada652013-10-16 15:44:46 +03001818 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1819 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001821 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001822 return;
1823 }
1824
Michal Kazior90046f52014-02-14 14:45:51 +01001825 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1826 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001827 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001828 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001829 return;
1830 }
1831
Michal Kazior7aa7a722014-08-25 12:09:38 +02001832 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001833 "mac vdev %d up (associated) bssid %pM aid %d\n",
1834 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1835
Michal Kazior077efc82014-10-21 10:10:29 +03001836 WARN_ON(arvif->is_up);
1837
Michal Kaziorc930f742014-01-23 11:38:25 +01001838 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001839 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001840
1841 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001843 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001844 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001845 return;
1846 }
1847
1848 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001849}
1850
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1852 struct ieee80211_vif *vif)
1853{
1854 struct ath10k *ar = hw->priv;
1855 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1856 int ret;
1857
Michal Kazior548db542013-07-05 16:15:15 +03001858 lockdep_assert_held(&ar->conf_mutex);
1859
Michal Kazior077efc82014-10-21 10:10:29 +03001860 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1861 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001862
Kalle Valo5e3dd152013-06-12 20:52:10 +03001863 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001864 if (ret)
1865 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1866 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001867
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001868 arvif->def_wep_key_idx = -1;
1869
Michal Kaziorc930f742014-01-23 11:38:25 +01001870 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001871}
1872
Michal Kazior590922a2014-10-21 10:10:29 +03001873static int ath10k_station_assoc(struct ath10k *ar,
1874 struct ieee80211_vif *vif,
1875 struct ieee80211_sta *sta,
1876 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001877{
Michal Kazior590922a2014-10-21 10:10:29 +03001878 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001879 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001880 int ret = 0;
1881
Michal Kazior548db542013-07-05 16:15:15 +03001882 lockdep_assert_held(&ar->conf_mutex);
1883
Michal Kazior590922a2014-10-21 10:10:29 +03001884 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001886 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001887 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001888 return ret;
1889 }
1890
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001891 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001892 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1893 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001894 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001895 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001896 return ret;
1897 }
1898
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001899 /* Re-assoc is run only to update supported rates for given station. It
1900 * doesn't make much sense to reconfigure the peer completely.
1901 */
1902 if (!reassoc) {
1903 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1904 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001905 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001906 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001907 arvif->vdev_id, ret);
1908 return ret;
1909 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001910
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001911 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1912 if (ret) {
1913 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1914 sta->addr, arvif->vdev_id, ret);
1915 return ret;
1916 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001917
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001918 if (!sta->wme) {
1919 arvif->num_legacy_stations++;
1920 ret = ath10k_recalc_rtscts_prot(arvif);
1921 if (ret) {
1922 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1923 arvif->vdev_id, ret);
1924 return ret;
1925 }
1926 }
1927
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02001928 /* Plumb cached keys only for static WEP */
1929 if (arvif->def_wep_key_idx != -1) {
1930 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1931 if (ret) {
1932 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1933 arvif->vdev_id, ret);
1934 return ret;
1935 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001936 }
1937 }
1938
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 return ret;
1940}
1941
Michal Kazior590922a2014-10-21 10:10:29 +03001942static int ath10k_station_disassoc(struct ath10k *ar,
1943 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 struct ieee80211_sta *sta)
1945{
Michal Kazior590922a2014-10-21 10:10:29 +03001946 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001947 int ret = 0;
1948
1949 lockdep_assert_held(&ar->conf_mutex);
1950
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001951 if (!sta->wme) {
1952 arvif->num_legacy_stations--;
1953 ret = ath10k_recalc_rtscts_prot(arvif);
1954 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001955 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001956 arvif->vdev_id, ret);
1957 return ret;
1958 }
1959 }
1960
Kalle Valo5e3dd152013-06-12 20:52:10 +03001961 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1962 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001963 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001964 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 return ret;
1966 }
1967
1968 return ret;
1969}
1970
1971/**************/
1972/* Regulatory */
1973/**************/
1974
1975static int ath10k_update_channel_list(struct ath10k *ar)
1976{
1977 struct ieee80211_hw *hw = ar->hw;
1978 struct ieee80211_supported_band **bands;
1979 enum ieee80211_band band;
1980 struct ieee80211_channel *channel;
1981 struct wmi_scan_chan_list_arg arg = {0};
1982 struct wmi_channel_arg *ch;
1983 bool passive;
1984 int len;
1985 int ret;
1986 int i;
1987
Michal Kazior548db542013-07-05 16:15:15 +03001988 lockdep_assert_held(&ar->conf_mutex);
1989
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 bands = hw->wiphy->bands;
1991 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1992 if (!bands[band])
1993 continue;
1994
1995 for (i = 0; i < bands[band]->n_channels; i++) {
1996 if (bands[band]->channels[i].flags &
1997 IEEE80211_CHAN_DISABLED)
1998 continue;
1999
2000 arg.n_channels++;
2001 }
2002 }
2003
2004 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2005 arg.channels = kzalloc(len, GFP_KERNEL);
2006 if (!arg.channels)
2007 return -ENOMEM;
2008
2009 ch = arg.channels;
2010 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2011 if (!bands[band])
2012 continue;
2013
2014 for (i = 0; i < bands[band]->n_channels; i++) {
2015 channel = &bands[band]->channels[i];
2016
2017 if (channel->flags & IEEE80211_CHAN_DISABLED)
2018 continue;
2019
2020 ch->allow_ht = true;
2021
2022 /* FIXME: when should we really allow VHT? */
2023 ch->allow_vht = true;
2024
2025 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002026 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027
2028 ch->ht40plus =
2029 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2030
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002031 ch->chan_radar =
2032 !!(channel->flags & IEEE80211_CHAN_RADAR);
2033
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002034 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002035 ch->passive = passive;
2036
2037 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002038 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002039 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002040 ch->max_power = channel->max_power * 2;
2041 ch->max_reg_power = channel->max_reg_power * 2;
2042 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 ch->reg_class_id = 0; /* FIXME */
2044
2045 /* FIXME: why use only legacy modes, why not any
2046 * HT/VHT modes? Would that even make any
2047 * difference? */
2048 if (channel->band == IEEE80211_BAND_2GHZ)
2049 ch->mode = MODE_11G;
2050 else
2051 ch->mode = MODE_11A;
2052
2053 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2054 continue;
2055
Michal Kazior7aa7a722014-08-25 12:09:38 +02002056 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002057 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2058 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002059 ch->freq, ch->max_power, ch->max_reg_power,
2060 ch->max_antenna_gain, ch->mode);
2061
2062 ch++;
2063 }
2064 }
2065
2066 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2067 kfree(arg.channels);
2068
2069 return ret;
2070}
2071
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002072static enum wmi_dfs_region
2073ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2074{
2075 switch (dfs_region) {
2076 case NL80211_DFS_UNSET:
2077 return WMI_UNINIT_DFS_DOMAIN;
2078 case NL80211_DFS_FCC:
2079 return WMI_FCC_DFS_DOMAIN;
2080 case NL80211_DFS_ETSI:
2081 return WMI_ETSI_DFS_DOMAIN;
2082 case NL80211_DFS_JP:
2083 return WMI_MKK4_DFS_DOMAIN;
2084 }
2085 return WMI_UNINIT_DFS_DOMAIN;
2086}
2087
Michal Kaziorf7843d72013-07-16 09:38:52 +02002088static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002092 enum wmi_dfs_region wmi_dfs_reg;
2093 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094
Michal Kaziorf7843d72013-07-16 09:38:52 +02002095 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096
2097 ret = ath10k_update_channel_list(ar);
2098 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002099 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002100
2101 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002102
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002103 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2104 nl_dfs_reg = ar->dfs_detector->region;
2105 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2106 } else {
2107 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2108 }
2109
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 /* Target allows setting up per-band regdomain but ath_common provides
2111 * a combined one only */
2112 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002113 regpair->reg_domain,
2114 regpair->reg_domain, /* 2ghz */
2115 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002117 regpair->reg_5ghz_ctl,
2118 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002120 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002121}
Michal Kazior548db542013-07-05 16:15:15 +03002122
Michal Kaziorf7843d72013-07-16 09:38:52 +02002123static void ath10k_reg_notifier(struct wiphy *wiphy,
2124 struct regulatory_request *request)
2125{
2126 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2127 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002128 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002129
2130 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2131
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002132 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002133 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002134 request->dfs_region);
2135 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2136 request->dfs_region);
2137 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002138 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002139 request->dfs_region);
2140 }
2141
Michal Kaziorf7843d72013-07-16 09:38:52 +02002142 mutex_lock(&ar->conf_mutex);
2143 if (ar->state == ATH10K_STATE_ON)
2144 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002145 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146}
2147
2148/***************/
2149/* TX handlers */
2150/***************/
2151
Michal Kazior42c3aa62013-10-02 11:03:38 +02002152static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2153{
2154 if (ieee80211_is_mgmt(hdr->frame_control))
2155 return HTT_DATA_TX_EXT_TID_MGMT;
2156
2157 if (!ieee80211_is_data_qos(hdr->frame_control))
2158 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2159
2160 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2161 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2162
2163 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2164}
2165
Michal Kazior2b37c292014-09-02 11:00:22 +03002166static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002167{
Michal Kazior2b37c292014-09-02 11:00:22 +03002168 if (vif)
2169 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002170
Michal Kazior1bbc0972014-04-08 09:45:47 +03002171 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002172 return ar->monitor_vdev_id;
2173
Michal Kazior7aa7a722014-08-25 12:09:38 +02002174 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002175 return 0;
2176}
2177
Michal Kazior4b604552014-07-21 21:03:09 +03002178/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2179 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180 */
Michal Kazior4b604552014-07-21 21:03:09 +03002181static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182{
2183 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002184 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 u8 *qos_ctl;
2186
2187 if (!ieee80211_is_data_qos(hdr->frame_control))
2188 return;
2189
2190 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002191 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2192 skb->data, (void *)qos_ctl - (void *)skb->data);
2193 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002194
2195 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2196 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2197 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2198 * it is safe to downgrade to NullFunc.
2199 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002200 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002201 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2202 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2203 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2204 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205}
2206
Michal Kazior4b604552014-07-21 21:03:09 +03002207static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2208 struct ieee80211_vif *vif,
2209 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210{
2211 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002212 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2213
2214 /* This is case only for P2P_GO */
2215 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2216 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2217 return;
2218
2219 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2220 spin_lock_bh(&ar->data_lock);
2221 if (arvif->u.ap.noa_data)
2222 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2223 GFP_ATOMIC))
2224 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2225 arvif->u.ap.noa_data,
2226 arvif->u.ap.noa_len);
2227 spin_unlock_bh(&ar->data_lock);
2228 }
2229}
2230
Michal Kazior8d6d3622014-11-24 14:58:31 +01002231static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2232{
2233 /* FIXME: Not really sure since when the behaviour changed. At some
2234 * point new firmware stopped requiring creation of peer entries for
2235 * offchannel tx (and actually creating them causes issues with wmi-htc
2236 * tx credit replenishment and reliability). Assuming it's at least 3.4
2237 * because that's when the `freq` was introduced to TX_FRM HTT command.
2238 */
2239 return !(ar->htt.target_version_major >= 3 &&
2240 ar->htt.target_version_minor >= 4);
2241}
2242
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2244{
2245 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002246 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247
Michal Kazior961d4c32013-08-09 10:13:34 +02002248 if (ar->htt.target_version_major >= 3) {
2249 /* Since HTT 3.0 there is no separate mgmt tx command */
2250 ret = ath10k_htt_tx(&ar->htt, skb);
2251 goto exit;
2252 }
2253
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002254 if (ieee80211_is_mgmt(hdr->frame_control)) {
2255 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2256 ar->fw_features)) {
2257 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2258 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002259 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002260 ret = -EBUSY;
2261 goto exit;
2262 }
2263
2264 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2265 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2266 } else {
2267 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2268 }
2269 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2270 ar->fw_features) &&
2271 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002272 /* FW does not report tx status properly for NullFunc frames
2273 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002274 * those frames when it detects link/beacon loss and depends
2275 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002276 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002277 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002278 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002279 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280
Michal Kazior961d4c32013-08-09 10:13:34 +02002281exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002282 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002283 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2284 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285 ieee80211_free_txskb(ar->hw, skb);
2286 }
2287}
2288
2289void ath10k_offchan_tx_purge(struct ath10k *ar)
2290{
2291 struct sk_buff *skb;
2292
2293 for (;;) {
2294 skb = skb_dequeue(&ar->offchan_tx_queue);
2295 if (!skb)
2296 break;
2297
2298 ieee80211_free_txskb(ar->hw, skb);
2299 }
2300}
2301
2302void ath10k_offchan_tx_work(struct work_struct *work)
2303{
2304 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2305 struct ath10k_peer *peer;
2306 struct ieee80211_hdr *hdr;
2307 struct sk_buff *skb;
2308 const u8 *peer_addr;
2309 int vdev_id;
2310 int ret;
2311
2312 /* FW requirement: We must create a peer before FW will send out
2313 * an offchannel frame. Otherwise the frame will be stuck and
2314 * never transmitted. We delete the peer upon tx completion.
2315 * It is unlikely that a peer for offchannel tx will already be
2316 * present. However it may be in some rare cases so account for that.
2317 * Otherwise we might remove a legitimate peer and break stuff. */
2318
2319 for (;;) {
2320 skb = skb_dequeue(&ar->offchan_tx_queue);
2321 if (!skb)
2322 break;
2323
2324 mutex_lock(&ar->conf_mutex);
2325
Michal Kazior7aa7a722014-08-25 12:09:38 +02002326 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327 skb);
2328
2329 hdr = (struct ieee80211_hdr *)skb->data;
2330 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002331 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332
2333 spin_lock_bh(&ar->data_lock);
2334 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2335 spin_unlock_bh(&ar->data_lock);
2336
2337 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002338 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002339 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002340 peer_addr, vdev_id);
2341
2342 if (!peer) {
2343 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2344 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002345 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 peer_addr, vdev_id, ret);
2347 }
2348
2349 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002350 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002351 ar->offchan_tx_skb = skb;
2352 spin_unlock_bh(&ar->data_lock);
2353
2354 ath10k_tx_htt(ar, skb);
2355
2356 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2357 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002358 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002359 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360 skb);
2361
2362 if (!peer) {
2363 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2364 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002365 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366 peer_addr, vdev_id, ret);
2367 }
2368
2369 mutex_unlock(&ar->conf_mutex);
2370 }
2371}
2372
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002373void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2374{
2375 struct sk_buff *skb;
2376
2377 for (;;) {
2378 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2379 if (!skb)
2380 break;
2381
2382 ieee80211_free_txskb(ar->hw, skb);
2383 }
2384}
2385
2386void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2387{
2388 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2389 struct sk_buff *skb;
2390 int ret;
2391
2392 for (;;) {
2393 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2394 if (!skb)
2395 break;
2396
2397 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002398 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002399 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002400 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002401 ieee80211_free_txskb(ar->hw, skb);
2402 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002403 }
2404}
2405
Kalle Valo5e3dd152013-06-12 20:52:10 +03002406/************/
2407/* Scanning */
2408/************/
2409
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002410void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002411{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002412 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002413
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002414 switch (ar->scan.state) {
2415 case ATH10K_SCAN_IDLE:
2416 break;
2417 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002418 if (ar->scan.is_roc)
2419 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002420 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002421 case ATH10K_SCAN_ABORTING:
2422 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002423 ieee80211_scan_completed(ar->hw,
2424 (ar->scan.state ==
2425 ATH10K_SCAN_ABORTING));
2426 /* fall through */
2427 case ATH10K_SCAN_STARTING:
2428 ar->scan.state = ATH10K_SCAN_IDLE;
2429 ar->scan_channel = NULL;
2430 ath10k_offchan_tx_purge(ar);
2431 cancel_delayed_work(&ar->scan.timeout);
2432 complete_all(&ar->scan.completed);
2433 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002434 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002435}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002436
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002437void ath10k_scan_finish(struct ath10k *ar)
2438{
2439 spin_lock_bh(&ar->data_lock);
2440 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002441 spin_unlock_bh(&ar->data_lock);
2442}
2443
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002444static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445{
2446 struct wmi_stop_scan_arg arg = {
2447 .req_id = 1, /* FIXME */
2448 .req_type = WMI_SCAN_STOP_ONE,
2449 .u.scan_id = ATH10K_SCAN_ID,
2450 };
2451 int ret;
2452
2453 lockdep_assert_held(&ar->conf_mutex);
2454
Kalle Valo5e3dd152013-06-12 20:52:10 +03002455 ret = ath10k_wmi_stop_scan(ar, &arg);
2456 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002457 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002458 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002459 }
2460
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002462 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002463 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002465 } else if (ret > 0) {
2466 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002467 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002468
2469out:
2470 /* Scan state should be updated upon scan completion but in case
2471 * firmware fails to deliver the event (for whatever reason) it is
2472 * desired to clean up scan state anyway. Firmware may have just
2473 * dropped the scan completion event delivery due to transport pipe
2474 * being overflown with data and/or it can recover on its own before
2475 * next scan request is submitted.
2476 */
2477 spin_lock_bh(&ar->data_lock);
2478 if (ar->scan.state != ATH10K_SCAN_IDLE)
2479 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002480 spin_unlock_bh(&ar->data_lock);
2481
2482 return ret;
2483}
2484
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002485static void ath10k_scan_abort(struct ath10k *ar)
2486{
2487 int ret;
2488
2489 lockdep_assert_held(&ar->conf_mutex);
2490
2491 spin_lock_bh(&ar->data_lock);
2492
2493 switch (ar->scan.state) {
2494 case ATH10K_SCAN_IDLE:
2495 /* This can happen if timeout worker kicked in and called
2496 * abortion while scan completion was being processed.
2497 */
2498 break;
2499 case ATH10K_SCAN_STARTING:
2500 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002501 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002502 ath10k_scan_state_str(ar->scan.state),
2503 ar->scan.state);
2504 break;
2505 case ATH10K_SCAN_RUNNING:
2506 ar->scan.state = ATH10K_SCAN_ABORTING;
2507 spin_unlock_bh(&ar->data_lock);
2508
2509 ret = ath10k_scan_stop(ar);
2510 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002511 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002512
2513 spin_lock_bh(&ar->data_lock);
2514 break;
2515 }
2516
2517 spin_unlock_bh(&ar->data_lock);
2518}
2519
2520void ath10k_scan_timeout_work(struct work_struct *work)
2521{
2522 struct ath10k *ar = container_of(work, struct ath10k,
2523 scan.timeout.work);
2524
2525 mutex_lock(&ar->conf_mutex);
2526 ath10k_scan_abort(ar);
2527 mutex_unlock(&ar->conf_mutex);
2528}
2529
Kalle Valo5e3dd152013-06-12 20:52:10 +03002530static int ath10k_start_scan(struct ath10k *ar,
2531 const struct wmi_start_scan_arg *arg)
2532{
2533 int ret;
2534
2535 lockdep_assert_held(&ar->conf_mutex);
2536
2537 ret = ath10k_wmi_start_scan(ar, arg);
2538 if (ret)
2539 return ret;
2540
Kalle Valo5e3dd152013-06-12 20:52:10 +03002541 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2542 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002543 ret = ath10k_scan_stop(ar);
2544 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002545 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002546
2547 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002548 }
2549
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002550 /* Add a 200ms margin to account for event/command processing */
2551 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2552 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002553 return 0;
2554}
2555
2556/**********************/
2557/* mac80211 callbacks */
2558/**********************/
2559
2560static void ath10k_tx(struct ieee80211_hw *hw,
2561 struct ieee80211_tx_control *control,
2562 struct sk_buff *skb)
2563{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002564 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002565 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2566 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002567 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568
2569 /* We should disable CCK RATE due to P2P */
2570 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002571 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572
Michal Kazior4b604552014-07-21 21:03:09 +03002573 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2574 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002575 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002577 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002578 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2579 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002580 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2581 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002582 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2585 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002586 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002587 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 spin_unlock_bh(&ar->data_lock);
2589
Michal Kazior8d6d3622014-11-24 14:58:31 +01002590 if (ath10k_mac_need_offchan_tx_work(ar)) {
2591 ATH10K_SKB_CB(skb)->htt.freq = 0;
2592 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002593
Michal Kazior8d6d3622014-11-24 14:58:31 +01002594 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2595 skb);
2596
2597 skb_queue_tail(&ar->offchan_tx_queue, skb);
2598 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2599 return;
2600 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601 }
2602
2603 ath10k_tx_htt(ar, skb);
2604}
2605
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002606/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002607void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002608{
2609 /* make sure rcu-protected mac80211 tx path itself is drained */
2610 synchronize_net();
2611
2612 ath10k_offchan_tx_purge(ar);
2613 ath10k_mgmt_over_wmi_tx_purge(ar);
2614
2615 cancel_work_sync(&ar->offchan_tx_work);
2616 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2617}
2618
Michal Kazioraffd3212013-07-16 09:54:35 +02002619void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002620{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002621 struct ath10k_vif *arvif;
2622
Michal Kazior818bdd12013-07-16 09:38:57 +02002623 lockdep_assert_held(&ar->conf_mutex);
2624
Michal Kazior19337472014-08-28 12:58:16 +02002625 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2626 ar->filter_flags = 0;
2627 ar->monitor = false;
2628
2629 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002630 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002631
2632 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002633
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002634 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002635 ath10k_peer_cleanup_all(ar);
2636 ath10k_core_stop(ar);
2637 ath10k_hif_power_down(ar);
2638
2639 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002640 list_for_each_entry(arvif, &ar->arvifs, list)
2641 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002642 spin_unlock_bh(&ar->data_lock);
2643}
2644
Ben Greear46acf7b2014-05-16 17:15:38 +03002645static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2646{
2647 struct ath10k *ar = hw->priv;
2648
2649 mutex_lock(&ar->conf_mutex);
2650
2651 if (ar->cfg_tx_chainmask) {
2652 *tx_ant = ar->cfg_tx_chainmask;
2653 *rx_ant = ar->cfg_rx_chainmask;
2654 } else {
2655 *tx_ant = ar->supp_tx_chainmask;
2656 *rx_ant = ar->supp_rx_chainmask;
2657 }
2658
2659 mutex_unlock(&ar->conf_mutex);
2660
2661 return 0;
2662}
2663
Ben Greear5572a952014-11-24 16:22:10 +02002664static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2665{
2666 /* It is not clear that allowing gaps in chainmask
2667 * is helpful. Probably it will not do what user
2668 * is hoping for, so warn in that case.
2669 */
2670 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2671 return;
2672
2673 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2674 dbg, cm);
2675}
2676
Ben Greear46acf7b2014-05-16 17:15:38 +03002677static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2678{
2679 int ret;
2680
2681 lockdep_assert_held(&ar->conf_mutex);
2682
Ben Greear5572a952014-11-24 16:22:10 +02002683 ath10k_check_chain_mask(ar, tx_ant, "tx");
2684 ath10k_check_chain_mask(ar, rx_ant, "rx");
2685
Ben Greear46acf7b2014-05-16 17:15:38 +03002686 ar->cfg_tx_chainmask = tx_ant;
2687 ar->cfg_rx_chainmask = rx_ant;
2688
2689 if ((ar->state != ATH10K_STATE_ON) &&
2690 (ar->state != ATH10K_STATE_RESTARTED))
2691 return 0;
2692
2693 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2694 tx_ant);
2695 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002696 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002697 ret, tx_ant);
2698 return ret;
2699 }
2700
2701 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2702 rx_ant);
2703 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002704 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002705 ret, rx_ant);
2706 return ret;
2707 }
2708
2709 return 0;
2710}
2711
2712static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2713{
2714 struct ath10k *ar = hw->priv;
2715 int ret;
2716
2717 mutex_lock(&ar->conf_mutex);
2718 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2719 mutex_unlock(&ar->conf_mutex);
2720 return ret;
2721}
2722
Kalle Valo5e3dd152013-06-12 20:52:10 +03002723static int ath10k_start(struct ieee80211_hw *hw)
2724{
2725 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002726 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002727
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002728 /*
2729 * This makes sense only when restarting hw. It is harmless to call
2730 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2731 * commands will be submitted while restarting.
2732 */
2733 ath10k_drain_tx(ar);
2734
Michal Kazior548db542013-07-05 16:15:15 +03002735 mutex_lock(&ar->conf_mutex);
2736
Michal Kaziorc5058f52014-05-26 12:46:03 +03002737 switch (ar->state) {
2738 case ATH10K_STATE_OFF:
2739 ar->state = ATH10K_STATE_ON;
2740 break;
2741 case ATH10K_STATE_RESTARTING:
2742 ath10k_halt(ar);
2743 ar->state = ATH10K_STATE_RESTARTED;
2744 break;
2745 case ATH10K_STATE_ON:
2746 case ATH10K_STATE_RESTARTED:
2747 case ATH10K_STATE_WEDGED:
2748 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002749 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002750 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002751 case ATH10K_STATE_UTF:
2752 ret = -EBUSY;
2753 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002754 }
2755
2756 ret = ath10k_hif_power_up(ar);
2757 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002758 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002759 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002760 }
2761
Kalle Valo43d2a302014-09-10 18:23:30 +03002762 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002763 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002764 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002765 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002766 }
2767
Bartosz Markowski226a3392013-09-26 17:47:16 +02002768 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002771 goto err_core_stop;
2772 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002774 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002775 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002776 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002777 goto err_core_stop;
2778 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779
Ben Greear46acf7b2014-05-16 17:15:38 +03002780 if (ar->cfg_tx_chainmask)
2781 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2782 ar->cfg_rx_chainmask);
2783
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002784 /*
2785 * By default FW set ARP frames ac to voice (6). In that case ARP
2786 * exchange is not working properly for UAPSD enabled AP. ARP requests
2787 * which arrives with access category 0 are processed by network stack
2788 * and send back with access category 0, but FW changes access category
2789 * to 6. Set ARP frames access category to best effort (0) solves
2790 * this problem.
2791 */
2792
2793 ret = ath10k_wmi_pdev_set_param(ar,
2794 ar->wmi.pdev_param->arp_ac_override, 0);
2795 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002796 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002797 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002798 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002799 }
2800
Michal Kaziord6500972014-04-08 09:56:09 +03002801 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002802 ath10k_regd_update(ar);
2803
Simon Wunderlich855aed12014-08-02 09:12:54 +03002804 ath10k_spectral_start(ar);
2805
Michal Kaziorae254432014-05-26 12:46:02 +03002806 mutex_unlock(&ar->conf_mutex);
2807 return 0;
2808
2809err_core_stop:
2810 ath10k_core_stop(ar);
2811
2812err_power_down:
2813 ath10k_hif_power_down(ar);
2814
2815err_off:
2816 ar->state = ATH10K_STATE_OFF;
2817
2818err:
Michal Kazior548db542013-07-05 16:15:15 +03002819 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002820 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002821}
2822
2823static void ath10k_stop(struct ieee80211_hw *hw)
2824{
2825 struct ath10k *ar = hw->priv;
2826
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002827 ath10k_drain_tx(ar);
2828
Michal Kazior548db542013-07-05 16:15:15 +03002829 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002830 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002831 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002832 ar->state = ATH10K_STATE_OFF;
2833 }
Michal Kazior548db542013-07-05 16:15:15 +03002834 mutex_unlock(&ar->conf_mutex);
2835
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002836 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002837 cancel_work_sync(&ar->restart_work);
2838}
2839
Michal Kaziorad088bf2013-10-16 15:44:46 +03002840static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002841{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002842 struct ath10k_vif *arvif;
2843 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002844
2845 lockdep_assert_held(&ar->conf_mutex);
2846
Michal Kaziorad088bf2013-10-16 15:44:46 +03002847 list_for_each_entry(arvif, &ar->arvifs, list) {
2848 ret = ath10k_mac_vif_setup_ps(arvif);
2849 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002850 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002851 break;
2852 }
2853 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002854
Michal Kaziorad088bf2013-10-16 15:44:46 +03002855 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002856}
2857
Michal Kaziorc930f742014-01-23 11:38:25 +01002858static const char *chandef_get_width(enum nl80211_chan_width width)
2859{
2860 switch (width) {
2861 case NL80211_CHAN_WIDTH_20_NOHT:
2862 return "20 (noht)";
2863 case NL80211_CHAN_WIDTH_20:
2864 return "20";
2865 case NL80211_CHAN_WIDTH_40:
2866 return "40";
2867 case NL80211_CHAN_WIDTH_80:
2868 return "80";
2869 case NL80211_CHAN_WIDTH_80P80:
2870 return "80+80";
2871 case NL80211_CHAN_WIDTH_160:
2872 return "160";
2873 case NL80211_CHAN_WIDTH_5:
2874 return "5";
2875 case NL80211_CHAN_WIDTH_10:
2876 return "10";
2877 }
2878 return "?";
2879}
2880
2881static void ath10k_config_chan(struct ath10k *ar)
2882{
2883 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002884 int ret;
2885
2886 lockdep_assert_held(&ar->conf_mutex);
2887
Michal Kazior7aa7a722014-08-25 12:09:38 +02002888 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002889 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2890 ar->chandef.chan->center_freq,
2891 ar->chandef.center_freq1,
2892 ar->chandef.center_freq2,
2893 chandef_get_width(ar->chandef.width));
2894
2895 /* First stop monitor interface. Some FW versions crash if there's a
2896 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002897 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002898 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002899
2900 list_for_each_entry(arvif, &ar->arvifs, list) {
2901 if (!arvif->is_started)
2902 continue;
2903
Michal Kaziordc55e302014-07-29 12:53:36 +03002904 if (!arvif->is_up)
2905 continue;
2906
Michal Kaziorc930f742014-01-23 11:38:25 +01002907 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2908 continue;
2909
Michal Kaziordc55e302014-07-29 12:53:36 +03002910 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002911 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002912 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002913 arvif->vdev_id, ret);
2914 continue;
2915 }
2916 }
2917
Michal Kaziordc55e302014-07-29 12:53:36 +03002918 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002919
2920 list_for_each_entry(arvif, &ar->arvifs, list) {
2921 if (!arvif->is_started)
2922 continue;
2923
2924 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2925 continue;
2926
Michal Kaziordc55e302014-07-29 12:53:36 +03002927 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002928 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002929 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002930 arvif->vdev_id, ret);
2931 continue;
2932 }
2933
2934 if (!arvif->is_up)
2935 continue;
2936
2937 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2938 arvif->bssid);
2939 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002940 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002941 arvif->vdev_id, ret);
2942 continue;
2943 }
2944 }
2945
Michal Kazior19337472014-08-28 12:58:16 +02002946 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002947}
2948
Michal Kazior7d9d5582014-10-21 10:40:15 +03002949static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2950{
2951 int ret;
2952 u32 param;
2953
2954 lockdep_assert_held(&ar->conf_mutex);
2955
2956 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2957
2958 param = ar->wmi.pdev_param->txpower_limit2g;
2959 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2960 if (ret) {
2961 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2962 txpower, ret);
2963 return ret;
2964 }
2965
2966 param = ar->wmi.pdev_param->txpower_limit5g;
2967 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2968 if (ret) {
2969 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2970 txpower, ret);
2971 return ret;
2972 }
2973
2974 return 0;
2975}
2976
2977static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2978{
2979 struct ath10k_vif *arvif;
2980 int ret, txpower = -1;
2981
2982 lockdep_assert_held(&ar->conf_mutex);
2983
2984 list_for_each_entry(arvif, &ar->arvifs, list) {
2985 WARN_ON(arvif->txpower < 0);
2986
2987 if (txpower == -1)
2988 txpower = arvif->txpower;
2989 else
2990 txpower = min(txpower, arvif->txpower);
2991 }
2992
2993 if (WARN_ON(txpower == -1))
2994 return -EINVAL;
2995
2996 ret = ath10k_mac_txpower_setup(ar, txpower);
2997 if (ret) {
2998 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2999 txpower, ret);
3000 return ret;
3001 }
3002
3003 return 0;
3004}
3005
Kalle Valo5e3dd152013-06-12 20:52:10 +03003006static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3007{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003008 struct ath10k *ar = hw->priv;
3009 struct ieee80211_conf *conf = &hw->conf;
3010 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003011
3012 mutex_lock(&ar->conf_mutex);
3013
3014 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003015 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003016 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003017 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003018 conf->chandef.chan->flags,
3019 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003020
Kalle Valo5e3dd152013-06-12 20:52:10 +03003021 spin_lock_bh(&ar->data_lock);
3022 ar->rx_channel = conf->chandef.chan;
3023 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003024
Michal Kaziord6500972014-04-08 09:56:09 +03003025 ar->radar_enabled = conf->radar_enabled;
3026 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003027
3028 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3029 ar->chandef = conf->chandef;
3030 ath10k_config_chan(ar);
3031 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003032 }
3033
Michal Kazioraffd3212013-07-16 09:54:35 +02003034 if (changed & IEEE80211_CONF_CHANGE_PS)
3035 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036
3037 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003038 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3039 ret = ath10k_monitor_recalc(ar);
3040 if (ret)
3041 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003042 }
3043
3044 mutex_unlock(&ar->conf_mutex);
3045 return ret;
3046}
3047
Ben Greear5572a952014-11-24 16:22:10 +02003048static u32 get_nss_from_chainmask(u16 chain_mask)
3049{
3050 if ((chain_mask & 0x15) == 0x15)
3051 return 4;
3052 else if ((chain_mask & 0x7) == 0x7)
3053 return 3;
3054 else if ((chain_mask & 0x3) == 0x3)
3055 return 2;
3056 return 1;
3057}
3058
Kalle Valo5e3dd152013-06-12 20:52:10 +03003059/*
3060 * TODO:
3061 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3062 * because we will send mgmt frames without CCK. This requirement
3063 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3064 * in the TX packet.
3065 */
3066static int ath10k_add_interface(struct ieee80211_hw *hw,
3067 struct ieee80211_vif *vif)
3068{
3069 struct ath10k *ar = hw->priv;
3070 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3071 enum wmi_sta_powersave_param param;
3072 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003073 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003074 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003075 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076
3077 mutex_lock(&ar->conf_mutex);
3078
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003079 memset(arvif, 0, sizeof(*arvif));
3080
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081 arvif->ar = ar;
3082 arvif->vif = vif;
3083
Ben Greeare63b33f2013-10-22 14:54:14 -07003084 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003085
Ben Greeara9aefb32014-08-12 11:02:19 +03003086 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003087 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003088 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003089 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003090 }
Ben Greear16c11172014-09-23 14:17:16 -07003091 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003092
Ben Greear16c11172014-09-23 14:17:16 -07003093 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3094 bit, ar->free_vdev_map);
3095
3096 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003097 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003100 case NL80211_IFTYPE_P2P_DEVICE:
3101 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3102 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3103 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003104 case NL80211_IFTYPE_UNSPECIFIED:
3105 case NL80211_IFTYPE_STATION:
3106 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3107 if (vif->p2p)
3108 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3109 break;
3110 case NL80211_IFTYPE_ADHOC:
3111 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3112 break;
3113 case NL80211_IFTYPE_AP:
3114 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3115
3116 if (vif->p2p)
3117 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3118 break;
3119 case NL80211_IFTYPE_MONITOR:
3120 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3121 break;
3122 default:
3123 WARN_ON(1);
3124 break;
3125 }
3126
Michal Kazior64badcb2014-09-18 11:18:02 +03003127 /* Some firmware revisions don't wait for beacon tx completion before
3128 * sending another SWBA event. This could lead to hardware using old
3129 * (freed) beacon data in some cases, e.g. tx credit starvation
3130 * combined with missed TBTT. This is very very rare.
3131 *
3132 * On non-IOMMU-enabled hosts this could be a possible security issue
3133 * because hw could beacon some random data on the air. On
3134 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3135 * device would crash.
3136 *
3137 * Since there are no beacon tx completions (implicit nor explicit)
3138 * propagated to host the only workaround for this is to allocate a
3139 * DMA-coherent buffer for a lifetime of a vif and use it for all
3140 * beacon tx commands. Worst case for this approach is some beacons may
3141 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3142 */
3143 if (vif->type == NL80211_IFTYPE_ADHOC ||
3144 vif->type == NL80211_IFTYPE_AP) {
3145 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3146 IEEE80211_MAX_FRAME_LEN,
3147 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303148 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003149 if (!arvif->beacon_buf) {
3150 ret = -ENOMEM;
3151 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3152 ret);
3153 goto err;
3154 }
3155 }
3156
3157 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3158 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3159 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003160
3161 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3162 arvif->vdev_subtype, vif->addr);
3163 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003164 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003165 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003166 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003167 }
3168
Ben Greear16c11172014-09-23 14:17:16 -07003169 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003170 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003171
Michal Kazior46725b12015-01-28 09:57:49 +02003172 /* It makes no sense to have firmware do keepalives. mac80211 already
3173 * takes care of this with idle connection polling.
3174 */
3175 ret = ath10k_mac_vif_disable_keepalive(arvif);
3176 if (ret) {
3177 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
3178 arvif->vdev_id, ret);
3179 goto err_vdev_delete;
3180 }
3181
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003182 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003183
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003184 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3185 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003186 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003187 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003188 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003189 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003190 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003191 goto err_vdev_delete;
3192 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003193
Ben Greear5572a952014-11-24 16:22:10 +02003194 if (ar->cfg_tx_chainmask) {
3195 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3196
3197 vdev_param = ar->wmi.vdev_param->nss;
3198 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3199 nss);
3200 if (ret) {
3201 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3202 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3203 ret);
3204 goto err_vdev_delete;
3205 }
3206 }
3207
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3209 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3210 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003211 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003212 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003213 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003214 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003215
Kalle Valo5a13e762014-01-20 11:01:46 +02003216 ret = ath10k_mac_set_kickout(arvif);
3217 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003218 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003219 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003220 goto err_peer_delete;
3221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003222 }
3223
3224 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3225 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3226 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3227 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3228 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003229 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003230 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003231 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003232 goto err_peer_delete;
3233 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003234
Michal Kazior9f9b5742014-12-12 12:41:36 +01003235 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003236 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003237 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003238 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003239 goto err_peer_delete;
3240 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003241
Michal Kazior9f9b5742014-12-12 12:41:36 +01003242 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003243 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003244 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003245 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003246 goto err_peer_delete;
3247 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003248 }
3249
Michal Kazior424121c2013-07-22 14:13:31 +02003250 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003251 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003252 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003253 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003254 goto err_peer_delete;
3255 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003256
Michal Kazior424121c2013-07-22 14:13:31 +02003257 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003258 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003259 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003260 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003261 goto err_peer_delete;
3262 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003263
Michal Kazior7d9d5582014-10-21 10:40:15 +03003264 arvif->txpower = vif->bss_conf.txpower;
3265 ret = ath10k_mac_txpower_recalc(ar);
3266 if (ret) {
3267 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3268 goto err_peer_delete;
3269 }
3270
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003272 return 0;
3273
3274err_peer_delete:
3275 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3276 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3277
3278err_vdev_delete:
3279 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003280 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003281 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003282
3283err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003284 if (arvif->beacon_buf) {
3285 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3286 arvif->beacon_buf, arvif->beacon_paddr);
3287 arvif->beacon_buf = NULL;
3288 }
3289
Michal Kazior9dad14a2013-10-16 15:44:45 +03003290 mutex_unlock(&ar->conf_mutex);
3291
Kalle Valo5e3dd152013-06-12 20:52:10 +03003292 return ret;
3293}
3294
3295static void ath10k_remove_interface(struct ieee80211_hw *hw,
3296 struct ieee80211_vif *vif)
3297{
3298 struct ath10k *ar = hw->priv;
3299 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3300 int ret;
3301
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303302 mutex_lock(&ar->conf_mutex);
3303
Michal Kaziored543882013-09-13 14:16:56 +02003304 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003305 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003306 spin_unlock_bh(&ar->data_lock);
3307
Simon Wunderlich855aed12014-08-02 09:12:54 +03003308 ret = ath10k_spectral_vif_stop(arvif);
3309 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003310 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003311 arvif->vdev_id, ret);
3312
Ben Greear16c11172014-09-23 14:17:16 -07003313 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003314 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315
3316 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3317 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3318 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003319 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003320 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321
3322 kfree(arvif->u.ap.noa_data);
3323 }
3324
Michal Kazior7aa7a722014-08-25 12:09:38 +02003325 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003326 arvif->vdev_id);
3327
Kalle Valo5e3dd152013-06-12 20:52:10 +03003328 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3329 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003330 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003331 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003332
Kalle Valo5e3dd152013-06-12 20:52:10 +03003333 ath10k_peer_cleanup(ar, arvif->vdev_id);
3334
3335 mutex_unlock(&ar->conf_mutex);
3336}
3337
3338/*
3339 * FIXME: Has to be verified.
3340 */
3341#define SUPPORTED_FILTERS \
3342 (FIF_PROMISC_IN_BSS | \
3343 FIF_ALLMULTI | \
3344 FIF_CONTROL | \
3345 FIF_PSPOLL | \
3346 FIF_OTHER_BSS | \
3347 FIF_BCN_PRBRESP_PROMISC | \
3348 FIF_PROBE_REQ | \
3349 FIF_FCSFAIL)
3350
3351static void ath10k_configure_filter(struct ieee80211_hw *hw,
3352 unsigned int changed_flags,
3353 unsigned int *total_flags,
3354 u64 multicast)
3355{
3356 struct ath10k *ar = hw->priv;
3357 int ret;
3358
3359 mutex_lock(&ar->conf_mutex);
3360
3361 changed_flags &= SUPPORTED_FILTERS;
3362 *total_flags &= SUPPORTED_FILTERS;
3363 ar->filter_flags = *total_flags;
3364
Michal Kazior19337472014-08-28 12:58:16 +02003365 ret = ath10k_monitor_recalc(ar);
3366 if (ret)
3367 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003368
3369 mutex_unlock(&ar->conf_mutex);
3370}
3371
3372static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3373 struct ieee80211_vif *vif,
3374 struct ieee80211_bss_conf *info,
3375 u32 changed)
3376{
3377 struct ath10k *ar = hw->priv;
3378 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3379 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003380 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003381
3382 mutex_lock(&ar->conf_mutex);
3383
3384 if (changed & BSS_CHANGED_IBSS)
3385 ath10k_control_ibss(arvif, info, vif->addr);
3386
3387 if (changed & BSS_CHANGED_BEACON_INT) {
3388 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003389 vdev_param = ar->wmi.vdev_param->beacon_interval;
3390 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003392 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003393 "mac vdev %d beacon_interval %d\n",
3394 arvif->vdev_id, arvif->beacon_interval);
3395
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003397 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003398 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003399 }
3400
3401 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003402 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003403 "vdev %d set beacon tx mode to staggered\n",
3404 arvif->vdev_id);
3405
Bartosz Markowski226a3392013-09-26 17:47:16 +02003406 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3407 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 WMI_BEACON_STAGGERED_MODE);
3409 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003410 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003411 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003412
3413 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3414 if (ret)
3415 ath10k_warn(ar, "failed to update beacon template: %d\n",
3416 ret);
3417 }
3418
3419 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3420 ret = ath10k_mac_setup_prb_tmpl(arvif);
3421 if (ret)
3422 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3423 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003424 }
3425
Michal Kaziorba2479f2015-01-24 12:14:51 +02003426 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003427 arvif->dtim_period = info->dtim_period;
3428
Michal Kazior7aa7a722014-08-25 12:09:38 +02003429 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003430 "mac vdev %d dtim_period %d\n",
3431 arvif->vdev_id, arvif->dtim_period);
3432
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003433 vdev_param = ar->wmi.vdev_param->dtim_period;
3434 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003435 arvif->dtim_period);
3436 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003437 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003438 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003439 }
3440
3441 if (changed & BSS_CHANGED_SSID &&
3442 vif->type == NL80211_IFTYPE_AP) {
3443 arvif->u.ap.ssid_len = info->ssid_len;
3444 if (info->ssid_len)
3445 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3446 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3447 }
3448
Michal Kazior077efc82014-10-21 10:10:29 +03003449 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3450 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003451
3452 if (changed & BSS_CHANGED_BEACON_ENABLED)
3453 ath10k_control_beaconing(arvif, info);
3454
3455 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003456 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003457 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003458 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003459
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003460 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003461 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003462 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003463 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003464 }
3465
3466 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467 if (info->use_short_slot)
3468 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3469
3470 else
3471 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3472
Michal Kazior7aa7a722014-08-25 12:09:38 +02003473 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003474 arvif->vdev_id, slottime);
3475
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003476 vdev_param = ar->wmi.vdev_param->slot_time;
3477 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 slottime);
3479 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003480 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003481 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482 }
3483
3484 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003485 if (info->use_short_preamble)
3486 preamble = WMI_VDEV_PREAMBLE_SHORT;
3487 else
3488 preamble = WMI_VDEV_PREAMBLE_LONG;
3489
Michal Kazior7aa7a722014-08-25 12:09:38 +02003490 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003491 "mac vdev %d preamble %dn",
3492 arvif->vdev_id, preamble);
3493
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003494 vdev_param = ar->wmi.vdev_param->preamble;
3495 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003496 preamble);
3497 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003498 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003499 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500 }
3501
3502 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003503 if (info->assoc) {
3504 /* Workaround: Make sure monitor vdev is not running
3505 * when associating to prevent some firmware revisions
3506 * (e.g. 10.1 and 10.2) from crashing.
3507 */
3508 if (ar->monitor_started)
3509 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003511 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003512 } else {
3513 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003514 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003515 }
3516
Michal Kazior7d9d5582014-10-21 10:40:15 +03003517 if (changed & BSS_CHANGED_TXPOWER) {
3518 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3519 arvif->vdev_id, info->txpower);
3520
3521 arvif->txpower = info->txpower;
3522 ret = ath10k_mac_txpower_recalc(ar);
3523 if (ret)
3524 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3525 }
3526
Michal Kaziorbf14e652014-12-12 12:41:38 +01003527 if (changed & BSS_CHANGED_PS) {
3528 ret = ath10k_mac_vif_setup_ps(arvif);
3529 if (ret)
3530 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3531 arvif->vdev_id, ret);
3532 }
3533
Kalle Valo5e3dd152013-06-12 20:52:10 +03003534 mutex_unlock(&ar->conf_mutex);
3535}
3536
3537static int ath10k_hw_scan(struct ieee80211_hw *hw,
3538 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003539 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540{
3541 struct ath10k *ar = hw->priv;
3542 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003543 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544 struct wmi_start_scan_arg arg;
3545 int ret = 0;
3546 int i;
3547
3548 mutex_lock(&ar->conf_mutex);
3549
3550 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003551 switch (ar->scan.state) {
3552 case ATH10K_SCAN_IDLE:
3553 reinit_completion(&ar->scan.started);
3554 reinit_completion(&ar->scan.completed);
3555 ar->scan.state = ATH10K_SCAN_STARTING;
3556 ar->scan.is_roc = false;
3557 ar->scan.vdev_id = arvif->vdev_id;
3558 ret = 0;
3559 break;
3560 case ATH10K_SCAN_STARTING:
3561 case ATH10K_SCAN_RUNNING:
3562 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003563 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003564 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003565 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003566 spin_unlock_bh(&ar->data_lock);
3567
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003568 if (ret)
3569 goto exit;
3570
Kalle Valo5e3dd152013-06-12 20:52:10 +03003571 memset(&arg, 0, sizeof(arg));
3572 ath10k_wmi_start_scan_init(ar, &arg);
3573 arg.vdev_id = arvif->vdev_id;
3574 arg.scan_id = ATH10K_SCAN_ID;
3575
3576 if (!req->no_cck)
3577 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3578
3579 if (req->ie_len) {
3580 arg.ie_len = req->ie_len;
3581 memcpy(arg.ie, req->ie, arg.ie_len);
3582 }
3583
3584 if (req->n_ssids) {
3585 arg.n_ssids = req->n_ssids;
3586 for (i = 0; i < arg.n_ssids; i++) {
3587 arg.ssids[i].len = req->ssids[i].ssid_len;
3588 arg.ssids[i].ssid = req->ssids[i].ssid;
3589 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003590 } else {
3591 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592 }
3593
3594 if (req->n_channels) {
3595 arg.n_channels = req->n_channels;
3596 for (i = 0; i < arg.n_channels; i++)
3597 arg.channels[i] = req->channels[i]->center_freq;
3598 }
3599
3600 ret = ath10k_start_scan(ar, &arg);
3601 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003602 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003603 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003604 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 spin_unlock_bh(&ar->data_lock);
3606 }
3607
3608exit:
3609 mutex_unlock(&ar->conf_mutex);
3610 return ret;
3611}
3612
3613static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3614 struct ieee80211_vif *vif)
3615{
3616 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617
3618 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003619 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003621
3622 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003623}
3624
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003625static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3626 struct ath10k_vif *arvif,
3627 enum set_key_cmd cmd,
3628 struct ieee80211_key_conf *key)
3629{
3630 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3631 int ret;
3632
3633 /* 10.1 firmware branch requires default key index to be set to group
3634 * key index after installing it. Otherwise FW/HW Txes corrupted
3635 * frames with multi-vif APs. This is not required for main firmware
3636 * branch (e.g. 636).
3637 *
3638 * FIXME: This has been tested only in AP. It remains unknown if this
3639 * is required for multi-vif STA interfaces on 10.1 */
3640
3641 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3642 return;
3643
3644 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3645 return;
3646
3647 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3648 return;
3649
3650 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3651 return;
3652
3653 if (cmd != SET_KEY)
3654 return;
3655
3656 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3657 key->keyidx);
3658 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003659 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003660 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003661}
3662
Kalle Valo5e3dd152013-06-12 20:52:10 +03003663static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3664 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3665 struct ieee80211_key_conf *key)
3666{
3667 struct ath10k *ar = hw->priv;
3668 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3669 struct ath10k_peer *peer;
3670 const u8 *peer_addr;
3671 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3672 key->cipher == WLAN_CIPHER_SUITE_WEP104;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003673 bool def_idx = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003674 int ret = 0;
3675
3676 if (key->keyidx > WMI_MAX_KEY_INDEX)
3677 return -ENOSPC;
3678
3679 mutex_lock(&ar->conf_mutex);
3680
3681 if (sta)
3682 peer_addr = sta->addr;
3683 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3684 peer_addr = vif->bss_conf.bssid;
3685 else
3686 peer_addr = vif->addr;
3687
3688 key->hw_key_idx = key->keyidx;
3689
3690 /* the peer should not disappear in mid-way (unless FW goes awry) since
3691 * we already hold conf_mutex. we just make sure its there now. */
3692 spin_lock_bh(&ar->data_lock);
3693 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3694 spin_unlock_bh(&ar->data_lock);
3695
3696 if (!peer) {
3697 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003698 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003699 peer_addr);
3700 ret = -EOPNOTSUPP;
3701 goto exit;
3702 } else {
3703 /* if the peer doesn't exist there is no key to disable
3704 * anymore */
3705 goto exit;
3706 }
3707 }
3708
3709 if (is_wep) {
3710 if (cmd == SET_KEY)
3711 arvif->wep_keys[key->keyidx] = key;
3712 else
3713 arvif->wep_keys[key->keyidx] = NULL;
3714
3715 if (cmd == DISABLE_KEY)
3716 ath10k_clear_vdev_key(arvif, key);
3717 }
3718
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003719 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3720 * static WEP, do not set this flag for the keys whose key id
3721 * is greater than default key id.
3722 */
3723 if (arvif->def_wep_key_idx == -1)
3724 def_idx = true;
3725
3726 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003727 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003728 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003729 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003730 goto exit;
3731 }
3732
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003733 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3734
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735 spin_lock_bh(&ar->data_lock);
3736 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3737 if (peer && cmd == SET_KEY)
3738 peer->keys[key->keyidx] = key;
3739 else if (peer && cmd == DISABLE_KEY)
3740 peer->keys[key->keyidx] = NULL;
3741 else if (peer == NULL)
3742 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003743 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744 spin_unlock_bh(&ar->data_lock);
3745
3746exit:
3747 mutex_unlock(&ar->conf_mutex);
3748 return ret;
3749}
3750
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003751static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3752 struct ieee80211_vif *vif,
3753 int keyidx)
3754{
3755 struct ath10k *ar = hw->priv;
3756 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3757 int ret;
3758
3759 mutex_lock(&arvif->ar->conf_mutex);
3760
3761 if (arvif->ar->state != ATH10K_STATE_ON)
3762 goto unlock;
3763
3764 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3765 arvif->vdev_id, keyidx);
3766
3767 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3768 arvif->vdev_id,
3769 arvif->ar->wmi.vdev_param->def_keyid,
3770 keyidx);
3771
3772 if (ret) {
3773 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3774 arvif->vdev_id,
3775 ret);
3776 goto unlock;
3777 }
3778
3779 arvif->def_wep_key_idx = keyidx;
3780unlock:
3781 mutex_unlock(&arvif->ar->conf_mutex);
3782}
3783
Michal Kazior9797feb2014-02-14 14:49:48 +01003784static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3785{
3786 struct ath10k *ar;
3787 struct ath10k_vif *arvif;
3788 struct ath10k_sta *arsta;
3789 struct ieee80211_sta *sta;
3790 u32 changed, bw, nss, smps;
3791 int err;
3792
3793 arsta = container_of(wk, struct ath10k_sta, update_wk);
3794 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3795 arvif = arsta->arvif;
3796 ar = arvif->ar;
3797
3798 spin_lock_bh(&ar->data_lock);
3799
3800 changed = arsta->changed;
3801 arsta->changed = 0;
3802
3803 bw = arsta->bw;
3804 nss = arsta->nss;
3805 smps = arsta->smps;
3806
3807 spin_unlock_bh(&ar->data_lock);
3808
3809 mutex_lock(&ar->conf_mutex);
3810
3811 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003812 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003813 sta->addr, bw);
3814
3815 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3816 WMI_PEER_CHAN_WIDTH, bw);
3817 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003818 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003819 sta->addr, bw, err);
3820 }
3821
3822 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003824 sta->addr, nss);
3825
3826 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3827 WMI_PEER_NSS, nss);
3828 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003829 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003830 sta->addr, nss, err);
3831 }
3832
3833 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003834 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003835 sta->addr, smps);
3836
3837 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3838 WMI_PEER_SMPS_STATE, smps);
3839 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003840 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003841 sta->addr, smps, err);
3842 }
3843
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003844 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3845 changed & IEEE80211_RC_NSS_CHANGED) {
3846 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003847 sta->addr);
3848
Michal Kazior590922a2014-10-21 10:10:29 +03003849 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003850 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003851 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003852 sta->addr);
3853 }
3854
Michal Kazior9797feb2014-02-14 14:49:48 +01003855 mutex_unlock(&ar->conf_mutex);
3856}
3857
Michal Kaziorcfd10612014-11-25 15:16:05 +01003858static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3859{
3860 struct ath10k *ar = arvif->ar;
3861
3862 lockdep_assert_held(&ar->conf_mutex);
3863
3864 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3865 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3866 return 0;
3867
3868 if (ar->num_stations >= ar->max_num_stations)
3869 return -ENOBUFS;
3870
3871 ar->num_stations++;
3872
3873 return 0;
3874}
3875
3876static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3877{
3878 struct ath10k *ar = arvif->ar;
3879
3880 lockdep_assert_held(&ar->conf_mutex);
3881
3882 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3883 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3884 return;
3885
3886 ar->num_stations--;
3887}
3888
Kalle Valo5e3dd152013-06-12 20:52:10 +03003889static int ath10k_sta_state(struct ieee80211_hw *hw,
3890 struct ieee80211_vif *vif,
3891 struct ieee80211_sta *sta,
3892 enum ieee80211_sta_state old_state,
3893 enum ieee80211_sta_state new_state)
3894{
3895 struct ath10k *ar = hw->priv;
3896 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003897 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003898 int ret = 0;
3899
Michal Kazior76f90022014-02-25 09:29:57 +02003900 if (old_state == IEEE80211_STA_NOTEXIST &&
3901 new_state == IEEE80211_STA_NONE) {
3902 memset(arsta, 0, sizeof(*arsta));
3903 arsta->arvif = arvif;
3904 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3905 }
3906
Michal Kazior9797feb2014-02-14 14:49:48 +01003907 /* cancel must be done outside the mutex to avoid deadlock */
3908 if ((old_state == IEEE80211_STA_NONE &&
3909 new_state == IEEE80211_STA_NOTEXIST))
3910 cancel_work_sync(&arsta->update_wk);
3911
Kalle Valo5e3dd152013-06-12 20:52:10 +03003912 mutex_lock(&ar->conf_mutex);
3913
3914 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003915 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003916 /*
3917 * New station addition.
3918 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003919 ath10k_dbg(ar, ATH10K_DBG_MAC,
3920 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3921 arvif->vdev_id, sta->addr,
3922 ar->num_stations + 1, ar->max_num_stations,
3923 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003924
Michal Kaziorcfd10612014-11-25 15:16:05 +01003925 ret = ath10k_mac_inc_num_stations(arvif);
3926 if (ret) {
3927 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3928 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003929 goto exit;
3930 }
3931
Kalle Valo5e3dd152013-06-12 20:52:10 +03003932 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003933 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003934 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 -08003935 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003936 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003937 goto exit;
3938 }
Michal Kazior077efc82014-10-21 10:10:29 +03003939
3940 if (vif->type == NL80211_IFTYPE_STATION) {
3941 WARN_ON(arvif->is_started);
3942
3943 ret = ath10k_vdev_start(arvif);
3944 if (ret) {
3945 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3946 arvif->vdev_id, ret);
3947 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3948 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003949 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003950 goto exit;
3951 }
3952
3953 arvif->is_started = true;
3954 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955 } else if ((old_state == IEEE80211_STA_NONE &&
3956 new_state == IEEE80211_STA_NOTEXIST)) {
3957 /*
3958 * Existing station deletion.
3959 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003960 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003961 "mac vdev %d peer delete %pM (sta gone)\n",
3962 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003963
3964 if (vif->type == NL80211_IFTYPE_STATION) {
3965 WARN_ON(!arvif->is_started);
3966
3967 ret = ath10k_vdev_stop(arvif);
3968 if (ret)
3969 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3970 arvif->vdev_id, ret);
3971
3972 arvif->is_started = false;
3973 }
3974
Kalle Valo5e3dd152013-06-12 20:52:10 +03003975 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3976 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003977 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003978 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003979
Michal Kaziorcfd10612014-11-25 15:16:05 +01003980 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003981 } else if (old_state == IEEE80211_STA_AUTH &&
3982 new_state == IEEE80211_STA_ASSOC &&
3983 (vif->type == NL80211_IFTYPE_AP ||
3984 vif->type == NL80211_IFTYPE_ADHOC)) {
3985 /*
3986 * New association.
3987 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003988 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003989 sta->addr);
3990
Michal Kazior590922a2014-10-21 10:10:29 +03003991 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003992 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003993 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003994 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 } else if (old_state == IEEE80211_STA_ASSOC &&
3996 new_state == IEEE80211_STA_AUTH &&
3997 (vif->type == NL80211_IFTYPE_AP ||
3998 vif->type == NL80211_IFTYPE_ADHOC)) {
3999 /*
4000 * Disassociation.
4001 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004002 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004003 sta->addr);
4004
Michal Kazior590922a2014-10-21 10:10:29 +03004005 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004006 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004007 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004008 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004009 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004010exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004011 mutex_unlock(&ar->conf_mutex);
4012 return ret;
4013}
4014
4015static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004016 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017{
4018 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004019 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4020 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021 u32 value = 0;
4022 int ret = 0;
4023
Michal Kazior548db542013-07-05 16:15:15 +03004024 lockdep_assert_held(&ar->conf_mutex);
4025
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4027 return 0;
4028
4029 switch (ac) {
4030 case IEEE80211_AC_VO:
4031 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4032 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004033 prio = 7;
4034 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004035 break;
4036 case IEEE80211_AC_VI:
4037 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4038 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004039 prio = 5;
4040 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041 break;
4042 case IEEE80211_AC_BE:
4043 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4044 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004045 prio = 2;
4046 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004047 break;
4048 case IEEE80211_AC_BK:
4049 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4050 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004051 prio = 0;
4052 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004053 break;
4054 }
4055
4056 if (enable)
4057 arvif->u.sta.uapsd |= value;
4058 else
4059 arvif->u.sta.uapsd &= ~value;
4060
4061 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4062 WMI_STA_PS_PARAM_UAPSD,
4063 arvif->u.sta.uapsd);
4064 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004065 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004066 goto exit;
4067 }
4068
4069 if (arvif->u.sta.uapsd)
4070 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4071 else
4072 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4073
4074 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4075 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4076 value);
4077 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004078 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004079
Michal Kazior9f9b5742014-12-12 12:41:36 +01004080 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4081 if (ret) {
4082 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4083 arvif->vdev_id, ret);
4084 return ret;
4085 }
4086
4087 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4088 if (ret) {
4089 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4090 arvif->vdev_id, ret);
4091 return ret;
4092 }
4093
Michal Kaziorb0e56152015-01-24 12:14:52 +02004094 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4095 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4096 /* Only userspace can make an educated decision when to send
4097 * trigger frame. The following effectively disables u-UAPSD
4098 * autotrigger in firmware (which is enabled by default
4099 * provided the autotrigger service is available).
4100 */
4101
4102 arg.wmm_ac = acc;
4103 arg.user_priority = prio;
4104 arg.service_interval = 0;
4105 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4106 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4107
4108 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4109 arvif->bssid, &arg, 1);
4110 if (ret) {
4111 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4112 ret);
4113 return ret;
4114 }
4115 }
4116
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117exit:
4118 return ret;
4119}
4120
4121static int ath10k_conf_tx(struct ieee80211_hw *hw,
4122 struct ieee80211_vif *vif, u16 ac,
4123 const struct ieee80211_tx_queue_params *params)
4124{
4125 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004126 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004127 struct wmi_wmm_params_arg *p = NULL;
4128 int ret;
4129
4130 mutex_lock(&ar->conf_mutex);
4131
4132 switch (ac) {
4133 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004134 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004135 break;
4136 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004137 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004138 break;
4139 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004140 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004141 break;
4142 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004143 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004144 break;
4145 }
4146
4147 if (WARN_ON(!p)) {
4148 ret = -EINVAL;
4149 goto exit;
4150 }
4151
4152 p->cwmin = params->cw_min;
4153 p->cwmax = params->cw_max;
4154 p->aifs = params->aifs;
4155
4156 /*
4157 * The channel time duration programmed in the HW is in absolute
4158 * microseconds, while mac80211 gives the txop in units of
4159 * 32 microseconds.
4160 */
4161 p->txop = params->txop * 32;
4162
Michal Kazior7fc979a2015-01-28 09:57:28 +02004163 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4164 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4165 &arvif->wmm_params);
4166 if (ret) {
4167 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4168 arvif->vdev_id, ret);
4169 goto exit;
4170 }
4171 } else {
4172 /* This won't work well with multi-interface cases but it's
4173 * better than nothing.
4174 */
4175 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4176 if (ret) {
4177 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4178 goto exit;
4179 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004180 }
4181
4182 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004184 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004185
4186exit:
4187 mutex_unlock(&ar->conf_mutex);
4188 return ret;
4189}
4190
4191#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4192
4193static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4194 struct ieee80211_vif *vif,
4195 struct ieee80211_channel *chan,
4196 int duration,
4197 enum ieee80211_roc_type type)
4198{
4199 struct ath10k *ar = hw->priv;
4200 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4201 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004202 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004203
4204 mutex_lock(&ar->conf_mutex);
4205
4206 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004207 switch (ar->scan.state) {
4208 case ATH10K_SCAN_IDLE:
4209 reinit_completion(&ar->scan.started);
4210 reinit_completion(&ar->scan.completed);
4211 reinit_completion(&ar->scan.on_channel);
4212 ar->scan.state = ATH10K_SCAN_STARTING;
4213 ar->scan.is_roc = true;
4214 ar->scan.vdev_id = arvif->vdev_id;
4215 ar->scan.roc_freq = chan->center_freq;
4216 ret = 0;
4217 break;
4218 case ATH10K_SCAN_STARTING:
4219 case ATH10K_SCAN_RUNNING:
4220 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004221 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004222 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004223 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004224 spin_unlock_bh(&ar->data_lock);
4225
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004226 if (ret)
4227 goto exit;
4228
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004229 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4230
Kalle Valo5e3dd152013-06-12 20:52:10 +03004231 memset(&arg, 0, sizeof(arg));
4232 ath10k_wmi_start_scan_init(ar, &arg);
4233 arg.vdev_id = arvif->vdev_id;
4234 arg.scan_id = ATH10K_SCAN_ID;
4235 arg.n_channels = 1;
4236 arg.channels[0] = chan->center_freq;
4237 arg.dwell_time_active = duration;
4238 arg.dwell_time_passive = duration;
4239 arg.max_scan_time = 2 * duration;
4240 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4241 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4242
4243 ret = ath10k_start_scan(ar, &arg);
4244 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004245 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004246 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004247 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004248 spin_unlock_bh(&ar->data_lock);
4249 goto exit;
4250 }
4251
4252 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4253 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004254 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004255
4256 ret = ath10k_scan_stop(ar);
4257 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004258 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004259
Kalle Valo5e3dd152013-06-12 20:52:10 +03004260 ret = -ETIMEDOUT;
4261 goto exit;
4262 }
4263
4264 ret = 0;
4265exit:
4266 mutex_unlock(&ar->conf_mutex);
4267 return ret;
4268}
4269
4270static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4271{
4272 struct ath10k *ar = hw->priv;
4273
4274 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004275 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004276 mutex_unlock(&ar->conf_mutex);
4277
Michal Kazior4eb2e162014-10-28 10:23:09 +01004278 cancel_delayed_work_sync(&ar->scan.timeout);
4279
Kalle Valo5e3dd152013-06-12 20:52:10 +03004280 return 0;
4281}
4282
4283/*
4284 * Both RTS and Fragmentation threshold are interface-specific
4285 * in ath10k, but device-specific in mac80211.
4286 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004287
4288static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4289{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004290 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004291 struct ath10k_vif *arvif;
4292 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004293
Michal Kaziorad088bf2013-10-16 15:44:46 +03004294 mutex_lock(&ar->conf_mutex);
4295 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004296 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004297 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004298
Michal Kaziorad088bf2013-10-16 15:44:46 +03004299 ret = ath10k_mac_set_rts(arvif, value);
4300 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004301 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004302 arvif->vdev_id, ret);
4303 break;
4304 }
4305 }
4306 mutex_unlock(&ar->conf_mutex);
4307
4308 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004309}
4310
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004311static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4312 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004313{
4314 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004315 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004316 int ret;
4317
4318 /* mac80211 doesn't care if we really xmit queued frames or not
4319 * we'll collect those frames either way if we stop/delete vdevs */
4320 if (drop)
4321 return;
4322
Michal Kazior548db542013-07-05 16:15:15 +03004323 mutex_lock(&ar->conf_mutex);
4324
Michal Kazioraffd3212013-07-16 09:54:35 +02004325 if (ar->state == ATH10K_STATE_WEDGED)
4326 goto skip;
4327
Michal Kazioredb82362013-07-05 16:15:14 +03004328 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004329 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004330
Michal Kazioredb82362013-07-05 16:15:14 +03004331 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004332 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004333 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004334
Michal Kazior7962b0d2014-10-28 10:34:38 +01004335 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4336 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4337 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004338
4339 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004340 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004341
4342 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004343 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004344 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004345
Michal Kazioraffd3212013-07-16 09:54:35 +02004346skip:
Michal Kazior548db542013-07-05 16:15:15 +03004347 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004348}
4349
4350/* TODO: Implement this function properly
4351 * For now it is needed to reply to Probe Requests in IBSS mode.
4352 * Propably we need this information from FW.
4353 */
4354static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4355{
4356 return 1;
4357}
4358
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004359#ifdef CONFIG_PM
4360static int ath10k_suspend(struct ieee80211_hw *hw,
4361 struct cfg80211_wowlan *wowlan)
4362{
4363 struct ath10k *ar = hw->priv;
4364 int ret;
4365
Marek Puzyniak9042e172014-02-10 17:14:23 +01004366 mutex_lock(&ar->conf_mutex);
4367
Marek Puzyniak00f54822014-02-10 17:14:24 +01004368 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004369 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004370 if (ret == -ETIMEDOUT)
4371 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004372 ret = 1;
4373 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004374 }
4375
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004376 ret = ath10k_hif_suspend(ar);
4377 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004378 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004379 goto resume;
4380 }
4381
Marek Puzyniak9042e172014-02-10 17:14:23 +01004382 ret = 0;
4383 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004384resume:
4385 ret = ath10k_wmi_pdev_resume_target(ar);
4386 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004387 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004388
4389 ret = 1;
4390exit:
4391 mutex_unlock(&ar->conf_mutex);
4392 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004393}
4394
4395static int ath10k_resume(struct ieee80211_hw *hw)
4396{
4397 struct ath10k *ar = hw->priv;
4398 int ret;
4399
Marek Puzyniak9042e172014-02-10 17:14:23 +01004400 mutex_lock(&ar->conf_mutex);
4401
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004402 ret = ath10k_hif_resume(ar);
4403 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004404 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004405 ret = 1;
4406 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004407 }
4408
4409 ret = ath10k_wmi_pdev_resume_target(ar);
4410 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004411 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004412 ret = 1;
4413 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004414 }
4415
Marek Puzyniak9042e172014-02-10 17:14:23 +01004416 ret = 0;
4417exit:
4418 mutex_unlock(&ar->conf_mutex);
4419 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004420}
4421#endif
4422
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004423static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4424 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004425{
4426 struct ath10k *ar = hw->priv;
4427
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004428 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4429 return;
4430
Michal Kazioraffd3212013-07-16 09:54:35 +02004431 mutex_lock(&ar->conf_mutex);
4432
4433 /* If device failed to restart it will be in a different state, e.g.
4434 * ATH10K_STATE_WEDGED */
4435 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004436 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004437 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004438 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004439 }
4440
4441 mutex_unlock(&ar->conf_mutex);
4442}
4443
Michal Kazior2e1dea42013-07-31 10:32:40 +02004444static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4445 struct survey_info *survey)
4446{
4447 struct ath10k *ar = hw->priv;
4448 struct ieee80211_supported_band *sband;
4449 struct survey_info *ar_survey = &ar->survey[idx];
4450 int ret = 0;
4451
4452 mutex_lock(&ar->conf_mutex);
4453
4454 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4455 if (sband && idx >= sband->n_channels) {
4456 idx -= sband->n_channels;
4457 sband = NULL;
4458 }
4459
4460 if (!sband)
4461 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4462
4463 if (!sband || idx >= sband->n_channels) {
4464 ret = -ENOENT;
4465 goto exit;
4466 }
4467
4468 spin_lock_bh(&ar->data_lock);
4469 memcpy(survey, ar_survey, sizeof(*survey));
4470 spin_unlock_bh(&ar->data_lock);
4471
4472 survey->channel = &sband->channels[idx];
4473
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004474 if (ar->rx_channel == survey->channel)
4475 survey->filled |= SURVEY_INFO_IN_USE;
4476
Michal Kazior2e1dea42013-07-31 10:32:40 +02004477exit:
4478 mutex_unlock(&ar->conf_mutex);
4479 return ret;
4480}
4481
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004482/* Helper table for legacy fixed_rate/bitrate_mask */
4483static const u8 cck_ofdm_rate[] = {
4484 /* CCK */
4485 3, /* 1Mbps */
4486 2, /* 2Mbps */
4487 1, /* 5.5Mbps */
4488 0, /* 11Mbps */
4489 /* OFDM */
4490 3, /* 6Mbps */
4491 7, /* 9Mbps */
4492 2, /* 12Mbps */
4493 6, /* 18Mbps */
4494 1, /* 24Mbps */
4495 5, /* 36Mbps */
4496 0, /* 48Mbps */
4497 4, /* 54Mbps */
4498};
4499
4500/* Check if only one bit set */
4501static int ath10k_check_single_mask(u32 mask)
4502{
4503 int bit;
4504
4505 bit = ffs(mask);
4506 if (!bit)
4507 return 0;
4508
4509 mask &= ~BIT(bit - 1);
4510 if (mask)
4511 return 2;
4512
4513 return 1;
4514}
4515
4516static bool
4517ath10k_default_bitrate_mask(struct ath10k *ar,
4518 enum ieee80211_band band,
4519 const struct cfg80211_bitrate_mask *mask)
4520{
4521 u32 legacy = 0x00ff;
4522 u8 ht = 0xff, i;
4523 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004524 u16 nrf = ar->num_rf_chains;
4525
4526 if (ar->cfg_tx_chainmask)
4527 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004528
4529 switch (band) {
4530 case IEEE80211_BAND_2GHZ:
4531 legacy = 0x00fff;
4532 vht = 0;
4533 break;
4534 case IEEE80211_BAND_5GHZ:
4535 break;
4536 default:
4537 return false;
4538 }
4539
4540 if (mask->control[band].legacy != legacy)
4541 return false;
4542
Ben Greearb116ea12014-11-24 16:22:10 +02004543 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004544 if (mask->control[band].ht_mcs[i] != ht)
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].vht_mcs[i] != vht)
4549 return false;
4550
4551 return true;
4552}
4553
4554static bool
4555ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4556 enum ieee80211_band band,
4557 u8 *fixed_nss)
4558{
4559 int ht_nss = 0, vht_nss = 0, i;
4560
4561 /* check legacy */
4562 if (ath10k_check_single_mask(mask->control[band].legacy))
4563 return false;
4564
4565 /* check HT */
4566 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4567 if (mask->control[band].ht_mcs[i] == 0xff)
4568 continue;
4569 else if (mask->control[band].ht_mcs[i] == 0x00)
4570 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004571
4572 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004573 }
4574
4575 ht_nss = i;
4576
4577 /* check VHT */
4578 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4579 if (mask->control[band].vht_mcs[i] == 0x03ff)
4580 continue;
4581 else if (mask->control[band].vht_mcs[i] == 0x0000)
4582 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004583
4584 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004585 }
4586
4587 vht_nss = i;
4588
4589 if (ht_nss > 0 && vht_nss > 0)
4590 return false;
4591
4592 if (ht_nss)
4593 *fixed_nss = ht_nss;
4594 else if (vht_nss)
4595 *fixed_nss = vht_nss;
4596 else
4597 return false;
4598
4599 return true;
4600}
4601
4602static bool
4603ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4604 enum ieee80211_band band,
4605 enum wmi_rate_preamble *preamble)
4606{
4607 int legacy = 0, ht = 0, vht = 0, i;
4608
4609 *preamble = WMI_RATE_PREAMBLE_OFDM;
4610
4611 /* check legacy */
4612 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4613 if (legacy > 1)
4614 return false;
4615
4616 /* check HT */
4617 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4618 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4619 if (ht > 1)
4620 return false;
4621
4622 /* check VHT */
4623 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4624 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4625 if (vht > 1)
4626 return false;
4627
4628 /* Currently we support only one fixed_rate */
4629 if ((legacy + ht + vht) != 1)
4630 return false;
4631
4632 if (ht)
4633 *preamble = WMI_RATE_PREAMBLE_HT;
4634 else if (vht)
4635 *preamble = WMI_RATE_PREAMBLE_VHT;
4636
4637 return true;
4638}
4639
4640static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004641ath10k_bitrate_mask_rate(struct ath10k *ar,
4642 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004643 enum ieee80211_band band,
4644 u8 *fixed_rate,
4645 u8 *fixed_nss)
4646{
4647 u8 rate = 0, pream = 0, nss = 0, i;
4648 enum wmi_rate_preamble preamble;
4649
4650 /* Check if single rate correct */
4651 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4652 return false;
4653
4654 pream = preamble;
4655
4656 switch (preamble) {
4657 case WMI_RATE_PREAMBLE_CCK:
4658 case WMI_RATE_PREAMBLE_OFDM:
4659 i = ffs(mask->control[band].legacy) - 1;
4660
4661 if (band == IEEE80211_BAND_2GHZ && i < 4)
4662 pream = WMI_RATE_PREAMBLE_CCK;
4663
4664 if (band == IEEE80211_BAND_5GHZ)
4665 i += 4;
4666
4667 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4668 return false;
4669
4670 rate = cck_ofdm_rate[i];
4671 break;
4672 case WMI_RATE_PREAMBLE_HT:
4673 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4674 if (mask->control[band].ht_mcs[i])
4675 break;
4676
4677 if (i == IEEE80211_HT_MCS_MASK_LEN)
4678 return false;
4679
4680 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4681 nss = i;
4682 break;
4683 case WMI_RATE_PREAMBLE_VHT:
4684 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4685 if (mask->control[band].vht_mcs[i])
4686 break;
4687
4688 if (i == NL80211_VHT_NSS_MAX)
4689 return false;
4690
4691 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4692 nss = i;
4693 break;
4694 }
4695
4696 *fixed_nss = nss + 1;
4697 nss <<= 4;
4698 pream <<= 6;
4699
Michal Kazior7aa7a722014-08-25 12:09:38 +02004700 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 +01004701 pream, nss, rate);
4702
4703 *fixed_rate = pream | nss | rate;
4704
4705 return true;
4706}
4707
Michal Kazior7aa7a722014-08-25 12:09:38 +02004708static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4709 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004710 enum ieee80211_band band,
4711 u8 *fixed_rate,
4712 u8 *fixed_nss)
4713{
4714 /* First check full NSS mask, if we can simply limit NSS */
4715 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4716 return true;
4717
4718 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004719 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004720}
4721
4722static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4723 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004724 u8 fixed_nss,
4725 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004726{
4727 struct ath10k *ar = arvif->ar;
4728 u32 vdev_param;
4729 int ret = 0;
4730
4731 mutex_lock(&ar->conf_mutex);
4732
4733 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004734 arvif->fixed_nss == fixed_nss &&
4735 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004736 goto exit;
4737
4738 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004739 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004740
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004741 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004743
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004744 vdev_param = ar->wmi.vdev_param->fixed_rate;
4745 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4746 vdev_param, fixed_rate);
4747 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004748 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004749 fixed_rate, ret);
4750 ret = -EINVAL;
4751 goto exit;
4752 }
4753
4754 arvif->fixed_rate = fixed_rate;
4755
4756 vdev_param = ar->wmi.vdev_param->nss;
4757 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4758 vdev_param, fixed_nss);
4759
4760 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004761 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004762 fixed_nss, ret);
4763 ret = -EINVAL;
4764 goto exit;
4765 }
4766
4767 arvif->fixed_nss = fixed_nss;
4768
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004769 vdev_param = ar->wmi.vdev_param->sgi;
4770 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4771 force_sgi);
4772
4773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004774 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004775 force_sgi, ret);
4776 ret = -EINVAL;
4777 goto exit;
4778 }
4779
4780 arvif->force_sgi = force_sgi;
4781
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004782exit:
4783 mutex_unlock(&ar->conf_mutex);
4784 return ret;
4785}
4786
4787static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4788 struct ieee80211_vif *vif,
4789 const struct cfg80211_bitrate_mask *mask)
4790{
4791 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4792 struct ath10k *ar = arvif->ar;
4793 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4794 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4795 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004796 u8 force_sgi;
4797
Ben Greearb116ea12014-11-24 16:22:10 +02004798 if (ar->cfg_tx_chainmask)
4799 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4800
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004801 force_sgi = mask->control[band].gi;
4802 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4803 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004804
4805 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004806 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004807 &fixed_rate,
4808 &fixed_nss))
4809 return -EINVAL;
4810 }
4811
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004812 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004813 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004814 return -EINVAL;
4815 }
4816
4817 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4818 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004819}
4820
Michal Kazior9797feb2014-02-14 14:49:48 +01004821static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4822 struct ieee80211_vif *vif,
4823 struct ieee80211_sta *sta,
4824 u32 changed)
4825{
4826 struct ath10k *ar = hw->priv;
4827 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4828 u32 bw, smps;
4829
4830 spin_lock_bh(&ar->data_lock);
4831
Michal Kazior7aa7a722014-08-25 12:09:38 +02004832 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004833 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4834 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4835 sta->smps_mode);
4836
4837 if (changed & IEEE80211_RC_BW_CHANGED) {
4838 bw = WMI_PEER_CHWIDTH_20MHZ;
4839
4840 switch (sta->bandwidth) {
4841 case IEEE80211_STA_RX_BW_20:
4842 bw = WMI_PEER_CHWIDTH_20MHZ;
4843 break;
4844 case IEEE80211_STA_RX_BW_40:
4845 bw = WMI_PEER_CHWIDTH_40MHZ;
4846 break;
4847 case IEEE80211_STA_RX_BW_80:
4848 bw = WMI_PEER_CHWIDTH_80MHZ;
4849 break;
4850 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004851 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004852 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004853 bw = WMI_PEER_CHWIDTH_20MHZ;
4854 break;
4855 }
4856
4857 arsta->bw = bw;
4858 }
4859
4860 if (changed & IEEE80211_RC_NSS_CHANGED)
4861 arsta->nss = sta->rx_nss;
4862
4863 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4864 smps = WMI_PEER_SMPS_PS_NONE;
4865
4866 switch (sta->smps_mode) {
4867 case IEEE80211_SMPS_AUTOMATIC:
4868 case IEEE80211_SMPS_OFF:
4869 smps = WMI_PEER_SMPS_PS_NONE;
4870 break;
4871 case IEEE80211_SMPS_STATIC:
4872 smps = WMI_PEER_SMPS_STATIC;
4873 break;
4874 case IEEE80211_SMPS_DYNAMIC:
4875 smps = WMI_PEER_SMPS_DYNAMIC;
4876 break;
4877 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004878 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004879 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004880 smps = WMI_PEER_SMPS_PS_NONE;
4881 break;
4882 }
4883
4884 arsta->smps = smps;
4885 }
4886
Michal Kazior9797feb2014-02-14 14:49:48 +01004887 arsta->changed |= changed;
4888
4889 spin_unlock_bh(&ar->data_lock);
4890
4891 ieee80211_queue_work(hw, &arsta->update_wk);
4892}
4893
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004894static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4895{
4896 /*
4897 * FIXME: Return 0 for time being. Need to figure out whether FW
4898 * has the API to fetch 64-bit local TSF
4899 */
4900
4901 return 0;
4902}
4903
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004904static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4905 struct ieee80211_vif *vif,
4906 enum ieee80211_ampdu_mlme_action action,
4907 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4908 u8 buf_size)
4909{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004910 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004911 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4912
Michal Kazior7aa7a722014-08-25 12:09:38 +02004913 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 +02004914 arvif->vdev_id, sta->addr, tid, action);
4915
4916 switch (action) {
4917 case IEEE80211_AMPDU_RX_START:
4918 case IEEE80211_AMPDU_RX_STOP:
4919 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4920 * creation/removal. Do we need to verify this?
4921 */
4922 return 0;
4923 case IEEE80211_AMPDU_TX_START:
4924 case IEEE80211_AMPDU_TX_STOP_CONT:
4925 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4926 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4927 case IEEE80211_AMPDU_TX_OPERATIONAL:
4928 /* Firmware offloads Tx aggregation entirely so deny mac80211
4929 * Tx aggregation requests.
4930 */
4931 return -EOPNOTSUPP;
4932 }
4933
4934 return -EINVAL;
4935}
4936
Kalle Valo5e3dd152013-06-12 20:52:10 +03004937static const struct ieee80211_ops ath10k_ops = {
4938 .tx = ath10k_tx,
4939 .start = ath10k_start,
4940 .stop = ath10k_stop,
4941 .config = ath10k_config,
4942 .add_interface = ath10k_add_interface,
4943 .remove_interface = ath10k_remove_interface,
4944 .configure_filter = ath10k_configure_filter,
4945 .bss_info_changed = ath10k_bss_info_changed,
4946 .hw_scan = ath10k_hw_scan,
4947 .cancel_hw_scan = ath10k_cancel_hw_scan,
4948 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004949 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004950 .sta_state = ath10k_sta_state,
4951 .conf_tx = ath10k_conf_tx,
4952 .remain_on_channel = ath10k_remain_on_channel,
4953 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4954 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004955 .flush = ath10k_flush,
4956 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004957 .set_antenna = ath10k_set_antenna,
4958 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004959 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004960 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004961 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004962 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004963 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004964 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004965 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4966 .get_et_stats = ath10k_debug_get_et_stats,
4967 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004968
4969 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4970
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004971#ifdef CONFIG_PM
4972 .suspend = ath10k_suspend,
4973 .resume = ath10k_resume,
4974#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004975#ifdef CONFIG_MAC80211_DEBUGFS
4976 .sta_add_debugfs = ath10k_sta_add_debugfs,
4977#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004978};
4979
4980#define RATETAB_ENT(_rate, _rateid, _flags) { \
4981 .bitrate = (_rate), \
4982 .flags = (_flags), \
4983 .hw_value = (_rateid), \
4984}
4985
4986#define CHAN2G(_channel, _freq, _flags) { \
4987 .band = IEEE80211_BAND_2GHZ, \
4988 .hw_value = (_channel), \
4989 .center_freq = (_freq), \
4990 .flags = (_flags), \
4991 .max_antenna_gain = 0, \
4992 .max_power = 30, \
4993}
4994
4995#define CHAN5G(_channel, _freq, _flags) { \
4996 .band = IEEE80211_BAND_5GHZ, \
4997 .hw_value = (_channel), \
4998 .center_freq = (_freq), \
4999 .flags = (_flags), \
5000 .max_antenna_gain = 0, \
5001 .max_power = 30, \
5002}
5003
5004static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5005 CHAN2G(1, 2412, 0),
5006 CHAN2G(2, 2417, 0),
5007 CHAN2G(3, 2422, 0),
5008 CHAN2G(4, 2427, 0),
5009 CHAN2G(5, 2432, 0),
5010 CHAN2G(6, 2437, 0),
5011 CHAN2G(7, 2442, 0),
5012 CHAN2G(8, 2447, 0),
5013 CHAN2G(9, 2452, 0),
5014 CHAN2G(10, 2457, 0),
5015 CHAN2G(11, 2462, 0),
5016 CHAN2G(12, 2467, 0),
5017 CHAN2G(13, 2472, 0),
5018 CHAN2G(14, 2484, 0),
5019};
5020
5021static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005022 CHAN5G(36, 5180, 0),
5023 CHAN5G(40, 5200, 0),
5024 CHAN5G(44, 5220, 0),
5025 CHAN5G(48, 5240, 0),
5026 CHAN5G(52, 5260, 0),
5027 CHAN5G(56, 5280, 0),
5028 CHAN5G(60, 5300, 0),
5029 CHAN5G(64, 5320, 0),
5030 CHAN5G(100, 5500, 0),
5031 CHAN5G(104, 5520, 0),
5032 CHAN5G(108, 5540, 0),
5033 CHAN5G(112, 5560, 0),
5034 CHAN5G(116, 5580, 0),
5035 CHAN5G(120, 5600, 0),
5036 CHAN5G(124, 5620, 0),
5037 CHAN5G(128, 5640, 0),
5038 CHAN5G(132, 5660, 0),
5039 CHAN5G(136, 5680, 0),
5040 CHAN5G(140, 5700, 0),
5041 CHAN5G(149, 5745, 0),
5042 CHAN5G(153, 5765, 0),
5043 CHAN5G(157, 5785, 0),
5044 CHAN5G(161, 5805, 0),
5045 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005046};
5047
Michal Kazior91b12082014-12-12 12:41:35 +01005048/* Note: Be careful if you re-order these. There is code which depends on this
5049 * ordering.
5050 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005051static struct ieee80211_rate ath10k_rates[] = {
5052 /* CCK */
5053 RATETAB_ENT(10, 0x82, 0),
5054 RATETAB_ENT(20, 0x84, 0),
5055 RATETAB_ENT(55, 0x8b, 0),
5056 RATETAB_ENT(110, 0x96, 0),
5057 /* OFDM */
5058 RATETAB_ENT(60, 0x0c, 0),
5059 RATETAB_ENT(90, 0x12, 0),
5060 RATETAB_ENT(120, 0x18, 0),
5061 RATETAB_ENT(180, 0x24, 0),
5062 RATETAB_ENT(240, 0x30, 0),
5063 RATETAB_ENT(360, 0x48, 0),
5064 RATETAB_ENT(480, 0x60, 0),
5065 RATETAB_ENT(540, 0x6c, 0),
5066};
5067
5068#define ath10k_a_rates (ath10k_rates + 4)
5069#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5070#define ath10k_g_rates (ath10k_rates + 0)
5071#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5072
Michal Kaziore7b54192014-08-07 11:03:27 +02005073struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005074{
5075 struct ieee80211_hw *hw;
5076 struct ath10k *ar;
5077
Michal Kaziore7b54192014-08-07 11:03:27 +02005078 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005079 if (!hw)
5080 return NULL;
5081
5082 ar = hw->priv;
5083 ar->hw = hw;
5084
5085 return ar;
5086}
5087
5088void ath10k_mac_destroy(struct ath10k *ar)
5089{
5090 ieee80211_free_hw(ar->hw);
5091}
5092
5093static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5094 {
5095 .max = 8,
5096 .types = BIT(NL80211_IFTYPE_STATION)
5097 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005098 },
5099 {
5100 .max = 3,
5101 .types = BIT(NL80211_IFTYPE_P2P_GO)
5102 },
5103 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005104 .max = 1,
5105 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5106 },
5107 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005108 .max = 7,
5109 .types = BIT(NL80211_IFTYPE_AP)
5110 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005111};
5112
Bartosz Markowskif2595092013-12-10 16:20:39 +01005113static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005114 {
5115 .max = 8,
5116 .types = BIT(NL80211_IFTYPE_AP)
5117 },
5118};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005119
5120static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5121 {
5122 .limits = ath10k_if_limits,
5123 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5124 .max_interfaces = 8,
5125 .num_different_channels = 1,
5126 .beacon_int_infra_match = true,
5127 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005128};
5129
5130static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005131 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005132 .limits = ath10k_10x_if_limits,
5133 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005134 .max_interfaces = 8,
5135 .num_different_channels = 1,
5136 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005137#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005138 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5139 BIT(NL80211_CHAN_WIDTH_20) |
5140 BIT(NL80211_CHAN_WIDTH_40) |
5141 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005142#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005143 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005144};
5145
5146static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5147{
5148 struct ieee80211_sta_vht_cap vht_cap = {0};
5149 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005150 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005151
5152 vht_cap.vht_supported = 1;
5153 vht_cap.cap = ar->vht_cap_info;
5154
Michal Kazior8865bee42013-07-24 12:36:46 +02005155 mcs_map = 0;
5156 for (i = 0; i < 8; i++) {
5157 if (i < ar->num_rf_chains)
5158 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5159 else
5160 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5161 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005162
5163 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5164 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5165
5166 return vht_cap;
5167}
5168
5169static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5170{
5171 int i;
5172 struct ieee80211_sta_ht_cap ht_cap = {0};
5173
5174 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5175 return ht_cap;
5176
5177 ht_cap.ht_supported = 1;
5178 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5179 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5180 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5181 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5182 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5183
5184 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5185 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5186
5187 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5188 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5189
5190 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5191 u32 smps;
5192
5193 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5194 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5195
5196 ht_cap.cap |= smps;
5197 }
5198
5199 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5200 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5201
5202 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5203 u32 stbc;
5204
5205 stbc = ar->ht_cap_info;
5206 stbc &= WMI_HT_CAP_RX_STBC;
5207 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5208 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5209 stbc &= IEEE80211_HT_CAP_RX_STBC;
5210
5211 ht_cap.cap |= stbc;
5212 }
5213
5214 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5215 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5216
5217 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5218 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5219
5220 /* max AMSDU is implicitly taken from vht_cap_info */
5221 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5222 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5223
Michal Kazior8865bee42013-07-24 12:36:46 +02005224 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005225 ht_cap.mcs.rx_mask[i] = 0xFF;
5226
5227 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5228
5229 return ht_cap;
5230}
5231
Kalle Valo5e3dd152013-06-12 20:52:10 +03005232static void ath10k_get_arvif_iter(void *data, u8 *mac,
5233 struct ieee80211_vif *vif)
5234{
5235 struct ath10k_vif_iter *arvif_iter = data;
5236 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5237
5238 if (arvif->vdev_id == arvif_iter->vdev_id)
5239 arvif_iter->arvif = arvif;
5240}
5241
5242struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5243{
5244 struct ath10k_vif_iter arvif_iter;
5245 u32 flags;
5246
5247 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5248 arvif_iter.vdev_id = vdev_id;
5249
5250 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5251 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5252 flags,
5253 ath10k_get_arvif_iter,
5254 &arvif_iter);
5255 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005256 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005257 return NULL;
5258 }
5259
5260 return arvif_iter.arvif;
5261}
5262
5263int ath10k_mac_register(struct ath10k *ar)
5264{
5265 struct ieee80211_supported_band *band;
5266 struct ieee80211_sta_vht_cap vht_cap;
5267 struct ieee80211_sta_ht_cap ht_cap;
5268 void *channels;
5269 int ret;
5270
5271 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5272
5273 SET_IEEE80211_DEV(ar->hw, ar->dev);
5274
5275 ht_cap = ath10k_get_ht_cap(ar);
5276 vht_cap = ath10k_create_vht_cap(ar);
5277
5278 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5279 channels = kmemdup(ath10k_2ghz_channels,
5280 sizeof(ath10k_2ghz_channels),
5281 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005282 if (!channels) {
5283 ret = -ENOMEM;
5284 goto err_free;
5285 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005286
5287 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5288 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5289 band->channels = channels;
5290 band->n_bitrates = ath10k_g_rates_size;
5291 band->bitrates = ath10k_g_rates;
5292 band->ht_cap = ht_cap;
5293
Yanbo Lid68bb122015-01-23 08:18:20 +08005294 /* Enable the VHT support at 2.4 GHz */
5295 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005296
5297 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5298 }
5299
5300 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5301 channels = kmemdup(ath10k_5ghz_channels,
5302 sizeof(ath10k_5ghz_channels),
5303 GFP_KERNEL);
5304 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005305 ret = -ENOMEM;
5306 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005307 }
5308
5309 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5310 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5311 band->channels = channels;
5312 band->n_bitrates = ath10k_a_rates_size;
5313 band->bitrates = ath10k_a_rates;
5314 band->ht_cap = ht_cap;
5315 band->vht_cap = vht_cap;
5316 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5317 }
5318
5319 ar->hw->wiphy->interface_modes =
5320 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005321 BIT(NL80211_IFTYPE_AP);
5322
Ben Greear46acf7b2014-05-16 17:15:38 +03005323 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5324 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5325
Bartosz Markowskid3541812013-12-10 16:20:40 +01005326 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5327 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005328 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005329 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5330 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005331
5332 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5333 IEEE80211_HW_SUPPORTS_PS |
5334 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5335 IEEE80211_HW_SUPPORTS_UAPSD |
5336 IEEE80211_HW_MFP_CAPABLE |
5337 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5338 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005339 IEEE80211_HW_AP_LINK_PS |
5340 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005341
Eliad Peller0d8614b2014-09-10 14:07:36 +03005342 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5343
Kalle Valo5e3dd152013-06-12 20:52:10 +03005344 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005345 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005346
5347 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5348 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5349 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5350 }
5351
5352 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5353 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5354
5355 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005356 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005357
Kalle Valo5e3dd152013-06-12 20:52:10 +03005358 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5359
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005360 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5361 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5362
5363 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5364 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5365 * correct Probe Responses. This is more of a hack advert..
5366 */
5367 ar->hw->wiphy->probe_resp_offload |=
5368 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5369 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5370 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5371 }
5372
Kalle Valo5e3dd152013-06-12 20:52:10 +03005373 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005374 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005375 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5376
5377 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005378 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5379
Kalle Valo5e3dd152013-06-12 20:52:10 +03005380 /*
5381 * on LL hardware queues are managed entirely by the FW
5382 * so we only advertise to mac we can do the queues thing
5383 */
5384 ar->hw->queues = 4;
5385
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005386 switch (ar->wmi.op_version) {
5387 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5388 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005389 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5390 ar->hw->wiphy->n_iface_combinations =
5391 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005392 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005393 break;
5394 case ATH10K_FW_WMI_OP_VERSION_10_1:
5395 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005396 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005397 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5398 ar->hw->wiphy->n_iface_combinations =
5399 ARRAY_SIZE(ath10k_10x_if_comb);
5400 break;
5401 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5402 case ATH10K_FW_WMI_OP_VERSION_MAX:
5403 WARN_ON(1);
5404 ret = -EINVAL;
5405 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005406 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005407
Michal Kazior7c199992013-07-31 10:47:57 +02005408 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5409
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005410 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5411 /* Init ath dfs pattern detector */
5412 ar->ath_common.debug_mask = ATH_DBG_DFS;
5413 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5414 NL80211_DFS_UNSET);
5415
5416 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005417 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005418 }
5419
Kalle Valo5e3dd152013-06-12 20:52:10 +03005420 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5421 ath10k_reg_notifier);
5422 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005423 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005424 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005425 }
5426
5427 ret = ieee80211_register_hw(ar->hw);
5428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005429 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005430 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005431 }
5432
5433 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5434 ret = regulatory_hint(ar->hw->wiphy,
5435 ar->ath_common.regulatory.alpha2);
5436 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005437 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005438 }
5439
5440 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005441
5442err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005443 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005444err_free:
5445 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5446 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5447
Kalle Valo5e3dd152013-06-12 20:52:10 +03005448 return ret;
5449}
5450
5451void ath10k_mac_unregister(struct ath10k *ar)
5452{
5453 ieee80211_unregister_hw(ar->hw);
5454
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005455 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5456 ar->dfs_detector->exit(ar->dfs_detector);
5457
Kalle Valo5e3dd152013-06-12 20:52:10 +03005458 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5459 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5460
5461 SET_IEEE80211_DEV(ar->hw, NULL);
5462}