blob: 78726a9bb7f1d601de33cde41ef0212d7fcc021e [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
Michal Kaziorc930f742014-01-23 11:38:25 +0100995 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300996
997 return;
998 }
999
1000 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1001 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001002 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001003 self_peer, arvif->vdev_id, ret);
1004 return;
1005 }
1006
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001007 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1008 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001009 ATH10K_DEFAULT_ATIM);
1010 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001011 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001012 arvif->vdev_id, ret);
1013}
1014
1015/*
1016 * Review this when mac80211 gains per-interface powersave support.
1017 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001018static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001019{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001020 struct ath10k *ar = arvif->ar;
1021 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001022 enum wmi_sta_powersave_param param;
1023 enum wmi_sta_ps_mode psmode;
1024 int ret;
1025
Michal Kazior548db542013-07-05 16:15:15 +03001026 lockdep_assert_held(&arvif->ar->conf_mutex);
1027
Michal Kaziorad088bf2013-10-16 15:44:46 +03001028 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1029 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001030
1031 if (conf->flags & IEEE80211_CONF_PS) {
1032 psmode = WMI_STA_PS_MODE_ENABLED;
1033 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1034
Michal Kaziorad088bf2013-10-16 15:44:46 +03001035 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001036 conf->dynamic_ps_timeout);
1037 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001038 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001039 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001040 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001041 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001042 } else {
1043 psmode = WMI_STA_PS_MODE_DISABLED;
1044 }
1045
Michal Kazior7aa7a722014-08-25 12:09:38 +02001046 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001047 arvif->vdev_id, psmode ? "enable" : "disable");
1048
Michal Kaziorad088bf2013-10-16 15:44:46 +03001049 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1050 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001051 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001052 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001053 return ret;
1054 }
1055
1056 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001057}
1058
1059/**********************/
1060/* Station management */
1061/**********************/
1062
Michal Kazior590922a2014-10-21 10:10:29 +03001063static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1064 struct ieee80211_vif *vif)
1065{
1066 /* Some firmware revisions have unstable STA powersave when listen
1067 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1068 * generate NullFunc frames properly even if buffered frames have been
1069 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1070 * buffered frames. Often pinging the device from AP would simply fail.
1071 *
1072 * As a workaround set it to 1.
1073 */
1074 if (vif->type == NL80211_IFTYPE_STATION)
1075 return 1;
1076
1077 return ar->hw->conf.listen_interval;
1078}
1079
Kalle Valo5e3dd152013-06-12 20:52:10 +03001080static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001081 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001082 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001083 struct wmi_peer_assoc_complete_arg *arg)
1084{
Michal Kazior590922a2014-10-21 10:10:29 +03001085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1086
Michal Kazior548db542013-07-05 16:15:15 +03001087 lockdep_assert_held(&ar->conf_mutex);
1088
Kalle Valob25f32c2014-09-14 12:50:49 +03001089 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090 arg->vdev_id = arvif->vdev_id;
1091 arg->peer_aid = sta->aid;
1092 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001093 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001094 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001095 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001096}
1097
1098static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001099 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001100 struct wmi_peer_assoc_complete_arg *arg)
1101{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001102 struct ieee80211_bss_conf *info = &vif->bss_conf;
1103 struct cfg80211_bss *bss;
1104 const u8 *rsnie = NULL;
1105 const u8 *wpaie = NULL;
1106
Michal Kazior548db542013-07-05 16:15:15 +03001107 lockdep_assert_held(&ar->conf_mutex);
1108
Kalle Valo5e3dd152013-06-12 20:52:10 +03001109 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1110 info->bssid, NULL, 0, 0, 0);
1111 if (bss) {
1112 const struct cfg80211_bss_ies *ies;
1113
1114 rcu_read_lock();
1115 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1116
1117 ies = rcu_dereference(bss->ies);
1118
1119 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001120 WLAN_OUI_TYPE_MICROSOFT_WPA,
1121 ies->data,
1122 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 rcu_read_unlock();
1124 cfg80211_put_bss(ar->hw->wiphy, bss);
1125 }
1126
1127 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1128 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001129 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001130 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1131 }
1132
1133 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001134 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001135 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1136 }
1137}
1138
1139static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1140 struct ieee80211_sta *sta,
1141 struct wmi_peer_assoc_complete_arg *arg)
1142{
1143 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1144 const struct ieee80211_supported_band *sband;
1145 const struct ieee80211_rate *rates;
1146 u32 ratemask;
1147 int i;
1148
Michal Kazior548db542013-07-05 16:15:15 +03001149 lockdep_assert_held(&ar->conf_mutex);
1150
Kalle Valo5e3dd152013-06-12 20:52:10 +03001151 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1152 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1153 rates = sband->bitrates;
1154
1155 rateset->num_rates = 0;
1156
1157 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1158 if (!(ratemask & 1))
1159 continue;
1160
1161 rateset->rates[rateset->num_rates] = rates->hw_value;
1162 rateset->num_rates++;
1163 }
1164}
1165
1166static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1167 struct ieee80211_sta *sta,
1168 struct wmi_peer_assoc_complete_arg *arg)
1169{
1170 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001171 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001172 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001173
Michal Kazior548db542013-07-05 16:15:15 +03001174 lockdep_assert_held(&ar->conf_mutex);
1175
Kalle Valo5e3dd152013-06-12 20:52:10 +03001176 if (!ht_cap->ht_supported)
1177 return;
1178
1179 arg->peer_flags |= WMI_PEER_HT;
1180 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1181 ht_cap->ampdu_factor)) - 1;
1182
1183 arg->peer_mpdu_density =
1184 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1185
1186 arg->peer_ht_caps = ht_cap->cap;
1187 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1188
1189 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1190 arg->peer_flags |= WMI_PEER_LDPC;
1191
1192 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1193 arg->peer_flags |= WMI_PEER_40MHZ;
1194 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1195 }
1196
1197 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1198 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1199
1200 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1201 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1202
1203 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1204 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1205 arg->peer_flags |= WMI_PEER_STBC;
1206 }
1207
1208 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001209 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1210 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1211 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1212 arg->peer_rate_caps |= stbc;
1213 arg->peer_flags |= WMI_PEER_STBC;
1214 }
1215
Kalle Valo5e3dd152013-06-12 20:52:10 +03001216 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1217 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1218 else if (ht_cap->mcs.rx_mask[1])
1219 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1220
1221 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1222 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1223 arg->peer_ht_rates.rates[n++] = i;
1224
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001225 /*
1226 * This is a workaround for HT-enabled STAs which break the spec
1227 * and have no HT capabilities RX mask (no HT RX MCS map).
1228 *
1229 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1230 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1231 *
1232 * Firmware asserts if such situation occurs.
1233 */
1234 if (n == 0) {
1235 arg->peer_ht_rates.num_rates = 8;
1236 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1237 arg->peer_ht_rates.rates[i] = i;
1238 } else {
1239 arg->peer_ht_rates.num_rates = n;
1240 arg->peer_num_spatial_streams = sta->rx_nss;
1241 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001242
Michal Kazior7aa7a722014-08-25 12:09:38 +02001243 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001244 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001245 arg->peer_ht_rates.num_rates,
1246 arg->peer_num_spatial_streams);
1247}
1248
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001249static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1250 struct ath10k_vif *arvif,
1251 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001252{
1253 u32 uapsd = 0;
1254 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001255 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001256
Michal Kazior548db542013-07-05 16:15:15 +03001257 lockdep_assert_held(&ar->conf_mutex);
1258
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001260 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001261 sta->uapsd_queues, sta->max_sp);
1262
Kalle Valo5e3dd152013-06-12 20:52:10 +03001263 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1264 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1265 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1266 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1267 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1268 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1269 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1270 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1271 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1272 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1273 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1274 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1275
Kalle Valo5e3dd152013-06-12 20:52:10 +03001276 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1277 max_sp = sta->max_sp;
1278
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001279 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1280 sta->addr,
1281 WMI_AP_PS_PEER_PARAM_UAPSD,
1282 uapsd);
1283 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001284 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001285 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001286 return ret;
1287 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001288
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001289 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1290 sta->addr,
1291 WMI_AP_PS_PEER_PARAM_MAX_SP,
1292 max_sp);
1293 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001294 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001295 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001296 return ret;
1297 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001298
1299 /* TODO setup this based on STA listen interval and
1300 beacon interval. Currently we don't know
1301 sta->listen_interval - mac80211 patch required.
1302 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001303 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001304 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1305 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001306 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001307 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001308 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001309 return ret;
1310 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001311 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001312
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001313 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001314}
1315
1316static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1317 struct ieee80211_sta *sta,
1318 struct wmi_peer_assoc_complete_arg *arg)
1319{
1320 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001321 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001322
1323 if (!vht_cap->vht_supported)
1324 return;
1325
1326 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001327 arg->peer_vht_caps = vht_cap->cap;
1328
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001329 ampdu_factor = (vht_cap->cap &
1330 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1331 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1332
1333 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1334 * zero in VHT IE. Using it would result in degraded throughput.
1335 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1336 * it if VHT max_mpdu is smaller. */
1337 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1338 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1339 ampdu_factor)) - 1);
1340
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1342 arg->peer_flags |= WMI_PEER_80MHZ;
1343
1344 arg->peer_vht_rates.rx_max_rate =
1345 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1346 arg->peer_vht_rates.rx_mcs_set =
1347 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1348 arg->peer_vht_rates.tx_max_rate =
1349 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1350 arg->peer_vht_rates.tx_mcs_set =
1351 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1352
Michal Kazior7aa7a722014-08-25 12:09:38 +02001353 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001354 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355}
1356
1357static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001358 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001359 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001360 struct wmi_peer_assoc_complete_arg *arg)
1361{
Michal Kazior590922a2014-10-21 10:10:29 +03001362 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1363
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364 switch (arvif->vdev_type) {
1365 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001366 if (sta->wme)
1367 arg->peer_flags |= WMI_PEER_QOS;
1368
1369 if (sta->wme && sta->uapsd_queues) {
1370 arg->peer_flags |= WMI_PEER_APSD;
1371 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1372 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 break;
1374 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03001375 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001376 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 break;
1378 default:
1379 break;
1380 }
1381}
1382
1383static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001384 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001385 struct ieee80211_sta *sta,
1386 struct wmi_peer_assoc_complete_arg *arg)
1387{
1388 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1389
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390 switch (ar->hw->conf.chandef.chan->band) {
1391 case IEEE80211_BAND_2GHZ:
1392 if (sta->ht_cap.ht_supported) {
1393 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1394 phymode = MODE_11NG_HT40;
1395 else
1396 phymode = MODE_11NG_HT20;
1397 } else {
1398 phymode = MODE_11G;
1399 }
1400
1401 break;
1402 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001403 /*
1404 * Check VHT first.
1405 */
1406 if (sta->vht_cap.vht_supported) {
1407 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1408 phymode = MODE_11AC_VHT80;
1409 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1410 phymode = MODE_11AC_VHT40;
1411 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1412 phymode = MODE_11AC_VHT20;
1413 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001414 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1415 phymode = MODE_11NA_HT40;
1416 else
1417 phymode = MODE_11NA_HT20;
1418 } else {
1419 phymode = MODE_11A;
1420 }
1421
1422 break;
1423 default:
1424 break;
1425 }
1426
Michal Kazior7aa7a722014-08-25 12:09:38 +02001427 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001428 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001429
Kalle Valo5e3dd152013-06-12 20:52:10 +03001430 arg->peer_phymode = phymode;
1431 WARN_ON(phymode == MODE_UNKNOWN);
1432}
1433
Kalle Valob9ada652013-10-16 15:44:46 +03001434static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001435 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03001436 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03001437 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438{
Michal Kazior548db542013-07-05 16:15:15 +03001439 lockdep_assert_held(&ar->conf_mutex);
1440
Kalle Valob9ada652013-10-16 15:44:46 +03001441 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001442
Michal Kazior590922a2014-10-21 10:10:29 +03001443 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1444 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03001445 ath10k_peer_assoc_h_rates(ar, sta, arg);
1446 ath10k_peer_assoc_h_ht(ar, sta, arg);
1447 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03001448 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1449 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001450
Kalle Valob9ada652013-10-16 15:44:46 +03001451 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001452}
1453
Michal Kazior90046f52014-02-14 14:45:51 +01001454static const u32 ath10k_smps_map[] = {
1455 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1456 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1457 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1458 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1459};
1460
1461static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1462 const u8 *addr,
1463 const struct ieee80211_sta_ht_cap *ht_cap)
1464{
1465 int smps;
1466
1467 if (!ht_cap->ht_supported)
1468 return 0;
1469
1470 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1471 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1472
1473 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1474 return -EINVAL;
1475
1476 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1477 WMI_PEER_SMPS_STATE,
1478 ath10k_smps_map[smps]);
1479}
1480
Kalle Valo5e3dd152013-06-12 20:52:10 +03001481/* can be called only in mac80211 callbacks due to `key_count` usage */
1482static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1483 struct ieee80211_vif *vif,
1484 struct ieee80211_bss_conf *bss_conf)
1485{
1486 struct ath10k *ar = hw->priv;
1487 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001488 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001489 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001490 struct ieee80211_sta *ap_sta;
1491 int ret;
1492
Michal Kazior548db542013-07-05 16:15:15 +03001493 lockdep_assert_held(&ar->conf_mutex);
1494
Michal Kazior077efc82014-10-21 10:10:29 +03001495 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1496 arvif->vdev_id, arvif->bssid, arvif->aid);
1497
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498 rcu_read_lock();
1499
1500 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1501 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001502 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001503 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001504 rcu_read_unlock();
1505 return;
1506 }
1507
Michal Kazior90046f52014-02-14 14:45:51 +01001508 /* ap_sta must be accessed only within rcu section which must be left
1509 * before calling ath10k_setup_peer_smps() which might sleep. */
1510 ht_cap = ap_sta->ht_cap;
1511
Michal Kazior590922a2014-10-21 10:10:29 +03001512 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001513 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001514 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001515 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001516 rcu_read_unlock();
1517 return;
1518 }
1519
1520 rcu_read_unlock();
1521
Kalle Valob9ada652013-10-16 15:44:46 +03001522 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1523 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001524 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001525 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001526 return;
1527 }
1528
Michal Kazior90046f52014-02-14 14:45:51 +01001529 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1530 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001531 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001532 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001533 return;
1534 }
1535
Michal Kazior7aa7a722014-08-25 12:09:38 +02001536 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001537 "mac vdev %d up (associated) bssid %pM aid %d\n",
1538 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1539
Michal Kazior077efc82014-10-21 10:10:29 +03001540 WARN_ON(arvif->is_up);
1541
Michal Kaziorc930f742014-01-23 11:38:25 +01001542 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03001543 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001544
1545 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1546 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001547 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001549 return;
1550 }
1551
1552 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553}
1554
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1556 struct ieee80211_vif *vif)
1557{
1558 struct ath10k *ar = hw->priv;
1559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1560 int ret;
1561
Michal Kazior548db542013-07-05 16:15:15 +03001562 lockdep_assert_held(&ar->conf_mutex);
1563
Michal Kazior077efc82014-10-21 10:10:29 +03001564 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1565 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001566
Kalle Valo5e3dd152013-06-12 20:52:10 +03001567 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03001568 if (ret)
1569 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1570 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001571
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001572 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001573 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574}
1575
Michal Kazior590922a2014-10-21 10:10:29 +03001576static int ath10k_station_assoc(struct ath10k *ar,
1577 struct ieee80211_vif *vif,
1578 struct ieee80211_sta *sta,
1579 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001580{
Michal Kazior590922a2014-10-21 10:10:29 +03001581 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03001582 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 int ret = 0;
1584
Michal Kazior548db542013-07-05 16:15:15 +03001585 lockdep_assert_held(&ar->conf_mutex);
1586
Michal Kazior590922a2014-10-21 10:10:29 +03001587 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001588 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001589 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001590 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001591 return ret;
1592 }
1593
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001594 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001595 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001597 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001598 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 return ret;
1600 }
1601
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001602 /* Re-assoc is run only to update supported rates for given station. It
1603 * doesn't make much sense to reconfigure the peer completely.
1604 */
1605 if (!reassoc) {
1606 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1607 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001608 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001609 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001610 arvif->vdev_id, ret);
1611 return ret;
1612 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001613
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001614 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1615 if (ret) {
1616 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1617 sta->addr, arvif->vdev_id, ret);
1618 return ret;
1619 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001620
Michal Kaziorb1ecde32014-10-21 10:10:29 +03001621 if (!sta->wme) {
1622 arvif->num_legacy_stations++;
1623 ret = ath10k_recalc_rtscts_prot(arvif);
1624 if (ret) {
1625 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1626 arvif->vdev_id, ret);
1627 return ret;
1628 }
1629 }
1630
1631 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1632 if (ret) {
1633 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1634 arvif->vdev_id, ret);
1635 return ret;
1636 }
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001637 }
1638
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 return ret;
1640}
1641
Michal Kazior590922a2014-10-21 10:10:29 +03001642static int ath10k_station_disassoc(struct ath10k *ar,
1643 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 struct ieee80211_sta *sta)
1645{
Michal Kazior590922a2014-10-21 10:10:29 +03001646 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 int ret = 0;
1648
Michal Kazior548db542013-07-05 16:15:15 +03001649 lockdep_assert_held(&ar->conf_mutex);
1650
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001651 if (!sta->wme) {
1652 arvif->num_legacy_stations--;
1653 ret = ath10k_recalc_rtscts_prot(arvif);
1654 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001655 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001656 arvif->vdev_id, ret);
1657 return ret;
1658 }
1659 }
1660
Kalle Valo5e3dd152013-06-12 20:52:10 +03001661 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001663 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001664 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001665 return ret;
1666 }
1667
1668 return ret;
1669}
1670
1671/**************/
1672/* Regulatory */
1673/**************/
1674
1675static int ath10k_update_channel_list(struct ath10k *ar)
1676{
1677 struct ieee80211_hw *hw = ar->hw;
1678 struct ieee80211_supported_band **bands;
1679 enum ieee80211_band band;
1680 struct ieee80211_channel *channel;
1681 struct wmi_scan_chan_list_arg arg = {0};
1682 struct wmi_channel_arg *ch;
1683 bool passive;
1684 int len;
1685 int ret;
1686 int i;
1687
Michal Kazior548db542013-07-05 16:15:15 +03001688 lockdep_assert_held(&ar->conf_mutex);
1689
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690 bands = hw->wiphy->bands;
1691 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1692 if (!bands[band])
1693 continue;
1694
1695 for (i = 0; i < bands[band]->n_channels; i++) {
1696 if (bands[band]->channels[i].flags &
1697 IEEE80211_CHAN_DISABLED)
1698 continue;
1699
1700 arg.n_channels++;
1701 }
1702 }
1703
1704 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1705 arg.channels = kzalloc(len, GFP_KERNEL);
1706 if (!arg.channels)
1707 return -ENOMEM;
1708
1709 ch = arg.channels;
1710 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1711 if (!bands[band])
1712 continue;
1713
1714 for (i = 0; i < bands[band]->n_channels; i++) {
1715 channel = &bands[band]->channels[i];
1716
1717 if (channel->flags & IEEE80211_CHAN_DISABLED)
1718 continue;
1719
1720 ch->allow_ht = true;
1721
1722 /* FIXME: when should we really allow VHT? */
1723 ch->allow_vht = true;
1724
1725 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001726 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001727
1728 ch->ht40plus =
1729 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1730
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001731 ch->chan_radar =
1732 !!(channel->flags & IEEE80211_CHAN_RADAR);
1733
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001734 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735 ch->passive = passive;
1736
1737 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02001738 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001739 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001740 ch->max_power = channel->max_power * 2;
1741 ch->max_reg_power = channel->max_reg_power * 2;
1742 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743 ch->reg_class_id = 0; /* FIXME */
1744
1745 /* FIXME: why use only legacy modes, why not any
1746 * HT/VHT modes? Would that even make any
1747 * difference? */
1748 if (channel->band == IEEE80211_BAND_2GHZ)
1749 ch->mode = MODE_11G;
1750 else
1751 ch->mode = MODE_11A;
1752
1753 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1754 continue;
1755
Michal Kazior7aa7a722014-08-25 12:09:38 +02001756 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001757 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1758 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759 ch->freq, ch->max_power, ch->max_reg_power,
1760 ch->max_antenna_gain, ch->mode);
1761
1762 ch++;
1763 }
1764 }
1765
1766 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1767 kfree(arg.channels);
1768
1769 return ret;
1770}
1771
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001772static enum wmi_dfs_region
1773ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1774{
1775 switch (dfs_region) {
1776 case NL80211_DFS_UNSET:
1777 return WMI_UNINIT_DFS_DOMAIN;
1778 case NL80211_DFS_FCC:
1779 return WMI_FCC_DFS_DOMAIN;
1780 case NL80211_DFS_ETSI:
1781 return WMI_ETSI_DFS_DOMAIN;
1782 case NL80211_DFS_JP:
1783 return WMI_MKK4_DFS_DOMAIN;
1784 }
1785 return WMI_UNINIT_DFS_DOMAIN;
1786}
1787
Michal Kaziorf7843d72013-07-16 09:38:52 +02001788static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001792 enum wmi_dfs_region wmi_dfs_reg;
1793 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001794
Michal Kaziorf7843d72013-07-16 09:38:52 +02001795 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001796
1797 ret = ath10k_update_channel_list(ar);
1798 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001799 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800
1801 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001802
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001803 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1804 nl_dfs_reg = ar->dfs_detector->region;
1805 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1806 } else {
1807 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1808 }
1809
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810 /* Target allows setting up per-band regdomain but ath_common provides
1811 * a combined one only */
1812 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001813 regpair->reg_domain,
1814 regpair->reg_domain, /* 2ghz */
1815 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001817 regpair->reg_5ghz_ctl,
1818 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001821}
Michal Kazior548db542013-07-05 16:15:15 +03001822
Michal Kaziorf7843d72013-07-16 09:38:52 +02001823static void ath10k_reg_notifier(struct wiphy *wiphy,
1824 struct regulatory_request *request)
1825{
1826 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1827 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001828 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001829
1830 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1831
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001832 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001833 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001834 request->dfs_region);
1835 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1836 request->dfs_region);
1837 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001838 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001839 request->dfs_region);
1840 }
1841
Michal Kaziorf7843d72013-07-16 09:38:52 +02001842 mutex_lock(&ar->conf_mutex);
1843 if (ar->state == ATH10K_STATE_ON)
1844 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001845 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001846}
1847
1848/***************/
1849/* TX handlers */
1850/***************/
1851
Michal Kazior42c3aa62013-10-02 11:03:38 +02001852static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1853{
1854 if (ieee80211_is_mgmt(hdr->frame_control))
1855 return HTT_DATA_TX_EXT_TID_MGMT;
1856
1857 if (!ieee80211_is_data_qos(hdr->frame_control))
1858 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1859
1860 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1861 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1862
1863 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1864}
1865
Michal Kazior2b37c292014-09-02 11:00:22 +03001866static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001867{
Michal Kazior2b37c292014-09-02 11:00:22 +03001868 if (vif)
1869 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001870
Michal Kazior1bbc0972014-04-08 09:45:47 +03001871 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001872 return ar->monitor_vdev_id;
1873
Michal Kazior7aa7a722014-08-25 12:09:38 +02001874 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001875 return 0;
1876}
1877
Michal Kazior4b604552014-07-21 21:03:09 +03001878/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1879 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001880 */
Michal Kazior4b604552014-07-21 21:03:09 +03001881static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001882{
1883 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001884 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001885 u8 *qos_ctl;
1886
1887 if (!ieee80211_is_data_qos(hdr->frame_control))
1888 return;
1889
1890 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001891 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1892 skb->data, (void *)qos_ctl - (void *)skb->data);
1893 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001894
1895 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1896 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1897 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1898 * it is safe to downgrade to NullFunc.
1899 */
1900 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1901 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1902 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1903 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001904}
1905
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001906static void ath10k_tx_wep_key_work(struct work_struct *work)
1907{
1908 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1909 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001910 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001911 int ret, keyidx = arvif->def_wep_key_newidx;
1912
Michal Kazior911e6c02014-05-26 12:46:03 +03001913 mutex_lock(&arvif->ar->conf_mutex);
1914
1915 if (arvif->ar->state != ATH10K_STATE_ON)
1916 goto unlock;
1917
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001918 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001919 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001920
Michal Kazior7aa7a722014-08-25 12:09:38 +02001921 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001922 arvif->vdev_id, keyidx);
1923
1924 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1925 arvif->vdev_id,
1926 arvif->ar->wmi.vdev_param->def_keyid,
1927 keyidx);
1928 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001929 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001930 arvif->vdev_id,
1931 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001932 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001933 }
1934
1935 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001936
1937unlock:
1938 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001939}
1940
Michal Kazior4b604552014-07-21 21:03:09 +03001941static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1942 struct ieee80211_key_conf *key,
1943 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1946 struct ath10k *ar = arvif->ar;
1947 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949 if (!ieee80211_has_protected(hdr->frame_control))
1950 return;
1951
1952 if (!key)
1953 return;
1954
1955 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1956 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1957 return;
1958
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001959 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960 return;
1961
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001962 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1963 * queueing frames until key index is updated is not an option because
1964 * sk_buff may need more processing to be done, e.g. offchannel */
1965 arvif->def_wep_key_newidx = key->keyidx;
1966 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967}
1968
Michal Kazior4b604552014-07-21 21:03:09 +03001969static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1970 struct ieee80211_vif *vif,
1971 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972{
1973 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001974 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1975
1976 /* This is case only for P2P_GO */
1977 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1978 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1979 return;
1980
1981 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1982 spin_lock_bh(&ar->data_lock);
1983 if (arvif->u.ap.noa_data)
1984 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1985 GFP_ATOMIC))
1986 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1987 arvif->u.ap.noa_data,
1988 arvif->u.ap.noa_len);
1989 spin_unlock_bh(&ar->data_lock);
1990 }
1991}
1992
1993static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1994{
1995 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001996 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001997
Michal Kazior961d4c32013-08-09 10:13:34 +02001998 if (ar->htt.target_version_major >= 3) {
1999 /* Since HTT 3.0 there is no separate mgmt tx command */
2000 ret = ath10k_htt_tx(&ar->htt, skb);
2001 goto exit;
2002 }
2003
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002004 if (ieee80211_is_mgmt(hdr->frame_control)) {
2005 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2006 ar->fw_features)) {
2007 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2008 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002009 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002010 ret = -EBUSY;
2011 goto exit;
2012 }
2013
2014 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2015 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2016 } else {
2017 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2018 }
2019 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2020 ar->fw_features) &&
2021 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002022 /* FW does not report tx status properly for NullFunc frames
2023 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002024 * those frames when it detects link/beacon loss and depends
2025 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002026 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002027 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002028 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002029 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002030
Michal Kazior961d4c32013-08-09 10:13:34 +02002031exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002032 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002033 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2034 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002035 ieee80211_free_txskb(ar->hw, skb);
2036 }
2037}
2038
2039void ath10k_offchan_tx_purge(struct ath10k *ar)
2040{
2041 struct sk_buff *skb;
2042
2043 for (;;) {
2044 skb = skb_dequeue(&ar->offchan_tx_queue);
2045 if (!skb)
2046 break;
2047
2048 ieee80211_free_txskb(ar->hw, skb);
2049 }
2050}
2051
2052void ath10k_offchan_tx_work(struct work_struct *work)
2053{
2054 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2055 struct ath10k_peer *peer;
2056 struct ieee80211_hdr *hdr;
2057 struct sk_buff *skb;
2058 const u8 *peer_addr;
2059 int vdev_id;
2060 int ret;
2061
2062 /* FW requirement: We must create a peer before FW will send out
2063 * an offchannel frame. Otherwise the frame will be stuck and
2064 * never transmitted. We delete the peer upon tx completion.
2065 * It is unlikely that a peer for offchannel tx will already be
2066 * present. However it may be in some rare cases so account for that.
2067 * Otherwise we might remove a legitimate peer and break stuff. */
2068
2069 for (;;) {
2070 skb = skb_dequeue(&ar->offchan_tx_queue);
2071 if (!skb)
2072 break;
2073
2074 mutex_lock(&ar->conf_mutex);
2075
Michal Kazior7aa7a722014-08-25 12:09:38 +02002076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077 skb);
2078
2079 hdr = (struct ieee80211_hdr *)skb->data;
2080 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002081 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002082
2083 spin_lock_bh(&ar->data_lock);
2084 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2085 spin_unlock_bh(&ar->data_lock);
2086
2087 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002088 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002089 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090 peer_addr, vdev_id);
2091
2092 if (!peer) {
2093 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2094 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002095 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 peer_addr, vdev_id, ret);
2097 }
2098
2099 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002100 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002101 ar->offchan_tx_skb = skb;
2102 spin_unlock_bh(&ar->data_lock);
2103
2104 ath10k_tx_htt(ar, skb);
2105
2106 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2107 3 * HZ);
2108 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002109 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110 skb);
2111
2112 if (!peer) {
2113 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2114 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002115 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116 peer_addr, vdev_id, ret);
2117 }
2118
2119 mutex_unlock(&ar->conf_mutex);
2120 }
2121}
2122
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002123void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2124{
2125 struct sk_buff *skb;
2126
2127 for (;;) {
2128 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2129 if (!skb)
2130 break;
2131
2132 ieee80211_free_txskb(ar->hw, skb);
2133 }
2134}
2135
2136void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2137{
2138 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2139 struct sk_buff *skb;
2140 int ret;
2141
2142 for (;;) {
2143 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2144 if (!skb)
2145 break;
2146
2147 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002148 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002149 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002150 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002151 ieee80211_free_txskb(ar->hw, skb);
2152 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002153 }
2154}
2155
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156/************/
2157/* Scanning */
2158/************/
2159
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002160void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002161{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002162 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002164 switch (ar->scan.state) {
2165 case ATH10K_SCAN_IDLE:
2166 break;
2167 case ATH10K_SCAN_RUNNING:
2168 case ATH10K_SCAN_ABORTING:
2169 if (ar->scan.is_roc)
2170 ieee80211_remain_on_channel_expired(ar->hw);
2171 else
2172 ieee80211_scan_completed(ar->hw,
2173 (ar->scan.state ==
2174 ATH10K_SCAN_ABORTING));
2175 /* fall through */
2176 case ATH10K_SCAN_STARTING:
2177 ar->scan.state = ATH10K_SCAN_IDLE;
2178 ar->scan_channel = NULL;
2179 ath10k_offchan_tx_purge(ar);
2180 cancel_delayed_work(&ar->scan.timeout);
2181 complete_all(&ar->scan.completed);
2182 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002184}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002186void ath10k_scan_finish(struct ath10k *ar)
2187{
2188 spin_lock_bh(&ar->data_lock);
2189 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002190 spin_unlock_bh(&ar->data_lock);
2191}
2192
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002193static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002194{
2195 struct wmi_stop_scan_arg arg = {
2196 .req_id = 1, /* FIXME */
2197 .req_type = WMI_SCAN_STOP_ONE,
2198 .u.scan_id = ATH10K_SCAN_ID,
2199 };
2200 int ret;
2201
2202 lockdep_assert_held(&ar->conf_mutex);
2203
Kalle Valo5e3dd152013-06-12 20:52:10 +03002204 ret = ath10k_wmi_stop_scan(ar, &arg);
2205 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002206 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002207 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208 }
2209
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002211 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002212 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002213 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002214 } else if (ret > 0) {
2215 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002217
2218out:
2219 /* Scan state should be updated upon scan completion but in case
2220 * firmware fails to deliver the event (for whatever reason) it is
2221 * desired to clean up scan state anyway. Firmware may have just
2222 * dropped the scan completion event delivery due to transport pipe
2223 * being overflown with data and/or it can recover on its own before
2224 * next scan request is submitted.
2225 */
2226 spin_lock_bh(&ar->data_lock);
2227 if (ar->scan.state != ATH10K_SCAN_IDLE)
2228 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002229 spin_unlock_bh(&ar->data_lock);
2230
2231 return ret;
2232}
2233
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002234static void ath10k_scan_abort(struct ath10k *ar)
2235{
2236 int ret;
2237
2238 lockdep_assert_held(&ar->conf_mutex);
2239
2240 spin_lock_bh(&ar->data_lock);
2241
2242 switch (ar->scan.state) {
2243 case ATH10K_SCAN_IDLE:
2244 /* This can happen if timeout worker kicked in and called
2245 * abortion while scan completion was being processed.
2246 */
2247 break;
2248 case ATH10K_SCAN_STARTING:
2249 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002250 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002251 ath10k_scan_state_str(ar->scan.state),
2252 ar->scan.state);
2253 break;
2254 case ATH10K_SCAN_RUNNING:
2255 ar->scan.state = ATH10K_SCAN_ABORTING;
2256 spin_unlock_bh(&ar->data_lock);
2257
2258 ret = ath10k_scan_stop(ar);
2259 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002260 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002261
2262 spin_lock_bh(&ar->data_lock);
2263 break;
2264 }
2265
2266 spin_unlock_bh(&ar->data_lock);
2267}
2268
2269void ath10k_scan_timeout_work(struct work_struct *work)
2270{
2271 struct ath10k *ar = container_of(work, struct ath10k,
2272 scan.timeout.work);
2273
2274 mutex_lock(&ar->conf_mutex);
2275 ath10k_scan_abort(ar);
2276 mutex_unlock(&ar->conf_mutex);
2277}
2278
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279static int ath10k_start_scan(struct ath10k *ar,
2280 const struct wmi_start_scan_arg *arg)
2281{
2282 int ret;
2283
2284 lockdep_assert_held(&ar->conf_mutex);
2285
2286 ret = ath10k_wmi_start_scan(ar, arg);
2287 if (ret)
2288 return ret;
2289
Kalle Valo5e3dd152013-06-12 20:52:10 +03002290 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2291 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002292 ret = ath10k_scan_stop(ar);
2293 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002294 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002295
2296 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002297 }
2298
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002299 /* Add a 200ms margin to account for event/command processing */
2300 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2301 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002302 return 0;
2303}
2304
2305/**********************/
2306/* mac80211 callbacks */
2307/**********************/
2308
2309static void ath10k_tx(struct ieee80211_hw *hw,
2310 struct ieee80211_tx_control *control,
2311 struct sk_buff *skb)
2312{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002313 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002314 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2315 struct ieee80211_vif *vif = info->control.vif;
2316 struct ieee80211_key_conf *key = info->control.hw_key;
2317 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002318
2319 /* We should disable CCK RATE due to P2P */
2320 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002321 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322
Michal Kazior4b604552014-07-21 21:03:09 +03002323 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2324 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002325 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002326
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002327 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002328 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2329 ath10k_tx_h_nwifi(hw, skb);
2330 ath10k_tx_h_update_wep_key(vif, key, skb);
2331 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2332 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002333 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2336 spin_lock_bh(&ar->data_lock);
2337 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002338 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339 spin_unlock_bh(&ar->data_lock);
2340
Michal Kazior7aa7a722014-08-25 12:09:38 +02002341 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2342 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343
2344 skb_queue_tail(&ar->offchan_tx_queue, skb);
2345 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2346 return;
2347 }
2348
2349 ath10k_tx_htt(ar, skb);
2350}
2351
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002352/* Must not be called with conf_mutex held as workers can use that also. */
2353static void ath10k_drain_tx(struct ath10k *ar)
2354{
2355 /* make sure rcu-protected mac80211 tx path itself is drained */
2356 synchronize_net();
2357
2358 ath10k_offchan_tx_purge(ar);
2359 ath10k_mgmt_over_wmi_tx_purge(ar);
2360
2361 cancel_work_sync(&ar->offchan_tx_work);
2362 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2363}
2364
Michal Kazioraffd3212013-07-16 09:54:35 +02002365void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002366{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002367 struct ath10k_vif *arvif;
2368
Michal Kazior818bdd12013-07-16 09:38:57 +02002369 lockdep_assert_held(&ar->conf_mutex);
2370
Michal Kazior19337472014-08-28 12:58:16 +02002371 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2372 ar->filter_flags = 0;
2373 ar->monitor = false;
2374
2375 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002376 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002377
2378 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002379
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002380 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002381 ath10k_peer_cleanup_all(ar);
2382 ath10k_core_stop(ar);
2383 ath10k_hif_power_down(ar);
2384
2385 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002386 list_for_each_entry(arvif, &ar->arvifs, list)
2387 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02002388 spin_unlock_bh(&ar->data_lock);
2389}
2390
Ben Greear46acf7b2014-05-16 17:15:38 +03002391static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2392{
2393 struct ath10k *ar = hw->priv;
2394
2395 mutex_lock(&ar->conf_mutex);
2396
2397 if (ar->cfg_tx_chainmask) {
2398 *tx_ant = ar->cfg_tx_chainmask;
2399 *rx_ant = ar->cfg_rx_chainmask;
2400 } else {
2401 *tx_ant = ar->supp_tx_chainmask;
2402 *rx_ant = ar->supp_rx_chainmask;
2403 }
2404
2405 mutex_unlock(&ar->conf_mutex);
2406
2407 return 0;
2408}
2409
2410static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2411{
2412 int ret;
2413
2414 lockdep_assert_held(&ar->conf_mutex);
2415
2416 ar->cfg_tx_chainmask = tx_ant;
2417 ar->cfg_rx_chainmask = rx_ant;
2418
2419 if ((ar->state != ATH10K_STATE_ON) &&
2420 (ar->state != ATH10K_STATE_RESTARTED))
2421 return 0;
2422
2423 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2424 tx_ant);
2425 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002426 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002427 ret, tx_ant);
2428 return ret;
2429 }
2430
2431 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2432 rx_ant);
2433 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002434 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002435 ret, rx_ant);
2436 return ret;
2437 }
2438
2439 return 0;
2440}
2441
2442static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2443{
2444 struct ath10k *ar = hw->priv;
2445 int ret;
2446
2447 mutex_lock(&ar->conf_mutex);
2448 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2449 mutex_unlock(&ar->conf_mutex);
2450 return ret;
2451}
2452
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453static int ath10k_start(struct ieee80211_hw *hw)
2454{
2455 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002456 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002458 /*
2459 * This makes sense only when restarting hw. It is harmless to call
2460 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2461 * commands will be submitted while restarting.
2462 */
2463 ath10k_drain_tx(ar);
2464
Michal Kazior548db542013-07-05 16:15:15 +03002465 mutex_lock(&ar->conf_mutex);
2466
Michal Kaziorc5058f52014-05-26 12:46:03 +03002467 switch (ar->state) {
2468 case ATH10K_STATE_OFF:
2469 ar->state = ATH10K_STATE_ON;
2470 break;
2471 case ATH10K_STATE_RESTARTING:
2472 ath10k_halt(ar);
2473 ar->state = ATH10K_STATE_RESTARTED;
2474 break;
2475 case ATH10K_STATE_ON:
2476 case ATH10K_STATE_RESTARTED:
2477 case ATH10K_STATE_WEDGED:
2478 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002479 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002480 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002481 case ATH10K_STATE_UTF:
2482 ret = -EBUSY;
2483 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002484 }
2485
2486 ret = ath10k_hif_power_up(ar);
2487 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002488 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002489 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002490 }
2491
Kalle Valo43d2a302014-09-10 18:23:30 +03002492 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002493 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002494 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002495 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002496 }
2497
Bartosz Markowski226a3392013-09-26 17:47:16 +02002498 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002499 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002500 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002501 goto err_core_stop;
2502 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002503
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002504 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002506 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002507 goto err_core_stop;
2508 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509
Ben Greear46acf7b2014-05-16 17:15:38 +03002510 if (ar->cfg_tx_chainmask)
2511 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2512 ar->cfg_rx_chainmask);
2513
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002514 /*
2515 * By default FW set ARP frames ac to voice (6). In that case ARP
2516 * exchange is not working properly for UAPSD enabled AP. ARP requests
2517 * which arrives with access category 0 are processed by network stack
2518 * and send back with access category 0, but FW changes access category
2519 * to 6. Set ARP frames access category to best effort (0) solves
2520 * this problem.
2521 */
2522
2523 ret = ath10k_wmi_pdev_set_param(ar,
2524 ar->wmi.pdev_param->arp_ac_override, 0);
2525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002526 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002527 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002528 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002529 }
2530
Michal Kaziord6500972014-04-08 09:56:09 +03002531 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002532 ath10k_regd_update(ar);
2533
Simon Wunderlich855aed12014-08-02 09:12:54 +03002534 ath10k_spectral_start(ar);
2535
Michal Kaziorae254432014-05-26 12:46:02 +03002536 mutex_unlock(&ar->conf_mutex);
2537 return 0;
2538
2539err_core_stop:
2540 ath10k_core_stop(ar);
2541
2542err_power_down:
2543 ath10k_hif_power_down(ar);
2544
2545err_off:
2546 ar->state = ATH10K_STATE_OFF;
2547
2548err:
Michal Kazior548db542013-07-05 16:15:15 +03002549 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002550 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551}
2552
2553static void ath10k_stop(struct ieee80211_hw *hw)
2554{
2555 struct ath10k *ar = hw->priv;
2556
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002557 ath10k_drain_tx(ar);
2558
Michal Kazior548db542013-07-05 16:15:15 +03002559 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002560 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002561 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002562 ar->state = ATH10K_STATE_OFF;
2563 }
Michal Kazior548db542013-07-05 16:15:15 +03002564 mutex_unlock(&ar->conf_mutex);
2565
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002566 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002567 cancel_work_sync(&ar->restart_work);
2568}
2569
Michal Kaziorad088bf2013-10-16 15:44:46 +03002570static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002571{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002572 struct ath10k_vif *arvif;
2573 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002574
2575 lockdep_assert_held(&ar->conf_mutex);
2576
Michal Kaziorad088bf2013-10-16 15:44:46 +03002577 list_for_each_entry(arvif, &ar->arvifs, list) {
2578 ret = ath10k_mac_vif_setup_ps(arvif);
2579 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002580 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002581 break;
2582 }
2583 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002584
Michal Kaziorad088bf2013-10-16 15:44:46 +03002585 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586}
2587
Michal Kaziorc930f742014-01-23 11:38:25 +01002588static const char *chandef_get_width(enum nl80211_chan_width width)
2589{
2590 switch (width) {
2591 case NL80211_CHAN_WIDTH_20_NOHT:
2592 return "20 (noht)";
2593 case NL80211_CHAN_WIDTH_20:
2594 return "20";
2595 case NL80211_CHAN_WIDTH_40:
2596 return "40";
2597 case NL80211_CHAN_WIDTH_80:
2598 return "80";
2599 case NL80211_CHAN_WIDTH_80P80:
2600 return "80+80";
2601 case NL80211_CHAN_WIDTH_160:
2602 return "160";
2603 case NL80211_CHAN_WIDTH_5:
2604 return "5";
2605 case NL80211_CHAN_WIDTH_10:
2606 return "10";
2607 }
2608 return "?";
2609}
2610
2611static void ath10k_config_chan(struct ath10k *ar)
2612{
2613 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002614 int ret;
2615
2616 lockdep_assert_held(&ar->conf_mutex);
2617
Michal Kazior7aa7a722014-08-25 12:09:38 +02002618 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002619 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2620 ar->chandef.chan->center_freq,
2621 ar->chandef.center_freq1,
2622 ar->chandef.center_freq2,
2623 chandef_get_width(ar->chandef.width));
2624
2625 /* First stop monitor interface. Some FW versions crash if there's a
2626 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002627 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002628 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002629
2630 list_for_each_entry(arvif, &ar->arvifs, list) {
2631 if (!arvif->is_started)
2632 continue;
2633
Michal Kaziordc55e302014-07-29 12:53:36 +03002634 if (!arvif->is_up)
2635 continue;
2636
Michal Kaziorc930f742014-01-23 11:38:25 +01002637 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2638 continue;
2639
Michal Kaziordc55e302014-07-29 12:53:36 +03002640 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002641 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002642 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002643 arvif->vdev_id, ret);
2644 continue;
2645 }
2646 }
2647
Michal Kaziordc55e302014-07-29 12:53:36 +03002648 /* all vdevs are downed now - attempt to restart and re-up them */
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
2654 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2655 continue;
2656
Michal Kaziordc55e302014-07-29 12:53:36 +03002657 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002658 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002659 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002660 arvif->vdev_id, ret);
2661 continue;
2662 }
2663
2664 if (!arvif->is_up)
2665 continue;
2666
2667 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2668 arvif->bssid);
2669 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002670 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002671 arvif->vdev_id, ret);
2672 continue;
2673 }
2674 }
2675
Michal Kazior19337472014-08-28 12:58:16 +02002676 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002677}
2678
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2680{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002681 struct ath10k *ar = hw->priv;
2682 struct ieee80211_conf *conf = &hw->conf;
2683 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002684 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002685
2686 mutex_lock(&ar->conf_mutex);
2687
2688 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002689 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002690 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002691 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002692 conf->chandef.chan->flags,
2693 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002694
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 spin_lock_bh(&ar->data_lock);
2696 ar->rx_channel = conf->chandef.chan;
2697 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002698
Michal Kaziord6500972014-04-08 09:56:09 +03002699 ar->radar_enabled = conf->radar_enabled;
2700 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002701
2702 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2703 ar->chandef = conf->chandef;
2704 ath10k_config_chan(ar);
2705 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706 }
2707
Michal Kazior5474efe2013-10-23 04:02:15 -07002708 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002710 hw->conf.power_level);
2711
2712 param = ar->wmi.pdev_param->txpower_limit2g;
2713 ret = ath10k_wmi_pdev_set_param(ar, param,
2714 hw->conf.power_level * 2);
2715 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002716 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002717 hw->conf.power_level, ret);
2718
2719 param = ar->wmi.pdev_param->txpower_limit5g;
2720 ret = ath10k_wmi_pdev_set_param(ar, param,
2721 hw->conf.power_level * 2);
2722 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002723 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002724 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002725 }
2726
Michal Kazioraffd3212013-07-16 09:54:35 +02002727 if (changed & IEEE80211_CONF_CHANGE_PS)
2728 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002729
2730 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002731 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2732 ret = ath10k_monitor_recalc(ar);
2733 if (ret)
2734 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002735 }
2736
2737 mutex_unlock(&ar->conf_mutex);
2738 return ret;
2739}
2740
2741/*
2742 * TODO:
2743 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2744 * because we will send mgmt frames without CCK. This requirement
2745 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2746 * in the TX packet.
2747 */
2748static int ath10k_add_interface(struct ieee80211_hw *hw,
2749 struct ieee80211_vif *vif)
2750{
2751 struct ath10k *ar = hw->priv;
2752 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2753 enum wmi_sta_powersave_param param;
2754 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002755 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002756 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002757 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758
2759 mutex_lock(&ar->conf_mutex);
2760
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002761 memset(arvif, 0, sizeof(*arvif));
2762
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763 arvif->ar = ar;
2764 arvif->vif = vif;
2765
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002766 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002767 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002768
Ben Greeara9aefb32014-08-12 11:02:19 +03002769 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002772 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773 }
Ben Greear16c11172014-09-23 14:17:16 -07002774 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002775
Ben Greear16c11172014-09-23 14:17:16 -07002776 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2777 bit, ar->free_vdev_map);
2778
2779 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002780 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002781
2782 if (ar->p2p)
2783 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2784
2785 switch (vif->type) {
2786 case NL80211_IFTYPE_UNSPECIFIED:
2787 case NL80211_IFTYPE_STATION:
2788 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2789 if (vif->p2p)
2790 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2791 break;
2792 case NL80211_IFTYPE_ADHOC:
2793 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2794 break;
2795 case NL80211_IFTYPE_AP:
2796 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2797
2798 if (vif->p2p)
2799 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2800 break;
2801 case NL80211_IFTYPE_MONITOR:
2802 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2803 break;
2804 default:
2805 WARN_ON(1);
2806 break;
2807 }
2808
Michal Kazior64badcb2014-09-18 11:18:02 +03002809 /* Some firmware revisions don't wait for beacon tx completion before
2810 * sending another SWBA event. This could lead to hardware using old
2811 * (freed) beacon data in some cases, e.g. tx credit starvation
2812 * combined with missed TBTT. This is very very rare.
2813 *
2814 * On non-IOMMU-enabled hosts this could be a possible security issue
2815 * because hw could beacon some random data on the air. On
2816 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2817 * device would crash.
2818 *
2819 * Since there are no beacon tx completions (implicit nor explicit)
2820 * propagated to host the only workaround for this is to allocate a
2821 * DMA-coherent buffer for a lifetime of a vif and use it for all
2822 * beacon tx commands. Worst case for this approach is some beacons may
2823 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2824 */
2825 if (vif->type == NL80211_IFTYPE_ADHOC ||
2826 vif->type == NL80211_IFTYPE_AP) {
2827 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2828 IEEE80211_MAX_FRAME_LEN,
2829 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05302830 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03002831 if (!arvif->beacon_buf) {
2832 ret = -ENOMEM;
2833 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2834 ret);
2835 goto err;
2836 }
2837 }
2838
2839 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2840 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2841 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002842
2843 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2844 arvif->vdev_subtype, vif->addr);
2845 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002846 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002847 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002848 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002849 }
2850
Ben Greear16c11172014-09-23 14:17:16 -07002851 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002852 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002853
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002854 vdev_param = ar->wmi.vdev_param->def_keyid;
2855 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002856 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002857 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002858 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002859 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002860 goto err_vdev_delete;
2861 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002862
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002863 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2864 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002865 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002866 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002867 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002868 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002869 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002870 goto err_vdev_delete;
2871 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002872
2873 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2874 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2875 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002876 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002877 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002878 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002879 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002880
Kalle Valo5a13e762014-01-20 11:01:46 +02002881 ret = ath10k_mac_set_kickout(arvif);
2882 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002883 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002884 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002885 goto err_peer_delete;
2886 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002887 }
2888
2889 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2890 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2891 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2892 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2893 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002894 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002895 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002896 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002897 goto err_peer_delete;
2898 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002899
2900 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2901 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2902 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2903 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002904 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002905 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002906 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002907 goto err_peer_delete;
2908 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909
2910 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2911 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
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 PSPOLL count: %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
Michal Kazior424121c2013-07-22 14:13:31 +02002921 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002922 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002923 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002924 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002925 goto err_peer_delete;
2926 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002927
Michal Kazior424121c2013-07-22 14:13:31 +02002928 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002929 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002930 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002931 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002932 goto err_peer_delete;
2933 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002934
Kalle Valo5e3dd152013-06-12 20:52:10 +03002935 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002936 return 0;
2937
2938err_peer_delete:
2939 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2940 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2941
2942err_vdev_delete:
2943 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07002944 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002945 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002946
2947err:
Michal Kazior64badcb2014-09-18 11:18:02 +03002948 if (arvif->beacon_buf) {
2949 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
2950 arvif->beacon_buf, arvif->beacon_paddr);
2951 arvif->beacon_buf = NULL;
2952 }
2953
Michal Kazior9dad14a2013-10-16 15:44:45 +03002954 mutex_unlock(&ar->conf_mutex);
2955
Kalle Valo5e3dd152013-06-12 20:52:10 +03002956 return ret;
2957}
2958
2959static void ath10k_remove_interface(struct ieee80211_hw *hw,
2960 struct ieee80211_vif *vif)
2961{
2962 struct ath10k *ar = hw->priv;
2963 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2964 int ret;
2965
2966 mutex_lock(&ar->conf_mutex);
2967
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002968 cancel_work_sync(&arvif->wep_key_work);
2969
Michal Kaziored543882013-09-13 14:16:56 +02002970 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03002971 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02002972 spin_unlock_bh(&ar->data_lock);
2973
Simon Wunderlich855aed12014-08-02 09:12:54 +03002974 ret = ath10k_spectral_vif_stop(arvif);
2975 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002976 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03002977 arvif->vdev_id, ret);
2978
Ben Greear16c11172014-09-23 14:17:16 -07002979 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002980 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002981
2982 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2983 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2984 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002985 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002986 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002987
2988 kfree(arvif->u.ap.noa_data);
2989 }
2990
Michal Kazior7aa7a722014-08-25 12:09:38 +02002991 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002992 arvif->vdev_id);
2993
Kalle Valo5e3dd152013-06-12 20:52:10 +03002994 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2995 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002996 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002997 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002998
Kalle Valo5e3dd152013-06-12 20:52:10 +03002999 ath10k_peer_cleanup(ar, arvif->vdev_id);
3000
3001 mutex_unlock(&ar->conf_mutex);
3002}
3003
3004/*
3005 * FIXME: Has to be verified.
3006 */
3007#define SUPPORTED_FILTERS \
3008 (FIF_PROMISC_IN_BSS | \
3009 FIF_ALLMULTI | \
3010 FIF_CONTROL | \
3011 FIF_PSPOLL | \
3012 FIF_OTHER_BSS | \
3013 FIF_BCN_PRBRESP_PROMISC | \
3014 FIF_PROBE_REQ | \
3015 FIF_FCSFAIL)
3016
3017static void ath10k_configure_filter(struct ieee80211_hw *hw,
3018 unsigned int changed_flags,
3019 unsigned int *total_flags,
3020 u64 multicast)
3021{
3022 struct ath10k *ar = hw->priv;
3023 int ret;
3024
3025 mutex_lock(&ar->conf_mutex);
3026
3027 changed_flags &= SUPPORTED_FILTERS;
3028 *total_flags &= SUPPORTED_FILTERS;
3029 ar->filter_flags = *total_flags;
3030
Michal Kazior19337472014-08-28 12:58:16 +02003031 ret = ath10k_monitor_recalc(ar);
3032 if (ret)
3033 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003034
3035 mutex_unlock(&ar->conf_mutex);
3036}
3037
3038static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3039 struct ieee80211_vif *vif,
3040 struct ieee80211_bss_conf *info,
3041 u32 changed)
3042{
3043 struct ath10k *ar = hw->priv;
3044 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3045 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003046 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047
3048 mutex_lock(&ar->conf_mutex);
3049
3050 if (changed & BSS_CHANGED_IBSS)
3051 ath10k_control_ibss(arvif, info, vif->addr);
3052
3053 if (changed & BSS_CHANGED_BEACON_INT) {
3054 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003055 vdev_param = ar->wmi.vdev_param->beacon_interval;
3056 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003057 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003059 "mac vdev %d beacon_interval %d\n",
3060 arvif->vdev_id, arvif->beacon_interval);
3061
Kalle Valo5e3dd152013-06-12 20:52:10 +03003062 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003063 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003064 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003065 }
3066
3067 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003068 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003069 "vdev %d set beacon tx mode to staggered\n",
3070 arvif->vdev_id);
3071
Bartosz Markowski226a3392013-09-26 17:47:16 +02003072 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3073 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003074 WMI_BEACON_STAGGERED_MODE);
3075 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003076 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003077 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003078 }
3079
John W. Linvilleb70727e2013-06-13 13:34:29 -04003080 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081 arvif->dtim_period = info->dtim_period;
3082
Michal Kazior7aa7a722014-08-25 12:09:38 +02003083 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003084 "mac vdev %d dtim_period %d\n",
3085 arvif->vdev_id, arvif->dtim_period);
3086
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003087 vdev_param = ar->wmi.vdev_param->dtim_period;
3088 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003089 arvif->dtim_period);
3090 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003091 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003092 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003093 }
3094
3095 if (changed & BSS_CHANGED_SSID &&
3096 vif->type == NL80211_IFTYPE_AP) {
3097 arvif->u.ap.ssid_len = info->ssid_len;
3098 if (info->ssid_len)
3099 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3100 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3101 }
3102
Michal Kazior077efc82014-10-21 10:10:29 +03003103 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3104 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003105
3106 if (changed & BSS_CHANGED_BEACON_ENABLED)
3107 ath10k_control_beaconing(arvif, info);
3108
3109 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003110 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003111 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003112 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003113
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003114 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003116 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003117 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003118 }
3119
3120 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003121 if (info->use_short_slot)
3122 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3123
3124 else
3125 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3126
Michal Kazior7aa7a722014-08-25 12:09:38 +02003127 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003128 arvif->vdev_id, slottime);
3129
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003130 vdev_param = ar->wmi.vdev_param->slot_time;
3131 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 slottime);
3133 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003134 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003135 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003136 }
3137
3138 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139 if (info->use_short_preamble)
3140 preamble = WMI_VDEV_PREAMBLE_SHORT;
3141 else
3142 preamble = WMI_VDEV_PREAMBLE_LONG;
3143
Michal Kazior7aa7a722014-08-25 12:09:38 +02003144 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003145 "mac vdev %d preamble %dn",
3146 arvif->vdev_id, preamble);
3147
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003148 vdev_param = ar->wmi.vdev_param->preamble;
3149 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150 preamble);
3151 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003152 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003153 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003154 }
3155
3156 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003157 if (info->assoc) {
3158 /* Workaround: Make sure monitor vdev is not running
3159 * when associating to prevent some firmware revisions
3160 * (e.g. 10.1 and 10.2) from crashing.
3161 */
3162 if (ar->monitor_started)
3163 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003165 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03003166 } else {
3167 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02003168 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169 }
3170
3171 mutex_unlock(&ar->conf_mutex);
3172}
3173
3174static int ath10k_hw_scan(struct ieee80211_hw *hw,
3175 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003176 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003177{
3178 struct ath10k *ar = hw->priv;
3179 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003180 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 struct wmi_start_scan_arg arg;
3182 int ret = 0;
3183 int i;
3184
3185 mutex_lock(&ar->conf_mutex);
3186
3187 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003188 switch (ar->scan.state) {
3189 case ATH10K_SCAN_IDLE:
3190 reinit_completion(&ar->scan.started);
3191 reinit_completion(&ar->scan.completed);
3192 ar->scan.state = ATH10K_SCAN_STARTING;
3193 ar->scan.is_roc = false;
3194 ar->scan.vdev_id = arvif->vdev_id;
3195 ret = 0;
3196 break;
3197 case ATH10K_SCAN_STARTING:
3198 case ATH10K_SCAN_RUNNING:
3199 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003200 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003201 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003202 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003203 spin_unlock_bh(&ar->data_lock);
3204
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003205 if (ret)
3206 goto exit;
3207
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 memset(&arg, 0, sizeof(arg));
3209 ath10k_wmi_start_scan_init(ar, &arg);
3210 arg.vdev_id = arvif->vdev_id;
3211 arg.scan_id = ATH10K_SCAN_ID;
3212
3213 if (!req->no_cck)
3214 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3215
3216 if (req->ie_len) {
3217 arg.ie_len = req->ie_len;
3218 memcpy(arg.ie, req->ie, arg.ie_len);
3219 }
3220
3221 if (req->n_ssids) {
3222 arg.n_ssids = req->n_ssids;
3223 for (i = 0; i < arg.n_ssids; i++) {
3224 arg.ssids[i].len = req->ssids[i].ssid_len;
3225 arg.ssids[i].ssid = req->ssids[i].ssid;
3226 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003227 } else {
3228 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003229 }
3230
3231 if (req->n_channels) {
3232 arg.n_channels = req->n_channels;
3233 for (i = 0; i < arg.n_channels; i++)
3234 arg.channels[i] = req->channels[i]->center_freq;
3235 }
3236
3237 ret = ath10k_start_scan(ar, &arg);
3238 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003239 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003241 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242 spin_unlock_bh(&ar->data_lock);
3243 }
3244
3245exit:
3246 mutex_unlock(&ar->conf_mutex);
3247 return ret;
3248}
3249
3250static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3251 struct ieee80211_vif *vif)
3252{
3253 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003254
3255 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003256 cancel_delayed_work_sync(&ar->scan.timeout);
3257 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003258 mutex_unlock(&ar->conf_mutex);
3259}
3260
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003261static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3262 struct ath10k_vif *arvif,
3263 enum set_key_cmd cmd,
3264 struct ieee80211_key_conf *key)
3265{
3266 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3267 int ret;
3268
3269 /* 10.1 firmware branch requires default key index to be set to group
3270 * key index after installing it. Otherwise FW/HW Txes corrupted
3271 * frames with multi-vif APs. This is not required for main firmware
3272 * branch (e.g. 636).
3273 *
3274 * FIXME: This has been tested only in AP. It remains unknown if this
3275 * is required for multi-vif STA interfaces on 10.1 */
3276
3277 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3278 return;
3279
3280 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3281 return;
3282
3283 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3284 return;
3285
3286 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3287 return;
3288
3289 if (cmd != SET_KEY)
3290 return;
3291
3292 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3293 key->keyidx);
3294 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003295 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003296 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003297}
3298
Kalle Valo5e3dd152013-06-12 20:52:10 +03003299static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3300 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3301 struct ieee80211_key_conf *key)
3302{
3303 struct ath10k *ar = hw->priv;
3304 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3305 struct ath10k_peer *peer;
3306 const u8 *peer_addr;
3307 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3308 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3309 int ret = 0;
3310
3311 if (key->keyidx > WMI_MAX_KEY_INDEX)
3312 return -ENOSPC;
3313
3314 mutex_lock(&ar->conf_mutex);
3315
3316 if (sta)
3317 peer_addr = sta->addr;
3318 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3319 peer_addr = vif->bss_conf.bssid;
3320 else
3321 peer_addr = vif->addr;
3322
3323 key->hw_key_idx = key->keyidx;
3324
3325 /* the peer should not disappear in mid-way (unless FW goes awry) since
3326 * we already hold conf_mutex. we just make sure its there now. */
3327 spin_lock_bh(&ar->data_lock);
3328 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3329 spin_unlock_bh(&ar->data_lock);
3330
3331 if (!peer) {
3332 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003333 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003334 peer_addr);
3335 ret = -EOPNOTSUPP;
3336 goto exit;
3337 } else {
3338 /* if the peer doesn't exist there is no key to disable
3339 * anymore */
3340 goto exit;
3341 }
3342 }
3343
3344 if (is_wep) {
3345 if (cmd == SET_KEY)
3346 arvif->wep_keys[key->keyidx] = key;
3347 else
3348 arvif->wep_keys[key->keyidx] = NULL;
3349
3350 if (cmd == DISABLE_KEY)
3351 ath10k_clear_vdev_key(arvif, key);
3352 }
3353
3354 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3355 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003356 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003357 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003358 goto exit;
3359 }
3360
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003361 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3362
Kalle Valo5e3dd152013-06-12 20:52:10 +03003363 spin_lock_bh(&ar->data_lock);
3364 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3365 if (peer && cmd == SET_KEY)
3366 peer->keys[key->keyidx] = key;
3367 else if (peer && cmd == DISABLE_KEY)
3368 peer->keys[key->keyidx] = NULL;
3369 else if (peer == NULL)
3370 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003371 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372 spin_unlock_bh(&ar->data_lock);
3373
3374exit:
3375 mutex_unlock(&ar->conf_mutex);
3376 return ret;
3377}
3378
Michal Kazior9797feb2014-02-14 14:49:48 +01003379static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3380{
3381 struct ath10k *ar;
3382 struct ath10k_vif *arvif;
3383 struct ath10k_sta *arsta;
3384 struct ieee80211_sta *sta;
3385 u32 changed, bw, nss, smps;
3386 int err;
3387
3388 arsta = container_of(wk, struct ath10k_sta, update_wk);
3389 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3390 arvif = arsta->arvif;
3391 ar = arvif->ar;
3392
3393 spin_lock_bh(&ar->data_lock);
3394
3395 changed = arsta->changed;
3396 arsta->changed = 0;
3397
3398 bw = arsta->bw;
3399 nss = arsta->nss;
3400 smps = arsta->smps;
3401
3402 spin_unlock_bh(&ar->data_lock);
3403
3404 mutex_lock(&ar->conf_mutex);
3405
3406 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003407 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003408 sta->addr, bw);
3409
3410 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3411 WMI_PEER_CHAN_WIDTH, bw);
3412 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003413 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003414 sta->addr, bw, err);
3415 }
3416
3417 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003418 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003419 sta->addr, nss);
3420
3421 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3422 WMI_PEER_NSS, nss);
3423 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003424 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003425 sta->addr, nss, err);
3426 }
3427
3428 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003429 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003430 sta->addr, smps);
3431
3432 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3433 WMI_PEER_SMPS_STATE, smps);
3434 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003435 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003436 sta->addr, smps, err);
3437 }
3438
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003439 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003440 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003441 sta->addr);
3442
Michal Kazior590922a2014-10-21 10:10:29 +03003443 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003444 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003445 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003446 sta->addr);
3447 }
3448
Michal Kazior9797feb2014-02-14 14:49:48 +01003449 mutex_unlock(&ar->conf_mutex);
3450}
3451
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452static int ath10k_sta_state(struct ieee80211_hw *hw,
3453 struct ieee80211_vif *vif,
3454 struct ieee80211_sta *sta,
3455 enum ieee80211_sta_state old_state,
3456 enum ieee80211_sta_state new_state)
3457{
3458 struct ath10k *ar = hw->priv;
3459 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003460 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003461 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003462 int ret = 0;
3463
Michal Kazior76f90022014-02-25 09:29:57 +02003464 if (old_state == IEEE80211_STA_NOTEXIST &&
3465 new_state == IEEE80211_STA_NONE) {
3466 memset(arsta, 0, sizeof(*arsta));
3467 arsta->arvif = arvif;
3468 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3469 }
3470
Michal Kazior9797feb2014-02-14 14:49:48 +01003471 /* cancel must be done outside the mutex to avoid deadlock */
3472 if ((old_state == IEEE80211_STA_NONE &&
3473 new_state == IEEE80211_STA_NOTEXIST))
3474 cancel_work_sync(&arsta->update_wk);
3475
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476 mutex_lock(&ar->conf_mutex);
3477
3478 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03003479 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003480 /*
3481 * New station addition.
3482 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003483 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3484 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3485 else
3486 max_num_peers = TARGET_NUM_PEERS;
3487
3488 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003489 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003490 ar->num_peers, max_num_peers);
3491 ret = -ENOBUFS;
3492 goto exit;
3493 }
3494
Michal Kazior7aa7a722014-08-25 12:09:38 +02003495 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003496 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3497 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003498
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3500 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003501 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 -08003502 sta->addr, arvif->vdev_id, ret);
Michal Kazior077efc82014-10-21 10:10:29 +03003503
3504 if (vif->type == NL80211_IFTYPE_STATION) {
3505 WARN_ON(arvif->is_started);
3506
3507 ret = ath10k_vdev_start(arvif);
3508 if (ret) {
3509 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3510 arvif->vdev_id, ret);
3511 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3512 sta->addr));
3513 goto exit;
3514 }
3515
3516 arvif->is_started = true;
3517 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 } else if ((old_state == IEEE80211_STA_NONE &&
3519 new_state == IEEE80211_STA_NOTEXIST)) {
3520 /*
3521 * Existing station deletion.
3522 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003523 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003524 "mac vdev %d peer delete %pM (sta gone)\n",
3525 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03003526
3527 if (vif->type == NL80211_IFTYPE_STATION) {
3528 WARN_ON(!arvif->is_started);
3529
3530 ret = ath10k_vdev_stop(arvif);
3531 if (ret)
3532 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3533 arvif->vdev_id, ret);
3534
3535 arvif->is_started = false;
3536 }
3537
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3539 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003540 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003541 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003542
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543 } else if (old_state == IEEE80211_STA_AUTH &&
3544 new_state == IEEE80211_STA_ASSOC &&
3545 (vif->type == NL80211_IFTYPE_AP ||
3546 vif->type == NL80211_IFTYPE_ADHOC)) {
3547 /*
3548 * New association.
3549 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003550 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003551 sta->addr);
3552
Michal Kazior590922a2014-10-21 10:10:29 +03003553 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003554 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003555 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003556 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 } else if (old_state == IEEE80211_STA_ASSOC &&
3558 new_state == IEEE80211_STA_AUTH &&
3559 (vif->type == NL80211_IFTYPE_AP ||
3560 vif->type == NL80211_IFTYPE_ADHOC)) {
3561 /*
3562 * Disassociation.
3563 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003564 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003565 sta->addr);
3566
Michal Kazior590922a2014-10-21 10:10:29 +03003567 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003569 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003570 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003571 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003572exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003573 mutex_unlock(&ar->conf_mutex);
3574 return ret;
3575}
3576
3577static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003578 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003579{
3580 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3581 u32 value = 0;
3582 int ret = 0;
3583
Michal Kazior548db542013-07-05 16:15:15 +03003584 lockdep_assert_held(&ar->conf_mutex);
3585
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3587 return 0;
3588
3589 switch (ac) {
3590 case IEEE80211_AC_VO:
3591 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3592 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3593 break;
3594 case IEEE80211_AC_VI:
3595 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3596 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3597 break;
3598 case IEEE80211_AC_BE:
3599 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3600 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3601 break;
3602 case IEEE80211_AC_BK:
3603 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3604 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3605 break;
3606 }
3607
3608 if (enable)
3609 arvif->u.sta.uapsd |= value;
3610 else
3611 arvif->u.sta.uapsd &= ~value;
3612
3613 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3614 WMI_STA_PS_PARAM_UAPSD,
3615 arvif->u.sta.uapsd);
3616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003617 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618 goto exit;
3619 }
3620
3621 if (arvif->u.sta.uapsd)
3622 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3623 else
3624 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3625
3626 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3627 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3628 value);
3629 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003630 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003631
3632exit:
3633 return ret;
3634}
3635
3636static int ath10k_conf_tx(struct ieee80211_hw *hw,
3637 struct ieee80211_vif *vif, u16 ac,
3638 const struct ieee80211_tx_queue_params *params)
3639{
3640 struct ath10k *ar = hw->priv;
3641 struct wmi_wmm_params_arg *p = NULL;
3642 int ret;
3643
3644 mutex_lock(&ar->conf_mutex);
3645
3646 switch (ac) {
3647 case IEEE80211_AC_VO:
3648 p = &ar->wmm_params.ac_vo;
3649 break;
3650 case IEEE80211_AC_VI:
3651 p = &ar->wmm_params.ac_vi;
3652 break;
3653 case IEEE80211_AC_BE:
3654 p = &ar->wmm_params.ac_be;
3655 break;
3656 case IEEE80211_AC_BK:
3657 p = &ar->wmm_params.ac_bk;
3658 break;
3659 }
3660
3661 if (WARN_ON(!p)) {
3662 ret = -EINVAL;
3663 goto exit;
3664 }
3665
3666 p->cwmin = params->cw_min;
3667 p->cwmax = params->cw_max;
3668 p->aifs = params->aifs;
3669
3670 /*
3671 * The channel time duration programmed in the HW is in absolute
3672 * microseconds, while mac80211 gives the txop in units of
3673 * 32 microseconds.
3674 */
3675 p->txop = params->txop * 32;
3676
3677 /* FIXME: FW accepts wmm params per hw, not per vif */
3678 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3679 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003680 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003681 goto exit;
3682 }
3683
3684 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3685 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003686 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003687
3688exit:
3689 mutex_unlock(&ar->conf_mutex);
3690 return ret;
3691}
3692
3693#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3694
3695static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3696 struct ieee80211_vif *vif,
3697 struct ieee80211_channel *chan,
3698 int duration,
3699 enum ieee80211_roc_type type)
3700{
3701 struct ath10k *ar = hw->priv;
3702 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3703 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003704 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003705
3706 mutex_lock(&ar->conf_mutex);
3707
3708 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003709 switch (ar->scan.state) {
3710 case ATH10K_SCAN_IDLE:
3711 reinit_completion(&ar->scan.started);
3712 reinit_completion(&ar->scan.completed);
3713 reinit_completion(&ar->scan.on_channel);
3714 ar->scan.state = ATH10K_SCAN_STARTING;
3715 ar->scan.is_roc = true;
3716 ar->scan.vdev_id = arvif->vdev_id;
3717 ar->scan.roc_freq = chan->center_freq;
3718 ret = 0;
3719 break;
3720 case ATH10K_SCAN_STARTING:
3721 case ATH10K_SCAN_RUNNING:
3722 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003723 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003724 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003725 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003726 spin_unlock_bh(&ar->data_lock);
3727
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003728 if (ret)
3729 goto exit;
3730
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 memset(&arg, 0, sizeof(arg));
3732 ath10k_wmi_start_scan_init(ar, &arg);
3733 arg.vdev_id = arvif->vdev_id;
3734 arg.scan_id = ATH10K_SCAN_ID;
3735 arg.n_channels = 1;
3736 arg.channels[0] = chan->center_freq;
3737 arg.dwell_time_active = duration;
3738 arg.dwell_time_passive = duration;
3739 arg.max_scan_time = 2 * duration;
3740 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3741 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3742
3743 ret = ath10k_start_scan(ar, &arg);
3744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003745 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003746 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003747 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748 spin_unlock_bh(&ar->data_lock);
3749 goto exit;
3750 }
3751
3752 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3753 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003754 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003755
3756 ret = ath10k_scan_stop(ar);
3757 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003758 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003759
Kalle Valo5e3dd152013-06-12 20:52:10 +03003760 ret = -ETIMEDOUT;
3761 goto exit;
3762 }
3763
3764 ret = 0;
3765exit:
3766 mutex_unlock(&ar->conf_mutex);
3767 return ret;
3768}
3769
3770static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3771{
3772 struct ath10k *ar = hw->priv;
3773
3774 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003775 cancel_delayed_work_sync(&ar->scan.timeout);
3776 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003777 mutex_unlock(&ar->conf_mutex);
3778
3779 return 0;
3780}
3781
3782/*
3783 * Both RTS and Fragmentation threshold are interface-specific
3784 * in ath10k, but device-specific in mac80211.
3785 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786
3787static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3788{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003789 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003790 struct ath10k_vif *arvif;
3791 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003792
Michal Kaziorad088bf2013-10-16 15:44:46 +03003793 mutex_lock(&ar->conf_mutex);
3794 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003795 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003796 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003797
Michal Kaziorad088bf2013-10-16 15:44:46 +03003798 ret = ath10k_mac_set_rts(arvif, value);
3799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003800 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003801 arvif->vdev_id, ret);
3802 break;
3803 }
3804 }
3805 mutex_unlock(&ar->conf_mutex);
3806
3807 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003808}
3809
3810static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3811{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003812 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003813 struct ath10k_vif *arvif;
3814 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815
Kalle Valo5e3dd152013-06-12 20:52:10 +03003816 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003817 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003818 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003819 arvif->vdev_id, value);
3820
3821 ret = ath10k_mac_set_rts(arvif, value);
3822 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003824 arvif->vdev_id, ret);
3825 break;
3826 }
3827 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003828 mutex_unlock(&ar->conf_mutex);
3829
Michal Kaziorad088bf2013-10-16 15:44:46 +03003830 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003831}
3832
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003833static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3834 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003835{
3836 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003837 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003838 int ret;
3839
3840 /* mac80211 doesn't care if we really xmit queued frames or not
3841 * we'll collect those frames either way if we stop/delete vdevs */
3842 if (drop)
3843 return;
3844
Michal Kazior548db542013-07-05 16:15:15 +03003845 mutex_lock(&ar->conf_mutex);
3846
Michal Kazioraffd3212013-07-16 09:54:35 +02003847 if (ar->state == ATH10K_STATE_WEDGED)
3848 goto skip;
3849
Michal Kazioredb82362013-07-05 16:15:14 +03003850 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003851 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003852
Michal Kazioredb82362013-07-05 16:15:14 +03003853 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003854 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003855 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003856
3857 skip = (ar->state == ATH10K_STATE_WEDGED);
3858
3859 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003860 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003861
3862 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003863 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003864 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003865
Michal Kazioraffd3212013-07-16 09:54:35 +02003866skip:
Michal Kazior548db542013-07-05 16:15:15 +03003867 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003868}
3869
3870/* TODO: Implement this function properly
3871 * For now it is needed to reply to Probe Requests in IBSS mode.
3872 * Propably we need this information from FW.
3873 */
3874static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3875{
3876 return 1;
3877}
3878
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003879#ifdef CONFIG_PM
3880static int ath10k_suspend(struct ieee80211_hw *hw,
3881 struct cfg80211_wowlan *wowlan)
3882{
3883 struct ath10k *ar = hw->priv;
3884 int ret;
3885
Marek Puzyniak9042e172014-02-10 17:14:23 +01003886 mutex_lock(&ar->conf_mutex);
3887
Marek Puzyniak00f54822014-02-10 17:14:24 +01003888 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003889 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003890 if (ret == -ETIMEDOUT)
3891 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003892 ret = 1;
3893 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003894 }
3895
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003896 ret = ath10k_hif_suspend(ar);
3897 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003898 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003899 goto resume;
3900 }
3901
Marek Puzyniak9042e172014-02-10 17:14:23 +01003902 ret = 0;
3903 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003904resume:
3905 ret = ath10k_wmi_pdev_resume_target(ar);
3906 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003907 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003908
3909 ret = 1;
3910exit:
3911 mutex_unlock(&ar->conf_mutex);
3912 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003913}
3914
3915static int ath10k_resume(struct ieee80211_hw *hw)
3916{
3917 struct ath10k *ar = hw->priv;
3918 int ret;
3919
Marek Puzyniak9042e172014-02-10 17:14:23 +01003920 mutex_lock(&ar->conf_mutex);
3921
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003922 ret = ath10k_hif_resume(ar);
3923 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003924 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003925 ret = 1;
3926 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003927 }
3928
3929 ret = ath10k_wmi_pdev_resume_target(ar);
3930 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003931 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003932 ret = 1;
3933 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003934 }
3935
Marek Puzyniak9042e172014-02-10 17:14:23 +01003936 ret = 0;
3937exit:
3938 mutex_unlock(&ar->conf_mutex);
3939 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003940}
3941#endif
3942
Michal Kazioraffd3212013-07-16 09:54:35 +02003943static void ath10k_restart_complete(struct ieee80211_hw *hw)
3944{
3945 struct ath10k *ar = hw->priv;
3946
3947 mutex_lock(&ar->conf_mutex);
3948
3949 /* If device failed to restart it will be in a different state, e.g.
3950 * ATH10K_STATE_WEDGED */
3951 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003952 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02003953 ar->state = ATH10K_STATE_ON;
3954 }
3955
3956 mutex_unlock(&ar->conf_mutex);
3957}
3958
Michal Kazior2e1dea42013-07-31 10:32:40 +02003959static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3960 struct survey_info *survey)
3961{
3962 struct ath10k *ar = hw->priv;
3963 struct ieee80211_supported_band *sband;
3964 struct survey_info *ar_survey = &ar->survey[idx];
3965 int ret = 0;
3966
3967 mutex_lock(&ar->conf_mutex);
3968
3969 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3970 if (sband && idx >= sband->n_channels) {
3971 idx -= sband->n_channels;
3972 sband = NULL;
3973 }
3974
3975 if (!sband)
3976 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3977
3978 if (!sband || idx >= sband->n_channels) {
3979 ret = -ENOENT;
3980 goto exit;
3981 }
3982
3983 spin_lock_bh(&ar->data_lock);
3984 memcpy(survey, ar_survey, sizeof(*survey));
3985 spin_unlock_bh(&ar->data_lock);
3986
3987 survey->channel = &sband->channels[idx];
3988
3989exit:
3990 mutex_unlock(&ar->conf_mutex);
3991 return ret;
3992}
3993
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003994/* Helper table for legacy fixed_rate/bitrate_mask */
3995static const u8 cck_ofdm_rate[] = {
3996 /* CCK */
3997 3, /* 1Mbps */
3998 2, /* 2Mbps */
3999 1, /* 5.5Mbps */
4000 0, /* 11Mbps */
4001 /* OFDM */
4002 3, /* 6Mbps */
4003 7, /* 9Mbps */
4004 2, /* 12Mbps */
4005 6, /* 18Mbps */
4006 1, /* 24Mbps */
4007 5, /* 36Mbps */
4008 0, /* 48Mbps */
4009 4, /* 54Mbps */
4010};
4011
4012/* Check if only one bit set */
4013static int ath10k_check_single_mask(u32 mask)
4014{
4015 int bit;
4016
4017 bit = ffs(mask);
4018 if (!bit)
4019 return 0;
4020
4021 mask &= ~BIT(bit - 1);
4022 if (mask)
4023 return 2;
4024
4025 return 1;
4026}
4027
4028static bool
4029ath10k_default_bitrate_mask(struct ath10k *ar,
4030 enum ieee80211_band band,
4031 const struct cfg80211_bitrate_mask *mask)
4032{
4033 u32 legacy = 0x00ff;
4034 u8 ht = 0xff, i;
4035 u16 vht = 0x3ff;
4036
4037 switch (band) {
4038 case IEEE80211_BAND_2GHZ:
4039 legacy = 0x00fff;
4040 vht = 0;
4041 break;
4042 case IEEE80211_BAND_5GHZ:
4043 break;
4044 default:
4045 return false;
4046 }
4047
4048 if (mask->control[band].legacy != legacy)
4049 return false;
4050
4051 for (i = 0; i < ar->num_rf_chains; i++)
4052 if (mask->control[band].ht_mcs[i] != ht)
4053 return false;
4054
4055 for (i = 0; i < ar->num_rf_chains; i++)
4056 if (mask->control[band].vht_mcs[i] != vht)
4057 return false;
4058
4059 return true;
4060}
4061
4062static bool
4063ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4064 enum ieee80211_band band,
4065 u8 *fixed_nss)
4066{
4067 int ht_nss = 0, vht_nss = 0, i;
4068
4069 /* check legacy */
4070 if (ath10k_check_single_mask(mask->control[band].legacy))
4071 return false;
4072
4073 /* check HT */
4074 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4075 if (mask->control[band].ht_mcs[i] == 0xff)
4076 continue;
4077 else if (mask->control[band].ht_mcs[i] == 0x00)
4078 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004079
4080 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004081 }
4082
4083 ht_nss = i;
4084
4085 /* check VHT */
4086 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4087 if (mask->control[band].vht_mcs[i] == 0x03ff)
4088 continue;
4089 else if (mask->control[band].vht_mcs[i] == 0x0000)
4090 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004091
4092 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004093 }
4094
4095 vht_nss = i;
4096
4097 if (ht_nss > 0 && vht_nss > 0)
4098 return false;
4099
4100 if (ht_nss)
4101 *fixed_nss = ht_nss;
4102 else if (vht_nss)
4103 *fixed_nss = vht_nss;
4104 else
4105 return false;
4106
4107 return true;
4108}
4109
4110static bool
4111ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4112 enum ieee80211_band band,
4113 enum wmi_rate_preamble *preamble)
4114{
4115 int legacy = 0, ht = 0, vht = 0, i;
4116
4117 *preamble = WMI_RATE_PREAMBLE_OFDM;
4118
4119 /* check legacy */
4120 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4121 if (legacy > 1)
4122 return false;
4123
4124 /* check HT */
4125 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4126 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4127 if (ht > 1)
4128 return false;
4129
4130 /* check VHT */
4131 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4132 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4133 if (vht > 1)
4134 return false;
4135
4136 /* Currently we support only one fixed_rate */
4137 if ((legacy + ht + vht) != 1)
4138 return false;
4139
4140 if (ht)
4141 *preamble = WMI_RATE_PREAMBLE_HT;
4142 else if (vht)
4143 *preamble = WMI_RATE_PREAMBLE_VHT;
4144
4145 return true;
4146}
4147
4148static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004149ath10k_bitrate_mask_rate(struct ath10k *ar,
4150 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004151 enum ieee80211_band band,
4152 u8 *fixed_rate,
4153 u8 *fixed_nss)
4154{
4155 u8 rate = 0, pream = 0, nss = 0, i;
4156 enum wmi_rate_preamble preamble;
4157
4158 /* Check if single rate correct */
4159 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4160 return false;
4161
4162 pream = preamble;
4163
4164 switch (preamble) {
4165 case WMI_RATE_PREAMBLE_CCK:
4166 case WMI_RATE_PREAMBLE_OFDM:
4167 i = ffs(mask->control[band].legacy) - 1;
4168
4169 if (band == IEEE80211_BAND_2GHZ && i < 4)
4170 pream = WMI_RATE_PREAMBLE_CCK;
4171
4172 if (band == IEEE80211_BAND_5GHZ)
4173 i += 4;
4174
4175 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4176 return false;
4177
4178 rate = cck_ofdm_rate[i];
4179 break;
4180 case WMI_RATE_PREAMBLE_HT:
4181 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4182 if (mask->control[band].ht_mcs[i])
4183 break;
4184
4185 if (i == IEEE80211_HT_MCS_MASK_LEN)
4186 return false;
4187
4188 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4189 nss = i;
4190 break;
4191 case WMI_RATE_PREAMBLE_VHT:
4192 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4193 if (mask->control[band].vht_mcs[i])
4194 break;
4195
4196 if (i == NL80211_VHT_NSS_MAX)
4197 return false;
4198
4199 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4200 nss = i;
4201 break;
4202 }
4203
4204 *fixed_nss = nss + 1;
4205 nss <<= 4;
4206 pream <<= 6;
4207
Michal Kazior7aa7a722014-08-25 12:09:38 +02004208 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 +01004209 pream, nss, rate);
4210
4211 *fixed_rate = pream | nss | rate;
4212
4213 return true;
4214}
4215
Michal Kazior7aa7a722014-08-25 12:09:38 +02004216static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4217 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004218 enum ieee80211_band band,
4219 u8 *fixed_rate,
4220 u8 *fixed_nss)
4221{
4222 /* First check full NSS mask, if we can simply limit NSS */
4223 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4224 return true;
4225
4226 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004227 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004228}
4229
4230static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4231 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004232 u8 fixed_nss,
4233 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004234{
4235 struct ath10k *ar = arvif->ar;
4236 u32 vdev_param;
4237 int ret = 0;
4238
4239 mutex_lock(&ar->conf_mutex);
4240
4241 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004242 arvif->fixed_nss == fixed_nss &&
4243 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004244 goto exit;
4245
4246 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004247 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004248
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004249 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004250 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004251
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004252 vdev_param = ar->wmi.vdev_param->fixed_rate;
4253 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4254 vdev_param, fixed_rate);
4255 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004256 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004257 fixed_rate, ret);
4258 ret = -EINVAL;
4259 goto exit;
4260 }
4261
4262 arvif->fixed_rate = fixed_rate;
4263
4264 vdev_param = ar->wmi.vdev_param->nss;
4265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4266 vdev_param, fixed_nss);
4267
4268 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004269 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004270 fixed_nss, ret);
4271 ret = -EINVAL;
4272 goto exit;
4273 }
4274
4275 arvif->fixed_nss = fixed_nss;
4276
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004277 vdev_param = ar->wmi.vdev_param->sgi;
4278 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4279 force_sgi);
4280
4281 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004282 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004283 force_sgi, ret);
4284 ret = -EINVAL;
4285 goto exit;
4286 }
4287
4288 arvif->force_sgi = force_sgi;
4289
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004290exit:
4291 mutex_unlock(&ar->conf_mutex);
4292 return ret;
4293}
4294
4295static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4296 struct ieee80211_vif *vif,
4297 const struct cfg80211_bitrate_mask *mask)
4298{
4299 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4300 struct ath10k *ar = arvif->ar;
4301 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4302 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4303 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004304 u8 force_sgi;
4305
4306 force_sgi = mask->control[band].gi;
4307 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4308 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004309
4310 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004311 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004312 &fixed_rate,
4313 &fixed_nss))
4314 return -EINVAL;
4315 }
4316
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004317 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004318 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004319 return -EINVAL;
4320 }
4321
4322 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4323 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004324}
4325
Michal Kazior9797feb2014-02-14 14:49:48 +01004326static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4327 struct ieee80211_vif *vif,
4328 struct ieee80211_sta *sta,
4329 u32 changed)
4330{
4331 struct ath10k *ar = hw->priv;
4332 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4333 u32 bw, smps;
4334
4335 spin_lock_bh(&ar->data_lock);
4336
Michal Kazior7aa7a722014-08-25 12:09:38 +02004337 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004338 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4339 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4340 sta->smps_mode);
4341
4342 if (changed & IEEE80211_RC_BW_CHANGED) {
4343 bw = WMI_PEER_CHWIDTH_20MHZ;
4344
4345 switch (sta->bandwidth) {
4346 case IEEE80211_STA_RX_BW_20:
4347 bw = WMI_PEER_CHWIDTH_20MHZ;
4348 break;
4349 case IEEE80211_STA_RX_BW_40:
4350 bw = WMI_PEER_CHWIDTH_40MHZ;
4351 break;
4352 case IEEE80211_STA_RX_BW_80:
4353 bw = WMI_PEER_CHWIDTH_80MHZ;
4354 break;
4355 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004356 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004357 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004358 bw = WMI_PEER_CHWIDTH_20MHZ;
4359 break;
4360 }
4361
4362 arsta->bw = bw;
4363 }
4364
4365 if (changed & IEEE80211_RC_NSS_CHANGED)
4366 arsta->nss = sta->rx_nss;
4367
4368 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4369 smps = WMI_PEER_SMPS_PS_NONE;
4370
4371 switch (sta->smps_mode) {
4372 case IEEE80211_SMPS_AUTOMATIC:
4373 case IEEE80211_SMPS_OFF:
4374 smps = WMI_PEER_SMPS_PS_NONE;
4375 break;
4376 case IEEE80211_SMPS_STATIC:
4377 smps = WMI_PEER_SMPS_STATIC;
4378 break;
4379 case IEEE80211_SMPS_DYNAMIC:
4380 smps = WMI_PEER_SMPS_DYNAMIC;
4381 break;
4382 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004383 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004384 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004385 smps = WMI_PEER_SMPS_PS_NONE;
4386 break;
4387 }
4388
4389 arsta->smps = smps;
4390 }
4391
Michal Kazior9797feb2014-02-14 14:49:48 +01004392 arsta->changed |= changed;
4393
4394 spin_unlock_bh(&ar->data_lock);
4395
4396 ieee80211_queue_work(hw, &arsta->update_wk);
4397}
4398
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004399static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4400{
4401 /*
4402 * FIXME: Return 0 for time being. Need to figure out whether FW
4403 * has the API to fetch 64-bit local TSF
4404 */
4405
4406 return 0;
4407}
4408
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004409static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4410 struct ieee80211_vif *vif,
4411 enum ieee80211_ampdu_mlme_action action,
4412 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4413 u8 buf_size)
4414{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004415 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004416 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4417
Michal Kazior7aa7a722014-08-25 12:09:38 +02004418 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 +02004419 arvif->vdev_id, sta->addr, tid, action);
4420
4421 switch (action) {
4422 case IEEE80211_AMPDU_RX_START:
4423 case IEEE80211_AMPDU_RX_STOP:
4424 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4425 * creation/removal. Do we need to verify this?
4426 */
4427 return 0;
4428 case IEEE80211_AMPDU_TX_START:
4429 case IEEE80211_AMPDU_TX_STOP_CONT:
4430 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4431 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4432 case IEEE80211_AMPDU_TX_OPERATIONAL:
4433 /* Firmware offloads Tx aggregation entirely so deny mac80211
4434 * Tx aggregation requests.
4435 */
4436 return -EOPNOTSUPP;
4437 }
4438
4439 return -EINVAL;
4440}
4441
Kalle Valo5e3dd152013-06-12 20:52:10 +03004442static const struct ieee80211_ops ath10k_ops = {
4443 .tx = ath10k_tx,
4444 .start = ath10k_start,
4445 .stop = ath10k_stop,
4446 .config = ath10k_config,
4447 .add_interface = ath10k_add_interface,
4448 .remove_interface = ath10k_remove_interface,
4449 .configure_filter = ath10k_configure_filter,
4450 .bss_info_changed = ath10k_bss_info_changed,
4451 .hw_scan = ath10k_hw_scan,
4452 .cancel_hw_scan = ath10k_cancel_hw_scan,
4453 .set_key = ath10k_set_key,
4454 .sta_state = ath10k_sta_state,
4455 .conf_tx = ath10k_conf_tx,
4456 .remain_on_channel = ath10k_remain_on_channel,
4457 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4458 .set_rts_threshold = ath10k_set_rts_threshold,
4459 .set_frag_threshold = ath10k_set_frag_threshold,
4460 .flush = ath10k_flush,
4461 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004462 .set_antenna = ath10k_set_antenna,
4463 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004464 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004465 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004466 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004467 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004468 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004469 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03004470 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4471 .get_et_stats = ath10k_debug_get_et_stats,
4472 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03004473
4474 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4475
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004476#ifdef CONFIG_PM
4477 .suspend = ath10k_suspend,
4478 .resume = ath10k_resume,
4479#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004480};
4481
4482#define RATETAB_ENT(_rate, _rateid, _flags) { \
4483 .bitrate = (_rate), \
4484 .flags = (_flags), \
4485 .hw_value = (_rateid), \
4486}
4487
4488#define CHAN2G(_channel, _freq, _flags) { \
4489 .band = IEEE80211_BAND_2GHZ, \
4490 .hw_value = (_channel), \
4491 .center_freq = (_freq), \
4492 .flags = (_flags), \
4493 .max_antenna_gain = 0, \
4494 .max_power = 30, \
4495}
4496
4497#define CHAN5G(_channel, _freq, _flags) { \
4498 .band = IEEE80211_BAND_5GHZ, \
4499 .hw_value = (_channel), \
4500 .center_freq = (_freq), \
4501 .flags = (_flags), \
4502 .max_antenna_gain = 0, \
4503 .max_power = 30, \
4504}
4505
4506static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4507 CHAN2G(1, 2412, 0),
4508 CHAN2G(2, 2417, 0),
4509 CHAN2G(3, 2422, 0),
4510 CHAN2G(4, 2427, 0),
4511 CHAN2G(5, 2432, 0),
4512 CHAN2G(6, 2437, 0),
4513 CHAN2G(7, 2442, 0),
4514 CHAN2G(8, 2447, 0),
4515 CHAN2G(9, 2452, 0),
4516 CHAN2G(10, 2457, 0),
4517 CHAN2G(11, 2462, 0),
4518 CHAN2G(12, 2467, 0),
4519 CHAN2G(13, 2472, 0),
4520 CHAN2G(14, 2484, 0),
4521};
4522
4523static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004524 CHAN5G(36, 5180, 0),
4525 CHAN5G(40, 5200, 0),
4526 CHAN5G(44, 5220, 0),
4527 CHAN5G(48, 5240, 0),
4528 CHAN5G(52, 5260, 0),
4529 CHAN5G(56, 5280, 0),
4530 CHAN5G(60, 5300, 0),
4531 CHAN5G(64, 5320, 0),
4532 CHAN5G(100, 5500, 0),
4533 CHAN5G(104, 5520, 0),
4534 CHAN5G(108, 5540, 0),
4535 CHAN5G(112, 5560, 0),
4536 CHAN5G(116, 5580, 0),
4537 CHAN5G(120, 5600, 0),
4538 CHAN5G(124, 5620, 0),
4539 CHAN5G(128, 5640, 0),
4540 CHAN5G(132, 5660, 0),
4541 CHAN5G(136, 5680, 0),
4542 CHAN5G(140, 5700, 0),
4543 CHAN5G(149, 5745, 0),
4544 CHAN5G(153, 5765, 0),
4545 CHAN5G(157, 5785, 0),
4546 CHAN5G(161, 5805, 0),
4547 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004548};
4549
4550static struct ieee80211_rate ath10k_rates[] = {
4551 /* CCK */
4552 RATETAB_ENT(10, 0x82, 0),
4553 RATETAB_ENT(20, 0x84, 0),
4554 RATETAB_ENT(55, 0x8b, 0),
4555 RATETAB_ENT(110, 0x96, 0),
4556 /* OFDM */
4557 RATETAB_ENT(60, 0x0c, 0),
4558 RATETAB_ENT(90, 0x12, 0),
4559 RATETAB_ENT(120, 0x18, 0),
4560 RATETAB_ENT(180, 0x24, 0),
4561 RATETAB_ENT(240, 0x30, 0),
4562 RATETAB_ENT(360, 0x48, 0),
4563 RATETAB_ENT(480, 0x60, 0),
4564 RATETAB_ENT(540, 0x6c, 0),
4565};
4566
4567#define ath10k_a_rates (ath10k_rates + 4)
4568#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4569#define ath10k_g_rates (ath10k_rates + 0)
4570#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4571
Michal Kaziore7b54192014-08-07 11:03:27 +02004572struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004573{
4574 struct ieee80211_hw *hw;
4575 struct ath10k *ar;
4576
Michal Kaziore7b54192014-08-07 11:03:27 +02004577 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578 if (!hw)
4579 return NULL;
4580
4581 ar = hw->priv;
4582 ar->hw = hw;
4583
4584 return ar;
4585}
4586
4587void ath10k_mac_destroy(struct ath10k *ar)
4588{
4589 ieee80211_free_hw(ar->hw);
4590}
4591
4592static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4593 {
4594 .max = 8,
4595 .types = BIT(NL80211_IFTYPE_STATION)
4596 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004597 },
4598 {
4599 .max = 3,
4600 .types = BIT(NL80211_IFTYPE_P2P_GO)
4601 },
4602 {
4603 .max = 7,
4604 .types = BIT(NL80211_IFTYPE_AP)
4605 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004606};
4607
Bartosz Markowskif2595092013-12-10 16:20:39 +01004608static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004609 {
4610 .max = 8,
4611 .types = BIT(NL80211_IFTYPE_AP)
4612 },
4613};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004614
4615static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4616 {
4617 .limits = ath10k_if_limits,
4618 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4619 .max_interfaces = 8,
4620 .num_different_channels = 1,
4621 .beacon_int_infra_match = true,
4622 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004623};
4624
4625static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004626 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004627 .limits = ath10k_10x_if_limits,
4628 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004629 .max_interfaces = 8,
4630 .num_different_channels = 1,
4631 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004632#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004633 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4634 BIT(NL80211_CHAN_WIDTH_20) |
4635 BIT(NL80211_CHAN_WIDTH_40) |
4636 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004637#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004638 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004639};
4640
4641static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4642{
4643 struct ieee80211_sta_vht_cap vht_cap = {0};
4644 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004645 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004646
4647 vht_cap.vht_supported = 1;
4648 vht_cap.cap = ar->vht_cap_info;
4649
Michal Kazior8865bee42013-07-24 12:36:46 +02004650 mcs_map = 0;
4651 for (i = 0; i < 8; i++) {
4652 if (i < ar->num_rf_chains)
4653 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4654 else
4655 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4656 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004657
4658 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4659 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4660
4661 return vht_cap;
4662}
4663
4664static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4665{
4666 int i;
4667 struct ieee80211_sta_ht_cap ht_cap = {0};
4668
4669 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4670 return ht_cap;
4671
4672 ht_cap.ht_supported = 1;
4673 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4674 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4675 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4676 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4677 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4678
4679 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4680 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4681
4682 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4683 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4684
4685 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4686 u32 smps;
4687
4688 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4689 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4690
4691 ht_cap.cap |= smps;
4692 }
4693
4694 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4695 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4696
4697 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4698 u32 stbc;
4699
4700 stbc = ar->ht_cap_info;
4701 stbc &= WMI_HT_CAP_RX_STBC;
4702 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4703 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4704 stbc &= IEEE80211_HT_CAP_RX_STBC;
4705
4706 ht_cap.cap |= stbc;
4707 }
4708
4709 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4710 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4711
4712 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4713 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4714
4715 /* max AMSDU is implicitly taken from vht_cap_info */
4716 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4717 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4718
Michal Kazior8865bee42013-07-24 12:36:46 +02004719 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004720 ht_cap.mcs.rx_mask[i] = 0xFF;
4721
4722 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4723
4724 return ht_cap;
4725}
4726
Kalle Valo5e3dd152013-06-12 20:52:10 +03004727static void ath10k_get_arvif_iter(void *data, u8 *mac,
4728 struct ieee80211_vif *vif)
4729{
4730 struct ath10k_vif_iter *arvif_iter = data;
4731 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4732
4733 if (arvif->vdev_id == arvif_iter->vdev_id)
4734 arvif_iter->arvif = arvif;
4735}
4736
4737struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4738{
4739 struct ath10k_vif_iter arvif_iter;
4740 u32 flags;
4741
4742 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4743 arvif_iter.vdev_id = vdev_id;
4744
4745 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4746 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4747 flags,
4748 ath10k_get_arvif_iter,
4749 &arvif_iter);
4750 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004751 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004752 return NULL;
4753 }
4754
4755 return arvif_iter.arvif;
4756}
4757
4758int ath10k_mac_register(struct ath10k *ar)
4759{
4760 struct ieee80211_supported_band *band;
4761 struct ieee80211_sta_vht_cap vht_cap;
4762 struct ieee80211_sta_ht_cap ht_cap;
4763 void *channels;
4764 int ret;
4765
4766 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4767
4768 SET_IEEE80211_DEV(ar->hw, ar->dev);
4769
4770 ht_cap = ath10k_get_ht_cap(ar);
4771 vht_cap = ath10k_create_vht_cap(ar);
4772
4773 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4774 channels = kmemdup(ath10k_2ghz_channels,
4775 sizeof(ath10k_2ghz_channels),
4776 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004777 if (!channels) {
4778 ret = -ENOMEM;
4779 goto err_free;
4780 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004781
4782 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4783 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4784 band->channels = channels;
4785 band->n_bitrates = ath10k_g_rates_size;
4786 band->bitrates = ath10k_g_rates;
4787 band->ht_cap = ht_cap;
4788
4789 /* vht is not supported in 2.4 GHz */
4790
4791 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4792 }
4793
4794 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4795 channels = kmemdup(ath10k_5ghz_channels,
4796 sizeof(ath10k_5ghz_channels),
4797 GFP_KERNEL);
4798 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004799 ret = -ENOMEM;
4800 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004801 }
4802
4803 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4804 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4805 band->channels = channels;
4806 band->n_bitrates = ath10k_a_rates_size;
4807 band->bitrates = ath10k_a_rates;
4808 band->ht_cap = ht_cap;
4809 band->vht_cap = vht_cap;
4810 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4811 }
4812
4813 ar->hw->wiphy->interface_modes =
4814 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004815 BIT(NL80211_IFTYPE_AP);
4816
Ben Greear46acf7b2014-05-16 17:15:38 +03004817 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4818 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4819
Bartosz Markowskid3541812013-12-10 16:20:40 +01004820 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4821 ar->hw->wiphy->interface_modes |=
4822 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4823 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004824
4825 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4826 IEEE80211_HW_SUPPORTS_PS |
4827 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4828 IEEE80211_HW_SUPPORTS_UAPSD |
4829 IEEE80211_HW_MFP_CAPABLE |
4830 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4831 IEEE80211_HW_HAS_RATE_CONTROL |
4832 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004833 IEEE80211_HW_AP_LINK_PS |
4834 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004835
Michal Kazior1f8bb152013-09-18 14:43:22 +02004836 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4837 * bytes is used for padding/alignment if necessary. */
4838 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4839
Kalle Valo5e3dd152013-06-12 20:52:10 +03004840 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4841 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4842
4843 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4844 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4845 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4846 }
4847
4848 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4849 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4850
4851 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004852 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004853
Kalle Valo5e3dd152013-06-12 20:52:10 +03004854 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4855
4856 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004857 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004858 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4859
4860 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4861 /*
4862 * on LL hardware queues are managed entirely by the FW
4863 * so we only advertise to mac we can do the queues thing
4864 */
4865 ar->hw->queues = 4;
4866
Bartosz Markowskif2595092013-12-10 16:20:39 +01004867 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4868 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4869 ar->hw->wiphy->n_iface_combinations =
4870 ARRAY_SIZE(ath10k_10x_if_comb);
4871 } else {
4872 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4873 ar->hw->wiphy->n_iface_combinations =
4874 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004875
4876 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004877 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004878
Michal Kazior7c199992013-07-31 10:47:57 +02004879 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4880
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004881 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4882 /* Init ath dfs pattern detector */
4883 ar->ath_common.debug_mask = ATH_DBG_DFS;
4884 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4885 NL80211_DFS_UNSET);
4886
4887 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004888 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004889 }
4890
Kalle Valo5e3dd152013-06-12 20:52:10 +03004891 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4892 ath10k_reg_notifier);
4893 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004894 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004895 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004896 }
4897
4898 ret = ieee80211_register_hw(ar->hw);
4899 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004900 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004901 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004902 }
4903
4904 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4905 ret = regulatory_hint(ar->hw->wiphy,
4906 ar->ath_common.regulatory.alpha2);
4907 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004908 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004909 }
4910
4911 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004912
4913err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004914 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004915err_free:
4916 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4917 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4918
Kalle Valo5e3dd152013-06-12 20:52:10 +03004919 return ret;
4920}
4921
4922void ath10k_mac_unregister(struct ath10k *ar)
4923{
4924 ieee80211_unregister_hw(ar->hw);
4925
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004926 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4927 ar->dfs_detector->exit(ar->dfs_detector);
4928
Kalle Valo5e3dd152013-06-12 20:52:10 +03004929 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4930 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4931
4932 SET_IEEE80211_DEV(ar->hw, NULL);
4933}