blob: 4a061a7e0885f6ebd9820660272d76455fe1ca33 [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"
Kalle Valo5e3dd152013-06-12 20:52:10 +030030
31/**********/
32/* Crypto */
33/**********/
34
35static int ath10k_send_key(struct ath10k_vif *arvif,
36 struct ieee80211_key_conf *key,
37 enum set_key_cmd cmd,
38 const u8 *macaddr)
39{
Michal Kazior7aa7a722014-08-25 12:09:38 +020040 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030041 struct wmi_vdev_install_key_arg arg = {
42 .vdev_id = arvif->vdev_id,
43 .key_idx = key->keyidx,
44 .key_len = key->keylen,
45 .key_data = key->key,
46 .macaddr = macaddr,
47 };
48
Michal Kazior548db542013-07-05 16:15:15 +030049 lockdep_assert_held(&arvif->ar->conf_mutex);
50
Kalle Valo5e3dd152013-06-12 20:52:10 +030051 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
52 arg.key_flags = WMI_KEY_PAIRWISE;
53 else
54 arg.key_flags = WMI_KEY_GROUP;
55
56 switch (key->cipher) {
57 case WLAN_CIPHER_SUITE_CCMP:
58 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030059 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
60 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
61 else
62 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030063 break;
64 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030065 arg.key_cipher = WMI_CIPHER_TKIP;
66 arg.key_txmic_len = 8;
67 arg.key_rxmic_len = 8;
68 break;
69 case WLAN_CIPHER_SUITE_WEP40:
70 case WLAN_CIPHER_SUITE_WEP104:
71 arg.key_cipher = WMI_CIPHER_WEP;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
75 arg.key_flags = WMI_KEY_PAIRWISE;
76 break;
77 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020078 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030079 return -EOPNOTSUPP;
80 }
81
82 if (cmd == DISABLE_KEY) {
83 arg.key_cipher = WMI_CIPHER_NONE;
84 arg.key_data = NULL;
85 }
86
87 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
88}
89
90static int ath10k_install_key(struct ath10k_vif *arvif,
91 struct ieee80211_key_conf *key,
92 enum set_key_cmd cmd,
93 const u8 *macaddr)
94{
95 struct ath10k *ar = arvif->ar;
96 int ret;
97
Michal Kazior548db542013-07-05 16:15:15 +030098 lockdep_assert_held(&ar->conf_mutex);
99
Wolfram Sang16735d02013-11-14 14:32:02 -0800100 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300101
102 ret = ath10k_send_key(arvif, key, cmd, macaddr);
103 if (ret)
104 return ret;
105
106 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
107 if (ret == 0)
108 return -ETIMEDOUT;
109
110 return 0;
111}
112
113static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
114 const u8 *addr)
115{
116 struct ath10k *ar = arvif->ar;
117 struct ath10k_peer *peer;
118 int ret;
119 int i;
120
121 lockdep_assert_held(&ar->conf_mutex);
122
123 spin_lock_bh(&ar->data_lock);
124 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
125 spin_unlock_bh(&ar->data_lock);
126
127 if (!peer)
128 return -ENOENT;
129
130 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
131 if (arvif->wep_keys[i] == NULL)
132 continue;
133
134 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
135 addr);
136 if (ret)
137 return ret;
138
139 peer->keys[i] = arvif->wep_keys[i];
140 }
141
142 return 0;
143}
144
145static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
146 const u8 *addr)
147{
148 struct ath10k *ar = arvif->ar;
149 struct ath10k_peer *peer;
150 int first_errno = 0;
151 int ret;
152 int i;
153
154 lockdep_assert_held(&ar->conf_mutex);
155
156 spin_lock_bh(&ar->data_lock);
157 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
158 spin_unlock_bh(&ar->data_lock);
159
160 if (!peer)
161 return -ENOENT;
162
163 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
164 if (peer->keys[i] == NULL)
165 continue;
166
167 ret = ath10k_install_key(arvif, peer->keys[i],
168 DISABLE_KEY, addr);
169 if (ret && first_errno == 0)
170 first_errno = ret;
171
172 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200173 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174 i, ret);
175
176 peer->keys[i] = NULL;
177 }
178
179 return first_errno;
180}
181
182static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
183 struct ieee80211_key_conf *key)
184{
185 struct ath10k *ar = arvif->ar;
186 struct ath10k_peer *peer;
187 u8 addr[ETH_ALEN];
188 int first_errno = 0;
189 int ret;
190 int i;
191
192 lockdep_assert_held(&ar->conf_mutex);
193
194 for (;;) {
195 /* since ath10k_install_key we can't hold data_lock all the
196 * time, so we try to remove the keys incrementally */
197 spin_lock_bh(&ar->data_lock);
198 i = 0;
199 list_for_each_entry(peer, &ar->peers, list) {
200 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
201 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300202 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300203 peer->keys[i] = NULL;
204 break;
205 }
206 }
207
208 if (i < ARRAY_SIZE(peer->keys))
209 break;
210 }
211 spin_unlock_bh(&ar->data_lock);
212
213 if (i == ARRAY_SIZE(peer->keys))
214 break;
215
216 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
217 if (ret && first_errno == 0)
218 first_errno = ret;
219
220 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200221 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200222 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300223 }
224
225 return first_errno;
226}
227
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228/*********************/
229/* General utilities */
230/*********************/
231
232static inline enum wmi_phy_mode
233chan_to_phymode(const struct cfg80211_chan_def *chandef)
234{
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
241 phymode = MODE_11G;
242 break;
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
245 break;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
248 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
255 break;
256 }
257 break;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
261 phymode = MODE_11A;
262 break;
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
265 break;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
268 break;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
271 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
277 break;
278 }
279 break;
280 default:
281 break;
282 }
283
284 WARN_ON(phymode == MODE_UNKNOWN);
285 return phymode;
286}
287
288static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
289{
290/*
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
293 * 1 for 1/4 us
294 * 2 for 1/2 us
295 * 3 for 1 us
296 * 4 for 2 us
297 * 5 for 4 us
298 * 6 for 8 us
299 * 7 for 16 us
300 */
301 switch (mpdudensity) {
302 case 0:
303 return 0;
304 case 1:
305 case 2:
306 case 3:
307 /* Our lower layer calculations limit our precision to
308 1 microsecond */
309 return 1;
310 case 4:
311 return 2;
312 case 5:
313 return 4;
314 case 6:
315 return 8;
316 case 7:
317 return 16;
318 default:
319 return 0;
320 }
321}
322
323static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
324{
325 int ret;
326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800330 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200332 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200339 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800341 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100342 spin_lock_bh(&ar->data_lock);
343 ar->num_peers++;
344 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300345
346 return 0;
347}
348
Kalle Valo5a13e762014-01-20 11:01:46 +0200349static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350{
351 struct ath10k *ar = arvif->ar;
352 u32 param;
353 int ret;
354
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
358 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200360 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200361 return ret;
362 }
363
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200370 return ret;
371 }
372
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200378 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200379 return ret;
380 }
381
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200387 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200388 return ret;
389 }
390
391 return 0;
392}
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200396 struct ath10k *ar = arvif->ar;
397 u32 vdev_param;
398
Michal Kazior424121c2013-07-22 14:13:31 +0200399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
401 ATH10K_RTS_MAX);
402
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200405}
406
407static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 struct ath10k *ar = arvif->ar;
410 u32 vdev_param;
411
Michal Kazior424121c2013-07-22 14:13:31 +0200412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
416
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
422{
423 int ret;
424
425 lockdep_assert_held(&ar->conf_mutex);
426
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
428 if (ret)
429 return ret;
430
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
432 if (ret)
433 return ret;
434
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100435 spin_lock_bh(&ar->data_lock);
436 ar->num_peers--;
437 spin_unlock_bh(&ar->data_lock);
438
Kalle Valo5e3dd152013-06-12 20:52:10 +0300439 return 0;
440}
441
442static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443{
444 struct ath10k_peer *peer, *tmp;
445
446 lockdep_assert_held(&ar->conf_mutex);
447
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
451 continue;
452
Michal Kazior7aa7a722014-08-25 12:09:38 +0200453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 peer->addr, vdev_id);
455
456 list_del(&peer->list);
457 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100458 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 }
460 spin_unlock_bh(&ar->data_lock);
461}
462
Michal Kaziora96d7742013-07-16 09:38:56 +0200463static void ath10k_peer_cleanup_all(struct ath10k *ar)
464{
465 struct ath10k_peer *peer, *tmp;
466
467 lockdep_assert_held(&ar->conf_mutex);
468
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
472 kfree(peer);
473 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200475 spin_unlock_bh(&ar->data_lock);
476}
477
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478/************************/
479/* Interface management */
480/************************/
481
Michal Kazior64badcb2014-09-18 11:18:02 +0300482void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
483{
484 struct ath10k *ar = arvif->ar;
485
486 lockdep_assert_held(&ar->data_lock);
487
488 if (!arvif->beacon)
489 return;
490
491 if (!arvif->beacon_buf)
492 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
493 arvif->beacon->len, DMA_TO_DEVICE);
494
495 dev_kfree_skb_any(arvif->beacon);
496
497 arvif->beacon = NULL;
498 arvif->beacon_sent = false;
499}
500
501static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
502{
503 struct ath10k *ar = arvif->ar;
504
505 lockdep_assert_held(&ar->data_lock);
506
507 ath10k_mac_vif_beacon_free(arvif);
508
509 if (arvif->beacon_buf) {
510 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
511 arvif->beacon_buf, arvif->beacon_paddr);
512 arvif->beacon_buf = NULL;
513 }
514}
515
Kalle Valo5e3dd152013-06-12 20:52:10 +0300516static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
517{
518 int ret;
519
Michal Kazior548db542013-07-05 16:15:15 +0300520 lockdep_assert_held(&ar->conf_mutex);
521
Kalle Valo5e3dd152013-06-12 20:52:10 +0300522 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
523 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
524 if (ret == 0)
525 return -ETIMEDOUT;
526
527 return 0;
528}
529
Michal Kazior1bbc0972014-04-08 09:45:47 +0300530static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300531{
Michal Kaziorc930f742014-01-23 11:38:25 +0100532 struct cfg80211_chan_def *chandef = &ar->chandef;
533 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300534 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300535 int ret = 0;
536
537 lockdep_assert_held(&ar->conf_mutex);
538
Kalle Valo5e3dd152013-06-12 20:52:10 +0300539 arg.vdev_id = vdev_id;
540 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100541 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300542
543 /* TODO setup this dynamically, what in case we
544 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100545 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200546 arg.channel.chan_radar =
547 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300548
Michal Kazior89c5c842013-10-23 04:02:13 -0700549 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700550 arg.channel.max_power = channel->max_power * 2;
551 arg.channel.max_reg_power = channel->max_reg_power * 2;
552 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300553
554 ret = ath10k_wmi_vdev_start(ar, &arg);
555 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200556 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200557 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558 return ret;
559 }
560
561 ret = ath10k_vdev_setup_sync(ar);
562 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200563 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200564 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300565 return ret;
566 }
567
568 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
569 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200570 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200571 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300572 goto vdev_stop;
573 }
574
575 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300576
Michal Kazior7aa7a722014-08-25 12:09:38 +0200577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300578 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300579 return 0;
580
581vdev_stop:
582 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
583 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200584 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200585 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300586
587 return ret;
588}
589
Michal Kazior1bbc0972014-04-08 09:45:47 +0300590static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591{
592 int ret = 0;
593
594 lockdep_assert_held(&ar->conf_mutex);
595
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200596 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
597 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200598 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200599 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300600
601 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
602 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200603 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200604 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300605
606 ret = ath10k_vdev_setup_sync(ar);
607 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200608 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200609 ar->monitor_vdev_id, ret);
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 stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300612 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 return ret;
614}
615
Michal Kazior1bbc0972014-04-08 09:45:47 +0300616static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300617{
618 int bit, ret = 0;
619
620 lockdep_assert_held(&ar->conf_mutex);
621
Ben Greeara9aefb32014-08-12 11:02:19 +0300622 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200623 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624 return -ENOMEM;
625 }
626
Ben Greear16c11172014-09-23 14:17:16 -0700627 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300628
Ben Greear16c11172014-09-23 14:17:16 -0700629 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300630
631 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
632 WMI_VDEV_TYPE_MONITOR,
633 0, ar->mac_addr);
634 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200635 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200636 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300637 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300638 }
639
Ben Greear16c11172014-09-23 14:17:16 -0700640 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200641 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300642 ar->monitor_vdev_id);
643
Kalle Valo5e3dd152013-06-12 20:52:10 +0300644 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645}
646
Michal Kazior1bbc0972014-04-08 09:45:47 +0300647static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300648{
649 int ret = 0;
650
651 lockdep_assert_held(&ar->conf_mutex);
652
Kalle Valo5e3dd152013-06-12 20:52:10 +0300653 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
654 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200655 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200656 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300657 return ret;
658 }
659
Ben Greear16c11172014-09-23 14:17:16 -0700660 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300661
Michal Kazior7aa7a722014-08-25 12:09:38 +0200662 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 ar->monitor_vdev_id);
664 return ret;
665}
666
Michal Kazior1bbc0972014-04-08 09:45:47 +0300667static int ath10k_monitor_start(struct ath10k *ar)
668{
669 int ret;
670
671 lockdep_assert_held(&ar->conf_mutex);
672
Michal Kazior1bbc0972014-04-08 09:45:47 +0300673 ret = ath10k_monitor_vdev_create(ar);
674 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200675 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300676 return ret;
677 }
678
679 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
680 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200681 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300682 ath10k_monitor_vdev_delete(ar);
683 return ret;
684 }
685
686 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200687 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300688
689 return 0;
690}
691
Michal Kazior19337472014-08-28 12:58:16 +0200692static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300693{
694 int ret;
695
696 lockdep_assert_held(&ar->conf_mutex);
697
Michal Kazior1bbc0972014-04-08 09:45:47 +0300698 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200699 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200700 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200701 return ret;
702 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300703
704 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200705 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200706 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200707 return ret;
708 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300709
710 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200711 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200712
713 return 0;
714}
715
716static int ath10k_monitor_recalc(struct ath10k *ar)
717{
718 bool should_start;
719
720 lockdep_assert_held(&ar->conf_mutex);
721
722 should_start = ar->monitor ||
723 ar->filter_flags & FIF_PROMISC_IN_BSS ||
724 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
725
726 ath10k_dbg(ar, ATH10K_DBG_MAC,
727 "mac monitor recalc started? %d should? %d\n",
728 ar->monitor_started, should_start);
729
730 if (should_start == ar->monitor_started)
731 return 0;
732
733 if (should_start)
734 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300735
736 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300737}
738
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200739static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
740{
741 struct ath10k *ar = arvif->ar;
742 u32 vdev_param, rts_cts = 0;
743
744 lockdep_assert_held(&ar->conf_mutex);
745
746 vdev_param = ar->wmi.vdev_param->enable_rtscts;
747
748 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
749 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
750
751 if (arvif->num_legacy_stations > 0)
752 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
753 WMI_RTSCTS_PROFILE);
754
755 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
756 rts_cts);
757}
758
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200759static int ath10k_start_cac(struct ath10k *ar)
760{
761 int ret;
762
763 lockdep_assert_held(&ar->conf_mutex);
764
765 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
766
Michal Kazior19337472014-08-28 12:58:16 +0200767 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200768 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200769 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200770 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
771 return ret;
772 }
773
Michal Kazior7aa7a722014-08-25 12:09:38 +0200774 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200775 ar->monitor_vdev_id);
776
777 return 0;
778}
779
780static int ath10k_stop_cac(struct ath10k *ar)
781{
782 lockdep_assert_held(&ar->conf_mutex);
783
784 /* CAC is not running - do nothing */
785 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
786 return 0;
787
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200788 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300789 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200790
Michal Kazior7aa7a722014-08-25 12:09:38 +0200791 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200792
793 return 0;
794}
795
Michal Kaziord6500972014-04-08 09:56:09 +0300796static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200797{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200798 int ret;
799
800 lockdep_assert_held(&ar->conf_mutex);
801
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200802 ath10k_stop_cac(ar);
803
Michal Kaziord6500972014-04-08 09:56:09 +0300804 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200805 return;
806
Michal Kaziord6500972014-04-08 09:56:09 +0300807 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200808 return;
809
810 ret = ath10k_start_cac(ar);
811 if (ret) {
812 /*
813 * Not possible to start CAC on current channel so starting
814 * radiation is not allowed, make this channel DFS_UNAVAILABLE
815 * by indicating that radar was detected.
816 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200817 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200818 ieee80211_radar_detected(ar->hw);
819 }
820}
821
Michal Kaziordc55e302014-07-29 12:53:36 +0300822static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300823{
824 struct ath10k *ar = arvif->ar;
825 struct cfg80211_chan_def *chandef = &ar->chandef;
826 struct wmi_vdev_start_request_arg arg = {};
827 int ret = 0;
828
829 lockdep_assert_held(&ar->conf_mutex);
830
831 reinit_completion(&ar->vdev_setup_done);
832
833 arg.vdev_id = arvif->vdev_id;
834 arg.dtim_period = arvif->dtim_period;
835 arg.bcn_intval = arvif->beacon_interval;
836
837 arg.channel.freq = chandef->chan->center_freq;
838 arg.channel.band_center_freq1 = chandef->center_freq1;
839 arg.channel.mode = chan_to_phymode(chandef);
840
841 arg.channel.min_power = 0;
842 arg.channel.max_power = chandef->chan->max_power * 2;
843 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
844 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
845
846 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
847 arg.ssid = arvif->u.ap.ssid;
848 arg.ssid_len = arvif->u.ap.ssid_len;
849 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
850
851 /* For now allow DFS for AP mode */
852 arg.channel.chan_radar =
853 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
854 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
855 arg.ssid = arvif->vif->bss_conf.ssid;
856 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
857 }
858
Michal Kazior7aa7a722014-08-25 12:09:38 +0200859 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300860 "mac vdev %d start center_freq %d phymode %s\n",
861 arg.vdev_id, arg.channel.freq,
862 ath10k_wmi_phymode_str(arg.channel.mode));
863
Michal Kaziordc55e302014-07-29 12:53:36 +0300864 if (restart)
865 ret = ath10k_wmi_vdev_restart(ar, &arg);
866 else
867 ret = ath10k_wmi_vdev_start(ar, &arg);
868
Michal Kazior72654fa2014-04-08 09:56:09 +0300869 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200870 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300871 arg.vdev_id, ret);
872 return ret;
873 }
874
875 ret = ath10k_vdev_setup_sync(ar);
876 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200877 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300878 arg.vdev_id, ret);
879 return ret;
880 }
881
Michal Kaziord6500972014-04-08 09:56:09 +0300882 ar->num_started_vdevs++;
883 ath10k_recalc_radar_detection(ar);
884
Michal Kazior72654fa2014-04-08 09:56:09 +0300885 return ret;
886}
887
Michal Kaziordc55e302014-07-29 12:53:36 +0300888static int ath10k_vdev_start(struct ath10k_vif *arvif)
889{
890 return ath10k_vdev_start_restart(arvif, false);
891}
892
893static int ath10k_vdev_restart(struct ath10k_vif *arvif)
894{
895 return ath10k_vdev_start_restart(arvif, true);
896}
897
Michal Kazior72654fa2014-04-08 09:56:09 +0300898static int ath10k_vdev_stop(struct ath10k_vif *arvif)
899{
900 struct ath10k *ar = arvif->ar;
901 int ret;
902
903 lockdep_assert_held(&ar->conf_mutex);
904
905 reinit_completion(&ar->vdev_setup_done);
906
907 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
908 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200909 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300910 arvif->vdev_id, ret);
911 return ret;
912 }
913
914 ret = ath10k_vdev_setup_sync(ar);
915 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200916 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300917 arvif->vdev_id, ret);
918 return ret;
919 }
920
Michal Kaziord6500972014-04-08 09:56:09 +0300921 WARN_ON(ar->num_started_vdevs == 0);
922
923 if (ar->num_started_vdevs != 0) {
924 ar->num_started_vdevs--;
925 ath10k_recalc_radar_detection(ar);
926 }
927
Michal Kazior72654fa2014-04-08 09:56:09 +0300928 return ret;
929}
930
Kalle Valo5e3dd152013-06-12 20:52:10 +0300931static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +0300932 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300933{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200934 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935 int ret = 0;
936
Michal Kazior548db542013-07-05 16:15:15 +0300937 lockdep_assert_held(&arvif->ar->conf_mutex);
938
Kalle Valo5e3dd152013-06-12 20:52:10 +0300939 if (!info->enable_beacon) {
940 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100941
942 arvif->is_started = false;
943 arvif->is_up = false;
944
Michal Kazior748afc42014-01-23 12:48:21 +0100945 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +0300946 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +0100947 spin_unlock_bh(&arvif->ar->data_lock);
948
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 return;
950 }
951
952 arvif->tx_seq_no = 0x1000;
953
954 ret = ath10k_vdev_start(arvif);
955 if (ret)
956 return;
957
Michal Kaziorc930f742014-01-23 11:38:25 +0100958 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +0300959 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +0100960
961 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
962 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200964 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200965 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100966 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967 return;
968 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100969
970 arvif->is_started = true;
971 arvif->is_up = true;
972
Michal Kazior7aa7a722014-08-25 12:09:38 +0200973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300974}
975
976static void ath10k_control_ibss(struct ath10k_vif *arvif,
977 struct ieee80211_bss_conf *info,
978 const u8 self_peer[ETH_ALEN])
979{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200980 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200981 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982 int ret = 0;
983
Michal Kazior548db542013-07-05 16:15:15 +0300984 lockdep_assert_held(&arvif->ar->conf_mutex);
985
Kalle Valo5e3dd152013-06-12 20:52:10 +0300986 if (!info->ibss_joined) {
987 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
988 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200989 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300990 self_peer, arvif->vdev_id, ret);
991
Michal Kaziorc930f742014-01-23 11:38:25 +0100992 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300993 return;
994
995 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100996 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300997 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200998 ath10k_warn(ar, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100999 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001000 return;
1001 }
1002
Michal Kaziorc930f742014-01-23 11:38:25 +01001003 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001004
1005 return;
1006 }
1007
1008 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1009 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001010 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001011 self_peer, arvif->vdev_id, ret);
1012 return;
1013 }
1014
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001015 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1016 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001017 ATH10K_DEFAULT_ATIM);
1018 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001019 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001020 arvif->vdev_id, ret);
1021}
1022
1023/*
1024 * Review this when mac80211 gains per-interface powersave support.
1025 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001026static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001027{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001028 struct ath10k *ar = arvif->ar;
1029 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001030 enum wmi_sta_powersave_param param;
1031 enum wmi_sta_ps_mode psmode;
1032 int ret;
1033
Michal Kazior548db542013-07-05 16:15:15 +03001034 lockdep_assert_held(&arvif->ar->conf_mutex);
1035
Michal Kaziorad088bf2013-10-16 15:44:46 +03001036 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1037 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001038
1039 if (conf->flags & IEEE80211_CONF_PS) {
1040 psmode = WMI_STA_PS_MODE_ENABLED;
1041 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1042
Michal Kaziorad088bf2013-10-16 15:44:46 +03001043 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001044 conf->dynamic_ps_timeout);
1045 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001046 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001047 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001048 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001049 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001050 } else {
1051 psmode = WMI_STA_PS_MODE_DISABLED;
1052 }
1053
Michal Kazior7aa7a722014-08-25 12:09:38 +02001054 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001055 arvif->vdev_id, psmode ? "enable" : "disable");
1056
Michal Kaziorad088bf2013-10-16 15:44:46 +03001057 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1058 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001059 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001060 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001061 return ret;
1062 }
1063
1064 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001065}
1066
1067/**********************/
1068/* Station management */
1069/**********************/
1070
1071static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1072 struct ath10k_vif *arvif,
1073 struct ieee80211_sta *sta,
1074 struct ieee80211_bss_conf *bss_conf,
1075 struct wmi_peer_assoc_complete_arg *arg)
1076{
Michal Kazior548db542013-07-05 16:15:15 +03001077 lockdep_assert_held(&ar->conf_mutex);
1078
Kalle Valob25f32c2014-09-14 12:50:49 +03001079 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001080 arg->vdev_id = arvif->vdev_id;
1081 arg->peer_aid = sta->aid;
1082 arg->peer_flags |= WMI_PEER_AUTH;
1083
1084 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1085 /*
1086 * Seems FW have problems with Power Save in STA
1087 * mode when we setup this parameter to high (eg. 5).
1088 * Often we see that FW don't send NULL (with clean P flags)
1089 * frame even there is info about buffered frames in beacons.
1090 * Sometimes we have to wait more than 10 seconds before FW
1091 * will wakeup. Often sending one ping from AP to our device
1092 * just fail (more than 50%).
1093 *
1094 * Seems setting this FW parameter to 1 couse FW
1095 * will check every beacon and will wakup immediately
1096 * after detection buffered data.
1097 */
1098 arg->peer_listen_intval = 1;
1099 else
1100 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1101
1102 arg->peer_num_spatial_streams = 1;
1103
1104 /*
1105 * The assoc capabilities are available only in managed mode.
1106 */
1107 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1108 arg->peer_caps = bss_conf->assoc_capability;
1109}
1110
1111static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1112 struct ath10k_vif *arvif,
1113 struct wmi_peer_assoc_complete_arg *arg)
1114{
1115 struct ieee80211_vif *vif = arvif->vif;
1116 struct ieee80211_bss_conf *info = &vif->bss_conf;
1117 struct cfg80211_bss *bss;
1118 const u8 *rsnie = NULL;
1119 const u8 *wpaie = NULL;
1120
Michal Kazior548db542013-07-05 16:15:15 +03001121 lockdep_assert_held(&ar->conf_mutex);
1122
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1124 info->bssid, NULL, 0, 0, 0);
1125 if (bss) {
1126 const struct cfg80211_bss_ies *ies;
1127
1128 rcu_read_lock();
1129 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1130
1131 ies = rcu_dereference(bss->ies);
1132
1133 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001134 WLAN_OUI_TYPE_MICROSOFT_WPA,
1135 ies->data,
1136 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001137 rcu_read_unlock();
1138 cfg80211_put_bss(ar->hw->wiphy, bss);
1139 }
1140
1141 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1142 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001143 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001144 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1145 }
1146
1147 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001148 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001149 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1150 }
1151}
1152
1153static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1154 struct ieee80211_sta *sta,
1155 struct wmi_peer_assoc_complete_arg *arg)
1156{
1157 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1158 const struct ieee80211_supported_band *sband;
1159 const struct ieee80211_rate *rates;
1160 u32 ratemask;
1161 int i;
1162
Michal Kazior548db542013-07-05 16:15:15 +03001163 lockdep_assert_held(&ar->conf_mutex);
1164
Kalle Valo5e3dd152013-06-12 20:52:10 +03001165 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1166 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1167 rates = sband->bitrates;
1168
1169 rateset->num_rates = 0;
1170
1171 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1172 if (!(ratemask & 1))
1173 continue;
1174
1175 rateset->rates[rateset->num_rates] = rates->hw_value;
1176 rateset->num_rates++;
1177 }
1178}
1179
1180static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1181 struct ieee80211_sta *sta,
1182 struct wmi_peer_assoc_complete_arg *arg)
1183{
1184 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001185 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001186 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001187
Michal Kazior548db542013-07-05 16:15:15 +03001188 lockdep_assert_held(&ar->conf_mutex);
1189
Kalle Valo5e3dd152013-06-12 20:52:10 +03001190 if (!ht_cap->ht_supported)
1191 return;
1192
1193 arg->peer_flags |= WMI_PEER_HT;
1194 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1195 ht_cap->ampdu_factor)) - 1;
1196
1197 arg->peer_mpdu_density =
1198 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1199
1200 arg->peer_ht_caps = ht_cap->cap;
1201 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1202
1203 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1204 arg->peer_flags |= WMI_PEER_LDPC;
1205
1206 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1207 arg->peer_flags |= WMI_PEER_40MHZ;
1208 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1209 }
1210
1211 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1212 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1213
1214 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1215 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1216
1217 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1218 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1219 arg->peer_flags |= WMI_PEER_STBC;
1220 }
1221
1222 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001223 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1224 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1225 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1226 arg->peer_rate_caps |= stbc;
1227 arg->peer_flags |= WMI_PEER_STBC;
1228 }
1229
Kalle Valo5e3dd152013-06-12 20:52:10 +03001230 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1231 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1232 else if (ht_cap->mcs.rx_mask[1])
1233 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1234
1235 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1236 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1237 arg->peer_ht_rates.rates[n++] = i;
1238
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001239 /*
1240 * This is a workaround for HT-enabled STAs which break the spec
1241 * and have no HT capabilities RX mask (no HT RX MCS map).
1242 *
1243 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1244 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1245 *
1246 * Firmware asserts if such situation occurs.
1247 */
1248 if (n == 0) {
1249 arg->peer_ht_rates.num_rates = 8;
1250 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1251 arg->peer_ht_rates.rates[i] = i;
1252 } else {
1253 arg->peer_ht_rates.num_rates = n;
1254 arg->peer_num_spatial_streams = sta->rx_nss;
1255 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001256
Michal Kazior7aa7a722014-08-25 12:09:38 +02001257 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001258 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259 arg->peer_ht_rates.num_rates,
1260 arg->peer_num_spatial_streams);
1261}
1262
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001263static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1264 struct ath10k_vif *arvif,
1265 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001266{
1267 u32 uapsd = 0;
1268 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001269 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001270
Michal Kazior548db542013-07-05 16:15:15 +03001271 lockdep_assert_held(&ar->conf_mutex);
1272
Kalle Valo5e3dd152013-06-12 20:52:10 +03001273 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001274 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001275 sta->uapsd_queues, sta->max_sp);
1276
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1278 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1279 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1280 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1281 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1282 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1283 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1284 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1285 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1286 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1287 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1288 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1289
Kalle Valo5e3dd152013-06-12 20:52:10 +03001290 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1291 max_sp = sta->max_sp;
1292
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001293 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1294 sta->addr,
1295 WMI_AP_PS_PEER_PARAM_UAPSD,
1296 uapsd);
1297 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001298 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001299 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001300 return ret;
1301 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001303 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1304 sta->addr,
1305 WMI_AP_PS_PEER_PARAM_MAX_SP,
1306 max_sp);
1307 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001308 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001309 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001310 return ret;
1311 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312
1313 /* TODO setup this based on STA listen interval and
1314 beacon interval. Currently we don't know
1315 sta->listen_interval - mac80211 patch required.
1316 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001317 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001318 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1319 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001320 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001321 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001322 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001323 return ret;
1324 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001325 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001326
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001327 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001328}
1329
1330static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1331 struct ieee80211_sta *sta,
1332 struct wmi_peer_assoc_complete_arg *arg)
1333{
1334 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001335 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336
1337 if (!vht_cap->vht_supported)
1338 return;
1339
1340 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341 arg->peer_vht_caps = vht_cap->cap;
1342
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001343 ampdu_factor = (vht_cap->cap &
1344 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1345 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1346
1347 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1348 * zero in VHT IE. Using it would result in degraded throughput.
1349 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1350 * it if VHT max_mpdu is smaller. */
1351 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1352 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1353 ampdu_factor)) - 1);
1354
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1356 arg->peer_flags |= WMI_PEER_80MHZ;
1357
1358 arg->peer_vht_rates.rx_max_rate =
1359 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1360 arg->peer_vht_rates.rx_mcs_set =
1361 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1362 arg->peer_vht_rates.tx_max_rate =
1363 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1364 arg->peer_vht_rates.tx_mcs_set =
1365 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1366
Michal Kazior7aa7a722014-08-25 12:09:38 +02001367 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001368 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001369}
1370
1371static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1372 struct ath10k_vif *arvif,
1373 struct ieee80211_sta *sta,
1374 struct ieee80211_bss_conf *bss_conf,
1375 struct wmi_peer_assoc_complete_arg *arg)
1376{
1377 switch (arvif->vdev_type) {
1378 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001379 if (sta->wme)
1380 arg->peer_flags |= WMI_PEER_QOS;
1381
1382 if (sta->wme && sta->uapsd_queues) {
1383 arg->peer_flags |= WMI_PEER_APSD;
1384 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1385 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001386 break;
1387 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001388 if (bss_conf->qos)
1389 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390 break;
1391 default:
1392 break;
1393 }
1394}
1395
1396static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1397 struct ath10k_vif *arvif,
1398 struct ieee80211_sta *sta,
1399 struct wmi_peer_assoc_complete_arg *arg)
1400{
1401 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1402
Kalle Valo5e3dd152013-06-12 20:52:10 +03001403 switch (ar->hw->conf.chandef.chan->band) {
1404 case IEEE80211_BAND_2GHZ:
1405 if (sta->ht_cap.ht_supported) {
1406 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1407 phymode = MODE_11NG_HT40;
1408 else
1409 phymode = MODE_11NG_HT20;
1410 } else {
1411 phymode = MODE_11G;
1412 }
1413
1414 break;
1415 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001416 /*
1417 * Check VHT first.
1418 */
1419 if (sta->vht_cap.vht_supported) {
1420 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1421 phymode = MODE_11AC_VHT80;
1422 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1423 phymode = MODE_11AC_VHT40;
1424 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1425 phymode = MODE_11AC_VHT20;
1426 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001427 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1428 phymode = MODE_11NA_HT40;
1429 else
1430 phymode = MODE_11NA_HT20;
1431 } else {
1432 phymode = MODE_11A;
1433 }
1434
1435 break;
1436 default:
1437 break;
1438 }
1439
Michal Kazior7aa7a722014-08-25 12:09:38 +02001440 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001441 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001442
Kalle Valo5e3dd152013-06-12 20:52:10 +03001443 arg->peer_phymode = phymode;
1444 WARN_ON(phymode == MODE_UNKNOWN);
1445}
1446
Kalle Valob9ada652013-10-16 15:44:46 +03001447static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1448 struct ath10k_vif *arvif,
1449 struct ieee80211_sta *sta,
1450 struct ieee80211_bss_conf *bss_conf,
1451 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452{
Michal Kazior548db542013-07-05 16:15:15 +03001453 lockdep_assert_held(&ar->conf_mutex);
1454
Kalle Valob9ada652013-10-16 15:44:46 +03001455 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001456
Kalle Valob9ada652013-10-16 15:44:46 +03001457 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1458 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1459 ath10k_peer_assoc_h_rates(ar, sta, arg);
1460 ath10k_peer_assoc_h_ht(ar, sta, arg);
1461 ath10k_peer_assoc_h_vht(ar, sta, arg);
1462 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1463 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001464
Kalle Valob9ada652013-10-16 15:44:46 +03001465 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001466}
1467
Michal Kazior90046f52014-02-14 14:45:51 +01001468static const u32 ath10k_smps_map[] = {
1469 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1470 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1471 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1472 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1473};
1474
1475static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1476 const u8 *addr,
1477 const struct ieee80211_sta_ht_cap *ht_cap)
1478{
1479 int smps;
1480
1481 if (!ht_cap->ht_supported)
1482 return 0;
1483
1484 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1485 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1486
1487 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1488 return -EINVAL;
1489
1490 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1491 WMI_PEER_SMPS_STATE,
1492 ath10k_smps_map[smps]);
1493}
1494
Kalle Valo5e3dd152013-06-12 20:52:10 +03001495/* can be called only in mac80211 callbacks due to `key_count` usage */
1496static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1497 struct ieee80211_vif *vif,
1498 struct ieee80211_bss_conf *bss_conf)
1499{
1500 struct ath10k *ar = hw->priv;
1501 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001502 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001503 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001504 struct ieee80211_sta *ap_sta;
1505 int ret;
1506
Michal Kazior548db542013-07-05 16:15:15 +03001507 lockdep_assert_held(&ar->conf_mutex);
1508
Kalle Valo5e3dd152013-06-12 20:52:10 +03001509 rcu_read_lock();
1510
1511 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1512 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001513 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001514 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001515 rcu_read_unlock();
1516 return;
1517 }
1518
Michal Kazior90046f52014-02-14 14:45:51 +01001519 /* ap_sta must be accessed only within rcu section which must be left
1520 * before calling ath10k_setup_peer_smps() which might sleep. */
1521 ht_cap = ap_sta->ht_cap;
1522
Kalle Valob9ada652013-10-16 15:44:46 +03001523 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1524 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001526 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001527 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528 rcu_read_unlock();
1529 return;
1530 }
1531
1532 rcu_read_unlock();
1533
Kalle Valob9ada652013-10-16 15:44:46 +03001534 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1535 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001536 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001537 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001538 return;
1539 }
1540
Michal Kazior90046f52014-02-14 14:45:51 +01001541 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1542 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001543 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001544 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001545 return;
1546 }
1547
Michal Kazior7aa7a722014-08-25 12:09:38 +02001548 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001549 "mac vdev %d up (associated) bssid %pM aid %d\n",
1550 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1551
Michal Kaziorc930f742014-01-23 11:38:25 +01001552 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001553 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001554
1555 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1556 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001557 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001559 return;
1560 }
1561
1562 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001563}
1564
1565/*
1566 * FIXME: flush TIDs
1567 */
1568static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1569 struct ieee80211_vif *vif)
1570{
1571 struct ath10k *ar = hw->priv;
1572 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1573 int ret;
1574
Michal Kazior548db542013-07-05 16:15:15 +03001575 lockdep_assert_held(&ar->conf_mutex);
1576
Kalle Valo5e3dd152013-06-12 20:52:10 +03001577 /*
1578 * For some reason, calling VDEV-DOWN before VDEV-STOP
1579 * makes the FW to send frames via HTT after disassociation.
1580 * No idea why this happens, even though VDEV-DOWN is supposed
1581 * to be analogous to link down, so just stop the VDEV.
1582 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001583 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001584 arvif->vdev_id);
1585
1586 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588
1589 /*
1590 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1591 * report beacons from previously associated network through HTT.
1592 * This in turn would spam mac80211 WARN_ON if we bring down all
1593 * interfaces as it expects there is no rx when no interface is
1594 * running.
1595 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001597
1598 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001601 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001602
1603 arvif->is_started = false;
1604 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605}
1606
1607static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001608 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609{
Kalle Valob9ada652013-10-16 15:44:46 +03001610 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611 int ret = 0;
1612
Michal Kazior548db542013-07-05 16:15:15 +03001613 lockdep_assert_held(&ar->conf_mutex);
1614
Kalle Valob9ada652013-10-16 15:44:46 +03001615 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001617 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001618 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001619 return ret;
1620 }
1621
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001622 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001623 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001625 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001626 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 return ret;
1628 }
1629
Michal Kazior90046f52014-02-14 14:45:51 +01001630 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1631 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001632 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001633 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001634 return ret;
1635 }
1636
Michal Kaziora4841eb2014-08-28 09:59:39 +02001637 if (!sta->wme && !reassoc) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001638 arvif->num_legacy_stations++;
1639 ret = ath10k_recalc_rtscts_prot(arvif);
1640 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001641 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001642 arvif->vdev_id, ret);
1643 return ret;
1644 }
1645 }
1646
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1648 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001649 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001650 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001651 return ret;
1652 }
1653
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001654 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1655 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001656 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001657 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001658 return ret;
1659 }
1660
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 return ret;
1662}
1663
1664static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1665 struct ieee80211_sta *sta)
1666{
1667 int ret = 0;
1668
Michal Kazior548db542013-07-05 16:15:15 +03001669 lockdep_assert_held(&ar->conf_mutex);
1670
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001671 if (!sta->wme) {
1672 arvif->num_legacy_stations--;
1673 ret = ath10k_recalc_rtscts_prot(arvif);
1674 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001675 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001676 arvif->vdev_id, ret);
1677 return ret;
1678 }
1679 }
1680
Kalle Valo5e3dd152013-06-12 20:52:10 +03001681 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1682 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001683 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001684 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001685 return ret;
1686 }
1687
1688 return ret;
1689}
1690
1691/**************/
1692/* Regulatory */
1693/**************/
1694
1695static int ath10k_update_channel_list(struct ath10k *ar)
1696{
1697 struct ieee80211_hw *hw = ar->hw;
1698 struct ieee80211_supported_band **bands;
1699 enum ieee80211_band band;
1700 struct ieee80211_channel *channel;
1701 struct wmi_scan_chan_list_arg arg = {0};
1702 struct wmi_channel_arg *ch;
1703 bool passive;
1704 int len;
1705 int ret;
1706 int i;
1707
Michal Kazior548db542013-07-05 16:15:15 +03001708 lockdep_assert_held(&ar->conf_mutex);
1709
Kalle Valo5e3dd152013-06-12 20:52:10 +03001710 bands = hw->wiphy->bands;
1711 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1712 if (!bands[band])
1713 continue;
1714
1715 for (i = 0; i < bands[band]->n_channels; i++) {
1716 if (bands[band]->channels[i].flags &
1717 IEEE80211_CHAN_DISABLED)
1718 continue;
1719
1720 arg.n_channels++;
1721 }
1722 }
1723
1724 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1725 arg.channels = kzalloc(len, GFP_KERNEL);
1726 if (!arg.channels)
1727 return -ENOMEM;
1728
1729 ch = arg.channels;
1730 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1731 if (!bands[band])
1732 continue;
1733
1734 for (i = 0; i < bands[band]->n_channels; i++) {
1735 channel = &bands[band]->channels[i];
1736
1737 if (channel->flags & IEEE80211_CHAN_DISABLED)
1738 continue;
1739
1740 ch->allow_ht = true;
1741
1742 /* FIXME: when should we really allow VHT? */
1743 ch->allow_vht = true;
1744
1745 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001746 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001747
1748 ch->ht40plus =
1749 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1750
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001751 ch->chan_radar =
1752 !!(channel->flags & IEEE80211_CHAN_RADAR);
1753
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001754 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001755 ch->passive = passive;
1756
1757 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001758 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001759 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001760 ch->max_power = channel->max_power * 2;
1761 ch->max_reg_power = channel->max_reg_power * 2;
1762 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763 ch->reg_class_id = 0; /* FIXME */
1764
1765 /* FIXME: why use only legacy modes, why not any
1766 * HT/VHT modes? Would that even make any
1767 * difference? */
1768 if (channel->band == IEEE80211_BAND_2GHZ)
1769 ch->mode = MODE_11G;
1770 else
1771 ch->mode = MODE_11A;
1772
1773 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1774 continue;
1775
Michal Kazior7aa7a722014-08-25 12:09:38 +02001776 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001777 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1778 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001779 ch->freq, ch->max_power, ch->max_reg_power,
1780 ch->max_antenna_gain, ch->mode);
1781
1782 ch++;
1783 }
1784 }
1785
1786 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1787 kfree(arg.channels);
1788
1789 return ret;
1790}
1791
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001792static enum wmi_dfs_region
1793ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1794{
1795 switch (dfs_region) {
1796 case NL80211_DFS_UNSET:
1797 return WMI_UNINIT_DFS_DOMAIN;
1798 case NL80211_DFS_FCC:
1799 return WMI_FCC_DFS_DOMAIN;
1800 case NL80211_DFS_ETSI:
1801 return WMI_ETSI_DFS_DOMAIN;
1802 case NL80211_DFS_JP:
1803 return WMI_MKK4_DFS_DOMAIN;
1804 }
1805 return WMI_UNINIT_DFS_DOMAIN;
1806}
1807
Michal Kaziorf7843d72013-07-16 09:38:52 +02001808static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001809{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001811 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001812 enum wmi_dfs_region wmi_dfs_reg;
1813 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001814
Michal Kaziorf7843d72013-07-16 09:38:52 +02001815 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816
1817 ret = ath10k_update_channel_list(ar);
1818 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001819 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001820
1821 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001822
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001823 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1824 nl_dfs_reg = ar->dfs_detector->region;
1825 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1826 } else {
1827 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1828 }
1829
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830 /* Target allows setting up per-band regdomain but ath_common provides
1831 * a combined one only */
1832 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001833 regpair->reg_domain,
1834 regpair->reg_domain, /* 2ghz */
1835 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001836 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001837 regpair->reg_5ghz_ctl,
1838 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001840 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001841}
Michal Kazior548db542013-07-05 16:15:15 +03001842
Michal Kaziorf7843d72013-07-16 09:38:52 +02001843static void ath10k_reg_notifier(struct wiphy *wiphy,
1844 struct regulatory_request *request)
1845{
1846 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1847 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001848 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001849
1850 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1851
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001852 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001853 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001854 request->dfs_region);
1855 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1856 request->dfs_region);
1857 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001858 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001859 request->dfs_region);
1860 }
1861
Michal Kaziorf7843d72013-07-16 09:38:52 +02001862 mutex_lock(&ar->conf_mutex);
1863 if (ar->state == ATH10K_STATE_ON)
1864 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001865 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001866}
1867
1868/***************/
1869/* TX handlers */
1870/***************/
1871
Michal Kazior42c3aa62013-10-02 11:03:38 +02001872static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1873{
1874 if (ieee80211_is_mgmt(hdr->frame_control))
1875 return HTT_DATA_TX_EXT_TID_MGMT;
1876
1877 if (!ieee80211_is_data_qos(hdr->frame_control))
1878 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1879
1880 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1881 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1882
1883 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1884}
1885
Michal Kazior2b37c292014-09-02 11:00:22 +03001886static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001887{
Michal Kazior2b37c292014-09-02 11:00:22 +03001888 if (vif)
1889 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001890
Michal Kazior1bbc0972014-04-08 09:45:47 +03001891 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001892 return ar->monitor_vdev_id;
1893
Michal Kazior7aa7a722014-08-25 12:09:38 +02001894 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001895 return 0;
1896}
1897
Michal Kazior4b604552014-07-21 21:03:09 +03001898/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1899 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001900 */
Michal Kazior4b604552014-07-21 21:03:09 +03001901static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001902{
1903 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001904 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905 u8 *qos_ctl;
1906
1907 if (!ieee80211_is_data_qos(hdr->frame_control))
1908 return;
1909
1910 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001911 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1912 skb->data, (void *)qos_ctl - (void *)skb->data);
1913 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001914
1915 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1916 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1917 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1918 * it is safe to downgrade to NullFunc.
1919 */
1920 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1921 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1922 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1923 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924}
1925
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001926static void ath10k_tx_wep_key_work(struct work_struct *work)
1927{
1928 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1929 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001930 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001931 int ret, keyidx = arvif->def_wep_key_newidx;
1932
Michal Kazior911e6c02014-05-26 12:46:03 +03001933 mutex_lock(&arvif->ar->conf_mutex);
1934
1935 if (arvif->ar->state != ATH10K_STATE_ON)
1936 goto unlock;
1937
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001938 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001939 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001940
Michal Kazior7aa7a722014-08-25 12:09:38 +02001941 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001942 arvif->vdev_id, keyidx);
1943
1944 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1945 arvif->vdev_id,
1946 arvif->ar->wmi.vdev_param->def_keyid,
1947 keyidx);
1948 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001949 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001950 arvif->vdev_id,
1951 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001952 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001953 }
1954
1955 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001956
1957unlock:
1958 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001959}
1960
Michal Kazior4b604552014-07-21 21:03:09 +03001961static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1962 struct ieee80211_key_conf *key,
1963 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1966 struct ath10k *ar = arvif->ar;
1967 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969 if (!ieee80211_has_protected(hdr->frame_control))
1970 return;
1971
1972 if (!key)
1973 return;
1974
1975 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1976 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1977 return;
1978
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001979 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980 return;
1981
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001982 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1983 * queueing frames until key index is updated is not an option because
1984 * sk_buff may need more processing to be done, e.g. offchannel */
1985 arvif->def_wep_key_newidx = key->keyidx;
1986 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001987}
1988
Michal Kazior4b604552014-07-21 21:03:09 +03001989static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1990 struct ieee80211_vif *vif,
1991 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992{
1993 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1995
1996 /* This is case only for P2P_GO */
1997 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1998 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1999 return;
2000
2001 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2002 spin_lock_bh(&ar->data_lock);
2003 if (arvif->u.ap.noa_data)
2004 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2005 GFP_ATOMIC))
2006 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2007 arvif->u.ap.noa_data,
2008 arvif->u.ap.noa_len);
2009 spin_unlock_bh(&ar->data_lock);
2010 }
2011}
2012
2013static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2014{
2015 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002016 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017
Michal Kazior961d4c32013-08-09 10:13:34 +02002018 if (ar->htt.target_version_major >= 3) {
2019 /* Since HTT 3.0 there is no separate mgmt tx command */
2020 ret = ath10k_htt_tx(&ar->htt, skb);
2021 goto exit;
2022 }
2023
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002024 if (ieee80211_is_mgmt(hdr->frame_control)) {
2025 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2026 ar->fw_features)) {
2027 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2028 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002029 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002030 ret = -EBUSY;
2031 goto exit;
2032 }
2033
2034 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2035 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2036 } else {
2037 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2038 }
2039 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2040 ar->fw_features) &&
2041 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002042 /* FW does not report tx status properly for NullFunc frames
2043 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002044 * those frames when it detects link/beacon loss and depends
2045 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002046 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002047 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002048 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002049 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002050
Michal Kazior961d4c32013-08-09 10:13:34 +02002051exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002052 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002053 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2054 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055 ieee80211_free_txskb(ar->hw, skb);
2056 }
2057}
2058
2059void ath10k_offchan_tx_purge(struct ath10k *ar)
2060{
2061 struct sk_buff *skb;
2062
2063 for (;;) {
2064 skb = skb_dequeue(&ar->offchan_tx_queue);
2065 if (!skb)
2066 break;
2067
2068 ieee80211_free_txskb(ar->hw, skb);
2069 }
2070}
2071
2072void ath10k_offchan_tx_work(struct work_struct *work)
2073{
2074 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2075 struct ath10k_peer *peer;
2076 struct ieee80211_hdr *hdr;
2077 struct sk_buff *skb;
2078 const u8 *peer_addr;
2079 int vdev_id;
2080 int ret;
2081
2082 /* FW requirement: We must create a peer before FW will send out
2083 * an offchannel frame. Otherwise the frame will be stuck and
2084 * never transmitted. We delete the peer upon tx completion.
2085 * It is unlikely that a peer for offchannel tx will already be
2086 * present. However it may be in some rare cases so account for that.
2087 * Otherwise we might remove a legitimate peer and break stuff. */
2088
2089 for (;;) {
2090 skb = skb_dequeue(&ar->offchan_tx_queue);
2091 if (!skb)
2092 break;
2093
2094 mutex_lock(&ar->conf_mutex);
2095
Michal Kazior7aa7a722014-08-25 12:09:38 +02002096 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002097 skb);
2098
2099 hdr = (struct ieee80211_hdr *)skb->data;
2100 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002101 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002102
2103 spin_lock_bh(&ar->data_lock);
2104 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2105 spin_unlock_bh(&ar->data_lock);
2106
2107 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002108 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002109 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 peer_addr, vdev_id);
2111
2112 if (!peer) {
2113 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2114 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002115 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116 peer_addr, vdev_id, ret);
2117 }
2118
2119 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002120 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002121 ar->offchan_tx_skb = skb;
2122 spin_unlock_bh(&ar->data_lock);
2123
2124 ath10k_tx_htt(ar, skb);
2125
2126 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2127 3 * HZ);
2128 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002129 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130 skb);
2131
2132 if (!peer) {
2133 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2134 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002135 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002136 peer_addr, vdev_id, ret);
2137 }
2138
2139 mutex_unlock(&ar->conf_mutex);
2140 }
2141}
2142
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002143void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2144{
2145 struct sk_buff *skb;
2146
2147 for (;;) {
2148 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2149 if (!skb)
2150 break;
2151
2152 ieee80211_free_txskb(ar->hw, skb);
2153 }
2154}
2155
2156void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2157{
2158 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2159 struct sk_buff *skb;
2160 int ret;
2161
2162 for (;;) {
2163 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2164 if (!skb)
2165 break;
2166
2167 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002168 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002169 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002170 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002171 ieee80211_free_txskb(ar->hw, skb);
2172 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002173 }
2174}
2175
Kalle Valo5e3dd152013-06-12 20:52:10 +03002176/************/
2177/* Scanning */
2178/************/
2179
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002180void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002181{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002182 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002184 switch (ar->scan.state) {
2185 case ATH10K_SCAN_IDLE:
2186 break;
2187 case ATH10K_SCAN_RUNNING:
2188 case ATH10K_SCAN_ABORTING:
2189 if (ar->scan.is_roc)
2190 ieee80211_remain_on_channel_expired(ar->hw);
2191 else
2192 ieee80211_scan_completed(ar->hw,
2193 (ar->scan.state ==
2194 ATH10K_SCAN_ABORTING));
2195 /* fall through */
2196 case ATH10K_SCAN_STARTING:
2197 ar->scan.state = ATH10K_SCAN_IDLE;
2198 ar->scan_channel = NULL;
2199 ath10k_offchan_tx_purge(ar);
2200 cancel_delayed_work(&ar->scan.timeout);
2201 complete_all(&ar->scan.completed);
2202 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002204}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002206void ath10k_scan_finish(struct ath10k *ar)
2207{
2208 spin_lock_bh(&ar->data_lock);
2209 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210 spin_unlock_bh(&ar->data_lock);
2211}
2212
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002213static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214{
2215 struct wmi_stop_scan_arg arg = {
2216 .req_id = 1, /* FIXME */
2217 .req_type = WMI_SCAN_STOP_ONE,
2218 .u.scan_id = ATH10K_SCAN_ID,
2219 };
2220 int ret;
2221
2222 lockdep_assert_held(&ar->conf_mutex);
2223
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224 ret = ath10k_wmi_stop_scan(ar, &arg);
2225 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002226 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002227 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002228 }
2229
Kalle Valo5e3dd152013-06-12 20:52:10 +03002230 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002231 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002232 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002233 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002234 } else if (ret > 0) {
2235 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002236 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002237
2238out:
2239 /* Scan state should be updated upon scan completion but in case
2240 * firmware fails to deliver the event (for whatever reason) it is
2241 * desired to clean up scan state anyway. Firmware may have just
2242 * dropped the scan completion event delivery due to transport pipe
2243 * being overflown with data and/or it can recover on its own before
2244 * next scan request is submitted.
2245 */
2246 spin_lock_bh(&ar->data_lock);
2247 if (ar->scan.state != ATH10K_SCAN_IDLE)
2248 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002249 spin_unlock_bh(&ar->data_lock);
2250
2251 return ret;
2252}
2253
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002254static void ath10k_scan_abort(struct ath10k *ar)
2255{
2256 int ret;
2257
2258 lockdep_assert_held(&ar->conf_mutex);
2259
2260 spin_lock_bh(&ar->data_lock);
2261
2262 switch (ar->scan.state) {
2263 case ATH10K_SCAN_IDLE:
2264 /* This can happen if timeout worker kicked in and called
2265 * abortion while scan completion was being processed.
2266 */
2267 break;
2268 case ATH10K_SCAN_STARTING:
2269 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002270 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002271 ath10k_scan_state_str(ar->scan.state),
2272 ar->scan.state);
2273 break;
2274 case ATH10K_SCAN_RUNNING:
2275 ar->scan.state = ATH10K_SCAN_ABORTING;
2276 spin_unlock_bh(&ar->data_lock);
2277
2278 ret = ath10k_scan_stop(ar);
2279 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002280 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002281
2282 spin_lock_bh(&ar->data_lock);
2283 break;
2284 }
2285
2286 spin_unlock_bh(&ar->data_lock);
2287}
2288
2289void ath10k_scan_timeout_work(struct work_struct *work)
2290{
2291 struct ath10k *ar = container_of(work, struct ath10k,
2292 scan.timeout.work);
2293
2294 mutex_lock(&ar->conf_mutex);
2295 ath10k_scan_abort(ar);
2296 mutex_unlock(&ar->conf_mutex);
2297}
2298
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299static int ath10k_start_scan(struct ath10k *ar,
2300 const struct wmi_start_scan_arg *arg)
2301{
2302 int ret;
2303
2304 lockdep_assert_held(&ar->conf_mutex);
2305
2306 ret = ath10k_wmi_start_scan(ar, arg);
2307 if (ret)
2308 return ret;
2309
Kalle Valo5e3dd152013-06-12 20:52:10 +03002310 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2311 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002312 ret = ath10k_scan_stop(ar);
2313 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002314 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002315
2316 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317 }
2318
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002319 /* Add a 200ms margin to account for event/command processing */
2320 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2321 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322 return 0;
2323}
2324
2325/**********************/
2326/* mac80211 callbacks */
2327/**********************/
2328
2329static void ath10k_tx(struct ieee80211_hw *hw,
2330 struct ieee80211_tx_control *control,
2331 struct sk_buff *skb)
2332{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002334 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2335 struct ieee80211_vif *vif = info->control.vif;
2336 struct ieee80211_key_conf *key = info->control.hw_key;
2337 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338
2339 /* We should disable CCK RATE due to P2P */
2340 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002341 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002342
Michal Kazior4b604552014-07-21 21:03:09 +03002343 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2344 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002345 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002347 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002348 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2349 ath10k_tx_h_nwifi(hw, skb);
2350 ath10k_tx_h_update_wep_key(vif, key, skb);
2351 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2352 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002353 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002354
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2356 spin_lock_bh(&ar->data_lock);
2357 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002358 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002359 spin_unlock_bh(&ar->data_lock);
2360
Michal Kazior7aa7a722014-08-25 12:09:38 +02002361 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2362 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363
2364 skb_queue_tail(&ar->offchan_tx_queue, skb);
2365 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2366 return;
2367 }
2368
2369 ath10k_tx_htt(ar, skb);
2370}
2371
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002372/* Must not be called with conf_mutex held as workers can use that also. */
2373static void ath10k_drain_tx(struct ath10k *ar)
2374{
2375 /* make sure rcu-protected mac80211 tx path itself is drained */
2376 synchronize_net();
2377
2378 ath10k_offchan_tx_purge(ar);
2379 ath10k_mgmt_over_wmi_tx_purge(ar);
2380
2381 cancel_work_sync(&ar->offchan_tx_work);
2382 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2383}
2384
Michal Kazioraffd3212013-07-16 09:54:35 +02002385void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002386{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002387 struct ath10k_vif *arvif;
2388
Michal Kazior818bdd12013-07-16 09:38:57 +02002389 lockdep_assert_held(&ar->conf_mutex);
2390
Michal Kazior19337472014-08-28 12:58:16 +02002391 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2392 ar->filter_flags = 0;
2393 ar->monitor = false;
2394
2395 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002396 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002397
2398 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002399
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002400 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002401 ath10k_peer_cleanup_all(ar);
2402 ath10k_core_stop(ar);
2403 ath10k_hif_power_down(ar);
2404
2405 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002406 list_for_each_entry(arvif, &ar->arvifs, list)
2407 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002408 spin_unlock_bh(&ar->data_lock);
2409}
2410
Ben Greear46acf7b2014-05-16 17:15:38 +03002411static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2412{
2413 struct ath10k *ar = hw->priv;
2414
2415 mutex_lock(&ar->conf_mutex);
2416
2417 if (ar->cfg_tx_chainmask) {
2418 *tx_ant = ar->cfg_tx_chainmask;
2419 *rx_ant = ar->cfg_rx_chainmask;
2420 } else {
2421 *tx_ant = ar->supp_tx_chainmask;
2422 *rx_ant = ar->supp_rx_chainmask;
2423 }
2424
2425 mutex_unlock(&ar->conf_mutex);
2426
2427 return 0;
2428}
2429
2430static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2431{
2432 int ret;
2433
2434 lockdep_assert_held(&ar->conf_mutex);
2435
2436 ar->cfg_tx_chainmask = tx_ant;
2437 ar->cfg_rx_chainmask = rx_ant;
2438
2439 if ((ar->state != ATH10K_STATE_ON) &&
2440 (ar->state != ATH10K_STATE_RESTARTED))
2441 return 0;
2442
2443 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2444 tx_ant);
2445 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002446 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002447 ret, tx_ant);
2448 return ret;
2449 }
2450
2451 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2452 rx_ant);
2453 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002454 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002455 ret, rx_ant);
2456 return ret;
2457 }
2458
2459 return 0;
2460}
2461
2462static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2463{
2464 struct ath10k *ar = hw->priv;
2465 int ret;
2466
2467 mutex_lock(&ar->conf_mutex);
2468 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2469 mutex_unlock(&ar->conf_mutex);
2470 return ret;
2471}
2472
Kalle Valo5e3dd152013-06-12 20:52:10 +03002473static int ath10k_start(struct ieee80211_hw *hw)
2474{
2475 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002476 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002477
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002478 /*
2479 * This makes sense only when restarting hw. It is harmless to call
2480 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2481 * commands will be submitted while restarting.
2482 */
2483 ath10k_drain_tx(ar);
2484
Michal Kazior548db542013-07-05 16:15:15 +03002485 mutex_lock(&ar->conf_mutex);
2486
Michal Kaziorc5058f52014-05-26 12:46:03 +03002487 switch (ar->state) {
2488 case ATH10K_STATE_OFF:
2489 ar->state = ATH10K_STATE_ON;
2490 break;
2491 case ATH10K_STATE_RESTARTING:
2492 ath10k_halt(ar);
2493 ar->state = ATH10K_STATE_RESTARTED;
2494 break;
2495 case ATH10K_STATE_ON:
2496 case ATH10K_STATE_RESTARTED:
2497 case ATH10K_STATE_WEDGED:
2498 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002499 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002500 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002501 case ATH10K_STATE_UTF:
2502 ret = -EBUSY;
2503 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002504 }
2505
2506 ret = ath10k_hif_power_up(ar);
2507 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002508 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002509 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002510 }
2511
Kalle Valo43d2a302014-09-10 18:23:30 +03002512 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002513 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002514 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002515 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002516 }
2517
Bartosz Markowski226a3392013-09-26 17:47:16 +02002518 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002519 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002520 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002521 goto err_core_stop;
2522 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002523
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002524 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002526 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002527 goto err_core_stop;
2528 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002529
Ben Greear46acf7b2014-05-16 17:15:38 +03002530 if (ar->cfg_tx_chainmask)
2531 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2532 ar->cfg_rx_chainmask);
2533
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002534 /*
2535 * By default FW set ARP frames ac to voice (6). In that case ARP
2536 * exchange is not working properly for UAPSD enabled AP. ARP requests
2537 * which arrives with access category 0 are processed by network stack
2538 * and send back with access category 0, but FW changes access category
2539 * to 6. Set ARP frames access category to best effort (0) solves
2540 * this problem.
2541 */
2542
2543 ret = ath10k_wmi_pdev_set_param(ar,
2544 ar->wmi.pdev_param->arp_ac_override, 0);
2545 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002546 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002547 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002548 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002549 }
2550
Michal Kaziord6500972014-04-08 09:56:09 +03002551 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002552 ath10k_regd_update(ar);
2553
Simon Wunderlich855aed12014-08-02 09:12:54 +03002554 ath10k_spectral_start(ar);
2555
Michal Kaziorae254432014-05-26 12:46:02 +03002556 mutex_unlock(&ar->conf_mutex);
2557 return 0;
2558
2559err_core_stop:
2560 ath10k_core_stop(ar);
2561
2562err_power_down:
2563 ath10k_hif_power_down(ar);
2564
2565err_off:
2566 ar->state = ATH10K_STATE_OFF;
2567
2568err:
Michal Kazior548db542013-07-05 16:15:15 +03002569 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002570 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002571}
2572
2573static void ath10k_stop(struct ieee80211_hw *hw)
2574{
2575 struct ath10k *ar = hw->priv;
2576
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002577 ath10k_drain_tx(ar);
2578
Michal Kazior548db542013-07-05 16:15:15 +03002579 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002580 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002581 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002582 ar->state = ATH10K_STATE_OFF;
2583 }
Michal Kazior548db542013-07-05 16:15:15 +03002584 mutex_unlock(&ar->conf_mutex);
2585
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002586 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002587 cancel_work_sync(&ar->restart_work);
2588}
2589
Michal Kaziorad088bf2013-10-16 15:44:46 +03002590static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002591{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002592 struct ath10k_vif *arvif;
2593 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002594
2595 lockdep_assert_held(&ar->conf_mutex);
2596
Michal Kaziorad088bf2013-10-16 15:44:46 +03002597 list_for_each_entry(arvif, &ar->arvifs, list) {
2598 ret = ath10k_mac_vif_setup_ps(arvif);
2599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002600 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002601 break;
2602 }
2603 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002604
Michal Kaziorad088bf2013-10-16 15:44:46 +03002605 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002606}
2607
Michal Kaziorc930f742014-01-23 11:38:25 +01002608static const char *chandef_get_width(enum nl80211_chan_width width)
2609{
2610 switch (width) {
2611 case NL80211_CHAN_WIDTH_20_NOHT:
2612 return "20 (noht)";
2613 case NL80211_CHAN_WIDTH_20:
2614 return "20";
2615 case NL80211_CHAN_WIDTH_40:
2616 return "40";
2617 case NL80211_CHAN_WIDTH_80:
2618 return "80";
2619 case NL80211_CHAN_WIDTH_80P80:
2620 return "80+80";
2621 case NL80211_CHAN_WIDTH_160:
2622 return "160";
2623 case NL80211_CHAN_WIDTH_5:
2624 return "5";
2625 case NL80211_CHAN_WIDTH_10:
2626 return "10";
2627 }
2628 return "?";
2629}
2630
2631static void ath10k_config_chan(struct ath10k *ar)
2632{
2633 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002634 int ret;
2635
2636 lockdep_assert_held(&ar->conf_mutex);
2637
Michal Kazior7aa7a722014-08-25 12:09:38 +02002638 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002639 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2640 ar->chandef.chan->center_freq,
2641 ar->chandef.center_freq1,
2642 ar->chandef.center_freq2,
2643 chandef_get_width(ar->chandef.width));
2644
2645 /* First stop monitor interface. Some FW versions crash if there's a
2646 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002647 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002648 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002649
2650 list_for_each_entry(arvif, &ar->arvifs, list) {
2651 if (!arvif->is_started)
2652 continue;
2653
Michal Kaziordc55e302014-07-29 12:53:36 +03002654 if (!arvif->is_up)
2655 continue;
2656
Michal Kaziorc930f742014-01-23 11:38:25 +01002657 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2658 continue;
2659
Michal Kaziordc55e302014-07-29 12:53:36 +03002660 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002661 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002662 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002663 arvif->vdev_id, ret);
2664 continue;
2665 }
2666 }
2667
Michal Kaziordc55e302014-07-29 12:53:36 +03002668 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002669
2670 list_for_each_entry(arvif, &ar->arvifs, list) {
2671 if (!arvif->is_started)
2672 continue;
2673
2674 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2675 continue;
2676
Michal Kaziordc55e302014-07-29 12:53:36 +03002677 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002678 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002679 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002680 arvif->vdev_id, ret);
2681 continue;
2682 }
2683
2684 if (!arvif->is_up)
2685 continue;
2686
2687 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2688 arvif->bssid);
2689 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002690 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002691 arvif->vdev_id, ret);
2692 continue;
2693 }
2694 }
2695
Michal Kazior19337472014-08-28 12:58:16 +02002696 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002697}
2698
Kalle Valo5e3dd152013-06-12 20:52:10 +03002699static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2700{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002701 struct ath10k *ar = hw->priv;
2702 struct ieee80211_conf *conf = &hw->conf;
2703 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002704 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002705
2706 mutex_lock(&ar->conf_mutex);
2707
2708 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002710 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002711 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002712 conf->chandef.chan->flags,
2713 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002714
Kalle Valo5e3dd152013-06-12 20:52:10 +03002715 spin_lock_bh(&ar->data_lock);
2716 ar->rx_channel = conf->chandef.chan;
2717 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002718
Michal Kaziord6500972014-04-08 09:56:09 +03002719 ar->radar_enabled = conf->radar_enabled;
2720 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002721
2722 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2723 ar->chandef = conf->chandef;
2724 ath10k_config_chan(ar);
2725 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002726 }
2727
Michal Kazior5474efe2013-10-23 04:02:15 -07002728 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002729 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002730 hw->conf.power_level);
2731
2732 param = ar->wmi.pdev_param->txpower_limit2g;
2733 ret = ath10k_wmi_pdev_set_param(ar, param,
2734 hw->conf.power_level * 2);
2735 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002736 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002737 hw->conf.power_level, ret);
2738
2739 param = ar->wmi.pdev_param->txpower_limit5g;
2740 ret = ath10k_wmi_pdev_set_param(ar, param,
2741 hw->conf.power_level * 2);
2742 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002743 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002744 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745 }
2746
Michal Kazioraffd3212013-07-16 09:54:35 +02002747 if (changed & IEEE80211_CONF_CHANGE_PS)
2748 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749
2750 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002751 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2752 ret = ath10k_monitor_recalc(ar);
2753 if (ret)
2754 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002755 }
2756
2757 mutex_unlock(&ar->conf_mutex);
2758 return ret;
2759}
2760
2761/*
2762 * TODO:
2763 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2764 * because we will send mgmt frames without CCK. This requirement
2765 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2766 * in the TX packet.
2767 */
2768static int ath10k_add_interface(struct ieee80211_hw *hw,
2769 struct ieee80211_vif *vif)
2770{
2771 struct ath10k *ar = hw->priv;
2772 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2773 enum wmi_sta_powersave_param param;
2774 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002775 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002777 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778
2779 mutex_lock(&ar->conf_mutex);
2780
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002781 memset(arvif, 0, sizeof(*arvif));
2782
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 arvif->ar = ar;
2784 arvif->vif = vif;
2785
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002786 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002787 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002788
Ben Greeara9aefb32014-08-12 11:02:19 +03002789 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002790 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002791 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002792 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002793 }
Ben Greear16c11172014-09-23 14:17:16 -07002794 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795
Ben Greear16c11172014-09-23 14:17:16 -07002796 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2797 bit, ar->free_vdev_map);
2798
2799 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801
2802 if (ar->p2p)
2803 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2804
2805 switch (vif->type) {
2806 case NL80211_IFTYPE_UNSPECIFIED:
2807 case NL80211_IFTYPE_STATION:
2808 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2809 if (vif->p2p)
2810 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2811 break;
2812 case NL80211_IFTYPE_ADHOC:
2813 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2814 break;
2815 case NL80211_IFTYPE_AP:
2816 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2817
2818 if (vif->p2p)
2819 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2820 break;
2821 case NL80211_IFTYPE_MONITOR:
2822 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2823 break;
2824 default:
2825 WARN_ON(1);
2826 break;
2827 }
2828
Michal Kazior64badcb2014-09-18 11:18:02 +03002829 /* Some firmware revisions don't wait for beacon tx completion before
2830 * sending another SWBA event. This could lead to hardware using old
2831 * (freed) beacon data in some cases, e.g. tx credit starvation
2832 * combined with missed TBTT. This is very very rare.
2833 *
2834 * On non-IOMMU-enabled hosts this could be a possible security issue
2835 * because hw could beacon some random data on the air. On
2836 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2837 * device would crash.
2838 *
2839 * Since there are no beacon tx completions (implicit nor explicit)
2840 * propagated to host the only workaround for this is to allocate a
2841 * DMA-coherent buffer for a lifetime of a vif and use it for all
2842 * beacon tx commands. Worst case for this approach is some beacons may
2843 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2844 */
2845 if (vif->type == NL80211_IFTYPE_ADHOC ||
2846 vif->type == NL80211_IFTYPE_AP) {
2847 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2848 IEEE80211_MAX_FRAME_LEN,
2849 &arvif->beacon_paddr,
2850 GFP_KERNEL);
2851 if (!arvif->beacon_buf) {
2852 ret = -ENOMEM;
2853 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2854 ret);
2855 goto err;
2856 }
2857 }
2858
2859 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2860 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2861 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002862
2863 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2864 arvif->vdev_subtype, vif->addr);
2865 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002866 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002867 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002868 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869 }
2870
Ben Greear16c11172014-09-23 14:17:16 -07002871 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002872 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002873
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002874 vdev_param = ar->wmi.vdev_param->def_keyid;
2875 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002876 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002877 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002878 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002879 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002880 goto err_vdev_delete;
2881 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002882
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002883 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2884 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002885 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002886 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002887 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002888 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002889 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002890 goto err_vdev_delete;
2891 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002892
2893 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2894 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002896 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002897 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002898 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002899 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002900
Kalle Valo5a13e762014-01-20 11:01:46 +02002901 ret = ath10k_mac_set_kickout(arvif);
2902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002903 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002904 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002905 goto err_peer_delete;
2906 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907 }
2908
2909 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2910 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2911 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2912 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2913 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002914 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002915 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002916 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002917 goto err_peer_delete;
2918 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919
2920 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2921 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2922 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2923 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002924 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002925 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002926 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002927 goto err_peer_delete;
2928 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002929
2930 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2931 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2932 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2933 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002934 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002935 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002936 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002937 goto err_peer_delete;
2938 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002939 }
2940
Michal Kazior424121c2013-07-22 14:13:31 +02002941 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002942 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002943 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002944 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002945 goto err_peer_delete;
2946 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002947
Michal Kazior424121c2013-07-22 14:13:31 +02002948 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002949 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002950 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002951 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002952 goto err_peer_delete;
2953 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002954
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002956 return 0;
2957
2958err_peer_delete:
2959 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2960 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2961
2962err_vdev_delete:
2963 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07002964 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002965 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002966
2967err:
Michal Kazior64badcb2014-09-18 11:18:02 +03002968 if (arvif->beacon_buf) {
2969 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
2970 arvif->beacon_buf, arvif->beacon_paddr);
2971 arvif->beacon_buf = NULL;
2972 }
2973
Michal Kazior9dad14a2013-10-16 15:44:45 +03002974 mutex_unlock(&ar->conf_mutex);
2975
Kalle Valo5e3dd152013-06-12 20:52:10 +03002976 return ret;
2977}
2978
2979static void ath10k_remove_interface(struct ieee80211_hw *hw,
2980 struct ieee80211_vif *vif)
2981{
2982 struct ath10k *ar = hw->priv;
2983 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2984 int ret;
2985
2986 mutex_lock(&ar->conf_mutex);
2987
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002988 cancel_work_sync(&arvif->wep_key_work);
2989
Michal Kaziored543882013-09-13 14:16:56 +02002990 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002991 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02002992 spin_unlock_bh(&ar->data_lock);
2993
Simon Wunderlich855aed12014-08-02 09:12:54 +03002994 ret = ath10k_spectral_vif_stop(arvif);
2995 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002996 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03002997 arvif->vdev_id, ret);
2998
Ben Greear16c11172014-09-23 14:17:16 -07002999 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003000 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001
3002 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3003 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3004 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003005 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003006 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003007
3008 kfree(arvif->u.ap.noa_data);
3009 }
3010
Michal Kazior7aa7a722014-08-25 12:09:38 +02003011 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003012 arvif->vdev_id);
3013
Kalle Valo5e3dd152013-06-12 20:52:10 +03003014 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3015 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003016 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003017 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003018
Kalle Valo5e3dd152013-06-12 20:52:10 +03003019 ath10k_peer_cleanup(ar, arvif->vdev_id);
3020
3021 mutex_unlock(&ar->conf_mutex);
3022}
3023
3024/*
3025 * FIXME: Has to be verified.
3026 */
3027#define SUPPORTED_FILTERS \
3028 (FIF_PROMISC_IN_BSS | \
3029 FIF_ALLMULTI | \
3030 FIF_CONTROL | \
3031 FIF_PSPOLL | \
3032 FIF_OTHER_BSS | \
3033 FIF_BCN_PRBRESP_PROMISC | \
3034 FIF_PROBE_REQ | \
3035 FIF_FCSFAIL)
3036
3037static void ath10k_configure_filter(struct ieee80211_hw *hw,
3038 unsigned int changed_flags,
3039 unsigned int *total_flags,
3040 u64 multicast)
3041{
3042 struct ath10k *ar = hw->priv;
3043 int ret;
3044
3045 mutex_lock(&ar->conf_mutex);
3046
3047 changed_flags &= SUPPORTED_FILTERS;
3048 *total_flags &= SUPPORTED_FILTERS;
3049 ar->filter_flags = *total_flags;
3050
Michal Kazior19337472014-08-28 12:58:16 +02003051 ret = ath10k_monitor_recalc(ar);
3052 if (ret)
3053 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003054
3055 mutex_unlock(&ar->conf_mutex);
3056}
3057
3058static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3059 struct ieee80211_vif *vif,
3060 struct ieee80211_bss_conf *info,
3061 u32 changed)
3062{
3063 struct ath10k *ar = hw->priv;
3064 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3065 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003066 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003067
3068 mutex_lock(&ar->conf_mutex);
3069
3070 if (changed & BSS_CHANGED_IBSS)
3071 ath10k_control_ibss(arvif, info, vif->addr);
3072
3073 if (changed & BSS_CHANGED_BEACON_INT) {
3074 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003075 vdev_param = ar->wmi.vdev_param->beacon_interval;
3076 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003077 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003078 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003079 "mac vdev %d beacon_interval %d\n",
3080 arvif->vdev_id, arvif->beacon_interval);
3081
Kalle Valo5e3dd152013-06-12 20:52:10 +03003082 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003083 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003084 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003085 }
3086
3087 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003088 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003089 "vdev %d set beacon tx mode to staggered\n",
3090 arvif->vdev_id);
3091
Bartosz Markowski226a3392013-09-26 17:47:16 +02003092 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3093 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094 WMI_BEACON_STAGGERED_MODE);
3095 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003096 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003097 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098 }
3099
John W. Linvilleb70727e2013-06-13 13:34:29 -04003100 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003101 arvif->dtim_period = info->dtim_period;
3102
Michal Kazior7aa7a722014-08-25 12:09:38 +02003103 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003104 "mac vdev %d dtim_period %d\n",
3105 arvif->vdev_id, arvif->dtim_period);
3106
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003107 vdev_param = ar->wmi.vdev_param->dtim_period;
3108 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003109 arvif->dtim_period);
3110 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003111 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003112 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003113 }
3114
3115 if (changed & BSS_CHANGED_SSID &&
3116 vif->type == NL80211_IFTYPE_AP) {
3117 arvif->u.ap.ssid_len = info->ssid_len;
3118 if (info->ssid_len)
3119 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3120 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3121 }
3122
Michal Kazior7b161a72014-05-26 12:46:03 +03003123 /*
3124 * Firmware manages AP self-peer internally so make sure to not create
3125 * it in driver. Otherwise AP self-peer deletion may timeout later.
3126 */
3127 if (changed & BSS_CHANGED_BSSID &&
3128 vif->type != NL80211_IFTYPE_AP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 if (!is_zero_ether_addr(info->bssid)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003130 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003131 "mac vdev %d create peer %pM\n",
3132 arvif->vdev_id, info->bssid);
3133
Kalle Valo5e3dd152013-06-12 20:52:10 +03003134 ret = ath10k_peer_create(ar, arvif->vdev_id,
3135 info->bssid);
3136 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003137 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003138 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139
3140 if (vif->type == NL80211_IFTYPE_STATION) {
3141 /*
3142 * this is never erased as we it for crypto key
3143 * clearing; this is FW requirement
3144 */
Kalle Valob25f32c2014-09-14 12:50:49 +03003145 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146
Michal Kazior7aa7a722014-08-25 12:09:38 +02003147 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003148 "mac vdev %d start %pM\n",
3149 arvif->vdev_id, info->bssid);
3150
Kalle Valo5e3dd152013-06-12 20:52:10 +03003151 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003152 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003153 ath10k_warn(ar, "failed to start vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003154 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02003155 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01003156 }
3157
3158 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003159 }
3160
3161 /*
3162 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3163 * so driver need to store it. It is needed when leaving
3164 * IBSS in order to remove BSSID peer.
3165 */
3166 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01003167 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168 ETH_ALEN);
3169 }
3170 }
3171
3172 if (changed & BSS_CHANGED_BEACON_ENABLED)
3173 ath10k_control_beaconing(arvif, info);
3174
3175 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003176 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003177 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003178 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003179
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003180 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003182 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003183 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184 }
3185
3186 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187 if (info->use_short_slot)
3188 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3189
3190 else
3191 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3192
Michal Kazior7aa7a722014-08-25 12:09:38 +02003193 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003194 arvif->vdev_id, slottime);
3195
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003196 vdev_param = ar->wmi.vdev_param->slot_time;
3197 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003198 slottime);
3199 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003200 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003201 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003202 }
3203
3204 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003205 if (info->use_short_preamble)
3206 preamble = WMI_VDEV_PREAMBLE_SHORT;
3207 else
3208 preamble = WMI_VDEV_PREAMBLE_LONG;
3209
Michal Kazior7aa7a722014-08-25 12:09:38 +02003210 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003211 "mac vdev %d preamble %dn",
3212 arvif->vdev_id, preamble);
3213
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003214 vdev_param = ar->wmi.vdev_param->preamble;
3215 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 preamble);
3217 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003218 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003219 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003220 }
3221
3222 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003223 if (info->assoc) {
3224 /* Workaround: Make sure monitor vdev is not running
3225 * when associating to prevent some firmware revisions
3226 * (e.g. 10.1 and 10.2) from crashing.
3227 */
3228 if (ar->monitor_started)
3229 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003230 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003231 ath10k_monitor_recalc(ar);
3232 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233 }
3234
Kalle Valo75459e32014-02-13 18:13:12 +02003235exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236 mutex_unlock(&ar->conf_mutex);
3237}
3238
3239static int ath10k_hw_scan(struct ieee80211_hw *hw,
3240 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003241 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242{
3243 struct ath10k *ar = hw->priv;
3244 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003245 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003246 struct wmi_start_scan_arg arg;
3247 int ret = 0;
3248 int i;
3249
3250 mutex_lock(&ar->conf_mutex);
3251
3252 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003253 switch (ar->scan.state) {
3254 case ATH10K_SCAN_IDLE:
3255 reinit_completion(&ar->scan.started);
3256 reinit_completion(&ar->scan.completed);
3257 ar->scan.state = ATH10K_SCAN_STARTING;
3258 ar->scan.is_roc = false;
3259 ar->scan.vdev_id = arvif->vdev_id;
3260 ret = 0;
3261 break;
3262 case ATH10K_SCAN_STARTING:
3263 case ATH10K_SCAN_RUNNING:
3264 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003265 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003266 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003268 spin_unlock_bh(&ar->data_lock);
3269
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003270 if (ret)
3271 goto exit;
3272
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273 memset(&arg, 0, sizeof(arg));
3274 ath10k_wmi_start_scan_init(ar, &arg);
3275 arg.vdev_id = arvif->vdev_id;
3276 arg.scan_id = ATH10K_SCAN_ID;
3277
3278 if (!req->no_cck)
3279 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3280
3281 if (req->ie_len) {
3282 arg.ie_len = req->ie_len;
3283 memcpy(arg.ie, req->ie, arg.ie_len);
3284 }
3285
3286 if (req->n_ssids) {
3287 arg.n_ssids = req->n_ssids;
3288 for (i = 0; i < arg.n_ssids; i++) {
3289 arg.ssids[i].len = req->ssids[i].ssid_len;
3290 arg.ssids[i].ssid = req->ssids[i].ssid;
3291 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003292 } else {
3293 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294 }
3295
3296 if (req->n_channels) {
3297 arg.n_channels = req->n_channels;
3298 for (i = 0; i < arg.n_channels; i++)
3299 arg.channels[i] = req->channels[i]->center_freq;
3300 }
3301
3302 ret = ath10k_start_scan(ar, &arg);
3303 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003304 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003305 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003306 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003307 spin_unlock_bh(&ar->data_lock);
3308 }
3309
3310exit:
3311 mutex_unlock(&ar->conf_mutex);
3312 return ret;
3313}
3314
3315static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3316 struct ieee80211_vif *vif)
3317{
3318 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003319
3320 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003321 cancel_delayed_work_sync(&ar->scan.timeout);
3322 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003323 mutex_unlock(&ar->conf_mutex);
3324}
3325
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003326static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3327 struct ath10k_vif *arvif,
3328 enum set_key_cmd cmd,
3329 struct ieee80211_key_conf *key)
3330{
3331 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3332 int ret;
3333
3334 /* 10.1 firmware branch requires default key index to be set to group
3335 * key index after installing it. Otherwise FW/HW Txes corrupted
3336 * frames with multi-vif APs. This is not required for main firmware
3337 * branch (e.g. 636).
3338 *
3339 * FIXME: This has been tested only in AP. It remains unknown if this
3340 * is required for multi-vif STA interfaces on 10.1 */
3341
3342 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3343 return;
3344
3345 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3346 return;
3347
3348 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3349 return;
3350
3351 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3352 return;
3353
3354 if (cmd != SET_KEY)
3355 return;
3356
3357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3358 key->keyidx);
3359 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003360 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003361 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003362}
3363
Kalle Valo5e3dd152013-06-12 20:52:10 +03003364static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3365 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3366 struct ieee80211_key_conf *key)
3367{
3368 struct ath10k *ar = hw->priv;
3369 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3370 struct ath10k_peer *peer;
3371 const u8 *peer_addr;
3372 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3373 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3374 int ret = 0;
3375
3376 if (key->keyidx > WMI_MAX_KEY_INDEX)
3377 return -ENOSPC;
3378
3379 mutex_lock(&ar->conf_mutex);
3380
3381 if (sta)
3382 peer_addr = sta->addr;
3383 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3384 peer_addr = vif->bss_conf.bssid;
3385 else
3386 peer_addr = vif->addr;
3387
3388 key->hw_key_idx = key->keyidx;
3389
3390 /* the peer should not disappear in mid-way (unless FW goes awry) since
3391 * we already hold conf_mutex. we just make sure its there now. */
3392 spin_lock_bh(&ar->data_lock);
3393 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3394 spin_unlock_bh(&ar->data_lock);
3395
3396 if (!peer) {
3397 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003398 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003399 peer_addr);
3400 ret = -EOPNOTSUPP;
3401 goto exit;
3402 } else {
3403 /* if the peer doesn't exist there is no key to disable
3404 * anymore */
3405 goto exit;
3406 }
3407 }
3408
3409 if (is_wep) {
3410 if (cmd == SET_KEY)
3411 arvif->wep_keys[key->keyidx] = key;
3412 else
3413 arvif->wep_keys[key->keyidx] = NULL;
3414
3415 if (cmd == DISABLE_KEY)
3416 ath10k_clear_vdev_key(arvif, key);
3417 }
3418
3419 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3420 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003421 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003422 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003423 goto exit;
3424 }
3425
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003426 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3427
Kalle Valo5e3dd152013-06-12 20:52:10 +03003428 spin_lock_bh(&ar->data_lock);
3429 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3430 if (peer && cmd == SET_KEY)
3431 peer->keys[key->keyidx] = key;
3432 else if (peer && cmd == DISABLE_KEY)
3433 peer->keys[key->keyidx] = NULL;
3434 else if (peer == NULL)
3435 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003436 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003437 spin_unlock_bh(&ar->data_lock);
3438
3439exit:
3440 mutex_unlock(&ar->conf_mutex);
3441 return ret;
3442}
3443
Michal Kazior9797feb2014-02-14 14:49:48 +01003444static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3445{
3446 struct ath10k *ar;
3447 struct ath10k_vif *arvif;
3448 struct ath10k_sta *arsta;
3449 struct ieee80211_sta *sta;
3450 u32 changed, bw, nss, smps;
3451 int err;
3452
3453 arsta = container_of(wk, struct ath10k_sta, update_wk);
3454 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3455 arvif = arsta->arvif;
3456 ar = arvif->ar;
3457
3458 spin_lock_bh(&ar->data_lock);
3459
3460 changed = arsta->changed;
3461 arsta->changed = 0;
3462
3463 bw = arsta->bw;
3464 nss = arsta->nss;
3465 smps = arsta->smps;
3466
3467 spin_unlock_bh(&ar->data_lock);
3468
3469 mutex_lock(&ar->conf_mutex);
3470
3471 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003472 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003473 sta->addr, bw);
3474
3475 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3476 WMI_PEER_CHAN_WIDTH, bw);
3477 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003478 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003479 sta->addr, bw, err);
3480 }
3481
3482 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003483 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003484 sta->addr, nss);
3485
3486 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3487 WMI_PEER_NSS, nss);
3488 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003489 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003490 sta->addr, nss, err);
3491 }
3492
3493 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003494 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003495 sta->addr, smps);
3496
3497 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3498 WMI_PEER_SMPS_STATE, smps);
3499 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003500 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003501 sta->addr, smps, err);
3502 }
3503
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003504 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003505 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003506 sta->addr);
3507
3508 err = ath10k_station_assoc(ar, arvif, sta, true);
3509 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003510 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003511 sta->addr);
3512 }
3513
Michal Kazior9797feb2014-02-14 14:49:48 +01003514 mutex_unlock(&ar->conf_mutex);
3515}
3516
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517static int ath10k_sta_state(struct ieee80211_hw *hw,
3518 struct ieee80211_vif *vif,
3519 struct ieee80211_sta *sta,
3520 enum ieee80211_sta_state old_state,
3521 enum ieee80211_sta_state new_state)
3522{
3523 struct ath10k *ar = hw->priv;
3524 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003525 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003526 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003527 int ret = 0;
3528
Michal Kazior76f90022014-02-25 09:29:57 +02003529 if (old_state == IEEE80211_STA_NOTEXIST &&
3530 new_state == IEEE80211_STA_NONE) {
3531 memset(arsta, 0, sizeof(*arsta));
3532 arsta->arvif = arvif;
3533 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3534 }
3535
Michal Kazior9797feb2014-02-14 14:49:48 +01003536 /* cancel must be done outside the mutex to avoid deadlock */
3537 if ((old_state == IEEE80211_STA_NONE &&
3538 new_state == IEEE80211_STA_NOTEXIST))
3539 cancel_work_sync(&arsta->update_wk);
3540
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 mutex_lock(&ar->conf_mutex);
3542
3543 if (old_state == IEEE80211_STA_NOTEXIST &&
3544 new_state == IEEE80211_STA_NONE &&
3545 vif->type != NL80211_IFTYPE_STATION) {
3546 /*
3547 * New station addition.
3548 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003549 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3550 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3551 else
3552 max_num_peers = TARGET_NUM_PEERS;
3553
3554 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003555 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003556 ar->num_peers, max_num_peers);
3557 ret = -ENOBUFS;
3558 goto exit;
3559 }
3560
Michal Kazior7aa7a722014-08-25 12:09:38 +02003561 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003562 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3563 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003564
Kalle Valo5e3dd152013-06-12 20:52:10 +03003565 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3566 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003567 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 -08003568 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003569 } else if ((old_state == IEEE80211_STA_NONE &&
3570 new_state == IEEE80211_STA_NOTEXIST)) {
3571 /*
3572 * Existing station deletion.
3573 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003574 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003575 "mac vdev %d peer delete %pM (sta gone)\n",
3576 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3578 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003579 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003580 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003581
3582 if (vif->type == NL80211_IFTYPE_STATION)
3583 ath10k_bss_disassoc(hw, vif);
3584 } else if (old_state == IEEE80211_STA_AUTH &&
3585 new_state == IEEE80211_STA_ASSOC &&
3586 (vif->type == NL80211_IFTYPE_AP ||
3587 vif->type == NL80211_IFTYPE_ADHOC)) {
3588 /*
3589 * New association.
3590 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003591 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003592 sta->addr);
3593
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003594 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003595 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003596 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003597 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003598 } else if (old_state == IEEE80211_STA_ASSOC &&
3599 new_state == IEEE80211_STA_AUTH &&
3600 (vif->type == NL80211_IFTYPE_AP ||
3601 vif->type == NL80211_IFTYPE_ADHOC)) {
3602 /*
3603 * Disassociation.
3604 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003605 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003606 sta->addr);
3607
Kalle Valo5e3dd152013-06-12 20:52:10 +03003608 ret = ath10k_station_disassoc(ar, arvif, sta);
3609 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003610 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003611 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003612 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003613exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003614 mutex_unlock(&ar->conf_mutex);
3615 return ret;
3616}
3617
3618static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003619 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620{
3621 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3622 u32 value = 0;
3623 int ret = 0;
3624
Michal Kazior548db542013-07-05 16:15:15 +03003625 lockdep_assert_held(&ar->conf_mutex);
3626
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3628 return 0;
3629
3630 switch (ac) {
3631 case IEEE80211_AC_VO:
3632 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3633 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3634 break;
3635 case IEEE80211_AC_VI:
3636 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3637 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3638 break;
3639 case IEEE80211_AC_BE:
3640 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3641 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3642 break;
3643 case IEEE80211_AC_BK:
3644 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3645 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3646 break;
3647 }
3648
3649 if (enable)
3650 arvif->u.sta.uapsd |= value;
3651 else
3652 arvif->u.sta.uapsd &= ~value;
3653
3654 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3655 WMI_STA_PS_PARAM_UAPSD,
3656 arvif->u.sta.uapsd);
3657 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003658 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659 goto exit;
3660 }
3661
3662 if (arvif->u.sta.uapsd)
3663 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3664 else
3665 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3666
3667 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3668 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3669 value);
3670 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003671 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003672
3673exit:
3674 return ret;
3675}
3676
3677static int ath10k_conf_tx(struct ieee80211_hw *hw,
3678 struct ieee80211_vif *vif, u16 ac,
3679 const struct ieee80211_tx_queue_params *params)
3680{
3681 struct ath10k *ar = hw->priv;
3682 struct wmi_wmm_params_arg *p = NULL;
3683 int ret;
3684
3685 mutex_lock(&ar->conf_mutex);
3686
3687 switch (ac) {
3688 case IEEE80211_AC_VO:
3689 p = &ar->wmm_params.ac_vo;
3690 break;
3691 case IEEE80211_AC_VI:
3692 p = &ar->wmm_params.ac_vi;
3693 break;
3694 case IEEE80211_AC_BE:
3695 p = &ar->wmm_params.ac_be;
3696 break;
3697 case IEEE80211_AC_BK:
3698 p = &ar->wmm_params.ac_bk;
3699 break;
3700 }
3701
3702 if (WARN_ON(!p)) {
3703 ret = -EINVAL;
3704 goto exit;
3705 }
3706
3707 p->cwmin = params->cw_min;
3708 p->cwmax = params->cw_max;
3709 p->aifs = params->aifs;
3710
3711 /*
3712 * The channel time duration programmed in the HW is in absolute
3713 * microseconds, while mac80211 gives the txop in units of
3714 * 32 microseconds.
3715 */
3716 p->txop = params->txop * 32;
3717
3718 /* FIXME: FW accepts wmm params per hw, not per vif */
3719 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3720 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003721 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003722 goto exit;
3723 }
3724
3725 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3726 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003727 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003728
3729exit:
3730 mutex_unlock(&ar->conf_mutex);
3731 return ret;
3732}
3733
3734#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3735
3736static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3737 struct ieee80211_vif *vif,
3738 struct ieee80211_channel *chan,
3739 int duration,
3740 enum ieee80211_roc_type type)
3741{
3742 struct ath10k *ar = hw->priv;
3743 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3744 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003745 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003746
3747 mutex_lock(&ar->conf_mutex);
3748
3749 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003750 switch (ar->scan.state) {
3751 case ATH10K_SCAN_IDLE:
3752 reinit_completion(&ar->scan.started);
3753 reinit_completion(&ar->scan.completed);
3754 reinit_completion(&ar->scan.on_channel);
3755 ar->scan.state = ATH10K_SCAN_STARTING;
3756 ar->scan.is_roc = true;
3757 ar->scan.vdev_id = arvif->vdev_id;
3758 ar->scan.roc_freq = chan->center_freq;
3759 ret = 0;
3760 break;
3761 case ATH10K_SCAN_STARTING:
3762 case ATH10K_SCAN_RUNNING:
3763 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003764 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003765 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003766 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003767 spin_unlock_bh(&ar->data_lock);
3768
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003769 if (ret)
3770 goto exit;
3771
Kalle Valo5e3dd152013-06-12 20:52:10 +03003772 memset(&arg, 0, sizeof(arg));
3773 ath10k_wmi_start_scan_init(ar, &arg);
3774 arg.vdev_id = arvif->vdev_id;
3775 arg.scan_id = ATH10K_SCAN_ID;
3776 arg.n_channels = 1;
3777 arg.channels[0] = chan->center_freq;
3778 arg.dwell_time_active = duration;
3779 arg.dwell_time_passive = duration;
3780 arg.max_scan_time = 2 * duration;
3781 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3782 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3783
3784 ret = ath10k_start_scan(ar, &arg);
3785 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003786 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003787 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003788 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003789 spin_unlock_bh(&ar->data_lock);
3790 goto exit;
3791 }
3792
3793 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3794 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003795 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003796
3797 ret = ath10k_scan_stop(ar);
3798 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003799 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003800
Kalle Valo5e3dd152013-06-12 20:52:10 +03003801 ret = -ETIMEDOUT;
3802 goto exit;
3803 }
3804
3805 ret = 0;
3806exit:
3807 mutex_unlock(&ar->conf_mutex);
3808 return ret;
3809}
3810
3811static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3812{
3813 struct ath10k *ar = hw->priv;
3814
3815 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003816 cancel_delayed_work_sync(&ar->scan.timeout);
3817 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003818 mutex_unlock(&ar->conf_mutex);
3819
3820 return 0;
3821}
3822
3823/*
3824 * Both RTS and Fragmentation threshold are interface-specific
3825 * in ath10k, but device-specific in mac80211.
3826 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827
3828static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3829{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003830 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003831 struct ath10k_vif *arvif;
3832 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003833
Michal Kaziorad088bf2013-10-16 15:44:46 +03003834 mutex_lock(&ar->conf_mutex);
3835 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003836 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003837 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003838
Michal Kaziorad088bf2013-10-16 15:44:46 +03003839 ret = ath10k_mac_set_rts(arvif, value);
3840 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003841 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003842 arvif->vdev_id, ret);
3843 break;
3844 }
3845 }
3846 mutex_unlock(&ar->conf_mutex);
3847
3848 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849}
3850
3851static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3852{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003853 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003854 struct ath10k_vif *arvif;
3855 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003856
Kalle Valo5e3dd152013-06-12 20:52:10 +03003857 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003858 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003859 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003860 arvif->vdev_id, value);
3861
3862 ret = ath10k_mac_set_rts(arvif, value);
3863 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003864 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003865 arvif->vdev_id, ret);
3866 break;
3867 }
3868 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869 mutex_unlock(&ar->conf_mutex);
3870
Michal Kaziorad088bf2013-10-16 15:44:46 +03003871 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003872}
3873
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003874static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3875 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003876{
3877 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003878 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003879 int ret;
3880
3881 /* mac80211 doesn't care if we really xmit queued frames or not
3882 * we'll collect those frames either way if we stop/delete vdevs */
3883 if (drop)
3884 return;
3885
Michal Kazior548db542013-07-05 16:15:15 +03003886 mutex_lock(&ar->conf_mutex);
3887
Michal Kazioraffd3212013-07-16 09:54:35 +02003888 if (ar->state == ATH10K_STATE_WEDGED)
3889 goto skip;
3890
Michal Kazioredb82362013-07-05 16:15:14 +03003891 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003892 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003893
Michal Kazioredb82362013-07-05 16:15:14 +03003894 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003895 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003896 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003897
3898 skip = (ar->state == ATH10K_STATE_WEDGED);
3899
3900 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003901 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003902
3903 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003904 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003905 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003906
Michal Kazioraffd3212013-07-16 09:54:35 +02003907skip:
Michal Kazior548db542013-07-05 16:15:15 +03003908 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003909}
3910
3911/* TODO: Implement this function properly
3912 * For now it is needed to reply to Probe Requests in IBSS mode.
3913 * Propably we need this information from FW.
3914 */
3915static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3916{
3917 return 1;
3918}
3919
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003920#ifdef CONFIG_PM
3921static int ath10k_suspend(struct ieee80211_hw *hw,
3922 struct cfg80211_wowlan *wowlan)
3923{
3924 struct ath10k *ar = hw->priv;
3925 int ret;
3926
Marek Puzyniak9042e172014-02-10 17:14:23 +01003927 mutex_lock(&ar->conf_mutex);
3928
Marek Puzyniak00f54822014-02-10 17:14:24 +01003929 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003930 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003931 if (ret == -ETIMEDOUT)
3932 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003933 ret = 1;
3934 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003935 }
3936
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003937 ret = ath10k_hif_suspend(ar);
3938 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003939 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003940 goto resume;
3941 }
3942
Marek Puzyniak9042e172014-02-10 17:14:23 +01003943 ret = 0;
3944 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003945resume:
3946 ret = ath10k_wmi_pdev_resume_target(ar);
3947 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003948 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003949
3950 ret = 1;
3951exit:
3952 mutex_unlock(&ar->conf_mutex);
3953 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003954}
3955
3956static int ath10k_resume(struct ieee80211_hw *hw)
3957{
3958 struct ath10k *ar = hw->priv;
3959 int ret;
3960
Marek Puzyniak9042e172014-02-10 17:14:23 +01003961 mutex_lock(&ar->conf_mutex);
3962
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003963 ret = ath10k_hif_resume(ar);
3964 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003965 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003966 ret = 1;
3967 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003968 }
3969
3970 ret = ath10k_wmi_pdev_resume_target(ar);
3971 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003972 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003973 ret = 1;
3974 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003975 }
3976
Marek Puzyniak9042e172014-02-10 17:14:23 +01003977 ret = 0;
3978exit:
3979 mutex_unlock(&ar->conf_mutex);
3980 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003981}
3982#endif
3983
Michal Kazioraffd3212013-07-16 09:54:35 +02003984static void ath10k_restart_complete(struct ieee80211_hw *hw)
3985{
3986 struct ath10k *ar = hw->priv;
3987
3988 mutex_lock(&ar->conf_mutex);
3989
3990 /* If device failed to restart it will be in a different state, e.g.
3991 * ATH10K_STATE_WEDGED */
3992 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003993 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02003994 ar->state = ATH10K_STATE_ON;
3995 }
3996
3997 mutex_unlock(&ar->conf_mutex);
3998}
3999
Michal Kazior2e1dea42013-07-31 10:32:40 +02004000static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4001 struct survey_info *survey)
4002{
4003 struct ath10k *ar = hw->priv;
4004 struct ieee80211_supported_band *sband;
4005 struct survey_info *ar_survey = &ar->survey[idx];
4006 int ret = 0;
4007
4008 mutex_lock(&ar->conf_mutex);
4009
4010 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4011 if (sband && idx >= sband->n_channels) {
4012 idx -= sband->n_channels;
4013 sband = NULL;
4014 }
4015
4016 if (!sband)
4017 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4018
4019 if (!sband || idx >= sband->n_channels) {
4020 ret = -ENOENT;
4021 goto exit;
4022 }
4023
4024 spin_lock_bh(&ar->data_lock);
4025 memcpy(survey, ar_survey, sizeof(*survey));
4026 spin_unlock_bh(&ar->data_lock);
4027
4028 survey->channel = &sband->channels[idx];
4029
4030exit:
4031 mutex_unlock(&ar->conf_mutex);
4032 return ret;
4033}
4034
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004035/* Helper table for legacy fixed_rate/bitrate_mask */
4036static const u8 cck_ofdm_rate[] = {
4037 /* CCK */
4038 3, /* 1Mbps */
4039 2, /* 2Mbps */
4040 1, /* 5.5Mbps */
4041 0, /* 11Mbps */
4042 /* OFDM */
4043 3, /* 6Mbps */
4044 7, /* 9Mbps */
4045 2, /* 12Mbps */
4046 6, /* 18Mbps */
4047 1, /* 24Mbps */
4048 5, /* 36Mbps */
4049 0, /* 48Mbps */
4050 4, /* 54Mbps */
4051};
4052
4053/* Check if only one bit set */
4054static int ath10k_check_single_mask(u32 mask)
4055{
4056 int bit;
4057
4058 bit = ffs(mask);
4059 if (!bit)
4060 return 0;
4061
4062 mask &= ~BIT(bit - 1);
4063 if (mask)
4064 return 2;
4065
4066 return 1;
4067}
4068
4069static bool
4070ath10k_default_bitrate_mask(struct ath10k *ar,
4071 enum ieee80211_band band,
4072 const struct cfg80211_bitrate_mask *mask)
4073{
4074 u32 legacy = 0x00ff;
4075 u8 ht = 0xff, i;
4076 u16 vht = 0x3ff;
4077
4078 switch (band) {
4079 case IEEE80211_BAND_2GHZ:
4080 legacy = 0x00fff;
4081 vht = 0;
4082 break;
4083 case IEEE80211_BAND_5GHZ:
4084 break;
4085 default:
4086 return false;
4087 }
4088
4089 if (mask->control[band].legacy != legacy)
4090 return false;
4091
4092 for (i = 0; i < ar->num_rf_chains; i++)
4093 if (mask->control[band].ht_mcs[i] != ht)
4094 return false;
4095
4096 for (i = 0; i < ar->num_rf_chains; i++)
4097 if (mask->control[band].vht_mcs[i] != vht)
4098 return false;
4099
4100 return true;
4101}
4102
4103static bool
4104ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4105 enum ieee80211_band band,
4106 u8 *fixed_nss)
4107{
4108 int ht_nss = 0, vht_nss = 0, i;
4109
4110 /* check legacy */
4111 if (ath10k_check_single_mask(mask->control[band].legacy))
4112 return false;
4113
4114 /* check HT */
4115 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4116 if (mask->control[band].ht_mcs[i] == 0xff)
4117 continue;
4118 else if (mask->control[band].ht_mcs[i] == 0x00)
4119 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004120
4121 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004122 }
4123
4124 ht_nss = i;
4125
4126 /* check VHT */
4127 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4128 if (mask->control[band].vht_mcs[i] == 0x03ff)
4129 continue;
4130 else if (mask->control[band].vht_mcs[i] == 0x0000)
4131 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004132
4133 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004134 }
4135
4136 vht_nss = i;
4137
4138 if (ht_nss > 0 && vht_nss > 0)
4139 return false;
4140
4141 if (ht_nss)
4142 *fixed_nss = ht_nss;
4143 else if (vht_nss)
4144 *fixed_nss = vht_nss;
4145 else
4146 return false;
4147
4148 return true;
4149}
4150
4151static bool
4152ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4153 enum ieee80211_band band,
4154 enum wmi_rate_preamble *preamble)
4155{
4156 int legacy = 0, ht = 0, vht = 0, i;
4157
4158 *preamble = WMI_RATE_PREAMBLE_OFDM;
4159
4160 /* check legacy */
4161 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4162 if (legacy > 1)
4163 return false;
4164
4165 /* check HT */
4166 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4167 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4168 if (ht > 1)
4169 return false;
4170
4171 /* check VHT */
4172 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4173 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4174 if (vht > 1)
4175 return false;
4176
4177 /* Currently we support only one fixed_rate */
4178 if ((legacy + ht + vht) != 1)
4179 return false;
4180
4181 if (ht)
4182 *preamble = WMI_RATE_PREAMBLE_HT;
4183 else if (vht)
4184 *preamble = WMI_RATE_PREAMBLE_VHT;
4185
4186 return true;
4187}
4188
4189static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004190ath10k_bitrate_mask_rate(struct ath10k *ar,
4191 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004192 enum ieee80211_band band,
4193 u8 *fixed_rate,
4194 u8 *fixed_nss)
4195{
4196 u8 rate = 0, pream = 0, nss = 0, i;
4197 enum wmi_rate_preamble preamble;
4198
4199 /* Check if single rate correct */
4200 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4201 return false;
4202
4203 pream = preamble;
4204
4205 switch (preamble) {
4206 case WMI_RATE_PREAMBLE_CCK:
4207 case WMI_RATE_PREAMBLE_OFDM:
4208 i = ffs(mask->control[band].legacy) - 1;
4209
4210 if (band == IEEE80211_BAND_2GHZ && i < 4)
4211 pream = WMI_RATE_PREAMBLE_CCK;
4212
4213 if (band == IEEE80211_BAND_5GHZ)
4214 i += 4;
4215
4216 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4217 return false;
4218
4219 rate = cck_ofdm_rate[i];
4220 break;
4221 case WMI_RATE_PREAMBLE_HT:
4222 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4223 if (mask->control[band].ht_mcs[i])
4224 break;
4225
4226 if (i == IEEE80211_HT_MCS_MASK_LEN)
4227 return false;
4228
4229 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4230 nss = i;
4231 break;
4232 case WMI_RATE_PREAMBLE_VHT:
4233 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4234 if (mask->control[band].vht_mcs[i])
4235 break;
4236
4237 if (i == NL80211_VHT_NSS_MAX)
4238 return false;
4239
4240 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4241 nss = i;
4242 break;
4243 }
4244
4245 *fixed_nss = nss + 1;
4246 nss <<= 4;
4247 pream <<= 6;
4248
Michal Kazior7aa7a722014-08-25 12:09:38 +02004249 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 +01004250 pream, nss, rate);
4251
4252 *fixed_rate = pream | nss | rate;
4253
4254 return true;
4255}
4256
Michal Kazior7aa7a722014-08-25 12:09:38 +02004257static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4258 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004259 enum ieee80211_band band,
4260 u8 *fixed_rate,
4261 u8 *fixed_nss)
4262{
4263 /* First check full NSS mask, if we can simply limit NSS */
4264 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4265 return true;
4266
4267 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004268 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004269}
4270
4271static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4272 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004273 u8 fixed_nss,
4274 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004275{
4276 struct ath10k *ar = arvif->ar;
4277 u32 vdev_param;
4278 int ret = 0;
4279
4280 mutex_lock(&ar->conf_mutex);
4281
4282 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004283 arvif->fixed_nss == fixed_nss &&
4284 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004285 goto exit;
4286
4287 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004288 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004289
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004290 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004291 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004292
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004293 vdev_param = ar->wmi.vdev_param->fixed_rate;
4294 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4295 vdev_param, fixed_rate);
4296 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004297 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004298 fixed_rate, ret);
4299 ret = -EINVAL;
4300 goto exit;
4301 }
4302
4303 arvif->fixed_rate = fixed_rate;
4304
4305 vdev_param = ar->wmi.vdev_param->nss;
4306 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4307 vdev_param, fixed_nss);
4308
4309 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004310 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004311 fixed_nss, ret);
4312 ret = -EINVAL;
4313 goto exit;
4314 }
4315
4316 arvif->fixed_nss = fixed_nss;
4317
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004318 vdev_param = ar->wmi.vdev_param->sgi;
4319 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4320 force_sgi);
4321
4322 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004323 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004324 force_sgi, ret);
4325 ret = -EINVAL;
4326 goto exit;
4327 }
4328
4329 arvif->force_sgi = force_sgi;
4330
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004331exit:
4332 mutex_unlock(&ar->conf_mutex);
4333 return ret;
4334}
4335
4336static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4337 struct ieee80211_vif *vif,
4338 const struct cfg80211_bitrate_mask *mask)
4339{
4340 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4341 struct ath10k *ar = arvif->ar;
4342 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4343 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4344 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004345 u8 force_sgi;
4346
4347 force_sgi = mask->control[band].gi;
4348 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4349 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004350
4351 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004352 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004353 &fixed_rate,
4354 &fixed_nss))
4355 return -EINVAL;
4356 }
4357
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004358 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004359 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004360 return -EINVAL;
4361 }
4362
4363 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4364 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004365}
4366
Michal Kazior9797feb2014-02-14 14:49:48 +01004367static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4368 struct ieee80211_vif *vif,
4369 struct ieee80211_sta *sta,
4370 u32 changed)
4371{
4372 struct ath10k *ar = hw->priv;
4373 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4374 u32 bw, smps;
4375
4376 spin_lock_bh(&ar->data_lock);
4377
Michal Kazior7aa7a722014-08-25 12:09:38 +02004378 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004379 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4380 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4381 sta->smps_mode);
4382
4383 if (changed & IEEE80211_RC_BW_CHANGED) {
4384 bw = WMI_PEER_CHWIDTH_20MHZ;
4385
4386 switch (sta->bandwidth) {
4387 case IEEE80211_STA_RX_BW_20:
4388 bw = WMI_PEER_CHWIDTH_20MHZ;
4389 break;
4390 case IEEE80211_STA_RX_BW_40:
4391 bw = WMI_PEER_CHWIDTH_40MHZ;
4392 break;
4393 case IEEE80211_STA_RX_BW_80:
4394 bw = WMI_PEER_CHWIDTH_80MHZ;
4395 break;
4396 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004397 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004398 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004399 bw = WMI_PEER_CHWIDTH_20MHZ;
4400 break;
4401 }
4402
4403 arsta->bw = bw;
4404 }
4405
4406 if (changed & IEEE80211_RC_NSS_CHANGED)
4407 arsta->nss = sta->rx_nss;
4408
4409 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4410 smps = WMI_PEER_SMPS_PS_NONE;
4411
4412 switch (sta->smps_mode) {
4413 case IEEE80211_SMPS_AUTOMATIC:
4414 case IEEE80211_SMPS_OFF:
4415 smps = WMI_PEER_SMPS_PS_NONE;
4416 break;
4417 case IEEE80211_SMPS_STATIC:
4418 smps = WMI_PEER_SMPS_STATIC;
4419 break;
4420 case IEEE80211_SMPS_DYNAMIC:
4421 smps = WMI_PEER_SMPS_DYNAMIC;
4422 break;
4423 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004424 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004425 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004426 smps = WMI_PEER_SMPS_PS_NONE;
4427 break;
4428 }
4429
4430 arsta->smps = smps;
4431 }
4432
Michal Kazior9797feb2014-02-14 14:49:48 +01004433 arsta->changed |= changed;
4434
4435 spin_unlock_bh(&ar->data_lock);
4436
4437 ieee80211_queue_work(hw, &arsta->update_wk);
4438}
4439
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004440static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4441{
4442 /*
4443 * FIXME: Return 0 for time being. Need to figure out whether FW
4444 * has the API to fetch 64-bit local TSF
4445 */
4446
4447 return 0;
4448}
4449
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004450static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4451 struct ieee80211_vif *vif,
4452 enum ieee80211_ampdu_mlme_action action,
4453 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4454 u8 buf_size)
4455{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004456 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004457 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4458
Michal Kazior7aa7a722014-08-25 12:09:38 +02004459 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 +02004460 arvif->vdev_id, sta->addr, tid, action);
4461
4462 switch (action) {
4463 case IEEE80211_AMPDU_RX_START:
4464 case IEEE80211_AMPDU_RX_STOP:
4465 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4466 * creation/removal. Do we need to verify this?
4467 */
4468 return 0;
4469 case IEEE80211_AMPDU_TX_START:
4470 case IEEE80211_AMPDU_TX_STOP_CONT:
4471 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4472 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4473 case IEEE80211_AMPDU_TX_OPERATIONAL:
4474 /* Firmware offloads Tx aggregation entirely so deny mac80211
4475 * Tx aggregation requests.
4476 */
4477 return -EOPNOTSUPP;
4478 }
4479
4480 return -EINVAL;
4481}
4482
Kalle Valo5e3dd152013-06-12 20:52:10 +03004483static const struct ieee80211_ops ath10k_ops = {
4484 .tx = ath10k_tx,
4485 .start = ath10k_start,
4486 .stop = ath10k_stop,
4487 .config = ath10k_config,
4488 .add_interface = ath10k_add_interface,
4489 .remove_interface = ath10k_remove_interface,
4490 .configure_filter = ath10k_configure_filter,
4491 .bss_info_changed = ath10k_bss_info_changed,
4492 .hw_scan = ath10k_hw_scan,
4493 .cancel_hw_scan = ath10k_cancel_hw_scan,
4494 .set_key = ath10k_set_key,
4495 .sta_state = ath10k_sta_state,
4496 .conf_tx = ath10k_conf_tx,
4497 .remain_on_channel = ath10k_remain_on_channel,
4498 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4499 .set_rts_threshold = ath10k_set_rts_threshold,
4500 .set_frag_threshold = ath10k_set_frag_threshold,
4501 .flush = ath10k_flush,
4502 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004503 .set_antenna = ath10k_set_antenna,
4504 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004505 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004506 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004507 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004508 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004509 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004510 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004511 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4512 .get_et_stats = ath10k_debug_get_et_stats,
4513 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004514
4515 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4516
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004517#ifdef CONFIG_PM
4518 .suspend = ath10k_suspend,
4519 .resume = ath10k_resume,
4520#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004521};
4522
4523#define RATETAB_ENT(_rate, _rateid, _flags) { \
4524 .bitrate = (_rate), \
4525 .flags = (_flags), \
4526 .hw_value = (_rateid), \
4527}
4528
4529#define CHAN2G(_channel, _freq, _flags) { \
4530 .band = IEEE80211_BAND_2GHZ, \
4531 .hw_value = (_channel), \
4532 .center_freq = (_freq), \
4533 .flags = (_flags), \
4534 .max_antenna_gain = 0, \
4535 .max_power = 30, \
4536}
4537
4538#define CHAN5G(_channel, _freq, _flags) { \
4539 .band = IEEE80211_BAND_5GHZ, \
4540 .hw_value = (_channel), \
4541 .center_freq = (_freq), \
4542 .flags = (_flags), \
4543 .max_antenna_gain = 0, \
4544 .max_power = 30, \
4545}
4546
4547static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4548 CHAN2G(1, 2412, 0),
4549 CHAN2G(2, 2417, 0),
4550 CHAN2G(3, 2422, 0),
4551 CHAN2G(4, 2427, 0),
4552 CHAN2G(5, 2432, 0),
4553 CHAN2G(6, 2437, 0),
4554 CHAN2G(7, 2442, 0),
4555 CHAN2G(8, 2447, 0),
4556 CHAN2G(9, 2452, 0),
4557 CHAN2G(10, 2457, 0),
4558 CHAN2G(11, 2462, 0),
4559 CHAN2G(12, 2467, 0),
4560 CHAN2G(13, 2472, 0),
4561 CHAN2G(14, 2484, 0),
4562};
4563
4564static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004565 CHAN5G(36, 5180, 0),
4566 CHAN5G(40, 5200, 0),
4567 CHAN5G(44, 5220, 0),
4568 CHAN5G(48, 5240, 0),
4569 CHAN5G(52, 5260, 0),
4570 CHAN5G(56, 5280, 0),
4571 CHAN5G(60, 5300, 0),
4572 CHAN5G(64, 5320, 0),
4573 CHAN5G(100, 5500, 0),
4574 CHAN5G(104, 5520, 0),
4575 CHAN5G(108, 5540, 0),
4576 CHAN5G(112, 5560, 0),
4577 CHAN5G(116, 5580, 0),
4578 CHAN5G(120, 5600, 0),
4579 CHAN5G(124, 5620, 0),
4580 CHAN5G(128, 5640, 0),
4581 CHAN5G(132, 5660, 0),
4582 CHAN5G(136, 5680, 0),
4583 CHAN5G(140, 5700, 0),
4584 CHAN5G(149, 5745, 0),
4585 CHAN5G(153, 5765, 0),
4586 CHAN5G(157, 5785, 0),
4587 CHAN5G(161, 5805, 0),
4588 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004589};
4590
4591static struct ieee80211_rate ath10k_rates[] = {
4592 /* CCK */
4593 RATETAB_ENT(10, 0x82, 0),
4594 RATETAB_ENT(20, 0x84, 0),
4595 RATETAB_ENT(55, 0x8b, 0),
4596 RATETAB_ENT(110, 0x96, 0),
4597 /* OFDM */
4598 RATETAB_ENT(60, 0x0c, 0),
4599 RATETAB_ENT(90, 0x12, 0),
4600 RATETAB_ENT(120, 0x18, 0),
4601 RATETAB_ENT(180, 0x24, 0),
4602 RATETAB_ENT(240, 0x30, 0),
4603 RATETAB_ENT(360, 0x48, 0),
4604 RATETAB_ENT(480, 0x60, 0),
4605 RATETAB_ENT(540, 0x6c, 0),
4606};
4607
4608#define ath10k_a_rates (ath10k_rates + 4)
4609#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4610#define ath10k_g_rates (ath10k_rates + 0)
4611#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4612
Michal Kaziore7b54192014-08-07 11:03:27 +02004613struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004614{
4615 struct ieee80211_hw *hw;
4616 struct ath10k *ar;
4617
Michal Kaziore7b54192014-08-07 11:03:27 +02004618 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004619 if (!hw)
4620 return NULL;
4621
4622 ar = hw->priv;
4623 ar->hw = hw;
4624
4625 return ar;
4626}
4627
4628void ath10k_mac_destroy(struct ath10k *ar)
4629{
4630 ieee80211_free_hw(ar->hw);
4631}
4632
4633static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4634 {
4635 .max = 8,
4636 .types = BIT(NL80211_IFTYPE_STATION)
4637 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004638 },
4639 {
4640 .max = 3,
4641 .types = BIT(NL80211_IFTYPE_P2P_GO)
4642 },
4643 {
4644 .max = 7,
4645 .types = BIT(NL80211_IFTYPE_AP)
4646 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004647};
4648
Bartosz Markowskif2595092013-12-10 16:20:39 +01004649static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004650 {
4651 .max = 8,
4652 .types = BIT(NL80211_IFTYPE_AP)
4653 },
4654};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004655
4656static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4657 {
4658 .limits = ath10k_if_limits,
4659 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4660 .max_interfaces = 8,
4661 .num_different_channels = 1,
4662 .beacon_int_infra_match = true,
4663 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004664};
4665
4666static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004667 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004668 .limits = ath10k_10x_if_limits,
4669 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004670 .max_interfaces = 8,
4671 .num_different_channels = 1,
4672 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004673#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004674 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4675 BIT(NL80211_CHAN_WIDTH_20) |
4676 BIT(NL80211_CHAN_WIDTH_40) |
4677 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004678#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004679 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004680};
4681
4682static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4683{
4684 struct ieee80211_sta_vht_cap vht_cap = {0};
4685 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004686 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004687
4688 vht_cap.vht_supported = 1;
4689 vht_cap.cap = ar->vht_cap_info;
4690
Michal Kazior8865bee42013-07-24 12:36:46 +02004691 mcs_map = 0;
4692 for (i = 0; i < 8; i++) {
4693 if (i < ar->num_rf_chains)
4694 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4695 else
4696 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4697 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004698
4699 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4700 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4701
4702 return vht_cap;
4703}
4704
4705static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4706{
4707 int i;
4708 struct ieee80211_sta_ht_cap ht_cap = {0};
4709
4710 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4711 return ht_cap;
4712
4713 ht_cap.ht_supported = 1;
4714 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4715 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4716 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4717 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4718 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4719
4720 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4721 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4722
4723 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4724 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4725
4726 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4727 u32 smps;
4728
4729 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4730 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4731
4732 ht_cap.cap |= smps;
4733 }
4734
4735 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4736 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4737
4738 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4739 u32 stbc;
4740
4741 stbc = ar->ht_cap_info;
4742 stbc &= WMI_HT_CAP_RX_STBC;
4743 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4744 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4745 stbc &= IEEE80211_HT_CAP_RX_STBC;
4746
4747 ht_cap.cap |= stbc;
4748 }
4749
4750 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4751 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4752
4753 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4754 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4755
4756 /* max AMSDU is implicitly taken from vht_cap_info */
4757 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4758 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4759
Michal Kazior8865bee42013-07-24 12:36:46 +02004760 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004761 ht_cap.mcs.rx_mask[i] = 0xFF;
4762
4763 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4764
4765 return ht_cap;
4766}
4767
Kalle Valo5e3dd152013-06-12 20:52:10 +03004768static void ath10k_get_arvif_iter(void *data, u8 *mac,
4769 struct ieee80211_vif *vif)
4770{
4771 struct ath10k_vif_iter *arvif_iter = data;
4772 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4773
4774 if (arvif->vdev_id == arvif_iter->vdev_id)
4775 arvif_iter->arvif = arvif;
4776}
4777
4778struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4779{
4780 struct ath10k_vif_iter arvif_iter;
4781 u32 flags;
4782
4783 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4784 arvif_iter.vdev_id = vdev_id;
4785
4786 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4787 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4788 flags,
4789 ath10k_get_arvif_iter,
4790 &arvif_iter);
4791 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004792 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004793 return NULL;
4794 }
4795
4796 return arvif_iter.arvif;
4797}
4798
4799int ath10k_mac_register(struct ath10k *ar)
4800{
4801 struct ieee80211_supported_band *band;
4802 struct ieee80211_sta_vht_cap vht_cap;
4803 struct ieee80211_sta_ht_cap ht_cap;
4804 void *channels;
4805 int ret;
4806
4807 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4808
4809 SET_IEEE80211_DEV(ar->hw, ar->dev);
4810
4811 ht_cap = ath10k_get_ht_cap(ar);
4812 vht_cap = ath10k_create_vht_cap(ar);
4813
4814 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4815 channels = kmemdup(ath10k_2ghz_channels,
4816 sizeof(ath10k_2ghz_channels),
4817 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004818 if (!channels) {
4819 ret = -ENOMEM;
4820 goto err_free;
4821 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004822
4823 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4824 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4825 band->channels = channels;
4826 band->n_bitrates = ath10k_g_rates_size;
4827 band->bitrates = ath10k_g_rates;
4828 band->ht_cap = ht_cap;
4829
4830 /* vht is not supported in 2.4 GHz */
4831
4832 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4833 }
4834
4835 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4836 channels = kmemdup(ath10k_5ghz_channels,
4837 sizeof(ath10k_5ghz_channels),
4838 GFP_KERNEL);
4839 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004840 ret = -ENOMEM;
4841 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004842 }
4843
4844 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4845 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4846 band->channels = channels;
4847 band->n_bitrates = ath10k_a_rates_size;
4848 band->bitrates = ath10k_a_rates;
4849 band->ht_cap = ht_cap;
4850 band->vht_cap = vht_cap;
4851 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4852 }
4853
4854 ar->hw->wiphy->interface_modes =
4855 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004856 BIT(NL80211_IFTYPE_AP);
4857
Ben Greear46acf7b2014-05-16 17:15:38 +03004858 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4859 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4860
Bartosz Markowskid3541812013-12-10 16:20:40 +01004861 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4862 ar->hw->wiphy->interface_modes |=
4863 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4864 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004865
4866 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4867 IEEE80211_HW_SUPPORTS_PS |
4868 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4869 IEEE80211_HW_SUPPORTS_UAPSD |
4870 IEEE80211_HW_MFP_CAPABLE |
4871 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4872 IEEE80211_HW_HAS_RATE_CONTROL |
4873 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004874 IEEE80211_HW_AP_LINK_PS |
4875 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004876
Michal Kazior1f8bb152013-09-18 14:43:22 +02004877 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4878 * bytes is used for padding/alignment if necessary. */
4879 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4880
Kalle Valo5e3dd152013-06-12 20:52:10 +03004881 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4882 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4883
4884 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4885 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4886 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4887 }
4888
4889 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4890 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4891
4892 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004893 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004894
Kalle Valo5e3dd152013-06-12 20:52:10 +03004895 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4896
4897 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004898 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004899 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4900
4901 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4902 /*
4903 * on LL hardware queues are managed entirely by the FW
4904 * so we only advertise to mac we can do the queues thing
4905 */
4906 ar->hw->queues = 4;
4907
Bartosz Markowskif2595092013-12-10 16:20:39 +01004908 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4909 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4910 ar->hw->wiphy->n_iface_combinations =
4911 ARRAY_SIZE(ath10k_10x_if_comb);
4912 } else {
4913 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4914 ar->hw->wiphy->n_iface_combinations =
4915 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004916
4917 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004918 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004919
Michal Kazior7c199992013-07-31 10:47:57 +02004920 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4921
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004922 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4923 /* Init ath dfs pattern detector */
4924 ar->ath_common.debug_mask = ATH_DBG_DFS;
4925 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4926 NL80211_DFS_UNSET);
4927
4928 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004929 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004930 }
4931
Kalle Valo5e3dd152013-06-12 20:52:10 +03004932 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4933 ath10k_reg_notifier);
4934 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004935 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004936 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004937 }
4938
4939 ret = ieee80211_register_hw(ar->hw);
4940 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004941 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004942 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004943 }
4944
4945 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4946 ret = regulatory_hint(ar->hw->wiphy,
4947 ar->ath_common.regulatory.alpha2);
4948 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004949 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004950 }
4951
4952 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004953
4954err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004955 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004956err_free:
4957 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4958 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4959
Kalle Valo5e3dd152013-06-12 20:52:10 +03004960 return ret;
4961}
4962
4963void ath10k_mac_unregister(struct ath10k *ar)
4964{
4965 ieee80211_unregister_hw(ar->hw);
4966
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004967 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4968 ar->dfs_detector->exit(ar->dfs_detector);
4969
Kalle Valo5e3dd152013-06-12 20:52:10 +03004970 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4971 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4972
4973 SET_IEEE80211_DEV(ar->hw, NULL);
4974}