blob: e6bc57e2379d5f210d4f13144d63bf70195d311f [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,
Michal Kazior370e5672015-02-18 14:02:26 +010040 const u8 *macaddr, u32 flags)
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,
Michal Kazior370e5672015-02-18 14:02:26 +010048 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 .macaddr = macaddr,
50 };
51
Michal Kazior548db542013-07-05 16:15:15 +030052 lockdep_assert_held(&arvif->ar->conf_mutex);
53
Kalle Valo5e3dd152013-06-12 20:52:10 +030054 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020057 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030058 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +030067 break;
Johannes Berg3cb10942015-01-22 21:38:45 +010068 case WLAN_CIPHER_SUITE_AES_CMAC:
69 /* this one needs to be done in software */
70 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +030071 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020072 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030073 return -EOPNOTSUPP;
74 }
75
76 if (cmd == DISABLE_KEY) {
77 arg.key_cipher = WMI_CIPHER_NONE;
78 arg.key_data = NULL;
79 }
80
81 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
82}
83
84static int ath10k_install_key(struct ath10k_vif *arvif,
85 struct ieee80211_key_conf *key,
86 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +010087 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +030088{
89 struct ath10k *ar = arvif->ar;
90 int ret;
91
Michal Kazior548db542013-07-05 16:15:15 +030092 lockdep_assert_held(&ar->conf_mutex);
93
Wolfram Sang16735d02013-11-14 14:32:02 -080094 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030095
Michal Kazior370e5672015-02-18 14:02:26 +010096 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +030097 if (ret)
98 return ret;
99
100 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
101 if (ret == 0)
102 return -ETIMEDOUT;
103
104 return 0;
105}
106
107static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
108 const u8 *addr)
109{
110 struct ath10k *ar = arvif->ar;
111 struct ath10k_peer *peer;
112 int ret;
113 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100114 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100128
129 flags = 0;
130 flags |= WMI_KEY_PAIRWISE;
131
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200132 /* set TX_USAGE flag for default key id */
133 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100134 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300135
136 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100137 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300138 if (ret)
139 return ret;
140
Sujith Manoharanae167132014-11-25 11:46:59 +0530141 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300142 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530143 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 }
145
146 return 0;
147}
148
149static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
150 const u8 *addr)
151{
152 struct ath10k *ar = arvif->ar;
153 struct ath10k_peer *peer;
154 int first_errno = 0;
155 int ret;
156 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100157 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300158
159 lockdep_assert_held(&ar->conf_mutex);
160
161 spin_lock_bh(&ar->data_lock);
162 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
163 spin_unlock_bh(&ar->data_lock);
164
165 if (!peer)
166 return -ENOENT;
167
168 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
169 if (peer->keys[i] == NULL)
170 continue;
171
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200172 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100174 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300175 if (ret && first_errno == 0)
176 first_errno = ret;
177
178 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200179 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 i, ret);
181
Sujith Manoharanae167132014-11-25 11:46:59 +0530182 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300183 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530184 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 }
186
187 return first_errno;
188}
189
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530190bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
191 u8 keyidx)
192{
193 struct ath10k_peer *peer;
194 int i;
195
196 lockdep_assert_held(&ar->data_lock);
197
198 /* We don't know which vdev this peer belongs to,
199 * since WMI doesn't give us that information.
200 *
201 * FIXME: multi-bss needs to be handled.
202 */
203 peer = ath10k_peer_find(ar, 0, addr);
204 if (!peer)
205 return false;
206
207 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
208 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
209 return true;
210 }
211
212 return false;
213}
214
Kalle Valo5e3dd152013-06-12 20:52:10 +0300215static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
216 struct ieee80211_key_conf *key)
217{
218 struct ath10k *ar = arvif->ar;
219 struct ath10k_peer *peer;
220 u8 addr[ETH_ALEN];
221 int first_errno = 0;
222 int ret;
223 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100224 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225
226 lockdep_assert_held(&ar->conf_mutex);
227
228 for (;;) {
229 /* since ath10k_install_key we can't hold data_lock all the
230 * time, so we try to remove the keys incrementally */
231 spin_lock_bh(&ar->data_lock);
232 i = 0;
233 list_for_each_entry(peer, &ar->peers, list) {
234 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
235 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300236 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300237 peer->keys[i] = NULL;
238 break;
239 }
240 }
241
242 if (i < ARRAY_SIZE(peer->keys))
243 break;
244 }
245 spin_unlock_bh(&ar->data_lock);
246
247 if (i == ARRAY_SIZE(peer->keys))
248 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200249 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100250 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 if (ret && first_errno == 0)
252 first_errno = ret;
253
254 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200255 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200256 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300257 }
258
259 return first_errno;
260}
261
Michal Kazior370e5672015-02-18 14:02:26 +0100262static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
263{
264 struct ath10k *ar = arvif->ar;
265 enum nl80211_iftype iftype = arvif->vif->type;
266 struct ieee80211_key_conf *key;
267 u32 flags = 0;
268 int num = 0;
269 int i;
270 int ret;
271
272 lockdep_assert_held(&ar->conf_mutex);
273
274 if (iftype != NL80211_IFTYPE_STATION)
275 return 0;
276
277 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
278 if (arvif->wep_keys[i]) {
279 key = arvif->wep_keys[i];
280 ++num;
281 }
282 }
283
284 if (num != 1)
285 return 0;
286
287 flags |= WMI_KEY_PAIRWISE;
288 flags |= WMI_KEY_TX_USAGE;
289
290 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
291 if (ret) {
292 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
293 key->keyidx, arvif->vdev_id, ret);
294 return ret;
295 }
296
297 return 0;
298}
299
Michal Kaziorad325cb2015-02-18 14:02:27 +0100300static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
301 struct ieee80211_key_conf *key)
302{
303 struct ath10k *ar = arvif->ar;
304 struct ath10k_peer *peer;
305 int ret;
306
307 lockdep_assert_held(&ar->conf_mutex);
308
309 list_for_each_entry(peer, &ar->peers, list) {
310 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
311 continue;
312
313 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
314 continue;
315
316 if (peer->keys[key->keyidx] == key)
317 continue;
318
319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
320 arvif->vdev_id, key->keyidx);
321
322 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
323 if (ret) {
324 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
325 arvif->vdev_id, peer->addr, ret);
326 return ret;
327 }
328 }
329
330 return 0;
331}
332
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333/*********************/
334/* General utilities */
335/*********************/
336
337static inline enum wmi_phy_mode
338chan_to_phymode(const struct cfg80211_chan_def *chandef)
339{
340 enum wmi_phy_mode phymode = MODE_UNKNOWN;
341
342 switch (chandef->chan->band) {
343 case IEEE80211_BAND_2GHZ:
344 switch (chandef->width) {
345 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800346 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
347 phymode = MODE_11B;
348 else
349 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300350 break;
351 case NL80211_CHAN_WIDTH_20:
352 phymode = MODE_11NG_HT20;
353 break;
354 case NL80211_CHAN_WIDTH_40:
355 phymode = MODE_11NG_HT40;
356 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400357 case NL80211_CHAN_WIDTH_5:
358 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300359 case NL80211_CHAN_WIDTH_80:
360 case NL80211_CHAN_WIDTH_80P80:
361 case NL80211_CHAN_WIDTH_160:
362 phymode = MODE_UNKNOWN;
363 break;
364 }
365 break;
366 case IEEE80211_BAND_5GHZ:
367 switch (chandef->width) {
368 case NL80211_CHAN_WIDTH_20_NOHT:
369 phymode = MODE_11A;
370 break;
371 case NL80211_CHAN_WIDTH_20:
372 phymode = MODE_11NA_HT20;
373 break;
374 case NL80211_CHAN_WIDTH_40:
375 phymode = MODE_11NA_HT40;
376 break;
377 case NL80211_CHAN_WIDTH_80:
378 phymode = MODE_11AC_VHT80;
379 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400380 case NL80211_CHAN_WIDTH_5:
381 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300382 case NL80211_CHAN_WIDTH_80P80:
383 case NL80211_CHAN_WIDTH_160:
384 phymode = MODE_UNKNOWN;
385 break;
386 }
387 break;
388 default:
389 break;
390 }
391
392 WARN_ON(phymode == MODE_UNKNOWN);
393 return phymode;
394}
395
396static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
397{
398/*
399 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
400 * 0 for no restriction
401 * 1 for 1/4 us
402 * 2 for 1/2 us
403 * 3 for 1 us
404 * 4 for 2 us
405 * 5 for 4 us
406 * 6 for 8 us
407 * 7 for 16 us
408 */
409 switch (mpdudensity) {
410 case 0:
411 return 0;
412 case 1:
413 case 2:
414 case 3:
415 /* Our lower layer calculations limit our precision to
416 1 microsecond */
417 return 1;
418 case 4:
419 return 2;
420 case 5:
421 return 4;
422 case 6:
423 return 8;
424 case 7:
425 return 16;
426 default:
427 return 0;
428 }
429}
430
431static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
432{
433 int ret;
434
435 lockdep_assert_held(&ar->conf_mutex);
436
Michal Kaziorcfd10612014-11-25 15:16:05 +0100437 if (ar->num_peers >= ar->max_num_peers)
438 return -ENOBUFS;
439
Kalle Valo5e3dd152013-06-12 20:52:10 +0300440 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800441 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200442 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200443 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300444 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800445 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300446
447 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800448 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200449 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200450 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300451 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800452 }
Michal Kazior292a7532014-11-25 15:16:04 +0100453
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100454 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300455
456 return 0;
457}
458
Kalle Valo5a13e762014-01-20 11:01:46 +0200459static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
460{
461 struct ath10k *ar = arvif->ar;
462 u32 param;
463 int ret;
464
465 param = ar->wmi.pdev_param->sta_kickout_th;
466 ret = ath10k_wmi_pdev_set_param(ar, param,
467 ATH10K_KICKOUT_THRESHOLD);
468 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200469 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200470 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200471 return ret;
472 }
473
474 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
475 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
476 ATH10K_KEEPALIVE_MIN_IDLE);
477 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200478 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200479 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200480 return ret;
481 }
482
483 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
484 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
485 ATH10K_KEEPALIVE_MAX_IDLE);
486 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200487 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200488 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200489 return ret;
490 }
491
492 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
493 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
494 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
495 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200496 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200497 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200498 return ret;
499 }
500
501 return 0;
502}
503
Vivek Natarajanacab6402014-11-26 09:06:12 +0200504static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200505{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200506 struct ath10k *ar = arvif->ar;
507 u32 vdev_param;
508
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200509 vdev_param = ar->wmi.vdev_param->rts_threshold;
510 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200511}
512
513static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
514{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200515 struct ath10k *ar = arvif->ar;
516 u32 vdev_param;
517
Michal Kazior424121c2013-07-22 14:13:31 +0200518 if (value != 0xFFFFFFFF)
519 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
520 ATH10K_FRAGMT_THRESHOLD_MIN,
521 ATH10K_FRAGMT_THRESHOLD_MAX);
522
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200523 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
524 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200525}
526
Kalle Valo5e3dd152013-06-12 20:52:10 +0300527static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
528{
529 int ret;
530
531 lockdep_assert_held(&ar->conf_mutex);
532
533 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
534 if (ret)
535 return ret;
536
537 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
538 if (ret)
539 return ret;
540
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100541 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100542
Kalle Valo5e3dd152013-06-12 20:52:10 +0300543 return 0;
544}
545
546static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
547{
548 struct ath10k_peer *peer, *tmp;
549
550 lockdep_assert_held(&ar->conf_mutex);
551
552 spin_lock_bh(&ar->data_lock);
553 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
554 if (peer->vdev_id != vdev_id)
555 continue;
556
Michal Kazior7aa7a722014-08-25 12:09:38 +0200557 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558 peer->addr, vdev_id);
559
560 list_del(&peer->list);
561 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100562 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563 }
564 spin_unlock_bh(&ar->data_lock);
565}
566
Michal Kaziora96d7742013-07-16 09:38:56 +0200567static void ath10k_peer_cleanup_all(struct ath10k *ar)
568{
569 struct ath10k_peer *peer, *tmp;
570
571 lockdep_assert_held(&ar->conf_mutex);
572
573 spin_lock_bh(&ar->data_lock);
574 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
575 list_del(&peer->list);
576 kfree(peer);
577 }
578 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100579
580 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100581 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200582}
583
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584/************************/
585/* Interface management */
586/************************/
587
Michal Kazior64badcb2014-09-18 11:18:02 +0300588void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
589{
590 struct ath10k *ar = arvif->ar;
591
592 lockdep_assert_held(&ar->data_lock);
593
594 if (!arvif->beacon)
595 return;
596
597 if (!arvif->beacon_buf)
598 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
599 arvif->beacon->len, DMA_TO_DEVICE);
600
Michal Kazioraf213192015-01-29 14:29:52 +0200601 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
602 arvif->beacon_state != ATH10K_BEACON_SENT))
603 return;
604
Michal Kazior64badcb2014-09-18 11:18:02 +0300605 dev_kfree_skb_any(arvif->beacon);
606
607 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200608 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300609}
610
611static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
612{
613 struct ath10k *ar = arvif->ar;
614
615 lockdep_assert_held(&ar->data_lock);
616
617 ath10k_mac_vif_beacon_free(arvif);
618
619 if (arvif->beacon_buf) {
620 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
621 arvif->beacon_buf, arvif->beacon_paddr);
622 arvif->beacon_buf = NULL;
623 }
624}
625
Kalle Valo5e3dd152013-06-12 20:52:10 +0300626static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
627{
628 int ret;
629
Michal Kazior548db542013-07-05 16:15:15 +0300630 lockdep_assert_held(&ar->conf_mutex);
631
Michal Kazior7962b0d2014-10-28 10:34:38 +0100632 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
633 return -ESHUTDOWN;
634
Kalle Valo5e3dd152013-06-12 20:52:10 +0300635 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
636 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
637 if (ret == 0)
638 return -ETIMEDOUT;
639
640 return 0;
641}
642
Michal Kazior1bbc0972014-04-08 09:45:47 +0300643static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300644{
Michal Kaziorc930f742014-01-23 11:38:25 +0100645 struct cfg80211_chan_def *chandef = &ar->chandef;
646 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300647 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648 int ret = 0;
649
650 lockdep_assert_held(&ar->conf_mutex);
651
Kalle Valo5e3dd152013-06-12 20:52:10 +0300652 arg.vdev_id = vdev_id;
653 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100654 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655
656 /* TODO setup this dynamically, what in case we
657 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100658 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200659 arg.channel.chan_radar =
660 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300661
Michal Kazior89c5c842013-10-23 04:02:13 -0700662 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700663 arg.channel.max_power = channel->max_power * 2;
664 arg.channel.max_reg_power = channel->max_reg_power * 2;
665 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666
Michal Kazior7962b0d2014-10-28 10:34:38 +0100667 reinit_completion(&ar->vdev_setup_done);
668
Kalle Valo5e3dd152013-06-12 20:52:10 +0300669 ret = ath10k_wmi_vdev_start(ar, &arg);
670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200671 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200672 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300673 return ret;
674 }
675
676 ret = ath10k_vdev_setup_sync(ar);
677 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200678 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200679 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680 return ret;
681 }
682
683 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200685 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200686 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300687 goto vdev_stop;
688 }
689
690 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300691
Michal Kazior7aa7a722014-08-25 12:09:38 +0200692 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300693 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 return 0;
695
696vdev_stop:
697 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
698 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200699 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200700 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300701
702 return ret;
703}
704
Michal Kazior1bbc0972014-04-08 09:45:47 +0300705static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300706{
707 int ret = 0;
708
709 lockdep_assert_held(&ar->conf_mutex);
710
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200711 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
712 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200713 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200714 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300715
Michal Kazior7962b0d2014-10-28 10:34:38 +0100716 reinit_completion(&ar->vdev_setup_done);
717
Kalle Valo5e3dd152013-06-12 20:52:10 +0300718 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200720 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200721 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300722
723 ret = ath10k_vdev_setup_sync(ar);
724 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200725 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200726 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300727
Michal Kazior7aa7a722014-08-25 12:09:38 +0200728 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300729 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300730 return ret;
731}
732
Michal Kazior1bbc0972014-04-08 09:45:47 +0300733static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300734{
735 int bit, ret = 0;
736
737 lockdep_assert_held(&ar->conf_mutex);
738
Ben Greeara9aefb32014-08-12 11:02:19 +0300739 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200740 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300741 return -ENOMEM;
742 }
743
Ben Greear16c11172014-09-23 14:17:16 -0700744 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300745
Ben Greear16c11172014-09-23 14:17:16 -0700746 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300747
748 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
749 WMI_VDEV_TYPE_MONITOR,
750 0, ar->mac_addr);
751 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200752 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200753 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300754 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300755 }
756
Ben Greear16c11172014-09-23 14:17:16 -0700757 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200758 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300759 ar->monitor_vdev_id);
760
Kalle Valo5e3dd152013-06-12 20:52:10 +0300761 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300762}
763
Michal Kazior1bbc0972014-04-08 09:45:47 +0300764static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300765{
766 int ret = 0;
767
768 lockdep_assert_held(&ar->conf_mutex);
769
Kalle Valo5e3dd152013-06-12 20:52:10 +0300770 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200772 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200773 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300774 return ret;
775 }
776
Ben Greear16c11172014-09-23 14:17:16 -0700777 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300778
Michal Kazior7aa7a722014-08-25 12:09:38 +0200779 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300780 ar->monitor_vdev_id);
781 return ret;
782}
783
Michal Kazior1bbc0972014-04-08 09:45:47 +0300784static int ath10k_monitor_start(struct ath10k *ar)
785{
786 int ret;
787
788 lockdep_assert_held(&ar->conf_mutex);
789
Michal Kazior1bbc0972014-04-08 09:45:47 +0300790 ret = ath10k_monitor_vdev_create(ar);
791 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200792 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300793 return ret;
794 }
795
796 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
797 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200798 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300799 ath10k_monitor_vdev_delete(ar);
800 return ret;
801 }
802
803 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200804 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300805
806 return 0;
807}
808
Michal Kazior19337472014-08-28 12:58:16 +0200809static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300810{
811 int ret;
812
813 lockdep_assert_held(&ar->conf_mutex);
814
Michal Kazior1bbc0972014-04-08 09:45:47 +0300815 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200816 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200817 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200818 return ret;
819 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300820
821 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200822 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200823 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200824 return ret;
825 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300826
827 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200829
830 return 0;
831}
832
833static int ath10k_monitor_recalc(struct ath10k *ar)
834{
835 bool should_start;
836
837 lockdep_assert_held(&ar->conf_mutex);
838
839 should_start = ar->monitor ||
840 ar->filter_flags & FIF_PROMISC_IN_BSS ||
841 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
842
843 ath10k_dbg(ar, ATH10K_DBG_MAC,
844 "mac monitor recalc started? %d should? %d\n",
845 ar->monitor_started, should_start);
846
847 if (should_start == ar->monitor_started)
848 return 0;
849
850 if (should_start)
851 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300852
853 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300854}
855
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200856static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
857{
858 struct ath10k *ar = arvif->ar;
859 u32 vdev_param, rts_cts = 0;
860
861 lockdep_assert_held(&ar->conf_mutex);
862
863 vdev_param = ar->wmi.vdev_param->enable_rtscts;
864
865 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
866 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
867
868 if (arvif->num_legacy_stations > 0)
869 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
870 WMI_RTSCTS_PROFILE);
871
872 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
873 rts_cts);
874}
875
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200876static int ath10k_start_cac(struct ath10k *ar)
877{
878 int ret;
879
880 lockdep_assert_held(&ar->conf_mutex);
881
882 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
883
Michal Kazior19337472014-08-28 12:58:16 +0200884 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200886 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200887 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
888 return ret;
889 }
890
Michal Kazior7aa7a722014-08-25 12:09:38 +0200891 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200892 ar->monitor_vdev_id);
893
894 return 0;
895}
896
897static int ath10k_stop_cac(struct ath10k *ar)
898{
899 lockdep_assert_held(&ar->conf_mutex);
900
901 /* CAC is not running - do nothing */
902 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
903 return 0;
904
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200905 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300906 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200907
Michal Kazior7aa7a722014-08-25 12:09:38 +0200908 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200909
910 return 0;
911}
912
Michal Kaziord6500972014-04-08 09:56:09 +0300913static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200914{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200915 int ret;
916
917 lockdep_assert_held(&ar->conf_mutex);
918
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200919 ath10k_stop_cac(ar);
920
Michal Kaziord6500972014-04-08 09:56:09 +0300921 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200922 return;
923
Michal Kaziord6500972014-04-08 09:56:09 +0300924 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200925 return;
926
927 ret = ath10k_start_cac(ar);
928 if (ret) {
929 /*
930 * Not possible to start CAC on current channel so starting
931 * radiation is not allowed, make this channel DFS_UNAVAILABLE
932 * by indicating that radar was detected.
933 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200934 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200935 ieee80211_radar_detected(ar->hw);
936 }
937}
938
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +0530939static int ath10k_vdev_stop(struct ath10k_vif *arvif)
940{
941 struct ath10k *ar = arvif->ar;
942 int ret;
943
944 lockdep_assert_held(&ar->conf_mutex);
945
946 reinit_completion(&ar->vdev_setup_done);
947
948 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
949 if (ret) {
950 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
951 arvif->vdev_id, ret);
952 return ret;
953 }
954
955 ret = ath10k_vdev_setup_sync(ar);
956 if (ret) {
957 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
958 arvif->vdev_id, ret);
959 return ret;
960 }
961
962 WARN_ON(ar->num_started_vdevs == 0);
963
964 if (ar->num_started_vdevs != 0) {
965 ar->num_started_vdevs--;
966 ath10k_recalc_radar_detection(ar);
967 }
968
969 return ret;
970}
971
Michal Kaziordc55e302014-07-29 12:53:36 +0300972static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300973{
974 struct ath10k *ar = arvif->ar;
975 struct cfg80211_chan_def *chandef = &ar->chandef;
976 struct wmi_vdev_start_request_arg arg = {};
977 int ret = 0;
978
979 lockdep_assert_held(&ar->conf_mutex);
980
981 reinit_completion(&ar->vdev_setup_done);
982
983 arg.vdev_id = arvif->vdev_id;
984 arg.dtim_period = arvif->dtim_period;
985 arg.bcn_intval = arvif->beacon_interval;
986
987 arg.channel.freq = chandef->chan->center_freq;
988 arg.channel.band_center_freq1 = chandef->center_freq1;
989 arg.channel.mode = chan_to_phymode(chandef);
990
991 arg.channel.min_power = 0;
992 arg.channel.max_power = chandef->chan->max_power * 2;
993 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
994 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
995
996 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
997 arg.ssid = arvif->u.ap.ssid;
998 arg.ssid_len = arvif->u.ap.ssid_len;
999 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1000
1001 /* For now allow DFS for AP mode */
1002 arg.channel.chan_radar =
1003 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1004 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1005 arg.ssid = arvif->vif->bss_conf.ssid;
1006 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1007 }
1008
Michal Kazior7aa7a722014-08-25 12:09:38 +02001009 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001010 "mac vdev %d start center_freq %d phymode %s\n",
1011 arg.vdev_id, arg.channel.freq,
1012 ath10k_wmi_phymode_str(arg.channel.mode));
1013
Michal Kaziordc55e302014-07-29 12:53:36 +03001014 if (restart)
1015 ret = ath10k_wmi_vdev_restart(ar, &arg);
1016 else
1017 ret = ath10k_wmi_vdev_start(ar, &arg);
1018
Michal Kazior72654fa2014-04-08 09:56:09 +03001019 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001020 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001021 arg.vdev_id, ret);
1022 return ret;
1023 }
1024
1025 ret = ath10k_vdev_setup_sync(ar);
1026 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001027 ath10k_warn(ar,
1028 "failed to synchronize setup for vdev %i restart %d: %d\n",
1029 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001030 return ret;
1031 }
1032
Michal Kaziord6500972014-04-08 09:56:09 +03001033 ar->num_started_vdevs++;
1034 ath10k_recalc_radar_detection(ar);
1035
Michal Kazior72654fa2014-04-08 09:56:09 +03001036 return ret;
1037}
1038
Michal Kaziordc55e302014-07-29 12:53:36 +03001039static int ath10k_vdev_start(struct ath10k_vif *arvif)
1040{
1041 return ath10k_vdev_start_restart(arvif, false);
1042}
1043
1044static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1045{
1046 return ath10k_vdev_start_restart(arvif, true);
1047}
1048
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001049static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1050 struct sk_buff *bcn)
1051{
1052 struct ath10k *ar = arvif->ar;
1053 struct ieee80211_mgmt *mgmt;
1054 const u8 *p2p_ie;
1055 int ret;
1056
1057 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1058 return 0;
1059
1060 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1061 return 0;
1062
1063 mgmt = (void *)bcn->data;
1064 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1065 mgmt->u.beacon.variable,
1066 bcn->len - (mgmt->u.beacon.variable -
1067 bcn->data));
1068 if (!p2p_ie)
1069 return -ENOENT;
1070
1071 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1072 if (ret) {
1073 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1074 arvif->vdev_id, ret);
1075 return ret;
1076 }
1077
1078 return 0;
1079}
1080
1081static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1082 u8 oui_type, size_t ie_offset)
1083{
1084 size_t len;
1085 const u8 *next;
1086 const u8 *end;
1087 u8 *ie;
1088
1089 if (WARN_ON(skb->len < ie_offset))
1090 return -EINVAL;
1091
1092 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1093 skb->data + ie_offset,
1094 skb->len - ie_offset);
1095 if (!ie)
1096 return -ENOENT;
1097
1098 len = ie[1] + 2;
1099 end = skb->data + skb->len;
1100 next = ie + len;
1101
1102 if (WARN_ON(next > end))
1103 return -EINVAL;
1104
1105 memmove(ie, next, end - next);
1106 skb_trim(skb, skb->len - len);
1107
1108 return 0;
1109}
1110
1111static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1112{
1113 struct ath10k *ar = arvif->ar;
1114 struct ieee80211_hw *hw = ar->hw;
1115 struct ieee80211_vif *vif = arvif->vif;
1116 struct ieee80211_mutable_offsets offs = {};
1117 struct sk_buff *bcn;
1118 int ret;
1119
1120 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1121 return 0;
1122
Michal Kazior81a9a172015-03-05 16:02:17 +02001123 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1124 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1125 return 0;
1126
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001127 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1128 if (!bcn) {
1129 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1130 return -EPERM;
1131 }
1132
1133 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1134 if (ret) {
1135 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1136 kfree_skb(bcn);
1137 return ret;
1138 }
1139
1140 /* P2P IE is inserted by firmware automatically (as configured above)
1141 * so remove it from the base beacon template to avoid duplicate P2P
1142 * IEs in beacon frames.
1143 */
1144 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1145 offsetof(struct ieee80211_mgmt,
1146 u.beacon.variable));
1147
1148 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1149 0, NULL, 0);
1150 kfree_skb(bcn);
1151
1152 if (ret) {
1153 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1154 ret);
1155 return ret;
1156 }
1157
1158 return 0;
1159}
1160
1161static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1162{
1163 struct ath10k *ar = arvif->ar;
1164 struct ieee80211_hw *hw = ar->hw;
1165 struct ieee80211_vif *vif = arvif->vif;
1166 struct sk_buff *prb;
1167 int ret;
1168
1169 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1170 return 0;
1171
Michal Kazior81a9a172015-03-05 16:02:17 +02001172 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1173 return 0;
1174
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001175 prb = ieee80211_proberesp_get(hw, vif);
1176 if (!prb) {
1177 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1178 return -EPERM;
1179 }
1180
1181 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1182 kfree_skb(prb);
1183
1184 if (ret) {
1185 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1186 ret);
1187 return ret;
1188 }
1189
1190 return 0;
1191}
1192
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001194 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001196 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197 int ret = 0;
1198
Michal Kazior548db542013-07-05 16:15:15 +03001199 lockdep_assert_held(&arvif->ar->conf_mutex);
1200
Kalle Valo5e3dd152013-06-12 20:52:10 +03001201 if (!info->enable_beacon) {
1202 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001203
Michal Kazior81a9a172015-03-05 16:02:17 +02001204 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01001205 arvif->is_started = false;
1206 arvif->is_up = false;
Michal Kazior64badcb2014-09-18 11:18:02 +03001207 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001208 spin_unlock_bh(&arvif->ar->data_lock);
1209
Kalle Valo5e3dd152013-06-12 20:52:10 +03001210 return;
1211 }
1212
1213 arvif->tx_seq_no = 0x1000;
1214
1215 ret = ath10k_vdev_start(arvif);
1216 if (ret)
1217 return;
1218
Michal Kaziorc930f742014-01-23 11:38:25 +01001219 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001220 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001221
1222 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1223 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001224 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001225 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001226 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001227 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228 return;
1229 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001230
1231 arvif->is_started = true;
1232 arvif->is_up = true;
1233
Michal Kazior7aa7a722014-08-25 12:09:38 +02001234 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001235}
1236
1237static void ath10k_control_ibss(struct ath10k_vif *arvif,
1238 struct ieee80211_bss_conf *info,
1239 const u8 self_peer[ETH_ALEN])
1240{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001241 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001242 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001243 int ret = 0;
1244
Michal Kazior548db542013-07-05 16:15:15 +03001245 lockdep_assert_held(&arvif->ar->conf_mutex);
1246
Kalle Valo5e3dd152013-06-12 20:52:10 +03001247 if (!info->ibss_joined) {
1248 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1249 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001250 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001251 self_peer, arvif->vdev_id, ret);
1252
Michal Kaziorc930f742014-01-23 11:38:25 +01001253 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001254 return;
1255
Michal Kaziorc930f742014-01-23 11:38:25 +01001256 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001257
1258 return;
1259 }
1260
1261 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1262 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001263 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001264 self_peer, arvif->vdev_id, ret);
1265 return;
1266 }
1267
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001268 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1269 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270 ATH10K_DEFAULT_ATIM);
1271 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001272 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001273 arvif->vdev_id, ret);
1274}
1275
Michal Kazior9f9b5742014-12-12 12:41:36 +01001276static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1277{
1278 struct ath10k *ar = arvif->ar;
1279 u32 param;
1280 u32 value;
1281 int ret;
1282
1283 lockdep_assert_held(&arvif->ar->conf_mutex);
1284
1285 if (arvif->u.sta.uapsd)
1286 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1287 else
1288 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1289
1290 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1291 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1292 if (ret) {
1293 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1294 value, arvif->vdev_id, ret);
1295 return ret;
1296 }
1297
1298 return 0;
1299}
1300
1301static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1302{
1303 struct ath10k *ar = arvif->ar;
1304 u32 param;
1305 u32 value;
1306 int ret;
1307
1308 lockdep_assert_held(&arvif->ar->conf_mutex);
1309
1310 if (arvif->u.sta.uapsd)
1311 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1312 else
1313 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1314
1315 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1316 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1317 param, value);
1318 if (ret) {
1319 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1320 value, arvif->vdev_id, ret);
1321 return ret;
1322 }
1323
1324 return 0;
1325}
1326
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001327static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1328{
1329 struct ath10k_vif *arvif;
1330 int num = 0;
1331
1332 lockdep_assert_held(&ar->conf_mutex);
1333
1334 list_for_each_entry(arvif, &ar->arvifs, list)
1335 if (arvif->ps)
1336 num++;
1337
1338 return num;
1339}
1340
Michal Kaziorad088bf2013-10-16 15:44:46 +03001341static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001342{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001343 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001344 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001345 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001346 enum wmi_sta_powersave_param param;
1347 enum wmi_sta_ps_mode psmode;
1348 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001349 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001350 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001351
Michal Kazior548db542013-07-05 16:15:15 +03001352 lockdep_assert_held(&arvif->ar->conf_mutex);
1353
Michal Kaziorad088bf2013-10-16 15:44:46 +03001354 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1355 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001357 enable_ps = arvif->ps;
1358
1359 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1360 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1361 ar->fw_features)) {
1362 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1363 arvif->vdev_id);
1364 enable_ps = false;
1365 }
1366
1367 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368 psmode = WMI_STA_PS_MODE_ENABLED;
1369 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1370
Michal Kazior526549a2014-12-12 12:41:37 +01001371 ps_timeout = conf->dynamic_ps_timeout;
1372 if (ps_timeout == 0) {
1373 /* Firmware doesn't like 0 */
1374 ps_timeout = ieee80211_tu_to_usec(
1375 vif->bss_conf.beacon_int) / 1000;
1376 }
1377
Michal Kaziorad088bf2013-10-16 15:44:46 +03001378 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001379 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001380 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001381 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001382 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001383 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 } else {
1386 psmode = WMI_STA_PS_MODE_DISABLED;
1387 }
1388
Michal Kazior7aa7a722014-08-25 12:09:38 +02001389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001390 arvif->vdev_id, psmode ? "enable" : "disable");
1391
Michal Kaziorad088bf2013-10-16 15:44:46 +03001392 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1393 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001394 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001395 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001396 return ret;
1397 }
1398
1399 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001400}
1401
Michal Kazior46725b152015-01-28 09:57:49 +02001402static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1403{
1404 struct ath10k *ar = arvif->ar;
1405 struct wmi_sta_keepalive_arg arg = {};
1406 int ret;
1407
1408 lockdep_assert_held(&arvif->ar->conf_mutex);
1409
1410 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1411 return 0;
1412
1413 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1414 return 0;
1415
1416 /* Some firmware revisions have a bug and ignore the `enabled` field.
1417 * Instead use the interval to disable the keepalive.
1418 */
1419 arg.vdev_id = arvif->vdev_id;
1420 arg.enabled = 1;
1421 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1422 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1423
1424 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1425 if (ret) {
1426 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1427 arvif->vdev_id, ret);
1428 return ret;
1429 }
1430
1431 return 0;
1432}
1433
Michal Kazior81a9a172015-03-05 16:02:17 +02001434static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1435{
1436 struct ath10k *ar = arvif->ar;
1437 struct ieee80211_vif *vif = arvif->vif;
1438 int ret;
1439
1440 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1441 return;
1442
1443 if (!vif->csa_active)
1444 return;
1445
1446 if (!arvif->is_up)
1447 return;
1448
1449 if (!ieee80211_csa_is_complete(vif)) {
1450 ieee80211_csa_update_counter(vif);
1451
1452 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1453 if (ret)
1454 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1455 ret);
1456
1457 ret = ath10k_mac_setup_prb_tmpl(arvif);
1458 if (ret)
1459 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1460 ret);
1461 } else {
1462 ieee80211_csa_finish(vif);
1463 }
1464}
1465
1466static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1467{
1468 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1469 ap_csa_work);
1470 struct ath10k *ar = arvif->ar;
1471
1472 mutex_lock(&ar->conf_mutex);
1473 ath10k_mac_vif_ap_csa_count_down(arvif);
1474 mutex_unlock(&ar->conf_mutex);
1475}
1476
Kalle Valo5e3dd152013-06-12 20:52:10 +03001477/**********************/
1478/* Station management */
1479/**********************/
1480
Michal Kazior590922a2014-10-21 10:10:29 +03001481static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1482 struct ieee80211_vif *vif)
1483{
1484 /* Some firmware revisions have unstable STA powersave when listen
1485 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1486 * generate NullFunc frames properly even if buffered frames have been
1487 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1488 * buffered frames. Often pinging the device from AP would simply fail.
1489 *
1490 * As a workaround set it to 1.
1491 */
1492 if (vif->type == NL80211_IFTYPE_STATION)
1493 return 1;
1494
1495 return ar->hw->conf.listen_interval;
1496}
1497
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001499 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001500 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001501 struct wmi_peer_assoc_complete_arg *arg)
1502{
Michal Kazior590922a2014-10-21 10:10:29 +03001503 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1504
Michal Kazior548db542013-07-05 16:15:15 +03001505 lockdep_assert_held(&ar->conf_mutex);
1506
Kalle Valob25f32c2014-09-14 12:50:49 +03001507 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001508 arg->vdev_id = arvif->vdev_id;
1509 arg->peer_aid = sta->aid;
1510 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001511 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001512 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001513 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001514}
1515
1516static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001517 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518 struct wmi_peer_assoc_complete_arg *arg)
1519{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001520 struct ieee80211_bss_conf *info = &vif->bss_conf;
1521 struct cfg80211_bss *bss;
1522 const u8 *rsnie = NULL;
1523 const u8 *wpaie = NULL;
1524
Michal Kazior548db542013-07-05 16:15:15 +03001525 lockdep_assert_held(&ar->conf_mutex);
1526
Kalle Valo5e3dd152013-06-12 20:52:10 +03001527 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1528 info->bssid, NULL, 0, 0, 0);
1529 if (bss) {
1530 const struct cfg80211_bss_ies *ies;
1531
1532 rcu_read_lock();
1533 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1534
1535 ies = rcu_dereference(bss->ies);
1536
1537 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001538 WLAN_OUI_TYPE_MICROSOFT_WPA,
1539 ies->data,
1540 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001541 rcu_read_unlock();
1542 cfg80211_put_bss(ar->hw->wiphy, bss);
1543 }
1544
1545 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1546 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001547 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1549 }
1550
1551 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001552 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1554 }
1555}
1556
1557static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1558 struct ieee80211_sta *sta,
1559 struct wmi_peer_assoc_complete_arg *arg)
1560{
1561 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1562 const struct ieee80211_supported_band *sband;
1563 const struct ieee80211_rate *rates;
1564 u32 ratemask;
1565 int i;
1566
Michal Kazior548db542013-07-05 16:15:15 +03001567 lockdep_assert_held(&ar->conf_mutex);
1568
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1570 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1571 rates = sband->bitrates;
1572
1573 rateset->num_rates = 0;
1574
1575 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1576 if (!(ratemask & 1))
1577 continue;
1578
1579 rateset->rates[rateset->num_rates] = rates->hw_value;
1580 rateset->num_rates++;
1581 }
1582}
1583
1584static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1585 struct ieee80211_sta *sta,
1586 struct wmi_peer_assoc_complete_arg *arg)
1587{
1588 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001589 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001590 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591
Michal Kazior548db542013-07-05 16:15:15 +03001592 lockdep_assert_held(&ar->conf_mutex);
1593
Kalle Valo5e3dd152013-06-12 20:52:10 +03001594 if (!ht_cap->ht_supported)
1595 return;
1596
1597 arg->peer_flags |= WMI_PEER_HT;
1598 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1599 ht_cap->ampdu_factor)) - 1;
1600
1601 arg->peer_mpdu_density =
1602 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1603
1604 arg->peer_ht_caps = ht_cap->cap;
1605 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1606
1607 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1608 arg->peer_flags |= WMI_PEER_LDPC;
1609
1610 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1611 arg->peer_flags |= WMI_PEER_40MHZ;
1612 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1613 }
1614
1615 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1616 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1617
1618 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1619 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1620
1621 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1622 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1623 arg->peer_flags |= WMI_PEER_STBC;
1624 }
1625
1626 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1628 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1629 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1630 arg->peer_rate_caps |= stbc;
1631 arg->peer_flags |= WMI_PEER_STBC;
1632 }
1633
Kalle Valo5e3dd152013-06-12 20:52:10 +03001634 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1635 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1636 else if (ht_cap->mcs.rx_mask[1])
1637 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1638
1639 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1640 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1641 arg->peer_ht_rates.rates[n++] = i;
1642
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001643 /*
1644 * This is a workaround for HT-enabled STAs which break the spec
1645 * and have no HT capabilities RX mask (no HT RX MCS map).
1646 *
1647 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1648 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1649 *
1650 * Firmware asserts if such situation occurs.
1651 */
1652 if (n == 0) {
1653 arg->peer_ht_rates.num_rates = 8;
1654 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1655 arg->peer_ht_rates.rates[i] = i;
1656 } else {
1657 arg->peer_ht_rates.num_rates = n;
1658 arg->peer_num_spatial_streams = sta->rx_nss;
1659 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001660
Michal Kazior7aa7a722014-08-25 12:09:38 +02001661 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001662 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001663 arg->peer_ht_rates.num_rates,
1664 arg->peer_num_spatial_streams);
1665}
1666
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001667static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1668 struct ath10k_vif *arvif,
1669 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001670{
1671 u32 uapsd = 0;
1672 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001673 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001674
Michal Kazior548db542013-07-05 16:15:15 +03001675 lockdep_assert_held(&ar->conf_mutex);
1676
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001678 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001679 sta->uapsd_queues, sta->max_sp);
1680
Kalle Valo5e3dd152013-06-12 20:52:10 +03001681 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1682 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1683 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1684 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1685 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1686 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1687 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1688 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1689 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1690 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1691 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1692 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1693
Kalle Valo5e3dd152013-06-12 20:52:10 +03001694 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1695 max_sp = sta->max_sp;
1696
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001697 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1698 sta->addr,
1699 WMI_AP_PS_PEER_PARAM_UAPSD,
1700 uapsd);
1701 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001702 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001703 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001704 return ret;
1705 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001706
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001707 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1708 sta->addr,
1709 WMI_AP_PS_PEER_PARAM_MAX_SP,
1710 max_sp);
1711 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001712 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001713 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001714 return ret;
1715 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716
1717 /* TODO setup this based on STA listen interval and
1718 beacon interval. Currently we don't know
1719 sta->listen_interval - mac80211 patch required.
1720 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001721 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001722 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1723 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001724 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001725 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001726 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001727 return ret;
1728 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001731 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001732}
1733
1734static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1735 struct ieee80211_sta *sta,
1736 struct wmi_peer_assoc_complete_arg *arg)
1737{
1738 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001739 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001740
1741 if (!vht_cap->vht_supported)
1742 return;
1743
1744 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001745
1746 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1747 arg->peer_flags |= WMI_PEER_VHT_2G;
1748
Kalle Valo5e3dd152013-06-12 20:52:10 +03001749 arg->peer_vht_caps = vht_cap->cap;
1750
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001751 ampdu_factor = (vht_cap->cap &
1752 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1753 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1754
1755 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1756 * zero in VHT IE. Using it would result in degraded throughput.
1757 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1758 * it if VHT max_mpdu is smaller. */
1759 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1760 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1761 ampdu_factor)) - 1);
1762
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1764 arg->peer_flags |= WMI_PEER_80MHZ;
1765
1766 arg->peer_vht_rates.rx_max_rate =
1767 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1768 arg->peer_vht_rates.rx_mcs_set =
1769 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1770 arg->peer_vht_rates.tx_max_rate =
1771 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1772 arg->peer_vht_rates.tx_mcs_set =
1773 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1774
Michal Kazior7aa7a722014-08-25 12:09:38 +02001775 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001776 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001777}
1778
1779static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001780 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001782 struct wmi_peer_assoc_complete_arg *arg)
1783{
Michal Kazior590922a2014-10-21 10:10:29 +03001784 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1785
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786 switch (arvif->vdev_type) {
1787 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001788 if (sta->wme)
1789 arg->peer_flags |= WMI_PEER_QOS;
1790
1791 if (sta->wme && sta->uapsd_queues) {
1792 arg->peer_flags |= WMI_PEER_APSD;
1793 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1794 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001795 break;
1796 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001797 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001798 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001799 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001800 case WMI_VDEV_TYPE_IBSS:
1801 if (sta->wme)
1802 arg->peer_flags |= WMI_PEER_QOS;
1803 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001804 default:
1805 break;
1806 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001807
1808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1809 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810}
1811
Michal Kazior91b12082014-12-12 12:41:35 +01001812static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1813{
1814 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1815 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1816}
1817
Kalle Valo5e3dd152013-06-12 20:52:10 +03001818static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001819 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001820 struct ieee80211_sta *sta,
1821 struct wmi_peer_assoc_complete_arg *arg)
1822{
1823 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1824
Kalle Valo5e3dd152013-06-12 20:52:10 +03001825 switch (ar->hw->conf.chandef.chan->band) {
1826 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001827 if (sta->vht_cap.vht_supported) {
1828 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1829 phymode = MODE_11AC_VHT40;
1830 else
1831 phymode = MODE_11AC_VHT20;
1832 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001833 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1834 phymode = MODE_11NG_HT40;
1835 else
1836 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001837 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001838 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001839 } else {
1840 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001841 }
1842
1843 break;
1844 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001845 /*
1846 * Check VHT first.
1847 */
1848 if (sta->vht_cap.vht_supported) {
1849 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1850 phymode = MODE_11AC_VHT80;
1851 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1852 phymode = MODE_11AC_VHT40;
1853 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1854 phymode = MODE_11AC_VHT20;
1855 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001856 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1857 phymode = MODE_11NA_HT40;
1858 else
1859 phymode = MODE_11NA_HT20;
1860 } else {
1861 phymode = MODE_11A;
1862 }
1863
1864 break;
1865 default:
1866 break;
1867 }
1868
Michal Kazior7aa7a722014-08-25 12:09:38 +02001869 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001870 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001871
Kalle Valo5e3dd152013-06-12 20:52:10 +03001872 arg->peer_phymode = phymode;
1873 WARN_ON(phymode == MODE_UNKNOWN);
1874}
1875
Kalle Valob9ada652013-10-16 15:44:46 +03001876static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001877 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001878 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001879 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001880{
Michal Kazior548db542013-07-05 16:15:15 +03001881 lockdep_assert_held(&ar->conf_mutex);
1882
Kalle Valob9ada652013-10-16 15:44:46 +03001883 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001884
Michal Kazior590922a2014-10-21 10:10:29 +03001885 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1886 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001887 ath10k_peer_assoc_h_rates(ar, sta, arg);
1888 ath10k_peer_assoc_h_ht(ar, sta, arg);
1889 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001890 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1891 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001892
Kalle Valob9ada652013-10-16 15:44:46 +03001893 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001894}
1895
Michal Kazior90046f52014-02-14 14:45:51 +01001896static const u32 ath10k_smps_map[] = {
1897 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1898 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1899 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1900 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1901};
1902
1903static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1904 const u8 *addr,
1905 const struct ieee80211_sta_ht_cap *ht_cap)
1906{
1907 int smps;
1908
1909 if (!ht_cap->ht_supported)
1910 return 0;
1911
1912 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1913 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1914
1915 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1916 return -EINVAL;
1917
1918 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1919 WMI_PEER_SMPS_STATE,
1920 ath10k_smps_map[smps]);
1921}
1922
Michal Kazior139e1702015-02-15 16:50:42 +02001923static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1924 struct ieee80211_vif *vif,
1925 struct ieee80211_sta_vht_cap vht_cap)
1926{
1927 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1928 int ret;
1929 u32 param;
1930 u32 value;
1931
1932 if (!(ar->vht_cap_info &
1933 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1934 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1935 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1936 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1937 return 0;
1938
1939 param = ar->wmi.vdev_param->txbf;
1940 value = 0;
1941
1942 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1943 return 0;
1944
1945 /* The following logic is correct. If a remote STA advertises support
1946 * for being a beamformer then we should enable us being a beamformee.
1947 */
1948
1949 if (ar->vht_cap_info &
1950 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1951 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1952 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1953 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1954
1955 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1956 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1957 }
1958
1959 if (ar->vht_cap_info &
1960 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1961 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1962 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1963 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1964
1965 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
1966 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
1967 }
1968
1969 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
1970 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1971
1972 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
1973 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1974
1975 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
1976 if (ret) {
1977 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
1978 value, ret);
1979 return ret;
1980 }
1981
1982 return 0;
1983}
1984
Kalle Valo5e3dd152013-06-12 20:52:10 +03001985/* can be called only in mac80211 callbacks due to `key_count` usage */
1986static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1987 struct ieee80211_vif *vif,
1988 struct ieee80211_bss_conf *bss_conf)
1989{
1990 struct ath10k *ar = hw->priv;
1991 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001992 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001993 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001994 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 struct ieee80211_sta *ap_sta;
1996 int ret;
1997
Michal Kazior548db542013-07-05 16:15:15 +03001998 lockdep_assert_held(&ar->conf_mutex);
1999
Michal Kazior077efc82014-10-21 10:10:29 +03002000 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2001 arvif->vdev_id, arvif->bssid, arvif->aid);
2002
Kalle Valo5e3dd152013-06-12 20:52:10 +03002003 rcu_read_lock();
2004
2005 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2006 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002007 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002008 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002009 rcu_read_unlock();
2010 return;
2011 }
2012
Michal Kazior90046f52014-02-14 14:45:51 +01002013 /* ap_sta must be accessed only within rcu section which must be left
2014 * before calling ath10k_setup_peer_smps() which might sleep. */
2015 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002016 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002017
Michal Kazior590922a2014-10-21 10:10:29 +03002018 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002019 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002020 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002021 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002022 rcu_read_unlock();
2023 return;
2024 }
2025
2026 rcu_read_unlock();
2027
Kalle Valob9ada652013-10-16 15:44:46 +03002028 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2029 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002030 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002031 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002032 return;
2033 }
2034
Michal Kazior90046f52014-02-14 14:45:51 +01002035 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2036 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002037 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002038 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002039 return;
2040 }
2041
Michal Kazior139e1702015-02-15 16:50:42 +02002042 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2043 if (ret) {
2044 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2045 arvif->vdev_id, bss_conf->bssid, ret);
2046 return;
2047 }
2048
Michal Kazior7aa7a722014-08-25 12:09:38 +02002049 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002050 "mac vdev %d up (associated) bssid %pM aid %d\n",
2051 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2052
Michal Kazior077efc82014-10-21 10:10:29 +03002053 WARN_ON(arvif->is_up);
2054
Michal Kaziorc930f742014-01-23 11:38:25 +01002055 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002056 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002057
2058 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2059 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002060 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002061 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002062 return;
2063 }
2064
Michal Kazior81a9a172015-03-05 16:02:17 +02002065 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01002066 arvif->is_up = true;
Michal Kazior81a9a172015-03-05 16:02:17 +02002067 spin_unlock_bh(&arvif->ar->data_lock);
Michal Kazior0a987fb2015-02-13 13:30:15 +01002068
2069 /* Workaround: Some firmware revisions (tested with qca6174
2070 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2071 * poked with peer param command.
2072 */
2073 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2074 WMI_PEER_DUMMY_VAR, 1);
2075 if (ret) {
2076 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2077 arvif->bssid, arvif->vdev_id, ret);
2078 return;
2079 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080}
2081
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2083 struct ieee80211_vif *vif)
2084{
2085 struct ath10k *ar = hw->priv;
2086 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002087 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002088 int ret;
2089
Michal Kazior548db542013-07-05 16:15:15 +03002090 lockdep_assert_held(&ar->conf_mutex);
2091
Michal Kazior077efc82014-10-21 10:10:29 +03002092 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2093 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002094
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002096 if (ret)
2097 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2098 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002099
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002100 arvif->def_wep_key_idx = -1;
2101
Michal Kazior139e1702015-02-15 16:50:42 +02002102 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2103 if (ret) {
2104 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2105 arvif->vdev_id, ret);
2106 return;
2107 }
2108
Michal Kazior81a9a172015-03-05 16:02:17 +02002109 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01002110 arvif->is_up = false;
Michal Kazior81a9a172015-03-05 16:02:17 +02002111 spin_unlock_bh(&arvif->ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002112}
2113
Michal Kazior590922a2014-10-21 10:10:29 +03002114static int ath10k_station_assoc(struct ath10k *ar,
2115 struct ieee80211_vif *vif,
2116 struct ieee80211_sta *sta,
2117 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002118{
Michal Kazior590922a2014-10-21 10:10:29 +03002119 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002120 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002121 int ret = 0;
2122
Michal Kazior548db542013-07-05 16:15:15 +03002123 lockdep_assert_held(&ar->conf_mutex);
2124
Michal Kazior590922a2014-10-21 10:10:29 +03002125 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002127 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002128 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002129 return ret;
2130 }
2131
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002132 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002133 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2134 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002135 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002136 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137 return ret;
2138 }
2139
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002140 /* Re-assoc is run only to update supported rates for given station. It
2141 * doesn't make much sense to reconfigure the peer completely.
2142 */
2143 if (!reassoc) {
2144 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2145 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002146 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002147 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002148 arvif->vdev_id, ret);
2149 return ret;
2150 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002151
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002152 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2153 if (ret) {
2154 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2155 sta->addr, arvif->vdev_id, ret);
2156 return ret;
2157 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002158
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002159 if (!sta->wme) {
2160 arvif->num_legacy_stations++;
2161 ret = ath10k_recalc_rtscts_prot(arvif);
2162 if (ret) {
2163 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2164 arvif->vdev_id, ret);
2165 return ret;
2166 }
2167 }
2168
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002169 /* Plumb cached keys only for static WEP */
2170 if (arvif->def_wep_key_idx != -1) {
2171 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2172 if (ret) {
2173 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2174 arvif->vdev_id, ret);
2175 return ret;
2176 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002177 }
2178 }
2179
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180 return ret;
2181}
2182
Michal Kazior590922a2014-10-21 10:10:29 +03002183static int ath10k_station_disassoc(struct ath10k *ar,
2184 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 struct ieee80211_sta *sta)
2186{
Michal Kazior590922a2014-10-21 10:10:29 +03002187 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188 int ret = 0;
2189
2190 lockdep_assert_held(&ar->conf_mutex);
2191
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002192 if (!sta->wme) {
2193 arvif->num_legacy_stations--;
2194 ret = ath10k_recalc_rtscts_prot(arvif);
2195 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002196 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002197 arvif->vdev_id, ret);
2198 return ret;
2199 }
2200 }
2201
Kalle Valo5e3dd152013-06-12 20:52:10 +03002202 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2203 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002204 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002205 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002206 return ret;
2207 }
2208
2209 return ret;
2210}
2211
2212/**************/
2213/* Regulatory */
2214/**************/
2215
2216static int ath10k_update_channel_list(struct ath10k *ar)
2217{
2218 struct ieee80211_hw *hw = ar->hw;
2219 struct ieee80211_supported_band **bands;
2220 enum ieee80211_band band;
2221 struct ieee80211_channel *channel;
2222 struct wmi_scan_chan_list_arg arg = {0};
2223 struct wmi_channel_arg *ch;
2224 bool passive;
2225 int len;
2226 int ret;
2227 int i;
2228
Michal Kazior548db542013-07-05 16:15:15 +03002229 lockdep_assert_held(&ar->conf_mutex);
2230
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231 bands = hw->wiphy->bands;
2232 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2233 if (!bands[band])
2234 continue;
2235
2236 for (i = 0; i < bands[band]->n_channels; i++) {
2237 if (bands[band]->channels[i].flags &
2238 IEEE80211_CHAN_DISABLED)
2239 continue;
2240
2241 arg.n_channels++;
2242 }
2243 }
2244
2245 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2246 arg.channels = kzalloc(len, GFP_KERNEL);
2247 if (!arg.channels)
2248 return -ENOMEM;
2249
2250 ch = arg.channels;
2251 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2252 if (!bands[band])
2253 continue;
2254
2255 for (i = 0; i < bands[band]->n_channels; i++) {
2256 channel = &bands[band]->channels[i];
2257
2258 if (channel->flags & IEEE80211_CHAN_DISABLED)
2259 continue;
2260
2261 ch->allow_ht = true;
2262
2263 /* FIXME: when should we really allow VHT? */
2264 ch->allow_vht = true;
2265
2266 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002267 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002268
2269 ch->ht40plus =
2270 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2271
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002272 ch->chan_radar =
2273 !!(channel->flags & IEEE80211_CHAN_RADAR);
2274
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002275 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002276 ch->passive = passive;
2277
2278 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002279 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002280 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002281 ch->max_power = channel->max_power * 2;
2282 ch->max_reg_power = channel->max_reg_power * 2;
2283 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284 ch->reg_class_id = 0; /* FIXME */
2285
2286 /* FIXME: why use only legacy modes, why not any
2287 * HT/VHT modes? Would that even make any
2288 * difference? */
2289 if (channel->band == IEEE80211_BAND_2GHZ)
2290 ch->mode = MODE_11G;
2291 else
2292 ch->mode = MODE_11A;
2293
2294 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2295 continue;
2296
Michal Kazior7aa7a722014-08-25 12:09:38 +02002297 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002298 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2299 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002300 ch->freq, ch->max_power, ch->max_reg_power,
2301 ch->max_antenna_gain, ch->mode);
2302
2303 ch++;
2304 }
2305 }
2306
2307 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2308 kfree(arg.channels);
2309
2310 return ret;
2311}
2312
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002313static enum wmi_dfs_region
2314ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2315{
2316 switch (dfs_region) {
2317 case NL80211_DFS_UNSET:
2318 return WMI_UNINIT_DFS_DOMAIN;
2319 case NL80211_DFS_FCC:
2320 return WMI_FCC_DFS_DOMAIN;
2321 case NL80211_DFS_ETSI:
2322 return WMI_ETSI_DFS_DOMAIN;
2323 case NL80211_DFS_JP:
2324 return WMI_MKK4_DFS_DOMAIN;
2325 }
2326 return WMI_UNINIT_DFS_DOMAIN;
2327}
2328
Michal Kaziorf7843d72013-07-16 09:38:52 +02002329static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002330{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002333 enum wmi_dfs_region wmi_dfs_reg;
2334 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335
Michal Kaziorf7843d72013-07-16 09:38:52 +02002336 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002337
2338 ret = ath10k_update_channel_list(ar);
2339 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002340 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341
2342 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002343
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002344 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2345 nl_dfs_reg = ar->dfs_detector->region;
2346 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2347 } else {
2348 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2349 }
2350
Kalle Valo5e3dd152013-06-12 20:52:10 +03002351 /* Target allows setting up per-band regdomain but ath_common provides
2352 * a combined one only */
2353 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002354 regpair->reg_domain,
2355 regpair->reg_domain, /* 2ghz */
2356 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002358 regpair->reg_5ghz_ctl,
2359 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002361 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002362}
Michal Kazior548db542013-07-05 16:15:15 +03002363
Michal Kaziorf7843d72013-07-16 09:38:52 +02002364static void ath10k_reg_notifier(struct wiphy *wiphy,
2365 struct regulatory_request *request)
2366{
2367 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2368 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002369 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002370
2371 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2372
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002373 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002374 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002375 request->dfs_region);
2376 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2377 request->dfs_region);
2378 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002379 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002380 request->dfs_region);
2381 }
2382
Michal Kaziorf7843d72013-07-16 09:38:52 +02002383 mutex_lock(&ar->conf_mutex);
2384 if (ar->state == ATH10K_STATE_ON)
2385 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002386 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002387}
2388
2389/***************/
2390/* TX handlers */
2391/***************/
2392
Michal Kazior42c3aa62013-10-02 11:03:38 +02002393static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2394{
2395 if (ieee80211_is_mgmt(hdr->frame_control))
2396 return HTT_DATA_TX_EXT_TID_MGMT;
2397
2398 if (!ieee80211_is_data_qos(hdr->frame_control))
2399 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2400
2401 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2402 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2403
2404 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2405}
2406
Michal Kazior2b37c292014-09-02 11:00:22 +03002407static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002408{
Michal Kazior2b37c292014-09-02 11:00:22 +03002409 if (vif)
2410 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002411
Michal Kazior1bbc0972014-04-08 09:45:47 +03002412 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002413 return ar->monitor_vdev_id;
2414
Michal Kazior7aa7a722014-08-25 12:09:38 +02002415 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002416 return 0;
2417}
2418
Michal Kazior4b604552014-07-21 21:03:09 +03002419/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2420 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002421 */
Michal Kazior4b604552014-07-21 21:03:09 +03002422static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002423{
2424 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002425 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002426 u8 *qos_ctl;
2427
2428 if (!ieee80211_is_data_qos(hdr->frame_control))
2429 return;
2430
2431 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002432 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2433 skb->data, (void *)qos_ctl - (void *)skb->data);
2434 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002435
2436 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2437 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2438 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2439 * it is safe to downgrade to NullFunc.
2440 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002441 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002442 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2443 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2444 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2445 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002446}
2447
Michal Kazior4b604552014-07-21 21:03:09 +03002448static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2449 struct ieee80211_vif *vif,
2450 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002451{
2452 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2454
2455 /* This is case only for P2P_GO */
2456 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2457 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2458 return;
2459
2460 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2461 spin_lock_bh(&ar->data_lock);
2462 if (arvif->u.ap.noa_data)
2463 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2464 GFP_ATOMIC))
2465 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2466 arvif->u.ap.noa_data,
2467 arvif->u.ap.noa_len);
2468 spin_unlock_bh(&ar->data_lock);
2469 }
2470}
2471
Michal Kazior8d6d3622014-11-24 14:58:31 +01002472static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2473{
2474 /* FIXME: Not really sure since when the behaviour changed. At some
2475 * point new firmware stopped requiring creation of peer entries for
2476 * offchannel tx (and actually creating them causes issues with wmi-htc
2477 * tx credit replenishment and reliability). Assuming it's at least 3.4
2478 * because that's when the `freq` was introduced to TX_FRM HTT command.
2479 */
2480 return !(ar->htt.target_version_major >= 3 &&
2481 ar->htt.target_version_minor >= 4);
2482}
2483
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2485{
2486 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002487 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488
Michal Kazior961d4c32013-08-09 10:13:34 +02002489 if (ar->htt.target_version_major >= 3) {
2490 /* Since HTT 3.0 there is no separate mgmt tx command */
2491 ret = ath10k_htt_tx(&ar->htt, skb);
2492 goto exit;
2493 }
2494
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002495 if (ieee80211_is_mgmt(hdr->frame_control)) {
2496 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2497 ar->fw_features)) {
2498 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2499 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002500 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002501 ret = -EBUSY;
2502 goto exit;
2503 }
2504
2505 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2506 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2507 } else {
2508 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2509 }
2510 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2511 ar->fw_features) &&
2512 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002513 /* FW does not report tx status properly for NullFunc frames
2514 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002515 * those frames when it detects link/beacon loss and depends
2516 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002517 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002518 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002519 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002520 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002521
Michal Kazior961d4c32013-08-09 10:13:34 +02002522exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002524 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2525 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002526 ieee80211_free_txskb(ar->hw, skb);
2527 }
2528}
2529
2530void ath10k_offchan_tx_purge(struct ath10k *ar)
2531{
2532 struct sk_buff *skb;
2533
2534 for (;;) {
2535 skb = skb_dequeue(&ar->offchan_tx_queue);
2536 if (!skb)
2537 break;
2538
2539 ieee80211_free_txskb(ar->hw, skb);
2540 }
2541}
2542
2543void ath10k_offchan_tx_work(struct work_struct *work)
2544{
2545 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2546 struct ath10k_peer *peer;
2547 struct ieee80211_hdr *hdr;
2548 struct sk_buff *skb;
2549 const u8 *peer_addr;
2550 int vdev_id;
2551 int ret;
2552
2553 /* FW requirement: We must create a peer before FW will send out
2554 * an offchannel frame. Otherwise the frame will be stuck and
2555 * never transmitted. We delete the peer upon tx completion.
2556 * It is unlikely that a peer for offchannel tx will already be
2557 * present. However it may be in some rare cases so account for that.
2558 * Otherwise we might remove a legitimate peer and break stuff. */
2559
2560 for (;;) {
2561 skb = skb_dequeue(&ar->offchan_tx_queue);
2562 if (!skb)
2563 break;
2564
2565 mutex_lock(&ar->conf_mutex);
2566
Michal Kazior7aa7a722014-08-25 12:09:38 +02002567 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 skb);
2569
2570 hdr = (struct ieee80211_hdr *)skb->data;
2571 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002572 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002573
2574 spin_lock_bh(&ar->data_lock);
2575 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2576 spin_unlock_bh(&ar->data_lock);
2577
2578 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002579 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002580 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002581 peer_addr, vdev_id);
2582
2583 if (!peer) {
2584 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2585 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002586 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587 peer_addr, vdev_id, ret);
2588 }
2589
2590 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002591 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002592 ar->offchan_tx_skb = skb;
2593 spin_unlock_bh(&ar->data_lock);
2594
2595 ath10k_tx_htt(ar, skb);
2596
2597 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2598 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002599 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002600 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601 skb);
2602
2603 if (!peer) {
2604 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2605 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002606 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002607 peer_addr, vdev_id, ret);
2608 }
2609
2610 mutex_unlock(&ar->conf_mutex);
2611 }
2612}
2613
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002614void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2615{
2616 struct sk_buff *skb;
2617
2618 for (;;) {
2619 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2620 if (!skb)
2621 break;
2622
2623 ieee80211_free_txskb(ar->hw, skb);
2624 }
2625}
2626
2627void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2628{
2629 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2630 struct sk_buff *skb;
2631 int ret;
2632
2633 for (;;) {
2634 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2635 if (!skb)
2636 break;
2637
2638 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002639 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002640 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002641 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002642 ieee80211_free_txskb(ar->hw, skb);
2643 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002644 }
2645}
2646
Kalle Valo5e3dd152013-06-12 20:52:10 +03002647/************/
2648/* Scanning */
2649/************/
2650
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002651void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002652{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002653 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002654
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002655 switch (ar->scan.state) {
2656 case ATH10K_SCAN_IDLE:
2657 break;
2658 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002659 if (ar->scan.is_roc)
2660 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002661 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002662 case ATH10K_SCAN_ABORTING:
2663 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002664 ieee80211_scan_completed(ar->hw,
2665 (ar->scan.state ==
2666 ATH10K_SCAN_ABORTING));
2667 /* fall through */
2668 case ATH10K_SCAN_STARTING:
2669 ar->scan.state = ATH10K_SCAN_IDLE;
2670 ar->scan_channel = NULL;
2671 ath10k_offchan_tx_purge(ar);
2672 cancel_delayed_work(&ar->scan.timeout);
2673 complete_all(&ar->scan.completed);
2674 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002675 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002676}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002677
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002678void ath10k_scan_finish(struct ath10k *ar)
2679{
2680 spin_lock_bh(&ar->data_lock);
2681 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 spin_unlock_bh(&ar->data_lock);
2683}
2684
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002685static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686{
2687 struct wmi_stop_scan_arg arg = {
2688 .req_id = 1, /* FIXME */
2689 .req_type = WMI_SCAN_STOP_ONE,
2690 .u.scan_id = ATH10K_SCAN_ID,
2691 };
2692 int ret;
2693
2694 lockdep_assert_held(&ar->conf_mutex);
2695
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 ret = ath10k_wmi_stop_scan(ar, &arg);
2697 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002698 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002699 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700 }
2701
Kalle Valo5e3dd152013-06-12 20:52:10 +03002702 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002703 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002704 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002705 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002706 } else if (ret > 0) {
2707 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002708 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002709
2710out:
2711 /* Scan state should be updated upon scan completion but in case
2712 * firmware fails to deliver the event (for whatever reason) it is
2713 * desired to clean up scan state anyway. Firmware may have just
2714 * dropped the scan completion event delivery due to transport pipe
2715 * being overflown with data and/or it can recover on its own before
2716 * next scan request is submitted.
2717 */
2718 spin_lock_bh(&ar->data_lock);
2719 if (ar->scan.state != ATH10K_SCAN_IDLE)
2720 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002721 spin_unlock_bh(&ar->data_lock);
2722
2723 return ret;
2724}
2725
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002726static void ath10k_scan_abort(struct ath10k *ar)
2727{
2728 int ret;
2729
2730 lockdep_assert_held(&ar->conf_mutex);
2731
2732 spin_lock_bh(&ar->data_lock);
2733
2734 switch (ar->scan.state) {
2735 case ATH10K_SCAN_IDLE:
2736 /* This can happen if timeout worker kicked in and called
2737 * abortion while scan completion was being processed.
2738 */
2739 break;
2740 case ATH10K_SCAN_STARTING:
2741 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002742 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002743 ath10k_scan_state_str(ar->scan.state),
2744 ar->scan.state);
2745 break;
2746 case ATH10K_SCAN_RUNNING:
2747 ar->scan.state = ATH10K_SCAN_ABORTING;
2748 spin_unlock_bh(&ar->data_lock);
2749
2750 ret = ath10k_scan_stop(ar);
2751 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002752 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002753
2754 spin_lock_bh(&ar->data_lock);
2755 break;
2756 }
2757
2758 spin_unlock_bh(&ar->data_lock);
2759}
2760
2761void ath10k_scan_timeout_work(struct work_struct *work)
2762{
2763 struct ath10k *ar = container_of(work, struct ath10k,
2764 scan.timeout.work);
2765
2766 mutex_lock(&ar->conf_mutex);
2767 ath10k_scan_abort(ar);
2768 mutex_unlock(&ar->conf_mutex);
2769}
2770
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771static int ath10k_start_scan(struct ath10k *ar,
2772 const struct wmi_start_scan_arg *arg)
2773{
2774 int ret;
2775
2776 lockdep_assert_held(&ar->conf_mutex);
2777
2778 ret = ath10k_wmi_start_scan(ar, arg);
2779 if (ret)
2780 return ret;
2781
Kalle Valo5e3dd152013-06-12 20:52:10 +03002782 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2783 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002784 ret = ath10k_scan_stop(ar);
2785 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002786 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002787
2788 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002789 }
2790
Ben Greear2f9eec02015-02-15 16:50:38 +02002791 /* If we failed to start the scan, return error code at
2792 * this point. This is probably due to some issue in the
2793 * firmware, but no need to wedge the driver due to that...
2794 */
2795 spin_lock_bh(&ar->data_lock);
2796 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2797 spin_unlock_bh(&ar->data_lock);
2798 return -EINVAL;
2799 }
2800 spin_unlock_bh(&ar->data_lock);
2801
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002802 /* Add a 200ms margin to account for event/command processing */
2803 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2804 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805 return 0;
2806}
2807
2808/**********************/
2809/* mac80211 callbacks */
2810/**********************/
2811
2812static void ath10k_tx(struct ieee80211_hw *hw,
2813 struct ieee80211_tx_control *control,
2814 struct sk_buff *skb)
2815{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002816 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002817 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2818 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002819 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820
2821 /* We should disable CCK RATE due to P2P */
2822 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002823 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824
Michal Kazior4b604552014-07-21 21:03:09 +03002825 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2826 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002827 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002828
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002829 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002830 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2831 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002832 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2833 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002834 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835
Kalle Valo5e3dd152013-06-12 20:52:10 +03002836 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2837 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002838 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002839 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002840 spin_unlock_bh(&ar->data_lock);
2841
Michal Kazior8d6d3622014-11-24 14:58:31 +01002842 if (ath10k_mac_need_offchan_tx_work(ar)) {
2843 ATH10K_SKB_CB(skb)->htt.freq = 0;
2844 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002845
Michal Kazior8d6d3622014-11-24 14:58:31 +01002846 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2847 skb);
2848
2849 skb_queue_tail(&ar->offchan_tx_queue, skb);
2850 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2851 return;
2852 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002853 }
2854
2855 ath10k_tx_htt(ar, skb);
2856}
2857
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002858/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002859void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002860{
2861 /* make sure rcu-protected mac80211 tx path itself is drained */
2862 synchronize_net();
2863
2864 ath10k_offchan_tx_purge(ar);
2865 ath10k_mgmt_over_wmi_tx_purge(ar);
2866
2867 cancel_work_sync(&ar->offchan_tx_work);
2868 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2869}
2870
Michal Kazioraffd3212013-07-16 09:54:35 +02002871void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002872{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002873 struct ath10k_vif *arvif;
2874
Michal Kazior818bdd12013-07-16 09:38:57 +02002875 lockdep_assert_held(&ar->conf_mutex);
2876
Michal Kazior19337472014-08-28 12:58:16 +02002877 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2878 ar->filter_flags = 0;
2879 ar->monitor = false;
2880
2881 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002882 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002883
2884 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002885
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002886 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002887 ath10k_peer_cleanup_all(ar);
2888 ath10k_core_stop(ar);
2889 ath10k_hif_power_down(ar);
2890
2891 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002892 list_for_each_entry(arvif, &ar->arvifs, list)
2893 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002894 spin_unlock_bh(&ar->data_lock);
2895}
2896
Ben Greear46acf7b2014-05-16 17:15:38 +03002897static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2898{
2899 struct ath10k *ar = hw->priv;
2900
2901 mutex_lock(&ar->conf_mutex);
2902
2903 if (ar->cfg_tx_chainmask) {
2904 *tx_ant = ar->cfg_tx_chainmask;
2905 *rx_ant = ar->cfg_rx_chainmask;
2906 } else {
2907 *tx_ant = ar->supp_tx_chainmask;
2908 *rx_ant = ar->supp_rx_chainmask;
2909 }
2910
2911 mutex_unlock(&ar->conf_mutex);
2912
2913 return 0;
2914}
2915
Ben Greear5572a952014-11-24 16:22:10 +02002916static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2917{
2918 /* It is not clear that allowing gaps in chainmask
2919 * is helpful. Probably it will not do what user
2920 * is hoping for, so warn in that case.
2921 */
2922 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2923 return;
2924
2925 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2926 dbg, cm);
2927}
2928
Ben Greear46acf7b2014-05-16 17:15:38 +03002929static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2930{
2931 int ret;
2932
2933 lockdep_assert_held(&ar->conf_mutex);
2934
Ben Greear5572a952014-11-24 16:22:10 +02002935 ath10k_check_chain_mask(ar, tx_ant, "tx");
2936 ath10k_check_chain_mask(ar, rx_ant, "rx");
2937
Ben Greear46acf7b2014-05-16 17:15:38 +03002938 ar->cfg_tx_chainmask = tx_ant;
2939 ar->cfg_rx_chainmask = rx_ant;
2940
2941 if ((ar->state != ATH10K_STATE_ON) &&
2942 (ar->state != ATH10K_STATE_RESTARTED))
2943 return 0;
2944
2945 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2946 tx_ant);
2947 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002948 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002949 ret, tx_ant);
2950 return ret;
2951 }
2952
2953 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2954 rx_ant);
2955 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002956 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002957 ret, rx_ant);
2958 return ret;
2959 }
2960
2961 return 0;
2962}
2963
2964static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2965{
2966 struct ath10k *ar = hw->priv;
2967 int ret;
2968
2969 mutex_lock(&ar->conf_mutex);
2970 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2971 mutex_unlock(&ar->conf_mutex);
2972 return ret;
2973}
2974
Kalle Valo5e3dd152013-06-12 20:52:10 +03002975static int ath10k_start(struct ieee80211_hw *hw)
2976{
2977 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002978 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002979
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002980 /*
2981 * This makes sense only when restarting hw. It is harmless to call
2982 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2983 * commands will be submitted while restarting.
2984 */
2985 ath10k_drain_tx(ar);
2986
Michal Kazior548db542013-07-05 16:15:15 +03002987 mutex_lock(&ar->conf_mutex);
2988
Michal Kaziorc5058f52014-05-26 12:46:03 +03002989 switch (ar->state) {
2990 case ATH10K_STATE_OFF:
2991 ar->state = ATH10K_STATE_ON;
2992 break;
2993 case ATH10K_STATE_RESTARTING:
2994 ath10k_halt(ar);
2995 ar->state = ATH10K_STATE_RESTARTED;
2996 break;
2997 case ATH10K_STATE_ON:
2998 case ATH10K_STATE_RESTARTED:
2999 case ATH10K_STATE_WEDGED:
3000 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003001 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003002 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003003 case ATH10K_STATE_UTF:
3004 ret = -EBUSY;
3005 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003006 }
3007
3008 ret = ath10k_hif_power_up(ar);
3009 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003010 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003011 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003012 }
3013
Kalle Valo43d2a302014-09-10 18:23:30 +03003014 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003015 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003016 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003017 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003018 }
3019
Bartosz Markowski226a3392013-09-26 17:47:16 +02003020 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003021 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003022 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003023 goto err_core_stop;
3024 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003025
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003026 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003027 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003028 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003029 goto err_core_stop;
3030 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003031
Ben Greear46acf7b2014-05-16 17:15:38 +03003032 if (ar->cfg_tx_chainmask)
3033 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3034 ar->cfg_rx_chainmask);
3035
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003036 /*
3037 * By default FW set ARP frames ac to voice (6). In that case ARP
3038 * exchange is not working properly for UAPSD enabled AP. ARP requests
3039 * which arrives with access category 0 are processed by network stack
3040 * and send back with access category 0, but FW changes access category
3041 * to 6. Set ARP frames access category to best effort (0) solves
3042 * this problem.
3043 */
3044
3045 ret = ath10k_wmi_pdev_set_param(ar,
3046 ar->wmi.pdev_param->arp_ac_override, 0);
3047 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003048 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003049 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003050 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003051 }
3052
Michal Kaziord6500972014-04-08 09:56:09 +03003053 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003054 ath10k_regd_update(ar);
3055
Simon Wunderlich855aed12014-08-02 09:12:54 +03003056 ath10k_spectral_start(ar);
3057
Michal Kaziorae254432014-05-26 12:46:02 +03003058 mutex_unlock(&ar->conf_mutex);
3059 return 0;
3060
3061err_core_stop:
3062 ath10k_core_stop(ar);
3063
3064err_power_down:
3065 ath10k_hif_power_down(ar);
3066
3067err_off:
3068 ar->state = ATH10K_STATE_OFF;
3069
3070err:
Michal Kazior548db542013-07-05 16:15:15 +03003071 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003072 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003073}
3074
3075static void ath10k_stop(struct ieee80211_hw *hw)
3076{
3077 struct ath10k *ar = hw->priv;
3078
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003079 ath10k_drain_tx(ar);
3080
Michal Kazior548db542013-07-05 16:15:15 +03003081 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003082 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003083 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003084 ar->state = ATH10K_STATE_OFF;
3085 }
Michal Kazior548db542013-07-05 16:15:15 +03003086 mutex_unlock(&ar->conf_mutex);
3087
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003088 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003089 cancel_work_sync(&ar->restart_work);
3090}
3091
Michal Kaziorad088bf2013-10-16 15:44:46 +03003092static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003093{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003094 struct ath10k_vif *arvif;
3095 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003096
3097 lockdep_assert_held(&ar->conf_mutex);
3098
Michal Kaziorad088bf2013-10-16 15:44:46 +03003099 list_for_each_entry(arvif, &ar->arvifs, list) {
3100 ret = ath10k_mac_vif_setup_ps(arvif);
3101 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003102 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003103 break;
3104 }
3105 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003106
Michal Kaziorad088bf2013-10-16 15:44:46 +03003107 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003108}
3109
Michal Kaziorc930f742014-01-23 11:38:25 +01003110static const char *chandef_get_width(enum nl80211_chan_width width)
3111{
3112 switch (width) {
3113 case NL80211_CHAN_WIDTH_20_NOHT:
3114 return "20 (noht)";
3115 case NL80211_CHAN_WIDTH_20:
3116 return "20";
3117 case NL80211_CHAN_WIDTH_40:
3118 return "40";
3119 case NL80211_CHAN_WIDTH_80:
3120 return "80";
3121 case NL80211_CHAN_WIDTH_80P80:
3122 return "80+80";
3123 case NL80211_CHAN_WIDTH_160:
3124 return "160";
3125 case NL80211_CHAN_WIDTH_5:
3126 return "5";
3127 case NL80211_CHAN_WIDTH_10:
3128 return "10";
3129 }
3130 return "?";
3131}
3132
3133static void ath10k_config_chan(struct ath10k *ar)
3134{
3135 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003136 int ret;
3137
3138 lockdep_assert_held(&ar->conf_mutex);
3139
Michal Kazior7aa7a722014-08-25 12:09:38 +02003140 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003141 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3142 ar->chandef.chan->center_freq,
3143 ar->chandef.center_freq1,
3144 ar->chandef.center_freq2,
3145 chandef_get_width(ar->chandef.width));
3146
3147 /* First stop monitor interface. Some FW versions crash if there's a
3148 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003149 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003150 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003151
3152 list_for_each_entry(arvif, &ar->arvifs, list) {
3153 if (!arvif->is_started)
3154 continue;
3155
Michal Kaziordc55e302014-07-29 12:53:36 +03003156 if (!arvif->is_up)
3157 continue;
3158
Michal Kaziorc930f742014-01-23 11:38:25 +01003159 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3160 continue;
3161
Michal Kaziordc55e302014-07-29 12:53:36 +03003162 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003163 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003164 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003165 arvif->vdev_id, ret);
3166 continue;
3167 }
3168 }
3169
Michal Kaziordc55e302014-07-29 12:53:36 +03003170 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003171
3172 list_for_each_entry(arvif, &ar->arvifs, list) {
3173 if (!arvif->is_started)
3174 continue;
3175
3176 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3177 continue;
3178
Michal Kazior81a9a172015-03-05 16:02:17 +02003179 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3180 if (ret)
3181 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3182 ret);
3183
3184 ret = ath10k_mac_setup_prb_tmpl(arvif);
3185 if (ret)
3186 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3187 ret);
3188
Michal Kaziordc55e302014-07-29 12:53:36 +03003189 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003190 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003191 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003192 arvif->vdev_id, ret);
3193 continue;
3194 }
3195
3196 if (!arvif->is_up)
3197 continue;
3198
3199 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3200 arvif->bssid);
3201 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003202 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003203 arvif->vdev_id, ret);
3204 continue;
3205 }
3206 }
3207
Michal Kazior19337472014-08-28 12:58:16 +02003208 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003209}
3210
Michal Kazior7d9d5582014-10-21 10:40:15 +03003211static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3212{
3213 int ret;
3214 u32 param;
3215
3216 lockdep_assert_held(&ar->conf_mutex);
3217
3218 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3219
3220 param = ar->wmi.pdev_param->txpower_limit2g;
3221 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3222 if (ret) {
3223 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3224 txpower, ret);
3225 return ret;
3226 }
3227
3228 param = ar->wmi.pdev_param->txpower_limit5g;
3229 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3230 if (ret) {
3231 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3232 txpower, ret);
3233 return ret;
3234 }
3235
3236 return 0;
3237}
3238
3239static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3240{
3241 struct ath10k_vif *arvif;
3242 int ret, txpower = -1;
3243
3244 lockdep_assert_held(&ar->conf_mutex);
3245
3246 list_for_each_entry(arvif, &ar->arvifs, list) {
3247 WARN_ON(arvif->txpower < 0);
3248
3249 if (txpower == -1)
3250 txpower = arvif->txpower;
3251 else
3252 txpower = min(txpower, arvif->txpower);
3253 }
3254
3255 if (WARN_ON(txpower == -1))
3256 return -EINVAL;
3257
3258 ret = ath10k_mac_txpower_setup(ar, txpower);
3259 if (ret) {
3260 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3261 txpower, ret);
3262 return ret;
3263 }
3264
3265 return 0;
3266}
3267
Kalle Valo5e3dd152013-06-12 20:52:10 +03003268static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3269{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003270 struct ath10k *ar = hw->priv;
3271 struct ieee80211_conf *conf = &hw->conf;
3272 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273
3274 mutex_lock(&ar->conf_mutex);
3275
3276 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003277 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003278 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003279 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003280 conf->chandef.chan->flags,
3281 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003282
Kalle Valo5e3dd152013-06-12 20:52:10 +03003283 spin_lock_bh(&ar->data_lock);
3284 ar->rx_channel = conf->chandef.chan;
3285 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003286
Michal Kaziord6500972014-04-08 09:56:09 +03003287 ar->radar_enabled = conf->radar_enabled;
3288 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003289
3290 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3291 ar->chandef = conf->chandef;
3292 ath10k_config_chan(ar);
3293 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294 }
3295
Michal Kazioraffd3212013-07-16 09:54:35 +02003296 if (changed & IEEE80211_CONF_CHANGE_PS)
3297 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003298
3299 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003300 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3301 ret = ath10k_monitor_recalc(ar);
3302 if (ret)
3303 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003304 }
3305
3306 mutex_unlock(&ar->conf_mutex);
3307 return ret;
3308}
3309
Ben Greear5572a952014-11-24 16:22:10 +02003310static u32 get_nss_from_chainmask(u16 chain_mask)
3311{
3312 if ((chain_mask & 0x15) == 0x15)
3313 return 4;
3314 else if ((chain_mask & 0x7) == 0x7)
3315 return 3;
3316 else if ((chain_mask & 0x3) == 0x3)
3317 return 2;
3318 return 1;
3319}
3320
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321/*
3322 * TODO:
3323 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3324 * because we will send mgmt frames without CCK. This requirement
3325 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3326 * in the TX packet.
3327 */
3328static int ath10k_add_interface(struct ieee80211_hw *hw,
3329 struct ieee80211_vif *vif)
3330{
3331 struct ath10k *ar = hw->priv;
3332 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3333 enum wmi_sta_powersave_param param;
3334 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003335 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003336 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003337 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003338
Johannes Berg848955c2014-11-11 12:48:42 +01003339 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3340
Kalle Valo5e3dd152013-06-12 20:52:10 +03003341 mutex_lock(&ar->conf_mutex);
3342
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003343 memset(arvif, 0, sizeof(*arvif));
3344
Kalle Valo5e3dd152013-06-12 20:52:10 +03003345 arvif->ar = ar;
3346 arvif->vif = vif;
3347
Ben Greeare63b33f2013-10-22 14:54:14 -07003348 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003349 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003350
Ben Greeara9aefb32014-08-12 11:02:19 +03003351 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003352 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003353 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003354 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003355 }
Ben Greear16c11172014-09-23 14:17:16 -07003356 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003357
Ben Greear16c11172014-09-23 14:17:16 -07003358 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3359 bit, ar->free_vdev_map);
3360
3361 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003362 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003363
Kalle Valo5e3dd152013-06-12 20:52:10 +03003364 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003365 case NL80211_IFTYPE_P2P_DEVICE:
3366 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3367 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3368 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369 case NL80211_IFTYPE_UNSPECIFIED:
3370 case NL80211_IFTYPE_STATION:
3371 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3372 if (vif->p2p)
3373 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3374 break;
3375 case NL80211_IFTYPE_ADHOC:
3376 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3377 break;
3378 case NL80211_IFTYPE_AP:
3379 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3380
3381 if (vif->p2p)
3382 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3383 break;
3384 case NL80211_IFTYPE_MONITOR:
3385 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3386 break;
3387 default:
3388 WARN_ON(1);
3389 break;
3390 }
3391
Michal Kazior64badcb2014-09-18 11:18:02 +03003392 /* Some firmware revisions don't wait for beacon tx completion before
3393 * sending another SWBA event. This could lead to hardware using old
3394 * (freed) beacon data in some cases, e.g. tx credit starvation
3395 * combined with missed TBTT. This is very very rare.
3396 *
3397 * On non-IOMMU-enabled hosts this could be a possible security issue
3398 * because hw could beacon some random data on the air. On
3399 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3400 * device would crash.
3401 *
3402 * Since there are no beacon tx completions (implicit nor explicit)
3403 * propagated to host the only workaround for this is to allocate a
3404 * DMA-coherent buffer for a lifetime of a vif and use it for all
3405 * beacon tx commands. Worst case for this approach is some beacons may
3406 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3407 */
3408 if (vif->type == NL80211_IFTYPE_ADHOC ||
3409 vif->type == NL80211_IFTYPE_AP) {
3410 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3411 IEEE80211_MAX_FRAME_LEN,
3412 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303413 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003414 if (!arvif->beacon_buf) {
3415 ret = -ENOMEM;
3416 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3417 ret);
3418 goto err;
3419 }
3420 }
3421
3422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3423 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3424 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425
3426 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3427 arvif->vdev_subtype, vif->addr);
3428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003429 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003430 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003431 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003432 }
3433
Ben Greear16c11172014-09-23 14:17:16 -07003434 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003435 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003436
Michal Kazior46725b152015-01-28 09:57:49 +02003437 /* It makes no sense to have firmware do keepalives. mac80211 already
3438 * takes care of this with idle connection polling.
3439 */
3440 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003441 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003442 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003443 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003444 goto err_vdev_delete;
3445 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003446
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003447 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003449 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3450 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003451 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003452 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003453 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003454 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003455 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003456 goto err_vdev_delete;
3457 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458
Ben Greear5572a952014-11-24 16:22:10 +02003459 if (ar->cfg_tx_chainmask) {
3460 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3461
3462 vdev_param = ar->wmi.vdev_param->nss;
3463 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3464 nss);
3465 if (ret) {
3466 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3467 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3468 ret);
3469 goto err_vdev_delete;
3470 }
3471 }
3472
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3474 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3475 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003476 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003477 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003478 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003480
Kalle Valo5a13e762014-01-20 11:01:46 +02003481 ret = ath10k_mac_set_kickout(arvif);
3482 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003483 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003484 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003485 goto err_peer_delete;
3486 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003487 }
3488
3489 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3490 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3491 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3492 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3493 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003495 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003496 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003497 goto err_peer_delete;
3498 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499
Michal Kazior9f9b5742014-12-12 12:41:36 +01003500 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003501 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003502 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003503 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003504 goto err_peer_delete;
3505 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003506
Michal Kazior9f9b5742014-12-12 12:41:36 +01003507 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003508 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003509 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003510 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003511 goto err_peer_delete;
3512 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 }
3514
Michal Kazior424121c2013-07-22 14:13:31 +02003515 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003517 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003518 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003519 goto err_peer_delete;
3520 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003521
Michal Kazior424121c2013-07-22 14:13:31 +02003522 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003523 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003524 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003525 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003526 goto err_peer_delete;
3527 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003528
Michal Kazior7d9d5582014-10-21 10:40:15 +03003529 arvif->txpower = vif->bss_conf.txpower;
3530 ret = ath10k_mac_txpower_recalc(ar);
3531 if (ret) {
3532 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3533 goto err_peer_delete;
3534 }
3535
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003537 return 0;
3538
3539err_peer_delete:
3540 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3541 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3542
3543err_vdev_delete:
3544 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003545 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003546 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003547
3548err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003549 if (arvif->beacon_buf) {
3550 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3551 arvif->beacon_buf, arvif->beacon_paddr);
3552 arvif->beacon_buf = NULL;
3553 }
3554
Michal Kazior9dad14a2013-10-16 15:44:45 +03003555 mutex_unlock(&ar->conf_mutex);
3556
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 return ret;
3558}
3559
3560static void ath10k_remove_interface(struct ieee80211_hw *hw,
3561 struct ieee80211_vif *vif)
3562{
3563 struct ath10k *ar = hw->priv;
3564 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3565 int ret;
3566
Michal Kazior81a9a172015-03-05 16:02:17 +02003567 cancel_work_sync(&arvif->ap_csa_work);
3568
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303569 mutex_lock(&ar->conf_mutex);
3570
Michal Kaziored543882013-09-13 14:16:56 +02003571 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003572 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003573 spin_unlock_bh(&ar->data_lock);
3574
Simon Wunderlich855aed12014-08-02 09:12:54 +03003575 ret = ath10k_spectral_vif_stop(arvif);
3576 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003577 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003578 arvif->vdev_id, ret);
3579
Ben Greear16c11172014-09-23 14:17:16 -07003580 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003581 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003582
3583 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003584 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3585 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003587 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003588 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589
3590 kfree(arvif->u.ap.noa_data);
3591 }
3592
Michal Kazior7aa7a722014-08-25 12:09:38 +02003593 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003594 arvif->vdev_id);
3595
Kalle Valo5e3dd152013-06-12 20:52:10 +03003596 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3597 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003598 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003599 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003600
Michal Kazior2c512052015-02-15 16:50:40 +02003601 /* Some firmware revisions don't notify host about self-peer removal
3602 * until after associated vdev is deleted.
3603 */
3604 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3605 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3606 vif->addr);
3607 if (ret)
3608 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3609 arvif->vdev_id, ret);
3610
3611 spin_lock_bh(&ar->data_lock);
3612 ar->num_peers--;
3613 spin_unlock_bh(&ar->data_lock);
3614 }
3615
Kalle Valo5e3dd152013-06-12 20:52:10 +03003616 ath10k_peer_cleanup(ar, arvif->vdev_id);
3617
3618 mutex_unlock(&ar->conf_mutex);
3619}
3620
3621/*
3622 * FIXME: Has to be verified.
3623 */
3624#define SUPPORTED_FILTERS \
3625 (FIF_PROMISC_IN_BSS | \
3626 FIF_ALLMULTI | \
3627 FIF_CONTROL | \
3628 FIF_PSPOLL | \
3629 FIF_OTHER_BSS | \
3630 FIF_BCN_PRBRESP_PROMISC | \
3631 FIF_PROBE_REQ | \
3632 FIF_FCSFAIL)
3633
3634static void ath10k_configure_filter(struct ieee80211_hw *hw,
3635 unsigned int changed_flags,
3636 unsigned int *total_flags,
3637 u64 multicast)
3638{
3639 struct ath10k *ar = hw->priv;
3640 int ret;
3641
3642 mutex_lock(&ar->conf_mutex);
3643
3644 changed_flags &= SUPPORTED_FILTERS;
3645 *total_flags &= SUPPORTED_FILTERS;
3646 ar->filter_flags = *total_flags;
3647
Michal Kazior19337472014-08-28 12:58:16 +02003648 ret = ath10k_monitor_recalc(ar);
3649 if (ret)
3650 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003651
3652 mutex_unlock(&ar->conf_mutex);
3653}
3654
3655static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3656 struct ieee80211_vif *vif,
3657 struct ieee80211_bss_conf *info,
3658 u32 changed)
3659{
3660 struct ath10k *ar = hw->priv;
3661 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3662 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003663 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003664
3665 mutex_lock(&ar->conf_mutex);
3666
3667 if (changed & BSS_CHANGED_IBSS)
3668 ath10k_control_ibss(arvif, info, vif->addr);
3669
3670 if (changed & BSS_CHANGED_BEACON_INT) {
3671 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003672 vdev_param = ar->wmi.vdev_param->beacon_interval;
3673 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003674 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003675 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003676 "mac vdev %d beacon_interval %d\n",
3677 arvif->vdev_id, arvif->beacon_interval);
3678
Kalle Valo5e3dd152013-06-12 20:52:10 +03003679 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003680 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003681 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003682 }
3683
3684 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003685 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003686 "vdev %d set beacon tx mode to staggered\n",
3687 arvif->vdev_id);
3688
Bartosz Markowski226a3392013-09-26 17:47:16 +02003689 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3690 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003691 WMI_BEACON_STAGGERED_MODE);
3692 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003693 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003694 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003695
3696 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3697 if (ret)
3698 ath10k_warn(ar, "failed to update beacon template: %d\n",
3699 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700 }
3701
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003702 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3703 ret = ath10k_mac_setup_prb_tmpl(arvif);
3704 if (ret)
3705 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3706 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707 }
3708
Michal Kaziorba2479f2015-01-24 12:14:51 +02003709 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710 arvif->dtim_period = info->dtim_period;
3711
Michal Kazior7aa7a722014-08-25 12:09:38 +02003712 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003713 "mac vdev %d dtim_period %d\n",
3714 arvif->vdev_id, arvif->dtim_period);
3715
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003716 vdev_param = ar->wmi.vdev_param->dtim_period;
3717 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003718 arvif->dtim_period);
3719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003720 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003721 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722 }
3723
3724 if (changed & BSS_CHANGED_SSID &&
3725 vif->type == NL80211_IFTYPE_AP) {
3726 arvif->u.ap.ssid_len = info->ssid_len;
3727 if (info->ssid_len)
3728 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3729 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3730 }
3731
Michal Kazior077efc82014-10-21 10:10:29 +03003732 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3733 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003734
3735 if (changed & BSS_CHANGED_BEACON_ENABLED)
3736 ath10k_control_beaconing(arvif, info);
3737
3738 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003739 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003741 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003742
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003743 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003745 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003746 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01003747
3748 vdev_param = ar->wmi.vdev_param->protection_mode;
3749 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3750 info->use_cts_prot ? 1 : 0);
3751 if (ret)
3752 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
3753 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003754 }
3755
3756 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003757 if (info->use_short_slot)
3758 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3759
3760 else
3761 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3762
Michal Kazior7aa7a722014-08-25 12:09:38 +02003763 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003764 arvif->vdev_id, slottime);
3765
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003766 vdev_param = ar->wmi.vdev_param->slot_time;
3767 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003768 slottime);
3769 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003770 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003771 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003772 }
3773
3774 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003775 if (info->use_short_preamble)
3776 preamble = WMI_VDEV_PREAMBLE_SHORT;
3777 else
3778 preamble = WMI_VDEV_PREAMBLE_LONG;
3779
Michal Kazior7aa7a722014-08-25 12:09:38 +02003780 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003781 "mac vdev %d preamble %dn",
3782 arvif->vdev_id, preamble);
3783
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003784 vdev_param = ar->wmi.vdev_param->preamble;
3785 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786 preamble);
3787 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003788 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003789 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003790 }
3791
3792 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003793 if (info->assoc) {
3794 /* Workaround: Make sure monitor vdev is not running
3795 * when associating to prevent some firmware revisions
3796 * (e.g. 10.1 and 10.2) from crashing.
3797 */
3798 if (ar->monitor_started)
3799 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003800 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003801 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003802 } else {
3803 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003804 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805 }
3806
Michal Kazior7d9d5582014-10-21 10:40:15 +03003807 if (changed & BSS_CHANGED_TXPOWER) {
3808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3809 arvif->vdev_id, info->txpower);
3810
3811 arvif->txpower = info->txpower;
3812 ret = ath10k_mac_txpower_recalc(ar);
3813 if (ret)
3814 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3815 }
3816
Michal Kaziorbf14e652014-12-12 12:41:38 +01003817 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003818 arvif->ps = vif->bss_conf.ps;
3819
3820 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003821 if (ret)
3822 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3823 arvif->vdev_id, ret);
3824 }
3825
Kalle Valo5e3dd152013-06-12 20:52:10 +03003826 mutex_unlock(&ar->conf_mutex);
3827}
3828
3829static int ath10k_hw_scan(struct ieee80211_hw *hw,
3830 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003831 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003832{
3833 struct ath10k *ar = hw->priv;
3834 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003835 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003836 struct wmi_start_scan_arg arg;
3837 int ret = 0;
3838 int i;
3839
3840 mutex_lock(&ar->conf_mutex);
3841
3842 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003843 switch (ar->scan.state) {
3844 case ATH10K_SCAN_IDLE:
3845 reinit_completion(&ar->scan.started);
3846 reinit_completion(&ar->scan.completed);
3847 ar->scan.state = ATH10K_SCAN_STARTING;
3848 ar->scan.is_roc = false;
3849 ar->scan.vdev_id = arvif->vdev_id;
3850 ret = 0;
3851 break;
3852 case ATH10K_SCAN_STARTING:
3853 case ATH10K_SCAN_RUNNING:
3854 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003855 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003856 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003857 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003858 spin_unlock_bh(&ar->data_lock);
3859
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003860 if (ret)
3861 goto exit;
3862
Kalle Valo5e3dd152013-06-12 20:52:10 +03003863 memset(&arg, 0, sizeof(arg));
3864 ath10k_wmi_start_scan_init(ar, &arg);
3865 arg.vdev_id = arvif->vdev_id;
3866 arg.scan_id = ATH10K_SCAN_ID;
3867
3868 if (!req->no_cck)
3869 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3870
3871 if (req->ie_len) {
3872 arg.ie_len = req->ie_len;
3873 memcpy(arg.ie, req->ie, arg.ie_len);
3874 }
3875
3876 if (req->n_ssids) {
3877 arg.n_ssids = req->n_ssids;
3878 for (i = 0; i < arg.n_ssids; i++) {
3879 arg.ssids[i].len = req->ssids[i].ssid_len;
3880 arg.ssids[i].ssid = req->ssids[i].ssid;
3881 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003882 } else {
3883 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884 }
3885
3886 if (req->n_channels) {
3887 arg.n_channels = req->n_channels;
3888 for (i = 0; i < arg.n_channels; i++)
3889 arg.channels[i] = req->channels[i]->center_freq;
3890 }
3891
3892 ret = ath10k_start_scan(ar, &arg);
3893 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003894 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003896 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003897 spin_unlock_bh(&ar->data_lock);
3898 }
3899
3900exit:
3901 mutex_unlock(&ar->conf_mutex);
3902 return ret;
3903}
3904
3905static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3906 struct ieee80211_vif *vif)
3907{
3908 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909
3910 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003911 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003912 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003913
3914 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915}
3916
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003917static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3918 struct ath10k_vif *arvif,
3919 enum set_key_cmd cmd,
3920 struct ieee80211_key_conf *key)
3921{
3922 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3923 int ret;
3924
3925 /* 10.1 firmware branch requires default key index to be set to group
3926 * key index after installing it. Otherwise FW/HW Txes corrupted
3927 * frames with multi-vif APs. This is not required for main firmware
3928 * branch (e.g. 636).
3929 *
3930 * FIXME: This has been tested only in AP. It remains unknown if this
3931 * is required for multi-vif STA interfaces on 10.1 */
3932
3933 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3934 return;
3935
3936 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3937 return;
3938
3939 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3940 return;
3941
3942 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3943 return;
3944
3945 if (cmd != SET_KEY)
3946 return;
3947
3948 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3949 key->keyidx);
3950 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003951 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003952 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003953}
3954
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3956 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3957 struct ieee80211_key_conf *key)
3958{
3959 struct ath10k *ar = hw->priv;
3960 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3961 struct ath10k_peer *peer;
3962 const u8 *peer_addr;
3963 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3964 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3965 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01003966 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003967
3968 if (key->keyidx > WMI_MAX_KEY_INDEX)
3969 return -ENOSPC;
3970
3971 mutex_lock(&ar->conf_mutex);
3972
3973 if (sta)
3974 peer_addr = sta->addr;
3975 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3976 peer_addr = vif->bss_conf.bssid;
3977 else
3978 peer_addr = vif->addr;
3979
3980 key->hw_key_idx = key->keyidx;
3981
3982 /* the peer should not disappear in mid-way (unless FW goes awry) since
3983 * we already hold conf_mutex. we just make sure its there now. */
3984 spin_lock_bh(&ar->data_lock);
3985 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3986 spin_unlock_bh(&ar->data_lock);
3987
3988 if (!peer) {
3989 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003990 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003991 peer_addr);
3992 ret = -EOPNOTSUPP;
3993 goto exit;
3994 } else {
3995 /* if the peer doesn't exist there is no key to disable
3996 * anymore */
3997 goto exit;
3998 }
3999 }
4000
4001 if (is_wep) {
4002 if (cmd == SET_KEY)
4003 arvif->wep_keys[key->keyidx] = key;
4004 else
4005 arvif->wep_keys[key->keyidx] = NULL;
4006
4007 if (cmd == DISABLE_KEY)
4008 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004009
Michal Kaziorad325cb2015-02-18 14:02:27 +01004010 /* When WEP keys are uploaded it's possible that there are
4011 * stations associated already (e.g. when merging) without any
4012 * keys. Static WEP needs an explicit per-peer key upload.
4013 */
4014 if (vif->type == NL80211_IFTYPE_ADHOC &&
4015 cmd == SET_KEY)
4016 ath10k_mac_vif_update_wep_key(arvif, key);
4017
Michal Kazior370e5672015-02-18 14:02:26 +01004018 /* 802.1x never sets the def_wep_key_idx so each set_key()
4019 * call changes default tx key.
4020 *
4021 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4022 * after first set_key().
4023 */
4024 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4025 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 }
4027
Michal Kazior370e5672015-02-18 14:02:26 +01004028 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4029 flags |= WMI_KEY_PAIRWISE;
4030 else
4031 flags |= WMI_KEY_GROUP;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004032
Michal Kazior370e5672015-02-18 14:02:26 +01004033 /* mac80211 uploads static WEP keys as groupwise while fw/hw requires
4034 * pairwise keys for non-self peers, i.e. BSSID in STA mode and
4035 * associated stations in AP/IBSS.
4036 *
4037 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys work
4038 * fine when mapped directly from mac80211.
4039 *
4040 * Note: When installing first static WEP groupwise key (which should
4041 * be pairwise) def_wep_key_idx isn't known yet (it's equal to -1).
4042 * Since .set_default_unicast_key is called only for static WEP it's
4043 * used to re-upload the key as pairwise.
4044 */
4045 if (arvif->def_wep_key_idx >= 0 &&
4046 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4047 flags &= ~WMI_KEY_GROUP;
4048 flags |= WMI_KEY_PAIRWISE;
4049 }
4050
4051 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004052 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004053 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004054 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004055 goto exit;
4056 }
4057
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004058 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4059
Kalle Valo5e3dd152013-06-12 20:52:10 +03004060 spin_lock_bh(&ar->data_lock);
4061 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4062 if (peer && cmd == SET_KEY)
4063 peer->keys[key->keyidx] = key;
4064 else if (peer && cmd == DISABLE_KEY)
4065 peer->keys[key->keyidx] = NULL;
4066 else if (peer == NULL)
4067 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004068 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004069 spin_unlock_bh(&ar->data_lock);
4070
4071exit:
4072 mutex_unlock(&ar->conf_mutex);
4073 return ret;
4074}
4075
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004076static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4077 struct ieee80211_vif *vif,
4078 int keyidx)
4079{
4080 struct ath10k *ar = hw->priv;
4081 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4082 int ret;
4083
4084 mutex_lock(&arvif->ar->conf_mutex);
4085
4086 if (arvif->ar->state != ATH10K_STATE_ON)
4087 goto unlock;
4088
4089 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4090 arvif->vdev_id, keyidx);
4091
4092 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4093 arvif->vdev_id,
4094 arvif->ar->wmi.vdev_param->def_keyid,
4095 keyidx);
4096
4097 if (ret) {
4098 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4099 arvif->vdev_id,
4100 ret);
4101 goto unlock;
4102 }
4103
4104 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004105
4106 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4107 if (ret) {
4108 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4109 arvif->vdev_id, ret);
4110 goto unlock;
4111 }
4112
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004113unlock:
4114 mutex_unlock(&arvif->ar->conf_mutex);
4115}
4116
Michal Kazior9797feb2014-02-14 14:49:48 +01004117static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4118{
4119 struct ath10k *ar;
4120 struct ath10k_vif *arvif;
4121 struct ath10k_sta *arsta;
4122 struct ieee80211_sta *sta;
4123 u32 changed, bw, nss, smps;
4124 int err;
4125
4126 arsta = container_of(wk, struct ath10k_sta, update_wk);
4127 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4128 arvif = arsta->arvif;
4129 ar = arvif->ar;
4130
4131 spin_lock_bh(&ar->data_lock);
4132
4133 changed = arsta->changed;
4134 arsta->changed = 0;
4135
4136 bw = arsta->bw;
4137 nss = arsta->nss;
4138 smps = arsta->smps;
4139
4140 spin_unlock_bh(&ar->data_lock);
4141
4142 mutex_lock(&ar->conf_mutex);
4143
4144 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004146 sta->addr, bw);
4147
4148 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4149 WMI_PEER_CHAN_WIDTH, bw);
4150 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004151 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004152 sta->addr, bw, err);
4153 }
4154
4155 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004156 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004157 sta->addr, nss);
4158
4159 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4160 WMI_PEER_NSS, nss);
4161 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004162 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004163 sta->addr, nss, err);
4164 }
4165
4166 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004167 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004168 sta->addr, smps);
4169
4170 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4171 WMI_PEER_SMPS_STATE, smps);
4172 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004173 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004174 sta->addr, smps, err);
4175 }
4176
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004177 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4178 changed & IEEE80211_RC_NSS_CHANGED) {
4179 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004180 sta->addr);
4181
Michal Kazior590922a2014-10-21 10:10:29 +03004182 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004183 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004184 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004185 sta->addr);
4186 }
4187
Michal Kazior9797feb2014-02-14 14:49:48 +01004188 mutex_unlock(&ar->conf_mutex);
4189}
4190
Michal Kaziorcfd10612014-11-25 15:16:05 +01004191static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4192{
4193 struct ath10k *ar = arvif->ar;
4194
4195 lockdep_assert_held(&ar->conf_mutex);
4196
4197 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4198 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4199 return 0;
4200
4201 if (ar->num_stations >= ar->max_num_stations)
4202 return -ENOBUFS;
4203
4204 ar->num_stations++;
4205
4206 return 0;
4207}
4208
4209static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4210{
4211 struct ath10k *ar = arvif->ar;
4212
4213 lockdep_assert_held(&ar->conf_mutex);
4214
4215 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4216 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4217 return;
4218
4219 ar->num_stations--;
4220}
4221
Kalle Valo5e3dd152013-06-12 20:52:10 +03004222static int ath10k_sta_state(struct ieee80211_hw *hw,
4223 struct ieee80211_vif *vif,
4224 struct ieee80211_sta *sta,
4225 enum ieee80211_sta_state old_state,
4226 enum ieee80211_sta_state new_state)
4227{
4228 struct ath10k *ar = hw->priv;
4229 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004230 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004231 int ret = 0;
4232
Michal Kazior76f90022014-02-25 09:29:57 +02004233 if (old_state == IEEE80211_STA_NOTEXIST &&
4234 new_state == IEEE80211_STA_NONE) {
4235 memset(arsta, 0, sizeof(*arsta));
4236 arsta->arvif = arvif;
4237 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4238 }
4239
Michal Kazior9797feb2014-02-14 14:49:48 +01004240 /* cancel must be done outside the mutex to avoid deadlock */
4241 if ((old_state == IEEE80211_STA_NONE &&
4242 new_state == IEEE80211_STA_NOTEXIST))
4243 cancel_work_sync(&arsta->update_wk);
4244
Kalle Valo5e3dd152013-06-12 20:52:10 +03004245 mutex_lock(&ar->conf_mutex);
4246
4247 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004248 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004249 /*
4250 * New station addition.
4251 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004252 ath10k_dbg(ar, ATH10K_DBG_MAC,
4253 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4254 arvif->vdev_id, sta->addr,
4255 ar->num_stations + 1, ar->max_num_stations,
4256 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004257
Michal Kaziorcfd10612014-11-25 15:16:05 +01004258 ret = ath10k_mac_inc_num_stations(arvif);
4259 if (ret) {
4260 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4261 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004262 goto exit;
4263 }
4264
Kalle Valo5e3dd152013-06-12 20:52:10 +03004265 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004266 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004267 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 -08004268 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004269 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004270 goto exit;
4271 }
Michal Kazior077efc82014-10-21 10:10:29 +03004272
4273 if (vif->type == NL80211_IFTYPE_STATION) {
4274 WARN_ON(arvif->is_started);
4275
4276 ret = ath10k_vdev_start(arvif);
4277 if (ret) {
4278 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4279 arvif->vdev_id, ret);
4280 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4281 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004282 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004283 goto exit;
4284 }
4285
4286 arvif->is_started = true;
4287 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004288 } else if ((old_state == IEEE80211_STA_NONE &&
4289 new_state == IEEE80211_STA_NOTEXIST)) {
4290 /*
4291 * Existing station deletion.
4292 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004293 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004294 "mac vdev %d peer delete %pM (sta gone)\n",
4295 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004296
4297 if (vif->type == NL80211_IFTYPE_STATION) {
4298 WARN_ON(!arvif->is_started);
4299
4300 ret = ath10k_vdev_stop(arvif);
4301 if (ret)
4302 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4303 arvif->vdev_id, ret);
4304
4305 arvif->is_started = false;
4306 }
4307
Kalle Valo5e3dd152013-06-12 20:52:10 +03004308 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4309 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004310 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004311 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004312
Michal Kaziorcfd10612014-11-25 15:16:05 +01004313 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004314 } else if (old_state == IEEE80211_STA_AUTH &&
4315 new_state == IEEE80211_STA_ASSOC &&
4316 (vif->type == NL80211_IFTYPE_AP ||
4317 vif->type == NL80211_IFTYPE_ADHOC)) {
4318 /*
4319 * New association.
4320 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004321 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004322 sta->addr);
4323
Michal Kazior590922a2014-10-21 10:10:29 +03004324 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004325 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004326 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004327 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004328 } else if (old_state == IEEE80211_STA_ASSOC &&
4329 new_state == IEEE80211_STA_AUTH &&
4330 (vif->type == NL80211_IFTYPE_AP ||
4331 vif->type == NL80211_IFTYPE_ADHOC)) {
4332 /*
4333 * Disassociation.
4334 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004335 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004336 sta->addr);
4337
Michal Kazior590922a2014-10-21 10:10:29 +03004338 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004339 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004340 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004341 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004342 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004343exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004344 mutex_unlock(&ar->conf_mutex);
4345 return ret;
4346}
4347
4348static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004349 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004350{
4351 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004352 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4353 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004354 u32 value = 0;
4355 int ret = 0;
4356
Michal Kazior548db542013-07-05 16:15:15 +03004357 lockdep_assert_held(&ar->conf_mutex);
4358
Kalle Valo5e3dd152013-06-12 20:52:10 +03004359 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4360 return 0;
4361
4362 switch (ac) {
4363 case IEEE80211_AC_VO:
4364 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4365 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004366 prio = 7;
4367 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004368 break;
4369 case IEEE80211_AC_VI:
4370 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4371 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004372 prio = 5;
4373 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004374 break;
4375 case IEEE80211_AC_BE:
4376 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4377 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004378 prio = 2;
4379 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004380 break;
4381 case IEEE80211_AC_BK:
4382 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4383 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004384 prio = 0;
4385 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004386 break;
4387 }
4388
4389 if (enable)
4390 arvif->u.sta.uapsd |= value;
4391 else
4392 arvif->u.sta.uapsd &= ~value;
4393
4394 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4395 WMI_STA_PS_PARAM_UAPSD,
4396 arvif->u.sta.uapsd);
4397 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004398 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004399 goto exit;
4400 }
4401
4402 if (arvif->u.sta.uapsd)
4403 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4404 else
4405 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4406
4407 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4408 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4409 value);
4410 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004411 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412
Michal Kazior9f9b5742014-12-12 12:41:36 +01004413 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4414 if (ret) {
4415 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4416 arvif->vdev_id, ret);
4417 return ret;
4418 }
4419
4420 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4421 if (ret) {
4422 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4423 arvif->vdev_id, ret);
4424 return ret;
4425 }
4426
Michal Kaziorb0e56152015-01-24 12:14:52 +02004427 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4428 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4429 /* Only userspace can make an educated decision when to send
4430 * trigger frame. The following effectively disables u-UAPSD
4431 * autotrigger in firmware (which is enabled by default
4432 * provided the autotrigger service is available).
4433 */
4434
4435 arg.wmm_ac = acc;
4436 arg.user_priority = prio;
4437 arg.service_interval = 0;
4438 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4439 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4440
4441 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4442 arvif->bssid, &arg, 1);
4443 if (ret) {
4444 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4445 ret);
4446 return ret;
4447 }
4448 }
4449
Kalle Valo5e3dd152013-06-12 20:52:10 +03004450exit:
4451 return ret;
4452}
4453
4454static int ath10k_conf_tx(struct ieee80211_hw *hw,
4455 struct ieee80211_vif *vif, u16 ac,
4456 const struct ieee80211_tx_queue_params *params)
4457{
4458 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004459 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004460 struct wmi_wmm_params_arg *p = NULL;
4461 int ret;
4462
4463 mutex_lock(&ar->conf_mutex);
4464
4465 switch (ac) {
4466 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004467 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004468 break;
4469 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004470 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004471 break;
4472 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004473 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004474 break;
4475 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004476 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004477 break;
4478 }
4479
4480 if (WARN_ON(!p)) {
4481 ret = -EINVAL;
4482 goto exit;
4483 }
4484
4485 p->cwmin = params->cw_min;
4486 p->cwmax = params->cw_max;
4487 p->aifs = params->aifs;
4488
4489 /*
4490 * The channel time duration programmed in the HW is in absolute
4491 * microseconds, while mac80211 gives the txop in units of
4492 * 32 microseconds.
4493 */
4494 p->txop = params->txop * 32;
4495
Michal Kazior7fc979a2015-01-28 09:57:28 +02004496 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4497 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4498 &arvif->wmm_params);
4499 if (ret) {
4500 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4501 arvif->vdev_id, ret);
4502 goto exit;
4503 }
4504 } else {
4505 /* This won't work well with multi-interface cases but it's
4506 * better than nothing.
4507 */
4508 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4509 if (ret) {
4510 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4511 goto exit;
4512 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004513 }
4514
4515 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4516 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004517 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004518
4519exit:
4520 mutex_unlock(&ar->conf_mutex);
4521 return ret;
4522}
4523
4524#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4525
4526static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4527 struct ieee80211_vif *vif,
4528 struct ieee80211_channel *chan,
4529 int duration,
4530 enum ieee80211_roc_type type)
4531{
4532 struct ath10k *ar = hw->priv;
4533 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4534 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004535 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004536
4537 mutex_lock(&ar->conf_mutex);
4538
4539 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004540 switch (ar->scan.state) {
4541 case ATH10K_SCAN_IDLE:
4542 reinit_completion(&ar->scan.started);
4543 reinit_completion(&ar->scan.completed);
4544 reinit_completion(&ar->scan.on_channel);
4545 ar->scan.state = ATH10K_SCAN_STARTING;
4546 ar->scan.is_roc = true;
4547 ar->scan.vdev_id = arvif->vdev_id;
4548 ar->scan.roc_freq = chan->center_freq;
4549 ret = 0;
4550 break;
4551 case ATH10K_SCAN_STARTING:
4552 case ATH10K_SCAN_RUNNING:
4553 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004554 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004555 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004557 spin_unlock_bh(&ar->data_lock);
4558
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004559 if (ret)
4560 goto exit;
4561
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004562 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4563
Kalle Valo5e3dd152013-06-12 20:52:10 +03004564 memset(&arg, 0, sizeof(arg));
4565 ath10k_wmi_start_scan_init(ar, &arg);
4566 arg.vdev_id = arvif->vdev_id;
4567 arg.scan_id = ATH10K_SCAN_ID;
4568 arg.n_channels = 1;
4569 arg.channels[0] = chan->center_freq;
4570 arg.dwell_time_active = duration;
4571 arg.dwell_time_passive = duration;
4572 arg.max_scan_time = 2 * duration;
4573 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4574 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4575
4576 ret = ath10k_start_scan(ar, &arg);
4577 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004578 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004579 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004580 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004581 spin_unlock_bh(&ar->data_lock);
4582 goto exit;
4583 }
4584
4585 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4586 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004587 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004588
4589 ret = ath10k_scan_stop(ar);
4590 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004591 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004592
Kalle Valo5e3dd152013-06-12 20:52:10 +03004593 ret = -ETIMEDOUT;
4594 goto exit;
4595 }
4596
4597 ret = 0;
4598exit:
4599 mutex_unlock(&ar->conf_mutex);
4600 return ret;
4601}
4602
4603static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4604{
4605 struct ath10k *ar = hw->priv;
4606
4607 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004608 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004609 mutex_unlock(&ar->conf_mutex);
4610
Michal Kazior4eb2e162014-10-28 10:23:09 +01004611 cancel_delayed_work_sync(&ar->scan.timeout);
4612
Kalle Valo5e3dd152013-06-12 20:52:10 +03004613 return 0;
4614}
4615
4616/*
4617 * Both RTS and Fragmentation threshold are interface-specific
4618 * in ath10k, but device-specific in mac80211.
4619 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004620
4621static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4622{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004623 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004624 struct ath10k_vif *arvif;
4625 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004626
Michal Kaziorad088bf2013-10-16 15:44:46 +03004627 mutex_lock(&ar->conf_mutex);
4628 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004629 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004630 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004631
Michal Kaziorad088bf2013-10-16 15:44:46 +03004632 ret = ath10k_mac_set_rts(arvif, value);
4633 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004634 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004635 arvif->vdev_id, ret);
4636 break;
4637 }
4638 }
4639 mutex_unlock(&ar->conf_mutex);
4640
4641 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004642}
4643
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004644static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4645 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004646{
4647 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004648 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004649 int ret;
4650
4651 /* mac80211 doesn't care if we really xmit queued frames or not
4652 * we'll collect those frames either way if we stop/delete vdevs */
4653 if (drop)
4654 return;
4655
Michal Kazior548db542013-07-05 16:15:15 +03004656 mutex_lock(&ar->conf_mutex);
4657
Michal Kazioraffd3212013-07-16 09:54:35 +02004658 if (ar->state == ATH10K_STATE_WEDGED)
4659 goto skip;
4660
Michal Kazioredb82362013-07-05 16:15:14 +03004661 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004662 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004663
Michal Kazioredb82362013-07-05 16:15:14 +03004664 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004665 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004666 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004667
Michal Kazior7962b0d2014-10-28 10:34:38 +01004668 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4669 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4670 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004671
4672 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004674
4675 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004676 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004677 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004678
Michal Kazioraffd3212013-07-16 09:54:35 +02004679skip:
Michal Kazior548db542013-07-05 16:15:15 +03004680 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004681}
4682
4683/* TODO: Implement this function properly
4684 * For now it is needed to reply to Probe Requests in IBSS mode.
4685 * Propably we need this information from FW.
4686 */
4687static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4688{
4689 return 1;
4690}
4691
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004692#ifdef CONFIG_PM
4693static int ath10k_suspend(struct ieee80211_hw *hw,
4694 struct cfg80211_wowlan *wowlan)
4695{
4696 struct ath10k *ar = hw->priv;
4697 int ret;
4698
Marek Puzyniak9042e172014-02-10 17:14:23 +01004699 mutex_lock(&ar->conf_mutex);
4700
Marek Puzyniak00f54822014-02-10 17:14:24 +01004701 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004702 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004703 if (ret == -ETIMEDOUT)
4704 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004705 ret = 1;
4706 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004707 }
4708
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004709 ret = ath10k_hif_suspend(ar);
4710 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004711 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004712 goto resume;
4713 }
4714
Marek Puzyniak9042e172014-02-10 17:14:23 +01004715 ret = 0;
4716 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004717resume:
4718 ret = ath10k_wmi_pdev_resume_target(ar);
4719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004720 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004721
4722 ret = 1;
4723exit:
4724 mutex_unlock(&ar->conf_mutex);
4725 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004726}
4727
4728static int ath10k_resume(struct ieee80211_hw *hw)
4729{
4730 struct ath10k *ar = hw->priv;
4731 int ret;
4732
Marek Puzyniak9042e172014-02-10 17:14:23 +01004733 mutex_lock(&ar->conf_mutex);
4734
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004735 ret = ath10k_hif_resume(ar);
4736 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004737 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004738 ret = 1;
4739 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004740 }
4741
4742 ret = ath10k_wmi_pdev_resume_target(ar);
4743 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004744 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004745 ret = 1;
4746 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004747 }
4748
Marek Puzyniak9042e172014-02-10 17:14:23 +01004749 ret = 0;
4750exit:
4751 mutex_unlock(&ar->conf_mutex);
4752 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004753}
4754#endif
4755
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004756static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4757 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004758{
4759 struct ath10k *ar = hw->priv;
4760
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004761 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4762 return;
4763
Michal Kazioraffd3212013-07-16 09:54:35 +02004764 mutex_lock(&ar->conf_mutex);
4765
4766 /* If device failed to restart it will be in a different state, e.g.
4767 * ATH10K_STATE_WEDGED */
4768 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004769 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004770 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004771 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004772 }
4773
4774 mutex_unlock(&ar->conf_mutex);
4775}
4776
Michal Kazior2e1dea42013-07-31 10:32:40 +02004777static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4778 struct survey_info *survey)
4779{
4780 struct ath10k *ar = hw->priv;
4781 struct ieee80211_supported_band *sband;
4782 struct survey_info *ar_survey = &ar->survey[idx];
4783 int ret = 0;
4784
4785 mutex_lock(&ar->conf_mutex);
4786
4787 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4788 if (sband && idx >= sband->n_channels) {
4789 idx -= sband->n_channels;
4790 sband = NULL;
4791 }
4792
4793 if (!sband)
4794 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4795
4796 if (!sband || idx >= sband->n_channels) {
4797 ret = -ENOENT;
4798 goto exit;
4799 }
4800
4801 spin_lock_bh(&ar->data_lock);
4802 memcpy(survey, ar_survey, sizeof(*survey));
4803 spin_unlock_bh(&ar->data_lock);
4804
4805 survey->channel = &sband->channels[idx];
4806
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004807 if (ar->rx_channel == survey->channel)
4808 survey->filled |= SURVEY_INFO_IN_USE;
4809
Michal Kazior2e1dea42013-07-31 10:32:40 +02004810exit:
4811 mutex_unlock(&ar->conf_mutex);
4812 return ret;
4813}
4814
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004815/* Helper table for legacy fixed_rate/bitrate_mask */
4816static const u8 cck_ofdm_rate[] = {
4817 /* CCK */
4818 3, /* 1Mbps */
4819 2, /* 2Mbps */
4820 1, /* 5.5Mbps */
4821 0, /* 11Mbps */
4822 /* OFDM */
4823 3, /* 6Mbps */
4824 7, /* 9Mbps */
4825 2, /* 12Mbps */
4826 6, /* 18Mbps */
4827 1, /* 24Mbps */
4828 5, /* 36Mbps */
4829 0, /* 48Mbps */
4830 4, /* 54Mbps */
4831};
4832
4833/* Check if only one bit set */
4834static int ath10k_check_single_mask(u32 mask)
4835{
4836 int bit;
4837
4838 bit = ffs(mask);
4839 if (!bit)
4840 return 0;
4841
4842 mask &= ~BIT(bit - 1);
4843 if (mask)
4844 return 2;
4845
4846 return 1;
4847}
4848
4849static bool
4850ath10k_default_bitrate_mask(struct ath10k *ar,
4851 enum ieee80211_band band,
4852 const struct cfg80211_bitrate_mask *mask)
4853{
4854 u32 legacy = 0x00ff;
4855 u8 ht = 0xff, i;
4856 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004857 u16 nrf = ar->num_rf_chains;
4858
4859 if (ar->cfg_tx_chainmask)
4860 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004861
4862 switch (band) {
4863 case IEEE80211_BAND_2GHZ:
4864 legacy = 0x00fff;
4865 vht = 0;
4866 break;
4867 case IEEE80211_BAND_5GHZ:
4868 break;
4869 default:
4870 return false;
4871 }
4872
4873 if (mask->control[band].legacy != legacy)
4874 return false;
4875
Ben Greearb116ea12014-11-24 16:22:10 +02004876 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004877 if (mask->control[band].ht_mcs[i] != ht)
4878 return false;
4879
Ben Greearb116ea12014-11-24 16:22:10 +02004880 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004881 if (mask->control[band].vht_mcs[i] != vht)
4882 return false;
4883
4884 return true;
4885}
4886
4887static bool
4888ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4889 enum ieee80211_band band,
4890 u8 *fixed_nss)
4891{
4892 int ht_nss = 0, vht_nss = 0, i;
4893
4894 /* check legacy */
4895 if (ath10k_check_single_mask(mask->control[band].legacy))
4896 return false;
4897
4898 /* check HT */
4899 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4900 if (mask->control[band].ht_mcs[i] == 0xff)
4901 continue;
4902 else if (mask->control[band].ht_mcs[i] == 0x00)
4903 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004904
4905 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004906 }
4907
4908 ht_nss = i;
4909
4910 /* check VHT */
4911 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4912 if (mask->control[band].vht_mcs[i] == 0x03ff)
4913 continue;
4914 else if (mask->control[band].vht_mcs[i] == 0x0000)
4915 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004916
4917 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004918 }
4919
4920 vht_nss = i;
4921
4922 if (ht_nss > 0 && vht_nss > 0)
4923 return false;
4924
4925 if (ht_nss)
4926 *fixed_nss = ht_nss;
4927 else if (vht_nss)
4928 *fixed_nss = vht_nss;
4929 else
4930 return false;
4931
4932 return true;
4933}
4934
4935static bool
4936ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4937 enum ieee80211_band band,
4938 enum wmi_rate_preamble *preamble)
4939{
4940 int legacy = 0, ht = 0, vht = 0, i;
4941
4942 *preamble = WMI_RATE_PREAMBLE_OFDM;
4943
4944 /* check legacy */
4945 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4946 if (legacy > 1)
4947 return false;
4948
4949 /* check HT */
4950 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4951 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4952 if (ht > 1)
4953 return false;
4954
4955 /* check VHT */
4956 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4957 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4958 if (vht > 1)
4959 return false;
4960
4961 /* Currently we support only one fixed_rate */
4962 if ((legacy + ht + vht) != 1)
4963 return false;
4964
4965 if (ht)
4966 *preamble = WMI_RATE_PREAMBLE_HT;
4967 else if (vht)
4968 *preamble = WMI_RATE_PREAMBLE_VHT;
4969
4970 return true;
4971}
4972
4973static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004974ath10k_bitrate_mask_rate(struct ath10k *ar,
4975 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004976 enum ieee80211_band band,
4977 u8 *fixed_rate,
4978 u8 *fixed_nss)
4979{
4980 u8 rate = 0, pream = 0, nss = 0, i;
4981 enum wmi_rate_preamble preamble;
4982
4983 /* Check if single rate correct */
4984 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4985 return false;
4986
4987 pream = preamble;
4988
4989 switch (preamble) {
4990 case WMI_RATE_PREAMBLE_CCK:
4991 case WMI_RATE_PREAMBLE_OFDM:
4992 i = ffs(mask->control[band].legacy) - 1;
4993
4994 if (band == IEEE80211_BAND_2GHZ && i < 4)
4995 pream = WMI_RATE_PREAMBLE_CCK;
4996
4997 if (band == IEEE80211_BAND_5GHZ)
4998 i += 4;
4999
5000 if (i >= ARRAY_SIZE(cck_ofdm_rate))
5001 return false;
5002
5003 rate = cck_ofdm_rate[i];
5004 break;
5005 case WMI_RATE_PREAMBLE_HT:
5006 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5007 if (mask->control[band].ht_mcs[i])
5008 break;
5009
5010 if (i == IEEE80211_HT_MCS_MASK_LEN)
5011 return false;
5012
5013 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5014 nss = i;
5015 break;
5016 case WMI_RATE_PREAMBLE_VHT:
5017 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5018 if (mask->control[band].vht_mcs[i])
5019 break;
5020
5021 if (i == NL80211_VHT_NSS_MAX)
5022 return false;
5023
5024 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5025 nss = i;
5026 break;
5027 }
5028
5029 *fixed_nss = nss + 1;
5030 nss <<= 4;
5031 pream <<= 6;
5032
Michal Kazior7aa7a722014-08-25 12:09:38 +02005033 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 +01005034 pream, nss, rate);
5035
5036 *fixed_rate = pream | nss | rate;
5037
5038 return true;
5039}
5040
Michal Kazior7aa7a722014-08-25 12:09:38 +02005041static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5042 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005043 enum ieee80211_band band,
5044 u8 *fixed_rate,
5045 u8 *fixed_nss)
5046{
5047 /* First check full NSS mask, if we can simply limit NSS */
5048 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5049 return true;
5050
5051 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005052 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005053}
5054
5055static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5056 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005057 u8 fixed_nss,
5058 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005059{
5060 struct ath10k *ar = arvif->ar;
5061 u32 vdev_param;
5062 int ret = 0;
5063
5064 mutex_lock(&ar->conf_mutex);
5065
5066 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005067 arvif->fixed_nss == fixed_nss &&
5068 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005069 goto exit;
5070
5071 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005072 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005073
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005074 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005075 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005076
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005077 vdev_param = ar->wmi.vdev_param->fixed_rate;
5078 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5079 vdev_param, fixed_rate);
5080 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005081 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005082 fixed_rate, ret);
5083 ret = -EINVAL;
5084 goto exit;
5085 }
5086
5087 arvif->fixed_rate = fixed_rate;
5088
5089 vdev_param = ar->wmi.vdev_param->nss;
5090 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5091 vdev_param, fixed_nss);
5092
5093 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005094 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005095 fixed_nss, ret);
5096 ret = -EINVAL;
5097 goto exit;
5098 }
5099
5100 arvif->fixed_nss = fixed_nss;
5101
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005102 vdev_param = ar->wmi.vdev_param->sgi;
5103 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5104 force_sgi);
5105
5106 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005107 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005108 force_sgi, ret);
5109 ret = -EINVAL;
5110 goto exit;
5111 }
5112
5113 arvif->force_sgi = force_sgi;
5114
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005115exit:
5116 mutex_unlock(&ar->conf_mutex);
5117 return ret;
5118}
5119
5120static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5121 struct ieee80211_vif *vif,
5122 const struct cfg80211_bitrate_mask *mask)
5123{
5124 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5125 struct ath10k *ar = arvif->ar;
5126 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5127 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5128 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005129 u8 force_sgi;
5130
Ben Greearb116ea12014-11-24 16:22:10 +02005131 if (ar->cfg_tx_chainmask)
5132 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5133
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005134 force_sgi = mask->control[band].gi;
5135 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5136 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005137
5138 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005139 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005140 &fixed_rate,
5141 &fixed_nss))
5142 return -EINVAL;
5143 }
5144
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005145 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005146 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005147 return -EINVAL;
5148 }
5149
5150 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5151 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005152}
5153
Michal Kazior9797feb2014-02-14 14:49:48 +01005154static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5155 struct ieee80211_vif *vif,
5156 struct ieee80211_sta *sta,
5157 u32 changed)
5158{
5159 struct ath10k *ar = hw->priv;
5160 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5161 u32 bw, smps;
5162
5163 spin_lock_bh(&ar->data_lock);
5164
Michal Kazior7aa7a722014-08-25 12:09:38 +02005165 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005166 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5167 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5168 sta->smps_mode);
5169
5170 if (changed & IEEE80211_RC_BW_CHANGED) {
5171 bw = WMI_PEER_CHWIDTH_20MHZ;
5172
5173 switch (sta->bandwidth) {
5174 case IEEE80211_STA_RX_BW_20:
5175 bw = WMI_PEER_CHWIDTH_20MHZ;
5176 break;
5177 case IEEE80211_STA_RX_BW_40:
5178 bw = WMI_PEER_CHWIDTH_40MHZ;
5179 break;
5180 case IEEE80211_STA_RX_BW_80:
5181 bw = WMI_PEER_CHWIDTH_80MHZ;
5182 break;
5183 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005184 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005185 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005186 bw = WMI_PEER_CHWIDTH_20MHZ;
5187 break;
5188 }
5189
5190 arsta->bw = bw;
5191 }
5192
5193 if (changed & IEEE80211_RC_NSS_CHANGED)
5194 arsta->nss = sta->rx_nss;
5195
5196 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5197 smps = WMI_PEER_SMPS_PS_NONE;
5198
5199 switch (sta->smps_mode) {
5200 case IEEE80211_SMPS_AUTOMATIC:
5201 case IEEE80211_SMPS_OFF:
5202 smps = WMI_PEER_SMPS_PS_NONE;
5203 break;
5204 case IEEE80211_SMPS_STATIC:
5205 smps = WMI_PEER_SMPS_STATIC;
5206 break;
5207 case IEEE80211_SMPS_DYNAMIC:
5208 smps = WMI_PEER_SMPS_DYNAMIC;
5209 break;
5210 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005211 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005212 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005213 smps = WMI_PEER_SMPS_PS_NONE;
5214 break;
5215 }
5216
5217 arsta->smps = smps;
5218 }
5219
Michal Kazior9797feb2014-02-14 14:49:48 +01005220 arsta->changed |= changed;
5221
5222 spin_unlock_bh(&ar->data_lock);
5223
5224 ieee80211_queue_work(hw, &arsta->update_wk);
5225}
5226
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005227static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5228{
5229 /*
5230 * FIXME: Return 0 for time being. Need to figure out whether FW
5231 * has the API to fetch 64-bit local TSF
5232 */
5233
5234 return 0;
5235}
5236
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005237static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5238 struct ieee80211_vif *vif,
5239 enum ieee80211_ampdu_mlme_action action,
5240 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5241 u8 buf_size)
5242{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005243 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005244 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5245
Michal Kazior7aa7a722014-08-25 12:09:38 +02005246 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 +02005247 arvif->vdev_id, sta->addr, tid, action);
5248
5249 switch (action) {
5250 case IEEE80211_AMPDU_RX_START:
5251 case IEEE80211_AMPDU_RX_STOP:
5252 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5253 * creation/removal. Do we need to verify this?
5254 */
5255 return 0;
5256 case IEEE80211_AMPDU_TX_START:
5257 case IEEE80211_AMPDU_TX_STOP_CONT:
5258 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5259 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5260 case IEEE80211_AMPDU_TX_OPERATIONAL:
5261 /* Firmware offloads Tx aggregation entirely so deny mac80211
5262 * Tx aggregation requests.
5263 */
5264 return -EOPNOTSUPP;
5265 }
5266
5267 return -EINVAL;
5268}
5269
Kalle Valo5e3dd152013-06-12 20:52:10 +03005270static const struct ieee80211_ops ath10k_ops = {
5271 .tx = ath10k_tx,
5272 .start = ath10k_start,
5273 .stop = ath10k_stop,
5274 .config = ath10k_config,
5275 .add_interface = ath10k_add_interface,
5276 .remove_interface = ath10k_remove_interface,
5277 .configure_filter = ath10k_configure_filter,
5278 .bss_info_changed = ath10k_bss_info_changed,
5279 .hw_scan = ath10k_hw_scan,
5280 .cancel_hw_scan = ath10k_cancel_hw_scan,
5281 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005282 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005283 .sta_state = ath10k_sta_state,
5284 .conf_tx = ath10k_conf_tx,
5285 .remain_on_channel = ath10k_remain_on_channel,
5286 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5287 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005288 .flush = ath10k_flush,
5289 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005290 .set_antenna = ath10k_set_antenna,
5291 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005292 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005293 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005294 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005295 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005296 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005297 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005298 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5299 .get_et_stats = ath10k_debug_get_et_stats,
5300 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005301
5302 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5303
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005304#ifdef CONFIG_PM
5305 .suspend = ath10k_suspend,
5306 .resume = ath10k_resume,
5307#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005308#ifdef CONFIG_MAC80211_DEBUGFS
5309 .sta_add_debugfs = ath10k_sta_add_debugfs,
5310#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311};
5312
5313#define RATETAB_ENT(_rate, _rateid, _flags) { \
5314 .bitrate = (_rate), \
5315 .flags = (_flags), \
5316 .hw_value = (_rateid), \
5317}
5318
5319#define CHAN2G(_channel, _freq, _flags) { \
5320 .band = IEEE80211_BAND_2GHZ, \
5321 .hw_value = (_channel), \
5322 .center_freq = (_freq), \
5323 .flags = (_flags), \
5324 .max_antenna_gain = 0, \
5325 .max_power = 30, \
5326}
5327
5328#define CHAN5G(_channel, _freq, _flags) { \
5329 .band = IEEE80211_BAND_5GHZ, \
5330 .hw_value = (_channel), \
5331 .center_freq = (_freq), \
5332 .flags = (_flags), \
5333 .max_antenna_gain = 0, \
5334 .max_power = 30, \
5335}
5336
5337static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5338 CHAN2G(1, 2412, 0),
5339 CHAN2G(2, 2417, 0),
5340 CHAN2G(3, 2422, 0),
5341 CHAN2G(4, 2427, 0),
5342 CHAN2G(5, 2432, 0),
5343 CHAN2G(6, 2437, 0),
5344 CHAN2G(7, 2442, 0),
5345 CHAN2G(8, 2447, 0),
5346 CHAN2G(9, 2452, 0),
5347 CHAN2G(10, 2457, 0),
5348 CHAN2G(11, 2462, 0),
5349 CHAN2G(12, 2467, 0),
5350 CHAN2G(13, 2472, 0),
5351 CHAN2G(14, 2484, 0),
5352};
5353
5354static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005355 CHAN5G(36, 5180, 0),
5356 CHAN5G(40, 5200, 0),
5357 CHAN5G(44, 5220, 0),
5358 CHAN5G(48, 5240, 0),
5359 CHAN5G(52, 5260, 0),
5360 CHAN5G(56, 5280, 0),
5361 CHAN5G(60, 5300, 0),
5362 CHAN5G(64, 5320, 0),
5363 CHAN5G(100, 5500, 0),
5364 CHAN5G(104, 5520, 0),
5365 CHAN5G(108, 5540, 0),
5366 CHAN5G(112, 5560, 0),
5367 CHAN5G(116, 5580, 0),
5368 CHAN5G(120, 5600, 0),
5369 CHAN5G(124, 5620, 0),
5370 CHAN5G(128, 5640, 0),
5371 CHAN5G(132, 5660, 0),
5372 CHAN5G(136, 5680, 0),
5373 CHAN5G(140, 5700, 0),
5374 CHAN5G(149, 5745, 0),
5375 CHAN5G(153, 5765, 0),
5376 CHAN5G(157, 5785, 0),
5377 CHAN5G(161, 5805, 0),
5378 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005379};
5380
Michal Kazior91b12082014-12-12 12:41:35 +01005381/* Note: Be careful if you re-order these. There is code which depends on this
5382 * ordering.
5383 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384static struct ieee80211_rate ath10k_rates[] = {
5385 /* CCK */
5386 RATETAB_ENT(10, 0x82, 0),
5387 RATETAB_ENT(20, 0x84, 0),
5388 RATETAB_ENT(55, 0x8b, 0),
5389 RATETAB_ENT(110, 0x96, 0),
5390 /* OFDM */
5391 RATETAB_ENT(60, 0x0c, 0),
5392 RATETAB_ENT(90, 0x12, 0),
5393 RATETAB_ENT(120, 0x18, 0),
5394 RATETAB_ENT(180, 0x24, 0),
5395 RATETAB_ENT(240, 0x30, 0),
5396 RATETAB_ENT(360, 0x48, 0),
5397 RATETAB_ENT(480, 0x60, 0),
5398 RATETAB_ENT(540, 0x6c, 0),
5399};
5400
5401#define ath10k_a_rates (ath10k_rates + 4)
5402#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5403#define ath10k_g_rates (ath10k_rates + 0)
5404#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5405
Michal Kaziore7b54192014-08-07 11:03:27 +02005406struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005407{
5408 struct ieee80211_hw *hw;
5409 struct ath10k *ar;
5410
Michal Kaziore7b54192014-08-07 11:03:27 +02005411 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005412 if (!hw)
5413 return NULL;
5414
5415 ar = hw->priv;
5416 ar->hw = hw;
5417
5418 return ar;
5419}
5420
5421void ath10k_mac_destroy(struct ath10k *ar)
5422{
5423 ieee80211_free_hw(ar->hw);
5424}
5425
5426static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5427 {
5428 .max = 8,
5429 .types = BIT(NL80211_IFTYPE_STATION)
5430 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005431 },
5432 {
5433 .max = 3,
5434 .types = BIT(NL80211_IFTYPE_P2P_GO)
5435 },
5436 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005437 .max = 1,
5438 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5439 },
5440 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005441 .max = 7,
5442 .types = BIT(NL80211_IFTYPE_AP)
5443 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005444};
5445
Bartosz Markowskif2595092013-12-10 16:20:39 +01005446static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005447 {
5448 .max = 8,
5449 .types = BIT(NL80211_IFTYPE_AP)
5450 },
5451};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005452
5453static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5454 {
5455 .limits = ath10k_if_limits,
5456 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5457 .max_interfaces = 8,
5458 .num_different_channels = 1,
5459 .beacon_int_infra_match = true,
5460 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005461};
5462
5463static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005464 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005465 .limits = ath10k_10x_if_limits,
5466 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005467 .max_interfaces = 8,
5468 .num_different_channels = 1,
5469 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005470#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005471 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5472 BIT(NL80211_CHAN_WIDTH_20) |
5473 BIT(NL80211_CHAN_WIDTH_40) |
5474 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005475#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005476 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005477};
5478
5479static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5480{
5481 struct ieee80211_sta_vht_cap vht_cap = {0};
5482 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005483 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005484 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005485
5486 vht_cap.vht_supported = 1;
5487 vht_cap.cap = ar->vht_cap_info;
5488
Michal Kaziorbc657a362015-02-26 11:11:22 +01005489 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5490 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5491 val = ar->num_rf_chains - 1;
5492 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5493 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5494
5495 vht_cap.cap |= val;
5496 }
5497
5498 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5499 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5500 val = ar->num_rf_chains - 1;
5501 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5502 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5503
5504 vht_cap.cap |= val;
5505 }
5506
Michal Kazior8865bee42013-07-24 12:36:46 +02005507 mcs_map = 0;
5508 for (i = 0; i < 8; i++) {
5509 if (i < ar->num_rf_chains)
5510 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5511 else
5512 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5513 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005514
5515 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5516 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5517
5518 return vht_cap;
5519}
5520
5521static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5522{
5523 int i;
5524 struct ieee80211_sta_ht_cap ht_cap = {0};
5525
5526 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5527 return ht_cap;
5528
5529 ht_cap.ht_supported = 1;
5530 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5531 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5532 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5533 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5534 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5535
5536 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5537 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5538
5539 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5540 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5541
5542 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5543 u32 smps;
5544
5545 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5546 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5547
5548 ht_cap.cap |= smps;
5549 }
5550
5551 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5552 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5553
5554 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5555 u32 stbc;
5556
5557 stbc = ar->ht_cap_info;
5558 stbc &= WMI_HT_CAP_RX_STBC;
5559 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5560 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5561 stbc &= IEEE80211_HT_CAP_RX_STBC;
5562
5563 ht_cap.cap |= stbc;
5564 }
5565
5566 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5567 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5568
5569 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5570 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5571
5572 /* max AMSDU is implicitly taken from vht_cap_info */
5573 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5574 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5575
Michal Kazior8865bee42013-07-24 12:36:46 +02005576 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005577 ht_cap.mcs.rx_mask[i] = 0xFF;
5578
5579 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5580
5581 return ht_cap;
5582}
5583
Kalle Valo5e3dd152013-06-12 20:52:10 +03005584static void ath10k_get_arvif_iter(void *data, u8 *mac,
5585 struct ieee80211_vif *vif)
5586{
5587 struct ath10k_vif_iter *arvif_iter = data;
5588 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5589
5590 if (arvif->vdev_id == arvif_iter->vdev_id)
5591 arvif_iter->arvif = arvif;
5592}
5593
5594struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5595{
5596 struct ath10k_vif_iter arvif_iter;
5597 u32 flags;
5598
5599 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5600 arvif_iter.vdev_id = vdev_id;
5601
5602 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5603 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5604 flags,
5605 ath10k_get_arvif_iter,
5606 &arvif_iter);
5607 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005608 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005609 return NULL;
5610 }
5611
5612 return arvif_iter.arvif;
5613}
5614
5615int ath10k_mac_register(struct ath10k *ar)
5616{
Johannes Berg3cb10942015-01-22 21:38:45 +01005617 static const u32 cipher_suites[] = {
5618 WLAN_CIPHER_SUITE_WEP40,
5619 WLAN_CIPHER_SUITE_WEP104,
5620 WLAN_CIPHER_SUITE_TKIP,
5621 WLAN_CIPHER_SUITE_CCMP,
5622 WLAN_CIPHER_SUITE_AES_CMAC,
5623 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005624 struct ieee80211_supported_band *band;
5625 struct ieee80211_sta_vht_cap vht_cap;
5626 struct ieee80211_sta_ht_cap ht_cap;
5627 void *channels;
5628 int ret;
5629
5630 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5631
5632 SET_IEEE80211_DEV(ar->hw, ar->dev);
5633
5634 ht_cap = ath10k_get_ht_cap(ar);
5635 vht_cap = ath10k_create_vht_cap(ar);
5636
5637 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5638 channels = kmemdup(ath10k_2ghz_channels,
5639 sizeof(ath10k_2ghz_channels),
5640 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005641 if (!channels) {
5642 ret = -ENOMEM;
5643 goto err_free;
5644 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005645
5646 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5647 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5648 band->channels = channels;
5649 band->n_bitrates = ath10k_g_rates_size;
5650 band->bitrates = ath10k_g_rates;
5651 band->ht_cap = ht_cap;
5652
Yanbo Lid68bb122015-01-23 08:18:20 +08005653 /* Enable the VHT support at 2.4 GHz */
5654 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005655
5656 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5657 }
5658
5659 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5660 channels = kmemdup(ath10k_5ghz_channels,
5661 sizeof(ath10k_5ghz_channels),
5662 GFP_KERNEL);
5663 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005664 ret = -ENOMEM;
5665 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005666 }
5667
5668 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5669 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5670 band->channels = channels;
5671 band->n_bitrates = ath10k_a_rates_size;
5672 band->bitrates = ath10k_a_rates;
5673 band->ht_cap = ht_cap;
5674 band->vht_cap = vht_cap;
5675 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5676 }
5677
5678 ar->hw->wiphy->interface_modes =
5679 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005680 BIT(NL80211_IFTYPE_AP);
5681
Ben Greear46acf7b2014-05-16 17:15:38 +03005682 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5683 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5684
Bartosz Markowskid3541812013-12-10 16:20:40 +01005685 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5686 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005687 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005688 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5689 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005690
5691 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5692 IEEE80211_HW_SUPPORTS_PS |
5693 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005694 IEEE80211_HW_MFP_CAPABLE |
5695 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5696 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005697 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005698 IEEE80211_HW_SPECTRUM_MGMT |
5699 IEEE80211_HW_SW_CRYPTO_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005700
Eliad Peller0d8614b2014-09-10 14:07:36 +03005701 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5702
Kalle Valo5e3dd152013-06-12 20:52:10 +03005703 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005704 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005705
5706 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5707 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5708 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5709 }
5710
5711 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5712 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5713
5714 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005715 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005716
Kalle Valo5e3dd152013-06-12 20:52:10 +03005717 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5718
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005719 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5720 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5721
5722 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5723 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5724 * correct Probe Responses. This is more of a hack advert..
5725 */
5726 ar->hw->wiphy->probe_resp_offload |=
5727 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5728 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5729 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5730 }
5731
Kalle Valo5e3dd152013-06-12 20:52:10 +03005732 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005733 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005734 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5735
5736 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005737 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5738
Kalle Valo5e3dd152013-06-12 20:52:10 +03005739 /*
5740 * on LL hardware queues are managed entirely by the FW
5741 * so we only advertise to mac we can do the queues thing
5742 */
5743 ar->hw->queues = 4;
5744
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005745 switch (ar->wmi.op_version) {
5746 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5747 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005748 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5749 ar->hw->wiphy->n_iface_combinations =
5750 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005751 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005752 break;
5753 case ATH10K_FW_WMI_OP_VERSION_10_1:
5754 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005755 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005756 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5757 ar->hw->wiphy->n_iface_combinations =
5758 ARRAY_SIZE(ath10k_10x_if_comb);
5759 break;
5760 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5761 case ATH10K_FW_WMI_OP_VERSION_MAX:
5762 WARN_ON(1);
5763 ret = -EINVAL;
5764 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005765 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005766
Michal Kazior7c199992013-07-31 10:47:57 +02005767 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5768
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005769 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5770 /* Init ath dfs pattern detector */
5771 ar->ath_common.debug_mask = ATH_DBG_DFS;
5772 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5773 NL80211_DFS_UNSET);
5774
5775 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005776 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005777 }
5778
Kalle Valo5e3dd152013-06-12 20:52:10 +03005779 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5780 ath10k_reg_notifier);
5781 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005782 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005783 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005784 }
5785
Johannes Berg3cb10942015-01-22 21:38:45 +01005786 ar->hw->wiphy->cipher_suites = cipher_suites;
5787 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5788
Kalle Valo5e3dd152013-06-12 20:52:10 +03005789 ret = ieee80211_register_hw(ar->hw);
5790 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005791 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005792 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005793 }
5794
5795 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5796 ret = regulatory_hint(ar->hw->wiphy,
5797 ar->ath_common.regulatory.alpha2);
5798 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005799 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005800 }
5801
5802 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005803
5804err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005805 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005806err_free:
5807 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5808 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5809
Kalle Valo5e3dd152013-06-12 20:52:10 +03005810 return ret;
5811}
5812
5813void ath10k_mac_unregister(struct ath10k *ar)
5814{
5815 ieee80211_unregister_hw(ar->hw);
5816
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005817 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5818 ar->dfs_detector->exit(ar->dfs_detector);
5819
Kalle Valo5e3dd152013-06-12 20:52:10 +03005820 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5821 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5822
5823 SET_IEEE80211_DEV(ar->hw, NULL);
5824}