blob: 4ee74f660443a92edd06602ba600eba82dd52eda [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;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001589 arg->peer_vht_caps = vht_cap->cap;
1590
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001591 ampdu_factor = (vht_cap->cap &
1592 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1593 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1594
1595 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1596 * zero in VHT IE. Using it would result in degraded throughput.
1597 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1598 * it if VHT max_mpdu is smaller. */
1599 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1600 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1601 ampdu_factor)) - 1);
1602
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1604 arg->peer_flags |= WMI_PEER_80MHZ;
1605
1606 arg->peer_vht_rates.rx_max_rate =
1607 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1608 arg->peer_vht_rates.rx_mcs_set =
1609 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1610 arg->peer_vht_rates.tx_max_rate =
1611 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1612 arg->peer_vht_rates.tx_mcs_set =
1613 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1614
Michal Kazior7aa7a722014-08-25 12:09:38 +02001615 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001616 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617}
1618
1619static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001620 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 struct wmi_peer_assoc_complete_arg *arg)
1623{
Michal Kazior590922a2014-10-21 10:10:29 +03001624 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1625
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626 switch (arvif->vdev_type) {
1627 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001628 if (sta->wme)
1629 arg->peer_flags |= WMI_PEER_QOS;
1630
1631 if (sta->wme && sta->uapsd_queues) {
1632 arg->peer_flags |= WMI_PEER_APSD;
1633 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1634 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 break;
1636 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001637 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001638 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001640 case WMI_VDEV_TYPE_IBSS:
1641 if (sta->wme)
1642 arg->peer_flags |= WMI_PEER_QOS;
1643 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 default:
1645 break;
1646 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02001647
1648 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1649 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001650}
1651
Michal Kazior91b12082014-12-12 12:41:35 +01001652static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1653{
1654 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1655 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1656}
1657
Kalle Valo5e3dd152013-06-12 20:52:10 +03001658static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001659 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001660 struct ieee80211_sta *sta,
1661 struct wmi_peer_assoc_complete_arg *arg)
1662{
1663 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1664
Kalle Valo5e3dd152013-06-12 20:52:10 +03001665 switch (ar->hw->conf.chandef.chan->band) {
1666 case IEEE80211_BAND_2GHZ:
1667 if (sta->ht_cap.ht_supported) {
1668 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1669 phymode = MODE_11NG_HT40;
1670 else
1671 phymode = MODE_11NG_HT20;
Michal Kazior91b12082014-12-12 12:41:35 +01001672 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001673 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01001674 } else {
1675 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001676 }
1677
1678 break;
1679 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001680 /*
1681 * Check VHT first.
1682 */
1683 if (sta->vht_cap.vht_supported) {
1684 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1685 phymode = MODE_11AC_VHT80;
1686 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1687 phymode = MODE_11AC_VHT40;
1688 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1689 phymode = MODE_11AC_VHT20;
1690 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1692 phymode = MODE_11NA_HT40;
1693 else
1694 phymode = MODE_11NA_HT20;
1695 } else {
1696 phymode = MODE_11A;
1697 }
1698
1699 break;
1700 default:
1701 break;
1702 }
1703
Michal Kazior7aa7a722014-08-25 12:09:38 +02001704 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001705 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001706
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707 arg->peer_phymode = phymode;
1708 WARN_ON(phymode == MODE_UNKNOWN);
1709}
1710
Kalle Valob9ada652013-10-16 15:44:46 +03001711static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001712 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001713 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001714 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001715{
Michal Kazior548db542013-07-05 16:15:15 +03001716 lockdep_assert_held(&ar->conf_mutex);
1717
Kalle Valob9ada652013-10-16 15:44:46 +03001718 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001719
Michal Kazior590922a2014-10-21 10:10:29 +03001720 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1721 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001722 ath10k_peer_assoc_h_rates(ar, sta, arg);
1723 ath10k_peer_assoc_h_ht(ar, sta, arg);
1724 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001725 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1726 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001727
Kalle Valob9ada652013-10-16 15:44:46 +03001728 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729}
1730
Michal Kazior90046f52014-02-14 14:45:51 +01001731static const u32 ath10k_smps_map[] = {
1732 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1733 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1734 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1735 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1736};
1737
1738static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1739 const u8 *addr,
1740 const struct ieee80211_sta_ht_cap *ht_cap)
1741{
1742 int smps;
1743
1744 if (!ht_cap->ht_supported)
1745 return 0;
1746
1747 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1748 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1749
1750 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1751 return -EINVAL;
1752
1753 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1754 WMI_PEER_SMPS_STATE,
1755 ath10k_smps_map[smps]);
1756}
1757
Kalle Valo5e3dd152013-06-12 20:52:10 +03001758/* can be called only in mac80211 callbacks due to `key_count` usage */
1759static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1760 struct ieee80211_vif *vif,
1761 struct ieee80211_bss_conf *bss_conf)
1762{
1763 struct ath10k *ar = hw->priv;
1764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001765 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001766 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767 struct ieee80211_sta *ap_sta;
1768 int ret;
1769
Michal Kazior548db542013-07-05 16:15:15 +03001770 lockdep_assert_held(&ar->conf_mutex);
1771
Michal Kazior077efc82014-10-21 10:10:29 +03001772 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1773 arvif->vdev_id, arvif->bssid, arvif->aid);
1774
Kalle Valo5e3dd152013-06-12 20:52:10 +03001775 rcu_read_lock();
1776
1777 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1778 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001779 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001780 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001781 rcu_read_unlock();
1782 return;
1783 }
1784
Michal Kazior90046f52014-02-14 14:45:51 +01001785 /* ap_sta must be accessed only within rcu section which must be left
1786 * before calling ath10k_setup_peer_smps() which might sleep. */
1787 ht_cap = ap_sta->ht_cap;
1788
Michal Kazior590922a2014-10-21 10:10:29 +03001789 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001791 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001792 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001793 rcu_read_unlock();
1794 return;
1795 }
1796
1797 rcu_read_unlock();
1798
Kalle Valob9ada652013-10-16 15:44:46 +03001799 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1800 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001801 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001802 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001803 return;
1804 }
1805
Michal Kazior90046f52014-02-14 14:45:51 +01001806 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1807 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001808 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001809 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001810 return;
1811 }
1812
Michal Kazior7aa7a722014-08-25 12:09:38 +02001813 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001814 "mac vdev %d up (associated) bssid %pM aid %d\n",
1815 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1816
Michal Kazior077efc82014-10-21 10:10:29 +03001817 WARN_ON(arvif->is_up);
1818
Michal Kaziorc930f742014-01-23 11:38:25 +01001819 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001820 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001821
1822 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001824 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001825 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001826 return;
1827 }
1828
1829 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830}
1831
Kalle Valo5e3dd152013-06-12 20:52:10 +03001832static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1833 struct ieee80211_vif *vif)
1834{
1835 struct ath10k *ar = hw->priv;
1836 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1837 int ret;
1838
Michal Kazior548db542013-07-05 16:15:15 +03001839 lockdep_assert_held(&ar->conf_mutex);
1840
Michal Kazior077efc82014-10-21 10:10:29 +03001841 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1842 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001843
Kalle Valo5e3dd152013-06-12 20:52:10 +03001844 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001845 if (ret)
1846 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1847 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001848
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001849 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001850 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001851}
1852
Michal Kazior590922a2014-10-21 10:10:29 +03001853static int ath10k_station_assoc(struct ath10k *ar,
1854 struct ieee80211_vif *vif,
1855 struct ieee80211_sta *sta,
1856 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001857{
Michal Kazior590922a2014-10-21 10:10:29 +03001858 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001859 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001860 int ret = 0;
1861
Michal Kazior548db542013-07-05 16:15:15 +03001862 lockdep_assert_held(&ar->conf_mutex);
1863
Michal Kazior590922a2014-10-21 10:10:29 +03001864 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001865 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001866 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001867 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001868 return ret;
1869 }
1870
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001871 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001872 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1873 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001874 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001875 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001876 return ret;
1877 }
1878
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001879 /* Re-assoc is run only to update supported rates for given station. It
1880 * doesn't make much sense to reconfigure the peer completely.
1881 */
1882 if (!reassoc) {
1883 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1884 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001885 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001886 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001887 arvif->vdev_id, ret);
1888 return ret;
1889 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001890
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001891 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1892 if (ret) {
1893 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1894 sta->addr, arvif->vdev_id, ret);
1895 return ret;
1896 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001897
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001898 if (!sta->wme) {
1899 arvif->num_legacy_stations++;
1900 ret = ath10k_recalc_rtscts_prot(arvif);
1901 if (ret) {
1902 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1903 arvif->vdev_id, ret);
1904 return ret;
1905 }
1906 }
1907
1908 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1909 if (ret) {
1910 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001911 arvif->vdev_id, ret);
1912 return ret;
1913 }
1914 }
1915
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916 return ret;
1917}
1918
Michal Kazior590922a2014-10-21 10:10:29 +03001919static int ath10k_station_disassoc(struct ath10k *ar,
1920 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001921 struct ieee80211_sta *sta)
1922{
Michal Kazior590922a2014-10-21 10:10:29 +03001923 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924 int ret = 0;
1925
1926 lockdep_assert_held(&ar->conf_mutex);
1927
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001928 if (!sta->wme) {
1929 arvif->num_legacy_stations--;
1930 ret = ath10k_recalc_rtscts_prot(arvif);
1931 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001932 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001933 arvif->vdev_id, ret);
1934 return ret;
1935 }
1936 }
1937
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1939 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001940 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001941 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 return ret;
1943 }
1944
1945 return ret;
1946}
1947
1948/**************/
1949/* Regulatory */
1950/**************/
1951
1952static int ath10k_update_channel_list(struct ath10k *ar)
1953{
1954 struct ieee80211_hw *hw = ar->hw;
1955 struct ieee80211_supported_band **bands;
1956 enum ieee80211_band band;
1957 struct ieee80211_channel *channel;
1958 struct wmi_scan_chan_list_arg arg = {0};
1959 struct wmi_channel_arg *ch;
1960 bool passive;
1961 int len;
1962 int ret;
1963 int i;
1964
Michal Kazior548db542013-07-05 16:15:15 +03001965 lockdep_assert_held(&ar->conf_mutex);
1966
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 bands = hw->wiphy->bands;
1968 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1969 if (!bands[band])
1970 continue;
1971
1972 for (i = 0; i < bands[band]->n_channels; i++) {
1973 if (bands[band]->channels[i].flags &
1974 IEEE80211_CHAN_DISABLED)
1975 continue;
1976
1977 arg.n_channels++;
1978 }
1979 }
1980
1981 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1982 arg.channels = kzalloc(len, GFP_KERNEL);
1983 if (!arg.channels)
1984 return -ENOMEM;
1985
1986 ch = arg.channels;
1987 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1988 if (!bands[band])
1989 continue;
1990
1991 for (i = 0; i < bands[band]->n_channels; i++) {
1992 channel = &bands[band]->channels[i];
1993
1994 if (channel->flags & IEEE80211_CHAN_DISABLED)
1995 continue;
1996
1997 ch->allow_ht = true;
1998
1999 /* FIXME: when should we really allow VHT? */
2000 ch->allow_vht = true;
2001
2002 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002003 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004
2005 ch->ht40plus =
2006 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2007
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002008 ch->chan_radar =
2009 !!(channel->flags & IEEE80211_CHAN_RADAR);
2010
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002011 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002012 ch->passive = passive;
2013
2014 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002015 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002016 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002017 ch->max_power = channel->max_power * 2;
2018 ch->max_reg_power = channel->max_reg_power * 2;
2019 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002020 ch->reg_class_id = 0; /* FIXME */
2021
2022 /* FIXME: why use only legacy modes, why not any
2023 * HT/VHT modes? Would that even make any
2024 * difference? */
2025 if (channel->band == IEEE80211_BAND_2GHZ)
2026 ch->mode = MODE_11G;
2027 else
2028 ch->mode = MODE_11A;
2029
2030 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2031 continue;
2032
Michal Kazior7aa7a722014-08-25 12:09:38 +02002033 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002034 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2035 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 ch->freq, ch->max_power, ch->max_reg_power,
2037 ch->max_antenna_gain, ch->mode);
2038
2039 ch++;
2040 }
2041 }
2042
2043 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2044 kfree(arg.channels);
2045
2046 return ret;
2047}
2048
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002049static enum wmi_dfs_region
2050ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2051{
2052 switch (dfs_region) {
2053 case NL80211_DFS_UNSET:
2054 return WMI_UNINIT_DFS_DOMAIN;
2055 case NL80211_DFS_FCC:
2056 return WMI_FCC_DFS_DOMAIN;
2057 case NL80211_DFS_ETSI:
2058 return WMI_ETSI_DFS_DOMAIN;
2059 case NL80211_DFS_JP:
2060 return WMI_MKK4_DFS_DOMAIN;
2061 }
2062 return WMI_UNINIT_DFS_DOMAIN;
2063}
2064
Michal Kaziorf7843d72013-07-16 09:38:52 +02002065static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002066{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002067 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002069 enum wmi_dfs_region wmi_dfs_reg;
2070 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002071
Michal Kaziorf7843d72013-07-16 09:38:52 +02002072 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002073
2074 ret = ath10k_update_channel_list(ar);
2075 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002076 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077
2078 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002079
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002080 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2081 nl_dfs_reg = ar->dfs_detector->region;
2082 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2083 } else {
2084 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2085 }
2086
Kalle Valo5e3dd152013-06-12 20:52:10 +03002087 /* Target allows setting up per-band regdomain but ath_common provides
2088 * a combined one only */
2089 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002090 regpair->reg_domain,
2091 regpair->reg_domain, /* 2ghz */
2092 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002093 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002094 regpair->reg_5ghz_ctl,
2095 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002097 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002098}
Michal Kazior548db542013-07-05 16:15:15 +03002099
Michal Kaziorf7843d72013-07-16 09:38:52 +02002100static void ath10k_reg_notifier(struct wiphy *wiphy,
2101 struct regulatory_request *request)
2102{
2103 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2104 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002105 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002106
2107 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2108
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002109 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002110 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002111 request->dfs_region);
2112 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2113 request->dfs_region);
2114 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002115 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002116 request->dfs_region);
2117 }
2118
Michal Kaziorf7843d72013-07-16 09:38:52 +02002119 mutex_lock(&ar->conf_mutex);
2120 if (ar->state == ATH10K_STATE_ON)
2121 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002122 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123}
2124
2125/***************/
2126/* TX handlers */
2127/***************/
2128
Michal Kazior42c3aa62013-10-02 11:03:38 +02002129static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2130{
2131 if (ieee80211_is_mgmt(hdr->frame_control))
2132 return HTT_DATA_TX_EXT_TID_MGMT;
2133
2134 if (!ieee80211_is_data_qos(hdr->frame_control))
2135 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2136
2137 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2138 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2139
2140 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2141}
2142
Michal Kazior2b37c292014-09-02 11:00:22 +03002143static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002144{
Michal Kazior2b37c292014-09-02 11:00:22 +03002145 if (vif)
2146 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002147
Michal Kazior1bbc0972014-04-08 09:45:47 +03002148 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002149 return ar->monitor_vdev_id;
2150
Michal Kazior7aa7a722014-08-25 12:09:38 +02002151 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002152 return 0;
2153}
2154
Michal Kazior4b604552014-07-21 21:03:09 +03002155/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2156 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157 */
Michal Kazior4b604552014-07-21 21:03:09 +03002158static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159{
2160 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002161 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162 u8 *qos_ctl;
2163
2164 if (!ieee80211_is_data_qos(hdr->frame_control))
2165 return;
2166
2167 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002168 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2169 skb->data, (void *)qos_ctl - (void *)skb->data);
2170 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002171
2172 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2173 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2174 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2175 * it is safe to downgrade to NullFunc.
2176 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002177 hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002178 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2179 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2180 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2181 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182}
2183
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002184static void ath10k_tx_wep_key_work(struct work_struct *work)
2185{
2186 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2187 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02002188 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002189 int ret, keyidx = arvif->def_wep_key_newidx;
2190
Michal Kazior911e6c02014-05-26 12:46:03 +03002191 mutex_lock(&arvif->ar->conf_mutex);
2192
2193 if (arvif->ar->state != ATH10K_STATE_ON)
2194 goto unlock;
2195
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002196 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03002197 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002198
Michal Kazior7aa7a722014-08-25 12:09:38 +02002199 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002200 arvif->vdev_id, keyidx);
2201
2202 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2203 arvif->vdev_id,
2204 arvif->ar->wmi.vdev_param->def_keyid,
2205 keyidx);
2206 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002207 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002208 arvif->vdev_id,
2209 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03002210 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002211 }
2212
2213 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03002214
2215unlock:
2216 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002217}
2218
Michal Kazior4b604552014-07-21 21:03:09 +03002219static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2220 struct ieee80211_key_conf *key,
2221 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2224 struct ath10k *ar = arvif->ar;
2225 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002226
Kalle Valo5e3dd152013-06-12 20:52:10 +03002227 if (!ieee80211_has_protected(hdr->frame_control))
2228 return;
2229
2230 if (!key)
2231 return;
2232
2233 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2234 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2235 return;
2236
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002237 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238 return;
2239
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002240 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2241 * queueing frames until key index is updated is not an option because
2242 * sk_buff may need more processing to be done, e.g. offchannel */
2243 arvif->def_wep_key_newidx = key->keyidx;
2244 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002245}
2246
Michal Kazior4b604552014-07-21 21:03:09 +03002247static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2248 struct ieee80211_vif *vif,
2249 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002250{
2251 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002252 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2253
2254 /* This is case only for P2P_GO */
2255 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2256 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2257 return;
2258
2259 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2260 spin_lock_bh(&ar->data_lock);
2261 if (arvif->u.ap.noa_data)
2262 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2263 GFP_ATOMIC))
2264 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2265 arvif->u.ap.noa_data,
2266 arvif->u.ap.noa_len);
2267 spin_unlock_bh(&ar->data_lock);
2268 }
2269}
2270
Michal Kazior8d6d3622014-11-24 14:58:31 +01002271static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2272{
2273 /* FIXME: Not really sure since when the behaviour changed. At some
2274 * point new firmware stopped requiring creation of peer entries for
2275 * offchannel tx (and actually creating them causes issues with wmi-htc
2276 * tx credit replenishment and reliability). Assuming it's at least 3.4
2277 * because that's when the `freq` was introduced to TX_FRM HTT command.
2278 */
2279 return !(ar->htt.target_version_major >= 3 &&
2280 ar->htt.target_version_minor >= 4);
2281}
2282
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2284{
2285 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002286 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002287
Michal Kazior961d4c32013-08-09 10:13:34 +02002288 if (ar->htt.target_version_major >= 3) {
2289 /* Since HTT 3.0 there is no separate mgmt tx command */
2290 ret = ath10k_htt_tx(&ar->htt, skb);
2291 goto exit;
2292 }
2293
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002294 if (ieee80211_is_mgmt(hdr->frame_control)) {
2295 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2296 ar->fw_features)) {
2297 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2298 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002299 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002300 ret = -EBUSY;
2301 goto exit;
2302 }
2303
2304 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2305 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2306 } else {
2307 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2308 }
2309 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2310 ar->fw_features) &&
2311 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002312 /* FW does not report tx status properly for NullFunc frames
2313 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002314 * those frames when it detects link/beacon loss and depends
2315 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002316 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002317 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002318 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002319 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320
Michal Kazior961d4c32013-08-09 10:13:34 +02002321exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002323 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2324 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325 ieee80211_free_txskb(ar->hw, skb);
2326 }
2327}
2328
2329void ath10k_offchan_tx_purge(struct ath10k *ar)
2330{
2331 struct sk_buff *skb;
2332
2333 for (;;) {
2334 skb = skb_dequeue(&ar->offchan_tx_queue);
2335 if (!skb)
2336 break;
2337
2338 ieee80211_free_txskb(ar->hw, skb);
2339 }
2340}
2341
2342void ath10k_offchan_tx_work(struct work_struct *work)
2343{
2344 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2345 struct ath10k_peer *peer;
2346 struct ieee80211_hdr *hdr;
2347 struct sk_buff *skb;
2348 const u8 *peer_addr;
2349 int vdev_id;
2350 int ret;
2351
2352 /* FW requirement: We must create a peer before FW will send out
2353 * an offchannel frame. Otherwise the frame will be stuck and
2354 * never transmitted. We delete the peer upon tx completion.
2355 * It is unlikely that a peer for offchannel tx will already be
2356 * present. However it may be in some rare cases so account for that.
2357 * Otherwise we might remove a legitimate peer and break stuff. */
2358
2359 for (;;) {
2360 skb = skb_dequeue(&ar->offchan_tx_queue);
2361 if (!skb)
2362 break;
2363
2364 mutex_lock(&ar->conf_mutex);
2365
Michal Kazior7aa7a722014-08-25 12:09:38 +02002366 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002367 skb);
2368
2369 hdr = (struct ieee80211_hdr *)skb->data;
2370 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002371 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002372
2373 spin_lock_bh(&ar->data_lock);
2374 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2375 spin_unlock_bh(&ar->data_lock);
2376
2377 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002378 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002379 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002380 peer_addr, vdev_id);
2381
2382 if (!peer) {
2383 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2384 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002385 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386 peer_addr, vdev_id, ret);
2387 }
2388
2389 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002390 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002391 ar->offchan_tx_skb = skb;
2392 spin_unlock_bh(&ar->data_lock);
2393
2394 ath10k_tx_htt(ar, skb);
2395
2396 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2397 3 * HZ);
Nicholas Mc Guire38e2a642015-01-08 13:27:34 +01002398 if (ret == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002399 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002400 skb);
2401
2402 if (!peer) {
2403 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2404 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002405 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002406 peer_addr, vdev_id, ret);
2407 }
2408
2409 mutex_unlock(&ar->conf_mutex);
2410 }
2411}
2412
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002413void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2414{
2415 struct sk_buff *skb;
2416
2417 for (;;) {
2418 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2419 if (!skb)
2420 break;
2421
2422 ieee80211_free_txskb(ar->hw, skb);
2423 }
2424}
2425
2426void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2427{
2428 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2429 struct sk_buff *skb;
2430 int ret;
2431
2432 for (;;) {
2433 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2434 if (!skb)
2435 break;
2436
2437 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002438 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002439 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002440 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002441 ieee80211_free_txskb(ar->hw, skb);
2442 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002443 }
2444}
2445
Kalle Valo5e3dd152013-06-12 20:52:10 +03002446/************/
2447/* Scanning */
2448/************/
2449
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002450void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002451{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002452 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002454 switch (ar->scan.state) {
2455 case ATH10K_SCAN_IDLE:
2456 break;
2457 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002458 if (ar->scan.is_roc)
2459 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002460 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002461 case ATH10K_SCAN_ABORTING:
2462 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002463 ieee80211_scan_completed(ar->hw,
2464 (ar->scan.state ==
2465 ATH10K_SCAN_ABORTING));
2466 /* fall through */
2467 case ATH10K_SCAN_STARTING:
2468 ar->scan.state = ATH10K_SCAN_IDLE;
2469 ar->scan_channel = NULL;
2470 ath10k_offchan_tx_purge(ar);
2471 cancel_delayed_work(&ar->scan.timeout);
2472 complete_all(&ar->scan.completed);
2473 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002474 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002475}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002476
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002477void ath10k_scan_finish(struct ath10k *ar)
2478{
2479 spin_lock_bh(&ar->data_lock);
2480 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002481 spin_unlock_bh(&ar->data_lock);
2482}
2483
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002484static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485{
2486 struct wmi_stop_scan_arg arg = {
2487 .req_id = 1, /* FIXME */
2488 .req_type = WMI_SCAN_STOP_ONE,
2489 .u.scan_id = ATH10K_SCAN_ID,
2490 };
2491 int ret;
2492
2493 lockdep_assert_held(&ar->conf_mutex);
2494
Kalle Valo5e3dd152013-06-12 20:52:10 +03002495 ret = ath10k_wmi_stop_scan(ar, &arg);
2496 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002497 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002498 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002499 }
2500
Kalle Valo5e3dd152013-06-12 20:52:10 +03002501 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002502 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002503 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002504 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002505 } else if (ret > 0) {
2506 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002508
2509out:
2510 /* Scan state should be updated upon scan completion but in case
2511 * firmware fails to deliver the event (for whatever reason) it is
2512 * desired to clean up scan state anyway. Firmware may have just
2513 * dropped the scan completion event delivery due to transport pipe
2514 * being overflown with data and/or it can recover on its own before
2515 * next scan request is submitted.
2516 */
2517 spin_lock_bh(&ar->data_lock);
2518 if (ar->scan.state != ATH10K_SCAN_IDLE)
2519 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002520 spin_unlock_bh(&ar->data_lock);
2521
2522 return ret;
2523}
2524
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002525static void ath10k_scan_abort(struct ath10k *ar)
2526{
2527 int ret;
2528
2529 lockdep_assert_held(&ar->conf_mutex);
2530
2531 spin_lock_bh(&ar->data_lock);
2532
2533 switch (ar->scan.state) {
2534 case ATH10K_SCAN_IDLE:
2535 /* This can happen if timeout worker kicked in and called
2536 * abortion while scan completion was being processed.
2537 */
2538 break;
2539 case ATH10K_SCAN_STARTING:
2540 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002541 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002542 ath10k_scan_state_str(ar->scan.state),
2543 ar->scan.state);
2544 break;
2545 case ATH10K_SCAN_RUNNING:
2546 ar->scan.state = ATH10K_SCAN_ABORTING;
2547 spin_unlock_bh(&ar->data_lock);
2548
2549 ret = ath10k_scan_stop(ar);
2550 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002551 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002552
2553 spin_lock_bh(&ar->data_lock);
2554 break;
2555 }
2556
2557 spin_unlock_bh(&ar->data_lock);
2558}
2559
2560void ath10k_scan_timeout_work(struct work_struct *work)
2561{
2562 struct ath10k *ar = container_of(work, struct ath10k,
2563 scan.timeout.work);
2564
2565 mutex_lock(&ar->conf_mutex);
2566 ath10k_scan_abort(ar);
2567 mutex_unlock(&ar->conf_mutex);
2568}
2569
Kalle Valo5e3dd152013-06-12 20:52:10 +03002570static int ath10k_start_scan(struct ath10k *ar,
2571 const struct wmi_start_scan_arg *arg)
2572{
2573 int ret;
2574
2575 lockdep_assert_held(&ar->conf_mutex);
2576
2577 ret = ath10k_wmi_start_scan(ar, arg);
2578 if (ret)
2579 return ret;
2580
Kalle Valo5e3dd152013-06-12 20:52:10 +03002581 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2582 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002583 ret = ath10k_scan_stop(ar);
2584 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002585 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002586
2587 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 }
2589
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002590 /* Add a 200ms margin to account for event/command processing */
2591 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2592 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002593 return 0;
2594}
2595
2596/**********************/
2597/* mac80211 callbacks */
2598/**********************/
2599
2600static void ath10k_tx(struct ieee80211_hw *hw,
2601 struct ieee80211_tx_control *control,
2602 struct sk_buff *skb)
2603{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002604 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002605 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2606 struct ieee80211_vif *vif = info->control.vif;
2607 struct ieee80211_key_conf *key = info->control.hw_key;
2608 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002609
2610 /* We should disable CCK RATE due to P2P */
2611 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002612 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002613
Michal Kazior4b604552014-07-21 21:03:09 +03002614 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2615 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002616 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002617
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002618 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002619 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2620 ath10k_tx_h_nwifi(hw, skb);
2621 ath10k_tx_h_update_wep_key(vif, key, skb);
2622 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2623 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002625
Kalle Valo5e3dd152013-06-12 20:52:10 +03002626 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2627 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01002628 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002629 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002630 spin_unlock_bh(&ar->data_lock);
2631
Michal Kazior8d6d3622014-11-24 14:58:31 +01002632 if (ath10k_mac_need_offchan_tx_work(ar)) {
2633 ATH10K_SKB_CB(skb)->htt.freq = 0;
2634 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002635
Michal Kazior8d6d3622014-11-24 14:58:31 +01002636 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2637 skb);
2638
2639 skb_queue_tail(&ar->offchan_tx_queue, skb);
2640 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2641 return;
2642 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002643 }
2644
2645 ath10k_tx_htt(ar, skb);
2646}
2647
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002648/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01002649void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002650{
2651 /* make sure rcu-protected mac80211 tx path itself is drained */
2652 synchronize_net();
2653
2654 ath10k_offchan_tx_purge(ar);
2655 ath10k_mgmt_over_wmi_tx_purge(ar);
2656
2657 cancel_work_sync(&ar->offchan_tx_work);
2658 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2659}
2660
Michal Kazioraffd3212013-07-16 09:54:35 +02002661void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002662{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002663 struct ath10k_vif *arvif;
2664
Michal Kazior818bdd12013-07-16 09:38:57 +02002665 lockdep_assert_held(&ar->conf_mutex);
2666
Michal Kazior19337472014-08-28 12:58:16 +02002667 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2668 ar->filter_flags = 0;
2669 ar->monitor = false;
2670
2671 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002672 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002673
2674 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002675
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002676 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002677 ath10k_peer_cleanup_all(ar);
2678 ath10k_core_stop(ar);
2679 ath10k_hif_power_down(ar);
2680
2681 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002682 list_for_each_entry(arvif, &ar->arvifs, list)
2683 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002684 spin_unlock_bh(&ar->data_lock);
2685}
2686
Ben Greear46acf7b2014-05-16 17:15:38 +03002687static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2688{
2689 struct ath10k *ar = hw->priv;
2690
2691 mutex_lock(&ar->conf_mutex);
2692
2693 if (ar->cfg_tx_chainmask) {
2694 *tx_ant = ar->cfg_tx_chainmask;
2695 *rx_ant = ar->cfg_rx_chainmask;
2696 } else {
2697 *tx_ant = ar->supp_tx_chainmask;
2698 *rx_ant = ar->supp_rx_chainmask;
2699 }
2700
2701 mutex_unlock(&ar->conf_mutex);
2702
2703 return 0;
2704}
2705
Ben Greear5572a952014-11-24 16:22:10 +02002706static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2707{
2708 /* It is not clear that allowing gaps in chainmask
2709 * is helpful. Probably it will not do what user
2710 * is hoping for, so warn in that case.
2711 */
2712 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2713 return;
2714
2715 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2716 dbg, cm);
2717}
2718
Ben Greear46acf7b2014-05-16 17:15:38 +03002719static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2720{
2721 int ret;
2722
2723 lockdep_assert_held(&ar->conf_mutex);
2724
Ben Greear5572a952014-11-24 16:22:10 +02002725 ath10k_check_chain_mask(ar, tx_ant, "tx");
2726 ath10k_check_chain_mask(ar, rx_ant, "rx");
2727
Ben Greear46acf7b2014-05-16 17:15:38 +03002728 ar->cfg_tx_chainmask = tx_ant;
2729 ar->cfg_rx_chainmask = rx_ant;
2730
2731 if ((ar->state != ATH10K_STATE_ON) &&
2732 (ar->state != ATH10K_STATE_RESTARTED))
2733 return 0;
2734
2735 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2736 tx_ant);
2737 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002738 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002739 ret, tx_ant);
2740 return ret;
2741 }
2742
2743 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2744 rx_ant);
2745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002746 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002747 ret, rx_ant);
2748 return ret;
2749 }
2750
2751 return 0;
2752}
2753
2754static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2755{
2756 struct ath10k *ar = hw->priv;
2757 int ret;
2758
2759 mutex_lock(&ar->conf_mutex);
2760 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2761 mutex_unlock(&ar->conf_mutex);
2762 return ret;
2763}
2764
Kalle Valo5e3dd152013-06-12 20:52:10 +03002765static int ath10k_start(struct ieee80211_hw *hw)
2766{
2767 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002768 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002769
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002770 /*
2771 * This makes sense only when restarting hw. It is harmless to call
2772 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2773 * commands will be submitted while restarting.
2774 */
2775 ath10k_drain_tx(ar);
2776
Michal Kazior548db542013-07-05 16:15:15 +03002777 mutex_lock(&ar->conf_mutex);
2778
Michal Kaziorc5058f52014-05-26 12:46:03 +03002779 switch (ar->state) {
2780 case ATH10K_STATE_OFF:
2781 ar->state = ATH10K_STATE_ON;
2782 break;
2783 case ATH10K_STATE_RESTARTING:
2784 ath10k_halt(ar);
2785 ar->state = ATH10K_STATE_RESTARTED;
2786 break;
2787 case ATH10K_STATE_ON:
2788 case ATH10K_STATE_RESTARTED:
2789 case ATH10K_STATE_WEDGED:
2790 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002791 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002792 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002793 case ATH10K_STATE_UTF:
2794 ret = -EBUSY;
2795 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002796 }
2797
2798 ret = ath10k_hif_power_up(ar);
2799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002800 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002801 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002802 }
2803
Kalle Valo43d2a302014-09-10 18:23:30 +03002804 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002805 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002806 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002807 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002808 }
2809
Bartosz Markowski226a3392013-09-26 17:47:16 +02002810 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002811 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002812 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002813 goto err_core_stop;
2814 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002816 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002817 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002818 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002819 goto err_core_stop;
2820 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002821
Ben Greear46acf7b2014-05-16 17:15:38 +03002822 if (ar->cfg_tx_chainmask)
2823 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2824 ar->cfg_rx_chainmask);
2825
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002826 /*
2827 * By default FW set ARP frames ac to voice (6). In that case ARP
2828 * exchange is not working properly for UAPSD enabled AP. ARP requests
2829 * which arrives with access category 0 are processed by network stack
2830 * and send back with access category 0, but FW changes access category
2831 * to 6. Set ARP frames access category to best effort (0) solves
2832 * this problem.
2833 */
2834
2835 ret = ath10k_wmi_pdev_set_param(ar,
2836 ar->wmi.pdev_param->arp_ac_override, 0);
2837 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002838 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002839 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002840 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002841 }
2842
Michal Kaziord6500972014-04-08 09:56:09 +03002843 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002844 ath10k_regd_update(ar);
2845
Simon Wunderlich855aed12014-08-02 09:12:54 +03002846 ath10k_spectral_start(ar);
2847
Michal Kaziorae254432014-05-26 12:46:02 +03002848 mutex_unlock(&ar->conf_mutex);
2849 return 0;
2850
2851err_core_stop:
2852 ath10k_core_stop(ar);
2853
2854err_power_down:
2855 ath10k_hif_power_down(ar);
2856
2857err_off:
2858 ar->state = ATH10K_STATE_OFF;
2859
2860err:
Michal Kazior548db542013-07-05 16:15:15 +03002861 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002862 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002863}
2864
2865static void ath10k_stop(struct ieee80211_hw *hw)
2866{
2867 struct ath10k *ar = hw->priv;
2868
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002869 ath10k_drain_tx(ar);
2870
Michal Kazior548db542013-07-05 16:15:15 +03002871 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002872 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002873 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002874 ar->state = ATH10K_STATE_OFF;
2875 }
Michal Kazior548db542013-07-05 16:15:15 +03002876 mutex_unlock(&ar->conf_mutex);
2877
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002878 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002879 cancel_work_sync(&ar->restart_work);
2880}
2881
Michal Kaziorad088bf2013-10-16 15:44:46 +03002882static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002883{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002884 struct ath10k_vif *arvif;
2885 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002886
2887 lockdep_assert_held(&ar->conf_mutex);
2888
Michal Kaziorad088bf2013-10-16 15:44:46 +03002889 list_for_each_entry(arvif, &ar->arvifs, list) {
2890 ret = ath10k_mac_vif_setup_ps(arvif);
2891 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002892 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002893 break;
2894 }
2895 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002896
Michal Kaziorad088bf2013-10-16 15:44:46 +03002897 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002898}
2899
Michal Kaziorc930f742014-01-23 11:38:25 +01002900static const char *chandef_get_width(enum nl80211_chan_width width)
2901{
2902 switch (width) {
2903 case NL80211_CHAN_WIDTH_20_NOHT:
2904 return "20 (noht)";
2905 case NL80211_CHAN_WIDTH_20:
2906 return "20";
2907 case NL80211_CHAN_WIDTH_40:
2908 return "40";
2909 case NL80211_CHAN_WIDTH_80:
2910 return "80";
2911 case NL80211_CHAN_WIDTH_80P80:
2912 return "80+80";
2913 case NL80211_CHAN_WIDTH_160:
2914 return "160";
2915 case NL80211_CHAN_WIDTH_5:
2916 return "5";
2917 case NL80211_CHAN_WIDTH_10:
2918 return "10";
2919 }
2920 return "?";
2921}
2922
2923static void ath10k_config_chan(struct ath10k *ar)
2924{
2925 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002926 int ret;
2927
2928 lockdep_assert_held(&ar->conf_mutex);
2929
Michal Kazior7aa7a722014-08-25 12:09:38 +02002930 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002931 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2932 ar->chandef.chan->center_freq,
2933 ar->chandef.center_freq1,
2934 ar->chandef.center_freq2,
2935 chandef_get_width(ar->chandef.width));
2936
2937 /* First stop monitor interface. Some FW versions crash if there's a
2938 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002939 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002940 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002941
2942 list_for_each_entry(arvif, &ar->arvifs, list) {
2943 if (!arvif->is_started)
2944 continue;
2945
Michal Kaziordc55e302014-07-29 12:53:36 +03002946 if (!arvif->is_up)
2947 continue;
2948
Michal Kaziorc930f742014-01-23 11:38:25 +01002949 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2950 continue;
2951
Michal Kaziordc55e302014-07-29 12:53:36 +03002952 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002954 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002955 arvif->vdev_id, ret);
2956 continue;
2957 }
2958 }
2959
Michal Kaziordc55e302014-07-29 12:53:36 +03002960 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002961
2962 list_for_each_entry(arvif, &ar->arvifs, list) {
2963 if (!arvif->is_started)
2964 continue;
2965
2966 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2967 continue;
2968
Michal Kaziordc55e302014-07-29 12:53:36 +03002969 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002971 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002972 arvif->vdev_id, ret);
2973 continue;
2974 }
2975
2976 if (!arvif->is_up)
2977 continue;
2978
2979 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2980 arvif->bssid);
2981 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002982 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002983 arvif->vdev_id, ret);
2984 continue;
2985 }
2986 }
2987
Michal Kazior19337472014-08-28 12:58:16 +02002988 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002989}
2990
Michal Kazior7d9d5582014-10-21 10:40:15 +03002991static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2992{
2993 int ret;
2994 u32 param;
2995
2996 lockdep_assert_held(&ar->conf_mutex);
2997
2998 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2999
3000 param = ar->wmi.pdev_param->txpower_limit2g;
3001 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3002 if (ret) {
3003 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3004 txpower, ret);
3005 return ret;
3006 }
3007
3008 param = ar->wmi.pdev_param->txpower_limit5g;
3009 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3010 if (ret) {
3011 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3012 txpower, ret);
3013 return ret;
3014 }
3015
3016 return 0;
3017}
3018
3019static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3020{
3021 struct ath10k_vif *arvif;
3022 int ret, txpower = -1;
3023
3024 lockdep_assert_held(&ar->conf_mutex);
3025
3026 list_for_each_entry(arvif, &ar->arvifs, list) {
3027 WARN_ON(arvif->txpower < 0);
3028
3029 if (txpower == -1)
3030 txpower = arvif->txpower;
3031 else
3032 txpower = min(txpower, arvif->txpower);
3033 }
3034
3035 if (WARN_ON(txpower == -1))
3036 return -EINVAL;
3037
3038 ret = ath10k_mac_txpower_setup(ar, txpower);
3039 if (ret) {
3040 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3041 txpower, ret);
3042 return ret;
3043 }
3044
3045 return 0;
3046}
3047
Kalle Valo5e3dd152013-06-12 20:52:10 +03003048static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3049{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003050 struct ath10k *ar = hw->priv;
3051 struct ieee80211_conf *conf = &hw->conf;
3052 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003053
3054 mutex_lock(&ar->conf_mutex);
3055
3056 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003057 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003058 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003059 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003060 conf->chandef.chan->flags,
3061 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003062
Kalle Valo5e3dd152013-06-12 20:52:10 +03003063 spin_lock_bh(&ar->data_lock);
3064 ar->rx_channel = conf->chandef.chan;
3065 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003066
Michal Kaziord6500972014-04-08 09:56:09 +03003067 ar->radar_enabled = conf->radar_enabled;
3068 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003069
3070 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3071 ar->chandef = conf->chandef;
3072 ath10k_config_chan(ar);
3073 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003074 }
3075
Michal Kazioraffd3212013-07-16 09:54:35 +02003076 if (changed & IEEE80211_CONF_CHANGE_PS)
3077 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003078
3079 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003080 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3081 ret = ath10k_monitor_recalc(ar);
3082 if (ret)
3083 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003084 }
3085
3086 mutex_unlock(&ar->conf_mutex);
3087 return ret;
3088}
3089
Ben Greear5572a952014-11-24 16:22:10 +02003090static u32 get_nss_from_chainmask(u16 chain_mask)
3091{
3092 if ((chain_mask & 0x15) == 0x15)
3093 return 4;
3094 else if ((chain_mask & 0x7) == 0x7)
3095 return 3;
3096 else if ((chain_mask & 0x3) == 0x3)
3097 return 2;
3098 return 1;
3099}
3100
Kalle Valo5e3dd152013-06-12 20:52:10 +03003101/*
3102 * TODO:
3103 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3104 * because we will send mgmt frames without CCK. This requirement
3105 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3106 * in the TX packet.
3107 */
3108static int ath10k_add_interface(struct ieee80211_hw *hw,
3109 struct ieee80211_vif *vif)
3110{
3111 struct ath10k *ar = hw->priv;
3112 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3113 enum wmi_sta_powersave_param param;
3114 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003115 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003117 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003118
3119 mutex_lock(&ar->conf_mutex);
3120
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003121 memset(arvif, 0, sizeof(*arvif));
3122
Kalle Valo5e3dd152013-06-12 20:52:10 +03003123 arvif->ar = ar;
3124 arvif->vif = vif;
3125
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003126 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07003127 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003128
Ben Greeara9aefb32014-08-12 11:02:19 +03003129 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003130 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003131 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003132 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003133 }
Ben Greear16c11172014-09-23 14:17:16 -07003134 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003135
Ben Greear16c11172014-09-23 14:17:16 -07003136 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3137 bit, ar->free_vdev_map);
3138
3139 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003140 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003141
Kalle Valo5e3dd152013-06-12 20:52:10 +03003142 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003143 case NL80211_IFTYPE_P2P_DEVICE:
3144 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3145 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3146 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003147 case NL80211_IFTYPE_UNSPECIFIED:
3148 case NL80211_IFTYPE_STATION:
3149 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3150 if (vif->p2p)
3151 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3152 break;
3153 case NL80211_IFTYPE_ADHOC:
3154 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3155 break;
3156 case NL80211_IFTYPE_AP:
3157 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3158
3159 if (vif->p2p)
3160 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3161 break;
3162 case NL80211_IFTYPE_MONITOR:
3163 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3164 break;
3165 default:
3166 WARN_ON(1);
3167 break;
3168 }
3169
Michal Kazior64badcb2014-09-18 11:18:02 +03003170 /* Some firmware revisions don't wait for beacon tx completion before
3171 * sending another SWBA event. This could lead to hardware using old
3172 * (freed) beacon data in some cases, e.g. tx credit starvation
3173 * combined with missed TBTT. This is very very rare.
3174 *
3175 * On non-IOMMU-enabled hosts this could be a possible security issue
3176 * because hw could beacon some random data on the air. On
3177 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3178 * device would crash.
3179 *
3180 * Since there are no beacon tx completions (implicit nor explicit)
3181 * propagated to host the only workaround for this is to allocate a
3182 * DMA-coherent buffer for a lifetime of a vif and use it for all
3183 * beacon tx commands. Worst case for this approach is some beacons may
3184 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3185 */
3186 if (vif->type == NL80211_IFTYPE_ADHOC ||
3187 vif->type == NL80211_IFTYPE_AP) {
3188 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3189 IEEE80211_MAX_FRAME_LEN,
3190 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303191 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003192 if (!arvif->beacon_buf) {
3193 ret = -ENOMEM;
3194 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3195 ret);
3196 goto err;
3197 }
3198 }
3199
3200 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3201 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3202 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003203
3204 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3205 arvif->vdev_subtype, vif->addr);
3206 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003207 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003208 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003209 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210 }
3211
Ben Greear16c11172014-09-23 14:17:16 -07003212 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003213 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003214
Michal Kazior46725b152015-01-28 09:57:49 +02003215 /* It makes no sense to have firmware do keepalives. mac80211 already
3216 * takes care of this with idle connection polling.
3217 */
3218 ret = ath10k_mac_vif_disable_keepalive(arvif);
3219 if (ret) {
3220 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
3221 arvif->vdev_id, ret);
3222 goto err_vdev_delete;
3223 }
3224
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003225 vdev_param = ar->wmi.vdev_param->def_keyid;
3226 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003227 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003228 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003229 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003230 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003231 goto err_vdev_delete;
3232 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003234 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3235 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003237 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003238 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003239 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003240 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003241 goto err_vdev_delete;
3242 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003243
Ben Greear5572a952014-11-24 16:22:10 +02003244 if (ar->cfg_tx_chainmask) {
3245 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3246
3247 vdev_param = ar->wmi.vdev_param->nss;
3248 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3249 nss);
3250 if (ret) {
3251 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3252 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3253 ret);
3254 goto err_vdev_delete;
3255 }
3256 }
3257
Kalle Valo5e3dd152013-06-12 20:52:10 +03003258 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3259 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3260 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003261 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003262 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003263 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003265
Kalle Valo5a13e762014-01-20 11:01:46 +02003266 ret = ath10k_mac_set_kickout(arvif);
3267 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003268 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003269 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003270 goto err_peer_delete;
3271 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272 }
3273
3274 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3275 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3276 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3277 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3278 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003279 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003280 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003281 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003282 goto err_peer_delete;
3283 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003284
Michal Kazior9f9b5742014-12-12 12:41:36 +01003285 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003286 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003287 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003288 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003289 goto err_peer_delete;
3290 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003291
Michal Kazior9f9b5742014-12-12 12:41:36 +01003292 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003293 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003294 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003295 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003296 goto err_peer_delete;
3297 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003298 }
3299
Michal Kazior424121c2013-07-22 14:13:31 +02003300 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003301 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003302 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003303 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003304 goto err_peer_delete;
3305 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003306
Michal Kazior424121c2013-07-22 14:13:31 +02003307 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003308 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003309 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003310 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003311 goto err_peer_delete;
3312 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003313
Michal Kazior7d9d5582014-10-21 10:40:15 +03003314 arvif->txpower = vif->bss_conf.txpower;
3315 ret = ath10k_mac_txpower_recalc(ar);
3316 if (ret) {
3317 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3318 goto err_peer_delete;
3319 }
3320
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003322 return 0;
3323
3324err_peer_delete:
3325 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3326 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3327
3328err_vdev_delete:
3329 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003330 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003331 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003332
3333err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003334 if (arvif->beacon_buf) {
3335 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3336 arvif->beacon_buf, arvif->beacon_paddr);
3337 arvif->beacon_buf = NULL;
3338 }
3339
Michal Kazior9dad14a2013-10-16 15:44:45 +03003340 mutex_unlock(&ar->conf_mutex);
3341
Kalle Valo5e3dd152013-06-12 20:52:10 +03003342 return ret;
3343}
3344
3345static void ath10k_remove_interface(struct ieee80211_hw *hw,
3346 struct ieee80211_vif *vif)
3347{
3348 struct ath10k *ar = hw->priv;
3349 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3350 int ret;
3351
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003352 cancel_work_sync(&arvif->wep_key_work);
3353
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303354 mutex_lock(&ar->conf_mutex);
3355
Michal Kaziored543882013-09-13 14:16:56 +02003356 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003357 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003358 spin_unlock_bh(&ar->data_lock);
3359
Simon Wunderlich855aed12014-08-02 09:12:54 +03003360 ret = ath10k_spectral_vif_stop(arvif);
3361 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003362 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003363 arvif->vdev_id, ret);
3364
Ben Greear16c11172014-09-23 14:17:16 -07003365 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003366 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003367
3368 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3369 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3370 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003371 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003372 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003373
3374 kfree(arvif->u.ap.noa_data);
3375 }
3376
Michal Kazior7aa7a722014-08-25 12:09:38 +02003377 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003378 arvif->vdev_id);
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3381 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003382 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003383 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003384
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 ath10k_peer_cleanup(ar, arvif->vdev_id);
3386
3387 mutex_unlock(&ar->conf_mutex);
3388}
3389
3390/*
3391 * FIXME: Has to be verified.
3392 */
3393#define SUPPORTED_FILTERS \
3394 (FIF_PROMISC_IN_BSS | \
3395 FIF_ALLMULTI | \
3396 FIF_CONTROL | \
3397 FIF_PSPOLL | \
3398 FIF_OTHER_BSS | \
3399 FIF_BCN_PRBRESP_PROMISC | \
3400 FIF_PROBE_REQ | \
3401 FIF_FCSFAIL)
3402
3403static void ath10k_configure_filter(struct ieee80211_hw *hw,
3404 unsigned int changed_flags,
3405 unsigned int *total_flags,
3406 u64 multicast)
3407{
3408 struct ath10k *ar = hw->priv;
3409 int ret;
3410
3411 mutex_lock(&ar->conf_mutex);
3412
3413 changed_flags &= SUPPORTED_FILTERS;
3414 *total_flags &= SUPPORTED_FILTERS;
3415 ar->filter_flags = *total_flags;
3416
Michal Kazior19337472014-08-28 12:58:16 +02003417 ret = ath10k_monitor_recalc(ar);
3418 if (ret)
3419 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003420
3421 mutex_unlock(&ar->conf_mutex);
3422}
3423
3424static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3425 struct ieee80211_vif *vif,
3426 struct ieee80211_bss_conf *info,
3427 u32 changed)
3428{
3429 struct ath10k *ar = hw->priv;
3430 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3431 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003432 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003433
3434 mutex_lock(&ar->conf_mutex);
3435
3436 if (changed & BSS_CHANGED_IBSS)
3437 ath10k_control_ibss(arvif, info, vif->addr);
3438
3439 if (changed & BSS_CHANGED_BEACON_INT) {
3440 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003441 vdev_param = ar->wmi.vdev_param->beacon_interval;
3442 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003443 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003444 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003445 "mac vdev %d beacon_interval %d\n",
3446 arvif->vdev_id, arvif->beacon_interval);
3447
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003449 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003450 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003451 }
3452
3453 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003454 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003455 "vdev %d set beacon tx mode to staggered\n",
3456 arvif->vdev_id);
3457
Bartosz Markowski226a3392013-09-26 17:47:16 +02003458 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3459 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003460 WMI_BEACON_STAGGERED_MODE);
3461 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003462 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003463 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02003464
3465 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3466 if (ret)
3467 ath10k_warn(ar, "failed to update beacon template: %d\n",
3468 ret);
3469 }
3470
3471 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3472 ret = ath10k_mac_setup_prb_tmpl(arvif);
3473 if (ret)
3474 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3475 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476 }
3477
Michal Kaziorba2479f2015-01-24 12:14:51 +02003478 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479 arvif->dtim_period = info->dtim_period;
3480
Michal Kazior7aa7a722014-08-25 12:09:38 +02003481 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003482 "mac vdev %d dtim_period %d\n",
3483 arvif->vdev_id, arvif->dtim_period);
3484
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003485 vdev_param = ar->wmi.vdev_param->dtim_period;
3486 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003487 arvif->dtim_period);
3488 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003489 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003490 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003491 }
3492
3493 if (changed & BSS_CHANGED_SSID &&
3494 vif->type == NL80211_IFTYPE_AP) {
3495 arvif->u.ap.ssid_len = info->ssid_len;
3496 if (info->ssid_len)
3497 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3498 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3499 }
3500
Michal Kazior077efc82014-10-21 10:10:29 +03003501 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3502 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503
3504 if (changed & BSS_CHANGED_BEACON_ENABLED)
3505 ath10k_control_beaconing(arvif, info);
3506
3507 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003508 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003509 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003510 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003511
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003512 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003514 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003515 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516 }
3517
3518 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003519 if (info->use_short_slot)
3520 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3521
3522 else
3523 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3524
Michal Kazior7aa7a722014-08-25 12:09:38 +02003525 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003526 arvif->vdev_id, slottime);
3527
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003528 vdev_param = ar->wmi.vdev_param->slot_time;
3529 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003530 slottime);
3531 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003532 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003533 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003534 }
3535
3536 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003537 if (info->use_short_preamble)
3538 preamble = WMI_VDEV_PREAMBLE_SHORT;
3539 else
3540 preamble = WMI_VDEV_PREAMBLE_LONG;
3541
Michal Kazior7aa7a722014-08-25 12:09:38 +02003542 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003543 "mac vdev %d preamble %dn",
3544 arvif->vdev_id, preamble);
3545
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003546 vdev_param = ar->wmi.vdev_param->preamble;
3547 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003548 preamble);
3549 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003550 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003551 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003552 }
3553
3554 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003555 if (info->assoc) {
3556 /* Workaround: Make sure monitor vdev is not running
3557 * when associating to prevent some firmware revisions
3558 * (e.g. 10.1 and 10.2) from crashing.
3559 */
3560 if (ar->monitor_started)
3561 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003563 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003564 } else {
3565 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003566 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567 }
3568
Michal Kazior7d9d5582014-10-21 10:40:15 +03003569 if (changed & BSS_CHANGED_TXPOWER) {
3570 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3571 arvif->vdev_id, info->txpower);
3572
3573 arvif->txpower = info->txpower;
3574 ret = ath10k_mac_txpower_recalc(ar);
3575 if (ret)
3576 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3577 }
3578
Michal Kaziorbf14e652014-12-12 12:41:38 +01003579 if (changed & BSS_CHANGED_PS) {
3580 ret = ath10k_mac_vif_setup_ps(arvif);
3581 if (ret)
3582 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3583 arvif->vdev_id, ret);
3584 }
3585
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 mutex_unlock(&ar->conf_mutex);
3587}
3588
3589static int ath10k_hw_scan(struct ieee80211_hw *hw,
3590 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003591 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592{
3593 struct ath10k *ar = hw->priv;
3594 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003595 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003596 struct wmi_start_scan_arg arg;
3597 int ret = 0;
3598 int i;
3599
3600 mutex_lock(&ar->conf_mutex);
3601
3602 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003603 switch (ar->scan.state) {
3604 case ATH10K_SCAN_IDLE:
3605 reinit_completion(&ar->scan.started);
3606 reinit_completion(&ar->scan.completed);
3607 ar->scan.state = ATH10K_SCAN_STARTING;
3608 ar->scan.is_roc = false;
3609 ar->scan.vdev_id = arvif->vdev_id;
3610 ret = 0;
3611 break;
3612 case ATH10K_SCAN_STARTING:
3613 case ATH10K_SCAN_RUNNING:
3614 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003615 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003616 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618 spin_unlock_bh(&ar->data_lock);
3619
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003620 if (ret)
3621 goto exit;
3622
Kalle Valo5e3dd152013-06-12 20:52:10 +03003623 memset(&arg, 0, sizeof(arg));
3624 ath10k_wmi_start_scan_init(ar, &arg);
3625 arg.vdev_id = arvif->vdev_id;
3626 arg.scan_id = ATH10K_SCAN_ID;
3627
3628 if (!req->no_cck)
3629 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3630
3631 if (req->ie_len) {
3632 arg.ie_len = req->ie_len;
3633 memcpy(arg.ie, req->ie, arg.ie_len);
3634 }
3635
3636 if (req->n_ssids) {
3637 arg.n_ssids = req->n_ssids;
3638 for (i = 0; i < arg.n_ssids; i++) {
3639 arg.ssids[i].len = req->ssids[i].ssid_len;
3640 arg.ssids[i].ssid = req->ssids[i].ssid;
3641 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003642 } else {
3643 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003644 }
3645
3646 if (req->n_channels) {
3647 arg.n_channels = req->n_channels;
3648 for (i = 0; i < arg.n_channels; i++)
3649 arg.channels[i] = req->channels[i]->center_freq;
3650 }
3651
3652 ret = ath10k_start_scan(ar, &arg);
3653 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003654 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003656 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003657 spin_unlock_bh(&ar->data_lock);
3658 }
3659
3660exit:
3661 mutex_unlock(&ar->conf_mutex);
3662 return ret;
3663}
3664
3665static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3666 struct ieee80211_vif *vif)
3667{
3668 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669
3670 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003671 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003672 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01003673
3674 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003675}
3676
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003677static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3678 struct ath10k_vif *arvif,
3679 enum set_key_cmd cmd,
3680 struct ieee80211_key_conf *key)
3681{
3682 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3683 int ret;
3684
3685 /* 10.1 firmware branch requires default key index to be set to group
3686 * key index after installing it. Otherwise FW/HW Txes corrupted
3687 * frames with multi-vif APs. This is not required for main firmware
3688 * branch (e.g. 636).
3689 *
3690 * FIXME: This has been tested only in AP. It remains unknown if this
3691 * is required for multi-vif STA interfaces on 10.1 */
3692
3693 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3694 return;
3695
3696 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3697 return;
3698
3699 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3700 return;
3701
3702 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3703 return;
3704
3705 if (cmd != SET_KEY)
3706 return;
3707
3708 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3709 key->keyidx);
3710 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003711 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003712 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003713}
3714
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3716 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3717 struct ieee80211_key_conf *key)
3718{
3719 struct ath10k *ar = hw->priv;
3720 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3721 struct ath10k_peer *peer;
3722 const u8 *peer_addr;
3723 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3724 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3725 int ret = 0;
3726
3727 if (key->keyidx > WMI_MAX_KEY_INDEX)
3728 return -ENOSPC;
3729
3730 mutex_lock(&ar->conf_mutex);
3731
3732 if (sta)
3733 peer_addr = sta->addr;
3734 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3735 peer_addr = vif->bss_conf.bssid;
3736 else
3737 peer_addr = vif->addr;
3738
3739 key->hw_key_idx = key->keyidx;
3740
3741 /* the peer should not disappear in mid-way (unless FW goes awry) since
3742 * we already hold conf_mutex. we just make sure its there now. */
3743 spin_lock_bh(&ar->data_lock);
3744 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3745 spin_unlock_bh(&ar->data_lock);
3746
3747 if (!peer) {
3748 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003749 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003750 peer_addr);
3751 ret = -EOPNOTSUPP;
3752 goto exit;
3753 } else {
3754 /* if the peer doesn't exist there is no key to disable
3755 * anymore */
3756 goto exit;
3757 }
3758 }
3759
3760 if (is_wep) {
3761 if (cmd == SET_KEY)
3762 arvif->wep_keys[key->keyidx] = key;
3763 else
3764 arvif->wep_keys[key->keyidx] = NULL;
3765
3766 if (cmd == DISABLE_KEY)
3767 ath10k_clear_vdev_key(arvif, key);
3768 }
3769
3770 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003772 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003773 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003774 goto exit;
3775 }
3776
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003777 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3778
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779 spin_lock_bh(&ar->data_lock);
3780 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3781 if (peer && cmd == SET_KEY)
3782 peer->keys[key->keyidx] = key;
3783 else if (peer && cmd == DISABLE_KEY)
3784 peer->keys[key->keyidx] = NULL;
3785 else if (peer == NULL)
3786 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003787 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788 spin_unlock_bh(&ar->data_lock);
3789
3790exit:
3791 mutex_unlock(&ar->conf_mutex);
3792 return ret;
3793}
3794
Michal Kazior9797feb2014-02-14 14:49:48 +01003795static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3796{
3797 struct ath10k *ar;
3798 struct ath10k_vif *arvif;
3799 struct ath10k_sta *arsta;
3800 struct ieee80211_sta *sta;
3801 u32 changed, bw, nss, smps;
3802 int err;
3803
3804 arsta = container_of(wk, struct ath10k_sta, update_wk);
3805 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3806 arvif = arsta->arvif;
3807 ar = arvif->ar;
3808
3809 spin_lock_bh(&ar->data_lock);
3810
3811 changed = arsta->changed;
3812 arsta->changed = 0;
3813
3814 bw = arsta->bw;
3815 nss = arsta->nss;
3816 smps = arsta->smps;
3817
3818 spin_unlock_bh(&ar->data_lock);
3819
3820 mutex_lock(&ar->conf_mutex);
3821
3822 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003824 sta->addr, bw);
3825
3826 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3827 WMI_PEER_CHAN_WIDTH, bw);
3828 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003829 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003830 sta->addr, bw, err);
3831 }
3832
3833 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003834 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003835 sta->addr, nss);
3836
3837 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3838 WMI_PEER_NSS, nss);
3839 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003840 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003841 sta->addr, nss, err);
3842 }
3843
3844 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003845 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003846 sta->addr, smps);
3847
3848 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3849 WMI_PEER_SMPS_STATE, smps);
3850 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003851 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003852 sta->addr, smps, err);
3853 }
3854
Janusz Dziedzic55884c02014-12-17 12:30:02 +02003855 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3856 changed & IEEE80211_RC_NSS_CHANGED) {
3857 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003858 sta->addr);
3859
Michal Kazior590922a2014-10-21 10:10:29 +03003860 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003861 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003862 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003863 sta->addr);
3864 }
3865
Michal Kazior9797feb2014-02-14 14:49:48 +01003866 mutex_unlock(&ar->conf_mutex);
3867}
3868
Michal Kaziorcfd10612014-11-25 15:16:05 +01003869static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3870{
3871 struct ath10k *ar = arvif->ar;
3872
3873 lockdep_assert_held(&ar->conf_mutex);
3874
3875 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3876 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3877 return 0;
3878
3879 if (ar->num_stations >= ar->max_num_stations)
3880 return -ENOBUFS;
3881
3882 ar->num_stations++;
3883
3884 return 0;
3885}
3886
3887static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3888{
3889 struct ath10k *ar = arvif->ar;
3890
3891 lockdep_assert_held(&ar->conf_mutex);
3892
3893 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3894 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3895 return;
3896
3897 ar->num_stations--;
3898}
3899
Kalle Valo5e3dd152013-06-12 20:52:10 +03003900static int ath10k_sta_state(struct ieee80211_hw *hw,
3901 struct ieee80211_vif *vif,
3902 struct ieee80211_sta *sta,
3903 enum ieee80211_sta_state old_state,
3904 enum ieee80211_sta_state new_state)
3905{
3906 struct ath10k *ar = hw->priv;
3907 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003908 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909 int ret = 0;
3910
Michal Kazior76f90022014-02-25 09:29:57 +02003911 if (old_state == IEEE80211_STA_NOTEXIST &&
3912 new_state == IEEE80211_STA_NONE) {
3913 memset(arsta, 0, sizeof(*arsta));
3914 arsta->arvif = arvif;
3915 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3916 }
3917
Michal Kazior9797feb2014-02-14 14:49:48 +01003918 /* cancel must be done outside the mutex to avoid deadlock */
3919 if ((old_state == IEEE80211_STA_NONE &&
3920 new_state == IEEE80211_STA_NOTEXIST))
3921 cancel_work_sync(&arsta->update_wk);
3922
Kalle Valo5e3dd152013-06-12 20:52:10 +03003923 mutex_lock(&ar->conf_mutex);
3924
3925 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003926 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927 /*
3928 * New station addition.
3929 */
Michal Kaziorcfd10612014-11-25 15:16:05 +01003930 ath10k_dbg(ar, ATH10K_DBG_MAC,
3931 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3932 arvif->vdev_id, sta->addr,
3933 ar->num_stations + 1, ar->max_num_stations,
3934 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003935
Michal Kaziorcfd10612014-11-25 15:16:05 +01003936 ret = ath10k_mac_inc_num_stations(arvif);
3937 if (ret) {
3938 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3939 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003940 goto exit;
3941 }
3942
Kalle Valo5e3dd152013-06-12 20:52:10 +03003943 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
Michal Kaziora52c0282014-11-25 15:16:03 +01003944 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003945 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 -08003946 sta->addr, arvif->vdev_id, ret);
Michal Kaziorcfd10612014-11-25 15:16:05 +01003947 ath10k_mac_dec_num_stations(arvif);
Michal Kaziora52c0282014-11-25 15:16:03 +01003948 goto exit;
3949 }
Michal Kazior077efc82014-10-21 10:10:29 +03003950
3951 if (vif->type == NL80211_IFTYPE_STATION) {
3952 WARN_ON(arvif->is_started);
3953
3954 ret = ath10k_vdev_start(arvif);
3955 if (ret) {
3956 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3957 arvif->vdev_id, ret);
3958 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3959 sta->addr));
Michal Kaziorcfd10612014-11-25 15:16:05 +01003960 ath10k_mac_dec_num_stations(arvif);
Michal Kazior077efc82014-10-21 10:10:29 +03003961 goto exit;
3962 }
3963
3964 arvif->is_started = true;
3965 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003966 } else if ((old_state == IEEE80211_STA_NONE &&
3967 new_state == IEEE80211_STA_NOTEXIST)) {
3968 /*
3969 * Existing station deletion.
3970 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003971 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003972 "mac vdev %d peer delete %pM (sta gone)\n",
3973 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003974
3975 if (vif->type == NL80211_IFTYPE_STATION) {
3976 WARN_ON(!arvif->is_started);
3977
3978 ret = ath10k_vdev_stop(arvif);
3979 if (ret)
3980 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3981 arvif->vdev_id, ret);
3982
3983 arvif->is_started = false;
3984 }
3985
Kalle Valo5e3dd152013-06-12 20:52:10 +03003986 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3987 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003988 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003989 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003990
Michal Kaziorcfd10612014-11-25 15:16:05 +01003991 ath10k_mac_dec_num_stations(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003992 } else if (old_state == IEEE80211_STA_AUTH &&
3993 new_state == IEEE80211_STA_ASSOC &&
3994 (vif->type == NL80211_IFTYPE_AP ||
3995 vif->type == NL80211_IFTYPE_ADHOC)) {
3996 /*
3997 * New association.
3998 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003999 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004000 sta->addr);
4001
Michal Kazior590922a2014-10-21 10:10:29 +03004002 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004003 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004004 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004005 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004006 } else if (old_state == IEEE80211_STA_ASSOC &&
4007 new_state == IEEE80211_STA_AUTH &&
4008 (vif->type == NL80211_IFTYPE_AP ||
4009 vif->type == NL80211_IFTYPE_ADHOC)) {
4010 /*
4011 * Disassociation.
4012 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004013 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004014 sta->addr);
4015
Michal Kazior590922a2014-10-21 10:10:29 +03004016 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004018 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004019 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004020 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004021exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022 mutex_unlock(&ar->conf_mutex);
4023 return ret;
4024}
4025
4026static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004027 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028{
4029 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004030 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4031 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004032 u32 value = 0;
4033 int ret = 0;
4034
Michal Kazior548db542013-07-05 16:15:15 +03004035 lockdep_assert_held(&ar->conf_mutex);
4036
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4038 return 0;
4039
4040 switch (ac) {
4041 case IEEE80211_AC_VO:
4042 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4043 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004044 prio = 7;
4045 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004046 break;
4047 case IEEE80211_AC_VI:
4048 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4049 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004050 prio = 5;
4051 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004052 break;
4053 case IEEE80211_AC_BE:
4054 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4055 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004056 prio = 2;
4057 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004058 break;
4059 case IEEE80211_AC_BK:
4060 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4061 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004062 prio = 0;
4063 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004064 break;
4065 }
4066
4067 if (enable)
4068 arvif->u.sta.uapsd |= value;
4069 else
4070 arvif->u.sta.uapsd &= ~value;
4071
4072 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4073 WMI_STA_PS_PARAM_UAPSD,
4074 arvif->u.sta.uapsd);
4075 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004076 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004077 goto exit;
4078 }
4079
4080 if (arvif->u.sta.uapsd)
4081 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4082 else
4083 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4084
4085 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4086 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4087 value);
4088 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004089 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004090
Michal Kazior9f9b5742014-12-12 12:41:36 +01004091 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4092 if (ret) {
4093 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4094 arvif->vdev_id, ret);
4095 return ret;
4096 }
4097
4098 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4099 if (ret) {
4100 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4101 arvif->vdev_id, ret);
4102 return ret;
4103 }
4104
Michal Kaziorb0e56152015-01-24 12:14:52 +02004105 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4106 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4107 /* Only userspace can make an educated decision when to send
4108 * trigger frame. The following effectively disables u-UAPSD
4109 * autotrigger in firmware (which is enabled by default
4110 * provided the autotrigger service is available).
4111 */
4112
4113 arg.wmm_ac = acc;
4114 arg.user_priority = prio;
4115 arg.service_interval = 0;
4116 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4117 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4118
4119 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4120 arvif->bssid, &arg, 1);
4121 if (ret) {
4122 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4123 ret);
4124 return ret;
4125 }
4126 }
4127
Kalle Valo5e3dd152013-06-12 20:52:10 +03004128exit:
4129 return ret;
4130}
4131
4132static int ath10k_conf_tx(struct ieee80211_hw *hw,
4133 struct ieee80211_vif *vif, u16 ac,
4134 const struct ieee80211_tx_queue_params *params)
4135{
4136 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004137 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004138 struct wmi_wmm_params_arg *p = NULL;
4139 int ret;
4140
4141 mutex_lock(&ar->conf_mutex);
4142
4143 switch (ac) {
4144 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004145 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004146 break;
4147 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004148 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004149 break;
4150 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004151 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004152 break;
4153 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004154 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004155 break;
4156 }
4157
4158 if (WARN_ON(!p)) {
4159 ret = -EINVAL;
4160 goto exit;
4161 }
4162
4163 p->cwmin = params->cw_min;
4164 p->cwmax = params->cw_max;
4165 p->aifs = params->aifs;
4166
4167 /*
4168 * The channel time duration programmed in the HW is in absolute
4169 * microseconds, while mac80211 gives the txop in units of
4170 * 32 microseconds.
4171 */
4172 p->txop = params->txop * 32;
4173
Michal Kazior7fc979a2015-01-28 09:57:28 +02004174 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4175 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4176 &arvif->wmm_params);
4177 if (ret) {
4178 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4179 arvif->vdev_id, ret);
4180 goto exit;
4181 }
4182 } else {
4183 /* This won't work well with multi-interface cases but it's
4184 * better than nothing.
4185 */
4186 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4187 if (ret) {
4188 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4189 goto exit;
4190 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004191 }
4192
4193 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4194 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004195 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004196
4197exit:
4198 mutex_unlock(&ar->conf_mutex);
4199 return ret;
4200}
4201
4202#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4203
4204static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4205 struct ieee80211_vif *vif,
4206 struct ieee80211_channel *chan,
4207 int duration,
4208 enum ieee80211_roc_type type)
4209{
4210 struct ath10k *ar = hw->priv;
4211 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4212 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004213 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004214
4215 mutex_lock(&ar->conf_mutex);
4216
4217 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004218 switch (ar->scan.state) {
4219 case ATH10K_SCAN_IDLE:
4220 reinit_completion(&ar->scan.started);
4221 reinit_completion(&ar->scan.completed);
4222 reinit_completion(&ar->scan.on_channel);
4223 ar->scan.state = ATH10K_SCAN_STARTING;
4224 ar->scan.is_roc = true;
4225 ar->scan.vdev_id = arvif->vdev_id;
4226 ar->scan.roc_freq = chan->center_freq;
4227 ret = 0;
4228 break;
4229 case ATH10K_SCAN_STARTING:
4230 case ATH10K_SCAN_RUNNING:
4231 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004232 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004233 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004234 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004235 spin_unlock_bh(&ar->data_lock);
4236
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004237 if (ret)
4238 goto exit;
4239
Michal Kaziordcca0bd2014-11-24 14:58:32 +01004240 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4241
Kalle Valo5e3dd152013-06-12 20:52:10 +03004242 memset(&arg, 0, sizeof(arg));
4243 ath10k_wmi_start_scan_init(ar, &arg);
4244 arg.vdev_id = arvif->vdev_id;
4245 arg.scan_id = ATH10K_SCAN_ID;
4246 arg.n_channels = 1;
4247 arg.channels[0] = chan->center_freq;
4248 arg.dwell_time_active = duration;
4249 arg.dwell_time_passive = duration;
4250 arg.max_scan_time = 2 * duration;
4251 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4252 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4253
4254 ret = ath10k_start_scan(ar, &arg);
4255 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004256 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004257 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004258 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004259 spin_unlock_bh(&ar->data_lock);
4260 goto exit;
4261 }
4262
4263 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4264 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004265 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004266
4267 ret = ath10k_scan_stop(ar);
4268 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004269 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004270
Kalle Valo5e3dd152013-06-12 20:52:10 +03004271 ret = -ETIMEDOUT;
4272 goto exit;
4273 }
4274
4275 ret = 0;
4276exit:
4277 mutex_unlock(&ar->conf_mutex);
4278 return ret;
4279}
4280
4281static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4282{
4283 struct ath10k *ar = hw->priv;
4284
4285 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004286 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004287 mutex_unlock(&ar->conf_mutex);
4288
Michal Kazior4eb2e162014-10-28 10:23:09 +01004289 cancel_delayed_work_sync(&ar->scan.timeout);
4290
Kalle Valo5e3dd152013-06-12 20:52:10 +03004291 return 0;
4292}
4293
4294/*
4295 * Both RTS and Fragmentation threshold are interface-specific
4296 * in ath10k, but device-specific in mac80211.
4297 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03004298
4299static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4300{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004301 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03004302 struct ath10k_vif *arvif;
4303 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03004304
Michal Kaziorad088bf2013-10-16 15:44:46 +03004305 mutex_lock(&ar->conf_mutex);
4306 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004307 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004308 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004309
Michal Kaziorad088bf2013-10-16 15:44:46 +03004310 ret = ath10k_mac_set_rts(arvif, value);
4311 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004312 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03004313 arvif->vdev_id, ret);
4314 break;
4315 }
4316 }
4317 mutex_unlock(&ar->conf_mutex);
4318
4319 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320}
4321
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02004322static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4323 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004324{
4325 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02004326 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004327 int ret;
4328
4329 /* mac80211 doesn't care if we really xmit queued frames or not
4330 * we'll collect those frames either way if we stop/delete vdevs */
4331 if (drop)
4332 return;
4333
Michal Kazior548db542013-07-05 16:15:15 +03004334 mutex_lock(&ar->conf_mutex);
4335
Michal Kazioraffd3212013-07-16 09:54:35 +02004336 if (ar->state == ATH10K_STATE_WEDGED)
4337 goto skip;
4338
Michal Kazioredb82362013-07-05 16:15:14 +03004339 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03004340 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02004341
Michal Kazioredb82362013-07-05 16:15:14 +03004342 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02004343 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03004344 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02004345
Michal Kazior7962b0d2014-10-28 10:34:38 +01004346 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4347 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4348 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02004349
4350 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004351 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02004352
4353 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004354 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02004355 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03004356
Michal Kazioraffd3212013-07-16 09:54:35 +02004357skip:
Michal Kazior548db542013-07-05 16:15:15 +03004358 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004359}
4360
4361/* TODO: Implement this function properly
4362 * For now it is needed to reply to Probe Requests in IBSS mode.
4363 * Propably we need this information from FW.
4364 */
4365static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4366{
4367 return 1;
4368}
4369
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004370#ifdef CONFIG_PM
4371static int ath10k_suspend(struct ieee80211_hw *hw,
4372 struct cfg80211_wowlan *wowlan)
4373{
4374 struct ath10k *ar = hw->priv;
4375 int ret;
4376
Marek Puzyniak9042e172014-02-10 17:14:23 +01004377 mutex_lock(&ar->conf_mutex);
4378
Marek Puzyniak00f54822014-02-10 17:14:24 +01004379 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004380 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01004381 if (ret == -ETIMEDOUT)
4382 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01004383 ret = 1;
4384 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004385 }
4386
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004387 ret = ath10k_hif_suspend(ar);
4388 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004389 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004390 goto resume;
4391 }
4392
Marek Puzyniak9042e172014-02-10 17:14:23 +01004393 ret = 0;
4394 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004395resume:
4396 ret = ath10k_wmi_pdev_resume_target(ar);
4397 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004398 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004399
4400 ret = 1;
4401exit:
4402 mutex_unlock(&ar->conf_mutex);
4403 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004404}
4405
4406static int ath10k_resume(struct ieee80211_hw *hw)
4407{
4408 struct ath10k *ar = hw->priv;
4409 int ret;
4410
Marek Puzyniak9042e172014-02-10 17:14:23 +01004411 mutex_lock(&ar->conf_mutex);
4412
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004413 ret = ath10k_hif_resume(ar);
4414 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004415 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004416 ret = 1;
4417 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004418 }
4419
4420 ret = ath10k_wmi_pdev_resume_target(ar);
4421 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004422 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01004423 ret = 1;
4424 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004425 }
4426
Marek Puzyniak9042e172014-02-10 17:14:23 +01004427 ret = 0;
4428exit:
4429 mutex_unlock(&ar->conf_mutex);
4430 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004431}
4432#endif
4433
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004434static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4435 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02004436{
4437 struct ath10k *ar = hw->priv;
4438
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004439 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4440 return;
4441
Michal Kazioraffd3212013-07-16 09:54:35 +02004442 mutex_lock(&ar->conf_mutex);
4443
4444 /* If device failed to restart it will be in a different state, e.g.
4445 * ATH10K_STATE_WEDGED */
4446 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004447 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02004448 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01004449 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02004450 }
4451
4452 mutex_unlock(&ar->conf_mutex);
4453}
4454
Michal Kazior2e1dea42013-07-31 10:32:40 +02004455static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4456 struct survey_info *survey)
4457{
4458 struct ath10k *ar = hw->priv;
4459 struct ieee80211_supported_band *sband;
4460 struct survey_info *ar_survey = &ar->survey[idx];
4461 int ret = 0;
4462
4463 mutex_lock(&ar->conf_mutex);
4464
4465 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4466 if (sband && idx >= sband->n_channels) {
4467 idx -= sband->n_channels;
4468 sband = NULL;
4469 }
4470
4471 if (!sband)
4472 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4473
4474 if (!sband || idx >= sband->n_channels) {
4475 ret = -ENOENT;
4476 goto exit;
4477 }
4478
4479 spin_lock_bh(&ar->data_lock);
4480 memcpy(survey, ar_survey, sizeof(*survey));
4481 spin_unlock_bh(&ar->data_lock);
4482
4483 survey->channel = &sband->channels[idx];
4484
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03004485 if (ar->rx_channel == survey->channel)
4486 survey->filled |= SURVEY_INFO_IN_USE;
4487
Michal Kazior2e1dea42013-07-31 10:32:40 +02004488exit:
4489 mutex_unlock(&ar->conf_mutex);
4490 return ret;
4491}
4492
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004493/* Helper table for legacy fixed_rate/bitrate_mask */
4494static const u8 cck_ofdm_rate[] = {
4495 /* CCK */
4496 3, /* 1Mbps */
4497 2, /* 2Mbps */
4498 1, /* 5.5Mbps */
4499 0, /* 11Mbps */
4500 /* OFDM */
4501 3, /* 6Mbps */
4502 7, /* 9Mbps */
4503 2, /* 12Mbps */
4504 6, /* 18Mbps */
4505 1, /* 24Mbps */
4506 5, /* 36Mbps */
4507 0, /* 48Mbps */
4508 4, /* 54Mbps */
4509};
4510
4511/* Check if only one bit set */
4512static int ath10k_check_single_mask(u32 mask)
4513{
4514 int bit;
4515
4516 bit = ffs(mask);
4517 if (!bit)
4518 return 0;
4519
4520 mask &= ~BIT(bit - 1);
4521 if (mask)
4522 return 2;
4523
4524 return 1;
4525}
4526
4527static bool
4528ath10k_default_bitrate_mask(struct ath10k *ar,
4529 enum ieee80211_band band,
4530 const struct cfg80211_bitrate_mask *mask)
4531{
4532 u32 legacy = 0x00ff;
4533 u8 ht = 0xff, i;
4534 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02004535 u16 nrf = ar->num_rf_chains;
4536
4537 if (ar->cfg_tx_chainmask)
4538 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004539
4540 switch (band) {
4541 case IEEE80211_BAND_2GHZ:
4542 legacy = 0x00fff;
4543 vht = 0;
4544 break;
4545 case IEEE80211_BAND_5GHZ:
4546 break;
4547 default:
4548 return false;
4549 }
4550
4551 if (mask->control[band].legacy != legacy)
4552 return false;
4553
Ben Greearb116ea12014-11-24 16:22:10 +02004554 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004555 if (mask->control[band].ht_mcs[i] != ht)
4556 return false;
4557
Ben Greearb116ea12014-11-24 16:22:10 +02004558 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004559 if (mask->control[band].vht_mcs[i] != vht)
4560 return false;
4561
4562 return true;
4563}
4564
4565static bool
4566ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4567 enum ieee80211_band band,
4568 u8 *fixed_nss)
4569{
4570 int ht_nss = 0, vht_nss = 0, i;
4571
4572 /* check legacy */
4573 if (ath10k_check_single_mask(mask->control[band].legacy))
4574 return false;
4575
4576 /* check HT */
4577 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4578 if (mask->control[band].ht_mcs[i] == 0xff)
4579 continue;
4580 else if (mask->control[band].ht_mcs[i] == 0x00)
4581 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004582
4583 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004584 }
4585
4586 ht_nss = i;
4587
4588 /* check VHT */
4589 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4590 if (mask->control[band].vht_mcs[i] == 0x03ff)
4591 continue;
4592 else if (mask->control[band].vht_mcs[i] == 0x0000)
4593 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004594
4595 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004596 }
4597
4598 vht_nss = i;
4599
4600 if (ht_nss > 0 && vht_nss > 0)
4601 return false;
4602
4603 if (ht_nss)
4604 *fixed_nss = ht_nss;
4605 else if (vht_nss)
4606 *fixed_nss = vht_nss;
4607 else
4608 return false;
4609
4610 return true;
4611}
4612
4613static bool
4614ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4615 enum ieee80211_band band,
4616 enum wmi_rate_preamble *preamble)
4617{
4618 int legacy = 0, ht = 0, vht = 0, i;
4619
4620 *preamble = WMI_RATE_PREAMBLE_OFDM;
4621
4622 /* check legacy */
4623 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4624 if (legacy > 1)
4625 return false;
4626
4627 /* check HT */
4628 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4629 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4630 if (ht > 1)
4631 return false;
4632
4633 /* check VHT */
4634 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4635 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4636 if (vht > 1)
4637 return false;
4638
4639 /* Currently we support only one fixed_rate */
4640 if ((legacy + ht + vht) != 1)
4641 return false;
4642
4643 if (ht)
4644 *preamble = WMI_RATE_PREAMBLE_HT;
4645 else if (vht)
4646 *preamble = WMI_RATE_PREAMBLE_VHT;
4647
4648 return true;
4649}
4650
4651static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004652ath10k_bitrate_mask_rate(struct ath10k *ar,
4653 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004654 enum ieee80211_band band,
4655 u8 *fixed_rate,
4656 u8 *fixed_nss)
4657{
4658 u8 rate = 0, pream = 0, nss = 0, i;
4659 enum wmi_rate_preamble preamble;
4660
4661 /* Check if single rate correct */
4662 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4663 return false;
4664
4665 pream = preamble;
4666
4667 switch (preamble) {
4668 case WMI_RATE_PREAMBLE_CCK:
4669 case WMI_RATE_PREAMBLE_OFDM:
4670 i = ffs(mask->control[band].legacy) - 1;
4671
4672 if (band == IEEE80211_BAND_2GHZ && i < 4)
4673 pream = WMI_RATE_PREAMBLE_CCK;
4674
4675 if (band == IEEE80211_BAND_5GHZ)
4676 i += 4;
4677
4678 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4679 return false;
4680
4681 rate = cck_ofdm_rate[i];
4682 break;
4683 case WMI_RATE_PREAMBLE_HT:
4684 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4685 if (mask->control[band].ht_mcs[i])
4686 break;
4687
4688 if (i == IEEE80211_HT_MCS_MASK_LEN)
4689 return false;
4690
4691 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4692 nss = i;
4693 break;
4694 case WMI_RATE_PREAMBLE_VHT:
4695 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4696 if (mask->control[band].vht_mcs[i])
4697 break;
4698
4699 if (i == NL80211_VHT_NSS_MAX)
4700 return false;
4701
4702 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4703 nss = i;
4704 break;
4705 }
4706
4707 *fixed_nss = nss + 1;
4708 nss <<= 4;
4709 pream <<= 6;
4710
Michal Kazior7aa7a722014-08-25 12:09:38 +02004711 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 +01004712 pream, nss, rate);
4713
4714 *fixed_rate = pream | nss | rate;
4715
4716 return true;
4717}
4718
Michal Kazior7aa7a722014-08-25 12:09:38 +02004719static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4720 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004721 enum ieee80211_band band,
4722 u8 *fixed_rate,
4723 u8 *fixed_nss)
4724{
4725 /* First check full NSS mask, if we can simply limit NSS */
4726 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4727 return true;
4728
4729 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004730 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004731}
4732
4733static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4734 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004735 u8 fixed_nss,
4736 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004737{
4738 struct ath10k *ar = arvif->ar;
4739 u32 vdev_param;
4740 int ret = 0;
4741
4742 mutex_lock(&ar->conf_mutex);
4743
4744 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004745 arvif->fixed_nss == fixed_nss &&
4746 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004747 goto exit;
4748
4749 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004750 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004751
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004752 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004754
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004755 vdev_param = ar->wmi.vdev_param->fixed_rate;
4756 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4757 vdev_param, fixed_rate);
4758 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004759 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004760 fixed_rate, ret);
4761 ret = -EINVAL;
4762 goto exit;
4763 }
4764
4765 arvif->fixed_rate = fixed_rate;
4766
4767 vdev_param = ar->wmi.vdev_param->nss;
4768 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4769 vdev_param, fixed_nss);
4770
4771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004772 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004773 fixed_nss, ret);
4774 ret = -EINVAL;
4775 goto exit;
4776 }
4777
4778 arvif->fixed_nss = fixed_nss;
4779
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004780 vdev_param = ar->wmi.vdev_param->sgi;
4781 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4782 force_sgi);
4783
4784 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004785 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004786 force_sgi, ret);
4787 ret = -EINVAL;
4788 goto exit;
4789 }
4790
4791 arvif->force_sgi = force_sgi;
4792
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004793exit:
4794 mutex_unlock(&ar->conf_mutex);
4795 return ret;
4796}
4797
4798static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4799 struct ieee80211_vif *vif,
4800 const struct cfg80211_bitrate_mask *mask)
4801{
4802 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4803 struct ath10k *ar = arvif->ar;
4804 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4805 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4806 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004807 u8 force_sgi;
4808
Ben Greearb116ea12014-11-24 16:22:10 +02004809 if (ar->cfg_tx_chainmask)
4810 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4811
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004812 force_sgi = mask->control[band].gi;
4813 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4814 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004815
4816 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004817 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004818 &fixed_rate,
4819 &fixed_nss))
4820 return -EINVAL;
4821 }
4822
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004823 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004824 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004825 return -EINVAL;
4826 }
4827
4828 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4829 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004830}
4831
Michal Kazior9797feb2014-02-14 14:49:48 +01004832static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4833 struct ieee80211_vif *vif,
4834 struct ieee80211_sta *sta,
4835 u32 changed)
4836{
4837 struct ath10k *ar = hw->priv;
4838 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4839 u32 bw, smps;
4840
4841 spin_lock_bh(&ar->data_lock);
4842
Michal Kazior7aa7a722014-08-25 12:09:38 +02004843 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004844 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4845 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4846 sta->smps_mode);
4847
4848 if (changed & IEEE80211_RC_BW_CHANGED) {
4849 bw = WMI_PEER_CHWIDTH_20MHZ;
4850
4851 switch (sta->bandwidth) {
4852 case IEEE80211_STA_RX_BW_20:
4853 bw = WMI_PEER_CHWIDTH_20MHZ;
4854 break;
4855 case IEEE80211_STA_RX_BW_40:
4856 bw = WMI_PEER_CHWIDTH_40MHZ;
4857 break;
4858 case IEEE80211_STA_RX_BW_80:
4859 bw = WMI_PEER_CHWIDTH_80MHZ;
4860 break;
4861 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004862 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004863 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004864 bw = WMI_PEER_CHWIDTH_20MHZ;
4865 break;
4866 }
4867
4868 arsta->bw = bw;
4869 }
4870
4871 if (changed & IEEE80211_RC_NSS_CHANGED)
4872 arsta->nss = sta->rx_nss;
4873
4874 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4875 smps = WMI_PEER_SMPS_PS_NONE;
4876
4877 switch (sta->smps_mode) {
4878 case IEEE80211_SMPS_AUTOMATIC:
4879 case IEEE80211_SMPS_OFF:
4880 smps = WMI_PEER_SMPS_PS_NONE;
4881 break;
4882 case IEEE80211_SMPS_STATIC:
4883 smps = WMI_PEER_SMPS_STATIC;
4884 break;
4885 case IEEE80211_SMPS_DYNAMIC:
4886 smps = WMI_PEER_SMPS_DYNAMIC;
4887 break;
4888 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004889 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004890 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004891 smps = WMI_PEER_SMPS_PS_NONE;
4892 break;
4893 }
4894
4895 arsta->smps = smps;
4896 }
4897
Michal Kazior9797feb2014-02-14 14:49:48 +01004898 arsta->changed |= changed;
4899
4900 spin_unlock_bh(&ar->data_lock);
4901
4902 ieee80211_queue_work(hw, &arsta->update_wk);
4903}
4904
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004905static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4906{
4907 /*
4908 * FIXME: Return 0 for time being. Need to figure out whether FW
4909 * has the API to fetch 64-bit local TSF
4910 */
4911
4912 return 0;
4913}
4914
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004915static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4916 struct ieee80211_vif *vif,
4917 enum ieee80211_ampdu_mlme_action action,
4918 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4919 u8 buf_size)
4920{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004921 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004922 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4923
Michal Kazior7aa7a722014-08-25 12:09:38 +02004924 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 +02004925 arvif->vdev_id, sta->addr, tid, action);
4926
4927 switch (action) {
4928 case IEEE80211_AMPDU_RX_START:
4929 case IEEE80211_AMPDU_RX_STOP:
4930 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4931 * creation/removal. Do we need to verify this?
4932 */
4933 return 0;
4934 case IEEE80211_AMPDU_TX_START:
4935 case IEEE80211_AMPDU_TX_STOP_CONT:
4936 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4937 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4938 case IEEE80211_AMPDU_TX_OPERATIONAL:
4939 /* Firmware offloads Tx aggregation entirely so deny mac80211
4940 * Tx aggregation requests.
4941 */
4942 return -EOPNOTSUPP;
4943 }
4944
4945 return -EINVAL;
4946}
4947
Kalle Valo5e3dd152013-06-12 20:52:10 +03004948static const struct ieee80211_ops ath10k_ops = {
4949 .tx = ath10k_tx,
4950 .start = ath10k_start,
4951 .stop = ath10k_stop,
4952 .config = ath10k_config,
4953 .add_interface = ath10k_add_interface,
4954 .remove_interface = ath10k_remove_interface,
4955 .configure_filter = ath10k_configure_filter,
4956 .bss_info_changed = ath10k_bss_info_changed,
4957 .hw_scan = ath10k_hw_scan,
4958 .cancel_hw_scan = ath10k_cancel_hw_scan,
4959 .set_key = ath10k_set_key,
4960 .sta_state = ath10k_sta_state,
4961 .conf_tx = ath10k_conf_tx,
4962 .remain_on_channel = ath10k_remain_on_channel,
4963 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4964 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004965 .flush = ath10k_flush,
4966 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004967 .set_antenna = ath10k_set_antenna,
4968 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02004969 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004970 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004971 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004972 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004973 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004974 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004975 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4976 .get_et_stats = ath10k_debug_get_et_stats,
4977 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004978
4979 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4980
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004981#ifdef CONFIG_PM
4982 .suspend = ath10k_suspend,
4983 .resume = ath10k_resume,
4984#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02004985#ifdef CONFIG_MAC80211_DEBUGFS
4986 .sta_add_debugfs = ath10k_sta_add_debugfs,
4987#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004988};
4989
4990#define RATETAB_ENT(_rate, _rateid, _flags) { \
4991 .bitrate = (_rate), \
4992 .flags = (_flags), \
4993 .hw_value = (_rateid), \
4994}
4995
4996#define CHAN2G(_channel, _freq, _flags) { \
4997 .band = IEEE80211_BAND_2GHZ, \
4998 .hw_value = (_channel), \
4999 .center_freq = (_freq), \
5000 .flags = (_flags), \
5001 .max_antenna_gain = 0, \
5002 .max_power = 30, \
5003}
5004
5005#define CHAN5G(_channel, _freq, _flags) { \
5006 .band = IEEE80211_BAND_5GHZ, \
5007 .hw_value = (_channel), \
5008 .center_freq = (_freq), \
5009 .flags = (_flags), \
5010 .max_antenna_gain = 0, \
5011 .max_power = 30, \
5012}
5013
5014static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5015 CHAN2G(1, 2412, 0),
5016 CHAN2G(2, 2417, 0),
5017 CHAN2G(3, 2422, 0),
5018 CHAN2G(4, 2427, 0),
5019 CHAN2G(5, 2432, 0),
5020 CHAN2G(6, 2437, 0),
5021 CHAN2G(7, 2442, 0),
5022 CHAN2G(8, 2447, 0),
5023 CHAN2G(9, 2452, 0),
5024 CHAN2G(10, 2457, 0),
5025 CHAN2G(11, 2462, 0),
5026 CHAN2G(12, 2467, 0),
5027 CHAN2G(13, 2472, 0),
5028 CHAN2G(14, 2484, 0),
5029};
5030
5031static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005032 CHAN5G(36, 5180, 0),
5033 CHAN5G(40, 5200, 0),
5034 CHAN5G(44, 5220, 0),
5035 CHAN5G(48, 5240, 0),
5036 CHAN5G(52, 5260, 0),
5037 CHAN5G(56, 5280, 0),
5038 CHAN5G(60, 5300, 0),
5039 CHAN5G(64, 5320, 0),
5040 CHAN5G(100, 5500, 0),
5041 CHAN5G(104, 5520, 0),
5042 CHAN5G(108, 5540, 0),
5043 CHAN5G(112, 5560, 0),
5044 CHAN5G(116, 5580, 0),
5045 CHAN5G(120, 5600, 0),
5046 CHAN5G(124, 5620, 0),
5047 CHAN5G(128, 5640, 0),
5048 CHAN5G(132, 5660, 0),
5049 CHAN5G(136, 5680, 0),
5050 CHAN5G(140, 5700, 0),
5051 CHAN5G(149, 5745, 0),
5052 CHAN5G(153, 5765, 0),
5053 CHAN5G(157, 5785, 0),
5054 CHAN5G(161, 5805, 0),
5055 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005056};
5057
Michal Kazior91b12082014-12-12 12:41:35 +01005058/* Note: Be careful if you re-order these. There is code which depends on this
5059 * ordering.
5060 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005061static struct ieee80211_rate ath10k_rates[] = {
5062 /* CCK */
5063 RATETAB_ENT(10, 0x82, 0),
5064 RATETAB_ENT(20, 0x84, 0),
5065 RATETAB_ENT(55, 0x8b, 0),
5066 RATETAB_ENT(110, 0x96, 0),
5067 /* OFDM */
5068 RATETAB_ENT(60, 0x0c, 0),
5069 RATETAB_ENT(90, 0x12, 0),
5070 RATETAB_ENT(120, 0x18, 0),
5071 RATETAB_ENT(180, 0x24, 0),
5072 RATETAB_ENT(240, 0x30, 0),
5073 RATETAB_ENT(360, 0x48, 0),
5074 RATETAB_ENT(480, 0x60, 0),
5075 RATETAB_ENT(540, 0x6c, 0),
5076};
5077
5078#define ath10k_a_rates (ath10k_rates + 4)
5079#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5080#define ath10k_g_rates (ath10k_rates + 0)
5081#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5082
Michal Kaziore7b54192014-08-07 11:03:27 +02005083struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005084{
5085 struct ieee80211_hw *hw;
5086 struct ath10k *ar;
5087
Michal Kaziore7b54192014-08-07 11:03:27 +02005088 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005089 if (!hw)
5090 return NULL;
5091
5092 ar = hw->priv;
5093 ar->hw = hw;
5094
5095 return ar;
5096}
5097
5098void ath10k_mac_destroy(struct ath10k *ar)
5099{
5100 ieee80211_free_hw(ar->hw);
5101}
5102
5103static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5104 {
5105 .max = 8,
5106 .types = BIT(NL80211_IFTYPE_STATION)
5107 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005108 },
5109 {
5110 .max = 3,
5111 .types = BIT(NL80211_IFTYPE_P2P_GO)
5112 },
5113 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005114 .max = 1,
5115 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5116 },
5117 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005118 .max = 7,
5119 .types = BIT(NL80211_IFTYPE_AP)
5120 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005121};
5122
Bartosz Markowskif2595092013-12-10 16:20:39 +01005123static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005124 {
5125 .max = 8,
5126 .types = BIT(NL80211_IFTYPE_AP)
5127 },
5128};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005129
5130static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5131 {
5132 .limits = ath10k_if_limits,
5133 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5134 .max_interfaces = 8,
5135 .num_different_channels = 1,
5136 .beacon_int_infra_match = true,
5137 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005138};
5139
5140static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005141 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005142 .limits = ath10k_10x_if_limits,
5143 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005144 .max_interfaces = 8,
5145 .num_different_channels = 1,
5146 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005147#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005148 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5149 BIT(NL80211_CHAN_WIDTH_20) |
5150 BIT(NL80211_CHAN_WIDTH_40) |
5151 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005152#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005153 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005154};
5155
5156static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5157{
5158 struct ieee80211_sta_vht_cap vht_cap = {0};
5159 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02005160 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005161
5162 vht_cap.vht_supported = 1;
5163 vht_cap.cap = ar->vht_cap_info;
5164
Michal Kazior8865bee42013-07-24 12:36:46 +02005165 mcs_map = 0;
5166 for (i = 0; i < 8; i++) {
5167 if (i < ar->num_rf_chains)
5168 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5169 else
5170 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5171 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005172
5173 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5174 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5175
5176 return vht_cap;
5177}
5178
5179static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5180{
5181 int i;
5182 struct ieee80211_sta_ht_cap ht_cap = {0};
5183
5184 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5185 return ht_cap;
5186
5187 ht_cap.ht_supported = 1;
5188 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5189 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5190 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5191 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5192 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5193
5194 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5195 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5196
5197 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5198 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5199
5200 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5201 u32 smps;
5202
5203 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5204 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5205
5206 ht_cap.cap |= smps;
5207 }
5208
5209 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5210 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5211
5212 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5213 u32 stbc;
5214
5215 stbc = ar->ht_cap_info;
5216 stbc &= WMI_HT_CAP_RX_STBC;
5217 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5218 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5219 stbc &= IEEE80211_HT_CAP_RX_STBC;
5220
5221 ht_cap.cap |= stbc;
5222 }
5223
5224 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5225 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5226
5227 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5228 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5229
5230 /* max AMSDU is implicitly taken from vht_cap_info */
5231 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5232 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5233
Michal Kazior8865bee42013-07-24 12:36:46 +02005234 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005235 ht_cap.mcs.rx_mask[i] = 0xFF;
5236
5237 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5238
5239 return ht_cap;
5240}
5241
Kalle Valo5e3dd152013-06-12 20:52:10 +03005242static void ath10k_get_arvif_iter(void *data, u8 *mac,
5243 struct ieee80211_vif *vif)
5244{
5245 struct ath10k_vif_iter *arvif_iter = data;
5246 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5247
5248 if (arvif->vdev_id == arvif_iter->vdev_id)
5249 arvif_iter->arvif = arvif;
5250}
5251
5252struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5253{
5254 struct ath10k_vif_iter arvif_iter;
5255 u32 flags;
5256
5257 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5258 arvif_iter.vdev_id = vdev_id;
5259
5260 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5261 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5262 flags,
5263 ath10k_get_arvif_iter,
5264 &arvif_iter);
5265 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005266 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005267 return NULL;
5268 }
5269
5270 return arvif_iter.arvif;
5271}
5272
5273int ath10k_mac_register(struct ath10k *ar)
5274{
5275 struct ieee80211_supported_band *band;
5276 struct ieee80211_sta_vht_cap vht_cap;
5277 struct ieee80211_sta_ht_cap ht_cap;
5278 void *channels;
5279 int ret;
5280
5281 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5282
5283 SET_IEEE80211_DEV(ar->hw, ar->dev);
5284
5285 ht_cap = ath10k_get_ht_cap(ar);
5286 vht_cap = ath10k_create_vht_cap(ar);
5287
5288 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5289 channels = kmemdup(ath10k_2ghz_channels,
5290 sizeof(ath10k_2ghz_channels),
5291 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02005292 if (!channels) {
5293 ret = -ENOMEM;
5294 goto err_free;
5295 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005296
5297 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5298 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5299 band->channels = channels;
5300 band->n_bitrates = ath10k_g_rates_size;
5301 band->bitrates = ath10k_g_rates;
5302 band->ht_cap = ht_cap;
5303
5304 /* vht is not supported in 2.4 GHz */
5305
5306 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5307 }
5308
5309 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5310 channels = kmemdup(ath10k_5ghz_channels,
5311 sizeof(ath10k_5ghz_channels),
5312 GFP_KERNEL);
5313 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02005314 ret = -ENOMEM;
5315 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005316 }
5317
5318 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5319 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5320 band->channels = channels;
5321 band->n_bitrates = ath10k_a_rates_size;
5322 band->bitrates = ath10k_a_rates;
5323 band->ht_cap = ht_cap;
5324 band->vht_cap = vht_cap;
5325 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5326 }
5327
5328 ar->hw->wiphy->interface_modes =
5329 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005330 BIT(NL80211_IFTYPE_AP);
5331
Ben Greear46acf7b2014-05-16 17:15:38 +03005332 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5333 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5334
Bartosz Markowskid3541812013-12-10 16:20:40 +01005335 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5336 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01005337 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01005338 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5339 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005340
5341 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5342 IEEE80211_HW_SUPPORTS_PS |
5343 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5344 IEEE80211_HW_SUPPORTS_UAPSD |
5345 IEEE80211_HW_MFP_CAPABLE |
5346 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5347 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02005348 IEEE80211_HW_AP_LINK_PS |
5349 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005350
Eliad Peller0d8614b2014-09-10 14:07:36 +03005351 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5352
Kalle Valo5e3dd152013-06-12 20:52:10 +03005353 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03005354 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005355
5356 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5357 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5358 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5359 }
5360
5361 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5362 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5363
5364 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005365 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005366
Kalle Valo5e3dd152013-06-12 20:52:10 +03005367 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5368
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02005369 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5370 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5371
5372 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5373 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5374 * correct Probe Responses. This is more of a hack advert..
5375 */
5376 ar->hw->wiphy->probe_resp_offload |=
5377 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5378 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5379 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5380 }
5381
Kalle Valo5e3dd152013-06-12 20:52:10 +03005382 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01005383 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5385
5386 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02005387 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5388
Kalle Valo5e3dd152013-06-12 20:52:10 +03005389 /*
5390 * on LL hardware queues are managed entirely by the FW
5391 * so we only advertise to mac we can do the queues thing
5392 */
5393 ar->hw->queues = 4;
5394
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005395 switch (ar->wmi.op_version) {
5396 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5397 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01005398 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5399 ar->hw->wiphy->n_iface_combinations =
5400 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03005401 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005402 break;
5403 case ATH10K_FW_WMI_OP_VERSION_10_1:
5404 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02005405 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02005406 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5407 ar->hw->wiphy->n_iface_combinations =
5408 ARRAY_SIZE(ath10k_10x_if_comb);
5409 break;
5410 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5411 case ATH10K_FW_WMI_OP_VERSION_MAX:
5412 WARN_ON(1);
5413 ret = -EINVAL;
5414 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01005415 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005416
Michal Kazior7c199992013-07-31 10:47:57 +02005417 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5418
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005419 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5420 /* Init ath dfs pattern detector */
5421 ar->ath_common.debug_mask = ATH_DBG_DFS;
5422 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5423 NL80211_DFS_UNSET);
5424
5425 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005426 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005427 }
5428
Kalle Valo5e3dd152013-06-12 20:52:10 +03005429 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5430 ath10k_reg_notifier);
5431 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005432 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005433 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005434 }
5435
5436 ret = ieee80211_register_hw(ar->hw);
5437 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005438 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02005439 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005440 }
5441
5442 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5443 ret = regulatory_hint(ar->hw->wiphy,
5444 ar->ath_common.regulatory.alpha2);
5445 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02005446 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005447 }
5448
5449 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02005450
5451err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005452 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02005453err_free:
5454 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5455 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5456
Kalle Valo5e3dd152013-06-12 20:52:10 +03005457 return ret;
5458}
5459
5460void ath10k_mac_unregister(struct ath10k *ar)
5461{
5462 ieee80211_unregister_hw(ar->hw);
5463
Janusz Dziedzic9702c682013-11-20 09:59:41 +02005464 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5465 ar->dfs_detector->exit(ar->dfs_detector);
5466
Kalle Valo5e3dd152013-06-12 20:52:10 +03005467 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5468 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5469
5470 SET_IEEE80211_DEV(ar->hw, NULL);
5471}