blob: f9440deffa261efcc693859b8c086dd00a34af2e [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,
40 const u8 *macaddr)
41{
Michal Kazior7aa7a722014-08-25 12:09:38 +020042 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030043 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
47 .key_data = key->key,
48 .macaddr = macaddr,
49 };
50
Michal Kazior548db542013-07-05 16:15:15 +030051 lockdep_assert_held(&arvif->ar->conf_mutex);
52
Kalle Valo5e3dd152013-06-12 20:52:10 +030053 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
55 else
56 arg.key_flags = WMI_KEY_GROUP;
57
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +020061 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
75 break;
76 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020077 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 return -EOPNOTSUPP;
79 }
80
81 if (cmd == DISABLE_KEY) {
82 arg.key_cipher = WMI_CIPHER_NONE;
83 arg.key_data = NULL;
84 }
85
86 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
87}
88
89static int ath10k_install_key(struct ath10k_vif *arvif,
90 struct ieee80211_key_conf *key,
91 enum set_key_cmd cmd,
92 const u8 *macaddr)
93{
94 struct ath10k *ar = arvif->ar;
95 int ret;
96
Michal Kazior548db542013-07-05 16:15:15 +030097 lockdep_assert_held(&ar->conf_mutex);
98
Wolfram Sang16735d02013-11-14 14:32:02 -080099 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300100
101 ret = ath10k_send_key(arvif, key, cmd, macaddr);
102 if (ret)
103 return ret;
104
105 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
106 if (ret == 0)
107 return -ETIMEDOUT;
108
109 return 0;
110}
111
112static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
113 const u8 *addr)
114{
115 struct ath10k *ar = arvif->ar;
116 struct ath10k_peer *peer;
117 int ret;
118 int i;
119
120 lockdep_assert_held(&ar->conf_mutex);
121
122 spin_lock_bh(&ar->data_lock);
123 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
124 spin_unlock_bh(&ar->data_lock);
125
126 if (!peer)
127 return -ENOENT;
128
129 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
130 if (arvif->wep_keys[i] == NULL)
131 continue;
132
133 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 addr);
135 if (ret)
136 return ret;
137
Sujith Manoharanae167132014-11-25 11:46:59 +0530138 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300139 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530140 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300141 }
142
143 return 0;
144}
145
146static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
147 const u8 *addr)
148{
149 struct ath10k *ar = arvif->ar;
150 struct ath10k_peer *peer;
151 int first_errno = 0;
152 int ret;
153 int i;
154
155 lockdep_assert_held(&ar->conf_mutex);
156
157 spin_lock_bh(&ar->data_lock);
158 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
159 spin_unlock_bh(&ar->data_lock);
160
161 if (!peer)
162 return -ENOENT;
163
164 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
165 if (peer->keys[i] == NULL)
166 continue;
167
168 ret = ath10k_install_key(arvif, peer->keys[i],
169 DISABLE_KEY, addr);
170 if (ret && first_errno == 0)
171 first_errno = ret;
172
173 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200174 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300175 i, ret);
176
Sujith Manoharanae167132014-11-25 11:46:59 +0530177 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530179 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180 }
181
182 return first_errno;
183}
184
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530185bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
186 u8 keyidx)
187{
188 struct ath10k_peer *peer;
189 int i;
190
191 lockdep_assert_held(&ar->data_lock);
192
193 /* We don't know which vdev this peer belongs to,
194 * since WMI doesn't give us that information.
195 *
196 * FIXME: multi-bss needs to be handled.
197 */
198 peer = ath10k_peer_find(ar, 0, addr);
199 if (!peer)
200 return false;
201
202 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
203 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
204 return true;
205 }
206
207 return false;
208}
209
Kalle Valo5e3dd152013-06-12 20:52:10 +0300210static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
211 struct ieee80211_key_conf *key)
212{
213 struct ath10k *ar = arvif->ar;
214 struct ath10k_peer *peer;
215 u8 addr[ETH_ALEN];
216 int first_errno = 0;
217 int ret;
218 int i;
219
220 lockdep_assert_held(&ar->conf_mutex);
221
222 for (;;) {
223 /* since ath10k_install_key we can't hold data_lock all the
224 * time, so we try to remove the keys incrementally */
225 spin_lock_bh(&ar->data_lock);
226 i = 0;
227 list_for_each_entry(peer, &ar->peers, list) {
228 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
229 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300230 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300231 peer->keys[i] = NULL;
232 break;
233 }
234 }
235
236 if (i < ARRAY_SIZE(peer->keys))
237 break;
238 }
239 spin_unlock_bh(&ar->data_lock);
240
241 if (i == ARRAY_SIZE(peer->keys))
242 break;
243
244 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
245 if (ret && first_errno == 0)
246 first_errno = ret;
247
248 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200249 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200250 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 }
252
253 return first_errno;
254}
255
Kalle Valo5e3dd152013-06-12 20:52:10 +0300256/*********************/
257/* General utilities */
258/*********************/
259
260static inline enum wmi_phy_mode
261chan_to_phymode(const struct cfg80211_chan_def *chandef)
262{
263 enum wmi_phy_mode phymode = MODE_UNKNOWN;
264
265 switch (chandef->chan->band) {
266 case IEEE80211_BAND_2GHZ:
267 switch (chandef->width) {
268 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800269 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
270 phymode = MODE_11B;
271 else
272 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 break;
274 case NL80211_CHAN_WIDTH_20:
275 phymode = MODE_11NG_HT20;
276 break;
277 case NL80211_CHAN_WIDTH_40:
278 phymode = MODE_11NG_HT40;
279 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400280 case NL80211_CHAN_WIDTH_5:
281 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300282 case NL80211_CHAN_WIDTH_80:
283 case NL80211_CHAN_WIDTH_80P80:
284 case NL80211_CHAN_WIDTH_160:
285 phymode = MODE_UNKNOWN;
286 break;
287 }
288 break;
289 case IEEE80211_BAND_5GHZ:
290 switch (chandef->width) {
291 case NL80211_CHAN_WIDTH_20_NOHT:
292 phymode = MODE_11A;
293 break;
294 case NL80211_CHAN_WIDTH_20:
295 phymode = MODE_11NA_HT20;
296 break;
297 case NL80211_CHAN_WIDTH_40:
298 phymode = MODE_11NA_HT40;
299 break;
300 case NL80211_CHAN_WIDTH_80:
301 phymode = MODE_11AC_VHT80;
302 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400303 case NL80211_CHAN_WIDTH_5:
304 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300305 case NL80211_CHAN_WIDTH_80P80:
306 case NL80211_CHAN_WIDTH_160:
307 phymode = MODE_UNKNOWN;
308 break;
309 }
310 break;
311 default:
312 break;
313 }
314
315 WARN_ON(phymode == MODE_UNKNOWN);
316 return phymode;
317}
318
319static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
320{
321/*
322 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
323 * 0 for no restriction
324 * 1 for 1/4 us
325 * 2 for 1/2 us
326 * 3 for 1 us
327 * 4 for 2 us
328 * 5 for 4 us
329 * 6 for 8 us
330 * 7 for 16 us
331 */
332 switch (mpdudensity) {
333 case 0:
334 return 0;
335 case 1:
336 case 2:
337 case 3:
338 /* Our lower layer calculations limit our precision to
339 1 microsecond */
340 return 1;
341 case 4:
342 return 2;
343 case 5:
344 return 4;
345 case 6:
346 return 8;
347 case 7:
348 return 16;
349 default:
350 return 0;
351 }
352}
353
354static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
355{
356 int ret;
357
358 lockdep_assert_held(&ar->conf_mutex);
359
Michal Kaziorcfd10612014-11-25 15:16:05 +0100360 if (ar->num_peers >= ar->max_num_peers)
361 return -ENOBUFS;
362
Kalle Valo5e3dd152013-06-12 20:52:10 +0300363 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800364 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200365 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200366 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300367 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800368 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300369
370 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800371 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200372 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200373 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300374 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800375 }
Michal Kazior292a7532014-11-25 15:16:04 +0100376
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100377 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300378
379 return 0;
380}
381
Kalle Valo5a13e762014-01-20 11:01:46 +0200382static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
383{
384 struct ath10k *ar = arvif->ar;
385 u32 param;
386 int ret;
387
388 param = ar->wmi.pdev_param->sta_kickout_th;
389 ret = ath10k_wmi_pdev_set_param(ar, param,
390 ATH10K_KICKOUT_THRESHOLD);
391 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200392 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200393 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200394 return ret;
395 }
396
397 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
398 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
399 ATH10K_KEEPALIVE_MIN_IDLE);
400 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200401 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200402 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200403 return ret;
404 }
405
406 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
407 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
408 ATH10K_KEEPALIVE_MAX_IDLE);
409 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200410 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200411 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200412 return ret;
413 }
414
415 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
416 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
417 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
418 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200419 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200420 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200421 return ret;
422 }
423
424 return 0;
425}
426
Vivek Natarajanacab6402014-11-26 09:06:12 +0200427static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200428{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200429 struct ath10k *ar = arvif->ar;
430 u32 vdev_param;
431
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200432 vdev_param = ar->wmi.vdev_param->rts_threshold;
433 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200434}
435
436static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
437{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200438 struct ath10k *ar = arvif->ar;
439 u32 vdev_param;
440
Michal Kazior424121c2013-07-22 14:13:31 +0200441 if (value != 0xFFFFFFFF)
442 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
443 ATH10K_FRAGMT_THRESHOLD_MIN,
444 ATH10K_FRAGMT_THRESHOLD_MAX);
445
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200446 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
447 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200448}
449
Kalle Valo5e3dd152013-06-12 20:52:10 +0300450static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
451{
452 int ret;
453
454 lockdep_assert_held(&ar->conf_mutex);
455
456 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
457 if (ret)
458 return ret;
459
460 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
461 if (ret)
462 return ret;
463
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100464 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100465
Kalle Valo5e3dd152013-06-12 20:52:10 +0300466 return 0;
467}
468
469static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
470{
471 struct ath10k_peer *peer, *tmp;
472
473 lockdep_assert_held(&ar->conf_mutex);
474
475 spin_lock_bh(&ar->data_lock);
476 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
477 if (peer->vdev_id != vdev_id)
478 continue;
479
Michal Kazior7aa7a722014-08-25 12:09:38 +0200480 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300481 peer->addr, vdev_id);
482
483 list_del(&peer->list);
484 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100485 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300486 }
487 spin_unlock_bh(&ar->data_lock);
488}
489
Michal Kaziora96d7742013-07-16 09:38:56 +0200490static void ath10k_peer_cleanup_all(struct ath10k *ar)
491{
492 struct ath10k_peer *peer, *tmp;
493
494 lockdep_assert_held(&ar->conf_mutex);
495
496 spin_lock_bh(&ar->data_lock);
497 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
498 list_del(&peer->list);
499 kfree(peer);
500 }
501 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100502
503 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100504 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200505}
506
Kalle Valo5e3dd152013-06-12 20:52:10 +0300507/************************/
508/* Interface management */
509/************************/
510
Michal Kazior64badcb2014-09-18 11:18:02 +0300511void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
512{
513 struct ath10k *ar = arvif->ar;
514
515 lockdep_assert_held(&ar->data_lock);
516
517 if (!arvif->beacon)
518 return;
519
520 if (!arvif->beacon_buf)
521 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
522 arvif->beacon->len, DMA_TO_DEVICE);
523
524 dev_kfree_skb_any(arvif->beacon);
525
526 arvif->beacon = NULL;
527 arvif->beacon_sent = false;
528}
529
530static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
531{
532 struct ath10k *ar = arvif->ar;
533
534 lockdep_assert_held(&ar->data_lock);
535
536 ath10k_mac_vif_beacon_free(arvif);
537
538 if (arvif->beacon_buf) {
539 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
540 arvif->beacon_buf, arvif->beacon_paddr);
541 arvif->beacon_buf = NULL;
542 }
543}
544
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
546{
547 int ret;
548
Michal Kazior548db542013-07-05 16:15:15 +0300549 lockdep_assert_held(&ar->conf_mutex);
550
Michal Kazior7962b0d2014-10-28 10:34:38 +0100551 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
552 return -ESHUTDOWN;
553
Kalle Valo5e3dd152013-06-12 20:52:10 +0300554 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
555 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
556 if (ret == 0)
557 return -ETIMEDOUT;
558
559 return 0;
560}
561
Michal Kazior1bbc0972014-04-08 09:45:47 +0300562static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300563{
Michal Kaziorc930f742014-01-23 11:38:25 +0100564 struct cfg80211_chan_def *chandef = &ar->chandef;
565 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300566 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300567 int ret = 0;
568
569 lockdep_assert_held(&ar->conf_mutex);
570
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571 arg.vdev_id = vdev_id;
572 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100573 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300574
575 /* TODO setup this dynamically, what in case we
576 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100577 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200578 arg.channel.chan_radar =
579 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300580
Michal Kazior89c5c842013-10-23 04:02:13 -0700581 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700582 arg.channel.max_power = channel->max_power * 2;
583 arg.channel.max_reg_power = channel->max_reg_power * 2;
584 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585
Michal Kazior7962b0d2014-10-28 10:34:38 +0100586 reinit_completion(&ar->vdev_setup_done);
587
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588 ret = ath10k_wmi_vdev_start(ar, &arg);
589 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200590 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200591 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592 return ret;
593 }
594
595 ret = ath10k_vdev_setup_sync(ar);
596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200597 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200598 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300599 return ret;
600 }
601
602 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
603 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200604 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200605 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300606 goto vdev_stop;
607 }
608
609 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300610
Michal Kazior7aa7a722014-08-25 12:09:38 +0200611 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300612 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return 0;
614
615vdev_stop:
616 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
617 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620
621 return ret;
622}
623
Michal Kazior1bbc0972014-04-08 09:45:47 +0300624static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300625{
626 int ret = 0;
627
628 lockdep_assert_held(&ar->conf_mutex);
629
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200630 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
631 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200632 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200633 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634
Michal Kazior7962b0d2014-10-28 10:34:38 +0100635 reinit_completion(&ar->vdev_setup_done);
636
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
638 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200639 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200640 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300641
642 ret = ath10k_vdev_setup_sync(ar);
643 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200644 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200645 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300646
Michal Kazior7aa7a722014-08-25 12:09:38 +0200647 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300648 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 return ret;
650}
651
Michal Kazior1bbc0972014-04-08 09:45:47 +0300652static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300653{
654 int bit, ret = 0;
655
656 lockdep_assert_held(&ar->conf_mutex);
657
Ben Greeara9aefb32014-08-12 11:02:19 +0300658 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200659 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660 return -ENOMEM;
661 }
662
Ben Greear16c11172014-09-23 14:17:16 -0700663 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300664
Ben Greear16c11172014-09-23 14:17:16 -0700665 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666
667 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
668 WMI_VDEV_TYPE_MONITOR,
669 0, ar->mac_addr);
670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200671 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200672 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300673 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674 }
675
Ben Greear16c11172014-09-23 14:17:16 -0700676 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300678 ar->monitor_vdev_id);
679
Kalle Valo5e3dd152013-06-12 20:52:10 +0300680 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300681}
682
Michal Kazior1bbc0972014-04-08 09:45:47 +0300683static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300684{
685 int ret = 0;
686
687 lockdep_assert_held(&ar->conf_mutex);
688
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
690 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200691 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200692 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300693 return ret;
694 }
695
Ben Greear16c11172014-09-23 14:17:16 -0700696 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697
Michal Kazior7aa7a722014-08-25 12:09:38 +0200698 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300699 ar->monitor_vdev_id);
700 return ret;
701}
702
Michal Kazior1bbc0972014-04-08 09:45:47 +0300703static int ath10k_monitor_start(struct ath10k *ar)
704{
705 int ret;
706
707 lockdep_assert_held(&ar->conf_mutex);
708
Michal Kazior1bbc0972014-04-08 09:45:47 +0300709 ret = ath10k_monitor_vdev_create(ar);
710 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200711 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300712 return ret;
713 }
714
715 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
716 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200717 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300718 ath10k_monitor_vdev_delete(ar);
719 return ret;
720 }
721
722 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300724
725 return 0;
726}
727
Michal Kazior19337472014-08-28 12:58:16 +0200728static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300729{
730 int ret;
731
732 lockdep_assert_held(&ar->conf_mutex);
733
Michal Kazior1bbc0972014-04-08 09:45:47 +0300734 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200735 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200736 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200737 return ret;
738 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300739
740 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200741 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200742 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200743 return ret;
744 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300745
746 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200748
749 return 0;
750}
751
752static int ath10k_monitor_recalc(struct ath10k *ar)
753{
754 bool should_start;
755
756 lockdep_assert_held(&ar->conf_mutex);
757
758 should_start = ar->monitor ||
759 ar->filter_flags & FIF_PROMISC_IN_BSS ||
760 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
761
762 ath10k_dbg(ar, ATH10K_DBG_MAC,
763 "mac monitor recalc started? %d should? %d\n",
764 ar->monitor_started, should_start);
765
766 if (should_start == ar->monitor_started)
767 return 0;
768
769 if (should_start)
770 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300771
772 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300773}
774
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200775static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
776{
777 struct ath10k *ar = arvif->ar;
778 u32 vdev_param, rts_cts = 0;
779
780 lockdep_assert_held(&ar->conf_mutex);
781
782 vdev_param = ar->wmi.vdev_param->enable_rtscts;
783
784 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
785 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
786
787 if (arvif->num_legacy_stations > 0)
788 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
789 WMI_RTSCTS_PROFILE);
790
791 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
792 rts_cts);
793}
794
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200795static int ath10k_start_cac(struct ath10k *ar)
796{
797 int ret;
798
799 lockdep_assert_held(&ar->conf_mutex);
800
801 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
802
Michal Kazior19337472014-08-28 12:58:16 +0200803 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200804 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200805 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200806 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
807 return ret;
808 }
809
Michal Kazior7aa7a722014-08-25 12:09:38 +0200810 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200811 ar->monitor_vdev_id);
812
813 return 0;
814}
815
816static int ath10k_stop_cac(struct ath10k *ar)
817{
818 lockdep_assert_held(&ar->conf_mutex);
819
820 /* CAC is not running - do nothing */
821 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
822 return 0;
823
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200824 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300825 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200826
Michal Kazior7aa7a722014-08-25 12:09:38 +0200827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200828
829 return 0;
830}
831
Michal Kaziord6500972014-04-08 09:56:09 +0300832static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200833{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200834 int ret;
835
836 lockdep_assert_held(&ar->conf_mutex);
837
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 ath10k_stop_cac(ar);
839
Michal Kaziord6500972014-04-08 09:56:09 +0300840 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200841 return;
842
Michal Kaziord6500972014-04-08 09:56:09 +0300843 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200844 return;
845
846 ret = ath10k_start_cac(ar);
847 if (ret) {
848 /*
849 * Not possible to start CAC on current channel so starting
850 * radiation is not allowed, make this channel DFS_UNAVAILABLE
851 * by indicating that radar was detected.
852 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200853 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200854 ieee80211_radar_detected(ar->hw);
855 }
856}
857
Michal Kaziordc55e302014-07-29 12:53:36 +0300858static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300859{
860 struct ath10k *ar = arvif->ar;
861 struct cfg80211_chan_def *chandef = &ar->chandef;
862 struct wmi_vdev_start_request_arg arg = {};
863 int ret = 0;
864
865 lockdep_assert_held(&ar->conf_mutex);
866
867 reinit_completion(&ar->vdev_setup_done);
868
869 arg.vdev_id = arvif->vdev_id;
870 arg.dtim_period = arvif->dtim_period;
871 arg.bcn_intval = arvif->beacon_interval;
872
873 arg.channel.freq = chandef->chan->center_freq;
874 arg.channel.band_center_freq1 = chandef->center_freq1;
875 arg.channel.mode = chan_to_phymode(chandef);
876
877 arg.channel.min_power = 0;
878 arg.channel.max_power = chandef->chan->max_power * 2;
879 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
880 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
881
882 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
883 arg.ssid = arvif->u.ap.ssid;
884 arg.ssid_len = arvif->u.ap.ssid_len;
885 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
886
887 /* For now allow DFS for AP mode */
888 arg.channel.chan_radar =
889 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
890 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
891 arg.ssid = arvif->vif->bss_conf.ssid;
892 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
893 }
894
Michal Kazior7aa7a722014-08-25 12:09:38 +0200895 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300896 "mac vdev %d start center_freq %d phymode %s\n",
897 arg.vdev_id, arg.channel.freq,
898 ath10k_wmi_phymode_str(arg.channel.mode));
899
Michal Kaziordc55e302014-07-29 12:53:36 +0300900 if (restart)
901 ret = ath10k_wmi_vdev_restart(ar, &arg);
902 else
903 ret = ath10k_wmi_vdev_start(ar, &arg);
904
Michal Kazior72654fa2014-04-08 09:56:09 +0300905 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200906 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300907 arg.vdev_id, ret);
908 return ret;
909 }
910
911 ret = ath10k_vdev_setup_sync(ar);
912 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200913 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300914 arg.vdev_id, ret);
915 return ret;
916 }
917
Michal Kaziord6500972014-04-08 09:56:09 +0300918 ar->num_started_vdevs++;
919 ath10k_recalc_radar_detection(ar);
920
Michal Kazior72654fa2014-04-08 09:56:09 +0300921 return ret;
922}
923
Michal Kaziordc55e302014-07-29 12:53:36 +0300924static int ath10k_vdev_start(struct ath10k_vif *arvif)
925{
926 return ath10k_vdev_start_restart(arvif, false);
927}
928
929static int ath10k_vdev_restart(struct ath10k_vif *arvif)
930{
931 return ath10k_vdev_start_restart(arvif, true);
932}
933
Michal Kazior72654fa2014-04-08 09:56:09 +0300934static int ath10k_vdev_stop(struct ath10k_vif *arvif)
935{
936 struct ath10k *ar = arvif->ar;
937 int ret;
938
939 lockdep_assert_held(&ar->conf_mutex);
940
941 reinit_completion(&ar->vdev_setup_done);
942
943 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
944 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200945 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300946 arvif->vdev_id, ret);
947 return ret;
948 }
949
950 ret = ath10k_vdev_setup_sync(ar);
951 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200952 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300953 arvif->vdev_id, ret);
954 return ret;
955 }
956
Michal Kaziord6500972014-04-08 09:56:09 +0300957 WARN_ON(ar->num_started_vdevs == 0);
958
959 if (ar->num_started_vdevs != 0) {
960 ar->num_started_vdevs--;
961 ath10k_recalc_radar_detection(ar);
962 }
963
Michal Kazior72654fa2014-04-08 09:56:09 +0300964 return ret;
965}
966
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +0200967static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
968 struct sk_buff *bcn)
969{
970 struct ath10k *ar = arvif->ar;
971 struct ieee80211_mgmt *mgmt;
972 const u8 *p2p_ie;
973 int ret;
974
975 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
976 return 0;
977
978 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
979 return 0;
980
981 mgmt = (void *)bcn->data;
982 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
983 mgmt->u.beacon.variable,
984 bcn->len - (mgmt->u.beacon.variable -
985 bcn->data));
986 if (!p2p_ie)
987 return -ENOENT;
988
989 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
990 if (ret) {
991 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
992 arvif->vdev_id, ret);
993 return ret;
994 }
995
996 return 0;
997}
998
999static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1000 u8 oui_type, size_t ie_offset)
1001{
1002 size_t len;
1003 const u8 *next;
1004 const u8 *end;
1005 u8 *ie;
1006
1007 if (WARN_ON(skb->len < ie_offset))
1008 return -EINVAL;
1009
1010 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1011 skb->data + ie_offset,
1012 skb->len - ie_offset);
1013 if (!ie)
1014 return -ENOENT;
1015
1016 len = ie[1] + 2;
1017 end = skb->data + skb->len;
1018 next = ie + len;
1019
1020 if (WARN_ON(next > end))
1021 return -EINVAL;
1022
1023 memmove(ie, next, end - next);
1024 skb_trim(skb, skb->len - len);
1025
1026 return 0;
1027}
1028
1029static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1030{
1031 struct ath10k *ar = arvif->ar;
1032 struct ieee80211_hw *hw = ar->hw;
1033 struct ieee80211_vif *vif = arvif->vif;
1034 struct ieee80211_mutable_offsets offs = {};
1035 struct sk_buff *bcn;
1036 int ret;
1037
1038 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1039 return 0;
1040
1041 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1042 if (!bcn) {
1043 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1044 return -EPERM;
1045 }
1046
1047 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1048 if (ret) {
1049 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1050 kfree_skb(bcn);
1051 return ret;
1052 }
1053
1054 /* P2P IE is inserted by firmware automatically (as configured above)
1055 * so remove it from the base beacon template to avoid duplicate P2P
1056 * IEs in beacon frames.
1057 */
1058 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1059 offsetof(struct ieee80211_mgmt,
1060 u.beacon.variable));
1061
1062 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1063 0, NULL, 0);
1064 kfree_skb(bcn);
1065
1066 if (ret) {
1067 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1068 ret);
1069 return ret;
1070 }
1071
1072 return 0;
1073}
1074
1075static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1076{
1077 struct ath10k *ar = arvif->ar;
1078 struct ieee80211_hw *hw = ar->hw;
1079 struct ieee80211_vif *vif = arvif->vif;
1080 struct sk_buff *prb;
1081 int ret;
1082
1083 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1084 return 0;
1085
1086 prb = ieee80211_proberesp_get(hw, vif);
1087 if (!prb) {
1088 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1089 return -EPERM;
1090 }
1091
1092 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1093 kfree_skb(prb);
1094
1095 if (ret) {
1096 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1097 ret);
1098 return ret;
1099 }
1100
1101 return 0;
1102}
1103
Kalle Valo5e3dd152013-06-12 20:52:10 +03001104static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001105 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001106{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001107 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001108 int ret = 0;
1109
Michal Kazior548db542013-07-05 16:15:15 +03001110 lockdep_assert_held(&arvif->ar->conf_mutex);
1111
Kalle Valo5e3dd152013-06-12 20:52:10 +03001112 if (!info->enable_beacon) {
1113 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001114
1115 arvif->is_started = false;
1116 arvif->is_up = false;
1117
Michal Kazior748afc42014-01-23 12:48:21 +01001118 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001119 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001120 spin_unlock_bh(&arvif->ar->data_lock);
1121
Kalle Valo5e3dd152013-06-12 20:52:10 +03001122 return;
1123 }
1124
1125 arvif->tx_seq_no = 0x1000;
1126
1127 ret = ath10k_vdev_start(arvif);
1128 if (ret)
1129 return;
1130
Michal Kaziorc930f742014-01-23 11:38:25 +01001131 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001132 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001133
1134 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1135 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001137 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001138 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001139 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001140 return;
1141 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001142
1143 arvif->is_started = true;
1144 arvif->is_up = true;
1145
Michal Kazior7aa7a722014-08-25 12:09:38 +02001146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001147}
1148
1149static void ath10k_control_ibss(struct ath10k_vif *arvif,
1150 struct ieee80211_bss_conf *info,
1151 const u8 self_peer[ETH_ALEN])
1152{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001153 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001154 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001155 int ret = 0;
1156
Michal Kazior548db542013-07-05 16:15:15 +03001157 lockdep_assert_held(&arvif->ar->conf_mutex);
1158
Kalle Valo5e3dd152013-06-12 20:52:10 +03001159 if (!info->ibss_joined) {
1160 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1161 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001162 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001163 self_peer, arvif->vdev_id, ret);
1164
Michal Kaziorc930f742014-01-23 11:38:25 +01001165 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001166 return;
1167
Michal Kaziorc930f742014-01-23 11:38:25 +01001168 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169
1170 return;
1171 }
1172
1173 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1174 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001175 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001176 self_peer, arvif->vdev_id, ret);
1177 return;
1178 }
1179
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001180 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1181 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001182 ATH10K_DEFAULT_ATIM);
1183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001184 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001185 arvif->vdev_id, ret);
1186}
1187
Michal Kazior9f9b5742014-12-12 12:41:36 +01001188static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1189{
1190 struct ath10k *ar = arvif->ar;
1191 u32 param;
1192 u32 value;
1193 int ret;
1194
1195 lockdep_assert_held(&arvif->ar->conf_mutex);
1196
1197 if (arvif->u.sta.uapsd)
1198 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1199 else
1200 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1201
1202 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1203 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1204 if (ret) {
1205 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1206 value, arvif->vdev_id, ret);
1207 return ret;
1208 }
1209
1210 return 0;
1211}
1212
1213static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1214{
1215 struct ath10k *ar = arvif->ar;
1216 u32 param;
1217 u32 value;
1218 int ret;
1219
1220 lockdep_assert_held(&arvif->ar->conf_mutex);
1221
1222 if (arvif->u.sta.uapsd)
1223 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1224 else
1225 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1226
1227 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1228 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1229 param, value);
1230 if (ret) {
1231 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1232 value, arvif->vdev_id, ret);
1233 return ret;
1234 }
1235
1236 return 0;
1237}
1238
Michal Kaziorad088bf2013-10-16 15:44:46 +03001239static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001241 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001242 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001243 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001244 enum wmi_sta_powersave_param param;
1245 enum wmi_sta_ps_mode psmode;
1246 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001247 int ps_timeout;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001248
Michal Kazior548db542013-07-05 16:15:15 +03001249 lockdep_assert_held(&arvif->ar->conf_mutex);
1250
Michal Kaziorad088bf2013-10-16 15:44:46 +03001251 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1252 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001253
Michal Kaziorbf14e652014-12-12 12:41:38 +01001254 if (vif->bss_conf.ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001255 psmode = WMI_STA_PS_MODE_ENABLED;
1256 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1257
Michal Kazior526549a2014-12-12 12:41:37 +01001258 ps_timeout = conf->dynamic_ps_timeout;
1259 if (ps_timeout == 0) {
1260 /* Firmware doesn't like 0 */
1261 ps_timeout = ieee80211_tu_to_usec(
1262 vif->bss_conf.beacon_int) / 1000;
1263 }
1264
Michal Kaziorad088bf2013-10-16 15:44:46 +03001265 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001266 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001267 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001268 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001269 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001270 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001271 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001272 } else {
1273 psmode = WMI_STA_PS_MODE_DISABLED;
1274 }
1275
Michal Kazior7aa7a722014-08-25 12:09:38 +02001276 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001277 arvif->vdev_id, psmode ? "enable" : "disable");
1278
Michal Kaziorad088bf2013-10-16 15:44:46 +03001279 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1280 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001281 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001282 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001283 return ret;
1284 }
1285
1286 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287}
1288
Michal Kazior46725b152015-01-28 09:57:49 +02001289static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1290{
1291 struct ath10k *ar = arvif->ar;
1292 struct wmi_sta_keepalive_arg arg = {};
1293 int ret;
1294
1295 lockdep_assert_held(&arvif->ar->conf_mutex);
1296
1297 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1298 return 0;
1299
1300 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1301 return 0;
1302
1303 /* Some firmware revisions have a bug and ignore the `enabled` field.
1304 * Instead use the interval to disable the keepalive.
1305 */
1306 arg.vdev_id = arvif->vdev_id;
1307 arg.enabled = 1;
1308 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1309 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1310
1311 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1312 if (ret) {
1313 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1314 arvif->vdev_id, ret);
1315 return ret;
1316 }
1317
1318 return 0;
1319}
1320
Kalle Valo5e3dd152013-06-12 20:52:10 +03001321/**********************/
1322/* Station management */
1323/**********************/
1324
Michal Kazior590922a2014-10-21 10:10:29 +03001325static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1326 struct ieee80211_vif *vif)
1327{
1328 /* Some firmware revisions have unstable STA powersave when listen
1329 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1330 * generate NullFunc frames properly even if buffered frames have been
1331 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1332 * buffered frames. Often pinging the device from AP would simply fail.
1333 *
1334 * As a workaround set it to 1.
1335 */
1336 if (vif->type == NL80211_IFTYPE_STATION)
1337 return 1;
1338
1339 return ar->hw->conf.listen_interval;
1340}
1341
Kalle Valo5e3dd152013-06-12 20:52:10 +03001342static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001343 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001345 struct wmi_peer_assoc_complete_arg *arg)
1346{
Michal Kazior590922a2014-10-21 10:10:29 +03001347 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1348
Michal Kazior548db542013-07-05 16:15:15 +03001349 lockdep_assert_held(&ar->conf_mutex);
1350
Kalle Valob25f32c2014-09-14 12:50:49 +03001351 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352 arg->vdev_id = arvif->vdev_id;
1353 arg->peer_aid = sta->aid;
1354 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001355 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001357 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001358}
1359
1360static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001361 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362 struct wmi_peer_assoc_complete_arg *arg)
1363{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364 struct ieee80211_bss_conf *info = &vif->bss_conf;
1365 struct cfg80211_bss *bss;
1366 const u8 *rsnie = NULL;
1367 const u8 *wpaie = NULL;
1368
Michal Kazior548db542013-07-05 16:15:15 +03001369 lockdep_assert_held(&ar->conf_mutex);
1370
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1372 info->bssid, NULL, 0, 0, 0);
1373 if (bss) {
1374 const struct cfg80211_bss_ies *ies;
1375
1376 rcu_read_lock();
1377 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1378
1379 ies = rcu_dereference(bss->ies);
1380
1381 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001382 WLAN_OUI_TYPE_MICROSOFT_WPA,
1383 ies->data,
1384 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 rcu_read_unlock();
1386 cfg80211_put_bss(ar->hw->wiphy, bss);
1387 }
1388
1389 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1390 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001391 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001392 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1393 }
1394
1395 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001396 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001397 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1398 }
1399}
1400
1401static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1402 struct ieee80211_sta *sta,
1403 struct wmi_peer_assoc_complete_arg *arg)
1404{
1405 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1406 const struct ieee80211_supported_band *sband;
1407 const struct ieee80211_rate *rates;
1408 u32 ratemask;
1409 int i;
1410
Michal Kazior548db542013-07-05 16:15:15 +03001411 lockdep_assert_held(&ar->conf_mutex);
1412
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1414 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1415 rates = sband->bitrates;
1416
1417 rateset->num_rates = 0;
1418
1419 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1420 if (!(ratemask & 1))
1421 continue;
1422
1423 rateset->rates[rateset->num_rates] = rates->hw_value;
1424 rateset->num_rates++;
1425 }
1426}
1427
1428static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1429 struct ieee80211_sta *sta,
1430 struct wmi_peer_assoc_complete_arg *arg)
1431{
1432 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001433 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001434 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001435
Michal Kazior548db542013-07-05 16:15:15 +03001436 lockdep_assert_held(&ar->conf_mutex);
1437
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438 if (!ht_cap->ht_supported)
1439 return;
1440
1441 arg->peer_flags |= WMI_PEER_HT;
1442 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1443 ht_cap->ampdu_factor)) - 1;
1444
1445 arg->peer_mpdu_density =
1446 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1447
1448 arg->peer_ht_caps = ht_cap->cap;
1449 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1450
1451 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1452 arg->peer_flags |= WMI_PEER_LDPC;
1453
1454 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1455 arg->peer_flags |= WMI_PEER_40MHZ;
1456 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1457 }
1458
1459 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1460 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1461
1462 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1463 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1464
1465 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1466 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1467 arg->peer_flags |= WMI_PEER_STBC;
1468 }
1469
1470 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001471 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1472 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1473 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1474 arg->peer_rate_caps |= stbc;
1475 arg->peer_flags |= WMI_PEER_STBC;
1476 }
1477
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1479 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1480 else if (ht_cap->mcs.rx_mask[1])
1481 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1482
1483 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1484 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1485 arg->peer_ht_rates.rates[n++] = i;
1486
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001487 /*
1488 * This is a workaround for HT-enabled STAs which break the spec
1489 * and have no HT capabilities RX mask (no HT RX MCS map).
1490 *
1491 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1492 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1493 *
1494 * Firmware asserts if such situation occurs.
1495 */
1496 if (n == 0) {
1497 arg->peer_ht_rates.num_rates = 8;
1498 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1499 arg->peer_ht_rates.rates[i] = i;
1500 } else {
1501 arg->peer_ht_rates.num_rates = n;
1502 arg->peer_num_spatial_streams = sta->rx_nss;
1503 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001504
Michal Kazior7aa7a722014-08-25 12:09:38 +02001505 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001506 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001507 arg->peer_ht_rates.num_rates,
1508 arg->peer_num_spatial_streams);
1509}
1510
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001511static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1512 struct ath10k_vif *arvif,
1513 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001514{
1515 u32 uapsd = 0;
1516 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001517 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001518
Michal Kazior548db542013-07-05 16:15:15 +03001519 lockdep_assert_held(&ar->conf_mutex);
1520
Kalle Valo5e3dd152013-06-12 20:52:10 +03001521 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001522 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001523 sta->uapsd_queues, sta->max_sp);
1524
Kalle Valo5e3dd152013-06-12 20:52:10 +03001525 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1526 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1527 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1528 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1529 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1530 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1531 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1532 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1533 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1534 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1535 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1536 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1537
Kalle Valo5e3dd152013-06-12 20:52:10 +03001538 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1539 max_sp = sta->max_sp;
1540
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001541 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1542 sta->addr,
1543 WMI_AP_PS_PEER_PARAM_UAPSD,
1544 uapsd);
1545 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001546 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001547 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001548 return ret;
1549 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001550
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001551 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1552 sta->addr,
1553 WMI_AP_PS_PEER_PARAM_MAX_SP,
1554 max_sp);
1555 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001557 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001558 return ret;
1559 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560
1561 /* TODO setup this based on STA listen interval and
1562 beacon interval. Currently we don't know
1563 sta->listen_interval - mac80211 patch required.
1564 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001565 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001566 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1567 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001568 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001569 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001570 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001571 return ret;
1572 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001575 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576}
1577
1578static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1579 struct ieee80211_sta *sta,
1580 struct wmi_peer_assoc_complete_arg *arg)
1581{
1582 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001583 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584
1585 if (!vht_cap->vht_supported)
1586 return;
1587
1588 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001589
1590 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1591 arg->peer_flags |= WMI_PEER_VHT_2G;
1592
Kalle Valo5e3dd152013-06-12 20:52:10 +03001593 arg->peer_vht_caps = vht_cap->cap;
1594
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001595 ampdu_factor = (vht_cap->cap &
1596 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1597 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1598
1599 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1600 * zero in VHT IE. Using it would result in degraded throughput.
1601 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1602 * it if VHT max_mpdu is smaller. */
1603 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1604 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1605 ampdu_factor)) - 1);
1606
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1608 arg->peer_flags |= WMI_PEER_80MHZ;
1609
1610 arg->peer_vht_rates.rx_max_rate =
1611 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1612 arg->peer_vht_rates.rx_mcs_set =
1613 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1614 arg->peer_vht_rates.tx_max_rate =
1615 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1616 arg->peer_vht_rates.tx_mcs_set =
1617 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1618
Michal Kazior7aa7a722014-08-25 12:09:38 +02001619 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001620 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621}
1622
1623static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001624 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001625 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626 struct wmi_peer_assoc_complete_arg *arg)
1627{
Michal Kazior590922a2014-10-21 10:10:29 +03001628 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1629
Kalle Valo5e3dd152013-06-12 20:52:10 +03001630 switch (arvif->vdev_type) {
1631 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001632 if (sta->wme)
1633 arg->peer_flags |= WMI_PEER_QOS;
1634
1635 if (sta->wme && sta->uapsd_queues) {
1636 arg->peer_flags |= WMI_PEER_APSD;
1637 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1638 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 break;
1640 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001641 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001642 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001643 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001644 case WMI_VDEV_TYPE_IBSS:
1645 if (sta->wme)
1646 arg->peer_flags |= WMI_PEER_QOS;
1647 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001648 default:
1649 break;
1650 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001651
1652 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1653 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001654}
1655
Michal Kazior91b12082014-12-12 12:41:35 +01001656static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1657{
1658 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1659 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1660}
1661
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001663 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001664 struct ieee80211_sta *sta,
1665 struct wmi_peer_assoc_complete_arg *arg)
1666{
1667 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1668
Kalle Valo5e3dd152013-06-12 20:52:10 +03001669 switch (ar->hw->conf.chandef.chan->band) {
1670 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08001671 if (sta->vht_cap.vht_supported) {
1672 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1673 phymode = MODE_11AC_VHT40;
1674 else
1675 phymode = MODE_11AC_VHT20;
1676 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001677 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1678 phymode = MODE_11NG_HT40;
1679 else
1680 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001681 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001682 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001683 } else {
1684 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001685 }
1686
1687 break;
1688 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001689 /*
1690 * Check VHT first.
1691 */
1692 if (sta->vht_cap.vht_supported) {
1693 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1694 phymode = MODE_11AC_VHT80;
1695 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1696 phymode = MODE_11AC_VHT40;
1697 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1698 phymode = MODE_11AC_VHT20;
1699 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1701 phymode = MODE_11NA_HT40;
1702 else
1703 phymode = MODE_11NA_HT20;
1704 } else {
1705 phymode = MODE_11A;
1706 }
1707
1708 break;
1709 default:
1710 break;
1711 }
1712
Michal Kazior7aa7a722014-08-25 12:09:38 +02001713 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001714 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001715
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716 arg->peer_phymode = phymode;
1717 WARN_ON(phymode == MODE_UNKNOWN);
1718}
1719
Kalle Valob9ada652013-10-16 15:44:46 +03001720static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001721 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001722 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001723 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001724{
Michal Kazior548db542013-07-05 16:15:15 +03001725 lockdep_assert_held(&ar->conf_mutex);
1726
Kalle Valob9ada652013-10-16 15:44:46 +03001727 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001728
Michal Kazior590922a2014-10-21 10:10:29 +03001729 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1730 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001731 ath10k_peer_assoc_h_rates(ar, sta, arg);
1732 ath10k_peer_assoc_h_ht(ar, sta, arg);
1733 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001734 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1735 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736
Kalle Valob9ada652013-10-16 15:44:46 +03001737 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738}
1739
Michal Kazior90046f52014-02-14 14:45:51 +01001740static const u32 ath10k_smps_map[] = {
1741 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1742 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1743 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1744 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1745};
1746
1747static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1748 const u8 *addr,
1749 const struct ieee80211_sta_ht_cap *ht_cap)
1750{
1751 int smps;
1752
1753 if (!ht_cap->ht_supported)
1754 return 0;
1755
1756 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1757 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1758
1759 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1760 return -EINVAL;
1761
1762 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1763 WMI_PEER_SMPS_STATE,
1764 ath10k_smps_map[smps]);
1765}
1766
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767/* can be called only in mac80211 callbacks due to `key_count` usage */
1768static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1769 struct ieee80211_vif *vif,
1770 struct ieee80211_bss_conf *bss_conf)
1771{
1772 struct ath10k *ar = hw->priv;
1773 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001774 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001775 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001776 struct ieee80211_sta *ap_sta;
1777 int ret;
1778
Michal Kazior548db542013-07-05 16:15:15 +03001779 lockdep_assert_held(&ar->conf_mutex);
1780
Michal Kazior077efc82014-10-21 10:10:29 +03001781 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1782 arvif->vdev_id, arvif->bssid, arvif->aid);
1783
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 rcu_read_lock();
1785
1786 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1787 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001788 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001789 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 rcu_read_unlock();
1791 return;
1792 }
1793
Michal Kazior90046f52014-02-14 14:45:51 +01001794 /* ap_sta must be accessed only within rcu section which must be left
1795 * before calling ath10k_setup_peer_smps() which might sleep. */
1796 ht_cap = ap_sta->ht_cap;
1797
Michal Kazior590922a2014-10-21 10:10:29 +03001798 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001800 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001801 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802 rcu_read_unlock();
1803 return;
1804 }
1805
1806 rcu_read_unlock();
1807
Kalle Valob9ada652013-10-16 15:44:46 +03001808 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1809 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001810 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001811 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001812 return;
1813 }
1814
Michal Kazior90046f52014-02-14 14:45:51 +01001815 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1816 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001817 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001818 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001819 return;
1820 }
1821
Michal Kazior7aa7a722014-08-25 12:09:38 +02001822 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001823 "mac vdev %d up (associated) bssid %pM aid %d\n",
1824 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1825
Michal Kazior077efc82014-10-21 10:10:29 +03001826 WARN_ON(arvif->is_up);
1827
Michal Kaziorc930f742014-01-23 11:38:25 +01001828 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001829 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001830
1831 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1832 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001833 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001834 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001835 return;
1836 }
1837
1838 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839}
1840
Kalle Valo5e3dd152013-06-12 20:52:10 +03001841static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1842 struct ieee80211_vif *vif)
1843{
1844 struct ath10k *ar = hw->priv;
1845 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1846 int ret;
1847
Michal Kazior548db542013-07-05 16:15:15 +03001848 lockdep_assert_held(&ar->conf_mutex);
1849
Michal Kazior077efc82014-10-21 10:10:29 +03001850 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1851 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001852
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001854 if (ret)
1855 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1856 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001857
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001858 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001859 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001860}
1861
Michal Kazior590922a2014-10-21 10:10:29 +03001862static int ath10k_station_assoc(struct ath10k *ar,
1863 struct ieee80211_vif *vif,
1864 struct ieee80211_sta *sta,
1865 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001866{
Michal Kazior590922a2014-10-21 10:10:29 +03001867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001868 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001869 int ret = 0;
1870
Michal Kazior548db542013-07-05 16:15:15 +03001871 lockdep_assert_held(&ar->conf_mutex);
1872
Michal Kazior590922a2014-10-21 10:10:29 +03001873 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001874 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001875 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001876 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001877 return ret;
1878 }
1879
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001880 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001881 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1882 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001883 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001884 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885 return ret;
1886 }
1887
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001888 /* Re-assoc is run only to update supported rates for given station. It
1889 * doesn't make much sense to reconfigure the peer completely.
1890 */
1891 if (!reassoc) {
1892 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1893 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001894 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001895 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001896 arvif->vdev_id, ret);
1897 return ret;
1898 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001899
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001900 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1901 if (ret) {
1902 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1903 sta->addr, arvif->vdev_id, ret);
1904 return ret;
1905 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001906
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001907 if (!sta->wme) {
1908 arvif->num_legacy_stations++;
1909 ret = ath10k_recalc_rtscts_prot(arvif);
1910 if (ret) {
1911 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1912 arvif->vdev_id, ret);
1913 return ret;
1914 }
1915 }
1916
1917 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1918 if (ret) {
1919 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001920 arvif->vdev_id, ret);
1921 return ret;
1922 }
1923 }
1924
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925 return ret;
1926}
1927
Michal Kazior590922a2014-10-21 10:10:29 +03001928static int ath10k_station_disassoc(struct ath10k *ar,
1929 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930 struct ieee80211_sta *sta)
1931{
Michal Kazior590922a2014-10-21 10:10:29 +03001932 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001933 int ret = 0;
1934
1935 lockdep_assert_held(&ar->conf_mutex);
1936
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001937 if (!sta->wme) {
1938 arvif->num_legacy_stations--;
1939 ret = ath10k_recalc_rtscts_prot(arvif);
1940 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001941 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001942 arvif->vdev_id, ret);
1943 return ret;
1944 }
1945 }
1946
Kalle Valo5e3dd152013-06-12 20:52:10 +03001947 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1948 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001949 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001950 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 return ret;
1952 }
1953
1954 return ret;
1955}
1956
1957/**************/
1958/* Regulatory */
1959/**************/
1960
1961static int ath10k_update_channel_list(struct ath10k *ar)
1962{
1963 struct ieee80211_hw *hw = ar->hw;
1964 struct ieee80211_supported_band **bands;
1965 enum ieee80211_band band;
1966 struct ieee80211_channel *channel;
1967 struct wmi_scan_chan_list_arg arg = {0};
1968 struct wmi_channel_arg *ch;
1969 bool passive;
1970 int len;
1971 int ret;
1972 int i;
1973
Michal Kazior548db542013-07-05 16:15:15 +03001974 lockdep_assert_held(&ar->conf_mutex);
1975
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 bands = hw->wiphy->bands;
1977 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1978 if (!bands[band])
1979 continue;
1980
1981 for (i = 0; i < bands[band]->n_channels; i++) {
1982 if (bands[band]->channels[i].flags &
1983 IEEE80211_CHAN_DISABLED)
1984 continue;
1985
1986 arg.n_channels++;
1987 }
1988 }
1989
1990 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1991 arg.channels = kzalloc(len, GFP_KERNEL);
1992 if (!arg.channels)
1993 return -ENOMEM;
1994
1995 ch = arg.channels;
1996 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1997 if (!bands[band])
1998 continue;
1999
2000 for (i = 0; i < bands[band]->n_channels; i++) {
2001 channel = &bands[band]->channels[i];
2002
2003 if (channel->flags & IEEE80211_CHAN_DISABLED)
2004 continue;
2005
2006 ch->allow_ht = true;
2007
2008 /* FIXME: when should we really allow VHT? */
2009 ch->allow_vht = true;
2010
2011 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002012 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013
2014 ch->ht40plus =
2015 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2016
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002017 ch->chan_radar =
2018 !!(channel->flags & IEEE80211_CHAN_RADAR);
2019
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002020 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002021 ch->passive = passive;
2022
2023 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002024 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002025 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002026 ch->max_power = channel->max_power * 2;
2027 ch->max_reg_power = channel->max_reg_power * 2;
2028 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002029 ch->reg_class_id = 0; /* FIXME */
2030
2031 /* FIXME: why use only legacy modes, why not any
2032 * HT/VHT modes? Would that even make any
2033 * difference? */
2034 if (channel->band == IEEE80211_BAND_2GHZ)
2035 ch->mode = MODE_11G;
2036 else
2037 ch->mode = MODE_11A;
2038
2039 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2040 continue;
2041
Michal Kazior7aa7a722014-08-25 12:09:38 +02002042 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002043 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2044 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 ch->freq, ch->max_power, ch->max_reg_power,
2046 ch->max_antenna_gain, ch->mode);
2047
2048 ch++;
2049 }
2050 }
2051
2052 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2053 kfree(arg.channels);
2054
2055 return ret;
2056}
2057
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002058static enum wmi_dfs_region
2059ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2060{
2061 switch (dfs_region) {
2062 case NL80211_DFS_UNSET:
2063 return WMI_UNINIT_DFS_DOMAIN;
2064 case NL80211_DFS_FCC:
2065 return WMI_FCC_DFS_DOMAIN;
2066 case NL80211_DFS_ETSI:
2067 return WMI_ETSI_DFS_DOMAIN;
2068 case NL80211_DFS_JP:
2069 return WMI_MKK4_DFS_DOMAIN;
2070 }
2071 return WMI_UNINIT_DFS_DOMAIN;
2072}
2073
Michal Kaziorf7843d72013-07-16 09:38:52 +02002074static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002076 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002078 enum wmi_dfs_region wmi_dfs_reg;
2079 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080
Michal Kaziorf7843d72013-07-16 09:38:52 +02002081 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082
2083 ret = ath10k_update_channel_list(ar);
2084 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002085 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002086
2087 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002088
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002089 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2090 nl_dfs_reg = ar->dfs_detector->region;
2091 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2092 } else {
2093 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2094 }
2095
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 /* Target allows setting up per-band regdomain but ath_common provides
2097 * a combined one only */
2098 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002099 regpair->reg_domain,
2100 regpair->reg_domain, /* 2ghz */
2101 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002102 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002103 regpair->reg_5ghz_ctl,
2104 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002105 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002106 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002107}
Michal Kazior548db542013-07-05 16:15:15 +03002108
Michal Kaziorf7843d72013-07-16 09:38:52 +02002109static void ath10k_reg_notifier(struct wiphy *wiphy,
2110 struct regulatory_request *request)
2111{
2112 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2113 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002114 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002115
2116 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2117
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002118 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002119 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002120 request->dfs_region);
2121 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2122 request->dfs_region);
2123 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002124 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002125 request->dfs_region);
2126 }
2127
Michal Kaziorf7843d72013-07-16 09:38:52 +02002128 mutex_lock(&ar->conf_mutex);
2129 if (ar->state == ATH10K_STATE_ON)
2130 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002131 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132}
2133
2134/***************/
2135/* TX handlers */
2136/***************/
2137
Michal Kazior42c3aa62013-10-02 11:03:38 +02002138static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2139{
2140 if (ieee80211_is_mgmt(hdr->frame_control))
2141 return HTT_DATA_TX_EXT_TID_MGMT;
2142
2143 if (!ieee80211_is_data_qos(hdr->frame_control))
2144 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2145
2146 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2147 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2148
2149 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2150}
2151
Michal Kazior2b37c292014-09-02 11:00:22 +03002152static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002153{
Michal Kazior2b37c292014-09-02 11:00:22 +03002154 if (vif)
2155 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002156
Michal Kazior1bbc0972014-04-08 09:45:47 +03002157 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002158 return ar->monitor_vdev_id;
2159
Michal Kazior7aa7a722014-08-25 12:09:38 +02002160 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002161 return 0;
2162}
2163
Michal Kazior4b604552014-07-21 21:03:09 +03002164/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2165 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002166 */
Michal Kazior4b604552014-07-21 21:03:09 +03002167static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002168{
2169 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002170 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002171 u8 *qos_ctl;
2172
2173 if (!ieee80211_is_data_qos(hdr->frame_control))
2174 return;
2175
2176 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002177 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2178 skb->data, (void *)qos_ctl - (void *)skb->data);
2179 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002180
2181 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2182 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2183 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2184 * it is safe to downgrade to NullFunc.
2185 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002186 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002187 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2188 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2189 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2190 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002191}
2192
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002193static void ath10k_tx_wep_key_work(struct work_struct *work)
2194{
2195 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2196 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02002197 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002198 int ret, keyidx = arvif->def_wep_key_newidx;
2199
Michal Kazior911e6c02014-05-26 12:46:03 +03002200 mutex_lock(&arvif->ar->conf_mutex);
2201
2202 if (arvif->ar->state != ATH10K_STATE_ON)
2203 goto unlock;
2204
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002205 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03002206 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002207
Michal Kazior7aa7a722014-08-25 12:09:38 +02002208 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002209 arvif->vdev_id, keyidx);
2210
2211 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2212 arvif->vdev_id,
2213 arvif->ar->wmi.vdev_param->def_keyid,
2214 keyidx);
2215 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002216 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002217 arvif->vdev_id,
2218 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03002219 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002220 }
2221
2222 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03002223
2224unlock:
2225 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002226}
2227
Michal Kazior4b604552014-07-21 21:03:09 +03002228static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2229 struct ieee80211_key_conf *key,
2230 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002232 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2233 struct ath10k *ar = arvif->ar;
2234 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002235
Kalle Valo5e3dd152013-06-12 20:52:10 +03002236 if (!ieee80211_has_protected(hdr->frame_control))
2237 return;
2238
2239 if (!key)
2240 return;
2241
2242 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2243 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2244 return;
2245
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002246 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247 return;
2248
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002249 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2250 * queueing frames until key index is updated is not an option because
2251 * sk_buff may need more processing to be done, e.g. offchannel */
2252 arvif->def_wep_key_newidx = key->keyidx;
2253 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002254}
2255
Michal Kazior4b604552014-07-21 21:03:09 +03002256static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2257 struct ieee80211_vif *vif,
2258 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002259{
2260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2262
2263 /* This is case only for P2P_GO */
2264 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2265 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2266 return;
2267
2268 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2269 spin_lock_bh(&ar->data_lock);
2270 if (arvif->u.ap.noa_data)
2271 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2272 GFP_ATOMIC))
2273 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2274 arvif->u.ap.noa_data,
2275 arvif->u.ap.noa_len);
2276 spin_unlock_bh(&ar->data_lock);
2277 }
2278}
2279
Michal Kazior8d6d3622014-11-24 14:58:31 +01002280static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2281{
2282 /* FIXME: Not really sure since when the behaviour changed. At some
2283 * point new firmware stopped requiring creation of peer entries for
2284 * offchannel tx (and actually creating them causes issues with wmi-htc
2285 * tx credit replenishment and reliability). Assuming it's at least 3.4
2286 * because that's when the `freq` was introduced to TX_FRM HTT command.
2287 */
2288 return !(ar->htt.target_version_major >= 3 &&
2289 ar->htt.target_version_minor >= 4);
2290}
2291
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2293{
2294 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002295 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002296
Michal Kazior961d4c32013-08-09 10:13:34 +02002297 if (ar->htt.target_version_major >= 3) {
2298 /* Since HTT 3.0 there is no separate mgmt tx command */
2299 ret = ath10k_htt_tx(&ar->htt, skb);
2300 goto exit;
2301 }
2302
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002303 if (ieee80211_is_mgmt(hdr->frame_control)) {
2304 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2305 ar->fw_features)) {
2306 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2307 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002308 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002309 ret = -EBUSY;
2310 goto exit;
2311 }
2312
2313 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2314 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2315 } else {
2316 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2317 }
2318 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2319 ar->fw_features) &&
2320 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 /* FW does not report tx status properly for NullFunc frames
2322 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002323 * those frames when it detects link/beacon loss and depends
2324 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002325 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002326 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002327 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002329
Michal Kazior961d4c32013-08-09 10:13:34 +02002330exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002332 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2333 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334 ieee80211_free_txskb(ar->hw, skb);
2335 }
2336}
2337
2338void ath10k_offchan_tx_purge(struct ath10k *ar)
2339{
2340 struct sk_buff *skb;
2341
2342 for (;;) {
2343 skb = skb_dequeue(&ar->offchan_tx_queue);
2344 if (!skb)
2345 break;
2346
2347 ieee80211_free_txskb(ar->hw, skb);
2348 }
2349}
2350
2351void ath10k_offchan_tx_work(struct work_struct *work)
2352{
2353 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2354 struct ath10k_peer *peer;
2355 struct ieee80211_hdr *hdr;
2356 struct sk_buff *skb;
2357 const u8 *peer_addr;
2358 int vdev_id;
2359 int ret;
2360
2361 /* FW requirement: We must create a peer before FW will send out
2362 * an offchannel frame. Otherwise the frame will be stuck and
2363 * never transmitted. We delete the peer upon tx completion.
2364 * It is unlikely that a peer for offchannel tx will already be
2365 * present. However it may be in some rare cases so account for that.
2366 * Otherwise we might remove a legitimate peer and break stuff. */
2367
2368 for (;;) {
2369 skb = skb_dequeue(&ar->offchan_tx_queue);
2370 if (!skb)
2371 break;
2372
2373 mutex_lock(&ar->conf_mutex);
2374
Michal Kazior7aa7a722014-08-25 12:09:38 +02002375 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376 skb);
2377
2378 hdr = (struct ieee80211_hdr *)skb->data;
2379 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002380 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002381
2382 spin_lock_bh(&ar->data_lock);
2383 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2384 spin_unlock_bh(&ar->data_lock);
2385
2386 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002387 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002388 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002389 peer_addr, vdev_id);
2390
2391 if (!peer) {
2392 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2393 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002394 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395 peer_addr, vdev_id, ret);
2396 }
2397
2398 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002399 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002400 ar->offchan_tx_skb = skb;
2401 spin_unlock_bh(&ar->data_lock);
2402
2403 ath10k_tx_htt(ar, skb);
2404
2405 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2406 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002407 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002408 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002409 skb);
2410
2411 if (!peer) {
2412 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2413 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002414 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002415 peer_addr, vdev_id, ret);
2416 }
2417
2418 mutex_unlock(&ar->conf_mutex);
2419 }
2420}
2421
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002422void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2423{
2424 struct sk_buff *skb;
2425
2426 for (;;) {
2427 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2428 if (!skb)
2429 break;
2430
2431 ieee80211_free_txskb(ar->hw, skb);
2432 }
2433}
2434
2435void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2436{
2437 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2438 struct sk_buff *skb;
2439 int ret;
2440
2441 for (;;) {
2442 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2443 if (!skb)
2444 break;
2445
2446 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002447 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002448 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002449 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002450 ieee80211_free_txskb(ar->hw, skb);
2451 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002452 }
2453}
2454
Kalle Valo5e3dd152013-06-12 20:52:10 +03002455/************/
2456/* Scanning */
2457/************/
2458
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002459void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002461 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002462
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002463 switch (ar->scan.state) {
2464 case ATH10K_SCAN_IDLE:
2465 break;
2466 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002467 if (ar->scan.is_roc)
2468 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002469 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002470 case ATH10K_SCAN_ABORTING:
2471 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002472 ieee80211_scan_completed(ar->hw,
2473 (ar->scan.state ==
2474 ATH10K_SCAN_ABORTING));
2475 /* fall through */
2476 case ATH10K_SCAN_STARTING:
2477 ar->scan.state = ATH10K_SCAN_IDLE;
2478 ar->scan_channel = NULL;
2479 ath10k_offchan_tx_purge(ar);
2480 cancel_delayed_work(&ar->scan.timeout);
2481 complete_all(&ar->scan.completed);
2482 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002483 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002484}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002486void ath10k_scan_finish(struct ath10k *ar)
2487{
2488 spin_lock_bh(&ar->data_lock);
2489 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490 spin_unlock_bh(&ar->data_lock);
2491}
2492
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002493static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002494{
2495 struct wmi_stop_scan_arg arg = {
2496 .req_id = 1, /* FIXME */
2497 .req_type = WMI_SCAN_STOP_ONE,
2498 .u.scan_id = ATH10K_SCAN_ID,
2499 };
2500 int ret;
2501
2502 lockdep_assert_held(&ar->conf_mutex);
2503
Kalle Valo5e3dd152013-06-12 20:52:10 +03002504 ret = ath10k_wmi_stop_scan(ar, &arg);
2505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002506 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002507 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002508 }
2509
Kalle Valo5e3dd152013-06-12 20:52:10 +03002510 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002511 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002512 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002513 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002514 } else if (ret > 0) {
2515 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002516 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002517
2518out:
2519 /* Scan state should be updated upon scan completion but in case
2520 * firmware fails to deliver the event (for whatever reason) it is
2521 * desired to clean up scan state anyway. Firmware may have just
2522 * dropped the scan completion event delivery due to transport pipe
2523 * being overflown with data and/or it can recover on its own before
2524 * next scan request is submitted.
2525 */
2526 spin_lock_bh(&ar->data_lock);
2527 if (ar->scan.state != ATH10K_SCAN_IDLE)
2528 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002529 spin_unlock_bh(&ar->data_lock);
2530
2531 return ret;
2532}
2533
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002534static void ath10k_scan_abort(struct ath10k *ar)
2535{
2536 int ret;
2537
2538 lockdep_assert_held(&ar->conf_mutex);
2539
2540 spin_lock_bh(&ar->data_lock);
2541
2542 switch (ar->scan.state) {
2543 case ATH10K_SCAN_IDLE:
2544 /* This can happen if timeout worker kicked in and called
2545 * abortion while scan completion was being processed.
2546 */
2547 break;
2548 case ATH10K_SCAN_STARTING:
2549 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002550 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002551 ath10k_scan_state_str(ar->scan.state),
2552 ar->scan.state);
2553 break;
2554 case ATH10K_SCAN_RUNNING:
2555 ar->scan.state = ATH10K_SCAN_ABORTING;
2556 spin_unlock_bh(&ar->data_lock);
2557
2558 ret = ath10k_scan_stop(ar);
2559 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002560 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002561
2562 spin_lock_bh(&ar->data_lock);
2563 break;
2564 }
2565
2566 spin_unlock_bh(&ar->data_lock);
2567}
2568
2569void ath10k_scan_timeout_work(struct work_struct *work)
2570{
2571 struct ath10k *ar = container_of(work, struct ath10k,
2572 scan.timeout.work);
2573
2574 mutex_lock(&ar->conf_mutex);
2575 ath10k_scan_abort(ar);
2576 mutex_unlock(&ar->conf_mutex);
2577}
2578
Kalle Valo5e3dd152013-06-12 20:52:10 +03002579static int ath10k_start_scan(struct ath10k *ar,
2580 const struct wmi_start_scan_arg *arg)
2581{
2582 int ret;
2583
2584 lockdep_assert_held(&ar->conf_mutex);
2585
2586 ret = ath10k_wmi_start_scan(ar, arg);
2587 if (ret)
2588 return ret;
2589
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2591 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002592 ret = ath10k_scan_stop(ar);
2593 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002594 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002595
2596 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597 }
2598
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002599 /* Add a 200ms margin to account for event/command processing */
2600 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2601 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002602 return 0;
2603}
2604
2605/**********************/
2606/* mac80211 callbacks */
2607/**********************/
2608
2609static void ath10k_tx(struct ieee80211_hw *hw,
2610 struct ieee80211_tx_control *control,
2611 struct sk_buff *skb)
2612{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002613 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002614 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2615 struct ieee80211_vif *vif = info->control.vif;
2616 struct ieee80211_key_conf *key = info->control.hw_key;
2617 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618
2619 /* We should disable CCK RATE due to P2P */
2620 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002621 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622
Michal Kazior4b604552014-07-21 21:03:09 +03002623 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2624 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002625 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002627 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002628 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2629 ath10k_tx_h_nwifi(hw, skb);
2630 ath10k_tx_h_update_wep_key(vif, key, skb);
2631 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2632 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002633 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002634
Kalle Valo5e3dd152013-06-12 20:52:10 +03002635 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2636 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002637 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002638 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002639 spin_unlock_bh(&ar->data_lock);
2640
Michal Kazior8d6d3622014-11-24 14:58:31 +01002641 if (ath10k_mac_need_offchan_tx_work(ar)) {
2642 ATH10K_SKB_CB(skb)->htt.freq = 0;
2643 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644
Michal Kazior8d6d3622014-11-24 14:58:31 +01002645 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2646 skb);
2647
2648 skb_queue_tail(&ar->offchan_tx_queue, skb);
2649 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2650 return;
2651 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002652 }
2653
2654 ath10k_tx_htt(ar, skb);
2655}
2656
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002657/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002658void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002659{
2660 /* make sure rcu-protected mac80211 tx path itself is drained */
2661 synchronize_net();
2662
2663 ath10k_offchan_tx_purge(ar);
2664 ath10k_mgmt_over_wmi_tx_purge(ar);
2665
2666 cancel_work_sync(&ar->offchan_tx_work);
2667 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2668}
2669
Michal Kazioraffd3212013-07-16 09:54:35 +02002670void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002671{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002672 struct ath10k_vif *arvif;
2673
Michal Kazior818bdd12013-07-16 09:38:57 +02002674 lockdep_assert_held(&ar->conf_mutex);
2675
Michal Kazior19337472014-08-28 12:58:16 +02002676 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2677 ar->filter_flags = 0;
2678 ar->monitor = false;
2679
2680 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002681 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002682
2683 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002684
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002685 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002686 ath10k_peer_cleanup_all(ar);
2687 ath10k_core_stop(ar);
2688 ath10k_hif_power_down(ar);
2689
2690 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002691 list_for_each_entry(arvif, &ar->arvifs, list)
2692 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002693 spin_unlock_bh(&ar->data_lock);
2694}
2695
Ben Greear46acf7b2014-05-16 17:15:38 +03002696static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2697{
2698 struct ath10k *ar = hw->priv;
2699
2700 mutex_lock(&ar->conf_mutex);
2701
2702 if (ar->cfg_tx_chainmask) {
2703 *tx_ant = ar->cfg_tx_chainmask;
2704 *rx_ant = ar->cfg_rx_chainmask;
2705 } else {
2706 *tx_ant = ar->supp_tx_chainmask;
2707 *rx_ant = ar->supp_rx_chainmask;
2708 }
2709
2710 mutex_unlock(&ar->conf_mutex);
2711
2712 return 0;
2713}
2714
Ben Greear5572a952014-11-24 16:22:10 +02002715static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2716{
2717 /* It is not clear that allowing gaps in chainmask
2718 * is helpful. Probably it will not do what user
2719 * is hoping for, so warn in that case.
2720 */
2721 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2722 return;
2723
2724 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2725 dbg, cm);
2726}
2727
Ben Greear46acf7b2014-05-16 17:15:38 +03002728static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2729{
2730 int ret;
2731
2732 lockdep_assert_held(&ar->conf_mutex);
2733
Ben Greear5572a952014-11-24 16:22:10 +02002734 ath10k_check_chain_mask(ar, tx_ant, "tx");
2735 ath10k_check_chain_mask(ar, rx_ant, "rx");
2736
Ben Greear46acf7b2014-05-16 17:15:38 +03002737 ar->cfg_tx_chainmask = tx_ant;
2738 ar->cfg_rx_chainmask = rx_ant;
2739
2740 if ((ar->state != ATH10K_STATE_ON) &&
2741 (ar->state != ATH10K_STATE_RESTARTED))
2742 return 0;
2743
2744 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2745 tx_ant);
2746 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002747 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002748 ret, tx_ant);
2749 return ret;
2750 }
2751
2752 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2753 rx_ant);
2754 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002755 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002756 ret, rx_ant);
2757 return ret;
2758 }
2759
2760 return 0;
2761}
2762
2763static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2764{
2765 struct ath10k *ar = hw->priv;
2766 int ret;
2767
2768 mutex_lock(&ar->conf_mutex);
2769 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2770 mutex_unlock(&ar->conf_mutex);
2771 return ret;
2772}
2773
Kalle Valo5e3dd152013-06-12 20:52:10 +03002774static int ath10k_start(struct ieee80211_hw *hw)
2775{
2776 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002777 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002779 /*
2780 * This makes sense only when restarting hw. It is harmless to call
2781 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2782 * commands will be submitted while restarting.
2783 */
2784 ath10k_drain_tx(ar);
2785
Michal Kazior548db542013-07-05 16:15:15 +03002786 mutex_lock(&ar->conf_mutex);
2787
Michal Kaziorc5058f52014-05-26 12:46:03 +03002788 switch (ar->state) {
2789 case ATH10K_STATE_OFF:
2790 ar->state = ATH10K_STATE_ON;
2791 break;
2792 case ATH10K_STATE_RESTARTING:
2793 ath10k_halt(ar);
2794 ar->state = ATH10K_STATE_RESTARTED;
2795 break;
2796 case ATH10K_STATE_ON:
2797 case ATH10K_STATE_RESTARTED:
2798 case ATH10K_STATE_WEDGED:
2799 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002800 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002801 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002802 case ATH10K_STATE_UTF:
2803 ret = -EBUSY;
2804 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002805 }
2806
2807 ret = ath10k_hif_power_up(ar);
2808 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002809 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002810 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002811 }
2812
Kalle Valo43d2a302014-09-10 18:23:30 +03002813 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002814 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002815 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002816 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002817 }
2818
Bartosz Markowski226a3392013-09-26 17:47:16 +02002819 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002820 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002821 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002822 goto err_core_stop;
2823 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002825 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002826 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002827 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002828 goto err_core_stop;
2829 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830
Ben Greear46acf7b2014-05-16 17:15:38 +03002831 if (ar->cfg_tx_chainmask)
2832 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2833 ar->cfg_rx_chainmask);
2834
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002835 /*
2836 * By default FW set ARP frames ac to voice (6). In that case ARP
2837 * exchange is not working properly for UAPSD enabled AP. ARP requests
2838 * which arrives with access category 0 are processed by network stack
2839 * and send back with access category 0, but FW changes access category
2840 * to 6. Set ARP frames access category to best effort (0) solves
2841 * this problem.
2842 */
2843
2844 ret = ath10k_wmi_pdev_set_param(ar,
2845 ar->wmi.pdev_param->arp_ac_override, 0);
2846 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002847 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002848 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002849 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002850 }
2851
Michal Kaziord6500972014-04-08 09:56:09 +03002852 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002853 ath10k_regd_update(ar);
2854
Simon Wunderlich855aed12014-08-02 09:12:54 +03002855 ath10k_spectral_start(ar);
2856
Michal Kaziorae254432014-05-26 12:46:02 +03002857 mutex_unlock(&ar->conf_mutex);
2858 return 0;
2859
2860err_core_stop:
2861 ath10k_core_stop(ar);
2862
2863err_power_down:
2864 ath10k_hif_power_down(ar);
2865
2866err_off:
2867 ar->state = ATH10K_STATE_OFF;
2868
2869err:
Michal Kazior548db542013-07-05 16:15:15 +03002870 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002871 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002872}
2873
2874static void ath10k_stop(struct ieee80211_hw *hw)
2875{
2876 struct ath10k *ar = hw->priv;
2877
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002878 ath10k_drain_tx(ar);
2879
Michal Kazior548db542013-07-05 16:15:15 +03002880 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002881 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002882 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002883 ar->state = ATH10K_STATE_OFF;
2884 }
Michal Kazior548db542013-07-05 16:15:15 +03002885 mutex_unlock(&ar->conf_mutex);
2886
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002887 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002888 cancel_work_sync(&ar->restart_work);
2889}
2890
Michal Kaziorad088bf2013-10-16 15:44:46 +03002891static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002892{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002893 struct ath10k_vif *arvif;
2894 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002895
2896 lockdep_assert_held(&ar->conf_mutex);
2897
Michal Kaziorad088bf2013-10-16 15:44:46 +03002898 list_for_each_entry(arvif, &ar->arvifs, list) {
2899 ret = ath10k_mac_vif_setup_ps(arvif);
2900 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002901 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002902 break;
2903 }
2904 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002905
Michal Kaziorad088bf2013-10-16 15:44:46 +03002906 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907}
2908
Michal Kaziorc930f742014-01-23 11:38:25 +01002909static const char *chandef_get_width(enum nl80211_chan_width width)
2910{
2911 switch (width) {
2912 case NL80211_CHAN_WIDTH_20_NOHT:
2913 return "20 (noht)";
2914 case NL80211_CHAN_WIDTH_20:
2915 return "20";
2916 case NL80211_CHAN_WIDTH_40:
2917 return "40";
2918 case NL80211_CHAN_WIDTH_80:
2919 return "80";
2920 case NL80211_CHAN_WIDTH_80P80:
2921 return "80+80";
2922 case NL80211_CHAN_WIDTH_160:
2923 return "160";
2924 case NL80211_CHAN_WIDTH_5:
2925 return "5";
2926 case NL80211_CHAN_WIDTH_10:
2927 return "10";
2928 }
2929 return "?";
2930}
2931
2932static void ath10k_config_chan(struct ath10k *ar)
2933{
2934 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002935 int ret;
2936
2937 lockdep_assert_held(&ar->conf_mutex);
2938
Michal Kazior7aa7a722014-08-25 12:09:38 +02002939 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002940 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2941 ar->chandef.chan->center_freq,
2942 ar->chandef.center_freq1,
2943 ar->chandef.center_freq2,
2944 chandef_get_width(ar->chandef.width));
2945
2946 /* First stop monitor interface. Some FW versions crash if there's a
2947 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002948 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002949 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002950
2951 list_for_each_entry(arvif, &ar->arvifs, list) {
2952 if (!arvif->is_started)
2953 continue;
2954
Michal Kaziordc55e302014-07-29 12:53:36 +03002955 if (!arvif->is_up)
2956 continue;
2957
Michal Kaziorc930f742014-01-23 11:38:25 +01002958 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2959 continue;
2960
Michal Kaziordc55e302014-07-29 12:53:36 +03002961 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002962 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002963 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002964 arvif->vdev_id, ret);
2965 continue;
2966 }
2967 }
2968
Michal Kaziordc55e302014-07-29 12:53:36 +03002969 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002970
2971 list_for_each_entry(arvif, &ar->arvifs, list) {
2972 if (!arvif->is_started)
2973 continue;
2974
2975 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2976 continue;
2977
Michal Kaziordc55e302014-07-29 12:53:36 +03002978 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002979 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002980 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002981 arvif->vdev_id, ret);
2982 continue;
2983 }
2984
2985 if (!arvif->is_up)
2986 continue;
2987
2988 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2989 arvif->bssid);
2990 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002991 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002992 arvif->vdev_id, ret);
2993 continue;
2994 }
2995 }
2996
Michal Kazior19337472014-08-28 12:58:16 +02002997 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002998}
2999
Michal Kazior7d9d5582014-10-21 10:40:15 +03003000static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3001{
3002 int ret;
3003 u32 param;
3004
3005 lockdep_assert_held(&ar->conf_mutex);
3006
3007 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3008
3009 param = ar->wmi.pdev_param->txpower_limit2g;
3010 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3011 if (ret) {
3012 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3013 txpower, ret);
3014 return ret;
3015 }
3016
3017 param = ar->wmi.pdev_param->txpower_limit5g;
3018 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3019 if (ret) {
3020 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3021 txpower, ret);
3022 return ret;
3023 }
3024
3025 return 0;
3026}
3027
3028static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3029{
3030 struct ath10k_vif *arvif;
3031 int ret, txpower = -1;
3032
3033 lockdep_assert_held(&ar->conf_mutex);
3034
3035 list_for_each_entry(arvif, &ar->arvifs, list) {
3036 WARN_ON(arvif->txpower < 0);
3037
3038 if (txpower == -1)
3039 txpower = arvif->txpower;
3040 else
3041 txpower = min(txpower, arvif->txpower);
3042 }
3043
3044 if (WARN_ON(txpower == -1))
3045 return -EINVAL;
3046
3047 ret = ath10k_mac_txpower_setup(ar, txpower);
3048 if (ret) {
3049 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3050 txpower, ret);
3051 return ret;
3052 }
3053
3054 return 0;
3055}
3056
Kalle Valo5e3dd152013-06-12 20:52:10 +03003057static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3058{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003059 struct ath10k *ar = hw->priv;
3060 struct ieee80211_conf *conf = &hw->conf;
3061 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003062
3063 mutex_lock(&ar->conf_mutex);
3064
3065 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003066 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003067 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003068 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003069 conf->chandef.chan->flags,
3070 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003071
Kalle Valo5e3dd152013-06-12 20:52:10 +03003072 spin_lock_bh(&ar->data_lock);
3073 ar->rx_channel = conf->chandef.chan;
3074 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003075
Michal Kaziord6500972014-04-08 09:56:09 +03003076 ar->radar_enabled = conf->radar_enabled;
3077 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003078
3079 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3080 ar->chandef = conf->chandef;
3081 ath10k_config_chan(ar);
3082 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003083 }
3084
Michal Kazioraffd3212013-07-16 09:54:35 +02003085 if (changed & IEEE80211_CONF_CHANGE_PS)
3086 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003087
3088 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003089 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3090 ret = ath10k_monitor_recalc(ar);
3091 if (ret)
3092 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003093 }
3094
3095 mutex_unlock(&ar->conf_mutex);
3096 return ret;
3097}
3098
Ben Greear5572a952014-11-24 16:22:10 +02003099static u32 get_nss_from_chainmask(u16 chain_mask)
3100{
3101 if ((chain_mask & 0x15) == 0x15)
3102 return 4;
3103 else if ((chain_mask & 0x7) == 0x7)
3104 return 3;
3105 else if ((chain_mask & 0x3) == 0x3)
3106 return 2;
3107 return 1;
3108}
3109
Kalle Valo5e3dd152013-06-12 20:52:10 +03003110/*
3111 * TODO:
3112 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3113 * because we will send mgmt frames without CCK. This requirement
3114 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3115 * in the TX packet.
3116 */
3117static int ath10k_add_interface(struct ieee80211_hw *hw,
3118 struct ieee80211_vif *vif)
3119{
3120 struct ath10k *ar = hw->priv;
3121 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3122 enum wmi_sta_powersave_param param;
3123 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003124 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003125 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003126 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003127
3128 mutex_lock(&ar->conf_mutex);
3129
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003130 memset(arvif, 0, sizeof(*arvif));
3131
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 arvif->ar = ar;
3133 arvif->vif = vif;
3134
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003135 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07003136 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003137
Ben Greeara9aefb32014-08-12 11:02:19 +03003138 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003139 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003140 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003141 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003142 }
Ben Greear16c11172014-09-23 14:17:16 -07003143 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003144
Ben Greear16c11172014-09-23 14:17:16 -07003145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3146 bit, ar->free_vdev_map);
3147
3148 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003149 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150
Kalle Valo5e3dd152013-06-12 20:52:10 +03003151 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003152 case NL80211_IFTYPE_P2P_DEVICE:
3153 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3154 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3155 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003156 case NL80211_IFTYPE_UNSPECIFIED:
3157 case NL80211_IFTYPE_STATION:
3158 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3159 if (vif->p2p)
3160 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3161 break;
3162 case NL80211_IFTYPE_ADHOC:
3163 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3164 break;
3165 case NL80211_IFTYPE_AP:
3166 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3167
3168 if (vif->p2p)
3169 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3170 break;
3171 case NL80211_IFTYPE_MONITOR:
3172 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3173 break;
3174 default:
3175 WARN_ON(1);
3176 break;
3177 }
3178
Michal Kazior64badcb2014-09-18 11:18:02 +03003179 /* Some firmware revisions don't wait for beacon tx completion before
3180 * sending another SWBA event. This could lead to hardware using old
3181 * (freed) beacon data in some cases, e.g. tx credit starvation
3182 * combined with missed TBTT. This is very very rare.
3183 *
3184 * On non-IOMMU-enabled hosts this could be a possible security issue
3185 * because hw could beacon some random data on the air. On
3186 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3187 * device would crash.
3188 *
3189 * Since there are no beacon tx completions (implicit nor explicit)
3190 * propagated to host the only workaround for this is to allocate a
3191 * DMA-coherent buffer for a lifetime of a vif and use it for all
3192 * beacon tx commands. Worst case for this approach is some beacons may
3193 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3194 */
3195 if (vif->type == NL80211_IFTYPE_ADHOC ||
3196 vif->type == NL80211_IFTYPE_AP) {
3197 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3198 IEEE80211_MAX_FRAME_LEN,
3199 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303200 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003201 if (!arvif->beacon_buf) {
3202 ret = -ENOMEM;
3203 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3204 ret);
3205 goto err;
3206 }
3207 }
3208
3209 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3210 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3211 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212
3213 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3214 arvif->vdev_subtype, vif->addr);
3215 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003216 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003217 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003218 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219 }
3220
Ben Greear16c11172014-09-23 14:17:16 -07003221 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003222 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003223
Michal Kazior46725b152015-01-28 09:57:49 +02003224 /* It makes no sense to have firmware do keepalives. mac80211 already
3225 * takes care of this with idle connection polling.
3226 */
3227 ret = ath10k_mac_vif_disable_keepalive(arvif);
3228 if (ret) {
3229 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
3230 arvif->vdev_id, ret);
3231 goto err_vdev_delete;
3232 }
3233
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003234 vdev_param = ar->wmi.vdev_param->def_keyid;
3235 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003236 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003237 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003238 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003239 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003240 goto err_vdev_delete;
3241 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003243 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3244 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003245 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003246 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003247 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003248 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003249 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003250 goto err_vdev_delete;
3251 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003252
Ben Greear5572a952014-11-24 16:22:10 +02003253 if (ar->cfg_tx_chainmask) {
3254 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3255
3256 vdev_param = ar->wmi.vdev_param->nss;
3257 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3258 nss);
3259 if (ret) {
3260 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3261 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3262 ret);
3263 goto err_vdev_delete;
3264 }
3265 }
3266
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3268 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3269 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003270 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003271 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003272 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003274
Kalle Valo5a13e762014-01-20 11:01:46 +02003275 ret = ath10k_mac_set_kickout(arvif);
3276 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003277 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003278 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003279 goto err_peer_delete;
3280 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003281 }
3282
3283 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3284 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3285 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3286 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3287 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003288 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003289 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003290 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003291 goto err_peer_delete;
3292 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003293
Michal Kazior9f9b5742014-12-12 12:41:36 +01003294 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003295 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003296 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003297 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003298 goto err_peer_delete;
3299 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003300
Michal Kazior9f9b5742014-12-12 12:41:36 +01003301 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003302 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003303 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003304 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003305 goto err_peer_delete;
3306 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003307 }
3308
Michal Kazior424121c2013-07-22 14:13:31 +02003309 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003310 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003311 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003312 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003313 goto err_peer_delete;
3314 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003315
Michal Kazior424121c2013-07-22 14:13:31 +02003316 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003317 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003318 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003319 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003320 goto err_peer_delete;
3321 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003322
Michal Kazior7d9d5582014-10-21 10:40:15 +03003323 arvif->txpower = vif->bss_conf.txpower;
3324 ret = ath10k_mac_txpower_recalc(ar);
3325 if (ret) {
3326 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3327 goto err_peer_delete;
3328 }
3329
Kalle Valo5e3dd152013-06-12 20:52:10 +03003330 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003331 return 0;
3332
3333err_peer_delete:
3334 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3335 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3336
3337err_vdev_delete:
3338 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003339 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003340 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003341
3342err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003343 if (arvif->beacon_buf) {
3344 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3345 arvif->beacon_buf, arvif->beacon_paddr);
3346 arvif->beacon_buf = NULL;
3347 }
3348
Michal Kazior9dad14a2013-10-16 15:44:45 +03003349 mutex_unlock(&ar->conf_mutex);
3350
Kalle Valo5e3dd152013-06-12 20:52:10 +03003351 return ret;
3352}
3353
3354static void ath10k_remove_interface(struct ieee80211_hw *hw,
3355 struct ieee80211_vif *vif)
3356{
3357 struct ath10k *ar = hw->priv;
3358 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3359 int ret;
3360
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003361 cancel_work_sync(&arvif->wep_key_work);
3362
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303363 mutex_lock(&ar->conf_mutex);
3364
Michal Kaziored543882013-09-13 14:16:56 +02003365 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003366 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003367 spin_unlock_bh(&ar->data_lock);
3368
Simon Wunderlich855aed12014-08-02 09:12:54 +03003369 ret = ath10k_spectral_vif_stop(arvif);
3370 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003371 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003372 arvif->vdev_id, ret);
3373
Ben Greear16c11172014-09-23 14:17:16 -07003374 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003375 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003376
3377 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3378 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3379 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003380 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003381 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003382
3383 kfree(arvif->u.ap.noa_data);
3384 }
3385
Michal Kazior7aa7a722014-08-25 12:09:38 +02003386 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003387 arvif->vdev_id);
3388
Kalle Valo5e3dd152013-06-12 20:52:10 +03003389 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3390 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003391 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003392 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003393
Kalle Valo5e3dd152013-06-12 20:52:10 +03003394 ath10k_peer_cleanup(ar, arvif->vdev_id);
3395
3396 mutex_unlock(&ar->conf_mutex);
3397}
3398
3399/*
3400 * FIXME: Has to be verified.
3401 */
3402#define SUPPORTED_FILTERS \
3403 (FIF_PROMISC_IN_BSS | \
3404 FIF_ALLMULTI | \
3405 FIF_CONTROL | \
3406 FIF_PSPOLL | \
3407 FIF_OTHER_BSS | \
3408 FIF_BCN_PRBRESP_PROMISC | \
3409 FIF_PROBE_REQ | \
3410 FIF_FCSFAIL)
3411
3412static void ath10k_configure_filter(struct ieee80211_hw *hw,
3413 unsigned int changed_flags,
3414 unsigned int *total_flags,
3415 u64 multicast)
3416{
3417 struct ath10k *ar = hw->priv;
3418 int ret;
3419
3420 mutex_lock(&ar->conf_mutex);
3421
3422 changed_flags &= SUPPORTED_FILTERS;
3423 *total_flags &= SUPPORTED_FILTERS;
3424 ar->filter_flags = *total_flags;
3425
Michal Kazior19337472014-08-28 12:58:16 +02003426 ret = ath10k_monitor_recalc(ar);
3427 if (ret)
3428 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003429
3430 mutex_unlock(&ar->conf_mutex);
3431}
3432
3433static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3434 struct ieee80211_vif *vif,
3435 struct ieee80211_bss_conf *info,
3436 u32 changed)
3437{
3438 struct ath10k *ar = hw->priv;
3439 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3440 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003441 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003442
3443 mutex_lock(&ar->conf_mutex);
3444
3445 if (changed & BSS_CHANGED_IBSS)
3446 ath10k_control_ibss(arvif, info, vif->addr);
3447
3448 if (changed & BSS_CHANGED_BEACON_INT) {
3449 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003450 vdev_param = ar->wmi.vdev_param->beacon_interval;
3451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003453 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003454 "mac vdev %d beacon_interval %d\n",
3455 arvif->vdev_id, arvif->beacon_interval);
3456
Kalle Valo5e3dd152013-06-12 20:52:10 +03003457 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003458 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003459 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003460 }
3461
3462 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003463 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003464 "vdev %d set beacon tx mode to staggered\n",
3465 arvif->vdev_id);
3466
Bartosz Markowski226a3392013-09-26 17:47:16 +02003467 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3468 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469 WMI_BEACON_STAGGERED_MODE);
3470 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003471 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003472 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003473
3474 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3475 if (ret)
3476 ath10k_warn(ar, "failed to update beacon template: %d\n",
3477 ret);
3478 }
3479
3480 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3481 ret = ath10k_mac_setup_prb_tmpl(arvif);
3482 if (ret)
3483 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3484 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003485 }
3486
Michal Kaziorba2479f2015-01-24 12:14:51 +02003487 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003488 arvif->dtim_period = info->dtim_period;
3489
Michal Kazior7aa7a722014-08-25 12:09:38 +02003490 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003491 "mac vdev %d dtim_period %d\n",
3492 arvif->vdev_id, arvif->dtim_period);
3493
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003494 vdev_param = ar->wmi.vdev_param->dtim_period;
3495 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003496 arvif->dtim_period);
3497 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003498 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003499 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500 }
3501
3502 if (changed & BSS_CHANGED_SSID &&
3503 vif->type == NL80211_IFTYPE_AP) {
3504 arvif->u.ap.ssid_len = info->ssid_len;
3505 if (info->ssid_len)
3506 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3507 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3508 }
3509
Michal Kazior077efc82014-10-21 10:10:29 +03003510 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3511 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003512
3513 if (changed & BSS_CHANGED_BEACON_ENABLED)
3514 ath10k_control_beaconing(arvif, info);
3515
3516 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003517 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003518 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003519 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003520
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003521 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003522 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003523 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003524 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003525 }
3526
3527 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003528 if (info->use_short_slot)
3529 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3530
3531 else
3532 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3533
Michal Kazior7aa7a722014-08-25 12:09:38 +02003534 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003535 arvif->vdev_id, slottime);
3536
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003537 vdev_param = ar->wmi.vdev_param->slot_time;
3538 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003539 slottime);
3540 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003541 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003542 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543 }
3544
3545 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 if (info->use_short_preamble)
3547 preamble = WMI_VDEV_PREAMBLE_SHORT;
3548 else
3549 preamble = WMI_VDEV_PREAMBLE_LONG;
3550
Michal Kazior7aa7a722014-08-25 12:09:38 +02003551 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003552 "mac vdev %d preamble %dn",
3553 arvif->vdev_id, preamble);
3554
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003555 vdev_param = ar->wmi.vdev_param->preamble;
3556 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 preamble);
3558 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003559 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003560 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561 }
3562
3563 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003564 if (info->assoc) {
3565 /* Workaround: Make sure monitor vdev is not running
3566 * when associating to prevent some firmware revisions
3567 * (e.g. 10.1 and 10.2) from crashing.
3568 */
3569 if (ar->monitor_started)
3570 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003571 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003572 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003573 } else {
3574 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003575 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 }
3577
Michal Kazior7d9d5582014-10-21 10:40:15 +03003578 if (changed & BSS_CHANGED_TXPOWER) {
3579 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3580 arvif->vdev_id, info->txpower);
3581
3582 arvif->txpower = info->txpower;
3583 ret = ath10k_mac_txpower_recalc(ar);
3584 if (ret)
3585 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3586 }
3587
Michal Kaziorbf14e652014-12-12 12:41:38 +01003588 if (changed & BSS_CHANGED_PS) {
3589 ret = ath10k_mac_vif_setup_ps(arvif);
3590 if (ret)
3591 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3592 arvif->vdev_id, ret);
3593 }
3594
Kalle Valo5e3dd152013-06-12 20:52:10 +03003595 mutex_unlock(&ar->conf_mutex);
3596}
3597
3598static int ath10k_hw_scan(struct ieee80211_hw *hw,
3599 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003600 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003601{
3602 struct ath10k *ar = hw->priv;
3603 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003604 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 struct wmi_start_scan_arg arg;
3606 int ret = 0;
3607 int i;
3608
3609 mutex_lock(&ar->conf_mutex);
3610
3611 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003612 switch (ar->scan.state) {
3613 case ATH10K_SCAN_IDLE:
3614 reinit_completion(&ar->scan.started);
3615 reinit_completion(&ar->scan.completed);
3616 ar->scan.state = ATH10K_SCAN_STARTING;
3617 ar->scan.is_roc = false;
3618 ar->scan.vdev_id = arvif->vdev_id;
3619 ret = 0;
3620 break;
3621 case ATH10K_SCAN_STARTING:
3622 case ATH10K_SCAN_RUNNING:
3623 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003624 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003625 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003626 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627 spin_unlock_bh(&ar->data_lock);
3628
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003629 if (ret)
3630 goto exit;
3631
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632 memset(&arg, 0, sizeof(arg));
3633 ath10k_wmi_start_scan_init(ar, &arg);
3634 arg.vdev_id = arvif->vdev_id;
3635 arg.scan_id = ATH10K_SCAN_ID;
3636
3637 if (!req->no_cck)
3638 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3639
3640 if (req->ie_len) {
3641 arg.ie_len = req->ie_len;
3642 memcpy(arg.ie, req->ie, arg.ie_len);
3643 }
3644
3645 if (req->n_ssids) {
3646 arg.n_ssids = req->n_ssids;
3647 for (i = 0; i < arg.n_ssids; i++) {
3648 arg.ssids[i].len = req->ssids[i].ssid_len;
3649 arg.ssids[i].ssid = req->ssids[i].ssid;
3650 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003651 } else {
3652 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003653 }
3654
3655 if (req->n_channels) {
3656 arg.n_channels = req->n_channels;
3657 for (i = 0; i < arg.n_channels; i++)
3658 arg.channels[i] = req->channels[i]->center_freq;
3659 }
3660
3661 ret = ath10k_start_scan(ar, &arg);
3662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003663 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003664 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003665 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003666 spin_unlock_bh(&ar->data_lock);
3667 }
3668
3669exit:
3670 mutex_unlock(&ar->conf_mutex);
3671 return ret;
3672}
3673
3674static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3675 struct ieee80211_vif *vif)
3676{
3677 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003678
3679 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003680 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003681 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003682
3683 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003684}
3685
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003686static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3687 struct ath10k_vif *arvif,
3688 enum set_key_cmd cmd,
3689 struct ieee80211_key_conf *key)
3690{
3691 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3692 int ret;
3693
3694 /* 10.1 firmware branch requires default key index to be set to group
3695 * key index after installing it. Otherwise FW/HW Txes corrupted
3696 * frames with multi-vif APs. This is not required for main firmware
3697 * branch (e.g. 636).
3698 *
3699 * FIXME: This has been tested only in AP. It remains unknown if this
3700 * is required for multi-vif STA interfaces on 10.1 */
3701
3702 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3703 return;
3704
3705 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3706 return;
3707
3708 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3709 return;
3710
3711 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3712 return;
3713
3714 if (cmd != SET_KEY)
3715 return;
3716
3717 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3718 key->keyidx);
3719 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003720 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003721 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003722}
3723
Kalle Valo5e3dd152013-06-12 20:52:10 +03003724static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3725 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3726 struct ieee80211_key_conf *key)
3727{
3728 struct ath10k *ar = hw->priv;
3729 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3730 struct ath10k_peer *peer;
3731 const u8 *peer_addr;
3732 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3733 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3734 int ret = 0;
3735
3736 if (key->keyidx > WMI_MAX_KEY_INDEX)
3737 return -ENOSPC;
3738
3739 mutex_lock(&ar->conf_mutex);
3740
3741 if (sta)
3742 peer_addr = sta->addr;
3743 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3744 peer_addr = vif->bss_conf.bssid;
3745 else
3746 peer_addr = vif->addr;
3747
3748 key->hw_key_idx = key->keyidx;
3749
3750 /* the peer should not disappear in mid-way (unless FW goes awry) since
3751 * we already hold conf_mutex. we just make sure its there now. */
3752 spin_lock_bh(&ar->data_lock);
3753 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3754 spin_unlock_bh(&ar->data_lock);
3755
3756 if (!peer) {
3757 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003758 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003759 peer_addr);
3760 ret = -EOPNOTSUPP;
3761 goto exit;
3762 } else {
3763 /* if the peer doesn't exist there is no key to disable
3764 * anymore */
3765 goto exit;
3766 }
3767 }
3768
3769 if (is_wep) {
3770 if (cmd == SET_KEY)
3771 arvif->wep_keys[key->keyidx] = key;
3772 else
3773 arvif->wep_keys[key->keyidx] = NULL;
3774
3775 if (cmd == DISABLE_KEY)
3776 ath10k_clear_vdev_key(arvif, key);
3777 }
3778
3779 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3780 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003781 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003782 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003783 goto exit;
3784 }
3785
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003786 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3787
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788 spin_lock_bh(&ar->data_lock);
3789 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3790 if (peer && cmd == SET_KEY)
3791 peer->keys[key->keyidx] = key;
3792 else if (peer && cmd == DISABLE_KEY)
3793 peer->keys[key->keyidx] = NULL;
3794 else if (peer == NULL)
3795 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003796 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003797 spin_unlock_bh(&ar->data_lock);
3798
3799exit:
3800 mutex_unlock(&ar->conf_mutex);
3801 return ret;
3802}
3803
Michal Kazior9797feb2014-02-14 14:49:48 +01003804static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3805{
3806 struct ath10k *ar;
3807 struct ath10k_vif *arvif;
3808 struct ath10k_sta *arsta;
3809 struct ieee80211_sta *sta;
3810 u32 changed, bw, nss, smps;
3811 int err;
3812
3813 arsta = container_of(wk, struct ath10k_sta, update_wk);
3814 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3815 arvif = arsta->arvif;
3816 ar = arvif->ar;
3817
3818 spin_lock_bh(&ar->data_lock);
3819
3820 changed = arsta->changed;
3821 arsta->changed = 0;
3822
3823 bw = arsta->bw;
3824 nss = arsta->nss;
3825 smps = arsta->smps;
3826
3827 spin_unlock_bh(&ar->data_lock);
3828
3829 mutex_lock(&ar->conf_mutex);
3830
3831 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003832 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003833 sta->addr, bw);
3834
3835 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3836 WMI_PEER_CHAN_WIDTH, bw);
3837 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003838 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003839 sta->addr, bw, err);
3840 }
3841
3842 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003843 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003844 sta->addr, nss);
3845
3846 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3847 WMI_PEER_NSS, nss);
3848 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003849 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003850 sta->addr, nss, err);
3851 }
3852
3853 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003854 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003855 sta->addr, smps);
3856
3857 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3858 WMI_PEER_SMPS_STATE, smps);
3859 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003860 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003861 sta->addr, smps, err);
3862 }
3863
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003864 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3865 changed & IEEE80211_RC_NSS_CHANGED) {
3866 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003867 sta->addr);
3868
Michal Kazior590922a2014-10-21 10:10:29 +03003869 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003870 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003871 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003872 sta->addr);
3873 }
3874
Michal Kazior9797feb2014-02-14 14:49:48 +01003875 mutex_unlock(&ar->conf_mutex);
3876}
3877
Michal Kaziorcfd10612014-11-25 15:16:05 +01003878static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3879{
3880 struct ath10k *ar = arvif->ar;
3881
3882 lockdep_assert_held(&ar->conf_mutex);
3883
3884 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3885 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3886 return 0;
3887
3888 if (ar->num_stations >= ar->max_num_stations)
3889 return -ENOBUFS;
3890
3891 ar->num_stations++;
3892
3893 return 0;
3894}
3895
3896static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3897{
3898 struct ath10k *ar = arvif->ar;
3899
3900 lockdep_assert_held(&ar->conf_mutex);
3901
3902 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3903 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3904 return;
3905
3906 ar->num_stations--;
3907}
3908
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909static int ath10k_sta_state(struct ieee80211_hw *hw,
3910 struct ieee80211_vif *vif,
3911 struct ieee80211_sta *sta,
3912 enum ieee80211_sta_state old_state,
3913 enum ieee80211_sta_state new_state)
3914{
3915 struct ath10k *ar = hw->priv;
3916 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003917 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003918 int ret = 0;
3919
Michal Kazior76f90022014-02-25 09:29:57 +02003920 if (old_state == IEEE80211_STA_NOTEXIST &&
3921 new_state == IEEE80211_STA_NONE) {
3922 memset(arsta, 0, sizeof(*arsta));
3923 arsta->arvif = arvif;
3924 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3925 }
3926
Michal Kazior9797feb2014-02-14 14:49:48 +01003927 /* cancel must be done outside the mutex to avoid deadlock */
3928 if ((old_state == IEEE80211_STA_NONE &&
3929 new_state == IEEE80211_STA_NOTEXIST))
3930 cancel_work_sync(&arsta->update_wk);
3931
Kalle Valo5e3dd152013-06-12 20:52:10 +03003932 mutex_lock(&ar->conf_mutex);
3933
3934 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003935 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003936 /*
3937 * New station addition.
3938 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003939 ath10k_dbg(ar, ATH10K_DBG_MAC,
3940 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3941 arvif->vdev_id, sta->addr,
3942 ar->num_stations + 1, ar->max_num_stations,
3943 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003944
Michal Kaziorcfd10612014-11-25 15:16:05 +01003945 ret = ath10k_mac_inc_num_stations(arvif);
3946 if (ret) {
3947 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3948 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003949 goto exit;
3950 }
3951
Kalle Valo5e3dd152013-06-12 20:52:10 +03003952 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003954 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 -08003955 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003956 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003957 goto exit;
3958 }
Michal Kazior077efc82014-10-21 10:10:29 +03003959
3960 if (vif->type == NL80211_IFTYPE_STATION) {
3961 WARN_ON(arvif->is_started);
3962
3963 ret = ath10k_vdev_start(arvif);
3964 if (ret) {
3965 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3966 arvif->vdev_id, ret);
3967 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3968 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003969 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003970 goto exit;
3971 }
3972
3973 arvif->is_started = true;
3974 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003975 } else if ((old_state == IEEE80211_STA_NONE &&
3976 new_state == IEEE80211_STA_NOTEXIST)) {
3977 /*
3978 * Existing station deletion.
3979 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003980 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003981 "mac vdev %d peer delete %pM (sta gone)\n",
3982 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003983
3984 if (vif->type == NL80211_IFTYPE_STATION) {
3985 WARN_ON(!arvif->is_started);
3986
3987 ret = ath10k_vdev_stop(arvif);
3988 if (ret)
3989 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3990 arvif->vdev_id, ret);
3991
3992 arvif->is_started = false;
3993 }
3994
Kalle Valo5e3dd152013-06-12 20:52:10 +03003995 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3996 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003997 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003998 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999
Michal Kaziorcfd10612014-11-25 15:16:05 +01004000 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004001 } else if (old_state == IEEE80211_STA_AUTH &&
4002 new_state == IEEE80211_STA_ASSOC &&
4003 (vif->type == NL80211_IFTYPE_AP ||
4004 vif->type == NL80211_IFTYPE_ADHOC)) {
4005 /*
4006 * New association.
4007 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004008 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004009 sta->addr);
4010
Michal Kazior590922a2014-10-21 10:10:29 +03004011 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004013 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004014 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004015 } else if (old_state == IEEE80211_STA_ASSOC &&
4016 new_state == IEEE80211_STA_AUTH &&
4017 (vif->type == NL80211_IFTYPE_AP ||
4018 vif->type == NL80211_IFTYPE_ADHOC)) {
4019 /*
4020 * Disassociation.
4021 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004022 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004023 sta->addr);
4024
Michal Kazior590922a2014-10-21 10:10:29 +03004025 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004026 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004027 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004028 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004029 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004030exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 mutex_unlock(&ar->conf_mutex);
4032 return ret;
4033}
4034
4035static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004036 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037{
4038 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004039 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4040 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004041 u32 value = 0;
4042 int ret = 0;
4043
Michal Kazior548db542013-07-05 16:15:15 +03004044 lockdep_assert_held(&ar->conf_mutex);
4045
Kalle Valo5e3dd152013-06-12 20:52:10 +03004046 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4047 return 0;
4048
4049 switch (ac) {
4050 case IEEE80211_AC_VO:
4051 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4052 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004053 prio = 7;
4054 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004055 break;
4056 case IEEE80211_AC_VI:
4057 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4058 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004059 prio = 5;
4060 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004061 break;
4062 case IEEE80211_AC_BE:
4063 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4064 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004065 prio = 2;
4066 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 break;
4068 case IEEE80211_AC_BK:
4069 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4070 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004071 prio = 0;
4072 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004073 break;
4074 }
4075
4076 if (enable)
4077 arvif->u.sta.uapsd |= value;
4078 else
4079 arvif->u.sta.uapsd &= ~value;
4080
4081 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4082 WMI_STA_PS_PARAM_UAPSD,
4083 arvif->u.sta.uapsd);
4084 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004085 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004086 goto exit;
4087 }
4088
4089 if (arvif->u.sta.uapsd)
4090 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4091 else
4092 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4093
4094 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4095 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4096 value);
4097 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004098 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004099
Michal Kazior9f9b5742014-12-12 12:41:36 +01004100 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4101 if (ret) {
4102 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4103 arvif->vdev_id, ret);
4104 return ret;
4105 }
4106
4107 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4108 if (ret) {
4109 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4110 arvif->vdev_id, ret);
4111 return ret;
4112 }
4113
Michal Kaziorb0e56152015-01-24 12:14:52 +02004114 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4115 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4116 /* Only userspace can make an educated decision when to send
4117 * trigger frame. The following effectively disables u-UAPSD
4118 * autotrigger in firmware (which is enabled by default
4119 * provided the autotrigger service is available).
4120 */
4121
4122 arg.wmm_ac = acc;
4123 arg.user_priority = prio;
4124 arg.service_interval = 0;
4125 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4126 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4127
4128 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4129 arvif->bssid, &arg, 1);
4130 if (ret) {
4131 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4132 ret);
4133 return ret;
4134 }
4135 }
4136
Kalle Valo5e3dd152013-06-12 20:52:10 +03004137exit:
4138 return ret;
4139}
4140
4141static int ath10k_conf_tx(struct ieee80211_hw *hw,
4142 struct ieee80211_vif *vif, u16 ac,
4143 const struct ieee80211_tx_queue_params *params)
4144{
4145 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004146 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004147 struct wmi_wmm_params_arg *p = NULL;
4148 int ret;
4149
4150 mutex_lock(&ar->conf_mutex);
4151
4152 switch (ac) {
4153 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004154 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004155 break;
4156 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004157 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004158 break;
4159 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004160 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 break;
4162 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004163 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004164 break;
4165 }
4166
4167 if (WARN_ON(!p)) {
4168 ret = -EINVAL;
4169 goto exit;
4170 }
4171
4172 p->cwmin = params->cw_min;
4173 p->cwmax = params->cw_max;
4174 p->aifs = params->aifs;
4175
4176 /*
4177 * The channel time duration programmed in the HW is in absolute
4178 * microseconds, while mac80211 gives the txop in units of
4179 * 32 microseconds.
4180 */
4181 p->txop = params->txop * 32;
4182
Michal Kazior7fc979a2015-01-28 09:57:28 +02004183 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4184 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4185 &arvif->wmm_params);
4186 if (ret) {
4187 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4188 arvif->vdev_id, ret);
4189 goto exit;
4190 }
4191 } else {
4192 /* This won't work well with multi-interface cases but it's
4193 * better than nothing.
4194 */
4195 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4196 if (ret) {
4197 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4198 goto exit;
4199 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004200 }
4201
4202 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4203 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004204 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004205
4206exit:
4207 mutex_unlock(&ar->conf_mutex);
4208 return ret;
4209}
4210
4211#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4212
4213static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4214 struct ieee80211_vif *vif,
4215 struct ieee80211_channel *chan,
4216 int duration,
4217 enum ieee80211_roc_type type)
4218{
4219 struct ath10k *ar = hw->priv;
4220 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4221 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004222 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004223
4224 mutex_lock(&ar->conf_mutex);
4225
4226 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004227 switch (ar->scan.state) {
4228 case ATH10K_SCAN_IDLE:
4229 reinit_completion(&ar->scan.started);
4230 reinit_completion(&ar->scan.completed);
4231 reinit_completion(&ar->scan.on_channel);
4232 ar->scan.state = ATH10K_SCAN_STARTING;
4233 ar->scan.is_roc = true;
4234 ar->scan.vdev_id = arvif->vdev_id;
4235 ar->scan.roc_freq = chan->center_freq;
4236 ret = 0;
4237 break;
4238 case ATH10K_SCAN_STARTING:
4239 case ATH10K_SCAN_RUNNING:
4240 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004241 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004242 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004243 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004244 spin_unlock_bh(&ar->data_lock);
4245
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004246 if (ret)
4247 goto exit;
4248
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004249 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4250
Kalle Valo5e3dd152013-06-12 20:52:10 +03004251 memset(&arg, 0, sizeof(arg));
4252 ath10k_wmi_start_scan_init(ar, &arg);
4253 arg.vdev_id = arvif->vdev_id;
4254 arg.scan_id = ATH10K_SCAN_ID;
4255 arg.n_channels = 1;
4256 arg.channels[0] = chan->center_freq;
4257 arg.dwell_time_active = duration;
4258 arg.dwell_time_passive = duration;
4259 arg.max_scan_time = 2 * duration;
4260 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4261 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4262
4263 ret = ath10k_start_scan(ar, &arg);
4264 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004265 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004267 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004268 spin_unlock_bh(&ar->data_lock);
4269 goto exit;
4270 }
4271
4272 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4273 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004274 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004275
4276 ret = ath10k_scan_stop(ar);
4277 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004278 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004279
Kalle Valo5e3dd152013-06-12 20:52:10 +03004280 ret = -ETIMEDOUT;
4281 goto exit;
4282 }
4283
4284 ret = 0;
4285exit:
4286 mutex_unlock(&ar->conf_mutex);
4287 return ret;
4288}
4289
4290static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4291{
4292 struct ath10k *ar = hw->priv;
4293
4294 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004295 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004296 mutex_unlock(&ar->conf_mutex);
4297
Michal Kazior4eb2e162014-10-28 10:23:09 +01004298 cancel_delayed_work_sync(&ar->scan.timeout);
4299
Kalle Valo5e3dd152013-06-12 20:52:10 +03004300 return 0;
4301}
4302
4303/*
4304 * Both RTS and Fragmentation threshold are interface-specific
4305 * in ath10k, but device-specific in mac80211.
4306 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004307
4308static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4309{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004310 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004311 struct ath10k_vif *arvif;
4312 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004313
Michal Kaziorad088bf2013-10-16 15:44:46 +03004314 mutex_lock(&ar->conf_mutex);
4315 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004317 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004318
Michal Kaziorad088bf2013-10-16 15:44:46 +03004319 ret = ath10k_mac_set_rts(arvif, value);
4320 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004321 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004322 arvif->vdev_id, ret);
4323 break;
4324 }
4325 }
4326 mutex_unlock(&ar->conf_mutex);
4327
4328 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004329}
4330
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004331static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4332 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004333{
4334 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004335 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004336 int ret;
4337
4338 /* mac80211 doesn't care if we really xmit queued frames or not
4339 * we'll collect those frames either way if we stop/delete vdevs */
4340 if (drop)
4341 return;
4342
Michal Kazior548db542013-07-05 16:15:15 +03004343 mutex_lock(&ar->conf_mutex);
4344
Michal Kazioraffd3212013-07-16 09:54:35 +02004345 if (ar->state == ATH10K_STATE_WEDGED)
4346 goto skip;
4347
Michal Kazioredb82362013-07-05 16:15:14 +03004348 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004349 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004350
Michal Kazioredb82362013-07-05 16:15:14 +03004351 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004352 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004353 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004354
Michal Kazior7962b0d2014-10-28 10:34:38 +01004355 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4356 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4357 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004358
4359 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004360 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004361
4362 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004363 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004364 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004365
Michal Kazioraffd3212013-07-16 09:54:35 +02004366skip:
Michal Kazior548db542013-07-05 16:15:15 +03004367 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004368}
4369
4370/* TODO: Implement this function properly
4371 * For now it is needed to reply to Probe Requests in IBSS mode.
4372 * Propably we need this information from FW.
4373 */
4374static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4375{
4376 return 1;
4377}
4378
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004379#ifdef CONFIG_PM
4380static int ath10k_suspend(struct ieee80211_hw *hw,
4381 struct cfg80211_wowlan *wowlan)
4382{
4383 struct ath10k *ar = hw->priv;
4384 int ret;
4385
Marek Puzyniak9042e172014-02-10 17:14:23 +01004386 mutex_lock(&ar->conf_mutex);
4387
Marek Puzyniak00f54822014-02-10 17:14:24 +01004388 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004389 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004390 if (ret == -ETIMEDOUT)
4391 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004392 ret = 1;
4393 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004394 }
4395
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004396 ret = ath10k_hif_suspend(ar);
4397 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004398 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004399 goto resume;
4400 }
4401
Marek Puzyniak9042e172014-02-10 17:14:23 +01004402 ret = 0;
4403 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004404resume:
4405 ret = ath10k_wmi_pdev_resume_target(ar);
4406 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004407 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004408
4409 ret = 1;
4410exit:
4411 mutex_unlock(&ar->conf_mutex);
4412 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004413}
4414
4415static int ath10k_resume(struct ieee80211_hw *hw)
4416{
4417 struct ath10k *ar = hw->priv;
4418 int ret;
4419
Marek Puzyniak9042e172014-02-10 17:14:23 +01004420 mutex_lock(&ar->conf_mutex);
4421
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004422 ret = ath10k_hif_resume(ar);
4423 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004424 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004425 ret = 1;
4426 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004427 }
4428
4429 ret = ath10k_wmi_pdev_resume_target(ar);
4430 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004431 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004432 ret = 1;
4433 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004434 }
4435
Marek Puzyniak9042e172014-02-10 17:14:23 +01004436 ret = 0;
4437exit:
4438 mutex_unlock(&ar->conf_mutex);
4439 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004440}
4441#endif
4442
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004443static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4444 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004445{
4446 struct ath10k *ar = hw->priv;
4447
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004448 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4449 return;
4450
Michal Kazioraffd3212013-07-16 09:54:35 +02004451 mutex_lock(&ar->conf_mutex);
4452
4453 /* If device failed to restart it will be in a different state, e.g.
4454 * ATH10K_STATE_WEDGED */
4455 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004456 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004457 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004458 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004459 }
4460
4461 mutex_unlock(&ar->conf_mutex);
4462}
4463
Michal Kazior2e1dea42013-07-31 10:32:40 +02004464static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4465 struct survey_info *survey)
4466{
4467 struct ath10k *ar = hw->priv;
4468 struct ieee80211_supported_band *sband;
4469 struct survey_info *ar_survey = &ar->survey[idx];
4470 int ret = 0;
4471
4472 mutex_lock(&ar->conf_mutex);
4473
4474 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4475 if (sband && idx >= sband->n_channels) {
4476 idx -= sband->n_channels;
4477 sband = NULL;
4478 }
4479
4480 if (!sband)
4481 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4482
4483 if (!sband || idx >= sband->n_channels) {
4484 ret = -ENOENT;
4485 goto exit;
4486 }
4487
4488 spin_lock_bh(&ar->data_lock);
4489 memcpy(survey, ar_survey, sizeof(*survey));
4490 spin_unlock_bh(&ar->data_lock);
4491
4492 survey->channel = &sband->channels[idx];
4493
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004494 if (ar->rx_channel == survey->channel)
4495 survey->filled |= SURVEY_INFO_IN_USE;
4496
Michal Kazior2e1dea42013-07-31 10:32:40 +02004497exit:
4498 mutex_unlock(&ar->conf_mutex);
4499 return ret;
4500}
4501
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004502/* Helper table for legacy fixed_rate/bitrate_mask */
4503static const u8 cck_ofdm_rate[] = {
4504 /* CCK */
4505 3, /* 1Mbps */
4506 2, /* 2Mbps */
4507 1, /* 5.5Mbps */
4508 0, /* 11Mbps */
4509 /* OFDM */
4510 3, /* 6Mbps */
4511 7, /* 9Mbps */
4512 2, /* 12Mbps */
4513 6, /* 18Mbps */
4514 1, /* 24Mbps */
4515 5, /* 36Mbps */
4516 0, /* 48Mbps */
4517 4, /* 54Mbps */
4518};
4519
4520/* Check if only one bit set */
4521static int ath10k_check_single_mask(u32 mask)
4522{
4523 int bit;
4524
4525 bit = ffs(mask);
4526 if (!bit)
4527 return 0;
4528
4529 mask &= ~BIT(bit - 1);
4530 if (mask)
4531 return 2;
4532
4533 return 1;
4534}
4535
4536static bool
4537ath10k_default_bitrate_mask(struct ath10k *ar,
4538 enum ieee80211_band band,
4539 const struct cfg80211_bitrate_mask *mask)
4540{
4541 u32 legacy = 0x00ff;
4542 u8 ht = 0xff, i;
4543 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004544 u16 nrf = ar->num_rf_chains;
4545
4546 if (ar->cfg_tx_chainmask)
4547 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004548
4549 switch (band) {
4550 case IEEE80211_BAND_2GHZ:
4551 legacy = 0x00fff;
4552 vht = 0;
4553 break;
4554 case IEEE80211_BAND_5GHZ:
4555 break;
4556 default:
4557 return false;
4558 }
4559
4560 if (mask->control[band].legacy != legacy)
4561 return false;
4562
Ben Greearb116ea12014-11-24 16:22:10 +02004563 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004564 if (mask->control[band].ht_mcs[i] != ht)
4565 return false;
4566
Ben Greearb116ea12014-11-24 16:22:10 +02004567 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004568 if (mask->control[band].vht_mcs[i] != vht)
4569 return false;
4570
4571 return true;
4572}
4573
4574static bool
4575ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4576 enum ieee80211_band band,
4577 u8 *fixed_nss)
4578{
4579 int ht_nss = 0, vht_nss = 0, i;
4580
4581 /* check legacy */
4582 if (ath10k_check_single_mask(mask->control[band].legacy))
4583 return false;
4584
4585 /* check HT */
4586 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4587 if (mask->control[band].ht_mcs[i] == 0xff)
4588 continue;
4589 else if (mask->control[band].ht_mcs[i] == 0x00)
4590 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004591
4592 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004593 }
4594
4595 ht_nss = i;
4596
4597 /* check VHT */
4598 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4599 if (mask->control[band].vht_mcs[i] == 0x03ff)
4600 continue;
4601 else if (mask->control[band].vht_mcs[i] == 0x0000)
4602 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004603
4604 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004605 }
4606
4607 vht_nss = i;
4608
4609 if (ht_nss > 0 && vht_nss > 0)
4610 return false;
4611
4612 if (ht_nss)
4613 *fixed_nss = ht_nss;
4614 else if (vht_nss)
4615 *fixed_nss = vht_nss;
4616 else
4617 return false;
4618
4619 return true;
4620}
4621
4622static bool
4623ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4624 enum ieee80211_band band,
4625 enum wmi_rate_preamble *preamble)
4626{
4627 int legacy = 0, ht = 0, vht = 0, i;
4628
4629 *preamble = WMI_RATE_PREAMBLE_OFDM;
4630
4631 /* check legacy */
4632 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4633 if (legacy > 1)
4634 return false;
4635
4636 /* check HT */
4637 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4638 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4639 if (ht > 1)
4640 return false;
4641
4642 /* check VHT */
4643 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4644 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4645 if (vht > 1)
4646 return false;
4647
4648 /* Currently we support only one fixed_rate */
4649 if ((legacy + ht + vht) != 1)
4650 return false;
4651
4652 if (ht)
4653 *preamble = WMI_RATE_PREAMBLE_HT;
4654 else if (vht)
4655 *preamble = WMI_RATE_PREAMBLE_VHT;
4656
4657 return true;
4658}
4659
4660static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004661ath10k_bitrate_mask_rate(struct ath10k *ar,
4662 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004663 enum ieee80211_band band,
4664 u8 *fixed_rate,
4665 u8 *fixed_nss)
4666{
4667 u8 rate = 0, pream = 0, nss = 0, i;
4668 enum wmi_rate_preamble preamble;
4669
4670 /* Check if single rate correct */
4671 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4672 return false;
4673
4674 pream = preamble;
4675
4676 switch (preamble) {
4677 case WMI_RATE_PREAMBLE_CCK:
4678 case WMI_RATE_PREAMBLE_OFDM:
4679 i = ffs(mask->control[band].legacy) - 1;
4680
4681 if (band == IEEE80211_BAND_2GHZ && i < 4)
4682 pream = WMI_RATE_PREAMBLE_CCK;
4683
4684 if (band == IEEE80211_BAND_5GHZ)
4685 i += 4;
4686
4687 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4688 return false;
4689
4690 rate = cck_ofdm_rate[i];
4691 break;
4692 case WMI_RATE_PREAMBLE_HT:
4693 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4694 if (mask->control[band].ht_mcs[i])
4695 break;
4696
4697 if (i == IEEE80211_HT_MCS_MASK_LEN)
4698 return false;
4699
4700 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4701 nss = i;
4702 break;
4703 case WMI_RATE_PREAMBLE_VHT:
4704 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4705 if (mask->control[band].vht_mcs[i])
4706 break;
4707
4708 if (i == NL80211_VHT_NSS_MAX)
4709 return false;
4710
4711 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4712 nss = i;
4713 break;
4714 }
4715
4716 *fixed_nss = nss + 1;
4717 nss <<= 4;
4718 pream <<= 6;
4719
Michal Kazior7aa7a722014-08-25 12:09:38 +02004720 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 +01004721 pream, nss, rate);
4722
4723 *fixed_rate = pream | nss | rate;
4724
4725 return true;
4726}
4727
Michal Kazior7aa7a722014-08-25 12:09:38 +02004728static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4729 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004730 enum ieee80211_band band,
4731 u8 *fixed_rate,
4732 u8 *fixed_nss)
4733{
4734 /* First check full NSS mask, if we can simply limit NSS */
4735 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4736 return true;
4737
4738 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004739 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004740}
4741
4742static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4743 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004744 u8 fixed_nss,
4745 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004746{
4747 struct ath10k *ar = arvif->ar;
4748 u32 vdev_param;
4749 int ret = 0;
4750
4751 mutex_lock(&ar->conf_mutex);
4752
4753 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004754 arvif->fixed_nss == fixed_nss &&
4755 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004756 goto exit;
4757
4758 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004759 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004760
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004761 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004762 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004763
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004764 vdev_param = ar->wmi.vdev_param->fixed_rate;
4765 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4766 vdev_param, fixed_rate);
4767 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004768 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004769 fixed_rate, ret);
4770 ret = -EINVAL;
4771 goto exit;
4772 }
4773
4774 arvif->fixed_rate = fixed_rate;
4775
4776 vdev_param = ar->wmi.vdev_param->nss;
4777 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4778 vdev_param, fixed_nss);
4779
4780 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004781 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004782 fixed_nss, ret);
4783 ret = -EINVAL;
4784 goto exit;
4785 }
4786
4787 arvif->fixed_nss = fixed_nss;
4788
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004789 vdev_param = ar->wmi.vdev_param->sgi;
4790 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4791 force_sgi);
4792
4793 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004794 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004795 force_sgi, ret);
4796 ret = -EINVAL;
4797 goto exit;
4798 }
4799
4800 arvif->force_sgi = force_sgi;
4801
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004802exit:
4803 mutex_unlock(&ar->conf_mutex);
4804 return ret;
4805}
4806
4807static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4808 struct ieee80211_vif *vif,
4809 const struct cfg80211_bitrate_mask *mask)
4810{
4811 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4812 struct ath10k *ar = arvif->ar;
4813 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4814 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4815 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004816 u8 force_sgi;
4817
Ben Greearb116ea12014-11-24 16:22:10 +02004818 if (ar->cfg_tx_chainmask)
4819 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4820
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004821 force_sgi = mask->control[band].gi;
4822 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4823 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004824
4825 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004826 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004827 &fixed_rate,
4828 &fixed_nss))
4829 return -EINVAL;
4830 }
4831
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004832 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004833 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004834 return -EINVAL;
4835 }
4836
4837 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4838 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004839}
4840
Michal Kazior9797feb2014-02-14 14:49:48 +01004841static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4842 struct ieee80211_vif *vif,
4843 struct ieee80211_sta *sta,
4844 u32 changed)
4845{
4846 struct ath10k *ar = hw->priv;
4847 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4848 u32 bw, smps;
4849
4850 spin_lock_bh(&ar->data_lock);
4851
Michal Kazior7aa7a722014-08-25 12:09:38 +02004852 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004853 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4854 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4855 sta->smps_mode);
4856
4857 if (changed & IEEE80211_RC_BW_CHANGED) {
4858 bw = WMI_PEER_CHWIDTH_20MHZ;
4859
4860 switch (sta->bandwidth) {
4861 case IEEE80211_STA_RX_BW_20:
4862 bw = WMI_PEER_CHWIDTH_20MHZ;
4863 break;
4864 case IEEE80211_STA_RX_BW_40:
4865 bw = WMI_PEER_CHWIDTH_40MHZ;
4866 break;
4867 case IEEE80211_STA_RX_BW_80:
4868 bw = WMI_PEER_CHWIDTH_80MHZ;
4869 break;
4870 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004871 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004872 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004873 bw = WMI_PEER_CHWIDTH_20MHZ;
4874 break;
4875 }
4876
4877 arsta->bw = bw;
4878 }
4879
4880 if (changed & IEEE80211_RC_NSS_CHANGED)
4881 arsta->nss = sta->rx_nss;
4882
4883 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4884 smps = WMI_PEER_SMPS_PS_NONE;
4885
4886 switch (sta->smps_mode) {
4887 case IEEE80211_SMPS_AUTOMATIC:
4888 case IEEE80211_SMPS_OFF:
4889 smps = WMI_PEER_SMPS_PS_NONE;
4890 break;
4891 case IEEE80211_SMPS_STATIC:
4892 smps = WMI_PEER_SMPS_STATIC;
4893 break;
4894 case IEEE80211_SMPS_DYNAMIC:
4895 smps = WMI_PEER_SMPS_DYNAMIC;
4896 break;
4897 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004898 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004899 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004900 smps = WMI_PEER_SMPS_PS_NONE;
4901 break;
4902 }
4903
4904 arsta->smps = smps;
4905 }
4906
Michal Kazior9797feb2014-02-14 14:49:48 +01004907 arsta->changed |= changed;
4908
4909 spin_unlock_bh(&ar->data_lock);
4910
4911 ieee80211_queue_work(hw, &arsta->update_wk);
4912}
4913
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004914static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4915{
4916 /*
4917 * FIXME: Return 0 for time being. Need to figure out whether FW
4918 * has the API to fetch 64-bit local TSF
4919 */
4920
4921 return 0;
4922}
4923
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004924static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4925 struct ieee80211_vif *vif,
4926 enum ieee80211_ampdu_mlme_action action,
4927 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4928 u8 buf_size)
4929{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004930 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004931 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4932
Michal Kazior7aa7a722014-08-25 12:09:38 +02004933 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 +02004934 arvif->vdev_id, sta->addr, tid, action);
4935
4936 switch (action) {
4937 case IEEE80211_AMPDU_RX_START:
4938 case IEEE80211_AMPDU_RX_STOP:
4939 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4940 * creation/removal. Do we need to verify this?
4941 */
4942 return 0;
4943 case IEEE80211_AMPDU_TX_START:
4944 case IEEE80211_AMPDU_TX_STOP_CONT:
4945 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4946 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4947 case IEEE80211_AMPDU_TX_OPERATIONAL:
4948 /* Firmware offloads Tx aggregation entirely so deny mac80211
4949 * Tx aggregation requests.
4950 */
4951 return -EOPNOTSUPP;
4952 }
4953
4954 return -EINVAL;
4955}
4956
Kalle Valo5e3dd152013-06-12 20:52:10 +03004957static const struct ieee80211_ops ath10k_ops = {
4958 .tx = ath10k_tx,
4959 .start = ath10k_start,
4960 .stop = ath10k_stop,
4961 .config = ath10k_config,
4962 .add_interface = ath10k_add_interface,
4963 .remove_interface = ath10k_remove_interface,
4964 .configure_filter = ath10k_configure_filter,
4965 .bss_info_changed = ath10k_bss_info_changed,
4966 .hw_scan = ath10k_hw_scan,
4967 .cancel_hw_scan = ath10k_cancel_hw_scan,
4968 .set_key = ath10k_set_key,
4969 .sta_state = ath10k_sta_state,
4970 .conf_tx = ath10k_conf_tx,
4971 .remain_on_channel = ath10k_remain_on_channel,
4972 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4973 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004974 .flush = ath10k_flush,
4975 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004976 .set_antenna = ath10k_set_antenna,
4977 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004978 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004979 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004980 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004981 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004982 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004983 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004984 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4985 .get_et_stats = ath10k_debug_get_et_stats,
4986 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004987
4988 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4989
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004990#ifdef CONFIG_PM
4991 .suspend = ath10k_suspend,
4992 .resume = ath10k_resume,
4993#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004994#ifdef CONFIG_MAC80211_DEBUGFS
4995 .sta_add_debugfs = ath10k_sta_add_debugfs,
4996#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004997};
4998
4999#define RATETAB_ENT(_rate, _rateid, _flags) { \
5000 .bitrate = (_rate), \
5001 .flags = (_flags), \
5002 .hw_value = (_rateid), \
5003}
5004
5005#define CHAN2G(_channel, _freq, _flags) { \
5006 .band = IEEE80211_BAND_2GHZ, \
5007 .hw_value = (_channel), \
5008 .center_freq = (_freq), \
5009 .flags = (_flags), \
5010 .max_antenna_gain = 0, \
5011 .max_power = 30, \
5012}
5013
5014#define CHAN5G(_channel, _freq, _flags) { \
5015 .band = IEEE80211_BAND_5GHZ, \
5016 .hw_value = (_channel), \
5017 .center_freq = (_freq), \
5018 .flags = (_flags), \
5019 .max_antenna_gain = 0, \
5020 .max_power = 30, \
5021}
5022
5023static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5024 CHAN2G(1, 2412, 0),
5025 CHAN2G(2, 2417, 0),
5026 CHAN2G(3, 2422, 0),
5027 CHAN2G(4, 2427, 0),
5028 CHAN2G(5, 2432, 0),
5029 CHAN2G(6, 2437, 0),
5030 CHAN2G(7, 2442, 0),
5031 CHAN2G(8, 2447, 0),
5032 CHAN2G(9, 2452, 0),
5033 CHAN2G(10, 2457, 0),
5034 CHAN2G(11, 2462, 0),
5035 CHAN2G(12, 2467, 0),
5036 CHAN2G(13, 2472, 0),
5037 CHAN2G(14, 2484, 0),
5038};
5039
5040static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005041 CHAN5G(36, 5180, 0),
5042 CHAN5G(40, 5200, 0),
5043 CHAN5G(44, 5220, 0),
5044 CHAN5G(48, 5240, 0),
5045 CHAN5G(52, 5260, 0),
5046 CHAN5G(56, 5280, 0),
5047 CHAN5G(60, 5300, 0),
5048 CHAN5G(64, 5320, 0),
5049 CHAN5G(100, 5500, 0),
5050 CHAN5G(104, 5520, 0),
5051 CHAN5G(108, 5540, 0),
5052 CHAN5G(112, 5560, 0),
5053 CHAN5G(116, 5580, 0),
5054 CHAN5G(120, 5600, 0),
5055 CHAN5G(124, 5620, 0),
5056 CHAN5G(128, 5640, 0),
5057 CHAN5G(132, 5660, 0),
5058 CHAN5G(136, 5680, 0),
5059 CHAN5G(140, 5700, 0),
5060 CHAN5G(149, 5745, 0),
5061 CHAN5G(153, 5765, 0),
5062 CHAN5G(157, 5785, 0),
5063 CHAN5G(161, 5805, 0),
5064 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005065};
5066
Michal Kazior91b12082014-12-12 12:41:35 +01005067/* Note: Be careful if you re-order these. There is code which depends on this
5068 * ordering.
5069 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005070static struct ieee80211_rate ath10k_rates[] = {
5071 /* CCK */
5072 RATETAB_ENT(10, 0x82, 0),
5073 RATETAB_ENT(20, 0x84, 0),
5074 RATETAB_ENT(55, 0x8b, 0),
5075 RATETAB_ENT(110, 0x96, 0),
5076 /* OFDM */
5077 RATETAB_ENT(60, 0x0c, 0),
5078 RATETAB_ENT(90, 0x12, 0),
5079 RATETAB_ENT(120, 0x18, 0),
5080 RATETAB_ENT(180, 0x24, 0),
5081 RATETAB_ENT(240, 0x30, 0),
5082 RATETAB_ENT(360, 0x48, 0),
5083 RATETAB_ENT(480, 0x60, 0),
5084 RATETAB_ENT(540, 0x6c, 0),
5085};
5086
5087#define ath10k_a_rates (ath10k_rates + 4)
5088#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5089#define ath10k_g_rates (ath10k_rates + 0)
5090#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5091
Michal Kaziore7b54192014-08-07 11:03:27 +02005092struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005093{
5094 struct ieee80211_hw *hw;
5095 struct ath10k *ar;
5096
Michal Kaziore7b54192014-08-07 11:03:27 +02005097 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005098 if (!hw)
5099 return NULL;
5100
5101 ar = hw->priv;
5102 ar->hw = hw;
5103
5104 return ar;
5105}
5106
5107void ath10k_mac_destroy(struct ath10k *ar)
5108{
5109 ieee80211_free_hw(ar->hw);
5110}
5111
5112static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5113 {
5114 .max = 8,
5115 .types = BIT(NL80211_IFTYPE_STATION)
5116 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005117 },
5118 {
5119 .max = 3,
5120 .types = BIT(NL80211_IFTYPE_P2P_GO)
5121 },
5122 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005123 .max = 1,
5124 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5125 },
5126 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005127 .max = 7,
5128 .types = BIT(NL80211_IFTYPE_AP)
5129 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005130};
5131
Bartosz Markowskif2595092013-12-10 16:20:39 +01005132static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005133 {
5134 .max = 8,
5135 .types = BIT(NL80211_IFTYPE_AP)
5136 },
5137};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005138
5139static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5140 {
5141 .limits = ath10k_if_limits,
5142 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5143 .max_interfaces = 8,
5144 .num_different_channels = 1,
5145 .beacon_int_infra_match = true,
5146 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005147};
5148
5149static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005150 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005151 .limits = ath10k_10x_if_limits,
5152 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005153 .max_interfaces = 8,
5154 .num_different_channels = 1,
5155 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005156#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005157 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5158 BIT(NL80211_CHAN_WIDTH_20) |
5159 BIT(NL80211_CHAN_WIDTH_40) |
5160 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005161#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005162 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005163};
5164
5165static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5166{
5167 struct ieee80211_sta_vht_cap vht_cap = {0};
5168 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005169 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005170
5171 vht_cap.vht_supported = 1;
5172 vht_cap.cap = ar->vht_cap_info;
5173
Michal Kazior8865bee42013-07-24 12:36:46 +02005174 mcs_map = 0;
5175 for (i = 0; i < 8; i++) {
5176 if (i < ar->num_rf_chains)
5177 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5178 else
5179 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5180 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005181
5182 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5183 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5184
5185 return vht_cap;
5186}
5187
5188static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5189{
5190 int i;
5191 struct ieee80211_sta_ht_cap ht_cap = {0};
5192
5193 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5194 return ht_cap;
5195
5196 ht_cap.ht_supported = 1;
5197 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5198 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5199 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5200 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5201 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5202
5203 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5204 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5205
5206 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5207 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5208
5209 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5210 u32 smps;
5211
5212 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5213 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5214
5215 ht_cap.cap |= smps;
5216 }
5217
5218 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5219 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5220
5221 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5222 u32 stbc;
5223
5224 stbc = ar->ht_cap_info;
5225 stbc &= WMI_HT_CAP_RX_STBC;
5226 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5227 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5228 stbc &= IEEE80211_HT_CAP_RX_STBC;
5229
5230 ht_cap.cap |= stbc;
5231 }
5232
5233 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5234 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5235
5236 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5237 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5238
5239 /* max AMSDU is implicitly taken from vht_cap_info */
5240 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5241 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5242
Michal Kazior8865bee42013-07-24 12:36:46 +02005243 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005244 ht_cap.mcs.rx_mask[i] = 0xFF;
5245
5246 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5247
5248 return ht_cap;
5249}
5250
Kalle Valo5e3dd152013-06-12 20:52:10 +03005251static void ath10k_get_arvif_iter(void *data, u8 *mac,
5252 struct ieee80211_vif *vif)
5253{
5254 struct ath10k_vif_iter *arvif_iter = data;
5255 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5256
5257 if (arvif->vdev_id == arvif_iter->vdev_id)
5258 arvif_iter->arvif = arvif;
5259}
5260
5261struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5262{
5263 struct ath10k_vif_iter arvif_iter;
5264 u32 flags;
5265
5266 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5267 arvif_iter.vdev_id = vdev_id;
5268
5269 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5270 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5271 flags,
5272 ath10k_get_arvif_iter,
5273 &arvif_iter);
5274 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005275 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005276 return NULL;
5277 }
5278
5279 return arvif_iter.arvif;
5280}
5281
5282int ath10k_mac_register(struct ath10k *ar)
5283{
5284 struct ieee80211_supported_band *band;
5285 struct ieee80211_sta_vht_cap vht_cap;
5286 struct ieee80211_sta_ht_cap ht_cap;
5287 void *channels;
5288 int ret;
5289
5290 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5291
5292 SET_IEEE80211_DEV(ar->hw, ar->dev);
5293
5294 ht_cap = ath10k_get_ht_cap(ar);
5295 vht_cap = ath10k_create_vht_cap(ar);
5296
5297 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5298 channels = kmemdup(ath10k_2ghz_channels,
5299 sizeof(ath10k_2ghz_channels),
5300 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005301 if (!channels) {
5302 ret = -ENOMEM;
5303 goto err_free;
5304 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005305
5306 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5307 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5308 band->channels = channels;
5309 band->n_bitrates = ath10k_g_rates_size;
5310 band->bitrates = ath10k_g_rates;
5311 band->ht_cap = ht_cap;
5312
Yanbo Lid68bb122015-01-23 08:18:20 +08005313 /* Enable the VHT support at 2.4 GHz */
5314 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005315
5316 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5317 }
5318
5319 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5320 channels = kmemdup(ath10k_5ghz_channels,
5321 sizeof(ath10k_5ghz_channels),
5322 GFP_KERNEL);
5323 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005324 ret = -ENOMEM;
5325 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005326 }
5327
5328 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5329 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5330 band->channels = channels;
5331 band->n_bitrates = ath10k_a_rates_size;
5332 band->bitrates = ath10k_a_rates;
5333 band->ht_cap = ht_cap;
5334 band->vht_cap = vht_cap;
5335 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5336 }
5337
5338 ar->hw->wiphy->interface_modes =
5339 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005340 BIT(NL80211_IFTYPE_AP);
5341
Ben Greear46acf7b2014-05-16 17:15:38 +03005342 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5343 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5344
Bartosz Markowskid3541812013-12-10 16:20:40 +01005345 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5346 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005347 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005348 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5349 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005350
5351 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5352 IEEE80211_HW_SUPPORTS_PS |
5353 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5354 IEEE80211_HW_SUPPORTS_UAPSD |
5355 IEEE80211_HW_MFP_CAPABLE |
5356 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5357 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005358 IEEE80211_HW_AP_LINK_PS |
5359 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005360
Eliad Peller0d8614b2014-09-10 14:07:36 +03005361 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5362
Kalle Valo5e3dd152013-06-12 20:52:10 +03005363 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005364 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005365
5366 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5367 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5368 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5369 }
5370
5371 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5372 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5373
5374 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005375 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005376
Kalle Valo5e3dd152013-06-12 20:52:10 +03005377 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5378
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005379 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5380 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5381
5382 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5383 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5384 * correct Probe Responses. This is more of a hack advert..
5385 */
5386 ar->hw->wiphy->probe_resp_offload |=
5387 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5388 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5389 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5390 }
5391
Kalle Valo5e3dd152013-06-12 20:52:10 +03005392 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005393 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005394 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5395
5396 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005397 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5398
Kalle Valo5e3dd152013-06-12 20:52:10 +03005399 /*
5400 * on LL hardware queues are managed entirely by the FW
5401 * so we only advertise to mac we can do the queues thing
5402 */
5403 ar->hw->queues = 4;
5404
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005405 switch (ar->wmi.op_version) {
5406 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5407 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005408 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5409 ar->hw->wiphy->n_iface_combinations =
5410 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005411 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005412 break;
5413 case ATH10K_FW_WMI_OP_VERSION_10_1:
5414 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005415 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005416 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5417 ar->hw->wiphy->n_iface_combinations =
5418 ARRAY_SIZE(ath10k_10x_if_comb);
5419 break;
5420 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5421 case ATH10K_FW_WMI_OP_VERSION_MAX:
5422 WARN_ON(1);
5423 ret = -EINVAL;
5424 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005425 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005426
Michal Kazior7c199992013-07-31 10:47:57 +02005427 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5428
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005429 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5430 /* Init ath dfs pattern detector */
5431 ar->ath_common.debug_mask = ATH_DBG_DFS;
5432 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5433 NL80211_DFS_UNSET);
5434
5435 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005436 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005437 }
5438
Kalle Valo5e3dd152013-06-12 20:52:10 +03005439 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5440 ath10k_reg_notifier);
5441 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005442 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005443 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005444 }
5445
5446 ret = ieee80211_register_hw(ar->hw);
5447 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005448 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005449 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005450 }
5451
5452 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5453 ret = regulatory_hint(ar->hw->wiphy,
5454 ar->ath_common.regulatory.alpha2);
5455 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005456 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005457 }
5458
5459 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005460
5461err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005462 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005463err_free:
5464 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5465 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5466
Kalle Valo5e3dd152013-06-12 20:52:10 +03005467 return ret;
5468}
5469
5470void ath10k_mac_unregister(struct ath10k *ar)
5471{
5472 ieee80211_unregister_hw(ar->hw);
5473
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005474 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5475 ar->dfs_detector->exit(ar->dfs_detector);
5476
Kalle Valo5e3dd152013-06-12 20:52:10 +03005477 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5478 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5479
5480 SET_IEEE80211_DEV(ar->hw, NULL);
5481}