blob: 722ff38b042b122806f0b07306c08904ceae2e65 [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
Kalle Valo5e3dd152013-06-12 20:52:10 +0300300/*********************/
301/* General utilities */
302/*********************/
303
304static inline enum wmi_phy_mode
305chan_to_phymode(const struct cfg80211_chan_def *chandef)
306{
307 enum wmi_phy_mode phymode = MODE_UNKNOWN;
308
309 switch (chandef->chan->band) {
310 case IEEE80211_BAND_2GHZ:
311 switch (chandef->width) {
312 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800313 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
314 phymode = MODE_11B;
315 else
316 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300317 break;
318 case NL80211_CHAN_WIDTH_20:
319 phymode = MODE_11NG_HT20;
320 break;
321 case NL80211_CHAN_WIDTH_40:
322 phymode = MODE_11NG_HT40;
323 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400324 case NL80211_CHAN_WIDTH_5:
325 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300326 case NL80211_CHAN_WIDTH_80:
327 case NL80211_CHAN_WIDTH_80P80:
328 case NL80211_CHAN_WIDTH_160:
329 phymode = MODE_UNKNOWN;
330 break;
331 }
332 break;
333 case IEEE80211_BAND_5GHZ:
334 switch (chandef->width) {
335 case NL80211_CHAN_WIDTH_20_NOHT:
336 phymode = MODE_11A;
337 break;
338 case NL80211_CHAN_WIDTH_20:
339 phymode = MODE_11NA_HT20;
340 break;
341 case NL80211_CHAN_WIDTH_40:
342 phymode = MODE_11NA_HT40;
343 break;
344 case NL80211_CHAN_WIDTH_80:
345 phymode = MODE_11AC_VHT80;
346 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400347 case NL80211_CHAN_WIDTH_5:
348 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300349 case NL80211_CHAN_WIDTH_80P80:
350 case NL80211_CHAN_WIDTH_160:
351 phymode = MODE_UNKNOWN;
352 break;
353 }
354 break;
355 default:
356 break;
357 }
358
359 WARN_ON(phymode == MODE_UNKNOWN);
360 return phymode;
361}
362
363static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
364{
365/*
366 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
367 * 0 for no restriction
368 * 1 for 1/4 us
369 * 2 for 1/2 us
370 * 3 for 1 us
371 * 4 for 2 us
372 * 5 for 4 us
373 * 6 for 8 us
374 * 7 for 16 us
375 */
376 switch (mpdudensity) {
377 case 0:
378 return 0;
379 case 1:
380 case 2:
381 case 3:
382 /* Our lower layer calculations limit our precision to
383 1 microsecond */
384 return 1;
385 case 4:
386 return 2;
387 case 5:
388 return 4;
389 case 6:
390 return 8;
391 case 7:
392 return 16;
393 default:
394 return 0;
395 }
396}
397
398static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
399{
400 int ret;
401
402 lockdep_assert_held(&ar->conf_mutex);
403
Michal Kaziorcfd10612014-11-25 15:16:05 +0100404 if (ar->num_peers >= ar->max_num_peers)
405 return -ENOBUFS;
406
Kalle Valo5e3dd152013-06-12 20:52:10 +0300407 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800408 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200409 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200410 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300411 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800412 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300413
414 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800415 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200416 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200417 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300418 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800419 }
Michal Kazior292a7532014-11-25 15:16:04 +0100420
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100421 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300422
423 return 0;
424}
425
Kalle Valo5a13e762014-01-20 11:01:46 +0200426static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
427{
428 struct ath10k *ar = arvif->ar;
429 u32 param;
430 int ret;
431
432 param = ar->wmi.pdev_param->sta_kickout_th;
433 ret = ath10k_wmi_pdev_set_param(ar, param,
434 ATH10K_KICKOUT_THRESHOLD);
435 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200436 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200437 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200438 return ret;
439 }
440
441 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
442 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
443 ATH10K_KEEPALIVE_MIN_IDLE);
444 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200445 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200446 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200447 return ret;
448 }
449
450 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
452 ATH10K_KEEPALIVE_MAX_IDLE);
453 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200454 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200455 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200456 return ret;
457 }
458
459 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
460 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
461 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
462 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200463 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200464 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200465 return ret;
466 }
467
468 return 0;
469}
470
Vivek Natarajanacab6402014-11-26 09:06:12 +0200471static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200472{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200473 struct ath10k *ar = arvif->ar;
474 u32 vdev_param;
475
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200476 vdev_param = ar->wmi.vdev_param->rts_threshold;
477 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200478}
479
480static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
481{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200482 struct ath10k *ar = arvif->ar;
483 u32 vdev_param;
484
Michal Kazior424121c2013-07-22 14:13:31 +0200485 if (value != 0xFFFFFFFF)
486 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
487 ATH10K_FRAGMT_THRESHOLD_MIN,
488 ATH10K_FRAGMT_THRESHOLD_MAX);
489
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200490 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
491 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200492}
493
Kalle Valo5e3dd152013-06-12 20:52:10 +0300494static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
495{
496 int ret;
497
498 lockdep_assert_held(&ar->conf_mutex);
499
500 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
501 if (ret)
502 return ret;
503
504 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
505 if (ret)
506 return ret;
507
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100508 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100509
Kalle Valo5e3dd152013-06-12 20:52:10 +0300510 return 0;
511}
512
513static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
514{
515 struct ath10k_peer *peer, *tmp;
516
517 lockdep_assert_held(&ar->conf_mutex);
518
519 spin_lock_bh(&ar->data_lock);
520 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
521 if (peer->vdev_id != vdev_id)
522 continue;
523
Michal Kazior7aa7a722014-08-25 12:09:38 +0200524 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300525 peer->addr, vdev_id);
526
527 list_del(&peer->list);
528 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100529 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300530 }
531 spin_unlock_bh(&ar->data_lock);
532}
533
Michal Kaziora96d7742013-07-16 09:38:56 +0200534static void ath10k_peer_cleanup_all(struct ath10k *ar)
535{
536 struct ath10k_peer *peer, *tmp;
537
538 lockdep_assert_held(&ar->conf_mutex);
539
540 spin_lock_bh(&ar->data_lock);
541 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
542 list_del(&peer->list);
543 kfree(peer);
544 }
545 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100546
547 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100548 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200549}
550
Kalle Valo5e3dd152013-06-12 20:52:10 +0300551/************************/
552/* Interface management */
553/************************/
554
Michal Kazior64badcb2014-09-18 11:18:02 +0300555void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
556{
557 struct ath10k *ar = arvif->ar;
558
559 lockdep_assert_held(&ar->data_lock);
560
561 if (!arvif->beacon)
562 return;
563
564 if (!arvif->beacon_buf)
565 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
566 arvif->beacon->len, DMA_TO_DEVICE);
567
Michal Kazioraf213192015-01-29 14:29:52 +0200568 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
569 arvif->beacon_state != ATH10K_BEACON_SENT))
570 return;
571
Michal Kazior64badcb2014-09-18 11:18:02 +0300572 dev_kfree_skb_any(arvif->beacon);
573
574 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200575 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300576}
577
578static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
579{
580 struct ath10k *ar = arvif->ar;
581
582 lockdep_assert_held(&ar->data_lock);
583
584 ath10k_mac_vif_beacon_free(arvif);
585
586 if (arvif->beacon_buf) {
587 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
588 arvif->beacon_buf, arvif->beacon_paddr);
589 arvif->beacon_buf = NULL;
590 }
591}
592
Kalle Valo5e3dd152013-06-12 20:52:10 +0300593static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
594{
595 int ret;
596
Michal Kazior548db542013-07-05 16:15:15 +0300597 lockdep_assert_held(&ar->conf_mutex);
598
Michal Kazior7962b0d2014-10-28 10:34:38 +0100599 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
600 return -ESHUTDOWN;
601
Kalle Valo5e3dd152013-06-12 20:52:10 +0300602 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
603 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
604 if (ret == 0)
605 return -ETIMEDOUT;
606
607 return 0;
608}
609
Michal Kazior1bbc0972014-04-08 09:45:47 +0300610static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300611{
Michal Kaziorc930f742014-01-23 11:38:25 +0100612 struct cfg80211_chan_def *chandef = &ar->chandef;
613 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300614 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300615 int ret = 0;
616
617 lockdep_assert_held(&ar->conf_mutex);
618
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619 arg.vdev_id = vdev_id;
620 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100621 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300622
623 /* TODO setup this dynamically, what in case we
624 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100625 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200626 arg.channel.chan_radar =
627 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300628
Michal Kazior89c5c842013-10-23 04:02:13 -0700629 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700630 arg.channel.max_power = channel->max_power * 2;
631 arg.channel.max_reg_power = channel->max_reg_power * 2;
632 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300633
Michal Kazior7962b0d2014-10-28 10:34:38 +0100634 reinit_completion(&ar->vdev_setup_done);
635
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636 ret = ath10k_wmi_vdev_start(ar, &arg);
637 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200638 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200639 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300640 return ret;
641 }
642
643 ret = ath10k_vdev_setup_sync(ar);
644 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200645 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200646 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300647 return ret;
648 }
649
650 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
651 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200652 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200653 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300654 goto vdev_stop;
655 }
656
657 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300658
Michal Kazior7aa7a722014-08-25 12:09:38 +0200659 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300660 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300661 return 0;
662
663vdev_stop:
664 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
665 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200666 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200667 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300668
669 return ret;
670}
671
Michal Kazior1bbc0972014-04-08 09:45:47 +0300672static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300673{
674 int ret = 0;
675
676 lockdep_assert_held(&ar->conf_mutex);
677
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200678 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
679 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200680 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200681 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682
Michal Kazior7962b0d2014-10-28 10:34:38 +0100683 reinit_completion(&ar->vdev_setup_done);
684
Kalle Valo5e3dd152013-06-12 20:52:10 +0300685 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
686 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200687 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200688 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689
690 ret = ath10k_vdev_setup_sync(ar);
691 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200692 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200693 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694
Michal Kazior7aa7a722014-08-25 12:09:38 +0200695 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300696 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697 return ret;
698}
699
Michal Kazior1bbc0972014-04-08 09:45:47 +0300700static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300701{
702 int bit, ret = 0;
703
704 lockdep_assert_held(&ar->conf_mutex);
705
Ben Greeara9aefb32014-08-12 11:02:19 +0300706 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200707 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300708 return -ENOMEM;
709 }
710
Ben Greear16c11172014-09-23 14:17:16 -0700711 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300712
Ben Greear16c11172014-09-23 14:17:16 -0700713 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300714
715 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
716 WMI_VDEV_TYPE_MONITOR,
717 0, ar->mac_addr);
718 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200719 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200720 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300721 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300722 }
723
Ben Greear16c11172014-09-23 14:17:16 -0700724 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200725 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300726 ar->monitor_vdev_id);
727
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300729}
730
Michal Kazior1bbc0972014-04-08 09:45:47 +0300731static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300732{
733 int ret = 0;
734
735 lockdep_assert_held(&ar->conf_mutex);
736
Kalle Valo5e3dd152013-06-12 20:52:10 +0300737 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200739 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200740 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300741 return ret;
742 }
743
Ben Greear16c11172014-09-23 14:17:16 -0700744 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300745
Michal Kazior7aa7a722014-08-25 12:09:38 +0200746 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300747 ar->monitor_vdev_id);
748 return ret;
749}
750
Michal Kazior1bbc0972014-04-08 09:45:47 +0300751static int ath10k_monitor_start(struct ath10k *ar)
752{
753 int ret;
754
755 lockdep_assert_held(&ar->conf_mutex);
756
Michal Kazior1bbc0972014-04-08 09:45:47 +0300757 ret = ath10k_monitor_vdev_create(ar);
758 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200759 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300760 return ret;
761 }
762
763 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200765 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300766 ath10k_monitor_vdev_delete(ar);
767 return ret;
768 }
769
770 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200771 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300772
773 return 0;
774}
775
Michal Kazior19337472014-08-28 12:58:16 +0200776static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300777{
778 int ret;
779
780 lockdep_assert_held(&ar->conf_mutex);
781
Michal Kazior1bbc0972014-04-08 09:45:47 +0300782 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200783 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200784 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200785 return ret;
786 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300787
788 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200789 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200790 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200791 return ret;
792 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300793
794 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200795 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200796
797 return 0;
798}
799
800static int ath10k_monitor_recalc(struct ath10k *ar)
801{
802 bool should_start;
803
804 lockdep_assert_held(&ar->conf_mutex);
805
806 should_start = ar->monitor ||
807 ar->filter_flags & FIF_PROMISC_IN_BSS ||
808 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
809
810 ath10k_dbg(ar, ATH10K_DBG_MAC,
811 "mac monitor recalc started? %d should? %d\n",
812 ar->monitor_started, should_start);
813
814 if (should_start == ar->monitor_started)
815 return 0;
816
817 if (should_start)
818 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300819
820 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300821}
822
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200823static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
824{
825 struct ath10k *ar = arvif->ar;
826 u32 vdev_param, rts_cts = 0;
827
828 lockdep_assert_held(&ar->conf_mutex);
829
830 vdev_param = ar->wmi.vdev_param->enable_rtscts;
831
832 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
833 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
834
835 if (arvif->num_legacy_stations > 0)
836 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
837 WMI_RTSCTS_PROFILE);
838
839 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
840 rts_cts);
841}
842
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200843static int ath10k_start_cac(struct ath10k *ar)
844{
845 int ret;
846
847 lockdep_assert_held(&ar->conf_mutex);
848
849 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
850
Michal Kazior19337472014-08-28 12:58:16 +0200851 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200852 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200853 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200854 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
855 return ret;
856 }
857
Michal Kazior7aa7a722014-08-25 12:09:38 +0200858 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200859 ar->monitor_vdev_id);
860
861 return 0;
862}
863
864static int ath10k_stop_cac(struct ath10k *ar)
865{
866 lockdep_assert_held(&ar->conf_mutex);
867
868 /* CAC is not running - do nothing */
869 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
870 return 0;
871
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200872 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300873 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200874
Michal Kazior7aa7a722014-08-25 12:09:38 +0200875 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200876
877 return 0;
878}
879
Michal Kaziord6500972014-04-08 09:56:09 +0300880static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200881{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200882 int ret;
883
884 lockdep_assert_held(&ar->conf_mutex);
885
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200886 ath10k_stop_cac(ar);
887
Michal Kaziord6500972014-04-08 09:56:09 +0300888 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200889 return;
890
Michal Kaziord6500972014-04-08 09:56:09 +0300891 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200892 return;
893
894 ret = ath10k_start_cac(ar);
895 if (ret) {
896 /*
897 * Not possible to start CAC on current channel so starting
898 * radiation is not allowed, make this channel DFS_UNAVAILABLE
899 * by indicating that radar was detected.
900 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200901 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200902 ieee80211_radar_detected(ar->hw);
903 }
904}
905
Michal Kaziordc55e302014-07-29 12:53:36 +0300906static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300907{
908 struct ath10k *ar = arvif->ar;
909 struct cfg80211_chan_def *chandef = &ar->chandef;
910 struct wmi_vdev_start_request_arg arg = {};
911 int ret = 0;
912
913 lockdep_assert_held(&ar->conf_mutex);
914
915 reinit_completion(&ar->vdev_setup_done);
916
917 arg.vdev_id = arvif->vdev_id;
918 arg.dtim_period = arvif->dtim_period;
919 arg.bcn_intval = arvif->beacon_interval;
920
921 arg.channel.freq = chandef->chan->center_freq;
922 arg.channel.band_center_freq1 = chandef->center_freq1;
923 arg.channel.mode = chan_to_phymode(chandef);
924
925 arg.channel.min_power = 0;
926 arg.channel.max_power = chandef->chan->max_power * 2;
927 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
928 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
929
930 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
931 arg.ssid = arvif->u.ap.ssid;
932 arg.ssid_len = arvif->u.ap.ssid_len;
933 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
934
935 /* For now allow DFS for AP mode */
936 arg.channel.chan_radar =
937 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
938 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
939 arg.ssid = arvif->vif->bss_conf.ssid;
940 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
941 }
942
Michal Kazior7aa7a722014-08-25 12:09:38 +0200943 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300944 "mac vdev %d start center_freq %d phymode %s\n",
945 arg.vdev_id, arg.channel.freq,
946 ath10k_wmi_phymode_str(arg.channel.mode));
947
Michal Kaziordc55e302014-07-29 12:53:36 +0300948 if (restart)
949 ret = ath10k_wmi_vdev_restart(ar, &arg);
950 else
951 ret = ath10k_wmi_vdev_start(ar, &arg);
952
Michal Kazior72654fa2014-04-08 09:56:09 +0300953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200954 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300955 arg.vdev_id, ret);
956 return ret;
957 }
958
959 ret = ath10k_vdev_setup_sync(ar);
960 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200961 ath10k_warn(ar,
962 "failed to synchronize setup for vdev %i restart %d: %d\n",
963 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +0300964 return ret;
965 }
966
Michal Kaziord6500972014-04-08 09:56:09 +0300967 ar->num_started_vdevs++;
968 ath10k_recalc_radar_detection(ar);
969
Michal Kazior72654fa2014-04-08 09:56:09 +0300970 return ret;
971}
972
Michal Kaziordc55e302014-07-29 12:53:36 +0300973static int ath10k_vdev_start(struct ath10k_vif *arvif)
974{
975 return ath10k_vdev_start_restart(arvif, false);
976}
977
978static int ath10k_vdev_restart(struct ath10k_vif *arvif)
979{
980 return ath10k_vdev_start_restart(arvif, true);
981}
982
Michal Kazior72654fa2014-04-08 09:56:09 +0300983static int ath10k_vdev_stop(struct ath10k_vif *arvif)
984{
985 struct ath10k *ar = arvif->ar;
986 int ret;
987
988 lockdep_assert_held(&ar->conf_mutex);
989
990 reinit_completion(&ar->vdev_setup_done);
991
992 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
993 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200994 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300995 arvif->vdev_id, ret);
996 return ret;
997 }
998
999 ret = ath10k_vdev_setup_sync(ar);
1000 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001001 ath10k_warn(ar, "failed to synchronize setup for vdev %i stop: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001002 arvif->vdev_id, ret);
1003 return ret;
1004 }
1005
Michal Kaziord6500972014-04-08 09:56:09 +03001006 WARN_ON(ar->num_started_vdevs == 0);
1007
1008 if (ar->num_started_vdevs != 0) {
1009 ar->num_started_vdevs--;
1010 ath10k_recalc_radar_detection(ar);
1011 }
1012
Michal Kazior72654fa2014-04-08 09:56:09 +03001013 return ret;
1014}
1015
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001016static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1017 struct sk_buff *bcn)
1018{
1019 struct ath10k *ar = arvif->ar;
1020 struct ieee80211_mgmt *mgmt;
1021 const u8 *p2p_ie;
1022 int ret;
1023
1024 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1025 return 0;
1026
1027 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1028 return 0;
1029
1030 mgmt = (void *)bcn->data;
1031 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1032 mgmt->u.beacon.variable,
1033 bcn->len - (mgmt->u.beacon.variable -
1034 bcn->data));
1035 if (!p2p_ie)
1036 return -ENOENT;
1037
1038 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1039 if (ret) {
1040 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1041 arvif->vdev_id, ret);
1042 return ret;
1043 }
1044
1045 return 0;
1046}
1047
1048static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1049 u8 oui_type, size_t ie_offset)
1050{
1051 size_t len;
1052 const u8 *next;
1053 const u8 *end;
1054 u8 *ie;
1055
1056 if (WARN_ON(skb->len < ie_offset))
1057 return -EINVAL;
1058
1059 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1060 skb->data + ie_offset,
1061 skb->len - ie_offset);
1062 if (!ie)
1063 return -ENOENT;
1064
1065 len = ie[1] + 2;
1066 end = skb->data + skb->len;
1067 next = ie + len;
1068
1069 if (WARN_ON(next > end))
1070 return -EINVAL;
1071
1072 memmove(ie, next, end - next);
1073 skb_trim(skb, skb->len - len);
1074
1075 return 0;
1076}
1077
1078static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1079{
1080 struct ath10k *ar = arvif->ar;
1081 struct ieee80211_hw *hw = ar->hw;
1082 struct ieee80211_vif *vif = arvif->vif;
1083 struct ieee80211_mutable_offsets offs = {};
1084 struct sk_buff *bcn;
1085 int ret;
1086
1087 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1088 return 0;
1089
Michal Kazior81a9a172015-03-05 16:02:17 +02001090 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1091 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1092 return 0;
1093
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001094 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1095 if (!bcn) {
1096 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1097 return -EPERM;
1098 }
1099
1100 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1101 if (ret) {
1102 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1103 kfree_skb(bcn);
1104 return ret;
1105 }
1106
1107 /* P2P IE is inserted by firmware automatically (as configured above)
1108 * so remove it from the base beacon template to avoid duplicate P2P
1109 * IEs in beacon frames.
1110 */
1111 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1112 offsetof(struct ieee80211_mgmt,
1113 u.beacon.variable));
1114
1115 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1116 0, NULL, 0);
1117 kfree_skb(bcn);
1118
1119 if (ret) {
1120 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1121 ret);
1122 return ret;
1123 }
1124
1125 return 0;
1126}
1127
1128static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1129{
1130 struct ath10k *ar = arvif->ar;
1131 struct ieee80211_hw *hw = ar->hw;
1132 struct ieee80211_vif *vif = arvif->vif;
1133 struct sk_buff *prb;
1134 int ret;
1135
1136 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1137 return 0;
1138
Michal Kazior81a9a172015-03-05 16:02:17 +02001139 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1140 return 0;
1141
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001142 prb = ieee80211_proberesp_get(hw, vif);
1143 if (!prb) {
1144 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1145 return -EPERM;
1146 }
1147
1148 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1149 kfree_skb(prb);
1150
1151 if (ret) {
1152 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1153 ret);
1154 return ret;
1155 }
1156
1157 return 0;
1158}
1159
Kalle Valo5e3dd152013-06-12 20:52:10 +03001160static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001161 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001162{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001163 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001164 int ret = 0;
1165
Michal Kazior548db542013-07-05 16:15:15 +03001166 lockdep_assert_held(&arvif->ar->conf_mutex);
1167
Kalle Valo5e3dd152013-06-12 20:52:10 +03001168 if (!info->enable_beacon) {
1169 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001170
Michal Kazior81a9a172015-03-05 16:02:17 +02001171 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01001172 arvif->is_started = false;
1173 arvif->is_up = false;
Michal Kazior64badcb2014-09-18 11:18:02 +03001174 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001175 spin_unlock_bh(&arvif->ar->data_lock);
1176
Kalle Valo5e3dd152013-06-12 20:52:10 +03001177 return;
1178 }
1179
1180 arvif->tx_seq_no = 0x1000;
1181
1182 ret = ath10k_vdev_start(arvif);
1183 if (ret)
1184 return;
1185
Michal Kaziorc930f742014-01-23 11:38:25 +01001186 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001187 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001188
1189 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1190 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001191 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001192 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001193 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001194 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001195 return;
1196 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001197
1198 arvif->is_started = true;
1199 arvif->is_up = true;
1200
Michal Kazior7aa7a722014-08-25 12:09:38 +02001201 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001202}
1203
1204static void ath10k_control_ibss(struct ath10k_vif *arvif,
1205 struct ieee80211_bss_conf *info,
1206 const u8 self_peer[ETH_ALEN])
1207{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001208 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001209 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001210 int ret = 0;
1211
Michal Kazior548db542013-07-05 16:15:15 +03001212 lockdep_assert_held(&arvif->ar->conf_mutex);
1213
Kalle Valo5e3dd152013-06-12 20:52:10 +03001214 if (!info->ibss_joined) {
1215 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1216 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001217 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001218 self_peer, arvif->vdev_id, ret);
1219
Michal Kaziorc930f742014-01-23 11:38:25 +01001220 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001221 return;
1222
Michal Kaziorc930f742014-01-23 11:38:25 +01001223 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001224
1225 return;
1226 }
1227
1228 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1229 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001230 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001231 self_peer, arvif->vdev_id, ret);
1232 return;
1233 }
1234
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001235 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1236 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001237 ATH10K_DEFAULT_ATIM);
1238 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001239 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240 arvif->vdev_id, ret);
1241}
1242
Michal Kazior9f9b5742014-12-12 12:41:36 +01001243static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1244{
1245 struct ath10k *ar = arvif->ar;
1246 u32 param;
1247 u32 value;
1248 int ret;
1249
1250 lockdep_assert_held(&arvif->ar->conf_mutex);
1251
1252 if (arvif->u.sta.uapsd)
1253 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1254 else
1255 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1256
1257 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1258 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1259 if (ret) {
1260 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1261 value, arvif->vdev_id, ret);
1262 return ret;
1263 }
1264
1265 return 0;
1266}
1267
1268static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1269{
1270 struct ath10k *ar = arvif->ar;
1271 u32 param;
1272 u32 value;
1273 int ret;
1274
1275 lockdep_assert_held(&arvif->ar->conf_mutex);
1276
1277 if (arvif->u.sta.uapsd)
1278 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1279 else
1280 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1281
1282 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1283 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1284 param, value);
1285 if (ret) {
1286 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1287 value, arvif->vdev_id, ret);
1288 return ret;
1289 }
1290
1291 return 0;
1292}
1293
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001294static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1295{
1296 struct ath10k_vif *arvif;
1297 int num = 0;
1298
1299 lockdep_assert_held(&ar->conf_mutex);
1300
1301 list_for_each_entry(arvif, &ar->arvifs, list)
1302 if (arvif->ps)
1303 num++;
1304
1305 return num;
1306}
1307
Michal Kaziorad088bf2013-10-16 15:44:46 +03001308static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001309{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001310 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001311 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001312 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001313 enum wmi_sta_powersave_param param;
1314 enum wmi_sta_ps_mode psmode;
1315 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001316 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001317 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001318
Michal Kazior548db542013-07-05 16:15:15 +03001319 lockdep_assert_held(&arvif->ar->conf_mutex);
1320
Michal Kaziorad088bf2013-10-16 15:44:46 +03001321 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1322 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001323
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001324 enable_ps = arvif->ps;
1325
1326 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1327 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1328 ar->fw_features)) {
1329 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1330 arvif->vdev_id);
1331 enable_ps = false;
1332 }
1333
1334 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001335 psmode = WMI_STA_PS_MODE_ENABLED;
1336 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1337
Michal Kazior526549a2014-12-12 12:41:37 +01001338 ps_timeout = conf->dynamic_ps_timeout;
1339 if (ps_timeout == 0) {
1340 /* Firmware doesn't like 0 */
1341 ps_timeout = ieee80211_tu_to_usec(
1342 vif->bss_conf.beacon_int) / 1000;
1343 }
1344
Michal Kaziorad088bf2013-10-16 15:44:46 +03001345 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001346 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001348 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001349 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001350 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001351 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352 } else {
1353 psmode = WMI_STA_PS_MODE_DISABLED;
1354 }
1355
Michal Kazior7aa7a722014-08-25 12:09:38 +02001356 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001357 arvif->vdev_id, psmode ? "enable" : "disable");
1358
Michal Kaziorad088bf2013-10-16 15:44:46 +03001359 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1360 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001361 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001362 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001363 return ret;
1364 }
1365
1366 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367}
1368
Michal Kazior46725b152015-01-28 09:57:49 +02001369static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1370{
1371 struct ath10k *ar = arvif->ar;
1372 struct wmi_sta_keepalive_arg arg = {};
1373 int ret;
1374
1375 lockdep_assert_held(&arvif->ar->conf_mutex);
1376
1377 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1378 return 0;
1379
1380 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1381 return 0;
1382
1383 /* Some firmware revisions have a bug and ignore the `enabled` field.
1384 * Instead use the interval to disable the keepalive.
1385 */
1386 arg.vdev_id = arvif->vdev_id;
1387 arg.enabled = 1;
1388 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1389 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1390
1391 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1392 if (ret) {
1393 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1394 arvif->vdev_id, ret);
1395 return ret;
1396 }
1397
1398 return 0;
1399}
1400
Michal Kazior81a9a172015-03-05 16:02:17 +02001401static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1402{
1403 struct ath10k *ar = arvif->ar;
1404 struct ieee80211_vif *vif = arvif->vif;
1405 int ret;
1406
1407 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1408 return;
1409
1410 if (!vif->csa_active)
1411 return;
1412
1413 if (!arvif->is_up)
1414 return;
1415
1416 if (!ieee80211_csa_is_complete(vif)) {
1417 ieee80211_csa_update_counter(vif);
1418
1419 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1420 if (ret)
1421 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1422 ret);
1423
1424 ret = ath10k_mac_setup_prb_tmpl(arvif);
1425 if (ret)
1426 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1427 ret);
1428 } else {
1429 ieee80211_csa_finish(vif);
1430 }
1431}
1432
1433static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1434{
1435 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1436 ap_csa_work);
1437 struct ath10k *ar = arvif->ar;
1438
1439 mutex_lock(&ar->conf_mutex);
1440 ath10k_mac_vif_ap_csa_count_down(arvif);
1441 mutex_unlock(&ar->conf_mutex);
1442}
1443
Kalle Valo5e3dd152013-06-12 20:52:10 +03001444/**********************/
1445/* Station management */
1446/**********************/
1447
Michal Kazior590922a2014-10-21 10:10:29 +03001448static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1449 struct ieee80211_vif *vif)
1450{
1451 /* Some firmware revisions have unstable STA powersave when listen
1452 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1453 * generate NullFunc frames properly even if buffered frames have been
1454 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1455 * buffered frames. Often pinging the device from AP would simply fail.
1456 *
1457 * As a workaround set it to 1.
1458 */
1459 if (vif->type == NL80211_IFTYPE_STATION)
1460 return 1;
1461
1462 return ar->hw->conf.listen_interval;
1463}
1464
Kalle Valo5e3dd152013-06-12 20:52:10 +03001465static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001466 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001467 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001468 struct wmi_peer_assoc_complete_arg *arg)
1469{
Michal Kazior590922a2014-10-21 10:10:29 +03001470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1471
Michal Kazior548db542013-07-05 16:15:15 +03001472 lockdep_assert_held(&ar->conf_mutex);
1473
Kalle Valob25f32c2014-09-14 12:50:49 +03001474 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001475 arg->vdev_id = arvif->vdev_id;
1476 arg->peer_aid = sta->aid;
1477 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001478 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001479 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001480 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481}
1482
1483static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001484 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 struct wmi_peer_assoc_complete_arg *arg)
1486{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001487 struct ieee80211_bss_conf *info = &vif->bss_conf;
1488 struct cfg80211_bss *bss;
1489 const u8 *rsnie = NULL;
1490 const u8 *wpaie = NULL;
1491
Michal Kazior548db542013-07-05 16:15:15 +03001492 lockdep_assert_held(&ar->conf_mutex);
1493
Kalle Valo5e3dd152013-06-12 20:52:10 +03001494 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1495 info->bssid, NULL, 0, 0, 0);
1496 if (bss) {
1497 const struct cfg80211_bss_ies *ies;
1498
1499 rcu_read_lock();
1500 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1501
1502 ies = rcu_dereference(bss->ies);
1503
1504 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001505 WLAN_OUI_TYPE_MICROSOFT_WPA,
1506 ies->data,
1507 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001508 rcu_read_unlock();
1509 cfg80211_put_bss(ar->hw->wiphy, bss);
1510 }
1511
1512 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1513 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001514 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001515 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1516 }
1517
1518 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001519 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001520 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1521 }
1522}
1523
1524static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1525 struct ieee80211_sta *sta,
1526 struct wmi_peer_assoc_complete_arg *arg)
1527{
1528 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1529 const struct ieee80211_supported_band *sband;
1530 const struct ieee80211_rate *rates;
1531 u32 ratemask;
1532 int i;
1533
Michal Kazior548db542013-07-05 16:15:15 +03001534 lockdep_assert_held(&ar->conf_mutex);
1535
Kalle Valo5e3dd152013-06-12 20:52:10 +03001536 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1537 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1538 rates = sband->bitrates;
1539
1540 rateset->num_rates = 0;
1541
1542 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1543 if (!(ratemask & 1))
1544 continue;
1545
1546 rateset->rates[rateset->num_rates] = rates->hw_value;
1547 rateset->num_rates++;
1548 }
1549}
1550
1551static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1552 struct ieee80211_sta *sta,
1553 struct wmi_peer_assoc_complete_arg *arg)
1554{
1555 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001556 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001557 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558
Michal Kazior548db542013-07-05 16:15:15 +03001559 lockdep_assert_held(&ar->conf_mutex);
1560
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 if (!ht_cap->ht_supported)
1562 return;
1563
1564 arg->peer_flags |= WMI_PEER_HT;
1565 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1566 ht_cap->ampdu_factor)) - 1;
1567
1568 arg->peer_mpdu_density =
1569 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1570
1571 arg->peer_ht_caps = ht_cap->cap;
1572 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1573
1574 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1575 arg->peer_flags |= WMI_PEER_LDPC;
1576
1577 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1578 arg->peer_flags |= WMI_PEER_40MHZ;
1579 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1580 }
1581
1582 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1583 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1584
1585 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1586 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1587
1588 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1589 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1590 arg->peer_flags |= WMI_PEER_STBC;
1591 }
1592
1593 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001594 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1595 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1596 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1597 arg->peer_rate_caps |= stbc;
1598 arg->peer_flags |= WMI_PEER_STBC;
1599 }
1600
Kalle Valo5e3dd152013-06-12 20:52:10 +03001601 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1602 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1603 else if (ht_cap->mcs.rx_mask[1])
1604 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1605
1606 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1607 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1608 arg->peer_ht_rates.rates[n++] = i;
1609
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001610 /*
1611 * This is a workaround for HT-enabled STAs which break the spec
1612 * and have no HT capabilities RX mask (no HT RX MCS map).
1613 *
1614 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1615 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1616 *
1617 * Firmware asserts if such situation occurs.
1618 */
1619 if (n == 0) {
1620 arg->peer_ht_rates.num_rates = 8;
1621 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1622 arg->peer_ht_rates.rates[i] = i;
1623 } else {
1624 arg->peer_ht_rates.num_rates = n;
1625 arg->peer_num_spatial_streams = sta->rx_nss;
1626 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627
Michal Kazior7aa7a722014-08-25 12:09:38 +02001628 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001629 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001630 arg->peer_ht_rates.num_rates,
1631 arg->peer_num_spatial_streams);
1632}
1633
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001634static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1635 struct ath10k_vif *arvif,
1636 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001637{
1638 u32 uapsd = 0;
1639 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001640 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001641
Michal Kazior548db542013-07-05 16:15:15 +03001642 lockdep_assert_held(&ar->conf_mutex);
1643
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001645 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001646 sta->uapsd_queues, sta->max_sp);
1647
Kalle Valo5e3dd152013-06-12 20:52:10 +03001648 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1649 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1650 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1651 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1652 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1653 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1654 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1655 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1656 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1657 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1658 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1659 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1660
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1662 max_sp = sta->max_sp;
1663
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001664 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1665 sta->addr,
1666 WMI_AP_PS_PEER_PARAM_UAPSD,
1667 uapsd);
1668 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001669 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001670 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001671 return ret;
1672 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001673
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001674 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1675 sta->addr,
1676 WMI_AP_PS_PEER_PARAM_MAX_SP,
1677 max_sp);
1678 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001679 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001680 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001681 return ret;
1682 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001683
1684 /* TODO setup this based on STA listen interval and
1685 beacon interval. Currently we don't know
1686 sta->listen_interval - mac80211 patch required.
1687 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001688 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001689 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1690 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001691 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001692 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001693 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001694 return ret;
1695 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001698 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001699}
1700
1701static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1702 struct ieee80211_sta *sta,
1703 struct wmi_peer_assoc_complete_arg *arg)
1704{
1705 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001706 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707
1708 if (!vht_cap->vht_supported)
1709 return;
1710
1711 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001712
1713 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1714 arg->peer_flags |= WMI_PEER_VHT_2G;
1715
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716 arg->peer_vht_caps = vht_cap->cap;
1717
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001718 ampdu_factor = (vht_cap->cap &
1719 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1720 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1721
1722 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1723 * zero in VHT IE. Using it would result in degraded throughput.
1724 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1725 * it if VHT max_mpdu is smaller. */
1726 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1727 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1728 ampdu_factor)) - 1);
1729
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1731 arg->peer_flags |= WMI_PEER_80MHZ;
1732
1733 arg->peer_vht_rates.rx_max_rate =
1734 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1735 arg->peer_vht_rates.rx_mcs_set =
1736 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1737 arg->peer_vht_rates.tx_max_rate =
1738 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1739 arg->peer_vht_rates.tx_mcs_set =
1740 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1741
Michal Kazior7aa7a722014-08-25 12:09:38 +02001742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001743 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001744}
1745
1746static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001747 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001748 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001749 struct wmi_peer_assoc_complete_arg *arg)
1750{
Michal Kazior590922a2014-10-21 10:10:29 +03001751 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1752
Kalle Valo5e3dd152013-06-12 20:52:10 +03001753 switch (arvif->vdev_type) {
1754 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001755 if (sta->wme)
1756 arg->peer_flags |= WMI_PEER_QOS;
1757
1758 if (sta->wme && sta->uapsd_queues) {
1759 arg->peer_flags |= WMI_PEER_APSD;
1760 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1761 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001762 break;
1763 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001764 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001765 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001767 case WMI_VDEV_TYPE_IBSS:
1768 if (sta->wme)
1769 arg->peer_flags |= WMI_PEER_QOS;
1770 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001771 default:
1772 break;
1773 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001774
1775 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1776 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001777}
1778
Michal Kazior91b12082014-12-12 12:41:35 +01001779static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1780{
1781 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1782 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1783}
1784
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001786 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787 struct ieee80211_sta *sta,
1788 struct wmi_peer_assoc_complete_arg *arg)
1789{
1790 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1791
Kalle Valo5e3dd152013-06-12 20:52:10 +03001792 switch (ar->hw->conf.chandef.chan->band) {
1793 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001794 if (sta->vht_cap.vht_supported) {
1795 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1796 phymode = MODE_11AC_VHT40;
1797 else
1798 phymode = MODE_11AC_VHT20;
1799 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1801 phymode = MODE_11NG_HT40;
1802 else
1803 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001804 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001805 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001806 } else {
1807 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001808 }
1809
1810 break;
1811 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001812 /*
1813 * Check VHT first.
1814 */
1815 if (sta->vht_cap.vht_supported) {
1816 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1817 phymode = MODE_11AC_VHT80;
1818 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1819 phymode = MODE_11AC_VHT40;
1820 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1821 phymode = MODE_11AC_VHT20;
1822 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001823 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1824 phymode = MODE_11NA_HT40;
1825 else
1826 phymode = MODE_11NA_HT20;
1827 } else {
1828 phymode = MODE_11A;
1829 }
1830
1831 break;
1832 default:
1833 break;
1834 }
1835
Michal Kazior7aa7a722014-08-25 12:09:38 +02001836 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001837 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001838
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839 arg->peer_phymode = phymode;
1840 WARN_ON(phymode == MODE_UNKNOWN);
1841}
1842
Kalle Valob9ada652013-10-16 15:44:46 +03001843static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001844 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001845 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001846 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001847{
Michal Kazior548db542013-07-05 16:15:15 +03001848 lockdep_assert_held(&ar->conf_mutex);
1849
Kalle Valob9ada652013-10-16 15:44:46 +03001850 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851
Michal Kazior590922a2014-10-21 10:10:29 +03001852 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1853 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001854 ath10k_peer_assoc_h_rates(ar, sta, arg);
1855 ath10k_peer_assoc_h_ht(ar, sta, arg);
1856 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001857 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1858 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001859
Kalle Valob9ada652013-10-16 15:44:46 +03001860 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001861}
1862
Michal Kazior90046f52014-02-14 14:45:51 +01001863static const u32 ath10k_smps_map[] = {
1864 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1865 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1866 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1867 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1868};
1869
1870static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1871 const u8 *addr,
1872 const struct ieee80211_sta_ht_cap *ht_cap)
1873{
1874 int smps;
1875
1876 if (!ht_cap->ht_supported)
1877 return 0;
1878
1879 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1880 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1881
1882 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1883 return -EINVAL;
1884
1885 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1886 WMI_PEER_SMPS_STATE,
1887 ath10k_smps_map[smps]);
1888}
1889
Michal Kazior139e1702015-02-15 16:50:42 +02001890static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1891 struct ieee80211_vif *vif,
1892 struct ieee80211_sta_vht_cap vht_cap)
1893{
1894 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1895 int ret;
1896 u32 param;
1897 u32 value;
1898
1899 if (!(ar->vht_cap_info &
1900 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1901 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1902 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1903 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1904 return 0;
1905
1906 param = ar->wmi.vdev_param->txbf;
1907 value = 0;
1908
1909 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1910 return 0;
1911
1912 /* The following logic is correct. If a remote STA advertises support
1913 * for being a beamformer then we should enable us being a beamformee.
1914 */
1915
1916 if (ar->vht_cap_info &
1917 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1918 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1919 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1920 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1921
1922 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1923 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1924 }
1925
1926 if (ar->vht_cap_info &
1927 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1928 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1929 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1930 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1931
1932 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
1933 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
1934 }
1935
1936 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
1937 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1938
1939 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
1940 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1941
1942 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
1943 if (ret) {
1944 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
1945 value, ret);
1946 return ret;
1947 }
1948
1949 return 0;
1950}
1951
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952/* can be called only in mac80211 callbacks due to `key_count` usage */
1953static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1954 struct ieee80211_vif *vif,
1955 struct ieee80211_bss_conf *bss_conf)
1956{
1957 struct ath10k *ar = hw->priv;
1958 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001959 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001960 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001961 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962 struct ieee80211_sta *ap_sta;
1963 int ret;
1964
Michal Kazior548db542013-07-05 16:15:15 +03001965 lockdep_assert_held(&ar->conf_mutex);
1966
Michal Kazior077efc82014-10-21 10:10:29 +03001967 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1968 arvif->vdev_id, arvif->bssid, arvif->aid);
1969
Kalle Valo5e3dd152013-06-12 20:52:10 +03001970 rcu_read_lock();
1971
1972 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1973 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001974 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001975 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 rcu_read_unlock();
1977 return;
1978 }
1979
Michal Kazior90046f52014-02-14 14:45:51 +01001980 /* ap_sta must be accessed only within rcu section which must be left
1981 * before calling ath10k_setup_peer_smps() which might sleep. */
1982 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02001983 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01001984
Michal Kazior590922a2014-10-21 10:10:29 +03001985 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001986 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001987 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001988 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001989 rcu_read_unlock();
1990 return;
1991 }
1992
1993 rcu_read_unlock();
1994
Kalle Valob9ada652013-10-16 15:44:46 +03001995 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1996 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001997 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001998 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001999 return;
2000 }
2001
Michal Kazior90046f52014-02-14 14:45:51 +01002002 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2003 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002004 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002005 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002006 return;
2007 }
2008
Michal Kazior139e1702015-02-15 16:50:42 +02002009 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2010 if (ret) {
2011 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2012 arvif->vdev_id, bss_conf->bssid, ret);
2013 return;
2014 }
2015
Michal Kazior7aa7a722014-08-25 12:09:38 +02002016 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002017 "mac vdev %d up (associated) bssid %pM aid %d\n",
2018 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2019
Michal Kazior077efc82014-10-21 10:10:29 +03002020 WARN_ON(arvif->is_up);
2021
Michal Kaziorc930f742014-01-23 11:38:25 +01002022 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002023 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002024
2025 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2026 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002027 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002029 return;
2030 }
2031
Michal Kazior81a9a172015-03-05 16:02:17 +02002032 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01002033 arvif->is_up = true;
Michal Kazior81a9a172015-03-05 16:02:17 +02002034 spin_unlock_bh(&arvif->ar->data_lock);
Michal Kazior0a987fb2015-02-13 13:30:15 +01002035
2036 /* Workaround: Some firmware revisions (tested with qca6174
2037 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2038 * poked with peer param command.
2039 */
2040 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2041 WMI_PEER_DUMMY_VAR, 1);
2042 if (ret) {
2043 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2044 arvif->bssid, arvif->vdev_id, ret);
2045 return;
2046 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047}
2048
Kalle Valo5e3dd152013-06-12 20:52:10 +03002049static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2050 struct ieee80211_vif *vif)
2051{
2052 struct ath10k *ar = hw->priv;
2053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002054 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055 int ret;
2056
Michal Kazior548db542013-07-05 16:15:15 +03002057 lockdep_assert_held(&ar->conf_mutex);
2058
Michal Kazior077efc82014-10-21 10:10:29 +03002059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2060 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002061
Kalle Valo5e3dd152013-06-12 20:52:10 +03002062 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002063 if (ret)
2064 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2065 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002066
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002067 arvif->def_wep_key_idx = -1;
2068
Michal Kazior139e1702015-02-15 16:50:42 +02002069 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2070 if (ret) {
2071 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2072 arvif->vdev_id, ret);
2073 return;
2074 }
2075
Michal Kazior81a9a172015-03-05 16:02:17 +02002076 spin_lock_bh(&arvif->ar->data_lock);
Michal Kaziorc930f742014-01-23 11:38:25 +01002077 arvif->is_up = false;
Michal Kazior81a9a172015-03-05 16:02:17 +02002078 spin_unlock_bh(&arvif->ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079}
2080
Michal Kazior590922a2014-10-21 10:10:29 +03002081static int ath10k_station_assoc(struct ath10k *ar,
2082 struct ieee80211_vif *vif,
2083 struct ieee80211_sta *sta,
2084 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085{
Michal Kazior590922a2014-10-21 10:10:29 +03002086 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002087 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002088 int ret = 0;
2089
Michal Kazior548db542013-07-05 16:15:15 +03002090 lockdep_assert_held(&ar->conf_mutex);
2091
Michal Kazior590922a2014-10-21 10:10:29 +03002092 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002094 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002095 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002096 return ret;
2097 }
2098
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002099 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002100 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2101 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002102 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002103 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002104 return ret;
2105 }
2106
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002107 /* Re-assoc is run only to update supported rates for given station. It
2108 * doesn't make much sense to reconfigure the peer completely.
2109 */
2110 if (!reassoc) {
2111 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2112 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002113 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002114 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002115 arvif->vdev_id, ret);
2116 return ret;
2117 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002118
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002119 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2120 if (ret) {
2121 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2122 sta->addr, arvif->vdev_id, ret);
2123 return ret;
2124 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002125
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002126 if (!sta->wme) {
2127 arvif->num_legacy_stations++;
2128 ret = ath10k_recalc_rtscts_prot(arvif);
2129 if (ret) {
2130 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2131 arvif->vdev_id, ret);
2132 return ret;
2133 }
2134 }
2135
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002136 /* Plumb cached keys only for static WEP */
2137 if (arvif->def_wep_key_idx != -1) {
2138 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2139 if (ret) {
2140 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2141 arvif->vdev_id, ret);
2142 return ret;
2143 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002144 }
2145 }
2146
Kalle Valo5e3dd152013-06-12 20:52:10 +03002147 return ret;
2148}
2149
Michal Kazior590922a2014-10-21 10:10:29 +03002150static int ath10k_station_disassoc(struct ath10k *ar,
2151 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002152 struct ieee80211_sta *sta)
2153{
Michal Kazior590922a2014-10-21 10:10:29 +03002154 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155 int ret = 0;
2156
2157 lockdep_assert_held(&ar->conf_mutex);
2158
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002159 if (!sta->wme) {
2160 arvif->num_legacy_stations--;
2161 ret = ath10k_recalc_rtscts_prot(arvif);
2162 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002163 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002164 arvif->vdev_id, ret);
2165 return ret;
2166 }
2167 }
2168
Kalle Valo5e3dd152013-06-12 20:52:10 +03002169 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2170 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002171 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002172 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173 return ret;
2174 }
2175
2176 return ret;
2177}
2178
2179/**************/
2180/* Regulatory */
2181/**************/
2182
2183static int ath10k_update_channel_list(struct ath10k *ar)
2184{
2185 struct ieee80211_hw *hw = ar->hw;
2186 struct ieee80211_supported_band **bands;
2187 enum ieee80211_band band;
2188 struct ieee80211_channel *channel;
2189 struct wmi_scan_chan_list_arg arg = {0};
2190 struct wmi_channel_arg *ch;
2191 bool passive;
2192 int len;
2193 int ret;
2194 int i;
2195
Michal Kazior548db542013-07-05 16:15:15 +03002196 lockdep_assert_held(&ar->conf_mutex);
2197
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198 bands = hw->wiphy->bands;
2199 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2200 if (!bands[band])
2201 continue;
2202
2203 for (i = 0; i < bands[band]->n_channels; i++) {
2204 if (bands[band]->channels[i].flags &
2205 IEEE80211_CHAN_DISABLED)
2206 continue;
2207
2208 arg.n_channels++;
2209 }
2210 }
2211
2212 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2213 arg.channels = kzalloc(len, GFP_KERNEL);
2214 if (!arg.channels)
2215 return -ENOMEM;
2216
2217 ch = arg.channels;
2218 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2219 if (!bands[band])
2220 continue;
2221
2222 for (i = 0; i < bands[band]->n_channels; i++) {
2223 channel = &bands[band]->channels[i];
2224
2225 if (channel->flags & IEEE80211_CHAN_DISABLED)
2226 continue;
2227
2228 ch->allow_ht = true;
2229
2230 /* FIXME: when should we really allow VHT? */
2231 ch->allow_vht = true;
2232
2233 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002234 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002235
2236 ch->ht40plus =
2237 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2238
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002239 ch->chan_radar =
2240 !!(channel->flags & IEEE80211_CHAN_RADAR);
2241
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002242 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 ch->passive = passive;
2244
2245 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002246 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002247 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002248 ch->max_power = channel->max_power * 2;
2249 ch->max_reg_power = channel->max_reg_power * 2;
2250 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002251 ch->reg_class_id = 0; /* FIXME */
2252
2253 /* FIXME: why use only legacy modes, why not any
2254 * HT/VHT modes? Would that even make any
2255 * difference? */
2256 if (channel->band == IEEE80211_BAND_2GHZ)
2257 ch->mode = MODE_11G;
2258 else
2259 ch->mode = MODE_11A;
2260
2261 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2262 continue;
2263
Michal Kazior7aa7a722014-08-25 12:09:38 +02002264 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002265 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2266 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002267 ch->freq, ch->max_power, ch->max_reg_power,
2268 ch->max_antenna_gain, ch->mode);
2269
2270 ch++;
2271 }
2272 }
2273
2274 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2275 kfree(arg.channels);
2276
2277 return ret;
2278}
2279
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002280static enum wmi_dfs_region
2281ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2282{
2283 switch (dfs_region) {
2284 case NL80211_DFS_UNSET:
2285 return WMI_UNINIT_DFS_DOMAIN;
2286 case NL80211_DFS_FCC:
2287 return WMI_FCC_DFS_DOMAIN;
2288 case NL80211_DFS_ETSI:
2289 return WMI_ETSI_DFS_DOMAIN;
2290 case NL80211_DFS_JP:
2291 return WMI_MKK4_DFS_DOMAIN;
2292 }
2293 return WMI_UNINIT_DFS_DOMAIN;
2294}
2295
Michal Kaziorf7843d72013-07-16 09:38:52 +02002296static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002297{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002298 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002300 enum wmi_dfs_region wmi_dfs_reg;
2301 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002302
Michal Kaziorf7843d72013-07-16 09:38:52 +02002303 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304
2305 ret = ath10k_update_channel_list(ar);
2306 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002307 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308
2309 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002310
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002311 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2312 nl_dfs_reg = ar->dfs_detector->region;
2313 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2314 } else {
2315 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2316 }
2317
Kalle Valo5e3dd152013-06-12 20:52:10 +03002318 /* Target allows setting up per-band regdomain but ath_common provides
2319 * a combined one only */
2320 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002321 regpair->reg_domain,
2322 regpair->reg_domain, /* 2ghz */
2323 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002324 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002325 regpair->reg_5ghz_ctl,
2326 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002328 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002329}
Michal Kazior548db542013-07-05 16:15:15 +03002330
Michal Kaziorf7843d72013-07-16 09:38:52 +02002331static void ath10k_reg_notifier(struct wiphy *wiphy,
2332 struct regulatory_request *request)
2333{
2334 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2335 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002336 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002337
2338 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2339
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002340 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002341 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002342 request->dfs_region);
2343 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2344 request->dfs_region);
2345 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002346 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002347 request->dfs_region);
2348 }
2349
Michal Kaziorf7843d72013-07-16 09:38:52 +02002350 mutex_lock(&ar->conf_mutex);
2351 if (ar->state == ATH10K_STATE_ON)
2352 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002353 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002354}
2355
2356/***************/
2357/* TX handlers */
2358/***************/
2359
Michal Kazior42c3aa62013-10-02 11:03:38 +02002360static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2361{
2362 if (ieee80211_is_mgmt(hdr->frame_control))
2363 return HTT_DATA_TX_EXT_TID_MGMT;
2364
2365 if (!ieee80211_is_data_qos(hdr->frame_control))
2366 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2367
2368 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2369 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2370
2371 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2372}
2373
Michal Kazior2b37c292014-09-02 11:00:22 +03002374static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002375{
Michal Kazior2b37c292014-09-02 11:00:22 +03002376 if (vif)
2377 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002378
Michal Kazior1bbc0972014-04-08 09:45:47 +03002379 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002380 return ar->monitor_vdev_id;
2381
Michal Kazior7aa7a722014-08-25 12:09:38 +02002382 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002383 return 0;
2384}
2385
Michal Kazior4b604552014-07-21 21:03:09 +03002386/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2387 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002388 */
Michal Kazior4b604552014-07-21 21:03:09 +03002389static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002390{
2391 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002392 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002393 u8 *qos_ctl;
2394
2395 if (!ieee80211_is_data_qos(hdr->frame_control))
2396 return;
2397
2398 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002399 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2400 skb->data, (void *)qos_ctl - (void *)skb->data);
2401 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002402
2403 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2404 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2405 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2406 * it is safe to downgrade to NullFunc.
2407 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002408 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002409 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2410 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2411 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2412 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002413}
2414
Michal Kazior4b604552014-07-21 21:03:09 +03002415static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2416 struct ieee80211_vif *vif,
2417 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418{
2419 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002420 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2421
2422 /* This is case only for P2P_GO */
2423 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2424 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2425 return;
2426
2427 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2428 spin_lock_bh(&ar->data_lock);
2429 if (arvif->u.ap.noa_data)
2430 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2431 GFP_ATOMIC))
2432 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2433 arvif->u.ap.noa_data,
2434 arvif->u.ap.noa_len);
2435 spin_unlock_bh(&ar->data_lock);
2436 }
2437}
2438
Michal Kazior8d6d3622014-11-24 14:58:31 +01002439static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2440{
2441 /* FIXME: Not really sure since when the behaviour changed. At some
2442 * point new firmware stopped requiring creation of peer entries for
2443 * offchannel tx (and actually creating them causes issues with wmi-htc
2444 * tx credit replenishment and reliability). Assuming it's at least 3.4
2445 * because that's when the `freq` was introduced to TX_FRM HTT command.
2446 */
2447 return !(ar->htt.target_version_major >= 3 &&
2448 ar->htt.target_version_minor >= 4);
2449}
2450
Kalle Valo5e3dd152013-06-12 20:52:10 +03002451static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2452{
2453 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002454 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002455
Michal Kazior961d4c32013-08-09 10:13:34 +02002456 if (ar->htt.target_version_major >= 3) {
2457 /* Since HTT 3.0 there is no separate mgmt tx command */
2458 ret = ath10k_htt_tx(&ar->htt, skb);
2459 goto exit;
2460 }
2461
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002462 if (ieee80211_is_mgmt(hdr->frame_control)) {
2463 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2464 ar->fw_features)) {
2465 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2466 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002467 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002468 ret = -EBUSY;
2469 goto exit;
2470 }
2471
2472 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2473 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2474 } else {
2475 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2476 }
2477 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2478 ar->fw_features) &&
2479 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002480 /* FW does not report tx status properly for NullFunc frames
2481 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002482 * those frames when it detects link/beacon loss and depends
2483 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002484 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002485 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002486 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002487 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488
Michal Kazior961d4c32013-08-09 10:13:34 +02002489exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002491 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2492 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002493 ieee80211_free_txskb(ar->hw, skb);
2494 }
2495}
2496
2497void ath10k_offchan_tx_purge(struct ath10k *ar)
2498{
2499 struct sk_buff *skb;
2500
2501 for (;;) {
2502 skb = skb_dequeue(&ar->offchan_tx_queue);
2503 if (!skb)
2504 break;
2505
2506 ieee80211_free_txskb(ar->hw, skb);
2507 }
2508}
2509
2510void ath10k_offchan_tx_work(struct work_struct *work)
2511{
2512 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2513 struct ath10k_peer *peer;
2514 struct ieee80211_hdr *hdr;
2515 struct sk_buff *skb;
2516 const u8 *peer_addr;
2517 int vdev_id;
2518 int ret;
2519
2520 /* FW requirement: We must create a peer before FW will send out
2521 * an offchannel frame. Otherwise the frame will be stuck and
2522 * never transmitted. We delete the peer upon tx completion.
2523 * It is unlikely that a peer for offchannel tx will already be
2524 * present. However it may be in some rare cases so account for that.
2525 * Otherwise we might remove a legitimate peer and break stuff. */
2526
2527 for (;;) {
2528 skb = skb_dequeue(&ar->offchan_tx_queue);
2529 if (!skb)
2530 break;
2531
2532 mutex_lock(&ar->conf_mutex);
2533
Michal Kazior7aa7a722014-08-25 12:09:38 +02002534 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002535 skb);
2536
2537 hdr = (struct ieee80211_hdr *)skb->data;
2538 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002539 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002540
2541 spin_lock_bh(&ar->data_lock);
2542 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2543 spin_unlock_bh(&ar->data_lock);
2544
2545 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002546 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002547 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002548 peer_addr, vdev_id);
2549
2550 if (!peer) {
2551 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2552 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002553 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554 peer_addr, vdev_id, ret);
2555 }
2556
2557 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002558 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002559 ar->offchan_tx_skb = skb;
2560 spin_unlock_bh(&ar->data_lock);
2561
2562 ath10k_tx_htt(ar, skb);
2563
2564 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2565 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002566 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002567 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 skb);
2569
2570 if (!peer) {
2571 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2572 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002573 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574 peer_addr, vdev_id, ret);
2575 }
2576
2577 mutex_unlock(&ar->conf_mutex);
2578 }
2579}
2580
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002581void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2582{
2583 struct sk_buff *skb;
2584
2585 for (;;) {
2586 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2587 if (!skb)
2588 break;
2589
2590 ieee80211_free_txskb(ar->hw, skb);
2591 }
2592}
2593
2594void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2595{
2596 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2597 struct sk_buff *skb;
2598 int ret;
2599
2600 for (;;) {
2601 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2602 if (!skb)
2603 break;
2604
2605 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002607 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002608 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002609 ieee80211_free_txskb(ar->hw, skb);
2610 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002611 }
2612}
2613
Kalle Valo5e3dd152013-06-12 20:52:10 +03002614/************/
2615/* Scanning */
2616/************/
2617
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002618void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002619{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002620 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002621
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002622 switch (ar->scan.state) {
2623 case ATH10K_SCAN_IDLE:
2624 break;
2625 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002626 if (ar->scan.is_roc)
2627 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002628 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002629 case ATH10K_SCAN_ABORTING:
2630 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002631 ieee80211_scan_completed(ar->hw,
2632 (ar->scan.state ==
2633 ATH10K_SCAN_ABORTING));
2634 /* fall through */
2635 case ATH10K_SCAN_STARTING:
2636 ar->scan.state = ATH10K_SCAN_IDLE;
2637 ar->scan_channel = NULL;
2638 ath10k_offchan_tx_purge(ar);
2639 cancel_delayed_work(&ar->scan.timeout);
2640 complete_all(&ar->scan.completed);
2641 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002642 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002643}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002645void ath10k_scan_finish(struct ath10k *ar)
2646{
2647 spin_lock_bh(&ar->data_lock);
2648 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002649 spin_unlock_bh(&ar->data_lock);
2650}
2651
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002652static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002653{
2654 struct wmi_stop_scan_arg arg = {
2655 .req_id = 1, /* FIXME */
2656 .req_type = WMI_SCAN_STOP_ONE,
2657 .u.scan_id = ATH10K_SCAN_ID,
2658 };
2659 int ret;
2660
2661 lockdep_assert_held(&ar->conf_mutex);
2662
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 ret = ath10k_wmi_stop_scan(ar, &arg);
2664 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002665 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002666 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002667 }
2668
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002670 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002671 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002672 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002673 } else if (ret > 0) {
2674 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002675 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002676
2677out:
2678 /* Scan state should be updated upon scan completion but in case
2679 * firmware fails to deliver the event (for whatever reason) it is
2680 * desired to clean up scan state anyway. Firmware may have just
2681 * dropped the scan completion event delivery due to transport pipe
2682 * being overflown with data and/or it can recover on its own before
2683 * next scan request is submitted.
2684 */
2685 spin_lock_bh(&ar->data_lock);
2686 if (ar->scan.state != ATH10K_SCAN_IDLE)
2687 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002688 spin_unlock_bh(&ar->data_lock);
2689
2690 return ret;
2691}
2692
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002693static void ath10k_scan_abort(struct ath10k *ar)
2694{
2695 int ret;
2696
2697 lockdep_assert_held(&ar->conf_mutex);
2698
2699 spin_lock_bh(&ar->data_lock);
2700
2701 switch (ar->scan.state) {
2702 case ATH10K_SCAN_IDLE:
2703 /* This can happen if timeout worker kicked in and called
2704 * abortion while scan completion was being processed.
2705 */
2706 break;
2707 case ATH10K_SCAN_STARTING:
2708 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002710 ath10k_scan_state_str(ar->scan.state),
2711 ar->scan.state);
2712 break;
2713 case ATH10K_SCAN_RUNNING:
2714 ar->scan.state = ATH10K_SCAN_ABORTING;
2715 spin_unlock_bh(&ar->data_lock);
2716
2717 ret = ath10k_scan_stop(ar);
2718 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002719 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002720
2721 spin_lock_bh(&ar->data_lock);
2722 break;
2723 }
2724
2725 spin_unlock_bh(&ar->data_lock);
2726}
2727
2728void ath10k_scan_timeout_work(struct work_struct *work)
2729{
2730 struct ath10k *ar = container_of(work, struct ath10k,
2731 scan.timeout.work);
2732
2733 mutex_lock(&ar->conf_mutex);
2734 ath10k_scan_abort(ar);
2735 mutex_unlock(&ar->conf_mutex);
2736}
2737
Kalle Valo5e3dd152013-06-12 20:52:10 +03002738static int ath10k_start_scan(struct ath10k *ar,
2739 const struct wmi_start_scan_arg *arg)
2740{
2741 int ret;
2742
2743 lockdep_assert_held(&ar->conf_mutex);
2744
2745 ret = ath10k_wmi_start_scan(ar, arg);
2746 if (ret)
2747 return ret;
2748
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2750 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002751 ret = ath10k_scan_stop(ar);
2752 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002753 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002754
2755 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002756 }
2757
Ben Greear2f9eec02015-02-15 16:50:38 +02002758 /* If we failed to start the scan, return error code at
2759 * this point. This is probably due to some issue in the
2760 * firmware, but no need to wedge the driver due to that...
2761 */
2762 spin_lock_bh(&ar->data_lock);
2763 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2764 spin_unlock_bh(&ar->data_lock);
2765 return -EINVAL;
2766 }
2767 spin_unlock_bh(&ar->data_lock);
2768
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002769 /* Add a 200ms margin to account for event/command processing */
2770 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2771 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002772 return 0;
2773}
2774
2775/**********************/
2776/* mac80211 callbacks */
2777/**********************/
2778
2779static void ath10k_tx(struct ieee80211_hw *hw,
2780 struct ieee80211_tx_control *control,
2781 struct sk_buff *skb)
2782{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002784 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2785 struct ieee80211_vif *vif = info->control.vif;
Michal Kazior4b604552014-07-21 21:03:09 +03002786 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002787
2788 /* We should disable CCK RATE due to P2P */
2789 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002790 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791
Michal Kazior4b604552014-07-21 21:03:09 +03002792 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2793 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002794 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002796 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002797 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2798 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03002799 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2800 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002801 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2804 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002805 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002806 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 spin_unlock_bh(&ar->data_lock);
2808
Michal Kazior8d6d3622014-11-24 14:58:31 +01002809 if (ath10k_mac_need_offchan_tx_work(ar)) {
2810 ATH10K_SKB_CB(skb)->htt.freq = 0;
2811 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002812
Michal Kazior8d6d3622014-11-24 14:58:31 +01002813 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2814 skb);
2815
2816 skb_queue_tail(&ar->offchan_tx_queue, skb);
2817 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2818 return;
2819 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 }
2821
2822 ath10k_tx_htt(ar, skb);
2823}
2824
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002825/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002826void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002827{
2828 /* make sure rcu-protected mac80211 tx path itself is drained */
2829 synchronize_net();
2830
2831 ath10k_offchan_tx_purge(ar);
2832 ath10k_mgmt_over_wmi_tx_purge(ar);
2833
2834 cancel_work_sync(&ar->offchan_tx_work);
2835 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2836}
2837
Michal Kazioraffd3212013-07-16 09:54:35 +02002838void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002839{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002840 struct ath10k_vif *arvif;
2841
Michal Kazior818bdd12013-07-16 09:38:57 +02002842 lockdep_assert_held(&ar->conf_mutex);
2843
Michal Kazior19337472014-08-28 12:58:16 +02002844 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2845 ar->filter_flags = 0;
2846 ar->monitor = false;
2847
2848 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002849 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002850
2851 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002852
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002853 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002854 ath10k_peer_cleanup_all(ar);
2855 ath10k_core_stop(ar);
2856 ath10k_hif_power_down(ar);
2857
2858 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002859 list_for_each_entry(arvif, &ar->arvifs, list)
2860 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002861 spin_unlock_bh(&ar->data_lock);
2862}
2863
Ben Greear46acf7b2014-05-16 17:15:38 +03002864static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2865{
2866 struct ath10k *ar = hw->priv;
2867
2868 mutex_lock(&ar->conf_mutex);
2869
2870 if (ar->cfg_tx_chainmask) {
2871 *tx_ant = ar->cfg_tx_chainmask;
2872 *rx_ant = ar->cfg_rx_chainmask;
2873 } else {
2874 *tx_ant = ar->supp_tx_chainmask;
2875 *rx_ant = ar->supp_rx_chainmask;
2876 }
2877
2878 mutex_unlock(&ar->conf_mutex);
2879
2880 return 0;
2881}
2882
Ben Greear5572a952014-11-24 16:22:10 +02002883static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2884{
2885 /* It is not clear that allowing gaps in chainmask
2886 * is helpful. Probably it will not do what user
2887 * is hoping for, so warn in that case.
2888 */
2889 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2890 return;
2891
2892 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2893 dbg, cm);
2894}
2895
Ben Greear46acf7b2014-05-16 17:15:38 +03002896static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2897{
2898 int ret;
2899
2900 lockdep_assert_held(&ar->conf_mutex);
2901
Ben Greear5572a952014-11-24 16:22:10 +02002902 ath10k_check_chain_mask(ar, tx_ant, "tx");
2903 ath10k_check_chain_mask(ar, rx_ant, "rx");
2904
Ben Greear46acf7b2014-05-16 17:15:38 +03002905 ar->cfg_tx_chainmask = tx_ant;
2906 ar->cfg_rx_chainmask = rx_ant;
2907
2908 if ((ar->state != ATH10K_STATE_ON) &&
2909 (ar->state != ATH10K_STATE_RESTARTED))
2910 return 0;
2911
2912 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2913 tx_ant);
2914 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002915 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002916 ret, tx_ant);
2917 return ret;
2918 }
2919
2920 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2921 rx_ant);
2922 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002923 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002924 ret, rx_ant);
2925 return ret;
2926 }
2927
2928 return 0;
2929}
2930
2931static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2932{
2933 struct ath10k *ar = hw->priv;
2934 int ret;
2935
2936 mutex_lock(&ar->conf_mutex);
2937 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2938 mutex_unlock(&ar->conf_mutex);
2939 return ret;
2940}
2941
Kalle Valo5e3dd152013-06-12 20:52:10 +03002942static int ath10k_start(struct ieee80211_hw *hw)
2943{
2944 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002945 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002946
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002947 /*
2948 * This makes sense only when restarting hw. It is harmless to call
2949 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2950 * commands will be submitted while restarting.
2951 */
2952 ath10k_drain_tx(ar);
2953
Michal Kazior548db542013-07-05 16:15:15 +03002954 mutex_lock(&ar->conf_mutex);
2955
Michal Kaziorc5058f52014-05-26 12:46:03 +03002956 switch (ar->state) {
2957 case ATH10K_STATE_OFF:
2958 ar->state = ATH10K_STATE_ON;
2959 break;
2960 case ATH10K_STATE_RESTARTING:
2961 ath10k_halt(ar);
2962 ar->state = ATH10K_STATE_RESTARTED;
2963 break;
2964 case ATH10K_STATE_ON:
2965 case ATH10K_STATE_RESTARTED:
2966 case ATH10K_STATE_WEDGED:
2967 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002968 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002969 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002970 case ATH10K_STATE_UTF:
2971 ret = -EBUSY;
2972 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002973 }
2974
2975 ret = ath10k_hif_power_up(ar);
2976 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002977 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002978 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002979 }
2980
Kalle Valo43d2a302014-09-10 18:23:30 +03002981 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002982 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002983 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002984 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002985 }
2986
Bartosz Markowski226a3392013-09-26 17:47:16 +02002987 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002988 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002989 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002990 goto err_core_stop;
2991 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002992
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002993 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002994 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002995 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002996 goto err_core_stop;
2997 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002998
Ben Greear46acf7b2014-05-16 17:15:38 +03002999 if (ar->cfg_tx_chainmask)
3000 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3001 ar->cfg_rx_chainmask);
3002
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003003 /*
3004 * By default FW set ARP frames ac to voice (6). In that case ARP
3005 * exchange is not working properly for UAPSD enabled AP. ARP requests
3006 * which arrives with access category 0 are processed by network stack
3007 * and send back with access category 0, but FW changes access category
3008 * to 6. Set ARP frames access category to best effort (0) solves
3009 * this problem.
3010 */
3011
3012 ret = ath10k_wmi_pdev_set_param(ar,
3013 ar->wmi.pdev_param->arp_ac_override, 0);
3014 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003015 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003016 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003017 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003018 }
3019
Michal Kaziord6500972014-04-08 09:56:09 +03003020 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003021 ath10k_regd_update(ar);
3022
Simon Wunderlich855aed12014-08-02 09:12:54 +03003023 ath10k_spectral_start(ar);
3024
Michal Kaziorae254432014-05-26 12:46:02 +03003025 mutex_unlock(&ar->conf_mutex);
3026 return 0;
3027
3028err_core_stop:
3029 ath10k_core_stop(ar);
3030
3031err_power_down:
3032 ath10k_hif_power_down(ar);
3033
3034err_off:
3035 ar->state = ATH10K_STATE_OFF;
3036
3037err:
Michal Kazior548db542013-07-05 16:15:15 +03003038 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003039 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003040}
3041
3042static void ath10k_stop(struct ieee80211_hw *hw)
3043{
3044 struct ath10k *ar = hw->priv;
3045
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003046 ath10k_drain_tx(ar);
3047
Michal Kazior548db542013-07-05 16:15:15 +03003048 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003049 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003050 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003051 ar->state = ATH10K_STATE_OFF;
3052 }
Michal Kazior548db542013-07-05 16:15:15 +03003053 mutex_unlock(&ar->conf_mutex);
3054
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003055 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003056 cancel_work_sync(&ar->restart_work);
3057}
3058
Michal Kaziorad088bf2013-10-16 15:44:46 +03003059static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003060{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003061 struct ath10k_vif *arvif;
3062 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003063
3064 lockdep_assert_held(&ar->conf_mutex);
3065
Michal Kaziorad088bf2013-10-16 15:44:46 +03003066 list_for_each_entry(arvif, &ar->arvifs, list) {
3067 ret = ath10k_mac_vif_setup_ps(arvif);
3068 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003069 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003070 break;
3071 }
3072 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003073
Michal Kaziorad088bf2013-10-16 15:44:46 +03003074 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003075}
3076
Michal Kaziorc930f742014-01-23 11:38:25 +01003077static const char *chandef_get_width(enum nl80211_chan_width width)
3078{
3079 switch (width) {
3080 case NL80211_CHAN_WIDTH_20_NOHT:
3081 return "20 (noht)";
3082 case NL80211_CHAN_WIDTH_20:
3083 return "20";
3084 case NL80211_CHAN_WIDTH_40:
3085 return "40";
3086 case NL80211_CHAN_WIDTH_80:
3087 return "80";
3088 case NL80211_CHAN_WIDTH_80P80:
3089 return "80+80";
3090 case NL80211_CHAN_WIDTH_160:
3091 return "160";
3092 case NL80211_CHAN_WIDTH_5:
3093 return "5";
3094 case NL80211_CHAN_WIDTH_10:
3095 return "10";
3096 }
3097 return "?";
3098}
3099
3100static void ath10k_config_chan(struct ath10k *ar)
3101{
3102 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003103 int ret;
3104
3105 lockdep_assert_held(&ar->conf_mutex);
3106
Michal Kazior7aa7a722014-08-25 12:09:38 +02003107 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003108 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3109 ar->chandef.chan->center_freq,
3110 ar->chandef.center_freq1,
3111 ar->chandef.center_freq2,
3112 chandef_get_width(ar->chandef.width));
3113
3114 /* First stop monitor interface. Some FW versions crash if there's a
3115 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003116 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003117 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003118
3119 list_for_each_entry(arvif, &ar->arvifs, list) {
3120 if (!arvif->is_started)
3121 continue;
3122
Michal Kaziordc55e302014-07-29 12:53:36 +03003123 if (!arvif->is_up)
3124 continue;
3125
Michal Kaziorc930f742014-01-23 11:38:25 +01003126 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3127 continue;
3128
Michal Kaziordc55e302014-07-29 12:53:36 +03003129 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003130 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003131 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003132 arvif->vdev_id, ret);
3133 continue;
3134 }
3135 }
3136
Michal Kaziordc55e302014-07-29 12:53:36 +03003137 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003138
3139 list_for_each_entry(arvif, &ar->arvifs, list) {
3140 if (!arvif->is_started)
3141 continue;
3142
3143 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3144 continue;
3145
Michal Kazior81a9a172015-03-05 16:02:17 +02003146 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3147 if (ret)
3148 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3149 ret);
3150
3151 ret = ath10k_mac_setup_prb_tmpl(arvif);
3152 if (ret)
3153 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3154 ret);
3155
Michal Kaziordc55e302014-07-29 12:53:36 +03003156 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003157 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003158 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003159 arvif->vdev_id, ret);
3160 continue;
3161 }
3162
3163 if (!arvif->is_up)
3164 continue;
3165
3166 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3167 arvif->bssid);
3168 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003169 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003170 arvif->vdev_id, ret);
3171 continue;
3172 }
3173 }
3174
Michal Kazior19337472014-08-28 12:58:16 +02003175 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003176}
3177
Michal Kazior7d9d5582014-10-21 10:40:15 +03003178static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3179{
3180 int ret;
3181 u32 param;
3182
3183 lockdep_assert_held(&ar->conf_mutex);
3184
3185 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3186
3187 param = ar->wmi.pdev_param->txpower_limit2g;
3188 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3189 if (ret) {
3190 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3191 txpower, ret);
3192 return ret;
3193 }
3194
3195 param = ar->wmi.pdev_param->txpower_limit5g;
3196 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3197 if (ret) {
3198 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3199 txpower, ret);
3200 return ret;
3201 }
3202
3203 return 0;
3204}
3205
3206static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3207{
3208 struct ath10k_vif *arvif;
3209 int ret, txpower = -1;
3210
3211 lockdep_assert_held(&ar->conf_mutex);
3212
3213 list_for_each_entry(arvif, &ar->arvifs, list) {
3214 WARN_ON(arvif->txpower < 0);
3215
3216 if (txpower == -1)
3217 txpower = arvif->txpower;
3218 else
3219 txpower = min(txpower, arvif->txpower);
3220 }
3221
3222 if (WARN_ON(txpower == -1))
3223 return -EINVAL;
3224
3225 ret = ath10k_mac_txpower_setup(ar, txpower);
3226 if (ret) {
3227 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3228 txpower, ret);
3229 return ret;
3230 }
3231
3232 return 0;
3233}
3234
Kalle Valo5e3dd152013-06-12 20:52:10 +03003235static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3236{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003237 struct ath10k *ar = hw->priv;
3238 struct ieee80211_conf *conf = &hw->conf;
3239 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240
3241 mutex_lock(&ar->conf_mutex);
3242
3243 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003244 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003245 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003246 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003247 conf->chandef.chan->flags,
3248 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003249
Kalle Valo5e3dd152013-06-12 20:52:10 +03003250 spin_lock_bh(&ar->data_lock);
3251 ar->rx_channel = conf->chandef.chan;
3252 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003253
Michal Kaziord6500972014-04-08 09:56:09 +03003254 ar->radar_enabled = conf->radar_enabled;
3255 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003256
3257 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3258 ar->chandef = conf->chandef;
3259 ath10k_config_chan(ar);
3260 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003261 }
3262
Michal Kazioraffd3212013-07-16 09:54:35 +02003263 if (changed & IEEE80211_CONF_CHANGE_PS)
3264 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003265
3266 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003267 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3268 ret = ath10k_monitor_recalc(ar);
3269 if (ret)
3270 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 }
3272
3273 mutex_unlock(&ar->conf_mutex);
3274 return ret;
3275}
3276
Ben Greear5572a952014-11-24 16:22:10 +02003277static u32 get_nss_from_chainmask(u16 chain_mask)
3278{
3279 if ((chain_mask & 0x15) == 0x15)
3280 return 4;
3281 else if ((chain_mask & 0x7) == 0x7)
3282 return 3;
3283 else if ((chain_mask & 0x3) == 0x3)
3284 return 2;
3285 return 1;
3286}
3287
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288/*
3289 * TODO:
3290 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3291 * because we will send mgmt frames without CCK. This requirement
3292 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3293 * in the TX packet.
3294 */
3295static int ath10k_add_interface(struct ieee80211_hw *hw,
3296 struct ieee80211_vif *vif)
3297{
3298 struct ath10k *ar = hw->priv;
3299 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3300 enum wmi_sta_powersave_param param;
3301 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003302 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003303 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003304 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003305
Johannes Berg848955c2014-11-11 12:48:42 +01003306 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3307
Kalle Valo5e3dd152013-06-12 20:52:10 +03003308 mutex_lock(&ar->conf_mutex);
3309
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003310 memset(arvif, 0, sizeof(*arvif));
3311
Kalle Valo5e3dd152013-06-12 20:52:10 +03003312 arvif->ar = ar;
3313 arvif->vif = vif;
3314
Ben Greeare63b33f2013-10-22 14:54:14 -07003315 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003316 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003317
Ben Greeara9aefb32014-08-12 11:02:19 +03003318 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003319 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003321 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003322 }
Ben Greear16c11172014-09-23 14:17:16 -07003323 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003324
Ben Greear16c11172014-09-23 14:17:16 -07003325 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3326 bit, ar->free_vdev_map);
3327
3328 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003329 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003330
Kalle Valo5e3dd152013-06-12 20:52:10 +03003331 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003332 case NL80211_IFTYPE_P2P_DEVICE:
3333 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3334 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3335 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003336 case NL80211_IFTYPE_UNSPECIFIED:
3337 case NL80211_IFTYPE_STATION:
3338 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3339 if (vif->p2p)
3340 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3341 break;
3342 case NL80211_IFTYPE_ADHOC:
3343 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3344 break;
3345 case NL80211_IFTYPE_AP:
3346 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3347
3348 if (vif->p2p)
3349 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3350 break;
3351 case NL80211_IFTYPE_MONITOR:
3352 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3353 break;
3354 default:
3355 WARN_ON(1);
3356 break;
3357 }
3358
Michal Kazior64badcb2014-09-18 11:18:02 +03003359 /* Some firmware revisions don't wait for beacon tx completion before
3360 * sending another SWBA event. This could lead to hardware using old
3361 * (freed) beacon data in some cases, e.g. tx credit starvation
3362 * combined with missed TBTT. This is very very rare.
3363 *
3364 * On non-IOMMU-enabled hosts this could be a possible security issue
3365 * because hw could beacon some random data on the air. On
3366 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3367 * device would crash.
3368 *
3369 * Since there are no beacon tx completions (implicit nor explicit)
3370 * propagated to host the only workaround for this is to allocate a
3371 * DMA-coherent buffer for a lifetime of a vif and use it for all
3372 * beacon tx commands. Worst case for this approach is some beacons may
3373 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3374 */
3375 if (vif->type == NL80211_IFTYPE_ADHOC ||
3376 vif->type == NL80211_IFTYPE_AP) {
3377 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3378 IEEE80211_MAX_FRAME_LEN,
3379 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303380 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003381 if (!arvif->beacon_buf) {
3382 ret = -ENOMEM;
3383 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3384 ret);
3385 goto err;
3386 }
3387 }
3388
3389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3390 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3391 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003392
3393 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3394 arvif->vdev_subtype, vif->addr);
3395 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003396 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003397 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003398 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003399 }
3400
Ben Greear16c11172014-09-23 14:17:16 -07003401 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003402 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003403
Michal Kazior46725b152015-01-28 09:57:49 +02003404 /* It makes no sense to have firmware do keepalives. mac80211 already
3405 * takes care of this with idle connection polling.
3406 */
3407 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003408 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003409 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003410 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003411 goto err_vdev_delete;
3412 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003413
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003414 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003415
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003416 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3417 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003418 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003419 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003420 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003421 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003422 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003423 goto err_vdev_delete;
3424 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003425
Ben Greear5572a952014-11-24 16:22:10 +02003426 if (ar->cfg_tx_chainmask) {
3427 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3428
3429 vdev_param = ar->wmi.vdev_param->nss;
3430 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3431 nss);
3432 if (ret) {
3433 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3434 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3435 ret);
3436 goto err_vdev_delete;
3437 }
3438 }
3439
Kalle Valo5e3dd152013-06-12 20:52:10 +03003440 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3441 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3442 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003443 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003444 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003445 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003446 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003447
Kalle Valo5a13e762014-01-20 11:01:46 +02003448 ret = ath10k_mac_set_kickout(arvif);
3449 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003450 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003451 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003452 goto err_peer_delete;
3453 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003454 }
3455
3456 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3457 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3458 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3459 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3460 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003461 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003462 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003463 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003464 goto err_peer_delete;
3465 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466
Michal Kazior9f9b5742014-12-12 12:41:36 +01003467 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003468 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003469 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003470 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003471 goto err_peer_delete;
3472 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473
Michal Kazior9f9b5742014-12-12 12:41:36 +01003474 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003475 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003476 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003477 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003478 goto err_peer_delete;
3479 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003480 }
3481
Michal Kazior424121c2013-07-22 14:13:31 +02003482 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003483 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003484 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003485 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003486 goto err_peer_delete;
3487 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003488
Michal Kazior424121c2013-07-22 14:13:31 +02003489 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003490 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003491 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003492 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003493 goto err_peer_delete;
3494 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003495
Michal Kazior7d9d5582014-10-21 10:40:15 +03003496 arvif->txpower = vif->bss_conf.txpower;
3497 ret = ath10k_mac_txpower_recalc(ar);
3498 if (ret) {
3499 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3500 goto err_peer_delete;
3501 }
3502
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003504 return 0;
3505
3506err_peer_delete:
3507 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3508 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3509
3510err_vdev_delete:
3511 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003512 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003513 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003514
3515err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003516 if (arvif->beacon_buf) {
3517 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3518 arvif->beacon_buf, arvif->beacon_paddr);
3519 arvif->beacon_buf = NULL;
3520 }
3521
Michal Kazior9dad14a2013-10-16 15:44:45 +03003522 mutex_unlock(&ar->conf_mutex);
3523
Kalle Valo5e3dd152013-06-12 20:52:10 +03003524 return ret;
3525}
3526
3527static void ath10k_remove_interface(struct ieee80211_hw *hw,
3528 struct ieee80211_vif *vif)
3529{
3530 struct ath10k *ar = hw->priv;
3531 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3532 int ret;
3533
Michal Kazior81a9a172015-03-05 16:02:17 +02003534 cancel_work_sync(&arvif->ap_csa_work);
3535
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303536 mutex_lock(&ar->conf_mutex);
3537
Michal Kaziored543882013-09-13 14:16:56 +02003538 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003539 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003540 spin_unlock_bh(&ar->data_lock);
3541
Simon Wunderlich855aed12014-08-02 09:12:54 +03003542 ret = ath10k_spectral_vif_stop(arvif);
3543 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003544 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003545 arvif->vdev_id, ret);
3546
Ben Greear16c11172014-09-23 14:17:16 -07003547 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003548 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003549
3550 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003551 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3552 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003553 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003554 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003555 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003556
3557 kfree(arvif->u.ap.noa_data);
3558 }
3559
Michal Kazior7aa7a722014-08-25 12:09:38 +02003560 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003561 arvif->vdev_id);
3562
Kalle Valo5e3dd152013-06-12 20:52:10 +03003563 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3564 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003565 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003566 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567
Michal Kazior2c512052015-02-15 16:50:40 +02003568 /* Some firmware revisions don't notify host about self-peer removal
3569 * until after associated vdev is deleted.
3570 */
3571 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3572 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3573 vif->addr);
3574 if (ret)
3575 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3576 arvif->vdev_id, ret);
3577
3578 spin_lock_bh(&ar->data_lock);
3579 ar->num_peers--;
3580 spin_unlock_bh(&ar->data_lock);
3581 }
3582
Kalle Valo5e3dd152013-06-12 20:52:10 +03003583 ath10k_peer_cleanup(ar, arvif->vdev_id);
3584
3585 mutex_unlock(&ar->conf_mutex);
3586}
3587
3588/*
3589 * FIXME: Has to be verified.
3590 */
3591#define SUPPORTED_FILTERS \
3592 (FIF_PROMISC_IN_BSS | \
3593 FIF_ALLMULTI | \
3594 FIF_CONTROL | \
3595 FIF_PSPOLL | \
3596 FIF_OTHER_BSS | \
3597 FIF_BCN_PRBRESP_PROMISC | \
3598 FIF_PROBE_REQ | \
3599 FIF_FCSFAIL)
3600
3601static void ath10k_configure_filter(struct ieee80211_hw *hw,
3602 unsigned int changed_flags,
3603 unsigned int *total_flags,
3604 u64 multicast)
3605{
3606 struct ath10k *ar = hw->priv;
3607 int ret;
3608
3609 mutex_lock(&ar->conf_mutex);
3610
3611 changed_flags &= SUPPORTED_FILTERS;
3612 *total_flags &= SUPPORTED_FILTERS;
3613 ar->filter_flags = *total_flags;
3614
Michal Kazior19337472014-08-28 12:58:16 +02003615 ret = ath10k_monitor_recalc(ar);
3616 if (ret)
3617 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618
3619 mutex_unlock(&ar->conf_mutex);
3620}
3621
3622static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3623 struct ieee80211_vif *vif,
3624 struct ieee80211_bss_conf *info,
3625 u32 changed)
3626{
3627 struct ath10k *ar = hw->priv;
3628 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3629 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003630 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003631
3632 mutex_lock(&ar->conf_mutex);
3633
3634 if (changed & BSS_CHANGED_IBSS)
3635 ath10k_control_ibss(arvif, info, vif->addr);
3636
3637 if (changed & BSS_CHANGED_BEACON_INT) {
3638 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003639 vdev_param = ar->wmi.vdev_param->beacon_interval;
3640 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003641 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003642 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003643 "mac vdev %d beacon_interval %d\n",
3644 arvif->vdev_id, arvif->beacon_interval);
3645
Kalle Valo5e3dd152013-06-12 20:52:10 +03003646 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003647 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003648 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649 }
3650
3651 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003652 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003653 "vdev %d set beacon tx mode to staggered\n",
3654 arvif->vdev_id);
3655
Bartosz Markowski226a3392013-09-26 17:47:16 +02003656 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3657 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003658 WMI_BEACON_STAGGERED_MODE);
3659 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003660 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003661 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003662
3663 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3664 if (ret)
3665 ath10k_warn(ar, "failed to update beacon template: %d\n",
3666 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003667 }
3668
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003669 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3670 ret = ath10k_mac_setup_prb_tmpl(arvif);
3671 if (ret)
3672 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3673 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003674 }
3675
Michal Kaziorba2479f2015-01-24 12:14:51 +02003676 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003677 arvif->dtim_period = info->dtim_period;
3678
Michal Kazior7aa7a722014-08-25 12:09:38 +02003679 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003680 "mac vdev %d dtim_period %d\n",
3681 arvif->vdev_id, arvif->dtim_period);
3682
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003683 vdev_param = ar->wmi.vdev_param->dtim_period;
3684 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003685 arvif->dtim_period);
3686 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003687 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003688 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003689 }
3690
3691 if (changed & BSS_CHANGED_SSID &&
3692 vif->type == NL80211_IFTYPE_AP) {
3693 arvif->u.ap.ssid_len = info->ssid_len;
3694 if (info->ssid_len)
3695 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3696 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3697 }
3698
Michal Kazior077efc82014-10-21 10:10:29 +03003699 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3700 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003701
3702 if (changed & BSS_CHANGED_BEACON_ENABLED)
3703 ath10k_control_beaconing(arvif, info);
3704
3705 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003706 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003707 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003708 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003709
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003710 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003711 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003712 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003713 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003714 }
3715
3716 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003717 if (info->use_short_slot)
3718 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3719
3720 else
3721 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3722
Michal Kazior7aa7a722014-08-25 12:09:38 +02003723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003724 arvif->vdev_id, slottime);
3725
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003726 vdev_param = ar->wmi.vdev_param->slot_time;
3727 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003728 slottime);
3729 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003730 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003731 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003732 }
3733
3734 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735 if (info->use_short_preamble)
3736 preamble = WMI_VDEV_PREAMBLE_SHORT;
3737 else
3738 preamble = WMI_VDEV_PREAMBLE_LONG;
3739
Michal Kazior7aa7a722014-08-25 12:09:38 +02003740 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003741 "mac vdev %d preamble %dn",
3742 arvif->vdev_id, preamble);
3743
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003744 vdev_param = ar->wmi.vdev_param->preamble;
3745 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003746 preamble);
3747 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003748 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003749 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003750 }
3751
3752 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003753 if (info->assoc) {
3754 /* Workaround: Make sure monitor vdev is not running
3755 * when associating to prevent some firmware revisions
3756 * (e.g. 10.1 and 10.2) from crashing.
3757 */
3758 if (ar->monitor_started)
3759 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003760 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003761 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003762 } else {
3763 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003764 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003765 }
3766
Michal Kazior7d9d5582014-10-21 10:40:15 +03003767 if (changed & BSS_CHANGED_TXPOWER) {
3768 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3769 arvif->vdev_id, info->txpower);
3770
3771 arvif->txpower = info->txpower;
3772 ret = ath10k_mac_txpower_recalc(ar);
3773 if (ret)
3774 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3775 }
3776
Michal Kaziorbf14e652014-12-12 12:41:38 +01003777 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01003778 arvif->ps = vif->bss_conf.ps;
3779
3780 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01003781 if (ret)
3782 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3783 arvif->vdev_id, ret);
3784 }
3785
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786 mutex_unlock(&ar->conf_mutex);
3787}
3788
3789static int ath10k_hw_scan(struct ieee80211_hw *hw,
3790 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003791 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003792{
3793 struct ath10k *ar = hw->priv;
3794 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003795 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003796 struct wmi_start_scan_arg arg;
3797 int ret = 0;
3798 int i;
3799
3800 mutex_lock(&ar->conf_mutex);
3801
3802 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003803 switch (ar->scan.state) {
3804 case ATH10K_SCAN_IDLE:
3805 reinit_completion(&ar->scan.started);
3806 reinit_completion(&ar->scan.completed);
3807 ar->scan.state = ATH10K_SCAN_STARTING;
3808 ar->scan.is_roc = false;
3809 ar->scan.vdev_id = arvif->vdev_id;
3810 ret = 0;
3811 break;
3812 case ATH10K_SCAN_STARTING:
3813 case ATH10K_SCAN_RUNNING:
3814 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003816 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003817 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003818 spin_unlock_bh(&ar->data_lock);
3819
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003820 if (ret)
3821 goto exit;
3822
Kalle Valo5e3dd152013-06-12 20:52:10 +03003823 memset(&arg, 0, sizeof(arg));
3824 ath10k_wmi_start_scan_init(ar, &arg);
3825 arg.vdev_id = arvif->vdev_id;
3826 arg.scan_id = ATH10K_SCAN_ID;
3827
3828 if (!req->no_cck)
3829 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3830
3831 if (req->ie_len) {
3832 arg.ie_len = req->ie_len;
3833 memcpy(arg.ie, req->ie, arg.ie_len);
3834 }
3835
3836 if (req->n_ssids) {
3837 arg.n_ssids = req->n_ssids;
3838 for (i = 0; i < arg.n_ssids; i++) {
3839 arg.ssids[i].len = req->ssids[i].ssid_len;
3840 arg.ssids[i].ssid = req->ssids[i].ssid;
3841 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003842 } else {
3843 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003844 }
3845
3846 if (req->n_channels) {
3847 arg.n_channels = req->n_channels;
3848 for (i = 0; i < arg.n_channels; i++)
3849 arg.channels[i] = req->channels[i]->center_freq;
3850 }
3851
3852 ret = ath10k_start_scan(ar, &arg);
3853 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003854 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003855 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003856 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003857 spin_unlock_bh(&ar->data_lock);
3858 }
3859
3860exit:
3861 mutex_unlock(&ar->conf_mutex);
3862 return ret;
3863}
3864
3865static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3866 struct ieee80211_vif *vif)
3867{
3868 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869
3870 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003871 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003872 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003873
3874 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003875}
3876
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003877static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3878 struct ath10k_vif *arvif,
3879 enum set_key_cmd cmd,
3880 struct ieee80211_key_conf *key)
3881{
3882 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3883 int ret;
3884
3885 /* 10.1 firmware branch requires default key index to be set to group
3886 * key index after installing it. Otherwise FW/HW Txes corrupted
3887 * frames with multi-vif APs. This is not required for main firmware
3888 * branch (e.g. 636).
3889 *
3890 * FIXME: This has been tested only in AP. It remains unknown if this
3891 * is required for multi-vif STA interfaces on 10.1 */
3892
3893 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3894 return;
3895
3896 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3897 return;
3898
3899 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3900 return;
3901
3902 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3903 return;
3904
3905 if (cmd != SET_KEY)
3906 return;
3907
3908 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3909 key->keyidx);
3910 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003911 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003912 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003913}
3914
Kalle Valo5e3dd152013-06-12 20:52:10 +03003915static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3916 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3917 struct ieee80211_key_conf *key)
3918{
3919 struct ath10k *ar = hw->priv;
3920 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3921 struct ath10k_peer *peer;
3922 const u8 *peer_addr;
3923 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3924 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3925 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01003926 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927
3928 if (key->keyidx > WMI_MAX_KEY_INDEX)
3929 return -ENOSPC;
3930
3931 mutex_lock(&ar->conf_mutex);
3932
3933 if (sta)
3934 peer_addr = sta->addr;
3935 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3936 peer_addr = vif->bss_conf.bssid;
3937 else
3938 peer_addr = vif->addr;
3939
3940 key->hw_key_idx = key->keyidx;
3941
3942 /* the peer should not disappear in mid-way (unless FW goes awry) since
3943 * we already hold conf_mutex. we just make sure its there now. */
3944 spin_lock_bh(&ar->data_lock);
3945 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3946 spin_unlock_bh(&ar->data_lock);
3947
3948 if (!peer) {
3949 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003950 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003951 peer_addr);
3952 ret = -EOPNOTSUPP;
3953 goto exit;
3954 } else {
3955 /* if the peer doesn't exist there is no key to disable
3956 * anymore */
3957 goto exit;
3958 }
3959 }
3960
3961 if (is_wep) {
3962 if (cmd == SET_KEY)
3963 arvif->wep_keys[key->keyidx] = key;
3964 else
3965 arvif->wep_keys[key->keyidx] = NULL;
3966
3967 if (cmd == DISABLE_KEY)
3968 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01003969
3970 /* 802.1x never sets the def_wep_key_idx so each set_key()
3971 * call changes default tx key.
3972 *
3973 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
3974 * after first set_key().
3975 */
3976 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
3977 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978 }
3979
Michal Kazior370e5672015-02-18 14:02:26 +01003980 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3981 flags |= WMI_KEY_PAIRWISE;
3982 else
3983 flags |= WMI_KEY_GROUP;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003984
Michal Kazior370e5672015-02-18 14:02:26 +01003985 /* mac80211 uploads static WEP keys as groupwise while fw/hw requires
3986 * pairwise keys for non-self peers, i.e. BSSID in STA mode and
3987 * associated stations in AP/IBSS.
3988 *
3989 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys work
3990 * fine when mapped directly from mac80211.
3991 *
3992 * Note: When installing first static WEP groupwise key (which should
3993 * be pairwise) def_wep_key_idx isn't known yet (it's equal to -1).
3994 * Since .set_default_unicast_key is called only for static WEP it's
3995 * used to re-upload the key as pairwise.
3996 */
3997 if (arvif->def_wep_key_idx >= 0 &&
3998 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
3999 flags &= ~WMI_KEY_GROUP;
4000 flags |= WMI_KEY_PAIRWISE;
4001 }
4002
4003 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004004 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004005 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004006 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004007 goto exit;
4008 }
4009
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004010 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4011
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012 spin_lock_bh(&ar->data_lock);
4013 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4014 if (peer && cmd == SET_KEY)
4015 peer->keys[key->keyidx] = key;
4016 else if (peer && cmd == DISABLE_KEY)
4017 peer->keys[key->keyidx] = NULL;
4018 else if (peer == NULL)
4019 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004020 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021 spin_unlock_bh(&ar->data_lock);
4022
4023exit:
4024 mutex_unlock(&ar->conf_mutex);
4025 return ret;
4026}
4027
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004028static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4029 struct ieee80211_vif *vif,
4030 int keyidx)
4031{
4032 struct ath10k *ar = hw->priv;
4033 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4034 int ret;
4035
4036 mutex_lock(&arvif->ar->conf_mutex);
4037
4038 if (arvif->ar->state != ATH10K_STATE_ON)
4039 goto unlock;
4040
4041 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4042 arvif->vdev_id, keyidx);
4043
4044 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4045 arvif->vdev_id,
4046 arvif->ar->wmi.vdev_param->def_keyid,
4047 keyidx);
4048
4049 if (ret) {
4050 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4051 arvif->vdev_id,
4052 ret);
4053 goto unlock;
4054 }
4055
4056 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004057
4058 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4059 if (ret) {
4060 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4061 arvif->vdev_id, ret);
4062 goto unlock;
4063 }
4064
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004065unlock:
4066 mutex_unlock(&arvif->ar->conf_mutex);
4067}
4068
Michal Kazior9797feb2014-02-14 14:49:48 +01004069static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4070{
4071 struct ath10k *ar;
4072 struct ath10k_vif *arvif;
4073 struct ath10k_sta *arsta;
4074 struct ieee80211_sta *sta;
4075 u32 changed, bw, nss, smps;
4076 int err;
4077
4078 arsta = container_of(wk, struct ath10k_sta, update_wk);
4079 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4080 arvif = arsta->arvif;
4081 ar = arvif->ar;
4082
4083 spin_lock_bh(&ar->data_lock);
4084
4085 changed = arsta->changed;
4086 arsta->changed = 0;
4087
4088 bw = arsta->bw;
4089 nss = arsta->nss;
4090 smps = arsta->smps;
4091
4092 spin_unlock_bh(&ar->data_lock);
4093
4094 mutex_lock(&ar->conf_mutex);
4095
4096 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004097 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004098 sta->addr, bw);
4099
4100 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4101 WMI_PEER_CHAN_WIDTH, bw);
4102 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004103 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004104 sta->addr, bw, err);
4105 }
4106
4107 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004108 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004109 sta->addr, nss);
4110
4111 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4112 WMI_PEER_NSS, nss);
4113 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004114 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004115 sta->addr, nss, err);
4116 }
4117
4118 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004119 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004120 sta->addr, smps);
4121
4122 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4123 WMI_PEER_SMPS_STATE, smps);
4124 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004125 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004126 sta->addr, smps, err);
4127 }
4128
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004129 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4130 changed & IEEE80211_RC_NSS_CHANGED) {
4131 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004132 sta->addr);
4133
Michal Kazior590922a2014-10-21 10:10:29 +03004134 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004135 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004136 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004137 sta->addr);
4138 }
4139
Michal Kazior9797feb2014-02-14 14:49:48 +01004140 mutex_unlock(&ar->conf_mutex);
4141}
4142
Michal Kaziorcfd10612014-11-25 15:16:05 +01004143static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4144{
4145 struct ath10k *ar = arvif->ar;
4146
4147 lockdep_assert_held(&ar->conf_mutex);
4148
4149 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4150 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4151 return 0;
4152
4153 if (ar->num_stations >= ar->max_num_stations)
4154 return -ENOBUFS;
4155
4156 ar->num_stations++;
4157
4158 return 0;
4159}
4160
4161static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4162{
4163 struct ath10k *ar = arvif->ar;
4164
4165 lockdep_assert_held(&ar->conf_mutex);
4166
4167 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4168 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4169 return;
4170
4171 ar->num_stations--;
4172}
4173
Kalle Valo5e3dd152013-06-12 20:52:10 +03004174static int ath10k_sta_state(struct ieee80211_hw *hw,
4175 struct ieee80211_vif *vif,
4176 struct ieee80211_sta *sta,
4177 enum ieee80211_sta_state old_state,
4178 enum ieee80211_sta_state new_state)
4179{
4180 struct ath10k *ar = hw->priv;
4181 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004182 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004183 int ret = 0;
4184
Michal Kazior76f90022014-02-25 09:29:57 +02004185 if (old_state == IEEE80211_STA_NOTEXIST &&
4186 new_state == IEEE80211_STA_NONE) {
4187 memset(arsta, 0, sizeof(*arsta));
4188 arsta->arvif = arvif;
4189 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4190 }
4191
Michal Kazior9797feb2014-02-14 14:49:48 +01004192 /* cancel must be done outside the mutex to avoid deadlock */
4193 if ((old_state == IEEE80211_STA_NONE &&
4194 new_state == IEEE80211_STA_NOTEXIST))
4195 cancel_work_sync(&arsta->update_wk);
4196
Kalle Valo5e3dd152013-06-12 20:52:10 +03004197 mutex_lock(&ar->conf_mutex);
4198
4199 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004200 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004201 /*
4202 * New station addition.
4203 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01004204 ath10k_dbg(ar, ATH10K_DBG_MAC,
4205 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4206 arvif->vdev_id, sta->addr,
4207 ar->num_stations + 1, ar->max_num_stations,
4208 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004209
Michal Kaziorcfd10612014-11-25 15:16:05 +01004210 ret = ath10k_mac_inc_num_stations(arvif);
4211 if (ret) {
4212 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4213 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004214 goto exit;
4215 }
4216
Kalle Valo5e3dd152013-06-12 20:52:10 +03004217 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01004218 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004219 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 -08004220 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004221 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01004222 goto exit;
4223 }
Michal Kazior077efc82014-10-21 10:10:29 +03004224
4225 if (vif->type == NL80211_IFTYPE_STATION) {
4226 WARN_ON(arvif->is_started);
4227
4228 ret = ath10k_vdev_start(arvif);
4229 if (ret) {
4230 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4231 arvif->vdev_id, ret);
4232 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4233 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01004234 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03004235 goto exit;
4236 }
4237
4238 arvif->is_started = true;
4239 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004240 } else if ((old_state == IEEE80211_STA_NONE &&
4241 new_state == IEEE80211_STA_NOTEXIST)) {
4242 /*
4243 * Existing station deletion.
4244 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004245 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004246 "mac vdev %d peer delete %pM (sta gone)\n",
4247 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004248
4249 if (vif->type == NL80211_IFTYPE_STATION) {
4250 WARN_ON(!arvif->is_started);
4251
4252 ret = ath10k_vdev_stop(arvif);
4253 if (ret)
4254 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4255 arvif->vdev_id, ret);
4256
4257 arvif->is_started = false;
4258 }
4259
Kalle Valo5e3dd152013-06-12 20:52:10 +03004260 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4261 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004262 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004263 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004264
Michal Kaziorcfd10612014-11-25 15:16:05 +01004265 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266 } else if (old_state == IEEE80211_STA_AUTH &&
4267 new_state == IEEE80211_STA_ASSOC &&
4268 (vif->type == NL80211_IFTYPE_AP ||
4269 vif->type == NL80211_IFTYPE_ADHOC)) {
4270 /*
4271 * New association.
4272 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004273 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004274 sta->addr);
4275
Michal Kazior590922a2014-10-21 10:10:29 +03004276 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004277 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004278 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004279 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004280 } else if (old_state == IEEE80211_STA_ASSOC &&
4281 new_state == IEEE80211_STA_AUTH &&
4282 (vif->type == NL80211_IFTYPE_AP ||
4283 vif->type == NL80211_IFTYPE_ADHOC)) {
4284 /*
4285 * Disassociation.
4286 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004288 sta->addr);
4289
Michal Kazior590922a2014-10-21 10:10:29 +03004290 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004291 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004292 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004293 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004294 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004295exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004296 mutex_unlock(&ar->conf_mutex);
4297 return ret;
4298}
4299
4300static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004301 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004302{
4303 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004304 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4305 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004306 u32 value = 0;
4307 int ret = 0;
4308
Michal Kazior548db542013-07-05 16:15:15 +03004309 lockdep_assert_held(&ar->conf_mutex);
4310
Kalle Valo5e3dd152013-06-12 20:52:10 +03004311 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4312 return 0;
4313
4314 switch (ac) {
4315 case IEEE80211_AC_VO:
4316 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4317 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004318 prio = 7;
4319 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320 break;
4321 case IEEE80211_AC_VI:
4322 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4323 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004324 prio = 5;
4325 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004326 break;
4327 case IEEE80211_AC_BE:
4328 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4329 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004330 prio = 2;
4331 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004332 break;
4333 case IEEE80211_AC_BK:
4334 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4335 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004336 prio = 0;
4337 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004338 break;
4339 }
4340
4341 if (enable)
4342 arvif->u.sta.uapsd |= value;
4343 else
4344 arvif->u.sta.uapsd &= ~value;
4345
4346 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4347 WMI_STA_PS_PARAM_UAPSD,
4348 arvif->u.sta.uapsd);
4349 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004350 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004351 goto exit;
4352 }
4353
4354 if (arvif->u.sta.uapsd)
4355 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4356 else
4357 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4358
4359 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4360 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4361 value);
4362 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004363 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004364
Michal Kazior9f9b5742014-12-12 12:41:36 +01004365 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4366 if (ret) {
4367 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4368 arvif->vdev_id, ret);
4369 return ret;
4370 }
4371
4372 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4373 if (ret) {
4374 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4375 arvif->vdev_id, ret);
4376 return ret;
4377 }
4378
Michal Kaziorb0e56152015-01-24 12:14:52 +02004379 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4380 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4381 /* Only userspace can make an educated decision when to send
4382 * trigger frame. The following effectively disables u-UAPSD
4383 * autotrigger in firmware (which is enabled by default
4384 * provided the autotrigger service is available).
4385 */
4386
4387 arg.wmm_ac = acc;
4388 arg.user_priority = prio;
4389 arg.service_interval = 0;
4390 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4391 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4392
4393 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4394 arvif->bssid, &arg, 1);
4395 if (ret) {
4396 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4397 ret);
4398 return ret;
4399 }
4400 }
4401
Kalle Valo5e3dd152013-06-12 20:52:10 +03004402exit:
4403 return ret;
4404}
4405
4406static int ath10k_conf_tx(struct ieee80211_hw *hw,
4407 struct ieee80211_vif *vif, u16 ac,
4408 const struct ieee80211_tx_queue_params *params)
4409{
4410 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004411 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412 struct wmi_wmm_params_arg *p = NULL;
4413 int ret;
4414
4415 mutex_lock(&ar->conf_mutex);
4416
4417 switch (ac) {
4418 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004419 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004420 break;
4421 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004422 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004423 break;
4424 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004425 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004426 break;
4427 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004428 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004429 break;
4430 }
4431
4432 if (WARN_ON(!p)) {
4433 ret = -EINVAL;
4434 goto exit;
4435 }
4436
4437 p->cwmin = params->cw_min;
4438 p->cwmax = params->cw_max;
4439 p->aifs = params->aifs;
4440
4441 /*
4442 * The channel time duration programmed in the HW is in absolute
4443 * microseconds, while mac80211 gives the txop in units of
4444 * 32 microseconds.
4445 */
4446 p->txop = params->txop * 32;
4447
Michal Kazior7fc979a2015-01-28 09:57:28 +02004448 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4449 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4450 &arvif->wmm_params);
4451 if (ret) {
4452 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4453 arvif->vdev_id, ret);
4454 goto exit;
4455 }
4456 } else {
4457 /* This won't work well with multi-interface cases but it's
4458 * better than nothing.
4459 */
4460 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4461 if (ret) {
4462 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4463 goto exit;
4464 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004465 }
4466
4467 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4468 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004469 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004470
4471exit:
4472 mutex_unlock(&ar->conf_mutex);
4473 return ret;
4474}
4475
4476#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4477
4478static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4479 struct ieee80211_vif *vif,
4480 struct ieee80211_channel *chan,
4481 int duration,
4482 enum ieee80211_roc_type type)
4483{
4484 struct ath10k *ar = hw->priv;
4485 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4486 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004487 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004488
4489 mutex_lock(&ar->conf_mutex);
4490
4491 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004492 switch (ar->scan.state) {
4493 case ATH10K_SCAN_IDLE:
4494 reinit_completion(&ar->scan.started);
4495 reinit_completion(&ar->scan.completed);
4496 reinit_completion(&ar->scan.on_channel);
4497 ar->scan.state = ATH10K_SCAN_STARTING;
4498 ar->scan.is_roc = true;
4499 ar->scan.vdev_id = arvif->vdev_id;
4500 ar->scan.roc_freq = chan->center_freq;
4501 ret = 0;
4502 break;
4503 case ATH10K_SCAN_STARTING:
4504 case ATH10K_SCAN_RUNNING:
4505 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004506 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004507 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004508 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004509 spin_unlock_bh(&ar->data_lock);
4510
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004511 if (ret)
4512 goto exit;
4513
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004514 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4515
Kalle Valo5e3dd152013-06-12 20:52:10 +03004516 memset(&arg, 0, sizeof(arg));
4517 ath10k_wmi_start_scan_init(ar, &arg);
4518 arg.vdev_id = arvif->vdev_id;
4519 arg.scan_id = ATH10K_SCAN_ID;
4520 arg.n_channels = 1;
4521 arg.channels[0] = chan->center_freq;
4522 arg.dwell_time_active = duration;
4523 arg.dwell_time_passive = duration;
4524 arg.max_scan_time = 2 * duration;
4525 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4526 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4527
4528 ret = ath10k_start_scan(ar, &arg);
4529 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004530 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004531 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004532 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004533 spin_unlock_bh(&ar->data_lock);
4534 goto exit;
4535 }
4536
4537 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4538 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004539 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004540
4541 ret = ath10k_scan_stop(ar);
4542 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004543 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004544
Kalle Valo5e3dd152013-06-12 20:52:10 +03004545 ret = -ETIMEDOUT;
4546 goto exit;
4547 }
4548
4549 ret = 0;
4550exit:
4551 mutex_unlock(&ar->conf_mutex);
4552 return ret;
4553}
4554
4555static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4556{
4557 struct ath10k *ar = hw->priv;
4558
4559 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004560 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004561 mutex_unlock(&ar->conf_mutex);
4562
Michal Kazior4eb2e162014-10-28 10:23:09 +01004563 cancel_delayed_work_sync(&ar->scan.timeout);
4564
Kalle Valo5e3dd152013-06-12 20:52:10 +03004565 return 0;
4566}
4567
4568/*
4569 * Both RTS and Fragmentation threshold are interface-specific
4570 * in ath10k, but device-specific in mac80211.
4571 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004572
4573static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4574{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004575 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004576 struct ath10k_vif *arvif;
4577 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004578
Michal Kaziorad088bf2013-10-16 15:44:46 +03004579 mutex_lock(&ar->conf_mutex);
4580 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004581 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004582 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004583
Michal Kaziorad088bf2013-10-16 15:44:46 +03004584 ret = ath10k_mac_set_rts(arvif, value);
4585 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004586 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004587 arvif->vdev_id, ret);
4588 break;
4589 }
4590 }
4591 mutex_unlock(&ar->conf_mutex);
4592
4593 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004594}
4595
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004596static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4597 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004598{
4599 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004600 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004601 int ret;
4602
4603 /* mac80211 doesn't care if we really xmit queued frames or not
4604 * we'll collect those frames either way if we stop/delete vdevs */
4605 if (drop)
4606 return;
4607
Michal Kazior548db542013-07-05 16:15:15 +03004608 mutex_lock(&ar->conf_mutex);
4609
Michal Kazioraffd3212013-07-16 09:54:35 +02004610 if (ar->state == ATH10K_STATE_WEDGED)
4611 goto skip;
4612
Michal Kazioredb82362013-07-05 16:15:14 +03004613 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004614 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004615
Michal Kazioredb82362013-07-05 16:15:14 +03004616 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004617 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004618 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004619
Michal Kazior7962b0d2014-10-28 10:34:38 +01004620 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4621 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4622 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004623
4624 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004625 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004626
4627 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004628 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004629 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004630
Michal Kazioraffd3212013-07-16 09:54:35 +02004631skip:
Michal Kazior548db542013-07-05 16:15:15 +03004632 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004633}
4634
4635/* TODO: Implement this function properly
4636 * For now it is needed to reply to Probe Requests in IBSS mode.
4637 * Propably we need this information from FW.
4638 */
4639static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4640{
4641 return 1;
4642}
4643
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004644#ifdef CONFIG_PM
4645static int ath10k_suspend(struct ieee80211_hw *hw,
4646 struct cfg80211_wowlan *wowlan)
4647{
4648 struct ath10k *ar = hw->priv;
4649 int ret;
4650
Marek Puzyniak9042e172014-02-10 17:14:23 +01004651 mutex_lock(&ar->conf_mutex);
4652
Marek Puzyniak00f54822014-02-10 17:14:24 +01004653 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004654 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004655 if (ret == -ETIMEDOUT)
4656 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004657 ret = 1;
4658 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004659 }
4660
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004661 ret = ath10k_hif_suspend(ar);
4662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004663 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004664 goto resume;
4665 }
4666
Marek Puzyniak9042e172014-02-10 17:14:23 +01004667 ret = 0;
4668 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004669resume:
4670 ret = ath10k_wmi_pdev_resume_target(ar);
4671 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004672 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004673
4674 ret = 1;
4675exit:
4676 mutex_unlock(&ar->conf_mutex);
4677 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004678}
4679
4680static int ath10k_resume(struct ieee80211_hw *hw)
4681{
4682 struct ath10k *ar = hw->priv;
4683 int ret;
4684
Marek Puzyniak9042e172014-02-10 17:14:23 +01004685 mutex_lock(&ar->conf_mutex);
4686
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004687 ret = ath10k_hif_resume(ar);
4688 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004689 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004690 ret = 1;
4691 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004692 }
4693
4694 ret = ath10k_wmi_pdev_resume_target(ar);
4695 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004696 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004697 ret = 1;
4698 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004699 }
4700
Marek Puzyniak9042e172014-02-10 17:14:23 +01004701 ret = 0;
4702exit:
4703 mutex_unlock(&ar->conf_mutex);
4704 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004705}
4706#endif
4707
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004708static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4709 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004710{
4711 struct ath10k *ar = hw->priv;
4712
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004713 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4714 return;
4715
Michal Kazioraffd3212013-07-16 09:54:35 +02004716 mutex_lock(&ar->conf_mutex);
4717
4718 /* If device failed to restart it will be in a different state, e.g.
4719 * ATH10K_STATE_WEDGED */
4720 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004721 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004722 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004723 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004724 }
4725
4726 mutex_unlock(&ar->conf_mutex);
4727}
4728
Michal Kazior2e1dea42013-07-31 10:32:40 +02004729static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4730 struct survey_info *survey)
4731{
4732 struct ath10k *ar = hw->priv;
4733 struct ieee80211_supported_band *sband;
4734 struct survey_info *ar_survey = &ar->survey[idx];
4735 int ret = 0;
4736
4737 mutex_lock(&ar->conf_mutex);
4738
4739 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4740 if (sband && idx >= sband->n_channels) {
4741 idx -= sband->n_channels;
4742 sband = NULL;
4743 }
4744
4745 if (!sband)
4746 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4747
4748 if (!sband || idx >= sband->n_channels) {
4749 ret = -ENOENT;
4750 goto exit;
4751 }
4752
4753 spin_lock_bh(&ar->data_lock);
4754 memcpy(survey, ar_survey, sizeof(*survey));
4755 spin_unlock_bh(&ar->data_lock);
4756
4757 survey->channel = &sband->channels[idx];
4758
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004759 if (ar->rx_channel == survey->channel)
4760 survey->filled |= SURVEY_INFO_IN_USE;
4761
Michal Kazior2e1dea42013-07-31 10:32:40 +02004762exit:
4763 mutex_unlock(&ar->conf_mutex);
4764 return ret;
4765}
4766
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004767/* Helper table for legacy fixed_rate/bitrate_mask */
4768static const u8 cck_ofdm_rate[] = {
4769 /* CCK */
4770 3, /* 1Mbps */
4771 2, /* 2Mbps */
4772 1, /* 5.5Mbps */
4773 0, /* 11Mbps */
4774 /* OFDM */
4775 3, /* 6Mbps */
4776 7, /* 9Mbps */
4777 2, /* 12Mbps */
4778 6, /* 18Mbps */
4779 1, /* 24Mbps */
4780 5, /* 36Mbps */
4781 0, /* 48Mbps */
4782 4, /* 54Mbps */
4783};
4784
4785/* Check if only one bit set */
4786static int ath10k_check_single_mask(u32 mask)
4787{
4788 int bit;
4789
4790 bit = ffs(mask);
4791 if (!bit)
4792 return 0;
4793
4794 mask &= ~BIT(bit - 1);
4795 if (mask)
4796 return 2;
4797
4798 return 1;
4799}
4800
4801static bool
4802ath10k_default_bitrate_mask(struct ath10k *ar,
4803 enum ieee80211_band band,
4804 const struct cfg80211_bitrate_mask *mask)
4805{
4806 u32 legacy = 0x00ff;
4807 u8 ht = 0xff, i;
4808 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004809 u16 nrf = ar->num_rf_chains;
4810
4811 if (ar->cfg_tx_chainmask)
4812 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004813
4814 switch (band) {
4815 case IEEE80211_BAND_2GHZ:
4816 legacy = 0x00fff;
4817 vht = 0;
4818 break;
4819 case IEEE80211_BAND_5GHZ:
4820 break;
4821 default:
4822 return false;
4823 }
4824
4825 if (mask->control[band].legacy != legacy)
4826 return false;
4827
Ben Greearb116ea12014-11-24 16:22:10 +02004828 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004829 if (mask->control[band].ht_mcs[i] != ht)
4830 return false;
4831
Ben Greearb116ea12014-11-24 16:22:10 +02004832 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004833 if (mask->control[band].vht_mcs[i] != vht)
4834 return false;
4835
4836 return true;
4837}
4838
4839static bool
4840ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4841 enum ieee80211_band band,
4842 u8 *fixed_nss)
4843{
4844 int ht_nss = 0, vht_nss = 0, i;
4845
4846 /* check legacy */
4847 if (ath10k_check_single_mask(mask->control[band].legacy))
4848 return false;
4849
4850 /* check HT */
4851 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4852 if (mask->control[band].ht_mcs[i] == 0xff)
4853 continue;
4854 else if (mask->control[band].ht_mcs[i] == 0x00)
4855 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004856
4857 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004858 }
4859
4860 ht_nss = i;
4861
4862 /* check VHT */
4863 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4864 if (mask->control[band].vht_mcs[i] == 0x03ff)
4865 continue;
4866 else if (mask->control[band].vht_mcs[i] == 0x0000)
4867 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004868
4869 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004870 }
4871
4872 vht_nss = i;
4873
4874 if (ht_nss > 0 && vht_nss > 0)
4875 return false;
4876
4877 if (ht_nss)
4878 *fixed_nss = ht_nss;
4879 else if (vht_nss)
4880 *fixed_nss = vht_nss;
4881 else
4882 return false;
4883
4884 return true;
4885}
4886
4887static bool
4888ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4889 enum ieee80211_band band,
4890 enum wmi_rate_preamble *preamble)
4891{
4892 int legacy = 0, ht = 0, vht = 0, i;
4893
4894 *preamble = WMI_RATE_PREAMBLE_OFDM;
4895
4896 /* check legacy */
4897 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4898 if (legacy > 1)
4899 return false;
4900
4901 /* check HT */
4902 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4903 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4904 if (ht > 1)
4905 return false;
4906
4907 /* check VHT */
4908 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4909 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4910 if (vht > 1)
4911 return false;
4912
4913 /* Currently we support only one fixed_rate */
4914 if ((legacy + ht + vht) != 1)
4915 return false;
4916
4917 if (ht)
4918 *preamble = WMI_RATE_PREAMBLE_HT;
4919 else if (vht)
4920 *preamble = WMI_RATE_PREAMBLE_VHT;
4921
4922 return true;
4923}
4924
4925static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004926ath10k_bitrate_mask_rate(struct ath10k *ar,
4927 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004928 enum ieee80211_band band,
4929 u8 *fixed_rate,
4930 u8 *fixed_nss)
4931{
4932 u8 rate = 0, pream = 0, nss = 0, i;
4933 enum wmi_rate_preamble preamble;
4934
4935 /* Check if single rate correct */
4936 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4937 return false;
4938
4939 pream = preamble;
4940
4941 switch (preamble) {
4942 case WMI_RATE_PREAMBLE_CCK:
4943 case WMI_RATE_PREAMBLE_OFDM:
4944 i = ffs(mask->control[band].legacy) - 1;
4945
4946 if (band == IEEE80211_BAND_2GHZ && i < 4)
4947 pream = WMI_RATE_PREAMBLE_CCK;
4948
4949 if (band == IEEE80211_BAND_5GHZ)
4950 i += 4;
4951
4952 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4953 return false;
4954
4955 rate = cck_ofdm_rate[i];
4956 break;
4957 case WMI_RATE_PREAMBLE_HT:
4958 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4959 if (mask->control[band].ht_mcs[i])
4960 break;
4961
4962 if (i == IEEE80211_HT_MCS_MASK_LEN)
4963 return false;
4964
4965 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4966 nss = i;
4967 break;
4968 case WMI_RATE_PREAMBLE_VHT:
4969 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4970 if (mask->control[band].vht_mcs[i])
4971 break;
4972
4973 if (i == NL80211_VHT_NSS_MAX)
4974 return false;
4975
4976 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4977 nss = i;
4978 break;
4979 }
4980
4981 *fixed_nss = nss + 1;
4982 nss <<= 4;
4983 pream <<= 6;
4984
Michal Kazior7aa7a722014-08-25 12:09:38 +02004985 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 +01004986 pream, nss, rate);
4987
4988 *fixed_rate = pream | nss | rate;
4989
4990 return true;
4991}
4992
Michal Kazior7aa7a722014-08-25 12:09:38 +02004993static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4994 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004995 enum ieee80211_band band,
4996 u8 *fixed_rate,
4997 u8 *fixed_nss)
4998{
4999 /* First check full NSS mask, if we can simply limit NSS */
5000 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5001 return true;
5002
5003 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005004 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005005}
5006
5007static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5008 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005009 u8 fixed_nss,
5010 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005011{
5012 struct ath10k *ar = arvif->ar;
5013 u32 vdev_param;
5014 int ret = 0;
5015
5016 mutex_lock(&ar->conf_mutex);
5017
5018 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005019 arvif->fixed_nss == fixed_nss &&
5020 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005021 goto exit;
5022
5023 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005024 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005025
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005026 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005027 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005028
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005029 vdev_param = ar->wmi.vdev_param->fixed_rate;
5030 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5031 vdev_param, fixed_rate);
5032 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005033 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005034 fixed_rate, ret);
5035 ret = -EINVAL;
5036 goto exit;
5037 }
5038
5039 arvif->fixed_rate = fixed_rate;
5040
5041 vdev_param = ar->wmi.vdev_param->nss;
5042 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5043 vdev_param, fixed_nss);
5044
5045 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005046 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005047 fixed_nss, ret);
5048 ret = -EINVAL;
5049 goto exit;
5050 }
5051
5052 arvif->fixed_nss = fixed_nss;
5053
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005054 vdev_param = ar->wmi.vdev_param->sgi;
5055 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5056 force_sgi);
5057
5058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005059 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005060 force_sgi, ret);
5061 ret = -EINVAL;
5062 goto exit;
5063 }
5064
5065 arvif->force_sgi = force_sgi;
5066
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005067exit:
5068 mutex_unlock(&ar->conf_mutex);
5069 return ret;
5070}
5071
5072static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5073 struct ieee80211_vif *vif,
5074 const struct cfg80211_bitrate_mask *mask)
5075{
5076 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5077 struct ath10k *ar = arvif->ar;
5078 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5079 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5080 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005081 u8 force_sgi;
5082
Ben Greearb116ea12014-11-24 16:22:10 +02005083 if (ar->cfg_tx_chainmask)
5084 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5085
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005086 force_sgi = mask->control[band].gi;
5087 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5088 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005089
5090 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005091 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005092 &fixed_rate,
5093 &fixed_nss))
5094 return -EINVAL;
5095 }
5096
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005097 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005098 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005099 return -EINVAL;
5100 }
5101
5102 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5103 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005104}
5105
Michal Kazior9797feb2014-02-14 14:49:48 +01005106static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5107 struct ieee80211_vif *vif,
5108 struct ieee80211_sta *sta,
5109 u32 changed)
5110{
5111 struct ath10k *ar = hw->priv;
5112 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5113 u32 bw, smps;
5114
5115 spin_lock_bh(&ar->data_lock);
5116
Michal Kazior7aa7a722014-08-25 12:09:38 +02005117 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005118 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5119 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5120 sta->smps_mode);
5121
5122 if (changed & IEEE80211_RC_BW_CHANGED) {
5123 bw = WMI_PEER_CHWIDTH_20MHZ;
5124
5125 switch (sta->bandwidth) {
5126 case IEEE80211_STA_RX_BW_20:
5127 bw = WMI_PEER_CHWIDTH_20MHZ;
5128 break;
5129 case IEEE80211_STA_RX_BW_40:
5130 bw = WMI_PEER_CHWIDTH_40MHZ;
5131 break;
5132 case IEEE80211_STA_RX_BW_80:
5133 bw = WMI_PEER_CHWIDTH_80MHZ;
5134 break;
5135 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005136 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005137 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005138 bw = WMI_PEER_CHWIDTH_20MHZ;
5139 break;
5140 }
5141
5142 arsta->bw = bw;
5143 }
5144
5145 if (changed & IEEE80211_RC_NSS_CHANGED)
5146 arsta->nss = sta->rx_nss;
5147
5148 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5149 smps = WMI_PEER_SMPS_PS_NONE;
5150
5151 switch (sta->smps_mode) {
5152 case IEEE80211_SMPS_AUTOMATIC:
5153 case IEEE80211_SMPS_OFF:
5154 smps = WMI_PEER_SMPS_PS_NONE;
5155 break;
5156 case IEEE80211_SMPS_STATIC:
5157 smps = WMI_PEER_SMPS_STATIC;
5158 break;
5159 case IEEE80211_SMPS_DYNAMIC:
5160 smps = WMI_PEER_SMPS_DYNAMIC;
5161 break;
5162 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005163 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005164 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005165 smps = WMI_PEER_SMPS_PS_NONE;
5166 break;
5167 }
5168
5169 arsta->smps = smps;
5170 }
5171
Michal Kazior9797feb2014-02-14 14:49:48 +01005172 arsta->changed |= changed;
5173
5174 spin_unlock_bh(&ar->data_lock);
5175
5176 ieee80211_queue_work(hw, &arsta->update_wk);
5177}
5178
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005179static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5180{
5181 /*
5182 * FIXME: Return 0 for time being. Need to figure out whether FW
5183 * has the API to fetch 64-bit local TSF
5184 */
5185
5186 return 0;
5187}
5188
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005189static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5190 struct ieee80211_vif *vif,
5191 enum ieee80211_ampdu_mlme_action action,
5192 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5193 u8 buf_size)
5194{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005195 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005196 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5197
Michal Kazior7aa7a722014-08-25 12:09:38 +02005198 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 +02005199 arvif->vdev_id, sta->addr, tid, action);
5200
5201 switch (action) {
5202 case IEEE80211_AMPDU_RX_START:
5203 case IEEE80211_AMPDU_RX_STOP:
5204 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5205 * creation/removal. Do we need to verify this?
5206 */
5207 return 0;
5208 case IEEE80211_AMPDU_TX_START:
5209 case IEEE80211_AMPDU_TX_STOP_CONT:
5210 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5211 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5212 case IEEE80211_AMPDU_TX_OPERATIONAL:
5213 /* Firmware offloads Tx aggregation entirely so deny mac80211
5214 * Tx aggregation requests.
5215 */
5216 return -EOPNOTSUPP;
5217 }
5218
5219 return -EINVAL;
5220}
5221
Kalle Valo5e3dd152013-06-12 20:52:10 +03005222static const struct ieee80211_ops ath10k_ops = {
5223 .tx = ath10k_tx,
5224 .start = ath10k_start,
5225 .stop = ath10k_stop,
5226 .config = ath10k_config,
5227 .add_interface = ath10k_add_interface,
5228 .remove_interface = ath10k_remove_interface,
5229 .configure_filter = ath10k_configure_filter,
5230 .bss_info_changed = ath10k_bss_info_changed,
5231 .hw_scan = ath10k_hw_scan,
5232 .cancel_hw_scan = ath10k_cancel_hw_scan,
5233 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005234 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005235 .sta_state = ath10k_sta_state,
5236 .conf_tx = ath10k_conf_tx,
5237 .remain_on_channel = ath10k_remain_on_channel,
5238 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5239 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005240 .flush = ath10k_flush,
5241 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005242 .set_antenna = ath10k_set_antenna,
5243 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005244 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005245 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005246 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005247 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005248 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005249 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005250 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5251 .get_et_stats = ath10k_debug_get_et_stats,
5252 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005253
5254 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5255
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005256#ifdef CONFIG_PM
5257 .suspend = ath10k_suspend,
5258 .resume = ath10k_resume,
5259#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005260#ifdef CONFIG_MAC80211_DEBUGFS
5261 .sta_add_debugfs = ath10k_sta_add_debugfs,
5262#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005263};
5264
5265#define RATETAB_ENT(_rate, _rateid, _flags) { \
5266 .bitrate = (_rate), \
5267 .flags = (_flags), \
5268 .hw_value = (_rateid), \
5269}
5270
5271#define CHAN2G(_channel, _freq, _flags) { \
5272 .band = IEEE80211_BAND_2GHZ, \
5273 .hw_value = (_channel), \
5274 .center_freq = (_freq), \
5275 .flags = (_flags), \
5276 .max_antenna_gain = 0, \
5277 .max_power = 30, \
5278}
5279
5280#define CHAN5G(_channel, _freq, _flags) { \
5281 .band = IEEE80211_BAND_5GHZ, \
5282 .hw_value = (_channel), \
5283 .center_freq = (_freq), \
5284 .flags = (_flags), \
5285 .max_antenna_gain = 0, \
5286 .max_power = 30, \
5287}
5288
5289static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5290 CHAN2G(1, 2412, 0),
5291 CHAN2G(2, 2417, 0),
5292 CHAN2G(3, 2422, 0),
5293 CHAN2G(4, 2427, 0),
5294 CHAN2G(5, 2432, 0),
5295 CHAN2G(6, 2437, 0),
5296 CHAN2G(7, 2442, 0),
5297 CHAN2G(8, 2447, 0),
5298 CHAN2G(9, 2452, 0),
5299 CHAN2G(10, 2457, 0),
5300 CHAN2G(11, 2462, 0),
5301 CHAN2G(12, 2467, 0),
5302 CHAN2G(13, 2472, 0),
5303 CHAN2G(14, 2484, 0),
5304};
5305
5306static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005307 CHAN5G(36, 5180, 0),
5308 CHAN5G(40, 5200, 0),
5309 CHAN5G(44, 5220, 0),
5310 CHAN5G(48, 5240, 0),
5311 CHAN5G(52, 5260, 0),
5312 CHAN5G(56, 5280, 0),
5313 CHAN5G(60, 5300, 0),
5314 CHAN5G(64, 5320, 0),
5315 CHAN5G(100, 5500, 0),
5316 CHAN5G(104, 5520, 0),
5317 CHAN5G(108, 5540, 0),
5318 CHAN5G(112, 5560, 0),
5319 CHAN5G(116, 5580, 0),
5320 CHAN5G(120, 5600, 0),
5321 CHAN5G(124, 5620, 0),
5322 CHAN5G(128, 5640, 0),
5323 CHAN5G(132, 5660, 0),
5324 CHAN5G(136, 5680, 0),
5325 CHAN5G(140, 5700, 0),
5326 CHAN5G(149, 5745, 0),
5327 CHAN5G(153, 5765, 0),
5328 CHAN5G(157, 5785, 0),
5329 CHAN5G(161, 5805, 0),
5330 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005331};
5332
Michal Kazior91b12082014-12-12 12:41:35 +01005333/* Note: Be careful if you re-order these. There is code which depends on this
5334 * ordering.
5335 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005336static struct ieee80211_rate ath10k_rates[] = {
5337 /* CCK */
5338 RATETAB_ENT(10, 0x82, 0),
5339 RATETAB_ENT(20, 0x84, 0),
5340 RATETAB_ENT(55, 0x8b, 0),
5341 RATETAB_ENT(110, 0x96, 0),
5342 /* OFDM */
5343 RATETAB_ENT(60, 0x0c, 0),
5344 RATETAB_ENT(90, 0x12, 0),
5345 RATETAB_ENT(120, 0x18, 0),
5346 RATETAB_ENT(180, 0x24, 0),
5347 RATETAB_ENT(240, 0x30, 0),
5348 RATETAB_ENT(360, 0x48, 0),
5349 RATETAB_ENT(480, 0x60, 0),
5350 RATETAB_ENT(540, 0x6c, 0),
5351};
5352
5353#define ath10k_a_rates (ath10k_rates + 4)
5354#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5355#define ath10k_g_rates (ath10k_rates + 0)
5356#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5357
Michal Kaziore7b54192014-08-07 11:03:27 +02005358struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005359{
5360 struct ieee80211_hw *hw;
5361 struct ath10k *ar;
5362
Michal Kaziore7b54192014-08-07 11:03:27 +02005363 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005364 if (!hw)
5365 return NULL;
5366
5367 ar = hw->priv;
5368 ar->hw = hw;
5369
5370 return ar;
5371}
5372
5373void ath10k_mac_destroy(struct ath10k *ar)
5374{
5375 ieee80211_free_hw(ar->hw);
5376}
5377
5378static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5379 {
5380 .max = 8,
5381 .types = BIT(NL80211_IFTYPE_STATION)
5382 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005383 },
5384 {
5385 .max = 3,
5386 .types = BIT(NL80211_IFTYPE_P2P_GO)
5387 },
5388 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005389 .max = 1,
5390 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5391 },
5392 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005393 .max = 7,
5394 .types = BIT(NL80211_IFTYPE_AP)
5395 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005396};
5397
Bartosz Markowskif2595092013-12-10 16:20:39 +01005398static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005399 {
5400 .max = 8,
5401 .types = BIT(NL80211_IFTYPE_AP)
5402 },
5403};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005404
5405static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5406 {
5407 .limits = ath10k_if_limits,
5408 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5409 .max_interfaces = 8,
5410 .num_different_channels = 1,
5411 .beacon_int_infra_match = true,
5412 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005413};
5414
5415static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005416 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005417 .limits = ath10k_10x_if_limits,
5418 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005419 .max_interfaces = 8,
5420 .num_different_channels = 1,
5421 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005422#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005423 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5424 BIT(NL80211_CHAN_WIDTH_20) |
5425 BIT(NL80211_CHAN_WIDTH_40) |
5426 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005427#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005428 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005429};
5430
5431static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5432{
5433 struct ieee80211_sta_vht_cap vht_cap = {0};
5434 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005435 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005436
5437 vht_cap.vht_supported = 1;
5438 vht_cap.cap = ar->vht_cap_info;
5439
Michal Kazior8865bee42013-07-24 12:36:46 +02005440 mcs_map = 0;
5441 for (i = 0; i < 8; i++) {
5442 if (i < ar->num_rf_chains)
5443 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5444 else
5445 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5446 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005447
5448 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5449 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5450
5451 return vht_cap;
5452}
5453
5454static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5455{
5456 int i;
5457 struct ieee80211_sta_ht_cap ht_cap = {0};
5458
5459 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5460 return ht_cap;
5461
5462 ht_cap.ht_supported = 1;
5463 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5464 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5465 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5466 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5467 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5468
5469 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5470 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5471
5472 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5473 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5474
5475 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5476 u32 smps;
5477
5478 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5479 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5480
5481 ht_cap.cap |= smps;
5482 }
5483
5484 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5485 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5486
5487 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5488 u32 stbc;
5489
5490 stbc = ar->ht_cap_info;
5491 stbc &= WMI_HT_CAP_RX_STBC;
5492 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5493 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5494 stbc &= IEEE80211_HT_CAP_RX_STBC;
5495
5496 ht_cap.cap |= stbc;
5497 }
5498
5499 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5500 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5501
5502 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5503 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5504
5505 /* max AMSDU is implicitly taken from vht_cap_info */
5506 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5507 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5508
Michal Kazior8865bee42013-07-24 12:36:46 +02005509 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005510 ht_cap.mcs.rx_mask[i] = 0xFF;
5511
5512 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5513
5514 return ht_cap;
5515}
5516
Kalle Valo5e3dd152013-06-12 20:52:10 +03005517static void ath10k_get_arvif_iter(void *data, u8 *mac,
5518 struct ieee80211_vif *vif)
5519{
5520 struct ath10k_vif_iter *arvif_iter = data;
5521 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5522
5523 if (arvif->vdev_id == arvif_iter->vdev_id)
5524 arvif_iter->arvif = arvif;
5525}
5526
5527struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5528{
5529 struct ath10k_vif_iter arvif_iter;
5530 u32 flags;
5531
5532 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5533 arvif_iter.vdev_id = vdev_id;
5534
5535 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5536 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5537 flags,
5538 ath10k_get_arvif_iter,
5539 &arvif_iter);
5540 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005541 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005542 return NULL;
5543 }
5544
5545 return arvif_iter.arvif;
5546}
5547
5548int ath10k_mac_register(struct ath10k *ar)
5549{
Johannes Berg3cb10942015-01-22 21:38:45 +01005550 static const u32 cipher_suites[] = {
5551 WLAN_CIPHER_SUITE_WEP40,
5552 WLAN_CIPHER_SUITE_WEP104,
5553 WLAN_CIPHER_SUITE_TKIP,
5554 WLAN_CIPHER_SUITE_CCMP,
5555 WLAN_CIPHER_SUITE_AES_CMAC,
5556 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03005557 struct ieee80211_supported_band *band;
5558 struct ieee80211_sta_vht_cap vht_cap;
5559 struct ieee80211_sta_ht_cap ht_cap;
5560 void *channels;
5561 int ret;
5562
5563 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5564
5565 SET_IEEE80211_DEV(ar->hw, ar->dev);
5566
5567 ht_cap = ath10k_get_ht_cap(ar);
5568 vht_cap = ath10k_create_vht_cap(ar);
5569
5570 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5571 channels = kmemdup(ath10k_2ghz_channels,
5572 sizeof(ath10k_2ghz_channels),
5573 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005574 if (!channels) {
5575 ret = -ENOMEM;
5576 goto err_free;
5577 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005578
5579 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5580 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5581 band->channels = channels;
5582 band->n_bitrates = ath10k_g_rates_size;
5583 band->bitrates = ath10k_g_rates;
5584 band->ht_cap = ht_cap;
5585
Yanbo Lid68bb122015-01-23 08:18:20 +08005586 /* Enable the VHT support at 2.4 GHz */
5587 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005588
5589 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5590 }
5591
5592 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5593 channels = kmemdup(ath10k_5ghz_channels,
5594 sizeof(ath10k_5ghz_channels),
5595 GFP_KERNEL);
5596 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005597 ret = -ENOMEM;
5598 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005599 }
5600
5601 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5602 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5603 band->channels = channels;
5604 band->n_bitrates = ath10k_a_rates_size;
5605 band->bitrates = ath10k_a_rates;
5606 band->ht_cap = ht_cap;
5607 band->vht_cap = vht_cap;
5608 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5609 }
5610
5611 ar->hw->wiphy->interface_modes =
5612 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005613 BIT(NL80211_IFTYPE_AP);
5614
Ben Greear46acf7b2014-05-16 17:15:38 +03005615 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5616 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5617
Bartosz Markowskid3541812013-12-10 16:20:40 +01005618 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5619 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005620 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005621 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5622 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005623
5624 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5625 IEEE80211_HW_SUPPORTS_PS |
5626 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03005627 IEEE80211_HW_MFP_CAPABLE |
5628 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5629 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005630 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01005631 IEEE80211_HW_SPECTRUM_MGMT |
5632 IEEE80211_HW_SW_CRYPTO_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005633
Eliad Peller0d8614b2014-09-10 14:07:36 +03005634 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5635
Kalle Valo5e3dd152013-06-12 20:52:10 +03005636 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005637 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005638
5639 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5640 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5641 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5642 }
5643
5644 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5645 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5646
5647 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005648 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005649
Kalle Valo5e3dd152013-06-12 20:52:10 +03005650 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5651
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005652 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5653 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5654
5655 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5656 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5657 * correct Probe Responses. This is more of a hack advert..
5658 */
5659 ar->hw->wiphy->probe_resp_offload |=
5660 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5661 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5662 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5663 }
5664
Kalle Valo5e3dd152013-06-12 20:52:10 +03005665 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005666 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005667 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5668
5669 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005670 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5671
Kalle Valo5e3dd152013-06-12 20:52:10 +03005672 /*
5673 * on LL hardware queues are managed entirely by the FW
5674 * so we only advertise to mac we can do the queues thing
5675 */
5676 ar->hw->queues = 4;
5677
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005678 switch (ar->wmi.op_version) {
5679 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5680 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005681 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5682 ar->hw->wiphy->n_iface_combinations =
5683 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005684 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005685 break;
5686 case ATH10K_FW_WMI_OP_VERSION_10_1:
5687 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005688 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005689 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5690 ar->hw->wiphy->n_iface_combinations =
5691 ARRAY_SIZE(ath10k_10x_if_comb);
5692 break;
5693 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5694 case ATH10K_FW_WMI_OP_VERSION_MAX:
5695 WARN_ON(1);
5696 ret = -EINVAL;
5697 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005698 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005699
Michal Kazior7c199992013-07-31 10:47:57 +02005700 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5701
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005702 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5703 /* Init ath dfs pattern detector */
5704 ar->ath_common.debug_mask = ATH_DBG_DFS;
5705 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5706 NL80211_DFS_UNSET);
5707
5708 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005709 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005710 }
5711
Kalle Valo5e3dd152013-06-12 20:52:10 +03005712 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5713 ath10k_reg_notifier);
5714 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005715 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005716 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005717 }
5718
Johannes Berg3cb10942015-01-22 21:38:45 +01005719 ar->hw->wiphy->cipher_suites = cipher_suites;
5720 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5721
Kalle Valo5e3dd152013-06-12 20:52:10 +03005722 ret = ieee80211_register_hw(ar->hw);
5723 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005724 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005725 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005726 }
5727
5728 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5729 ret = regulatory_hint(ar->hw->wiphy,
5730 ar->ath_common.regulatory.alpha2);
5731 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005732 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005733 }
5734
5735 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005736
5737err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005738 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005739err_free:
5740 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5741 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5742
Kalle Valo5e3dd152013-06-12 20:52:10 +03005743 return ret;
5744}
5745
5746void ath10k_mac_unregister(struct ath10k *ar)
5747{
5748 ieee80211_unregister_hw(ar->hw);
5749
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005750 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5751 ar->dfs_detector->exit(ar->dfs_detector);
5752
Kalle Valo5e3dd152013-06-12 20:52:10 +03005753 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5754 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5755
5756 SET_IEEE80211_DEV(ar->hw, NULL);
5757}