blob: 8ad03d530820445ae0b6c1ce6daec6f59e48b54e [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"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030057 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
58 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
59 else
60 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030061 break;
62 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030063 arg.key_cipher = WMI_CIPHER_TKIP;
64 arg.key_txmic_len = 8;
65 arg.key_rxmic_len = 8;
66 break;
67 case WLAN_CIPHER_SUITE_WEP40:
68 case WLAN_CIPHER_SUITE_WEP104:
69 arg.key_cipher = WMI_CIPHER_WEP;
70 /* AP/IBSS mode requires self-key to be groupwise
71 * Otherwise pairwise key must be set */
72 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
73 arg.key_flags = WMI_KEY_PAIRWISE;
74 break;
75 default:
76 ath10k_warn("cipher %d is not supported\n", key->cipher);
77 return -EOPNOTSUPP;
78 }
79
80 if (cmd == DISABLE_KEY) {
81 arg.key_cipher = WMI_CIPHER_NONE;
82 arg.key_data = NULL;
83 }
84
85 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
86}
87
88static int ath10k_install_key(struct ath10k_vif *arvif,
89 struct ieee80211_key_conf *key,
90 enum set_key_cmd cmd,
91 const u8 *macaddr)
92{
93 struct ath10k *ar = arvif->ar;
94 int ret;
95
Michal Kazior548db542013-07-05 16:15:15 +030096 lockdep_assert_held(&ar->conf_mutex);
97
Wolfram Sang16735d02013-11-14 14:32:02 -080098 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +030099
100 ret = ath10k_send_key(arvif, key, cmd, macaddr);
101 if (ret)
102 return ret;
103
104 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
105 if (ret == 0)
106 return -ETIMEDOUT;
107
108 return 0;
109}
110
111static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
112 const u8 *addr)
113{
114 struct ath10k *ar = arvif->ar;
115 struct ath10k_peer *peer;
116 int ret;
117 int i;
118
119 lockdep_assert_held(&ar->conf_mutex);
120
121 spin_lock_bh(&ar->data_lock);
122 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
123 spin_unlock_bh(&ar->data_lock);
124
125 if (!peer)
126 return -ENOENT;
127
128 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
129 if (arvif->wep_keys[i] == NULL)
130 continue;
131
132 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
133 addr);
134 if (ret)
135 return ret;
136
137 peer->keys[i] = arvif->wep_keys[i];
138 }
139
140 return 0;
141}
142
143static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
144 const u8 *addr)
145{
146 struct ath10k *ar = arvif->ar;
147 struct ath10k_peer *peer;
148 int first_errno = 0;
149 int ret;
150 int i;
151
152 lockdep_assert_held(&ar->conf_mutex);
153
154 spin_lock_bh(&ar->data_lock);
155 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
156 spin_unlock_bh(&ar->data_lock);
157
158 if (!peer)
159 return -ENOENT;
160
161 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
162 if (peer->keys[i] == NULL)
163 continue;
164
165 ret = ath10k_install_key(arvif, peer->keys[i],
166 DISABLE_KEY, addr);
167 if (ret && first_errno == 0)
168 first_errno = ret;
169
170 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200171 ath10k_warn("failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300172 i, ret);
173
174 peer->keys[i] = NULL;
175 }
176
177 return first_errno;
178}
179
180static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
181 struct ieee80211_key_conf *key)
182{
183 struct ath10k *ar = arvif->ar;
184 struct ath10k_peer *peer;
185 u8 addr[ETH_ALEN];
186 int first_errno = 0;
187 int ret;
188 int i;
189
190 lockdep_assert_held(&ar->conf_mutex);
191
192 for (;;) {
193 /* since ath10k_install_key we can't hold data_lock all the
194 * time, so we try to remove the keys incrementally */
195 spin_lock_bh(&ar->data_lock);
196 i = 0;
197 list_for_each_entry(peer, &ar->peers, list) {
198 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
199 if (peer->keys[i] == key) {
200 memcpy(addr, peer->addr, ETH_ALEN);
201 peer->keys[i] = NULL;
202 break;
203 }
204 }
205
206 if (i < ARRAY_SIZE(peer->keys))
207 break;
208 }
209 spin_unlock_bh(&ar->data_lock);
210
211 if (i == ARRAY_SIZE(peer->keys))
212 break;
213
214 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
215 if (ret && first_errno == 0)
216 first_errno = ret;
217
218 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200219 ath10k_warn("failed to remove key for %pM: %d\n",
220 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300221 }
222
223 return first_errno;
224}
225
226
227/*********************/
228/* General utilities */
229/*********************/
230
231static inline enum wmi_phy_mode
232chan_to_phymode(const struct cfg80211_chan_def *chandef)
233{
234 enum wmi_phy_mode phymode = MODE_UNKNOWN;
235
236 switch (chandef->chan->band) {
237 case IEEE80211_BAND_2GHZ:
238 switch (chandef->width) {
239 case NL80211_CHAN_WIDTH_20_NOHT:
240 phymode = MODE_11G;
241 break;
242 case NL80211_CHAN_WIDTH_20:
243 phymode = MODE_11NG_HT20;
244 break;
245 case NL80211_CHAN_WIDTH_40:
246 phymode = MODE_11NG_HT40;
247 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400248 case NL80211_CHAN_WIDTH_5:
249 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300250 case NL80211_CHAN_WIDTH_80:
251 case NL80211_CHAN_WIDTH_80P80:
252 case NL80211_CHAN_WIDTH_160:
253 phymode = MODE_UNKNOWN;
254 break;
255 }
256 break;
257 case IEEE80211_BAND_5GHZ:
258 switch (chandef->width) {
259 case NL80211_CHAN_WIDTH_20_NOHT:
260 phymode = MODE_11A;
261 break;
262 case NL80211_CHAN_WIDTH_20:
263 phymode = MODE_11NA_HT20;
264 break;
265 case NL80211_CHAN_WIDTH_40:
266 phymode = MODE_11NA_HT40;
267 break;
268 case NL80211_CHAN_WIDTH_80:
269 phymode = MODE_11AC_VHT80;
270 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400271 case NL80211_CHAN_WIDTH_5:
272 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 case NL80211_CHAN_WIDTH_80P80:
274 case NL80211_CHAN_WIDTH_160:
275 phymode = MODE_UNKNOWN;
276 break;
277 }
278 break;
279 default:
280 break;
281 }
282
283 WARN_ON(phymode == MODE_UNKNOWN);
284 return phymode;
285}
286
287static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
288{
289/*
290 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
291 * 0 for no restriction
292 * 1 for 1/4 us
293 * 2 for 1/2 us
294 * 3 for 1 us
295 * 4 for 2 us
296 * 5 for 4 us
297 * 6 for 8 us
298 * 7 for 16 us
299 */
300 switch (mpdudensity) {
301 case 0:
302 return 0;
303 case 1:
304 case 2:
305 case 3:
306 /* Our lower layer calculations limit our precision to
307 1 microsecond */
308 return 1;
309 case 4:
310 return 2;
311 case 5:
312 return 4;
313 case 6:
314 return 8;
315 case 7:
316 return 16;
317 default:
318 return 0;
319 }
320}
321
322static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
323{
324 int ret;
325
326 lockdep_assert_held(&ar->conf_mutex);
327
328 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800329 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200330 ath10k_warn("failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200331 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300332 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800333 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300334
335 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800336 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200337 ath10k_warn("failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200338 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300339 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800340 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100341 spin_lock_bh(&ar->data_lock);
342 ar->num_peers++;
343 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300344
345 return 0;
346}
347
Kalle Valo5a13e762014-01-20 11:01:46 +0200348static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
349{
350 struct ath10k *ar = arvif->ar;
351 u32 param;
352 int ret;
353
354 param = ar->wmi.pdev_param->sta_kickout_th;
355 ret = ath10k_wmi_pdev_set_param(ar, param,
356 ATH10K_KICKOUT_THRESHOLD);
357 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200358 ath10k_warn("failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200359 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200360 return ret;
361 }
362
363 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
364 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
365 ATH10K_KEEPALIVE_MIN_IDLE);
366 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200367 ath10k_warn("failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200368 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200369 return ret;
370 }
371
372 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
373 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
374 ATH10K_KEEPALIVE_MAX_IDLE);
375 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200376 ath10k_warn("failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200377 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200378 return ret;
379 }
380
381 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
382 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
383 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
384 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200385 ath10k_warn("failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200386 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200387 return ret;
388 }
389
390 return 0;
391}
392
Michal Kazior424121c2013-07-22 14:13:31 +0200393static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
394{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200395 struct ath10k *ar = arvif->ar;
396 u32 vdev_param;
397
Michal Kazior424121c2013-07-22 14:13:31 +0200398 if (value != 0xFFFFFFFF)
399 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
400 ATH10K_RTS_MAX);
401
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200402 vdev_param = ar->wmi.vdev_param->rts_threshold;
403 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200404}
405
406static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
407{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200408 struct ath10k *ar = arvif->ar;
409 u32 vdev_param;
410
Michal Kazior424121c2013-07-22 14:13:31 +0200411 if (value != 0xFFFFFFFF)
412 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
413 ATH10K_FRAGMT_THRESHOLD_MIN,
414 ATH10K_FRAGMT_THRESHOLD_MAX);
415
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200416 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
417 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200418}
419
Kalle Valo5e3dd152013-06-12 20:52:10 +0300420static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
421{
422 int ret;
423
424 lockdep_assert_held(&ar->conf_mutex);
425
426 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
427 if (ret)
428 return ret;
429
430 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
431 if (ret)
432 return ret;
433
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100434 spin_lock_bh(&ar->data_lock);
435 ar->num_peers--;
436 spin_unlock_bh(&ar->data_lock);
437
Kalle Valo5e3dd152013-06-12 20:52:10 +0300438 return 0;
439}
440
441static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
442{
443 struct ath10k_peer *peer, *tmp;
444
445 lockdep_assert_held(&ar->conf_mutex);
446
447 spin_lock_bh(&ar->data_lock);
448 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
449 if (peer->vdev_id != vdev_id)
450 continue;
451
452 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
453 peer->addr, vdev_id);
454
455 list_del(&peer->list);
456 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100457 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300458 }
459 spin_unlock_bh(&ar->data_lock);
460}
461
Michal Kaziora96d7742013-07-16 09:38:56 +0200462static void ath10k_peer_cleanup_all(struct ath10k *ar)
463{
464 struct ath10k_peer *peer, *tmp;
465
466 lockdep_assert_held(&ar->conf_mutex);
467
468 spin_lock_bh(&ar->data_lock);
469 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
470 list_del(&peer->list);
471 kfree(peer);
472 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100473 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200474 spin_unlock_bh(&ar->data_lock);
475}
476
Kalle Valo5e3dd152013-06-12 20:52:10 +0300477/************************/
478/* Interface management */
479/************************/
480
481static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
482{
483 int ret;
484
Michal Kazior548db542013-07-05 16:15:15 +0300485 lockdep_assert_held(&ar->conf_mutex);
486
Kalle Valo5e3dd152013-06-12 20:52:10 +0300487 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
488 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
489 if (ret == 0)
490 return -ETIMEDOUT;
491
492 return 0;
493}
494
Michal Kazior1bbc0972014-04-08 09:45:47 +0300495static bool ath10k_monitor_is_enabled(struct ath10k *ar)
496{
497 lockdep_assert_held(&ar->conf_mutex);
498
499 ath10k_dbg(ATH10K_DBG_MAC,
500 "mac monitor refs: promisc %d monitor %d cac %d\n",
501 ar->promisc, ar->monitor,
502 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags));
503
504 return ar->promisc || ar->monitor ||
505 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
506}
507
508static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300509{
Michal Kaziorc930f742014-01-23 11:38:25 +0100510 struct cfg80211_chan_def *chandef = &ar->chandef;
511 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300512 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300513 int ret = 0;
514
515 lockdep_assert_held(&ar->conf_mutex);
516
Kalle Valo5e3dd152013-06-12 20:52:10 +0300517 arg.vdev_id = vdev_id;
518 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100519 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300520
521 /* TODO setup this dynamically, what in case we
522 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100523 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200524 arg.channel.chan_radar =
525 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300526
Michal Kazior89c5c842013-10-23 04:02:13 -0700527 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700528 arg.channel.max_power = channel->max_power * 2;
529 arg.channel.max_reg_power = channel->max_reg_power * 2;
530 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300531
532 ret = ath10k_wmi_vdev_start(ar, &arg);
533 if (ret) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300534 ath10k_warn("failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200535 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300536 return ret;
537 }
538
539 ret = ath10k_vdev_setup_sync(ar);
540 if (ret) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300541 ath10k_warn("failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200542 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300543 return ret;
544 }
545
546 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
547 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200548 ath10k_warn("failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200549 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300550 goto vdev_stop;
551 }
552
553 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300554
Michal Kazior1bbc0972014-04-08 09:45:47 +0300555 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
556 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300557 return 0;
558
559vdev_stop:
560 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
561 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200562 ath10k_warn("failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200563 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300564
565 return ret;
566}
567
Michal Kazior1bbc0972014-04-08 09:45:47 +0300568static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300569{
570 int ret = 0;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200574 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
575 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200576 ath10k_warn("failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200577 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300578
579 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
580 if (ret)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300581 ath10k_warn("failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200582 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583
584 ret = ath10k_vdev_setup_sync(ar);
585 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200586 ath10k_warn("failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200587 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300588
Michal Kazior1bbc0972014-04-08 09:45:47 +0300589 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
590 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591 return ret;
592}
593
Michal Kazior1bbc0972014-04-08 09:45:47 +0300594static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595{
596 int bit, ret = 0;
597
598 lockdep_assert_held(&ar->conf_mutex);
599
Kalle Valo5e3dd152013-06-12 20:52:10 +0300600 bit = ffs(ar->free_vdev_map);
601 if (bit == 0) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300602 ath10k_warn("failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300603 return -ENOMEM;
604 }
605
606 ar->monitor_vdev_id = bit - 1;
607 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
608
609 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
610 WMI_VDEV_TYPE_MONITOR,
611 0, ar->mac_addr);
612 if (ret) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300613 ath10k_warn("failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200614 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300615 goto vdev_fail;
616 }
617
Kalle Valo60c3daa2013-09-08 17:56:07 +0300618 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619 ar->monitor_vdev_id);
620
Kalle Valo5e3dd152013-06-12 20:52:10 +0300621 return 0;
622
623vdev_fail:
624 /*
625 * Restore the ID to the global map.
626 */
627 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
628 return ret;
629}
630
Michal Kazior1bbc0972014-04-08 09:45:47 +0300631static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300632{
633 int ret = 0;
634
635 lockdep_assert_held(&ar->conf_mutex);
636
Kalle Valo5e3dd152013-06-12 20:52:10 +0300637 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
638 if (ret) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300639 ath10k_warn("failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200640 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300641 return ret;
642 }
643
644 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645
Kalle Valo60c3daa2013-09-08 17:56:07 +0300646 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300647 ar->monitor_vdev_id);
648 return ret;
649}
650
Michal Kazior1bbc0972014-04-08 09:45:47 +0300651static int ath10k_monitor_start(struct ath10k *ar)
652{
653 int ret;
654
655 lockdep_assert_held(&ar->conf_mutex);
656
657 if (!ath10k_monitor_is_enabled(ar)) {
658 ath10k_warn("trying to start monitor with no references\n");
659 return 0;
660 }
661
662 if (ar->monitor_started) {
663 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor already started\n");
664 return 0;
665 }
666
667 ret = ath10k_monitor_vdev_create(ar);
668 if (ret) {
669 ath10k_warn("failed to create monitor vdev: %d\n", ret);
670 return ret;
671 }
672
673 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
674 if (ret) {
675 ath10k_warn("failed to start monitor vdev: %d\n", ret);
676 ath10k_monitor_vdev_delete(ar);
677 return ret;
678 }
679
680 ar->monitor_started = true;
681 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor started\n");
682
683 return 0;
684}
685
686static void ath10k_monitor_stop(struct ath10k *ar)
687{
688 int ret;
689
690 lockdep_assert_held(&ar->conf_mutex);
691
692 if (ath10k_monitor_is_enabled(ar)) {
693 ath10k_dbg(ATH10K_DBG_MAC,
694 "mac monitor will be stopped later\n");
695 return;
696 }
697
698 if (!ar->monitor_started) {
699 ath10k_dbg(ATH10K_DBG_MAC,
700 "mac monitor probably failed to start earlier\n");
701 return;
702 }
703
704 ret = ath10k_monitor_vdev_stop(ar);
705 if (ret)
706 ath10k_warn("failed to stop monitor vdev: %d\n", ret);
707
708 ret = ath10k_monitor_vdev_delete(ar);
709 if (ret)
710 ath10k_warn("failed to delete monitor vdev: %d\n", ret);
711
712 ar->monitor_started = false;
713 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor stopped\n");
714}
715
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200716static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
717{
718 struct ath10k *ar = arvif->ar;
719 u32 vdev_param, rts_cts = 0;
720
721 lockdep_assert_held(&ar->conf_mutex);
722
723 vdev_param = ar->wmi.vdev_param->enable_rtscts;
724
725 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
726 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
727
728 if (arvif->num_legacy_stations > 0)
729 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
730 WMI_RTSCTS_PROFILE);
731
732 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
733 rts_cts);
734}
735
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200736static int ath10k_start_cac(struct ath10k *ar)
737{
738 int ret;
739
740 lockdep_assert_held(&ar->conf_mutex);
741
742 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
743
Michal Kazior1bbc0972014-04-08 09:45:47 +0300744 ret = ath10k_monitor_start(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200745 if (ret) {
Michal Kazior1bbc0972014-04-08 09:45:47 +0300746 ath10k_warn("failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200747 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
748 return ret;
749 }
750
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200751 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
752 ar->monitor_vdev_id);
753
754 return 0;
755}
756
757static int ath10k_stop_cac(struct ath10k *ar)
758{
759 lockdep_assert_held(&ar->conf_mutex);
760
761 /* CAC is not running - do nothing */
762 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
763 return 0;
764
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200765 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300766 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200767
768 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
769
770 return 0;
771}
772
Michal Kaziord6500972014-04-08 09:56:09 +0300773static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200774{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200775 int ret;
776
777 lockdep_assert_held(&ar->conf_mutex);
778
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200779 ath10k_stop_cac(ar);
780
Michal Kaziord6500972014-04-08 09:56:09 +0300781 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200782 return;
783
Michal Kaziord6500972014-04-08 09:56:09 +0300784 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200785 return;
786
787 ret = ath10k_start_cac(ar);
788 if (ret) {
789 /*
790 * Not possible to start CAC on current channel so starting
791 * radiation is not allowed, make this channel DFS_UNAVAILABLE
792 * by indicating that radar was detected.
793 */
Kalle Valobe6546f2014-03-25 14:18:51 +0200794 ath10k_warn("failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200795 ieee80211_radar_detected(ar->hw);
796 }
797}
798
Michal Kazior72654fa2014-04-08 09:56:09 +0300799static int ath10k_vdev_start(struct ath10k_vif *arvif)
800{
801 struct ath10k *ar = arvif->ar;
802 struct cfg80211_chan_def *chandef = &ar->chandef;
803 struct wmi_vdev_start_request_arg arg = {};
804 int ret = 0;
805
806 lockdep_assert_held(&ar->conf_mutex);
807
808 reinit_completion(&ar->vdev_setup_done);
809
810 arg.vdev_id = arvif->vdev_id;
811 arg.dtim_period = arvif->dtim_period;
812 arg.bcn_intval = arvif->beacon_interval;
813
814 arg.channel.freq = chandef->chan->center_freq;
815 arg.channel.band_center_freq1 = chandef->center_freq1;
816 arg.channel.mode = chan_to_phymode(chandef);
817
818 arg.channel.min_power = 0;
819 arg.channel.max_power = chandef->chan->max_power * 2;
820 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
821 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
822
823 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
824 arg.ssid = arvif->u.ap.ssid;
825 arg.ssid_len = arvif->u.ap.ssid_len;
826 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
827
828 /* For now allow DFS for AP mode */
829 arg.channel.chan_radar =
830 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
831 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
832 arg.ssid = arvif->vif->bss_conf.ssid;
833 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
834 }
835
836 ath10k_dbg(ATH10K_DBG_MAC,
837 "mac vdev %d start center_freq %d phymode %s\n",
838 arg.vdev_id, arg.channel.freq,
839 ath10k_wmi_phymode_str(arg.channel.mode));
840
841 ret = ath10k_wmi_vdev_start(ar, &arg);
842 if (ret) {
843 ath10k_warn("failed to start WMI vdev %i: %d\n",
844 arg.vdev_id, ret);
845 return ret;
846 }
847
848 ret = ath10k_vdev_setup_sync(ar);
849 if (ret) {
850 ath10k_warn("failed to synchronise setup for vdev %i: %d\n",
851 arg.vdev_id, ret);
852 return ret;
853 }
854
Michal Kaziord6500972014-04-08 09:56:09 +0300855 ar->num_started_vdevs++;
856 ath10k_recalc_radar_detection(ar);
857
Michal Kazior72654fa2014-04-08 09:56:09 +0300858 return ret;
859}
860
861static int ath10k_vdev_stop(struct ath10k_vif *arvif)
862{
863 struct ath10k *ar = arvif->ar;
864 int ret;
865
866 lockdep_assert_held(&ar->conf_mutex);
867
868 reinit_completion(&ar->vdev_setup_done);
869
870 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
871 if (ret) {
872 ath10k_warn("failed to stop WMI vdev %i: %d\n",
873 arvif->vdev_id, ret);
874 return ret;
875 }
876
877 ret = ath10k_vdev_setup_sync(ar);
878 if (ret) {
879 ath10k_warn("failed to syncronise setup for vdev %i: %d\n",
880 arvif->vdev_id, ret);
881 return ret;
882 }
883
Michal Kaziord6500972014-04-08 09:56:09 +0300884 WARN_ON(ar->num_started_vdevs == 0);
885
886 if (ar->num_started_vdevs != 0) {
887 ar->num_started_vdevs--;
888 ath10k_recalc_radar_detection(ar);
889 }
890
Michal Kazior72654fa2014-04-08 09:56:09 +0300891 return ret;
892}
893
Kalle Valo5e3dd152013-06-12 20:52:10 +0300894static void ath10k_control_beaconing(struct ath10k_vif *arvif,
895 struct ieee80211_bss_conf *info)
896{
897 int ret = 0;
898
Michal Kazior548db542013-07-05 16:15:15 +0300899 lockdep_assert_held(&arvif->ar->conf_mutex);
900
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901 if (!info->enable_beacon) {
902 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100903
904 arvif->is_started = false;
905 arvif->is_up = false;
906
Michal Kazior748afc42014-01-23 12:48:21 +0100907 spin_lock_bh(&arvif->ar->data_lock);
908 if (arvif->beacon) {
Michal Kazior767d34f2014-02-27 18:50:03 +0200909 dma_unmap_single(arvif->ar->dev,
910 ATH10K_SKB_CB(arvif->beacon)->paddr,
911 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kazior748afc42014-01-23 12:48:21 +0100912 dev_kfree_skb_any(arvif->beacon);
913
914 arvif->beacon = NULL;
915 arvif->beacon_sent = false;
916 }
917 spin_unlock_bh(&arvif->ar->data_lock);
918
Kalle Valo5e3dd152013-06-12 20:52:10 +0300919 return;
920 }
921
922 arvif->tx_seq_no = 0x1000;
923
924 ret = ath10k_vdev_start(arvif);
925 if (ret)
926 return;
927
Michal Kaziorc930f742014-01-23 11:38:25 +0100928 arvif->aid = 0;
929 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
930
931 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
932 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300933 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200934 ath10k_warn("failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200935 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100936 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300937 return;
938 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100939
940 arvif->is_started = true;
941 arvif->is_up = true;
942
Kalle Valo60c3daa2013-09-08 17:56:07 +0300943 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944}
945
946static void ath10k_control_ibss(struct ath10k_vif *arvif,
947 struct ieee80211_bss_conf *info,
948 const u8 self_peer[ETH_ALEN])
949{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200950 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300951 int ret = 0;
952
Michal Kazior548db542013-07-05 16:15:15 +0300953 lockdep_assert_held(&arvif->ar->conf_mutex);
954
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955 if (!info->ibss_joined) {
956 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
957 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200958 ath10k_warn("failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300959 self_peer, arvif->vdev_id, ret);
960
Michal Kaziorc930f742014-01-23 11:38:25 +0100961 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300962 return;
963
964 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100965 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300966 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200967 ath10k_warn("failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100968 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300969 return;
970 }
971
Michal Kaziorc930f742014-01-23 11:38:25 +0100972 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300973
974 return;
975 }
976
977 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
978 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +0200979 ath10k_warn("failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980 self_peer, arvif->vdev_id, ret);
981 return;
982 }
983
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200984 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
985 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300986 ATH10K_DEFAULT_ATIM);
987 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +0200988 ath10k_warn("failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300989 arvif->vdev_id, ret);
990}
991
992/*
993 * Review this when mac80211 gains per-interface powersave support.
994 */
Michal Kaziorad088bf2013-10-16 15:44:46 +0300995static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300996{
Michal Kaziorad088bf2013-10-16 15:44:46 +0300997 struct ath10k *ar = arvif->ar;
998 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300999 enum wmi_sta_powersave_param param;
1000 enum wmi_sta_ps_mode psmode;
1001 int ret;
1002
Michal Kazior548db542013-07-05 16:15:15 +03001003 lockdep_assert_held(&arvif->ar->conf_mutex);
1004
Michal Kaziorad088bf2013-10-16 15:44:46 +03001005 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1006 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001007
1008 if (conf->flags & IEEE80211_CONF_PS) {
1009 psmode = WMI_STA_PS_MODE_ENABLED;
1010 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1011
Michal Kaziorad088bf2013-10-16 15:44:46 +03001012 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001013 conf->dynamic_ps_timeout);
1014 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001015 ath10k_warn("failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001016 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001017 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001019 } else {
1020 psmode = WMI_STA_PS_MODE_DISABLED;
1021 }
1022
Kalle Valo60c3daa2013-09-08 17:56:07 +03001023 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1024 arvif->vdev_id, psmode ? "enable" : "disable");
1025
Michal Kaziorad088bf2013-10-16 15:44:46 +03001026 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1027 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001028 ath10k_warn("failed to set PS Mode %d for vdev %d: %d\n",
1029 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001030 return ret;
1031 }
1032
1033 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001034}
1035
1036/**********************/
1037/* Station management */
1038/**********************/
1039
1040static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1041 struct ath10k_vif *arvif,
1042 struct ieee80211_sta *sta,
1043 struct ieee80211_bss_conf *bss_conf,
1044 struct wmi_peer_assoc_complete_arg *arg)
1045{
Michal Kazior548db542013-07-05 16:15:15 +03001046 lockdep_assert_held(&ar->conf_mutex);
1047
Kalle Valo5e3dd152013-06-12 20:52:10 +03001048 memcpy(arg->addr, sta->addr, ETH_ALEN);
1049 arg->vdev_id = arvif->vdev_id;
1050 arg->peer_aid = sta->aid;
1051 arg->peer_flags |= WMI_PEER_AUTH;
1052
1053 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1054 /*
1055 * Seems FW have problems with Power Save in STA
1056 * mode when we setup this parameter to high (eg. 5).
1057 * Often we see that FW don't send NULL (with clean P flags)
1058 * frame even there is info about buffered frames in beacons.
1059 * Sometimes we have to wait more than 10 seconds before FW
1060 * will wakeup. Often sending one ping from AP to our device
1061 * just fail (more than 50%).
1062 *
1063 * Seems setting this FW parameter to 1 couse FW
1064 * will check every beacon and will wakup immediately
1065 * after detection buffered data.
1066 */
1067 arg->peer_listen_intval = 1;
1068 else
1069 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1070
1071 arg->peer_num_spatial_streams = 1;
1072
1073 /*
1074 * The assoc capabilities are available only in managed mode.
1075 */
1076 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1077 arg->peer_caps = bss_conf->assoc_capability;
1078}
1079
1080static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1081 struct ath10k_vif *arvif,
1082 struct wmi_peer_assoc_complete_arg *arg)
1083{
1084 struct ieee80211_vif *vif = arvif->vif;
1085 struct ieee80211_bss_conf *info = &vif->bss_conf;
1086 struct cfg80211_bss *bss;
1087 const u8 *rsnie = NULL;
1088 const u8 *wpaie = NULL;
1089
Michal Kazior548db542013-07-05 16:15:15 +03001090 lockdep_assert_held(&ar->conf_mutex);
1091
Kalle Valo5e3dd152013-06-12 20:52:10 +03001092 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1093 info->bssid, NULL, 0, 0, 0);
1094 if (bss) {
1095 const struct cfg80211_bss_ies *ies;
1096
1097 rcu_read_lock();
1098 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1099
1100 ies = rcu_dereference(bss->ies);
1101
1102 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1103 WLAN_OUI_TYPE_MICROSOFT_WPA,
1104 ies->data,
1105 ies->len);
1106 rcu_read_unlock();
1107 cfg80211_put_bss(ar->hw->wiphy, bss);
1108 }
1109
1110 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1111 if (rsnie || wpaie) {
1112 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1113 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1114 }
1115
1116 if (wpaie) {
1117 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1118 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1119 }
1120}
1121
1122static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1123 struct ieee80211_sta *sta,
1124 struct wmi_peer_assoc_complete_arg *arg)
1125{
1126 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1127 const struct ieee80211_supported_band *sband;
1128 const struct ieee80211_rate *rates;
1129 u32 ratemask;
1130 int i;
1131
Michal Kazior548db542013-07-05 16:15:15 +03001132 lockdep_assert_held(&ar->conf_mutex);
1133
Kalle Valo5e3dd152013-06-12 20:52:10 +03001134 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1135 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1136 rates = sband->bitrates;
1137
1138 rateset->num_rates = 0;
1139
1140 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1141 if (!(ratemask & 1))
1142 continue;
1143
1144 rateset->rates[rateset->num_rates] = rates->hw_value;
1145 rateset->num_rates++;
1146 }
1147}
1148
1149static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1150 struct ieee80211_sta *sta,
1151 struct wmi_peer_assoc_complete_arg *arg)
1152{
1153 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154 int i, n;
1155
Michal Kazior548db542013-07-05 16:15:15 +03001156 lockdep_assert_held(&ar->conf_mutex);
1157
Kalle Valo5e3dd152013-06-12 20:52:10 +03001158 if (!ht_cap->ht_supported)
1159 return;
1160
1161 arg->peer_flags |= WMI_PEER_HT;
1162 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1163 ht_cap->ampdu_factor)) - 1;
1164
1165 arg->peer_mpdu_density =
1166 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1167
1168 arg->peer_ht_caps = ht_cap->cap;
1169 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1170
1171 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1172 arg->peer_flags |= WMI_PEER_LDPC;
1173
1174 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1175 arg->peer_flags |= WMI_PEER_40MHZ;
1176 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1177 }
1178
1179 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1180 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1181
1182 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1183 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1184
1185 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1186 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1187 arg->peer_flags |= WMI_PEER_STBC;
1188 }
1189
1190 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1191 u32 stbc;
1192 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1193 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1194 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1195 arg->peer_rate_caps |= stbc;
1196 arg->peer_flags |= WMI_PEER_STBC;
1197 }
1198
Kalle Valo5e3dd152013-06-12 20:52:10 +03001199 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1200 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1201 else if (ht_cap->mcs.rx_mask[1])
1202 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1203
1204 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1205 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1206 arg->peer_ht_rates.rates[n++] = i;
1207
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001208 /*
1209 * This is a workaround for HT-enabled STAs which break the spec
1210 * and have no HT capabilities RX mask (no HT RX MCS map).
1211 *
1212 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1213 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1214 *
1215 * Firmware asserts if such situation occurs.
1216 */
1217 if (n == 0) {
1218 arg->peer_ht_rates.num_rates = 8;
1219 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1220 arg->peer_ht_rates.rates[i] = i;
1221 } else {
1222 arg->peer_ht_rates.num_rates = n;
1223 arg->peer_num_spatial_streams = sta->rx_nss;
1224 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001225
Kalle Valo60c3daa2013-09-08 17:56:07 +03001226 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1227 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001228 arg->peer_ht_rates.num_rates,
1229 arg->peer_num_spatial_streams);
1230}
1231
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001232static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1233 struct ath10k_vif *arvif,
1234 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001235{
1236 u32 uapsd = 0;
1237 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001238 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001239
Michal Kazior548db542013-07-05 16:15:15 +03001240 lockdep_assert_held(&ar->conf_mutex);
1241
Kalle Valo5e3dd152013-06-12 20:52:10 +03001242 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001243 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001244 sta->uapsd_queues, sta->max_sp);
1245
Kalle Valo5e3dd152013-06-12 20:52:10 +03001246 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1247 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1248 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1249 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1250 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1251 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1252 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1253 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1254 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1255 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1256 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1257 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1258
1259
1260 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1261 max_sp = sta->max_sp;
1262
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001263 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1264 sta->addr,
1265 WMI_AP_PS_PEER_PARAM_UAPSD,
1266 uapsd);
1267 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001268 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1269 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001270 return ret;
1271 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001272
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001273 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1274 sta->addr,
1275 WMI_AP_PS_PEER_PARAM_MAX_SP,
1276 max_sp);
1277 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001278 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1279 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001280 return ret;
1281 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001282
1283 /* TODO setup this based on STA listen interval and
1284 beacon interval. Currently we don't know
1285 sta->listen_interval - mac80211 patch required.
1286 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001287 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1288 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1289 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001290 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1291 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001292 return ret;
1293 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001294 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001295
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001296 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001297}
1298
1299static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1300 struct ieee80211_sta *sta,
1301 struct wmi_peer_assoc_complete_arg *arg)
1302{
1303 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001304 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305
1306 if (!vht_cap->vht_supported)
1307 return;
1308
1309 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001310 arg->peer_vht_caps = vht_cap->cap;
1311
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001312
1313 ampdu_factor = (vht_cap->cap &
1314 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1315 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1316
1317 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1318 * zero in VHT IE. Using it would result in degraded throughput.
1319 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1320 * it if VHT max_mpdu is smaller. */
1321 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1322 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1323 ampdu_factor)) - 1);
1324
Kalle Valo5e3dd152013-06-12 20:52:10 +03001325 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1326 arg->peer_flags |= WMI_PEER_80MHZ;
1327
1328 arg->peer_vht_rates.rx_max_rate =
1329 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1330 arg->peer_vht_rates.rx_mcs_set =
1331 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1332 arg->peer_vht_rates.tx_max_rate =
1333 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1334 arg->peer_vht_rates.tx_mcs_set =
1335 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1336
Kalle Valo60c3daa2013-09-08 17:56:07 +03001337 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1338 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001339}
1340
1341static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1342 struct ath10k_vif *arvif,
1343 struct ieee80211_sta *sta,
1344 struct ieee80211_bss_conf *bss_conf,
1345 struct wmi_peer_assoc_complete_arg *arg)
1346{
1347 switch (arvif->vdev_type) {
1348 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001349 if (sta->wme)
1350 arg->peer_flags |= WMI_PEER_QOS;
1351
1352 if (sta->wme && sta->uapsd_queues) {
1353 arg->peer_flags |= WMI_PEER_APSD;
1354 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1355 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001356 break;
1357 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001358 if (bss_conf->qos)
1359 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001360 break;
1361 default:
1362 break;
1363 }
1364}
1365
1366static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1367 struct ath10k_vif *arvif,
1368 struct ieee80211_sta *sta,
1369 struct wmi_peer_assoc_complete_arg *arg)
1370{
1371 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1372
Kalle Valo5e3dd152013-06-12 20:52:10 +03001373 switch (ar->hw->conf.chandef.chan->band) {
1374 case IEEE80211_BAND_2GHZ:
1375 if (sta->ht_cap.ht_supported) {
1376 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1377 phymode = MODE_11NG_HT40;
1378 else
1379 phymode = MODE_11NG_HT20;
1380 } else {
1381 phymode = MODE_11G;
1382 }
1383
1384 break;
1385 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001386 /*
1387 * Check VHT first.
1388 */
1389 if (sta->vht_cap.vht_supported) {
1390 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1391 phymode = MODE_11AC_VHT80;
1392 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1393 phymode = MODE_11AC_VHT40;
1394 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1395 phymode = MODE_11AC_VHT20;
1396 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001397 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1398 phymode = MODE_11NA_HT40;
1399 else
1400 phymode = MODE_11NA_HT20;
1401 } else {
1402 phymode = MODE_11A;
1403 }
1404
1405 break;
1406 default:
1407 break;
1408 }
1409
Kalle Valo38a1d472013-09-08 17:56:14 +03001410 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1411 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001412
Kalle Valo5e3dd152013-06-12 20:52:10 +03001413 arg->peer_phymode = phymode;
1414 WARN_ON(phymode == MODE_UNKNOWN);
1415}
1416
Kalle Valob9ada652013-10-16 15:44:46 +03001417static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1418 struct ath10k_vif *arvif,
1419 struct ieee80211_sta *sta,
1420 struct ieee80211_bss_conf *bss_conf,
1421 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001422{
Michal Kazior548db542013-07-05 16:15:15 +03001423 lockdep_assert_held(&ar->conf_mutex);
1424
Kalle Valob9ada652013-10-16 15:44:46 +03001425 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426
Kalle Valob9ada652013-10-16 15:44:46 +03001427 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1428 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1429 ath10k_peer_assoc_h_rates(ar, sta, arg);
1430 ath10k_peer_assoc_h_ht(ar, sta, arg);
1431 ath10k_peer_assoc_h_vht(ar, sta, arg);
1432 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1433 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001434
Kalle Valob9ada652013-10-16 15:44:46 +03001435 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001436}
1437
Michal Kazior90046f52014-02-14 14:45:51 +01001438static const u32 ath10k_smps_map[] = {
1439 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1440 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1441 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1442 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1443};
1444
1445static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1446 const u8 *addr,
1447 const struct ieee80211_sta_ht_cap *ht_cap)
1448{
1449 int smps;
1450
1451 if (!ht_cap->ht_supported)
1452 return 0;
1453
1454 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1455 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1456
1457 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1458 return -EINVAL;
1459
1460 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1461 WMI_PEER_SMPS_STATE,
1462 ath10k_smps_map[smps]);
1463}
1464
Kalle Valo5e3dd152013-06-12 20:52:10 +03001465/* can be called only in mac80211 callbacks due to `key_count` usage */
1466static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1467 struct ieee80211_vif *vif,
1468 struct ieee80211_bss_conf *bss_conf)
1469{
1470 struct ath10k *ar = hw->priv;
1471 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001472 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001473 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001474 struct ieee80211_sta *ap_sta;
1475 int ret;
1476
Michal Kazior548db542013-07-05 16:15:15 +03001477 lockdep_assert_held(&ar->conf_mutex);
1478
Kalle Valo5e3dd152013-06-12 20:52:10 +03001479 rcu_read_lock();
1480
1481 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1482 if (!ap_sta) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001483 ath10k_warn("failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001484 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 rcu_read_unlock();
1486 return;
1487 }
1488
Michal Kazior90046f52014-02-14 14:45:51 +01001489 /* ap_sta must be accessed only within rcu section which must be left
1490 * before calling ath10k_setup_peer_smps() which might sleep. */
1491 ht_cap = ap_sta->ht_cap;
1492
Kalle Valob9ada652013-10-16 15:44:46 +03001493 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1494 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001495 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001496 ath10k_warn("failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001497 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498 rcu_read_unlock();
1499 return;
1500 }
1501
1502 rcu_read_unlock();
1503
Kalle Valob9ada652013-10-16 15:44:46 +03001504 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1505 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001506 ath10k_warn("failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001507 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001508 return;
1509 }
1510
Michal Kazior90046f52014-02-14 14:45:51 +01001511 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1512 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02001513 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1514 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001515 return;
1516 }
1517
Kalle Valo60c3daa2013-09-08 17:56:07 +03001518 ath10k_dbg(ATH10K_DBG_MAC,
1519 "mac vdev %d up (associated) bssid %pM aid %d\n",
1520 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1521
Michal Kaziorc930f742014-01-23 11:38:25 +01001522 arvif->aid = bss_conf->aid;
1523 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1524
1525 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1526 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001527 ath10k_warn("failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001528 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001529 return;
1530 }
1531
1532 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533}
1534
1535/*
1536 * FIXME: flush TIDs
1537 */
1538static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1539 struct ieee80211_vif *vif)
1540{
1541 struct ath10k *ar = hw->priv;
1542 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1543 int ret;
1544
Michal Kazior548db542013-07-05 16:15:15 +03001545 lockdep_assert_held(&ar->conf_mutex);
1546
Kalle Valo5e3dd152013-06-12 20:52:10 +03001547 /*
1548 * For some reason, calling VDEV-DOWN before VDEV-STOP
1549 * makes the FW to send frames via HTT after disassociation.
1550 * No idea why this happens, even though VDEV-DOWN is supposed
1551 * to be analogous to link down, so just stop the VDEV.
1552 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001553 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1554 arvif->vdev_id);
1555
1556 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001557 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558
1559 /*
1560 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1561 * report beacons from previously associated network through HTT.
1562 * This in turn would spam mac80211 WARN_ON if we bring down all
1563 * interfaces as it expects there is no rx when no interface is
1564 * running.
1565 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001566 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1567
1568 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001570
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001571 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001572
1573 arvif->is_started = false;
1574 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575}
1576
1577static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001578 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579{
Kalle Valob9ada652013-10-16 15:44:46 +03001580 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581 int ret = 0;
1582
Michal Kazior548db542013-07-05 16:15:15 +03001583 lockdep_assert_held(&ar->conf_mutex);
1584
Kalle Valob9ada652013-10-16 15:44:46 +03001585 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001587 ath10k_warn("failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001588 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001589 return ret;
1590 }
1591
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001592 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001593 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1594 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001595 ath10k_warn("failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001596 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597 return ret;
1598 }
1599
Michal Kazior90046f52014-02-14 14:45:51 +01001600 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1601 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001602 ath10k_warn("failed to setup peer SMPS for vdev %d: %d\n",
1603 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001604 return ret;
1605 }
1606
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001607 if (!sta->wme) {
1608 arvif->num_legacy_stations++;
1609 ret = ath10k_recalc_rtscts_prot(arvif);
1610 if (ret) {
1611 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1612 arvif->vdev_id, ret);
1613 return ret;
1614 }
1615 }
1616
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1618 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001619 ath10k_warn("failed to install peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001620 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 return ret;
1622 }
1623
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001624 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1625 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001626 ath10k_warn("failed to set qos params for STA %pM for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001627 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001628 return ret;
1629 }
1630
Kalle Valo5e3dd152013-06-12 20:52:10 +03001631 return ret;
1632}
1633
1634static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1635 struct ieee80211_sta *sta)
1636{
1637 int ret = 0;
1638
Michal Kazior548db542013-07-05 16:15:15 +03001639 lockdep_assert_held(&ar->conf_mutex);
1640
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001641 if (!sta->wme) {
1642 arvif->num_legacy_stations--;
1643 ret = ath10k_recalc_rtscts_prot(arvif);
1644 if (ret) {
1645 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1646 arvif->vdev_id, ret);
1647 return ret;
1648 }
1649 }
1650
Kalle Valo5e3dd152013-06-12 20:52:10 +03001651 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1652 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001653 ath10k_warn("failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001654 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001655 return ret;
1656 }
1657
1658 return ret;
1659}
1660
1661/**************/
1662/* Regulatory */
1663/**************/
1664
1665static int ath10k_update_channel_list(struct ath10k *ar)
1666{
1667 struct ieee80211_hw *hw = ar->hw;
1668 struct ieee80211_supported_band **bands;
1669 enum ieee80211_band band;
1670 struct ieee80211_channel *channel;
1671 struct wmi_scan_chan_list_arg arg = {0};
1672 struct wmi_channel_arg *ch;
1673 bool passive;
1674 int len;
1675 int ret;
1676 int i;
1677
Michal Kazior548db542013-07-05 16:15:15 +03001678 lockdep_assert_held(&ar->conf_mutex);
1679
Kalle Valo5e3dd152013-06-12 20:52:10 +03001680 bands = hw->wiphy->bands;
1681 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1682 if (!bands[band])
1683 continue;
1684
1685 for (i = 0; i < bands[band]->n_channels; i++) {
1686 if (bands[band]->channels[i].flags &
1687 IEEE80211_CHAN_DISABLED)
1688 continue;
1689
1690 arg.n_channels++;
1691 }
1692 }
1693
1694 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1695 arg.channels = kzalloc(len, GFP_KERNEL);
1696 if (!arg.channels)
1697 return -ENOMEM;
1698
1699 ch = arg.channels;
1700 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1701 if (!bands[band])
1702 continue;
1703
1704 for (i = 0; i < bands[band]->n_channels; i++) {
1705 channel = &bands[band]->channels[i];
1706
1707 if (channel->flags & IEEE80211_CHAN_DISABLED)
1708 continue;
1709
1710 ch->allow_ht = true;
1711
1712 /* FIXME: when should we really allow VHT? */
1713 ch->allow_vht = true;
1714
1715 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001716 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001717
1718 ch->ht40plus =
1719 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1720
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001721 ch->chan_radar =
1722 !!(channel->flags & IEEE80211_CHAN_RADAR);
1723
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001724 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001725 ch->passive = passive;
1726
1727 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001728 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001729 ch->max_power = channel->max_power * 2;
1730 ch->max_reg_power = channel->max_reg_power * 2;
1731 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001732 ch->reg_class_id = 0; /* FIXME */
1733
1734 /* FIXME: why use only legacy modes, why not any
1735 * HT/VHT modes? Would that even make any
1736 * difference? */
1737 if (channel->band == IEEE80211_BAND_2GHZ)
1738 ch->mode = MODE_11G;
1739 else
1740 ch->mode = MODE_11A;
1741
1742 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1743 continue;
1744
1745 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001746 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1747 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001748 ch->freq, ch->max_power, ch->max_reg_power,
1749 ch->max_antenna_gain, ch->mode);
1750
1751 ch++;
1752 }
1753 }
1754
1755 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1756 kfree(arg.channels);
1757
1758 return ret;
1759}
1760
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001761static enum wmi_dfs_region
1762ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1763{
1764 switch (dfs_region) {
1765 case NL80211_DFS_UNSET:
1766 return WMI_UNINIT_DFS_DOMAIN;
1767 case NL80211_DFS_FCC:
1768 return WMI_FCC_DFS_DOMAIN;
1769 case NL80211_DFS_ETSI:
1770 return WMI_ETSI_DFS_DOMAIN;
1771 case NL80211_DFS_JP:
1772 return WMI_MKK4_DFS_DOMAIN;
1773 }
1774 return WMI_UNINIT_DFS_DOMAIN;
1775}
1776
Michal Kaziorf7843d72013-07-16 09:38:52 +02001777static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001779 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001780 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001781 enum wmi_dfs_region wmi_dfs_reg;
1782 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783
Michal Kaziorf7843d72013-07-16 09:38:52 +02001784 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785
1786 ret = ath10k_update_channel_list(ar);
1787 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02001788 ath10k_warn("failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789
1790 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001791
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001792 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1793 nl_dfs_reg = ar->dfs_detector->region;
1794 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1795 } else {
1796 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1797 }
1798
Kalle Valo5e3dd152013-06-12 20:52:10 +03001799 /* Target allows setting up per-band regdomain but ath_common provides
1800 * a combined one only */
1801 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001802 regpair->reg_domain,
1803 regpair->reg_domain, /* 2ghz */
1804 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001805 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001806 regpair->reg_5ghz_ctl,
1807 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001808 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02001809 ath10k_warn("failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001810}
Michal Kazior548db542013-07-05 16:15:15 +03001811
Michal Kaziorf7843d72013-07-16 09:38:52 +02001812static void ath10k_reg_notifier(struct wiphy *wiphy,
1813 struct regulatory_request *request)
1814{
1815 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1816 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001817 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001818
1819 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1820
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001821 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1822 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1823 request->dfs_region);
1824 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1825 request->dfs_region);
1826 if (!result)
Kalle Valobe6546f2014-03-25 14:18:51 +02001827 ath10k_warn("DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001828 request->dfs_region);
1829 }
1830
Michal Kaziorf7843d72013-07-16 09:38:52 +02001831 mutex_lock(&ar->conf_mutex);
1832 if (ar->state == ATH10K_STATE_ON)
1833 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001834 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835}
1836
1837/***************/
1838/* TX handlers */
1839/***************/
1840
Michal Kazior42c3aa62013-10-02 11:03:38 +02001841static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1842{
1843 if (ieee80211_is_mgmt(hdr->frame_control))
1844 return HTT_DATA_TX_EXT_TID_MGMT;
1845
1846 if (!ieee80211_is_data_qos(hdr->frame_control))
1847 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1848
1849 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1850 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1851
1852 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1853}
1854
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001855static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1856 struct ieee80211_tx_info *info)
1857{
1858 if (info->control.vif)
1859 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1860
Michal Kazior1bbc0972014-04-08 09:45:47 +03001861 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001862 return ar->monitor_vdev_id;
1863
Kalle Valobe6546f2014-03-25 14:18:51 +02001864 ath10k_warn("failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001865 return 0;
1866}
1867
Kalle Valo5e3dd152013-06-12 20:52:10 +03001868/*
1869 * Frames sent to the FW have to be in "Native Wifi" format.
1870 * Strip the QoS field from the 802.11 header.
1871 */
1872static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1873 struct ieee80211_tx_control *control,
1874 struct sk_buff *skb)
1875{
1876 struct ieee80211_hdr *hdr = (void *)skb->data;
1877 u8 *qos_ctl;
1878
1879 if (!ieee80211_is_data_qos(hdr->frame_control))
1880 return;
1881
1882 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001883 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1884 skb->data, (void *)qos_ctl - (void *)skb->data);
1885 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001886}
1887
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001888static void ath10k_tx_wep_key_work(struct work_struct *work)
1889{
1890 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1891 wep_key_work);
1892 int ret, keyidx = arvif->def_wep_key_newidx;
1893
1894 if (arvif->def_wep_key_idx == keyidx)
1895 return;
1896
1897 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1898 arvif->vdev_id, keyidx);
1899
1900 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1901 arvif->vdev_id,
1902 arvif->ar->wmi.vdev_param->def_keyid,
1903 keyidx);
1904 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001905 ath10k_warn("failed to update wep key index for vdev %d: %d\n",
1906 arvif->vdev_id,
1907 ret);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001908 return;
1909 }
1910
1911 arvif->def_wep_key_idx = keyidx;
1912}
1913
Kalle Valo5e3dd152013-06-12 20:52:10 +03001914static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1915{
1916 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1917 struct ieee80211_vif *vif = info->control.vif;
1918 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1919 struct ath10k *ar = arvif->ar;
1920 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1921 struct ieee80211_key_conf *key = info->control.hw_key;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001922
Kalle Valo5e3dd152013-06-12 20:52:10 +03001923 if (!ieee80211_has_protected(hdr->frame_control))
1924 return;
1925
1926 if (!key)
1927 return;
1928
1929 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1930 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1931 return;
1932
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001933 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001934 return;
1935
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001936 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1937 * queueing frames until key index is updated is not an option because
1938 * sk_buff may need more processing to be done, e.g. offchannel */
1939 arvif->def_wep_key_newidx = key->keyidx;
1940 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941}
1942
1943static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1944{
1945 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1946 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1947 struct ieee80211_vif *vif = info->control.vif;
1948 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1949
1950 /* This is case only for P2P_GO */
1951 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1952 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1953 return;
1954
1955 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1956 spin_lock_bh(&ar->data_lock);
1957 if (arvif->u.ap.noa_data)
1958 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1959 GFP_ATOMIC))
1960 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1961 arvif->u.ap.noa_data,
1962 arvif->u.ap.noa_len);
1963 spin_unlock_bh(&ar->data_lock);
1964 }
1965}
1966
1967static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1968{
1969 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001970 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001971
Michal Kazior961d4c32013-08-09 10:13:34 +02001972 if (ar->htt.target_version_major >= 3) {
1973 /* Since HTT 3.0 there is no separate mgmt tx command */
1974 ret = ath10k_htt_tx(&ar->htt, skb);
1975 goto exit;
1976 }
1977
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001978 if (ieee80211_is_mgmt(hdr->frame_control)) {
1979 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1980 ar->fw_features)) {
1981 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1982 ATH10K_MAX_NUM_MGMT_PENDING) {
Kalle Valobe6546f2014-03-25 14:18:51 +02001983 ath10k_warn("reached WMI management tranmist queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001984 ret = -EBUSY;
1985 goto exit;
1986 }
1987
1988 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1989 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1990 } else {
1991 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1992 }
1993 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1994 ar->fw_features) &&
1995 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001996 /* FW does not report tx status properly for NullFunc frames
1997 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001998 * those frames when it detects link/beacon loss and depends
1999 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002000 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002001 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002002 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002003 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004
Michal Kazior961d4c32013-08-09 10:13:34 +02002005exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002007 ath10k_warn("failed to transmit packet, dropping: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008 ieee80211_free_txskb(ar->hw, skb);
2009 }
2010}
2011
2012void ath10k_offchan_tx_purge(struct ath10k *ar)
2013{
2014 struct sk_buff *skb;
2015
2016 for (;;) {
2017 skb = skb_dequeue(&ar->offchan_tx_queue);
2018 if (!skb)
2019 break;
2020
2021 ieee80211_free_txskb(ar->hw, skb);
2022 }
2023}
2024
2025void ath10k_offchan_tx_work(struct work_struct *work)
2026{
2027 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2028 struct ath10k_peer *peer;
2029 struct ieee80211_hdr *hdr;
2030 struct sk_buff *skb;
2031 const u8 *peer_addr;
2032 int vdev_id;
2033 int ret;
2034
2035 /* FW requirement: We must create a peer before FW will send out
2036 * an offchannel frame. Otherwise the frame will be stuck and
2037 * never transmitted. We delete the peer upon tx completion.
2038 * It is unlikely that a peer for offchannel tx will already be
2039 * present. However it may be in some rare cases so account for that.
2040 * Otherwise we might remove a legitimate peer and break stuff. */
2041
2042 for (;;) {
2043 skb = skb_dequeue(&ar->offchan_tx_queue);
2044 if (!skb)
2045 break;
2046
2047 mutex_lock(&ar->conf_mutex);
2048
Kalle Valo60c3daa2013-09-08 17:56:07 +03002049 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002050 skb);
2051
2052 hdr = (struct ieee80211_hdr *)skb->data;
2053 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002054 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055
2056 spin_lock_bh(&ar->data_lock);
2057 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2058 spin_unlock_bh(&ar->data_lock);
2059
2060 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002061 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002062 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2063 peer_addr, vdev_id);
2064
2065 if (!peer) {
2066 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2067 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002068 ath10k_warn("failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002069 peer_addr, vdev_id, ret);
2070 }
2071
2072 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002073 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074 ar->offchan_tx_skb = skb;
2075 spin_unlock_bh(&ar->data_lock);
2076
2077 ath10k_tx_htt(ar, skb);
2078
2079 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2080 3 * HZ);
2081 if (ret <= 0)
2082 ath10k_warn("timed out waiting for offchannel skb %p\n",
2083 skb);
2084
2085 if (!peer) {
2086 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2087 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002088 ath10k_warn("failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089 peer_addr, vdev_id, ret);
2090 }
2091
2092 mutex_unlock(&ar->conf_mutex);
2093 }
2094}
2095
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002096void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2097{
2098 struct sk_buff *skb;
2099
2100 for (;;) {
2101 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2102 if (!skb)
2103 break;
2104
2105 ieee80211_free_txskb(ar->hw, skb);
2106 }
2107}
2108
2109void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2110{
2111 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2112 struct sk_buff *skb;
2113 int ret;
2114
2115 for (;;) {
2116 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2117 if (!skb)
2118 break;
2119
2120 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002121 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002122 ath10k_warn("failed to transmit management frame via WMI: %d\n",
2123 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002124 ieee80211_free_txskb(ar->hw, skb);
2125 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002126 }
2127}
2128
Kalle Valo5e3dd152013-06-12 20:52:10 +03002129/************/
2130/* Scanning */
2131/************/
2132
2133/*
2134 * This gets called if we dont get a heart-beat during scan.
2135 * This may indicate the FW has hung and we need to abort the
2136 * scan manually to prevent cancel_hw_scan() from deadlocking
2137 */
2138void ath10k_reset_scan(unsigned long ptr)
2139{
2140 struct ath10k *ar = (struct ath10k *)ptr;
2141
2142 spin_lock_bh(&ar->data_lock);
2143 if (!ar->scan.in_progress) {
2144 spin_unlock_bh(&ar->data_lock);
2145 return;
2146 }
2147
Kalle Valobe6546f2014-03-25 14:18:51 +02002148 ath10k_warn("scan timed out, firmware problem?\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149
2150 if (ar->scan.is_roc)
2151 ieee80211_remain_on_channel_expired(ar->hw);
2152 else
2153 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2154
2155 ar->scan.in_progress = false;
2156 complete_all(&ar->scan.completed);
2157 spin_unlock_bh(&ar->data_lock);
2158}
2159
2160static int ath10k_abort_scan(struct ath10k *ar)
2161{
2162 struct wmi_stop_scan_arg arg = {
2163 .req_id = 1, /* FIXME */
2164 .req_type = WMI_SCAN_STOP_ONE,
2165 .u.scan_id = ATH10K_SCAN_ID,
2166 };
2167 int ret;
2168
2169 lockdep_assert_held(&ar->conf_mutex);
2170
2171 del_timer_sync(&ar->scan.timeout);
2172
2173 spin_lock_bh(&ar->data_lock);
2174 if (!ar->scan.in_progress) {
2175 spin_unlock_bh(&ar->data_lock);
2176 return 0;
2177 }
2178
2179 ar->scan.aborting = true;
2180 spin_unlock_bh(&ar->data_lock);
2181
2182 ret = ath10k_wmi_stop_scan(ar, &arg);
2183 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002184 ath10k_warn("failed to stop wmi scan: %d\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03002185 spin_lock_bh(&ar->data_lock);
2186 ar->scan.in_progress = false;
2187 ath10k_offchan_tx_purge(ar);
2188 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189 return -EIO;
2190 }
2191
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2193 if (ret == 0)
2194 ath10k_warn("timed out while waiting for scan to stop\n");
2195
2196 /* scan completion may be done right after we timeout here, so let's
2197 * check the in_progress and tell mac80211 scan is completed. if we
2198 * don't do that and FW fails to send us scan completion indication
2199 * then userspace won't be able to scan anymore */
2200 ret = 0;
2201
2202 spin_lock_bh(&ar->data_lock);
2203 if (ar->scan.in_progress) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002204 ath10k_warn("failed to stop scan, it's still in progress\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205 ar->scan.in_progress = false;
2206 ath10k_offchan_tx_purge(ar);
2207 ret = -ETIMEDOUT;
2208 }
2209 spin_unlock_bh(&ar->data_lock);
2210
2211 return ret;
2212}
2213
2214static int ath10k_start_scan(struct ath10k *ar,
2215 const struct wmi_start_scan_arg *arg)
2216{
2217 int ret;
2218
2219 lockdep_assert_held(&ar->conf_mutex);
2220
2221 ret = ath10k_wmi_start_scan(ar, arg);
2222 if (ret)
2223 return ret;
2224
Kalle Valo5e3dd152013-06-12 20:52:10 +03002225 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2226 if (ret == 0) {
2227 ath10k_abort_scan(ar);
2228 return ret;
2229 }
2230
2231 /* the scan can complete earlier, before we even
2232 * start the timer. in that case the timer handler
2233 * checks ar->scan.in_progress and bails out if its
2234 * false. Add a 200ms margin to account event/command
2235 * processing. */
2236 mod_timer(&ar->scan.timeout, jiffies +
2237 msecs_to_jiffies(arg->max_scan_time+200));
2238 return 0;
2239}
2240
2241/**********************/
2242/* mac80211 callbacks */
2243/**********************/
2244
2245static void ath10k_tx(struct ieee80211_hw *hw,
2246 struct ieee80211_tx_control *control,
2247 struct sk_buff *skb)
2248{
2249 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2250 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2251 struct ath10k *ar = hw->priv;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002252 u8 tid, vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002253
2254 /* We should disable CCK RATE due to P2P */
2255 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2256 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2257
2258 /* we must calculate tid before we apply qos workaround
2259 * as we'd lose the qos control field */
Michal Kazior42c3aa62013-10-02 11:03:38 +02002260 tid = ath10k_tx_h_get_tid(hdr);
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002261 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002262
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002263 /* it makes no sense to process injected frames like that */
2264 if (info->control.vif &&
2265 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2266 ath10k_tx_h_qos_workaround(hw, control, skb);
2267 ath10k_tx_h_update_wep_key(skb);
2268 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2269 ath10k_tx_h_seq_no(skb);
2270 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002271
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002272 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
Michal Kazior27bb1782013-09-18 14:43:19 +02002273 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002274 ATH10K_SKB_CB(skb)->htt.tid = tid;
2275
2276 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2277 spin_lock_bh(&ar->data_lock);
2278 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002279 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280 spin_unlock_bh(&ar->data_lock);
2281
2282 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2283
2284 skb_queue_tail(&ar->offchan_tx_queue, skb);
2285 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2286 return;
2287 }
2288
2289 ath10k_tx_htt(ar, skb);
2290}
2291
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002292/* Must not be called with conf_mutex held as workers can use that also. */
2293static void ath10k_drain_tx(struct ath10k *ar)
2294{
2295 /* make sure rcu-protected mac80211 tx path itself is drained */
2296 synchronize_net();
2297
2298 ath10k_offchan_tx_purge(ar);
2299 ath10k_mgmt_over_wmi_tx_purge(ar);
2300
2301 cancel_work_sync(&ar->offchan_tx_work);
2302 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2303}
2304
Michal Kazioraffd3212013-07-16 09:54:35 +02002305void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002306{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002307 struct ath10k_vif *arvif;
2308
Michal Kazior818bdd12013-07-16 09:38:57 +02002309 lockdep_assert_held(&ar->conf_mutex);
2310
Michal Kazior1bbc0972014-04-08 09:45:47 +03002311 if (ath10k_monitor_is_enabled(ar)) {
2312 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2313 ar->promisc = false;
2314 ar->monitor = false;
2315 ath10k_monitor_stop(ar);
2316 }
2317
Michal Kazior818bdd12013-07-16 09:38:57 +02002318 del_timer_sync(&ar->scan.timeout);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002319 ath10k_reset_scan((unsigned long)ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002320 ath10k_peer_cleanup_all(ar);
2321 ath10k_core_stop(ar);
2322 ath10k_hif_power_down(ar);
2323
2324 spin_lock_bh(&ar->data_lock);
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002325 list_for_each_entry(arvif, &ar->arvifs, list) {
2326 if (!arvif->beacon)
2327 continue;
2328
2329 dma_unmap_single(arvif->ar->dev,
2330 ATH10K_SKB_CB(arvif->beacon)->paddr,
2331 arvif->beacon->len, DMA_TO_DEVICE);
2332 dev_kfree_skb_any(arvif->beacon);
2333 arvif->beacon = NULL;
2334 }
Michal Kazior818bdd12013-07-16 09:38:57 +02002335 spin_unlock_bh(&ar->data_lock);
2336}
2337
Ben Greear46acf7b2014-05-16 17:15:38 +03002338static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2339{
2340 struct ath10k *ar = hw->priv;
2341
2342 mutex_lock(&ar->conf_mutex);
2343
2344 if (ar->cfg_tx_chainmask) {
2345 *tx_ant = ar->cfg_tx_chainmask;
2346 *rx_ant = ar->cfg_rx_chainmask;
2347 } else {
2348 *tx_ant = ar->supp_tx_chainmask;
2349 *rx_ant = ar->supp_rx_chainmask;
2350 }
2351
2352 mutex_unlock(&ar->conf_mutex);
2353
2354 return 0;
2355}
2356
2357static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2358{
2359 int ret;
2360
2361 lockdep_assert_held(&ar->conf_mutex);
2362
2363 ar->cfg_tx_chainmask = tx_ant;
2364 ar->cfg_rx_chainmask = rx_ant;
2365
2366 if ((ar->state != ATH10K_STATE_ON) &&
2367 (ar->state != ATH10K_STATE_RESTARTED))
2368 return 0;
2369
2370 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2371 tx_ant);
2372 if (ret) {
2373 ath10k_warn("failed to set tx-chainmask: %d, req 0x%x\n",
2374 ret, tx_ant);
2375 return ret;
2376 }
2377
2378 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2379 rx_ant);
2380 if (ret) {
2381 ath10k_warn("failed to set rx-chainmask: %d, req 0x%x\n",
2382 ret, rx_ant);
2383 return ret;
2384 }
2385
2386 return 0;
2387}
2388
2389static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2390{
2391 struct ath10k *ar = hw->priv;
2392 int ret;
2393
2394 mutex_lock(&ar->conf_mutex);
2395 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2396 mutex_unlock(&ar->conf_mutex);
2397 return ret;
2398}
2399
Kalle Valo5e3dd152013-06-12 20:52:10 +03002400static int ath10k_start(struct ieee80211_hw *hw)
2401{
2402 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002403 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002404
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002405 /*
2406 * This makes sense only when restarting hw. It is harmless to call
2407 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2408 * commands will be submitted while restarting.
2409 */
2410 ath10k_drain_tx(ar);
2411
Michal Kazior548db542013-07-05 16:15:15 +03002412 mutex_lock(&ar->conf_mutex);
2413
Michal Kaziorc5058f52014-05-26 12:46:03 +03002414 switch (ar->state) {
2415 case ATH10K_STATE_OFF:
2416 ar->state = ATH10K_STATE_ON;
2417 break;
2418 case ATH10K_STATE_RESTARTING:
2419 ath10k_halt(ar);
2420 ar->state = ATH10K_STATE_RESTARTED;
2421 break;
2422 case ATH10K_STATE_ON:
2423 case ATH10K_STATE_RESTARTED:
2424 case ATH10K_STATE_WEDGED:
2425 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002426 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002427 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002428 }
2429
2430 ret = ath10k_hif_power_up(ar);
2431 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002432 ath10k_err("Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002433 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002434 }
2435
2436 ret = ath10k_core_start(ar);
2437 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002438 ath10k_err("Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002439 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002440 }
2441
Bartosz Markowski226a3392013-09-26 17:47:16 +02002442 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002443 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002444 ath10k_warn("failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002445 goto err_core_stop;
2446 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002447
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002448 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002449 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002450 ath10k_warn("failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002451 goto err_core_stop;
2452 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453
Ben Greear46acf7b2014-05-16 17:15:38 +03002454 if (ar->cfg_tx_chainmask)
2455 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2456 ar->cfg_rx_chainmask);
2457
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002458 /*
2459 * By default FW set ARP frames ac to voice (6). In that case ARP
2460 * exchange is not working properly for UAPSD enabled AP. ARP requests
2461 * which arrives with access category 0 are processed by network stack
2462 * and send back with access category 0, but FW changes access category
2463 * to 6. Set ARP frames access category to best effort (0) solves
2464 * this problem.
2465 */
2466
2467 ret = ath10k_wmi_pdev_set_param(ar,
2468 ar->wmi.pdev_param->arp_ac_override, 0);
2469 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002470 ath10k_warn("failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002471 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002472 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002473 }
2474
Michal Kaziord6500972014-04-08 09:56:09 +03002475 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002476 ath10k_regd_update(ar);
2477
Michal Kaziorae254432014-05-26 12:46:02 +03002478 mutex_unlock(&ar->conf_mutex);
2479 return 0;
2480
2481err_core_stop:
2482 ath10k_core_stop(ar);
2483
2484err_power_down:
2485 ath10k_hif_power_down(ar);
2486
2487err_off:
2488 ar->state = ATH10K_STATE_OFF;
2489
2490err:
Michal Kazior548db542013-07-05 16:15:15 +03002491 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002492 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002493}
2494
2495static void ath10k_stop(struct ieee80211_hw *hw)
2496{
2497 struct ath10k *ar = hw->priv;
2498
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002499 ath10k_drain_tx(ar);
2500
Michal Kazior548db542013-07-05 16:15:15 +03002501 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002502 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002503 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002504 ar->state = ATH10K_STATE_OFF;
2505 }
Michal Kazior548db542013-07-05 16:15:15 +03002506 mutex_unlock(&ar->conf_mutex);
2507
Michal Kazioraffd3212013-07-16 09:54:35 +02002508 cancel_work_sync(&ar->restart_work);
2509}
2510
Michal Kaziorad088bf2013-10-16 15:44:46 +03002511static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002512{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002513 struct ath10k_vif *arvif;
2514 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002515
2516 lockdep_assert_held(&ar->conf_mutex);
2517
Michal Kaziorad088bf2013-10-16 15:44:46 +03002518 list_for_each_entry(arvif, &ar->arvifs, list) {
2519 ret = ath10k_mac_vif_setup_ps(arvif);
2520 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002521 ath10k_warn("failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002522 break;
2523 }
2524 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002525
Michal Kaziorad088bf2013-10-16 15:44:46 +03002526 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527}
2528
Michal Kaziorc930f742014-01-23 11:38:25 +01002529static const char *chandef_get_width(enum nl80211_chan_width width)
2530{
2531 switch (width) {
2532 case NL80211_CHAN_WIDTH_20_NOHT:
2533 return "20 (noht)";
2534 case NL80211_CHAN_WIDTH_20:
2535 return "20";
2536 case NL80211_CHAN_WIDTH_40:
2537 return "40";
2538 case NL80211_CHAN_WIDTH_80:
2539 return "80";
2540 case NL80211_CHAN_WIDTH_80P80:
2541 return "80+80";
2542 case NL80211_CHAN_WIDTH_160:
2543 return "160";
2544 case NL80211_CHAN_WIDTH_5:
2545 return "5";
2546 case NL80211_CHAN_WIDTH_10:
2547 return "10";
2548 }
2549 return "?";
2550}
2551
2552static void ath10k_config_chan(struct ath10k *ar)
2553{
2554 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002555 int ret;
2556
2557 lockdep_assert_held(&ar->conf_mutex);
2558
2559 ath10k_dbg(ATH10K_DBG_MAC,
2560 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2561 ar->chandef.chan->center_freq,
2562 ar->chandef.center_freq1,
2563 ar->chandef.center_freq2,
2564 chandef_get_width(ar->chandef.width));
2565
2566 /* First stop monitor interface. Some FW versions crash if there's a
2567 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002568 if (ar->monitor_started)
2569 ath10k_monitor_vdev_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002570
2571 list_for_each_entry(arvif, &ar->arvifs, list) {
2572 if (!arvif->is_started)
2573 continue;
2574
2575 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2576 continue;
2577
2578 ret = ath10k_vdev_stop(arvif);
2579 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002580 ath10k_warn("failed to stop vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002581 arvif->vdev_id, ret);
2582 continue;
2583 }
2584 }
2585
2586 /* all vdevs are now stopped - now attempt to restart them */
2587
2588 list_for_each_entry(arvif, &ar->arvifs, list) {
2589 if (!arvif->is_started)
2590 continue;
2591
2592 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2593 continue;
2594
2595 ret = ath10k_vdev_start(arvif);
2596 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002597 ath10k_warn("failed to start vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002598 arvif->vdev_id, ret);
2599 continue;
2600 }
2601
2602 if (!arvif->is_up)
2603 continue;
2604
2605 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2606 arvif->bssid);
2607 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002608 ath10k_warn("failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002609 arvif->vdev_id, ret);
2610 continue;
2611 }
2612 }
2613
Michal Kazior1bbc0972014-04-08 09:45:47 +03002614 if (ath10k_monitor_is_enabled(ar))
2615 ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002616}
2617
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2619{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002620 struct ath10k *ar = hw->priv;
2621 struct ieee80211_conf *conf = &hw->conf;
2622 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002623 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624
2625 mutex_lock(&ar->conf_mutex);
2626
2627 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002628 ath10k_dbg(ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002629 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002630 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002631 conf->chandef.chan->flags,
2632 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002633
Kalle Valo5e3dd152013-06-12 20:52:10 +03002634 spin_lock_bh(&ar->data_lock);
2635 ar->rx_channel = conf->chandef.chan;
2636 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002637
Michal Kaziord6500972014-04-08 09:56:09 +03002638 ar->radar_enabled = conf->radar_enabled;
2639 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002640
2641 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2642 ar->chandef = conf->chandef;
2643 ath10k_config_chan(ar);
2644 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002645 }
2646
Michal Kazior5474efe2013-10-23 04:02:15 -07002647 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2648 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2649 hw->conf.power_level);
2650
2651 param = ar->wmi.pdev_param->txpower_limit2g;
2652 ret = ath10k_wmi_pdev_set_param(ar, param,
2653 hw->conf.power_level * 2);
2654 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002655 ath10k_warn("failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002656 hw->conf.power_level, ret);
2657
2658 param = ar->wmi.pdev_param->txpower_limit5g;
2659 ret = ath10k_wmi_pdev_set_param(ar, param,
2660 hw->conf.power_level * 2);
2661 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002662 ath10k_warn("failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002663 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002664 }
2665
Michal Kazioraffd3212013-07-16 09:54:35 +02002666 if (changed & IEEE80211_CONF_CHANGE_PS)
2667 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002668
2669 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior1bbc0972014-04-08 09:45:47 +03002670 if (conf->flags & IEEE80211_CONF_MONITOR && !ar->monitor) {
2671 ar->monitor = true;
2672 ret = ath10k_monitor_start(ar);
2673 if (ret) {
2674 ath10k_warn("failed to start monitor (config): %d\n",
2675 ret);
2676 ar->monitor = false;
2677 }
2678 } else if (!(conf->flags & IEEE80211_CONF_MONITOR) &&
2679 ar->monitor) {
2680 ar->monitor = false;
2681 ath10k_monitor_stop(ar);
2682 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683 }
2684
2685 mutex_unlock(&ar->conf_mutex);
2686 return ret;
2687}
2688
2689/*
2690 * TODO:
2691 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2692 * because we will send mgmt frames without CCK. This requirement
2693 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2694 * in the TX packet.
2695 */
2696static int ath10k_add_interface(struct ieee80211_hw *hw,
2697 struct ieee80211_vif *vif)
2698{
2699 struct ath10k *ar = hw->priv;
2700 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2701 enum wmi_sta_powersave_param param;
2702 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002703 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002705 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706
2707 mutex_lock(&ar->conf_mutex);
2708
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002709 memset(arvif, 0, sizeof(*arvif));
2710
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711 arvif->ar = ar;
2712 arvif->vif = vif;
2713
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002714 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002715 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002716
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717 bit = ffs(ar->free_vdev_map);
2718 if (bit == 0) {
2719 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002720 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002721 }
2722
2723 arvif->vdev_id = bit - 1;
2724 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002725
2726 if (ar->p2p)
2727 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2728
2729 switch (vif->type) {
2730 case NL80211_IFTYPE_UNSPECIFIED:
2731 case NL80211_IFTYPE_STATION:
2732 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2733 if (vif->p2p)
2734 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2735 break;
2736 case NL80211_IFTYPE_ADHOC:
2737 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2738 break;
2739 case NL80211_IFTYPE_AP:
2740 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2741
2742 if (vif->p2p)
2743 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2744 break;
2745 case NL80211_IFTYPE_MONITOR:
2746 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2747 break;
2748 default:
2749 WARN_ON(1);
2750 break;
2751 }
2752
Kalle Valo60c3daa2013-09-08 17:56:07 +03002753 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2755
2756 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2757 arvif->vdev_subtype, vif->addr);
2758 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002759 ath10k_warn("failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002760 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002761 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 }
2763
Michal Kazior9dad14a2013-10-16 15:44:45 +03002764 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002765 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002766
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002767 vdev_param = ar->wmi.vdev_param->def_keyid;
2768 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002769 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002770 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002771 ath10k_warn("failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002772 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002773 goto err_vdev_delete;
2774 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002775
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002776 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2777 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002779 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002780 if (ret && ret != -EOPNOTSUPP) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002781 ath10k_warn("failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002782 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002783 goto err_vdev_delete;
2784 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002785
2786 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2787 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2788 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002789 ath10k_warn("failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002790 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002791 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002793
Kalle Valo5a13e762014-01-20 11:01:46 +02002794 ret = ath10k_mac_set_kickout(arvif);
2795 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002796 ath10k_warn("failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002797 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002798 goto err_peer_delete;
2799 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800 }
2801
2802 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2803 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2804 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2805 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2806 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002807 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002808 ath10k_warn("failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002809 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002810 goto err_peer_delete;
2811 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002812
2813 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2814 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2815 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2816 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002817 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002818 ath10k_warn("failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002819 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002820 goto err_peer_delete;
2821 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002822
2823 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2824 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2825 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2826 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002827 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002828 ath10k_warn("failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002829 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002830 goto err_peer_delete;
2831 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002832 }
2833
Michal Kazior424121c2013-07-22 14:13:31 +02002834 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002835 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002836 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002837 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002838 goto err_peer_delete;
2839 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002840
Michal Kazior424121c2013-07-22 14:13:31 +02002841 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002842 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02002843 ath10k_warn("failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002844 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002845 goto err_peer_delete;
2846 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002847
Kalle Valo5e3dd152013-06-12 20:52:10 +03002848 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002849 return 0;
2850
2851err_peer_delete:
2852 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2853 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2854
2855err_vdev_delete:
2856 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2857 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002858 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002859
2860err:
2861 mutex_unlock(&ar->conf_mutex);
2862
Kalle Valo5e3dd152013-06-12 20:52:10 +03002863 return ret;
2864}
2865
2866static void ath10k_remove_interface(struct ieee80211_hw *hw,
2867 struct ieee80211_vif *vif)
2868{
2869 struct ath10k *ar = hw->priv;
2870 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2871 int ret;
2872
2873 mutex_lock(&ar->conf_mutex);
2874
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002875 cancel_work_sync(&arvif->wep_key_work);
2876
Michal Kaziored543882013-09-13 14:16:56 +02002877 spin_lock_bh(&ar->data_lock);
2878 if (arvif->beacon) {
Michal Kaziorec6bc552014-04-23 19:30:05 +03002879 dma_unmap_single(arvif->ar->dev,
2880 ATH10K_SKB_CB(arvif->beacon)->paddr,
2881 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02002882 dev_kfree_skb_any(arvif->beacon);
2883 arvif->beacon = NULL;
2884 }
2885 spin_unlock_bh(&ar->data_lock);
2886
Kalle Valo5e3dd152013-06-12 20:52:10 +03002887 ar->free_vdev_map |= 1 << (arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002888 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889
2890 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2891 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2892 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002893 ath10k_warn("failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002894 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002895
2896 kfree(arvif->u.ap.noa_data);
2897 }
2898
Ben Greear69244e52014-02-27 18:50:00 +02002899 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002900 arvif->vdev_id);
2901
Kalle Valo5e3dd152013-06-12 20:52:10 +03002902 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2903 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002904 ath10k_warn("failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002905 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907 ath10k_peer_cleanup(ar, arvif->vdev_id);
2908
2909 mutex_unlock(&ar->conf_mutex);
2910}
2911
2912/*
2913 * FIXME: Has to be verified.
2914 */
2915#define SUPPORTED_FILTERS \
2916 (FIF_PROMISC_IN_BSS | \
2917 FIF_ALLMULTI | \
2918 FIF_CONTROL | \
2919 FIF_PSPOLL | \
2920 FIF_OTHER_BSS | \
2921 FIF_BCN_PRBRESP_PROMISC | \
2922 FIF_PROBE_REQ | \
2923 FIF_FCSFAIL)
2924
2925static void ath10k_configure_filter(struct ieee80211_hw *hw,
2926 unsigned int changed_flags,
2927 unsigned int *total_flags,
2928 u64 multicast)
2929{
2930 struct ath10k *ar = hw->priv;
2931 int ret;
2932
2933 mutex_lock(&ar->conf_mutex);
2934
2935 changed_flags &= SUPPORTED_FILTERS;
2936 *total_flags &= SUPPORTED_FILTERS;
2937 ar->filter_flags = *total_flags;
2938
Michal Kazior1bbc0972014-04-08 09:45:47 +03002939 if (ar->filter_flags & FIF_PROMISC_IN_BSS && !ar->promisc) {
2940 ar->promisc = true;
2941 ret = ath10k_monitor_start(ar);
2942 if (ret) {
2943 ath10k_warn("failed to start monitor (promisc): %d\n",
2944 ret);
2945 ar->promisc = false;
2946 }
2947 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && ar->promisc) {
2948 ar->promisc = false;
2949 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002950 }
2951
2952 mutex_unlock(&ar->conf_mutex);
2953}
2954
2955static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2956 struct ieee80211_vif *vif,
2957 struct ieee80211_bss_conf *info,
2958 u32 changed)
2959{
2960 struct ath10k *ar = hw->priv;
2961 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2962 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002963 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002964
2965 mutex_lock(&ar->conf_mutex);
2966
2967 if (changed & BSS_CHANGED_IBSS)
2968 ath10k_control_ibss(arvif, info, vif->addr);
2969
2970 if (changed & BSS_CHANGED_BEACON_INT) {
2971 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002972 vdev_param = ar->wmi.vdev_param->beacon_interval;
2973 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002974 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002975 ath10k_dbg(ATH10K_DBG_MAC,
2976 "mac vdev %d beacon_interval %d\n",
2977 arvif->vdev_id, arvif->beacon_interval);
2978
Kalle Valo5e3dd152013-06-12 20:52:10 +03002979 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002980 ath10k_warn("failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002981 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002982 }
2983
2984 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002985 ath10k_dbg(ATH10K_DBG_MAC,
2986 "vdev %d set beacon tx mode to staggered\n",
2987 arvif->vdev_id);
2988
Bartosz Markowski226a3392013-09-26 17:47:16 +02002989 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2990 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002991 WMI_BEACON_STAGGERED_MODE);
2992 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02002993 ath10k_warn("failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002994 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002995 }
2996
John W. Linvilleb70727e2013-06-13 13:34:29 -04002997 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002998 arvif->dtim_period = info->dtim_period;
2999
Kalle Valo60c3daa2013-09-08 17:56:07 +03003000 ath10k_dbg(ATH10K_DBG_MAC,
3001 "mac vdev %d dtim_period %d\n",
3002 arvif->vdev_id, arvif->dtim_period);
3003
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003004 vdev_param = ar->wmi.vdev_param->dtim_period;
3005 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003006 arvif->dtim_period);
3007 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003008 ath10k_warn("failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003009 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003010 }
3011
3012 if (changed & BSS_CHANGED_SSID &&
3013 vif->type == NL80211_IFTYPE_AP) {
3014 arvif->u.ap.ssid_len = info->ssid_len;
3015 if (info->ssid_len)
3016 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3017 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3018 }
3019
3020 if (changed & BSS_CHANGED_BSSID) {
3021 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03003022 ath10k_dbg(ATH10K_DBG_MAC,
3023 "mac vdev %d create peer %pM\n",
3024 arvif->vdev_id, info->bssid);
3025
Kalle Valo5e3dd152013-06-12 20:52:10 +03003026 ret = ath10k_peer_create(ar, arvif->vdev_id,
3027 info->bssid);
3028 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003029 ath10k_warn("failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003030 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003031
3032 if (vif->type == NL80211_IFTYPE_STATION) {
3033 /*
3034 * this is never erased as we it for crypto key
3035 * clearing; this is FW requirement
3036 */
Michal Kaziorc930f742014-01-23 11:38:25 +01003037 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003038
Kalle Valo60c3daa2013-09-08 17:56:07 +03003039 ath10k_dbg(ATH10K_DBG_MAC,
3040 "mac vdev %d start %pM\n",
3041 arvif->vdev_id, info->bssid);
3042
Kalle Valo5e3dd152013-06-12 20:52:10 +03003043 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003044 if (ret) {
Ben Greear69244e52014-02-27 18:50:00 +02003045 ath10k_warn("failed to start vdev %i: %d\n",
3046 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02003047 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01003048 }
3049
3050 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003051 }
3052
3053 /*
3054 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3055 * so driver need to store it. It is needed when leaving
3056 * IBSS in order to remove BSSID peer.
3057 */
3058 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01003059 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003060 ETH_ALEN);
3061 }
3062 }
3063
3064 if (changed & BSS_CHANGED_BEACON_ENABLED)
3065 ath10k_control_beaconing(arvif, info);
3066
3067 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003068 arvif->use_cts_prot = info->use_cts_prot;
Kalle Valo60c3daa2013-09-08 17:56:07 +03003069 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003070 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003071
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003072 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003073 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003074 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003075 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076 }
3077
3078 if (changed & BSS_CHANGED_ERP_SLOT) {
3079 u32 slottime;
3080 if (info->use_short_slot)
3081 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3082
3083 else
3084 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3085
Kalle Valo60c3daa2013-09-08 17:56:07 +03003086 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3087 arvif->vdev_id, slottime);
3088
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003089 vdev_param = ar->wmi.vdev_param->slot_time;
3090 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003091 slottime);
3092 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003093 ath10k_warn("failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003094 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003095 }
3096
3097 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3098 u32 preamble;
3099 if (info->use_short_preamble)
3100 preamble = WMI_VDEV_PREAMBLE_SHORT;
3101 else
3102 preamble = WMI_VDEV_PREAMBLE_LONG;
3103
Kalle Valo60c3daa2013-09-08 17:56:07 +03003104 ath10k_dbg(ATH10K_DBG_MAC,
3105 "mac vdev %d preamble %dn",
3106 arvif->vdev_id, preamble);
3107
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003108 vdev_param = ar->wmi.vdev_param->preamble;
3109 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003110 preamble);
3111 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003112 ath10k_warn("failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003113 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003114 }
3115
3116 if (changed & BSS_CHANGED_ASSOC) {
3117 if (info->assoc)
3118 ath10k_bss_assoc(hw, vif, info);
3119 }
3120
Kalle Valo75459e32014-02-13 18:13:12 +02003121exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003122 mutex_unlock(&ar->conf_mutex);
3123}
3124
3125static int ath10k_hw_scan(struct ieee80211_hw *hw,
3126 struct ieee80211_vif *vif,
3127 struct cfg80211_scan_request *req)
3128{
3129 struct ath10k *ar = hw->priv;
3130 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3131 struct wmi_start_scan_arg arg;
3132 int ret = 0;
3133 int i;
3134
3135 mutex_lock(&ar->conf_mutex);
3136
3137 spin_lock_bh(&ar->data_lock);
3138 if (ar->scan.in_progress) {
3139 spin_unlock_bh(&ar->data_lock);
3140 ret = -EBUSY;
3141 goto exit;
3142 }
3143
Wolfram Sang16735d02013-11-14 14:32:02 -08003144 reinit_completion(&ar->scan.started);
3145 reinit_completion(&ar->scan.completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146 ar->scan.in_progress = true;
3147 ar->scan.aborting = false;
3148 ar->scan.is_roc = false;
3149 ar->scan.vdev_id = arvif->vdev_id;
3150 spin_unlock_bh(&ar->data_lock);
3151
3152 memset(&arg, 0, sizeof(arg));
3153 ath10k_wmi_start_scan_init(ar, &arg);
3154 arg.vdev_id = arvif->vdev_id;
3155 arg.scan_id = ATH10K_SCAN_ID;
3156
3157 if (!req->no_cck)
3158 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3159
3160 if (req->ie_len) {
3161 arg.ie_len = req->ie_len;
3162 memcpy(arg.ie, req->ie, arg.ie_len);
3163 }
3164
3165 if (req->n_ssids) {
3166 arg.n_ssids = req->n_ssids;
3167 for (i = 0; i < arg.n_ssids; i++) {
3168 arg.ssids[i].len = req->ssids[i].ssid_len;
3169 arg.ssids[i].ssid = req->ssids[i].ssid;
3170 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003171 } else {
3172 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003173 }
3174
3175 if (req->n_channels) {
3176 arg.n_channels = req->n_channels;
3177 for (i = 0; i < arg.n_channels; i++)
3178 arg.channels[i] = req->channels[i]->center_freq;
3179 }
3180
3181 ret = ath10k_start_scan(ar, &arg);
3182 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003183 ath10k_warn("failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184 spin_lock_bh(&ar->data_lock);
3185 ar->scan.in_progress = false;
3186 spin_unlock_bh(&ar->data_lock);
3187 }
3188
3189exit:
3190 mutex_unlock(&ar->conf_mutex);
3191 return ret;
3192}
3193
3194static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3195 struct ieee80211_vif *vif)
3196{
3197 struct ath10k *ar = hw->priv;
3198 int ret;
3199
3200 mutex_lock(&ar->conf_mutex);
3201 ret = ath10k_abort_scan(ar);
3202 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003203 ath10k_warn("failed to abort scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003204 ieee80211_scan_completed(hw, 1 /* aborted */);
3205 }
3206 mutex_unlock(&ar->conf_mutex);
3207}
3208
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003209static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3210 struct ath10k_vif *arvif,
3211 enum set_key_cmd cmd,
3212 struct ieee80211_key_conf *key)
3213{
3214 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3215 int ret;
3216
3217 /* 10.1 firmware branch requires default key index to be set to group
3218 * key index after installing it. Otherwise FW/HW Txes corrupted
3219 * frames with multi-vif APs. This is not required for main firmware
3220 * branch (e.g. 636).
3221 *
3222 * FIXME: This has been tested only in AP. It remains unknown if this
3223 * is required for multi-vif STA interfaces on 10.1 */
3224
3225 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3226 return;
3227
3228 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3229 return;
3230
3231 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3232 return;
3233
3234 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3235 return;
3236
3237 if (cmd != SET_KEY)
3238 return;
3239
3240 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3241 key->keyidx);
3242 if (ret)
Ben Greear69244e52014-02-27 18:50:00 +02003243 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3244 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003245}
3246
Kalle Valo5e3dd152013-06-12 20:52:10 +03003247static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3248 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3249 struct ieee80211_key_conf *key)
3250{
3251 struct ath10k *ar = hw->priv;
3252 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3253 struct ath10k_peer *peer;
3254 const u8 *peer_addr;
3255 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3256 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3257 int ret = 0;
3258
3259 if (key->keyidx > WMI_MAX_KEY_INDEX)
3260 return -ENOSPC;
3261
3262 mutex_lock(&ar->conf_mutex);
3263
3264 if (sta)
3265 peer_addr = sta->addr;
3266 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3267 peer_addr = vif->bss_conf.bssid;
3268 else
3269 peer_addr = vif->addr;
3270
3271 key->hw_key_idx = key->keyidx;
3272
3273 /* the peer should not disappear in mid-way (unless FW goes awry) since
3274 * we already hold conf_mutex. we just make sure its there now. */
3275 spin_lock_bh(&ar->data_lock);
3276 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3277 spin_unlock_bh(&ar->data_lock);
3278
3279 if (!peer) {
3280 if (cmd == SET_KEY) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003281 ath10k_warn("failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003282 peer_addr);
3283 ret = -EOPNOTSUPP;
3284 goto exit;
3285 } else {
3286 /* if the peer doesn't exist there is no key to disable
3287 * anymore */
3288 goto exit;
3289 }
3290 }
3291
3292 if (is_wep) {
3293 if (cmd == SET_KEY)
3294 arvif->wep_keys[key->keyidx] = key;
3295 else
3296 arvif->wep_keys[key->keyidx] = NULL;
3297
3298 if (cmd == DISABLE_KEY)
3299 ath10k_clear_vdev_key(arvif, key);
3300 }
3301
3302 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3303 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003304 ath10k_warn("failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003305 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003306 goto exit;
3307 }
3308
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003309 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3310
Kalle Valo5e3dd152013-06-12 20:52:10 +03003311 spin_lock_bh(&ar->data_lock);
3312 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3313 if (peer && cmd == SET_KEY)
3314 peer->keys[key->keyidx] = key;
3315 else if (peer && cmd == DISABLE_KEY)
3316 peer->keys[key->keyidx] = NULL;
3317 else if (peer == NULL)
3318 /* impossible unless FW goes crazy */
Kalle Valobe6546f2014-03-25 14:18:51 +02003319 ath10k_warn("Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003320 spin_unlock_bh(&ar->data_lock);
3321
3322exit:
3323 mutex_unlock(&ar->conf_mutex);
3324 return ret;
3325}
3326
Michal Kazior9797feb2014-02-14 14:49:48 +01003327static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3328{
3329 struct ath10k *ar;
3330 struct ath10k_vif *arvif;
3331 struct ath10k_sta *arsta;
3332 struct ieee80211_sta *sta;
3333 u32 changed, bw, nss, smps;
3334 int err;
3335
3336 arsta = container_of(wk, struct ath10k_sta, update_wk);
3337 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3338 arvif = arsta->arvif;
3339 ar = arvif->ar;
3340
3341 spin_lock_bh(&ar->data_lock);
3342
3343 changed = arsta->changed;
3344 arsta->changed = 0;
3345
3346 bw = arsta->bw;
3347 nss = arsta->nss;
3348 smps = arsta->smps;
3349
3350 spin_unlock_bh(&ar->data_lock);
3351
3352 mutex_lock(&ar->conf_mutex);
3353
3354 if (changed & IEEE80211_RC_BW_CHANGED) {
3355 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3356 sta->addr, bw);
3357
3358 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3359 WMI_PEER_CHAN_WIDTH, bw);
3360 if (err)
3361 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3362 sta->addr, bw, err);
3363 }
3364
3365 if (changed & IEEE80211_RC_NSS_CHANGED) {
3366 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3367 sta->addr, nss);
3368
3369 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3370 WMI_PEER_NSS, nss);
3371 if (err)
3372 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3373 sta->addr, nss, err);
3374 }
3375
3376 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3377 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3378 sta->addr, smps);
3379
3380 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3381 WMI_PEER_SMPS_STATE, smps);
3382 if (err)
3383 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3384 sta->addr, smps, err);
3385 }
3386
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003387 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3388 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3389 sta->addr);
3390
3391 err = ath10k_station_assoc(ar, arvif, sta, true);
3392 if (err)
Kalle Valobe6546f2014-03-25 14:18:51 +02003393 ath10k_warn("failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003394 sta->addr);
3395 }
3396
Michal Kazior9797feb2014-02-14 14:49:48 +01003397 mutex_unlock(&ar->conf_mutex);
3398}
3399
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400static int ath10k_sta_state(struct ieee80211_hw *hw,
3401 struct ieee80211_vif *vif,
3402 struct ieee80211_sta *sta,
3403 enum ieee80211_sta_state old_state,
3404 enum ieee80211_sta_state new_state)
3405{
3406 struct ath10k *ar = hw->priv;
3407 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003408 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003409 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003410 int ret = 0;
3411
Michal Kazior76f90022014-02-25 09:29:57 +02003412 if (old_state == IEEE80211_STA_NOTEXIST &&
3413 new_state == IEEE80211_STA_NONE) {
3414 memset(arsta, 0, sizeof(*arsta));
3415 arsta->arvif = arvif;
3416 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3417 }
3418
Michal Kazior9797feb2014-02-14 14:49:48 +01003419 /* cancel must be done outside the mutex to avoid deadlock */
3420 if ((old_state == IEEE80211_STA_NONE &&
3421 new_state == IEEE80211_STA_NOTEXIST))
3422 cancel_work_sync(&arsta->update_wk);
3423
Kalle Valo5e3dd152013-06-12 20:52:10 +03003424 mutex_lock(&ar->conf_mutex);
3425
3426 if (old_state == IEEE80211_STA_NOTEXIST &&
3427 new_state == IEEE80211_STA_NONE &&
3428 vif->type != NL80211_IFTYPE_STATION) {
3429 /*
3430 * New station addition.
3431 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003432 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3433 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3434 else
3435 max_num_peers = TARGET_NUM_PEERS;
3436
3437 if (ar->num_peers >= max_num_peers) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003438 ath10k_warn("number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003439 ar->num_peers, max_num_peers);
3440 ret = -ENOBUFS;
3441 goto exit;
3442 }
3443
Kalle Valo60c3daa2013-09-08 17:56:07 +03003444 ath10k_dbg(ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003445 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3446 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003447
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3449 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003450 ath10k_warn("failed to add peer %pM for vdev %d when adding a new sta: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003451 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452 } else if ((old_state == IEEE80211_STA_NONE &&
3453 new_state == IEEE80211_STA_NOTEXIST)) {
3454 /*
3455 * Existing station deletion.
3456 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003457 ath10k_dbg(ATH10K_DBG_MAC,
3458 "mac vdev %d peer delete %pM (sta gone)\n",
3459 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003460 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3461 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003462 ath10k_warn("failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003463 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003464
3465 if (vif->type == NL80211_IFTYPE_STATION)
3466 ath10k_bss_disassoc(hw, vif);
3467 } else if (old_state == IEEE80211_STA_AUTH &&
3468 new_state == IEEE80211_STA_ASSOC &&
3469 (vif->type == NL80211_IFTYPE_AP ||
3470 vif->type == NL80211_IFTYPE_ADHOC)) {
3471 /*
3472 * New association.
3473 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003474 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3475 sta->addr);
3476
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003477 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003479 ath10k_warn("failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003480 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481 } else if (old_state == IEEE80211_STA_ASSOC &&
3482 new_state == IEEE80211_STA_AUTH &&
3483 (vif->type == NL80211_IFTYPE_AP ||
3484 vif->type == NL80211_IFTYPE_ADHOC)) {
3485 /*
3486 * Disassociation.
3487 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03003488 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3489 sta->addr);
3490
Kalle Valo5e3dd152013-06-12 20:52:10 +03003491 ret = ath10k_station_disassoc(ar, arvif, sta);
3492 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003493 ath10k_warn("failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003494 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003495 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003496exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003497 mutex_unlock(&ar->conf_mutex);
3498 return ret;
3499}
3500
3501static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3502 u16 ac, bool enable)
3503{
3504 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3505 u32 value = 0;
3506 int ret = 0;
3507
Michal Kazior548db542013-07-05 16:15:15 +03003508 lockdep_assert_held(&ar->conf_mutex);
3509
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3511 return 0;
3512
3513 switch (ac) {
3514 case IEEE80211_AC_VO:
3515 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3516 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3517 break;
3518 case IEEE80211_AC_VI:
3519 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3520 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3521 break;
3522 case IEEE80211_AC_BE:
3523 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3524 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3525 break;
3526 case IEEE80211_AC_BK:
3527 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3528 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3529 break;
3530 }
3531
3532 if (enable)
3533 arvif->u.sta.uapsd |= value;
3534 else
3535 arvif->u.sta.uapsd &= ~value;
3536
3537 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3538 WMI_STA_PS_PARAM_UAPSD,
3539 arvif->u.sta.uapsd);
3540 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003541 ath10k_warn("failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003542 goto exit;
3543 }
3544
3545 if (arvif->u.sta.uapsd)
3546 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3547 else
3548 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3549
3550 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3551 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3552 value);
3553 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003554 ath10k_warn("failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003555
3556exit:
3557 return ret;
3558}
3559
3560static int ath10k_conf_tx(struct ieee80211_hw *hw,
3561 struct ieee80211_vif *vif, u16 ac,
3562 const struct ieee80211_tx_queue_params *params)
3563{
3564 struct ath10k *ar = hw->priv;
3565 struct wmi_wmm_params_arg *p = NULL;
3566 int ret;
3567
3568 mutex_lock(&ar->conf_mutex);
3569
3570 switch (ac) {
3571 case IEEE80211_AC_VO:
3572 p = &ar->wmm_params.ac_vo;
3573 break;
3574 case IEEE80211_AC_VI:
3575 p = &ar->wmm_params.ac_vi;
3576 break;
3577 case IEEE80211_AC_BE:
3578 p = &ar->wmm_params.ac_be;
3579 break;
3580 case IEEE80211_AC_BK:
3581 p = &ar->wmm_params.ac_bk;
3582 break;
3583 }
3584
3585 if (WARN_ON(!p)) {
3586 ret = -EINVAL;
3587 goto exit;
3588 }
3589
3590 p->cwmin = params->cw_min;
3591 p->cwmax = params->cw_max;
3592 p->aifs = params->aifs;
3593
3594 /*
3595 * The channel time duration programmed in the HW is in absolute
3596 * microseconds, while mac80211 gives the txop in units of
3597 * 32 microseconds.
3598 */
3599 p->txop = params->txop * 32;
3600
3601 /* FIXME: FW accepts wmm params per hw, not per vif */
3602 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3603 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003604 ath10k_warn("failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 goto exit;
3606 }
3607
3608 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3609 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003610 ath10k_warn("failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003611
3612exit:
3613 mutex_unlock(&ar->conf_mutex);
3614 return ret;
3615}
3616
3617#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3618
3619static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3620 struct ieee80211_vif *vif,
3621 struct ieee80211_channel *chan,
3622 int duration,
3623 enum ieee80211_roc_type type)
3624{
3625 struct ath10k *ar = hw->priv;
3626 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3627 struct wmi_start_scan_arg arg;
3628 int ret;
3629
3630 mutex_lock(&ar->conf_mutex);
3631
3632 spin_lock_bh(&ar->data_lock);
3633 if (ar->scan.in_progress) {
3634 spin_unlock_bh(&ar->data_lock);
3635 ret = -EBUSY;
3636 goto exit;
3637 }
3638
Wolfram Sang16735d02013-11-14 14:32:02 -08003639 reinit_completion(&ar->scan.started);
3640 reinit_completion(&ar->scan.completed);
3641 reinit_completion(&ar->scan.on_channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003642 ar->scan.in_progress = true;
3643 ar->scan.aborting = false;
3644 ar->scan.is_roc = true;
3645 ar->scan.vdev_id = arvif->vdev_id;
3646 ar->scan.roc_freq = chan->center_freq;
3647 spin_unlock_bh(&ar->data_lock);
3648
3649 memset(&arg, 0, sizeof(arg));
3650 ath10k_wmi_start_scan_init(ar, &arg);
3651 arg.vdev_id = arvif->vdev_id;
3652 arg.scan_id = ATH10K_SCAN_ID;
3653 arg.n_channels = 1;
3654 arg.channels[0] = chan->center_freq;
3655 arg.dwell_time_active = duration;
3656 arg.dwell_time_passive = duration;
3657 arg.max_scan_time = 2 * duration;
3658 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3659 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3660
3661 ret = ath10k_start_scan(ar, &arg);
3662 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003663 ath10k_warn("failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003664 spin_lock_bh(&ar->data_lock);
3665 ar->scan.in_progress = false;
3666 spin_unlock_bh(&ar->data_lock);
3667 goto exit;
3668 }
3669
3670 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3671 if (ret == 0) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003672 ath10k_warn("failed to switch to channel for roc scan\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003673 ath10k_abort_scan(ar);
3674 ret = -ETIMEDOUT;
3675 goto exit;
3676 }
3677
3678 ret = 0;
3679exit:
3680 mutex_unlock(&ar->conf_mutex);
3681 return ret;
3682}
3683
3684static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3685{
3686 struct ath10k *ar = hw->priv;
3687
3688 mutex_lock(&ar->conf_mutex);
3689 ath10k_abort_scan(ar);
3690 mutex_unlock(&ar->conf_mutex);
3691
3692 return 0;
3693}
3694
3695/*
3696 * Both RTS and Fragmentation threshold are interface-specific
3697 * in ath10k, but device-specific in mac80211.
3698 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003699
3700static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3701{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003702 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003703 struct ath10k_vif *arvif;
3704 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003705
Michal Kaziorad088bf2013-10-16 15:44:46 +03003706 mutex_lock(&ar->conf_mutex);
3707 list_for_each_entry(arvif, &ar->arvifs, list) {
3708 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3709 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003710
Michal Kaziorad088bf2013-10-16 15:44:46 +03003711 ret = ath10k_mac_set_rts(arvif, value);
3712 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003713 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003714 arvif->vdev_id, ret);
3715 break;
3716 }
3717 }
3718 mutex_unlock(&ar->conf_mutex);
3719
3720 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003721}
3722
3723static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3724{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003725 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003726 struct ath10k_vif *arvif;
3727 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003728
Kalle Valo5e3dd152013-06-12 20:52:10 +03003729 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003730 list_for_each_entry(arvif, &ar->arvifs, list) {
3731 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3732 arvif->vdev_id, value);
3733
3734 ret = ath10k_mac_set_rts(arvif, value);
3735 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003736 ath10k_warn("failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003737 arvif->vdev_id, ret);
3738 break;
3739 }
3740 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003741 mutex_unlock(&ar->conf_mutex);
3742
Michal Kaziorad088bf2013-10-16 15:44:46 +03003743 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003744}
3745
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003746static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3747 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003748{
3749 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003750 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003751 int ret;
3752
3753 /* mac80211 doesn't care if we really xmit queued frames or not
3754 * we'll collect those frames either way if we stop/delete vdevs */
3755 if (drop)
3756 return;
3757
Michal Kazior548db542013-07-05 16:15:15 +03003758 mutex_lock(&ar->conf_mutex);
3759
Michal Kazioraffd3212013-07-16 09:54:35 +02003760 if (ar->state == ATH10K_STATE_WEDGED)
3761 goto skip;
3762
Michal Kazioredb82362013-07-05 16:15:14 +03003763 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003764 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003765
Michal Kazioredb82362013-07-05 16:15:14 +03003766 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003767 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003768 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003769
3770 skip = (ar->state == ATH10K_STATE_WEDGED);
3771
3772 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003773 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003774
3775 if (ret <= 0 || skip)
Kalle Valobe6546f2014-03-25 14:18:51 +02003776 ath10k_warn("failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003777 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003778
Michal Kazioraffd3212013-07-16 09:54:35 +02003779skip:
Michal Kazior548db542013-07-05 16:15:15 +03003780 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003781}
3782
3783/* TODO: Implement this function properly
3784 * For now it is needed to reply to Probe Requests in IBSS mode.
3785 * Propably we need this information from FW.
3786 */
3787static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3788{
3789 return 1;
3790}
3791
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003792#ifdef CONFIG_PM
3793static int ath10k_suspend(struct ieee80211_hw *hw,
3794 struct cfg80211_wowlan *wowlan)
3795{
3796 struct ath10k *ar = hw->priv;
3797 int ret;
3798
Marek Puzyniak9042e172014-02-10 17:14:23 +01003799 mutex_lock(&ar->conf_mutex);
3800
Marek Puzyniak00f54822014-02-10 17:14:24 +01003801 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003802 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003803 if (ret == -ETIMEDOUT)
3804 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003805 ret = 1;
3806 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003807 }
3808
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003809 ret = ath10k_hif_suspend(ar);
3810 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003811 ath10k_warn("failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003812 goto resume;
3813 }
3814
Marek Puzyniak9042e172014-02-10 17:14:23 +01003815 ret = 0;
3816 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003817resume:
3818 ret = ath10k_wmi_pdev_resume_target(ar);
3819 if (ret)
Kalle Valobe6546f2014-03-25 14:18:51 +02003820 ath10k_warn("failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003821
3822 ret = 1;
3823exit:
3824 mutex_unlock(&ar->conf_mutex);
3825 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003826}
3827
3828static int ath10k_resume(struct ieee80211_hw *hw)
3829{
3830 struct ath10k *ar = hw->priv;
3831 int ret;
3832
Marek Puzyniak9042e172014-02-10 17:14:23 +01003833 mutex_lock(&ar->conf_mutex);
3834
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003835 ret = ath10k_hif_resume(ar);
3836 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003837 ath10k_warn("failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003838 ret = 1;
3839 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003840 }
3841
3842 ret = ath10k_wmi_pdev_resume_target(ar);
3843 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02003844 ath10k_warn("failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003845 ret = 1;
3846 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003847 }
3848
Marek Puzyniak9042e172014-02-10 17:14:23 +01003849 ret = 0;
3850exit:
3851 mutex_unlock(&ar->conf_mutex);
3852 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003853}
3854#endif
3855
Michal Kazioraffd3212013-07-16 09:54:35 +02003856static void ath10k_restart_complete(struct ieee80211_hw *hw)
3857{
3858 struct ath10k *ar = hw->priv;
3859
3860 mutex_lock(&ar->conf_mutex);
3861
3862 /* If device failed to restart it will be in a different state, e.g.
3863 * ATH10K_STATE_WEDGED */
3864 if (ar->state == ATH10K_STATE_RESTARTED) {
3865 ath10k_info("device successfully recovered\n");
3866 ar->state = ATH10K_STATE_ON;
3867 }
3868
3869 mutex_unlock(&ar->conf_mutex);
3870}
3871
Michal Kazior2e1dea42013-07-31 10:32:40 +02003872static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3873 struct survey_info *survey)
3874{
3875 struct ath10k *ar = hw->priv;
3876 struct ieee80211_supported_band *sband;
3877 struct survey_info *ar_survey = &ar->survey[idx];
3878 int ret = 0;
3879
3880 mutex_lock(&ar->conf_mutex);
3881
3882 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3883 if (sband && idx >= sband->n_channels) {
3884 idx -= sband->n_channels;
3885 sband = NULL;
3886 }
3887
3888 if (!sband)
3889 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3890
3891 if (!sband || idx >= sband->n_channels) {
3892 ret = -ENOENT;
3893 goto exit;
3894 }
3895
3896 spin_lock_bh(&ar->data_lock);
3897 memcpy(survey, ar_survey, sizeof(*survey));
3898 spin_unlock_bh(&ar->data_lock);
3899
3900 survey->channel = &sband->channels[idx];
3901
3902exit:
3903 mutex_unlock(&ar->conf_mutex);
3904 return ret;
3905}
3906
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003907/* Helper table for legacy fixed_rate/bitrate_mask */
3908static const u8 cck_ofdm_rate[] = {
3909 /* CCK */
3910 3, /* 1Mbps */
3911 2, /* 2Mbps */
3912 1, /* 5.5Mbps */
3913 0, /* 11Mbps */
3914 /* OFDM */
3915 3, /* 6Mbps */
3916 7, /* 9Mbps */
3917 2, /* 12Mbps */
3918 6, /* 18Mbps */
3919 1, /* 24Mbps */
3920 5, /* 36Mbps */
3921 0, /* 48Mbps */
3922 4, /* 54Mbps */
3923};
3924
3925/* Check if only one bit set */
3926static int ath10k_check_single_mask(u32 mask)
3927{
3928 int bit;
3929
3930 bit = ffs(mask);
3931 if (!bit)
3932 return 0;
3933
3934 mask &= ~BIT(bit - 1);
3935 if (mask)
3936 return 2;
3937
3938 return 1;
3939}
3940
3941static bool
3942ath10k_default_bitrate_mask(struct ath10k *ar,
3943 enum ieee80211_band band,
3944 const struct cfg80211_bitrate_mask *mask)
3945{
3946 u32 legacy = 0x00ff;
3947 u8 ht = 0xff, i;
3948 u16 vht = 0x3ff;
3949
3950 switch (band) {
3951 case IEEE80211_BAND_2GHZ:
3952 legacy = 0x00fff;
3953 vht = 0;
3954 break;
3955 case IEEE80211_BAND_5GHZ:
3956 break;
3957 default:
3958 return false;
3959 }
3960
3961 if (mask->control[band].legacy != legacy)
3962 return false;
3963
3964 for (i = 0; i < ar->num_rf_chains; i++)
3965 if (mask->control[band].ht_mcs[i] != ht)
3966 return false;
3967
3968 for (i = 0; i < ar->num_rf_chains; i++)
3969 if (mask->control[band].vht_mcs[i] != vht)
3970 return false;
3971
3972 return true;
3973}
3974
3975static bool
3976ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3977 enum ieee80211_band band,
3978 u8 *fixed_nss)
3979{
3980 int ht_nss = 0, vht_nss = 0, i;
3981
3982 /* check legacy */
3983 if (ath10k_check_single_mask(mask->control[band].legacy))
3984 return false;
3985
3986 /* check HT */
3987 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3988 if (mask->control[band].ht_mcs[i] == 0xff)
3989 continue;
3990 else if (mask->control[band].ht_mcs[i] == 0x00)
3991 break;
3992 else
3993 return false;
3994 }
3995
3996 ht_nss = i;
3997
3998 /* check VHT */
3999 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4000 if (mask->control[band].vht_mcs[i] == 0x03ff)
4001 continue;
4002 else if (mask->control[band].vht_mcs[i] == 0x0000)
4003 break;
4004 else
4005 return false;
4006 }
4007
4008 vht_nss = i;
4009
4010 if (ht_nss > 0 && vht_nss > 0)
4011 return false;
4012
4013 if (ht_nss)
4014 *fixed_nss = ht_nss;
4015 else if (vht_nss)
4016 *fixed_nss = vht_nss;
4017 else
4018 return false;
4019
4020 return true;
4021}
4022
4023static bool
4024ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4025 enum ieee80211_band band,
4026 enum wmi_rate_preamble *preamble)
4027{
4028 int legacy = 0, ht = 0, vht = 0, i;
4029
4030 *preamble = WMI_RATE_PREAMBLE_OFDM;
4031
4032 /* check legacy */
4033 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4034 if (legacy > 1)
4035 return false;
4036
4037 /* check HT */
4038 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4039 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4040 if (ht > 1)
4041 return false;
4042
4043 /* check VHT */
4044 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4045 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4046 if (vht > 1)
4047 return false;
4048
4049 /* Currently we support only one fixed_rate */
4050 if ((legacy + ht + vht) != 1)
4051 return false;
4052
4053 if (ht)
4054 *preamble = WMI_RATE_PREAMBLE_HT;
4055 else if (vht)
4056 *preamble = WMI_RATE_PREAMBLE_VHT;
4057
4058 return true;
4059}
4060
4061static bool
4062ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
4063 enum ieee80211_band band,
4064 u8 *fixed_rate,
4065 u8 *fixed_nss)
4066{
4067 u8 rate = 0, pream = 0, nss = 0, i;
4068 enum wmi_rate_preamble preamble;
4069
4070 /* Check if single rate correct */
4071 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4072 return false;
4073
4074 pream = preamble;
4075
4076 switch (preamble) {
4077 case WMI_RATE_PREAMBLE_CCK:
4078 case WMI_RATE_PREAMBLE_OFDM:
4079 i = ffs(mask->control[band].legacy) - 1;
4080
4081 if (band == IEEE80211_BAND_2GHZ && i < 4)
4082 pream = WMI_RATE_PREAMBLE_CCK;
4083
4084 if (band == IEEE80211_BAND_5GHZ)
4085 i += 4;
4086
4087 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4088 return false;
4089
4090 rate = cck_ofdm_rate[i];
4091 break;
4092 case WMI_RATE_PREAMBLE_HT:
4093 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4094 if (mask->control[band].ht_mcs[i])
4095 break;
4096
4097 if (i == IEEE80211_HT_MCS_MASK_LEN)
4098 return false;
4099
4100 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4101 nss = i;
4102 break;
4103 case WMI_RATE_PREAMBLE_VHT:
4104 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4105 if (mask->control[band].vht_mcs[i])
4106 break;
4107
4108 if (i == NL80211_VHT_NSS_MAX)
4109 return false;
4110
4111 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4112 nss = i;
4113 break;
4114 }
4115
4116 *fixed_nss = nss + 1;
4117 nss <<= 4;
4118 pream <<= 6;
4119
4120 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4121 pream, nss, rate);
4122
4123 *fixed_rate = pream | nss | rate;
4124
4125 return true;
4126}
4127
4128static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
4129 enum ieee80211_band band,
4130 u8 *fixed_rate,
4131 u8 *fixed_nss)
4132{
4133 /* First check full NSS mask, if we can simply limit NSS */
4134 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4135 return true;
4136
4137 /* Next Check single rate is set */
4138 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
4139}
4140
4141static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4142 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004143 u8 fixed_nss,
4144 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004145{
4146 struct ath10k *ar = arvif->ar;
4147 u32 vdev_param;
4148 int ret = 0;
4149
4150 mutex_lock(&ar->conf_mutex);
4151
4152 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004153 arvif->fixed_nss == fixed_nss &&
4154 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004155 goto exit;
4156
4157 if (fixed_rate == WMI_FIXED_RATE_NONE)
4158 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4159
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004160 if (force_sgi)
4161 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
4162
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004163 vdev_param = ar->wmi.vdev_param->fixed_rate;
4164 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4165 vdev_param, fixed_rate);
4166 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004167 ath10k_warn("failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004168 fixed_rate, ret);
4169 ret = -EINVAL;
4170 goto exit;
4171 }
4172
4173 arvif->fixed_rate = fixed_rate;
4174
4175 vdev_param = ar->wmi.vdev_param->nss;
4176 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4177 vdev_param, fixed_nss);
4178
4179 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004180 ath10k_warn("failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004181 fixed_nss, ret);
4182 ret = -EINVAL;
4183 goto exit;
4184 }
4185
4186 arvif->fixed_nss = fixed_nss;
4187
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004188 vdev_param = ar->wmi.vdev_param->sgi;
4189 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4190 force_sgi);
4191
4192 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004193 ath10k_warn("failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004194 force_sgi, ret);
4195 ret = -EINVAL;
4196 goto exit;
4197 }
4198
4199 arvif->force_sgi = force_sgi;
4200
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004201exit:
4202 mutex_unlock(&ar->conf_mutex);
4203 return ret;
4204}
4205
4206static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4207 struct ieee80211_vif *vif,
4208 const struct cfg80211_bitrate_mask *mask)
4209{
4210 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4211 struct ath10k *ar = arvif->ar;
4212 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4213 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4214 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004215 u8 force_sgi;
4216
4217 force_sgi = mask->control[band].gi;
4218 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4219 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004220
4221 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4222 if (!ath10k_get_fixed_rate_nss(mask, band,
4223 &fixed_rate,
4224 &fixed_nss))
4225 return -EINVAL;
4226 }
4227
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004228 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004229 ath10k_warn("failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004230 return -EINVAL;
4231 }
4232
4233 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4234 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004235}
4236
Michal Kazior9797feb2014-02-14 14:49:48 +01004237static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4238 struct ieee80211_vif *vif,
4239 struct ieee80211_sta *sta,
4240 u32 changed)
4241{
4242 struct ath10k *ar = hw->priv;
4243 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4244 u32 bw, smps;
4245
4246 spin_lock_bh(&ar->data_lock);
4247
4248 ath10k_dbg(ATH10K_DBG_MAC,
4249 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4250 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4251 sta->smps_mode);
4252
4253 if (changed & IEEE80211_RC_BW_CHANGED) {
4254 bw = WMI_PEER_CHWIDTH_20MHZ;
4255
4256 switch (sta->bandwidth) {
4257 case IEEE80211_STA_RX_BW_20:
4258 bw = WMI_PEER_CHWIDTH_20MHZ;
4259 break;
4260 case IEEE80211_STA_RX_BW_40:
4261 bw = WMI_PEER_CHWIDTH_40MHZ;
4262 break;
4263 case IEEE80211_STA_RX_BW_80:
4264 bw = WMI_PEER_CHWIDTH_80MHZ;
4265 break;
4266 case IEEE80211_STA_RX_BW_160:
Kalle Valobe6546f2014-03-25 14:18:51 +02004267 ath10k_warn("Invalid bandwith %d in rc update for %pM\n",
4268 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004269 bw = WMI_PEER_CHWIDTH_20MHZ;
4270 break;
4271 }
4272
4273 arsta->bw = bw;
4274 }
4275
4276 if (changed & IEEE80211_RC_NSS_CHANGED)
4277 arsta->nss = sta->rx_nss;
4278
4279 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4280 smps = WMI_PEER_SMPS_PS_NONE;
4281
4282 switch (sta->smps_mode) {
4283 case IEEE80211_SMPS_AUTOMATIC:
4284 case IEEE80211_SMPS_OFF:
4285 smps = WMI_PEER_SMPS_PS_NONE;
4286 break;
4287 case IEEE80211_SMPS_STATIC:
4288 smps = WMI_PEER_SMPS_STATIC;
4289 break;
4290 case IEEE80211_SMPS_DYNAMIC:
4291 smps = WMI_PEER_SMPS_DYNAMIC;
4292 break;
4293 case IEEE80211_SMPS_NUM_MODES:
Kalle Valobe6546f2014-03-25 14:18:51 +02004294 ath10k_warn("Invalid smps %d in sta rc update for %pM\n",
4295 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004296 smps = WMI_PEER_SMPS_PS_NONE;
4297 break;
4298 }
4299
4300 arsta->smps = smps;
4301 }
4302
Michal Kazior9797feb2014-02-14 14:49:48 +01004303 arsta->changed |= changed;
4304
4305 spin_unlock_bh(&ar->data_lock);
4306
4307 ieee80211_queue_work(hw, &arsta->update_wk);
4308}
4309
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004310static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4311{
4312 /*
4313 * FIXME: Return 0 for time being. Need to figure out whether FW
4314 * has the API to fetch 64-bit local TSF
4315 */
4316
4317 return 0;
4318}
4319
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320static const struct ieee80211_ops ath10k_ops = {
4321 .tx = ath10k_tx,
4322 .start = ath10k_start,
4323 .stop = ath10k_stop,
4324 .config = ath10k_config,
4325 .add_interface = ath10k_add_interface,
4326 .remove_interface = ath10k_remove_interface,
4327 .configure_filter = ath10k_configure_filter,
4328 .bss_info_changed = ath10k_bss_info_changed,
4329 .hw_scan = ath10k_hw_scan,
4330 .cancel_hw_scan = ath10k_cancel_hw_scan,
4331 .set_key = ath10k_set_key,
4332 .sta_state = ath10k_sta_state,
4333 .conf_tx = ath10k_conf_tx,
4334 .remain_on_channel = ath10k_remain_on_channel,
4335 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4336 .set_rts_threshold = ath10k_set_rts_threshold,
4337 .set_frag_threshold = ath10k_set_frag_threshold,
4338 .flush = ath10k_flush,
4339 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004340 .set_antenna = ath10k_set_antenna,
4341 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004342 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004343 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004344 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004345 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004346 .get_tsf = ath10k_get_tsf,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004347#ifdef CONFIG_PM
4348 .suspend = ath10k_suspend,
4349 .resume = ath10k_resume,
4350#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004351};
4352
4353#define RATETAB_ENT(_rate, _rateid, _flags) { \
4354 .bitrate = (_rate), \
4355 .flags = (_flags), \
4356 .hw_value = (_rateid), \
4357}
4358
4359#define CHAN2G(_channel, _freq, _flags) { \
4360 .band = IEEE80211_BAND_2GHZ, \
4361 .hw_value = (_channel), \
4362 .center_freq = (_freq), \
4363 .flags = (_flags), \
4364 .max_antenna_gain = 0, \
4365 .max_power = 30, \
4366}
4367
4368#define CHAN5G(_channel, _freq, _flags) { \
4369 .band = IEEE80211_BAND_5GHZ, \
4370 .hw_value = (_channel), \
4371 .center_freq = (_freq), \
4372 .flags = (_flags), \
4373 .max_antenna_gain = 0, \
4374 .max_power = 30, \
4375}
4376
4377static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4378 CHAN2G(1, 2412, 0),
4379 CHAN2G(2, 2417, 0),
4380 CHAN2G(3, 2422, 0),
4381 CHAN2G(4, 2427, 0),
4382 CHAN2G(5, 2432, 0),
4383 CHAN2G(6, 2437, 0),
4384 CHAN2G(7, 2442, 0),
4385 CHAN2G(8, 2447, 0),
4386 CHAN2G(9, 2452, 0),
4387 CHAN2G(10, 2457, 0),
4388 CHAN2G(11, 2462, 0),
4389 CHAN2G(12, 2467, 0),
4390 CHAN2G(13, 2472, 0),
4391 CHAN2G(14, 2484, 0),
4392};
4393
4394static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004395 CHAN5G(36, 5180, 0),
4396 CHAN5G(40, 5200, 0),
4397 CHAN5G(44, 5220, 0),
4398 CHAN5G(48, 5240, 0),
4399 CHAN5G(52, 5260, 0),
4400 CHAN5G(56, 5280, 0),
4401 CHAN5G(60, 5300, 0),
4402 CHAN5G(64, 5320, 0),
4403 CHAN5G(100, 5500, 0),
4404 CHAN5G(104, 5520, 0),
4405 CHAN5G(108, 5540, 0),
4406 CHAN5G(112, 5560, 0),
4407 CHAN5G(116, 5580, 0),
4408 CHAN5G(120, 5600, 0),
4409 CHAN5G(124, 5620, 0),
4410 CHAN5G(128, 5640, 0),
4411 CHAN5G(132, 5660, 0),
4412 CHAN5G(136, 5680, 0),
4413 CHAN5G(140, 5700, 0),
4414 CHAN5G(149, 5745, 0),
4415 CHAN5G(153, 5765, 0),
4416 CHAN5G(157, 5785, 0),
4417 CHAN5G(161, 5805, 0),
4418 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004419};
4420
4421static struct ieee80211_rate ath10k_rates[] = {
4422 /* CCK */
4423 RATETAB_ENT(10, 0x82, 0),
4424 RATETAB_ENT(20, 0x84, 0),
4425 RATETAB_ENT(55, 0x8b, 0),
4426 RATETAB_ENT(110, 0x96, 0),
4427 /* OFDM */
4428 RATETAB_ENT(60, 0x0c, 0),
4429 RATETAB_ENT(90, 0x12, 0),
4430 RATETAB_ENT(120, 0x18, 0),
4431 RATETAB_ENT(180, 0x24, 0),
4432 RATETAB_ENT(240, 0x30, 0),
4433 RATETAB_ENT(360, 0x48, 0),
4434 RATETAB_ENT(480, 0x60, 0),
4435 RATETAB_ENT(540, 0x6c, 0),
4436};
4437
4438#define ath10k_a_rates (ath10k_rates + 4)
4439#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4440#define ath10k_g_rates (ath10k_rates + 0)
4441#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4442
4443struct ath10k *ath10k_mac_create(void)
4444{
4445 struct ieee80211_hw *hw;
4446 struct ath10k *ar;
4447
4448 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4449 if (!hw)
4450 return NULL;
4451
4452 ar = hw->priv;
4453 ar->hw = hw;
4454
4455 return ar;
4456}
4457
4458void ath10k_mac_destroy(struct ath10k *ar)
4459{
4460 ieee80211_free_hw(ar->hw);
4461}
4462
4463static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4464 {
4465 .max = 8,
4466 .types = BIT(NL80211_IFTYPE_STATION)
4467 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004468 },
4469 {
4470 .max = 3,
4471 .types = BIT(NL80211_IFTYPE_P2P_GO)
4472 },
4473 {
4474 .max = 7,
4475 .types = BIT(NL80211_IFTYPE_AP)
4476 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004477};
4478
Bartosz Markowskif2595092013-12-10 16:20:39 +01004479static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004480 {
4481 .max = 8,
4482 .types = BIT(NL80211_IFTYPE_AP)
4483 },
4484};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004485
4486static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4487 {
4488 .limits = ath10k_if_limits,
4489 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4490 .max_interfaces = 8,
4491 .num_different_channels = 1,
4492 .beacon_int_infra_match = true,
4493 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004494};
4495
4496static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004497 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004498 .limits = ath10k_10x_if_limits,
4499 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004500 .max_interfaces = 8,
4501 .num_different_channels = 1,
4502 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004503#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004504 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4505 BIT(NL80211_CHAN_WIDTH_20) |
4506 BIT(NL80211_CHAN_WIDTH_40) |
4507 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004508#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004509 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510};
4511
4512static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4513{
4514 struct ieee80211_sta_vht_cap vht_cap = {0};
4515 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004516 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004517
4518 vht_cap.vht_supported = 1;
4519 vht_cap.cap = ar->vht_cap_info;
4520
Michal Kazior8865bee42013-07-24 12:36:46 +02004521 mcs_map = 0;
4522 for (i = 0; i < 8; i++) {
4523 if (i < ar->num_rf_chains)
4524 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4525 else
4526 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4527 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004528
4529 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4530 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4531
4532 return vht_cap;
4533}
4534
4535static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4536{
4537 int i;
4538 struct ieee80211_sta_ht_cap ht_cap = {0};
4539
4540 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4541 return ht_cap;
4542
4543 ht_cap.ht_supported = 1;
4544 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4545 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4546 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4547 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4548 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4549
4550 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4551 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4552
4553 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4554 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4555
4556 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4557 u32 smps;
4558
4559 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4560 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4561
4562 ht_cap.cap |= smps;
4563 }
4564
4565 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4566 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4567
4568 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4569 u32 stbc;
4570
4571 stbc = ar->ht_cap_info;
4572 stbc &= WMI_HT_CAP_RX_STBC;
4573 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4574 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4575 stbc &= IEEE80211_HT_CAP_RX_STBC;
4576
4577 ht_cap.cap |= stbc;
4578 }
4579
4580 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4581 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4582
4583 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4584 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4585
4586 /* max AMSDU is implicitly taken from vht_cap_info */
4587 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4588 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4589
Michal Kazior8865bee42013-07-24 12:36:46 +02004590 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004591 ht_cap.mcs.rx_mask[i] = 0xFF;
4592
4593 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4594
4595 return ht_cap;
4596}
4597
4598
4599static void ath10k_get_arvif_iter(void *data, u8 *mac,
4600 struct ieee80211_vif *vif)
4601{
4602 struct ath10k_vif_iter *arvif_iter = data;
4603 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4604
4605 if (arvif->vdev_id == arvif_iter->vdev_id)
4606 arvif_iter->arvif = arvif;
4607}
4608
4609struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4610{
4611 struct ath10k_vif_iter arvif_iter;
4612 u32 flags;
4613
4614 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4615 arvif_iter.vdev_id = vdev_id;
4616
4617 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4618 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4619 flags,
4620 ath10k_get_arvif_iter,
4621 &arvif_iter);
4622 if (!arvif_iter.arvif) {
Ben Greear69244e52014-02-27 18:50:00 +02004623 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624 return NULL;
4625 }
4626
4627 return arvif_iter.arvif;
4628}
4629
4630int ath10k_mac_register(struct ath10k *ar)
4631{
4632 struct ieee80211_supported_band *band;
4633 struct ieee80211_sta_vht_cap vht_cap;
4634 struct ieee80211_sta_ht_cap ht_cap;
4635 void *channels;
4636 int ret;
4637
4638 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4639
4640 SET_IEEE80211_DEV(ar->hw, ar->dev);
4641
4642 ht_cap = ath10k_get_ht_cap(ar);
4643 vht_cap = ath10k_create_vht_cap(ar);
4644
4645 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4646 channels = kmemdup(ath10k_2ghz_channels,
4647 sizeof(ath10k_2ghz_channels),
4648 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004649 if (!channels) {
4650 ret = -ENOMEM;
4651 goto err_free;
4652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004653
4654 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4655 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4656 band->channels = channels;
4657 band->n_bitrates = ath10k_g_rates_size;
4658 band->bitrates = ath10k_g_rates;
4659 band->ht_cap = ht_cap;
4660
4661 /* vht is not supported in 2.4 GHz */
4662
4663 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4664 }
4665
4666 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4667 channels = kmemdup(ath10k_5ghz_channels,
4668 sizeof(ath10k_5ghz_channels),
4669 GFP_KERNEL);
4670 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004671 ret = -ENOMEM;
4672 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004673 }
4674
4675 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4676 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4677 band->channels = channels;
4678 band->n_bitrates = ath10k_a_rates_size;
4679 band->bitrates = ath10k_a_rates;
4680 band->ht_cap = ht_cap;
4681 band->vht_cap = vht_cap;
4682 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4683 }
4684
4685 ar->hw->wiphy->interface_modes =
4686 BIT(NL80211_IFTYPE_STATION) |
4687 BIT(NL80211_IFTYPE_ADHOC) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004688 BIT(NL80211_IFTYPE_AP);
4689
Ben Greear46acf7b2014-05-16 17:15:38 +03004690 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4691 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4692 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4693 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4694 } else {
4695 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4696 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4697 }
4698
4699 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4700 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4701
Bartosz Markowskid3541812013-12-10 16:20:40 +01004702 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4703 ar->hw->wiphy->interface_modes |=
4704 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4705 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004706
4707 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4708 IEEE80211_HW_SUPPORTS_PS |
4709 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4710 IEEE80211_HW_SUPPORTS_UAPSD |
4711 IEEE80211_HW_MFP_CAPABLE |
4712 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4713 IEEE80211_HW_HAS_RATE_CONTROL |
4714 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004715 IEEE80211_HW_AP_LINK_PS |
4716 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004717
Michal Kazior1f8bb152013-09-18 14:43:22 +02004718 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4719 * bytes is used for padding/alignment if necessary. */
4720 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4721
Kalle Valo5e3dd152013-06-12 20:52:10 +03004722 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4723 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4724
4725 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4726 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4727 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4728 }
4729
4730 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4731 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4732
4733 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004734 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004735
Kalle Valo5e3dd152013-06-12 20:52:10 +03004736 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4737
4738 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004739 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004740 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4741
4742 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4743 /*
4744 * on LL hardware queues are managed entirely by the FW
4745 * so we only advertise to mac we can do the queues thing
4746 */
4747 ar->hw->queues = 4;
4748
Bartosz Markowskif2595092013-12-10 16:20:39 +01004749 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4750 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4751 ar->hw->wiphy->n_iface_combinations =
4752 ARRAY_SIZE(ath10k_10x_if_comb);
4753 } else {
4754 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4755 ar->hw->wiphy->n_iface_combinations =
4756 ARRAY_SIZE(ath10k_if_comb);
4757 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004758
Michal Kazior7c199992013-07-31 10:47:57 +02004759 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4760
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004761 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4762 /* Init ath dfs pattern detector */
4763 ar->ath_common.debug_mask = ATH_DBG_DFS;
4764 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4765 NL80211_DFS_UNSET);
4766
4767 if (!ar->dfs_detector)
Kalle Valobe6546f2014-03-25 14:18:51 +02004768 ath10k_warn("failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004769 }
4770
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4772 ath10k_reg_notifier);
4773 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004774 ath10k_err("failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004775 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004776 }
4777
4778 ret = ieee80211_register_hw(ar->hw);
4779 if (ret) {
Kalle Valobe6546f2014-03-25 14:18:51 +02004780 ath10k_err("failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004781 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004782 }
4783
4784 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4785 ret = regulatory_hint(ar->hw->wiphy,
4786 ar->ath_common.regulatory.alpha2);
4787 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004788 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004789 }
4790
4791 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004792
4793err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004794 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004795err_free:
4796 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4797 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4798
Kalle Valo5e3dd152013-06-12 20:52:10 +03004799 return ret;
4800}
4801
4802void ath10k_mac_unregister(struct ath10k *ar)
4803{
4804 ieee80211_unregister_hw(ar->hw);
4805
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004806 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4807 ar->dfs_detector->exit(ar->dfs_detector);
4808
Kalle Valo5e3dd152013-06-12 20:52:10 +03004809 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4810 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4811
4812 SET_IEEE80211_DEV(ar->hw, NULL);
4813}