blob: 4e30e577b3ed8dc68d9354d9fc9a657defb5806d [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{
Michal Kazior7aa7a722014-08-25 12:09:38 +020039 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030040 struct wmi_vdev_install_key_arg arg = {
41 .vdev_id = arvif->vdev_id,
42 .key_idx = key->keyidx,
43 .key_len = key->keylen,
44 .key_data = key->key,
45 .macaddr = macaddr,
46 };
47
Michal Kazior548db542013-07-05 16:15:15 +030048 lockdep_assert_held(&arvif->ar->conf_mutex);
49
Kalle Valo5e3dd152013-06-12 20:52:10 +030050 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
51 arg.key_flags = WMI_KEY_PAIRWISE;
52 else
53 arg.key_flags = WMI_KEY_GROUP;
54
55 switch (key->cipher) {
56 case WLAN_CIPHER_SUITE_CCMP:
57 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030058 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
59 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
60 else
61 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
75 break;
76 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020077 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 return -EOPNOTSUPP;
79 }
80
81 if (cmd == DISABLE_KEY) {
82 arg.key_cipher = WMI_CIPHER_NONE;
83 arg.key_data = NULL;
84 }
85
86 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
87}
88
89static int ath10k_install_key(struct ath10k_vif *arvif,
90 struct ieee80211_key_conf *key,
91 enum set_key_cmd cmd,
92 const u8 *macaddr)
93{
94 struct ath10k *ar = arvif->ar;
95 int ret;
96
Michal Kazior548db542013-07-05 16:15:15 +030097 lockdep_assert_held(&ar->conf_mutex);
98
Wolfram Sang16735d02013-11-14 14:32:02 -080099 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300100
101 ret = ath10k_send_key(arvif, key, cmd, macaddr);
102 if (ret)
103 return ret;
104
105 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
106 if (ret == 0)
107 return -ETIMEDOUT;
108
109 return 0;
110}
111
112static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
113 const u8 *addr)
114{
115 struct ath10k *ar = arvif->ar;
116 struct ath10k_peer *peer;
117 int ret;
118 int i;
119
120 lockdep_assert_held(&ar->conf_mutex);
121
122 spin_lock_bh(&ar->data_lock);
123 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
124 spin_unlock_bh(&ar->data_lock);
125
126 if (!peer)
127 return -ENOENT;
128
129 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
130 if (arvif->wep_keys[i] == NULL)
131 continue;
132
133 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 addr);
135 if (ret)
136 return ret;
137
138 peer->keys[i] = arvif->wep_keys[i];
139 }
140
141 return 0;
142}
143
144static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
145 const u8 *addr)
146{
147 struct ath10k *ar = arvif->ar;
148 struct ath10k_peer *peer;
149 int first_errno = 0;
150 int ret;
151 int i;
152
153 lockdep_assert_held(&ar->conf_mutex);
154
155 spin_lock_bh(&ar->data_lock);
156 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
157 spin_unlock_bh(&ar->data_lock);
158
159 if (!peer)
160 return -ENOENT;
161
162 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
163 if (peer->keys[i] == NULL)
164 continue;
165
166 ret = ath10k_install_key(arvif, peer->keys[i],
167 DISABLE_KEY, addr);
168 if (ret && first_errno == 0)
169 first_errno = ret;
170
171 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200172 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 i, ret);
174
175 peer->keys[i] = NULL;
176 }
177
178 return first_errno;
179}
180
181static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
182 struct ieee80211_key_conf *key)
183{
184 struct ath10k *ar = arvif->ar;
185 struct ath10k_peer *peer;
186 u8 addr[ETH_ALEN];
187 int first_errno = 0;
188 int ret;
189 int i;
190
191 lockdep_assert_held(&ar->conf_mutex);
192
193 for (;;) {
194 /* since ath10k_install_key we can't hold data_lock all the
195 * time, so we try to remove the keys incrementally */
196 spin_lock_bh(&ar->data_lock);
197 i = 0;
198 list_for_each_entry(peer, &ar->peers, list) {
199 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
200 if (peer->keys[i] == key) {
201 memcpy(addr, peer->addr, ETH_ALEN);
202 peer->keys[i] = NULL;
203 break;
204 }
205 }
206
207 if (i < ARRAY_SIZE(peer->keys))
208 break;
209 }
210 spin_unlock_bh(&ar->data_lock);
211
212 if (i == ARRAY_SIZE(peer->keys))
213 break;
214
215 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
216 if (ret && first_errno == 0)
217 first_errno = ret;
218
219 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200220 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200221 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300222 }
223
224 return first_errno;
225}
226
227
228/*********************/
229/* General utilities */
230/*********************/
231
232static inline enum wmi_phy_mode
233chan_to_phymode(const struct cfg80211_chan_def *chandef)
234{
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
241 phymode = MODE_11G;
242 break;
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
245 break;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
248 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
255 break;
256 }
257 break;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
261 phymode = MODE_11A;
262 break;
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
265 break;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
268 break;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
271 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
277 break;
278 }
279 break;
280 default:
281 break;
282 }
283
284 WARN_ON(phymode == MODE_UNKNOWN);
285 return phymode;
286}
287
288static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
289{
290/*
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
293 * 1 for 1/4 us
294 * 2 for 1/2 us
295 * 3 for 1 us
296 * 4 for 2 us
297 * 5 for 4 us
298 * 6 for 8 us
299 * 7 for 16 us
300 */
301 switch (mpdudensity) {
302 case 0:
303 return 0;
304 case 1:
305 case 2:
306 case 3:
307 /* Our lower layer calculations limit our precision to
308 1 microsecond */
309 return 1;
310 case 4:
311 return 2;
312 case 5:
313 return 4;
314 case 6:
315 return 8;
316 case 7:
317 return 16;
318 default:
319 return 0;
320 }
321}
322
323static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
324{
325 int ret;
326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800330 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200332 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200339 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800341 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100342 spin_lock_bh(&ar->data_lock);
343 ar->num_peers++;
344 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300345
346 return 0;
347}
348
Kalle Valo5a13e762014-01-20 11:01:46 +0200349static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350{
351 struct ath10k *ar = arvif->ar;
352 u32 param;
353 int ret;
354
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
358 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200360 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200361 return ret;
362 }
363
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200370 return ret;
371 }
372
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200378 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200379 return ret;
380 }
381
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200387 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200388 return ret;
389 }
390
391 return 0;
392}
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200396 struct ath10k *ar = arvif->ar;
397 u32 vdev_param;
398
Michal Kazior424121c2013-07-22 14:13:31 +0200399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
401 ATH10K_RTS_MAX);
402
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200405}
406
407static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 struct ath10k *ar = arvif->ar;
410 u32 vdev_param;
411
Michal Kazior424121c2013-07-22 14:13:31 +0200412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
416
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
422{
423 int ret;
424
425 lockdep_assert_held(&ar->conf_mutex);
426
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
428 if (ret)
429 return ret;
430
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
432 if (ret)
433 return ret;
434
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100435 spin_lock_bh(&ar->data_lock);
436 ar->num_peers--;
437 spin_unlock_bh(&ar->data_lock);
438
Kalle Valo5e3dd152013-06-12 20:52:10 +0300439 return 0;
440}
441
442static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443{
444 struct ath10k_peer *peer, *tmp;
445
446 lockdep_assert_held(&ar->conf_mutex);
447
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
451 continue;
452
Michal Kazior7aa7a722014-08-25 12:09:38 +0200453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 peer->addr, vdev_id);
455
456 list_del(&peer->list);
457 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100458 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 }
460 spin_unlock_bh(&ar->data_lock);
461}
462
Michal Kaziora96d7742013-07-16 09:38:56 +0200463static void ath10k_peer_cleanup_all(struct ath10k *ar)
464{
465 struct ath10k_peer *peer, *tmp;
466
467 lockdep_assert_held(&ar->conf_mutex);
468
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
472 kfree(peer);
473 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200475 spin_unlock_bh(&ar->data_lock);
476}
477
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478/************************/
479/* Interface management */
480/************************/
481
482static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
483{
484 int ret;
485
Michal Kazior548db542013-07-05 16:15:15 +0300486 lockdep_assert_held(&ar->conf_mutex);
487
Kalle Valo5e3dd152013-06-12 20:52:10 +0300488 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
489 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
490 if (ret == 0)
491 return -ETIMEDOUT;
492
493 return 0;
494}
495
Michal Kazior1bbc0972014-04-08 09:45:47 +0300496static bool ath10k_monitor_is_enabled(struct ath10k *ar)
497{
498 lockdep_assert_held(&ar->conf_mutex);
499
Michal Kazior7aa7a722014-08-25 12:09:38 +0200500 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior1bbc0972014-04-08 09:45:47 +0300501 "mac monitor refs: promisc %d monitor %d cac %d\n",
502 ar->promisc, ar->monitor,
503 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags));
504
505 return ar->promisc || ar->monitor ||
506 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
507}
508
509static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300510{
Michal Kaziorc930f742014-01-23 11:38:25 +0100511 struct cfg80211_chan_def *chandef = &ar->chandef;
512 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300513 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300514 int ret = 0;
515
516 lockdep_assert_held(&ar->conf_mutex);
517
Kalle Valo5e3dd152013-06-12 20:52:10 +0300518 arg.vdev_id = vdev_id;
519 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100520 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300521
522 /* TODO setup this dynamically, what in case we
523 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100524 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200525 arg.channel.chan_radar =
526 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300527
Michal Kazior89c5c842013-10-23 04:02:13 -0700528 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700529 arg.channel.max_power = channel->max_power * 2;
530 arg.channel.max_reg_power = channel->max_reg_power * 2;
531 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300532
533 ret = ath10k_wmi_vdev_start(ar, &arg);
534 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200535 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200536 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300537 return ret;
538 }
539
540 ret = ath10k_vdev_setup_sync(ar);
541 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200542 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200543 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300544 return ret;
545 }
546
547 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
548 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200549 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200550 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300551 goto vdev_stop;
552 }
553
554 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300555
Michal Kazior7aa7a722014-08-25 12:09:38 +0200556 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300557 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300558 return 0;
559
560vdev_stop:
561 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
562 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200563 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200564 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300565
566 return ret;
567}
568
Michal Kazior1bbc0972014-04-08 09:45:47 +0300569static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300570{
571 int ret = 0;
572
573 lockdep_assert_held(&ar->conf_mutex);
574
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200575 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
576 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200577 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200578 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300579
580 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
581 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200582 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200583 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584
585 ret = ath10k_vdev_setup_sync(ar);
586 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200587 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200588 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300589
Michal Kazior7aa7a722014-08-25 12:09:38 +0200590 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300591 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300592 return ret;
593}
594
Michal Kazior1bbc0972014-04-08 09:45:47 +0300595static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300596{
597 int bit, ret = 0;
598
599 lockdep_assert_held(&ar->conf_mutex);
600
Ben Greeara9aefb32014-08-12 11:02:19 +0300601 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200602 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300603 return -ENOMEM;
604 }
605
Ben Greeara9aefb32014-08-12 11:02:19 +0300606 bit = ffs(ar->free_vdev_map);
607
Kalle Valo5e3dd152013-06-12 20:52:10 +0300608 ar->monitor_vdev_id = bit - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300609
610 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
611 WMI_VDEV_TYPE_MONITOR,
612 0, ar->mac_addr);
613 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200614 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200615 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300616 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300617 }
618
Ben Greeara9aefb32014-08-12 11:02:19 +0300619 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200620 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300621 ar->monitor_vdev_id);
622
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300624}
625
Michal Kazior1bbc0972014-04-08 09:45:47 +0300626static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627{
628 int ret = 0;
629
630 lockdep_assert_held(&ar->conf_mutex);
631
Kalle Valo5e3dd152013-06-12 20:52:10 +0300632 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
633 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200634 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200635 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300636 return ret;
637 }
638
Ben Greeara9aefb32014-08-12 11:02:19 +0300639 ar->free_vdev_map |= 1 << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300640
Michal Kazior7aa7a722014-08-25 12:09:38 +0200641 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300642 ar->monitor_vdev_id);
643 return ret;
644}
645
Michal Kazior1bbc0972014-04-08 09:45:47 +0300646static int ath10k_monitor_start(struct ath10k *ar)
647{
648 int ret;
649
650 lockdep_assert_held(&ar->conf_mutex);
651
652 if (!ath10k_monitor_is_enabled(ar)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200653 ath10k_warn(ar, "trying to start monitor with no references\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300654 return 0;
655 }
656
657 if (ar->monitor_started) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200658 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor already started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300659 return 0;
660 }
661
662 ret = ath10k_monitor_vdev_create(ar);
663 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200664 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300665 return ret;
666 }
667
668 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
669 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200670 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300671 ath10k_monitor_vdev_delete(ar);
672 return ret;
673 }
674
675 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200676 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300677
678 return 0;
679}
680
681static void ath10k_monitor_stop(struct ath10k *ar)
682{
683 int ret;
684
685 lockdep_assert_held(&ar->conf_mutex);
686
687 if (ath10k_monitor_is_enabled(ar)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200688 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior1bbc0972014-04-08 09:45:47 +0300689 "mac monitor will be stopped later\n");
690 return;
691 }
692
693 if (!ar->monitor_started) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200694 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior1bbc0972014-04-08 09:45:47 +0300695 "mac monitor probably failed to start earlier\n");
696 return;
697 }
698
699 ret = ath10k_monitor_vdev_stop(ar);
700 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200701 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300702
703 ret = ath10k_monitor_vdev_delete(ar);
704 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200705 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300706
707 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200708 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300709}
710
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200711static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
712{
713 struct ath10k *ar = arvif->ar;
714 u32 vdev_param, rts_cts = 0;
715
716 lockdep_assert_held(&ar->conf_mutex);
717
718 vdev_param = ar->wmi.vdev_param->enable_rtscts;
719
720 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
721 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
722
723 if (arvif->num_legacy_stations > 0)
724 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
725 WMI_RTSCTS_PROFILE);
726
727 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
728 rts_cts);
729}
730
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200731static int ath10k_start_cac(struct ath10k *ar)
732{
733 int ret;
734
735 lockdep_assert_held(&ar->conf_mutex);
736
737 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
738
Michal Kazior1bbc0972014-04-08 09:45:47 +0300739 ret = ath10k_monitor_start(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200740 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200741 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200742 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
743 return ret;
744 }
745
Michal Kazior7aa7a722014-08-25 12:09:38 +0200746 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200747 ar->monitor_vdev_id);
748
749 return 0;
750}
751
752static int ath10k_stop_cac(struct ath10k *ar)
753{
754 lockdep_assert_held(&ar->conf_mutex);
755
756 /* CAC is not running - do nothing */
757 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
758 return 0;
759
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200760 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300761 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200762
Michal Kazior7aa7a722014-08-25 12:09:38 +0200763 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200764
765 return 0;
766}
767
Michal Kaziord6500972014-04-08 09:56:09 +0300768static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200769{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200770 int ret;
771
772 lockdep_assert_held(&ar->conf_mutex);
773
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200774 ath10k_stop_cac(ar);
775
Michal Kaziord6500972014-04-08 09:56:09 +0300776 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200777 return;
778
Michal Kaziord6500972014-04-08 09:56:09 +0300779 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200780 return;
781
782 ret = ath10k_start_cac(ar);
783 if (ret) {
784 /*
785 * Not possible to start CAC on current channel so starting
786 * radiation is not allowed, make this channel DFS_UNAVAILABLE
787 * by indicating that radar was detected.
788 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200789 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200790 ieee80211_radar_detected(ar->hw);
791 }
792}
793
Michal Kaziordc55e302014-07-29 12:53:36 +0300794static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300795{
796 struct ath10k *ar = arvif->ar;
797 struct cfg80211_chan_def *chandef = &ar->chandef;
798 struct wmi_vdev_start_request_arg arg = {};
799 int ret = 0;
800
801 lockdep_assert_held(&ar->conf_mutex);
802
803 reinit_completion(&ar->vdev_setup_done);
804
805 arg.vdev_id = arvif->vdev_id;
806 arg.dtim_period = arvif->dtim_period;
807 arg.bcn_intval = arvif->beacon_interval;
808
809 arg.channel.freq = chandef->chan->center_freq;
810 arg.channel.band_center_freq1 = chandef->center_freq1;
811 arg.channel.mode = chan_to_phymode(chandef);
812
813 arg.channel.min_power = 0;
814 arg.channel.max_power = chandef->chan->max_power * 2;
815 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
816 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
817
818 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
819 arg.ssid = arvif->u.ap.ssid;
820 arg.ssid_len = arvif->u.ap.ssid_len;
821 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
822
823 /* For now allow DFS for AP mode */
824 arg.channel.chan_radar =
825 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
826 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
827 arg.ssid = arvif->vif->bss_conf.ssid;
828 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
829 }
830
Michal Kazior7aa7a722014-08-25 12:09:38 +0200831 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300832 "mac vdev %d start center_freq %d phymode %s\n",
833 arg.vdev_id, arg.channel.freq,
834 ath10k_wmi_phymode_str(arg.channel.mode));
835
Michal Kaziordc55e302014-07-29 12:53:36 +0300836 if (restart)
837 ret = ath10k_wmi_vdev_restart(ar, &arg);
838 else
839 ret = ath10k_wmi_vdev_start(ar, &arg);
840
Michal Kazior72654fa2014-04-08 09:56:09 +0300841 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200842 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300843 arg.vdev_id, ret);
844 return ret;
845 }
846
847 ret = ath10k_vdev_setup_sync(ar);
848 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200849 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300850 arg.vdev_id, ret);
851 return ret;
852 }
853
Michal Kaziord6500972014-04-08 09:56:09 +0300854 ar->num_started_vdevs++;
855 ath10k_recalc_radar_detection(ar);
856
Michal Kazior72654fa2014-04-08 09:56:09 +0300857 return ret;
858}
859
Michal Kaziordc55e302014-07-29 12:53:36 +0300860static int ath10k_vdev_start(struct ath10k_vif *arvif)
861{
862 return ath10k_vdev_start_restart(arvif, false);
863}
864
865static int ath10k_vdev_restart(struct ath10k_vif *arvif)
866{
867 return ath10k_vdev_start_restart(arvif, true);
868}
869
Michal Kazior72654fa2014-04-08 09:56:09 +0300870static int ath10k_vdev_stop(struct ath10k_vif *arvif)
871{
872 struct ath10k *ar = arvif->ar;
873 int ret;
874
875 lockdep_assert_held(&ar->conf_mutex);
876
877 reinit_completion(&ar->vdev_setup_done);
878
879 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
880 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200881 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300882 arvif->vdev_id, ret);
883 return ret;
884 }
885
886 ret = ath10k_vdev_setup_sync(ar);
887 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200888 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300889 arvif->vdev_id, ret);
890 return ret;
891 }
892
Michal Kaziord6500972014-04-08 09:56:09 +0300893 WARN_ON(ar->num_started_vdevs == 0);
894
895 if (ar->num_started_vdevs != 0) {
896 ar->num_started_vdevs--;
897 ath10k_recalc_radar_detection(ar);
898 }
899
Michal Kazior72654fa2014-04-08 09:56:09 +0300900 return ret;
901}
902
Kalle Valo5e3dd152013-06-12 20:52:10 +0300903static void ath10k_control_beaconing(struct ath10k_vif *arvif,
904 struct ieee80211_bss_conf *info)
905{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200906 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907 int ret = 0;
908
Michal Kazior548db542013-07-05 16:15:15 +0300909 lockdep_assert_held(&arvif->ar->conf_mutex);
910
Kalle Valo5e3dd152013-06-12 20:52:10 +0300911 if (!info->enable_beacon) {
912 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100913
914 arvif->is_started = false;
915 arvif->is_up = false;
916
Michal Kazior748afc42014-01-23 12:48:21 +0100917 spin_lock_bh(&arvif->ar->data_lock);
918 if (arvif->beacon) {
Michal Kazior767d34f2014-02-27 18:50:03 +0200919 dma_unmap_single(arvif->ar->dev,
920 ATH10K_SKB_CB(arvif->beacon)->paddr,
921 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kazior748afc42014-01-23 12:48:21 +0100922 dev_kfree_skb_any(arvif->beacon);
923
924 arvif->beacon = NULL;
925 arvif->beacon_sent = false;
926 }
927 spin_unlock_bh(&arvif->ar->data_lock);
928
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929 return;
930 }
931
932 arvif->tx_seq_no = 0x1000;
933
934 ret = ath10k_vdev_start(arvif);
935 if (ret)
936 return;
937
Michal Kaziorc930f742014-01-23 11:38:25 +0100938 arvif->aid = 0;
939 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
940
941 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
942 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300943 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200944 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200945 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100946 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300947 return;
948 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100949
950 arvif->is_started = true;
951 arvif->is_up = true;
952
Michal Kazior7aa7a722014-08-25 12:09:38 +0200953 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300954}
955
956static void ath10k_control_ibss(struct ath10k_vif *arvif,
957 struct ieee80211_bss_conf *info,
958 const u8 self_peer[ETH_ALEN])
959{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200961 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300962 int ret = 0;
963
Michal Kazior548db542013-07-05 16:15:15 +0300964 lockdep_assert_held(&arvif->ar->conf_mutex);
965
Kalle Valo5e3dd152013-06-12 20:52:10 +0300966 if (!info->ibss_joined) {
967 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
968 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200969 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300970 self_peer, arvif->vdev_id, ret);
971
Michal Kaziorc930f742014-01-23 11:38:25 +0100972 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300973 return;
974
975 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100976 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300977 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200978 ath10k_warn(ar, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100979 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980 return;
981 }
982
Michal Kaziorc930f742014-01-23 11:38:25 +0100983 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300984
985 return;
986 }
987
988 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
989 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200990 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 self_peer, arvif->vdev_id, ret);
992 return;
993 }
994
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200995 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
996 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300997 ATH10K_DEFAULT_ATIM);
998 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200999 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001000 arvif->vdev_id, ret);
1001}
1002
1003/*
1004 * Review this when mac80211 gains per-interface powersave support.
1005 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001006static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001007{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001008 struct ath10k *ar = arvif->ar;
1009 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001010 enum wmi_sta_powersave_param param;
1011 enum wmi_sta_ps_mode psmode;
1012 int ret;
1013
Michal Kazior548db542013-07-05 16:15:15 +03001014 lockdep_assert_held(&arvif->ar->conf_mutex);
1015
Michal Kaziorad088bf2013-10-16 15:44:46 +03001016 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1017 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018
1019 if (conf->flags & IEEE80211_CONF_PS) {
1020 psmode = WMI_STA_PS_MODE_ENABLED;
1021 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1022
Michal Kaziorad088bf2013-10-16 15:44:46 +03001023 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001024 conf->dynamic_ps_timeout);
1025 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001026 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001027 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001028 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001029 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001030 } else {
1031 psmode = WMI_STA_PS_MODE_DISABLED;
1032 }
1033
Michal Kazior7aa7a722014-08-25 12:09:38 +02001034 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001035 arvif->vdev_id, psmode ? "enable" : "disable");
1036
Michal Kaziorad088bf2013-10-16 15:44:46 +03001037 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1038 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001039 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001040 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001041 return ret;
1042 }
1043
1044 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001045}
1046
1047/**********************/
1048/* Station management */
1049/**********************/
1050
1051static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1052 struct ath10k_vif *arvif,
1053 struct ieee80211_sta *sta,
1054 struct ieee80211_bss_conf *bss_conf,
1055 struct wmi_peer_assoc_complete_arg *arg)
1056{
Michal Kazior548db542013-07-05 16:15:15 +03001057 lockdep_assert_held(&ar->conf_mutex);
1058
Kalle Valo5e3dd152013-06-12 20:52:10 +03001059 memcpy(arg->addr, sta->addr, ETH_ALEN);
1060 arg->vdev_id = arvif->vdev_id;
1061 arg->peer_aid = sta->aid;
1062 arg->peer_flags |= WMI_PEER_AUTH;
1063
1064 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1065 /*
1066 * Seems FW have problems with Power Save in STA
1067 * mode when we setup this parameter to high (eg. 5).
1068 * Often we see that FW don't send NULL (with clean P flags)
1069 * frame even there is info about buffered frames in beacons.
1070 * Sometimes we have to wait more than 10 seconds before FW
1071 * will wakeup. Often sending one ping from AP to our device
1072 * just fail (more than 50%).
1073 *
1074 * Seems setting this FW parameter to 1 couse FW
1075 * will check every beacon and will wakup immediately
1076 * after detection buffered data.
1077 */
1078 arg->peer_listen_intval = 1;
1079 else
1080 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1081
1082 arg->peer_num_spatial_streams = 1;
1083
1084 /*
1085 * The assoc capabilities are available only in managed mode.
1086 */
1087 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1088 arg->peer_caps = bss_conf->assoc_capability;
1089}
1090
1091static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1092 struct ath10k_vif *arvif,
1093 struct wmi_peer_assoc_complete_arg *arg)
1094{
1095 struct ieee80211_vif *vif = arvif->vif;
1096 struct ieee80211_bss_conf *info = &vif->bss_conf;
1097 struct cfg80211_bss *bss;
1098 const u8 *rsnie = NULL;
1099 const u8 *wpaie = NULL;
1100
Michal Kazior548db542013-07-05 16:15:15 +03001101 lockdep_assert_held(&ar->conf_mutex);
1102
Kalle Valo5e3dd152013-06-12 20:52:10 +03001103 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1104 info->bssid, NULL, 0, 0, 0);
1105 if (bss) {
1106 const struct cfg80211_bss_ies *ies;
1107
1108 rcu_read_lock();
1109 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1110
1111 ies = rcu_dereference(bss->ies);
1112
1113 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1114 WLAN_OUI_TYPE_MICROSOFT_WPA,
1115 ies->data,
1116 ies->len);
1117 rcu_read_unlock();
1118 cfg80211_put_bss(ar->hw->wiphy, bss);
1119 }
1120
1121 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1122 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001123 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001124 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1125 }
1126
1127 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001128 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001129 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1130 }
1131}
1132
1133static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1134 struct ieee80211_sta *sta,
1135 struct wmi_peer_assoc_complete_arg *arg)
1136{
1137 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1138 const struct ieee80211_supported_band *sband;
1139 const struct ieee80211_rate *rates;
1140 u32 ratemask;
1141 int i;
1142
Michal Kazior548db542013-07-05 16:15:15 +03001143 lockdep_assert_held(&ar->conf_mutex);
1144
Kalle Valo5e3dd152013-06-12 20:52:10 +03001145 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1146 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1147 rates = sband->bitrates;
1148
1149 rateset->num_rates = 0;
1150
1151 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1152 if (!(ratemask & 1))
1153 continue;
1154
1155 rateset->rates[rateset->num_rates] = rates->hw_value;
1156 rateset->num_rates++;
1157 }
1158}
1159
1160static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1161 struct ieee80211_sta *sta,
1162 struct wmi_peer_assoc_complete_arg *arg)
1163{
1164 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001165 int i, n;
1166
Michal Kazior548db542013-07-05 16:15:15 +03001167 lockdep_assert_held(&ar->conf_mutex);
1168
Kalle Valo5e3dd152013-06-12 20:52:10 +03001169 if (!ht_cap->ht_supported)
1170 return;
1171
1172 arg->peer_flags |= WMI_PEER_HT;
1173 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1174 ht_cap->ampdu_factor)) - 1;
1175
1176 arg->peer_mpdu_density =
1177 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1178
1179 arg->peer_ht_caps = ht_cap->cap;
1180 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1181
1182 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1183 arg->peer_flags |= WMI_PEER_LDPC;
1184
1185 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1186 arg->peer_flags |= WMI_PEER_40MHZ;
1187 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1188 }
1189
1190 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1191 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1192
1193 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1194 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1195
1196 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1197 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1198 arg->peer_flags |= WMI_PEER_STBC;
1199 }
1200
1201 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1202 u32 stbc;
1203 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1204 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1205 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1206 arg->peer_rate_caps |= stbc;
1207 arg->peer_flags |= WMI_PEER_STBC;
1208 }
1209
Kalle Valo5e3dd152013-06-12 20:52:10 +03001210 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1211 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1212 else if (ht_cap->mcs.rx_mask[1])
1213 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1214
1215 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1216 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1217 arg->peer_ht_rates.rates[n++] = i;
1218
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001219 /*
1220 * This is a workaround for HT-enabled STAs which break the spec
1221 * and have no HT capabilities RX mask (no HT RX MCS map).
1222 *
1223 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1224 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1225 *
1226 * Firmware asserts if such situation occurs.
1227 */
1228 if (n == 0) {
1229 arg->peer_ht_rates.num_rates = 8;
1230 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1231 arg->peer_ht_rates.rates[i] = i;
1232 } else {
1233 arg->peer_ht_rates.num_rates = n;
1234 arg->peer_num_spatial_streams = sta->rx_nss;
1235 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001236
Michal Kazior7aa7a722014-08-25 12:09:38 +02001237 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001238 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001239 arg->peer_ht_rates.num_rates,
1240 arg->peer_num_spatial_streams);
1241}
1242
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001243static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1244 struct ath10k_vif *arvif,
1245 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001246{
1247 u32 uapsd = 0;
1248 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001249 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001250
Michal Kazior548db542013-07-05 16:15:15 +03001251 lockdep_assert_held(&ar->conf_mutex);
1252
Kalle Valo5e3dd152013-06-12 20:52:10 +03001253 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001254 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001255 sta->uapsd_queues, sta->max_sp);
1256
Kalle Valo5e3dd152013-06-12 20:52:10 +03001257 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1258 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1259 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1260 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1261 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1262 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1263 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1264 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1265 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1266 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1267 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1268 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1269
1270
1271 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1272 max_sp = sta->max_sp;
1273
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001274 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1275 sta->addr,
1276 WMI_AP_PS_PEER_PARAM_UAPSD,
1277 uapsd);
1278 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001279 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001280 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001281 return ret;
1282 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001283
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001284 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1285 sta->addr,
1286 WMI_AP_PS_PEER_PARAM_MAX_SP,
1287 max_sp);
1288 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001289 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001290 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001291 return ret;
1292 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001293
1294 /* TODO setup this based on STA listen interval and
1295 beacon interval. Currently we don't know
1296 sta->listen_interval - mac80211 patch required.
1297 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001298 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1299 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1300 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001301 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001302 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001303 return ret;
1304 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001305 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001306
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001307 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001308}
1309
1310static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1311 struct ieee80211_sta *sta,
1312 struct wmi_peer_assoc_complete_arg *arg)
1313{
1314 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001315 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001316
1317 if (!vht_cap->vht_supported)
1318 return;
1319
1320 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001321 arg->peer_vht_caps = vht_cap->cap;
1322
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001323
1324 ampdu_factor = (vht_cap->cap &
1325 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1326 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1327
1328 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1329 * zero in VHT IE. Using it would result in degraded throughput.
1330 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1331 * it if VHT max_mpdu is smaller. */
1332 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1333 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1334 ampdu_factor)) - 1);
1335
Kalle Valo5e3dd152013-06-12 20:52:10 +03001336 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1337 arg->peer_flags |= WMI_PEER_80MHZ;
1338
1339 arg->peer_vht_rates.rx_max_rate =
1340 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1341 arg->peer_vht_rates.rx_mcs_set =
1342 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1343 arg->peer_vht_rates.tx_max_rate =
1344 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1345 arg->peer_vht_rates.tx_mcs_set =
1346 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1347
Michal Kazior7aa7a722014-08-25 12:09:38 +02001348 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001349 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001350}
1351
1352static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1353 struct ath10k_vif *arvif,
1354 struct ieee80211_sta *sta,
1355 struct ieee80211_bss_conf *bss_conf,
1356 struct wmi_peer_assoc_complete_arg *arg)
1357{
1358 switch (arvif->vdev_type) {
1359 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001360 if (sta->wme)
1361 arg->peer_flags |= WMI_PEER_QOS;
1362
1363 if (sta->wme && sta->uapsd_queues) {
1364 arg->peer_flags |= WMI_PEER_APSD;
1365 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1366 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367 break;
1368 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001369 if (bss_conf->qos)
1370 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371 break;
1372 default:
1373 break;
1374 }
1375}
1376
1377static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1378 struct ath10k_vif *arvif,
1379 struct ieee80211_sta *sta,
1380 struct wmi_peer_assoc_complete_arg *arg)
1381{
1382 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1383
Kalle Valo5e3dd152013-06-12 20:52:10 +03001384 switch (ar->hw->conf.chandef.chan->band) {
1385 case IEEE80211_BAND_2GHZ:
1386 if (sta->ht_cap.ht_supported) {
1387 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1388 phymode = MODE_11NG_HT40;
1389 else
1390 phymode = MODE_11NG_HT20;
1391 } else {
1392 phymode = MODE_11G;
1393 }
1394
1395 break;
1396 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001397 /*
1398 * Check VHT first.
1399 */
1400 if (sta->vht_cap.vht_supported) {
1401 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1402 phymode = MODE_11AC_VHT80;
1403 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1404 phymode = MODE_11AC_VHT40;
1405 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1406 phymode = MODE_11AC_VHT20;
1407 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001408 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1409 phymode = MODE_11NA_HT40;
1410 else
1411 phymode = MODE_11NA_HT20;
1412 } else {
1413 phymode = MODE_11A;
1414 }
1415
1416 break;
1417 default:
1418 break;
1419 }
1420
Michal Kazior7aa7a722014-08-25 12:09:38 +02001421 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001422 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001423
Kalle Valo5e3dd152013-06-12 20:52:10 +03001424 arg->peer_phymode = phymode;
1425 WARN_ON(phymode == MODE_UNKNOWN);
1426}
1427
Kalle Valob9ada652013-10-16 15:44:46 +03001428static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1429 struct ath10k_vif *arvif,
1430 struct ieee80211_sta *sta,
1431 struct ieee80211_bss_conf *bss_conf,
1432 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001433{
Michal Kazior548db542013-07-05 16:15:15 +03001434 lockdep_assert_held(&ar->conf_mutex);
1435
Kalle Valob9ada652013-10-16 15:44:46 +03001436 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001437
Kalle Valob9ada652013-10-16 15:44:46 +03001438 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1439 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1440 ath10k_peer_assoc_h_rates(ar, sta, arg);
1441 ath10k_peer_assoc_h_ht(ar, sta, arg);
1442 ath10k_peer_assoc_h_vht(ar, sta, arg);
1443 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1444 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001445
Kalle Valob9ada652013-10-16 15:44:46 +03001446 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001447}
1448
Michal Kazior90046f52014-02-14 14:45:51 +01001449static const u32 ath10k_smps_map[] = {
1450 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1451 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1452 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1453 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1454};
1455
1456static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1457 const u8 *addr,
1458 const struct ieee80211_sta_ht_cap *ht_cap)
1459{
1460 int smps;
1461
1462 if (!ht_cap->ht_supported)
1463 return 0;
1464
1465 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1466 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1467
1468 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1469 return -EINVAL;
1470
1471 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1472 WMI_PEER_SMPS_STATE,
1473 ath10k_smps_map[smps]);
1474}
1475
Kalle Valo5e3dd152013-06-12 20:52:10 +03001476/* can be called only in mac80211 callbacks due to `key_count` usage */
1477static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1478 struct ieee80211_vif *vif,
1479 struct ieee80211_bss_conf *bss_conf)
1480{
1481 struct ath10k *ar = hw->priv;
1482 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001483 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001484 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001485 struct ieee80211_sta *ap_sta;
1486 int ret;
1487
Michal Kazior548db542013-07-05 16:15:15 +03001488 lockdep_assert_held(&ar->conf_mutex);
1489
Kalle Valo5e3dd152013-06-12 20:52:10 +03001490 rcu_read_lock();
1491
1492 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1493 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001494 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001495 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001496 rcu_read_unlock();
1497 return;
1498 }
1499
Michal Kazior90046f52014-02-14 14:45:51 +01001500 /* ap_sta must be accessed only within rcu section which must be left
1501 * before calling ath10k_setup_peer_smps() which might sleep. */
1502 ht_cap = ap_sta->ht_cap;
1503
Kalle Valob9ada652013-10-16 15:44:46 +03001504 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1505 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001507 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001508 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001509 rcu_read_unlock();
1510 return;
1511 }
1512
1513 rcu_read_unlock();
1514
Kalle Valob9ada652013-10-16 15:44:46 +03001515 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001517 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001518 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001519 return;
1520 }
1521
Michal Kazior90046f52014-02-14 14:45:51 +01001522 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1523 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001524 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001525 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001526 return;
1527 }
1528
Michal Kazior7aa7a722014-08-25 12:09:38 +02001529 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001530 "mac vdev %d up (associated) bssid %pM aid %d\n",
1531 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1532
Michal Kaziorc930f742014-01-23 11:38:25 +01001533 arvif->aid = bss_conf->aid;
1534 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1535
1536 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1537 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001538 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001539 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001540 return;
1541 }
1542
1543 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001544}
1545
1546/*
1547 * FIXME: flush TIDs
1548 */
1549static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1550 struct ieee80211_vif *vif)
1551{
1552 struct ath10k *ar = hw->priv;
1553 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1554 int ret;
1555
Michal Kazior548db542013-07-05 16:15:15 +03001556 lockdep_assert_held(&ar->conf_mutex);
1557
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558 /*
1559 * For some reason, calling VDEV-DOWN before VDEV-STOP
1560 * makes the FW to send frames via HTT after disassociation.
1561 * No idea why this happens, even though VDEV-DOWN is supposed
1562 * to be analogous to link down, so just stop the VDEV.
1563 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001564 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001565 arvif->vdev_id);
1566
1567 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001568 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001569
1570 /*
1571 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1572 * report beacons from previously associated network through HTT.
1573 * This in turn would spam mac80211 WARN_ON if we bring down all
1574 * interfaces as it expects there is no rx when no interface is
1575 * running.
1576 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001578
1579 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001580 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001582 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001583
1584 arvif->is_started = false;
1585 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586}
1587
1588static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001589 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590{
Kalle Valob9ada652013-10-16 15:44:46 +03001591 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592 int ret = 0;
1593
Michal Kazior548db542013-07-05 16:15:15 +03001594 lockdep_assert_held(&ar->conf_mutex);
1595
Kalle Valob9ada652013-10-16 15:44:46 +03001596 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001597 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001598 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001599 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001600 return ret;
1601 }
1602
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001603 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001604 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001606 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001607 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 return ret;
1609 }
1610
Michal Kazior90046f52014-02-14 14:45:51 +01001611 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1612 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001613 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001614 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001615 return ret;
1616 }
1617
Michal Kaziora4841eb2014-08-28 09:59:39 +02001618 if (!sta->wme && !reassoc) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001619 arvif->num_legacy_stations++;
1620 ret = ath10k_recalc_rtscts_prot(arvif);
1621 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001622 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001623 arvif->vdev_id, ret);
1624 return ret;
1625 }
1626 }
1627
Kalle Valo5e3dd152013-06-12 20:52:10 +03001628 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1629 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001630 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001631 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001632 return ret;
1633 }
1634
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001635 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001637 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001638 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001639 return ret;
1640 }
1641
Kalle Valo5e3dd152013-06-12 20:52:10 +03001642 return ret;
1643}
1644
1645static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1646 struct ieee80211_sta *sta)
1647{
1648 int ret = 0;
1649
Michal Kazior548db542013-07-05 16:15:15 +03001650 lockdep_assert_held(&ar->conf_mutex);
1651
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001652 if (!sta->wme) {
1653 arvif->num_legacy_stations--;
1654 ret = ath10k_recalc_rtscts_prot(arvif);
1655 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001656 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001657 arvif->vdev_id, ret);
1658 return ret;
1659 }
1660 }
1661
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1663 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001664 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001665 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001666 return ret;
1667 }
1668
1669 return ret;
1670}
1671
1672/**************/
1673/* Regulatory */
1674/**************/
1675
1676static int ath10k_update_channel_list(struct ath10k *ar)
1677{
1678 struct ieee80211_hw *hw = ar->hw;
1679 struct ieee80211_supported_band **bands;
1680 enum ieee80211_band band;
1681 struct ieee80211_channel *channel;
1682 struct wmi_scan_chan_list_arg arg = {0};
1683 struct wmi_channel_arg *ch;
1684 bool passive;
1685 int len;
1686 int ret;
1687 int i;
1688
Michal Kazior548db542013-07-05 16:15:15 +03001689 lockdep_assert_held(&ar->conf_mutex);
1690
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 bands = hw->wiphy->bands;
1692 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1693 if (!bands[band])
1694 continue;
1695
1696 for (i = 0; i < bands[band]->n_channels; i++) {
1697 if (bands[band]->channels[i].flags &
1698 IEEE80211_CHAN_DISABLED)
1699 continue;
1700
1701 arg.n_channels++;
1702 }
1703 }
1704
1705 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1706 arg.channels = kzalloc(len, GFP_KERNEL);
1707 if (!arg.channels)
1708 return -ENOMEM;
1709
1710 ch = arg.channels;
1711 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1712 if (!bands[band])
1713 continue;
1714
1715 for (i = 0; i < bands[band]->n_channels; i++) {
1716 channel = &bands[band]->channels[i];
1717
1718 if (channel->flags & IEEE80211_CHAN_DISABLED)
1719 continue;
1720
1721 ch->allow_ht = true;
1722
1723 /* FIXME: when should we really allow VHT? */
1724 ch->allow_vht = true;
1725
1726 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001727 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001728
1729 ch->ht40plus =
1730 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1731
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001732 ch->chan_radar =
1733 !!(channel->flags & IEEE80211_CHAN_RADAR);
1734
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001735 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 ch->passive = passive;
1737
1738 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001739 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001740 ch->max_power = channel->max_power * 2;
1741 ch->max_reg_power = channel->max_reg_power * 2;
1742 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743 ch->reg_class_id = 0; /* FIXME */
1744
1745 /* FIXME: why use only legacy modes, why not any
1746 * HT/VHT modes? Would that even make any
1747 * difference? */
1748 if (channel->band == IEEE80211_BAND_2GHZ)
1749 ch->mode = MODE_11G;
1750 else
1751 ch->mode = MODE_11A;
1752
1753 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1754 continue;
1755
Michal Kazior7aa7a722014-08-25 12:09:38 +02001756 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001757 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1758 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759 ch->freq, ch->max_power, ch->max_reg_power,
1760 ch->max_antenna_gain, ch->mode);
1761
1762 ch++;
1763 }
1764 }
1765
1766 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1767 kfree(arg.channels);
1768
1769 return ret;
1770}
1771
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001772static enum wmi_dfs_region
1773ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1774{
1775 switch (dfs_region) {
1776 case NL80211_DFS_UNSET:
1777 return WMI_UNINIT_DFS_DOMAIN;
1778 case NL80211_DFS_FCC:
1779 return WMI_FCC_DFS_DOMAIN;
1780 case NL80211_DFS_ETSI:
1781 return WMI_ETSI_DFS_DOMAIN;
1782 case NL80211_DFS_JP:
1783 return WMI_MKK4_DFS_DOMAIN;
1784 }
1785 return WMI_UNINIT_DFS_DOMAIN;
1786}
1787
Michal Kaziorf7843d72013-07-16 09:38:52 +02001788static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001791 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001792 enum wmi_dfs_region wmi_dfs_reg;
1793 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001794
Michal Kaziorf7843d72013-07-16 09:38:52 +02001795 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001796
1797 ret = ath10k_update_channel_list(ar);
1798 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001799 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001800
1801 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001802
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001803 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1804 nl_dfs_reg = ar->dfs_detector->region;
1805 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1806 } else {
1807 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1808 }
1809
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810 /* Target allows setting up per-band regdomain but ath_common provides
1811 * a combined one only */
1812 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001813 regpair->reg_domain,
1814 regpair->reg_domain, /* 2ghz */
1815 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001816 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001817 regpair->reg_5ghz_ctl,
1818 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001820 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001821}
Michal Kazior548db542013-07-05 16:15:15 +03001822
Michal Kaziorf7843d72013-07-16 09:38:52 +02001823static void ath10k_reg_notifier(struct wiphy *wiphy,
1824 struct regulatory_request *request)
1825{
1826 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1827 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001828 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001829
1830 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1831
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001832 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001833 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001834 request->dfs_region);
1835 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1836 request->dfs_region);
1837 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001838 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001839 request->dfs_region);
1840 }
1841
Michal Kaziorf7843d72013-07-16 09:38:52 +02001842 mutex_lock(&ar->conf_mutex);
1843 if (ar->state == ATH10K_STATE_ON)
1844 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001845 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001846}
1847
1848/***************/
1849/* TX handlers */
1850/***************/
1851
Michal Kazior42c3aa62013-10-02 11:03:38 +02001852static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1853{
1854 if (ieee80211_is_mgmt(hdr->frame_control))
1855 return HTT_DATA_TX_EXT_TID_MGMT;
1856
1857 if (!ieee80211_is_data_qos(hdr->frame_control))
1858 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1859
1860 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1861 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1862
1863 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1864}
1865
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001866static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1867 struct ieee80211_tx_info *info)
1868{
1869 if (info->control.vif)
1870 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1871
Michal Kazior1bbc0972014-04-08 09:45:47 +03001872 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001873 return ar->monitor_vdev_id;
1874
Michal Kazior7aa7a722014-08-25 12:09:38 +02001875 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001876 return 0;
1877}
1878
Michal Kazior4b604552014-07-21 21:03:09 +03001879/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1880 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001881 */
Michal Kazior4b604552014-07-21 21:03:09 +03001882static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001883{
1884 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001885 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001886 u8 *qos_ctl;
1887
1888 if (!ieee80211_is_data_qos(hdr->frame_control))
1889 return;
1890
1891 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001892 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1893 skb->data, (void *)qos_ctl - (void *)skb->data);
1894 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001895
1896 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1897 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1898 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1899 * it is safe to downgrade to NullFunc.
1900 */
1901 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1902 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1903 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1904 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001905}
1906
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001907static void ath10k_tx_wep_key_work(struct work_struct *work)
1908{
1909 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1910 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001911 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001912 int ret, keyidx = arvif->def_wep_key_newidx;
1913
Michal Kazior911e6c02014-05-26 12:46:03 +03001914 mutex_lock(&arvif->ar->conf_mutex);
1915
1916 if (arvif->ar->state != ATH10K_STATE_ON)
1917 goto unlock;
1918
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001919 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001920 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001921
Michal Kazior7aa7a722014-08-25 12:09:38 +02001922 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001923 arvif->vdev_id, keyidx);
1924
1925 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1926 arvif->vdev_id,
1927 arvif->ar->wmi.vdev_param->def_keyid,
1928 keyidx);
1929 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001930 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001931 arvif->vdev_id,
1932 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001933 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001934 }
1935
1936 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001937
1938unlock:
1939 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001940}
1941
Michal Kazior4b604552014-07-21 21:03:09 +03001942static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1943 struct ieee80211_key_conf *key,
1944 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1947 struct ath10k *ar = arvif->ar;
1948 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 if (!ieee80211_has_protected(hdr->frame_control))
1951 return;
1952
1953 if (!key)
1954 return;
1955
1956 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1957 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1958 return;
1959
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001960 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001961 return;
1962
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001963 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1964 * queueing frames until key index is updated is not an option because
1965 * sk_buff may need more processing to be done, e.g. offchannel */
1966 arvif->def_wep_key_newidx = key->keyidx;
1967 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968}
1969
Michal Kazior4b604552014-07-21 21:03:09 +03001970static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1971 struct ieee80211_vif *vif,
1972 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001973{
1974 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001975 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1976
1977 /* This is case only for P2P_GO */
1978 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1979 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1980 return;
1981
1982 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1983 spin_lock_bh(&ar->data_lock);
1984 if (arvif->u.ap.noa_data)
1985 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1986 GFP_ATOMIC))
1987 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1988 arvif->u.ap.noa_data,
1989 arvif->u.ap.noa_len);
1990 spin_unlock_bh(&ar->data_lock);
1991 }
1992}
1993
1994static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1995{
1996 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001997 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998
Michal Kazior961d4c32013-08-09 10:13:34 +02001999 if (ar->htt.target_version_major >= 3) {
2000 /* Since HTT 3.0 there is no separate mgmt tx command */
2001 ret = ath10k_htt_tx(&ar->htt, skb);
2002 goto exit;
2003 }
2004
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002005 if (ieee80211_is_mgmt(hdr->frame_control)) {
2006 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2007 ar->fw_features)) {
2008 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2009 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002010 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002011 ret = -EBUSY;
2012 goto exit;
2013 }
2014
2015 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2016 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2017 } else {
2018 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2019 }
2020 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2021 ar->fw_features) &&
2022 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023 /* FW does not report tx status properly for NullFunc frames
2024 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002025 * those frames when it detects link/beacon loss and depends
2026 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002027 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002028 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002029 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002030 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002031
Michal Kazior961d4c32013-08-09 10:13:34 +02002032exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002033 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002034 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2035 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 ieee80211_free_txskb(ar->hw, skb);
2037 }
2038}
2039
2040void ath10k_offchan_tx_purge(struct ath10k *ar)
2041{
2042 struct sk_buff *skb;
2043
2044 for (;;) {
2045 skb = skb_dequeue(&ar->offchan_tx_queue);
2046 if (!skb)
2047 break;
2048
2049 ieee80211_free_txskb(ar->hw, skb);
2050 }
2051}
2052
2053void ath10k_offchan_tx_work(struct work_struct *work)
2054{
2055 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2056 struct ath10k_peer *peer;
2057 struct ieee80211_hdr *hdr;
2058 struct sk_buff *skb;
2059 const u8 *peer_addr;
2060 int vdev_id;
2061 int ret;
2062
2063 /* FW requirement: We must create a peer before FW will send out
2064 * an offchannel frame. Otherwise the frame will be stuck and
2065 * never transmitted. We delete the peer upon tx completion.
2066 * It is unlikely that a peer for offchannel tx will already be
2067 * present. However it may be in some rare cases so account for that.
2068 * Otherwise we might remove a legitimate peer and break stuff. */
2069
2070 for (;;) {
2071 skb = skb_dequeue(&ar->offchan_tx_queue);
2072 if (!skb)
2073 break;
2074
2075 mutex_lock(&ar->conf_mutex);
2076
Michal Kazior7aa7a722014-08-25 12:09:38 +02002077 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002078 skb);
2079
2080 hdr = (struct ieee80211_hdr *)skb->data;
2081 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002082 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083
2084 spin_lock_bh(&ar->data_lock);
2085 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2086 spin_unlock_bh(&ar->data_lock);
2087
2088 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002089 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002090 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 peer_addr, vdev_id);
2092
2093 if (!peer) {
2094 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2095 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002096 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002097 peer_addr, vdev_id, ret);
2098 }
2099
2100 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002101 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002102 ar->offchan_tx_skb = skb;
2103 spin_unlock_bh(&ar->data_lock);
2104
2105 ath10k_tx_htt(ar, skb);
2106
2107 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2108 3 * HZ);
2109 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002110 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111 skb);
2112
2113 if (!peer) {
2114 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2115 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002116 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 peer_addr, vdev_id, ret);
2118 }
2119
2120 mutex_unlock(&ar->conf_mutex);
2121 }
2122}
2123
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002124void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2125{
2126 struct sk_buff *skb;
2127
2128 for (;;) {
2129 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2130 if (!skb)
2131 break;
2132
2133 ieee80211_free_txskb(ar->hw, skb);
2134 }
2135}
2136
2137void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2138{
2139 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2140 struct sk_buff *skb;
2141 int ret;
2142
2143 for (;;) {
2144 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2145 if (!skb)
2146 break;
2147
2148 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002149 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002150 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002151 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002152 ieee80211_free_txskb(ar->hw, skb);
2153 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002154 }
2155}
2156
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157/************/
2158/* Scanning */
2159/************/
2160
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002161void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002163 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002164
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002165 switch (ar->scan.state) {
2166 case ATH10K_SCAN_IDLE:
2167 break;
2168 case ATH10K_SCAN_RUNNING:
2169 case ATH10K_SCAN_ABORTING:
2170 if (ar->scan.is_roc)
2171 ieee80211_remain_on_channel_expired(ar->hw);
2172 else
2173 ieee80211_scan_completed(ar->hw,
2174 (ar->scan.state ==
2175 ATH10K_SCAN_ABORTING));
2176 /* fall through */
2177 case ATH10K_SCAN_STARTING:
2178 ar->scan.state = ATH10K_SCAN_IDLE;
2179 ar->scan_channel = NULL;
2180 ath10k_offchan_tx_purge(ar);
2181 cancel_delayed_work(&ar->scan.timeout);
2182 complete_all(&ar->scan.completed);
2183 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002184 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002185}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002187void ath10k_scan_finish(struct ath10k *ar)
2188{
2189 spin_lock_bh(&ar->data_lock);
2190 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002191 spin_unlock_bh(&ar->data_lock);
2192}
2193
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002194static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002195{
2196 struct wmi_stop_scan_arg arg = {
2197 .req_id = 1, /* FIXME */
2198 .req_type = WMI_SCAN_STOP_ONE,
2199 .u.scan_id = ATH10K_SCAN_ID,
2200 };
2201 int ret;
2202
2203 lockdep_assert_held(&ar->conf_mutex);
2204
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205 ret = ath10k_wmi_stop_scan(ar, &arg);
2206 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002207 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002208 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 }
2210
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002212 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002213 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002214 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002215 } else if (ret > 0) {
2216 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002217 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002218
2219out:
2220 /* Scan state should be updated upon scan completion but in case
2221 * firmware fails to deliver the event (for whatever reason) it is
2222 * desired to clean up scan state anyway. Firmware may have just
2223 * dropped the scan completion event delivery due to transport pipe
2224 * being overflown with data and/or it can recover on its own before
2225 * next scan request is submitted.
2226 */
2227 spin_lock_bh(&ar->data_lock);
2228 if (ar->scan.state != ATH10K_SCAN_IDLE)
2229 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002230 spin_unlock_bh(&ar->data_lock);
2231
2232 return ret;
2233}
2234
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002235static void ath10k_scan_abort(struct ath10k *ar)
2236{
2237 int ret;
2238
2239 lockdep_assert_held(&ar->conf_mutex);
2240
2241 spin_lock_bh(&ar->data_lock);
2242
2243 switch (ar->scan.state) {
2244 case ATH10K_SCAN_IDLE:
2245 /* This can happen if timeout worker kicked in and called
2246 * abortion while scan completion was being processed.
2247 */
2248 break;
2249 case ATH10K_SCAN_STARTING:
2250 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002251 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002252 ath10k_scan_state_str(ar->scan.state),
2253 ar->scan.state);
2254 break;
2255 case ATH10K_SCAN_RUNNING:
2256 ar->scan.state = ATH10K_SCAN_ABORTING;
2257 spin_unlock_bh(&ar->data_lock);
2258
2259 ret = ath10k_scan_stop(ar);
2260 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002261 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002262
2263 spin_lock_bh(&ar->data_lock);
2264 break;
2265 }
2266
2267 spin_unlock_bh(&ar->data_lock);
2268}
2269
2270void ath10k_scan_timeout_work(struct work_struct *work)
2271{
2272 struct ath10k *ar = container_of(work, struct ath10k,
2273 scan.timeout.work);
2274
2275 mutex_lock(&ar->conf_mutex);
2276 ath10k_scan_abort(ar);
2277 mutex_unlock(&ar->conf_mutex);
2278}
2279
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280static int ath10k_start_scan(struct ath10k *ar,
2281 const struct wmi_start_scan_arg *arg)
2282{
2283 int ret;
2284
2285 lockdep_assert_held(&ar->conf_mutex);
2286
2287 ret = ath10k_wmi_start_scan(ar, arg);
2288 if (ret)
2289 return ret;
2290
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2292 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002293 ret = ath10k_scan_stop(ar);
2294 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002295 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002296
2297 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002298 }
2299
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002300 /* Add a 200ms margin to account for event/command processing */
2301 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2302 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303 return 0;
2304}
2305
2306/**********************/
2307/* mac80211 callbacks */
2308/**********************/
2309
2310static void ath10k_tx(struct ieee80211_hw *hw,
2311 struct ieee80211_tx_control *control,
2312 struct sk_buff *skb)
2313{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002314 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002315 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2316 struct ieee80211_vif *vif = info->control.vif;
2317 struct ieee80211_key_conf *key = info->control.hw_key;
2318 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319
2320 /* We should disable CCK RATE due to P2P */
2321 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002322 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002323
Michal Kazior4b604552014-07-21 21:03:09 +03002324 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2325 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2326 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002328 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002329 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2330 ath10k_tx_h_nwifi(hw, skb);
2331 ath10k_tx_h_update_wep_key(vif, key, skb);
2332 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2333 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2337 spin_lock_bh(&ar->data_lock);
2338 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002339 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002340 spin_unlock_bh(&ar->data_lock);
2341
Michal Kazior7aa7a722014-08-25 12:09:38 +02002342 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2343 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344
2345 skb_queue_tail(&ar->offchan_tx_queue, skb);
2346 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2347 return;
2348 }
2349
2350 ath10k_tx_htt(ar, skb);
2351}
2352
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002353/* Must not be called with conf_mutex held as workers can use that also. */
2354static void ath10k_drain_tx(struct ath10k *ar)
2355{
2356 /* make sure rcu-protected mac80211 tx path itself is drained */
2357 synchronize_net();
2358
2359 ath10k_offchan_tx_purge(ar);
2360 ath10k_mgmt_over_wmi_tx_purge(ar);
2361
2362 cancel_work_sync(&ar->offchan_tx_work);
2363 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2364}
2365
Michal Kazioraffd3212013-07-16 09:54:35 +02002366void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002367{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002368 struct ath10k_vif *arvif;
2369
Michal Kazior818bdd12013-07-16 09:38:57 +02002370 lockdep_assert_held(&ar->conf_mutex);
2371
Michal Kazior1bbc0972014-04-08 09:45:47 +03002372 if (ath10k_monitor_is_enabled(ar)) {
2373 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2374 ar->promisc = false;
2375 ar->monitor = false;
2376 ath10k_monitor_stop(ar);
2377 }
2378
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002379 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002380 ath10k_peer_cleanup_all(ar);
2381 ath10k_core_stop(ar);
2382 ath10k_hif_power_down(ar);
2383
2384 spin_lock_bh(&ar->data_lock);
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002385 list_for_each_entry(arvif, &ar->arvifs, list) {
2386 if (!arvif->beacon)
2387 continue;
2388
2389 dma_unmap_single(arvif->ar->dev,
2390 ATH10K_SKB_CB(arvif->beacon)->paddr,
2391 arvif->beacon->len, DMA_TO_DEVICE);
2392 dev_kfree_skb_any(arvif->beacon);
2393 arvif->beacon = NULL;
2394 }
Michal Kazior818bdd12013-07-16 09:38:57 +02002395 spin_unlock_bh(&ar->data_lock);
2396}
2397
Ben Greear46acf7b2014-05-16 17:15:38 +03002398static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2399{
2400 struct ath10k *ar = hw->priv;
2401
2402 mutex_lock(&ar->conf_mutex);
2403
2404 if (ar->cfg_tx_chainmask) {
2405 *tx_ant = ar->cfg_tx_chainmask;
2406 *rx_ant = ar->cfg_rx_chainmask;
2407 } else {
2408 *tx_ant = ar->supp_tx_chainmask;
2409 *rx_ant = ar->supp_rx_chainmask;
2410 }
2411
2412 mutex_unlock(&ar->conf_mutex);
2413
2414 return 0;
2415}
2416
2417static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2418{
2419 int ret;
2420
2421 lockdep_assert_held(&ar->conf_mutex);
2422
2423 ar->cfg_tx_chainmask = tx_ant;
2424 ar->cfg_rx_chainmask = rx_ant;
2425
2426 if ((ar->state != ATH10K_STATE_ON) &&
2427 (ar->state != ATH10K_STATE_RESTARTED))
2428 return 0;
2429
2430 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2431 tx_ant);
2432 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002433 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002434 ret, tx_ant);
2435 return ret;
2436 }
2437
2438 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2439 rx_ant);
2440 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002441 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002442 ret, rx_ant);
2443 return ret;
2444 }
2445
2446 return 0;
2447}
2448
2449static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2450{
2451 struct ath10k *ar = hw->priv;
2452 int ret;
2453
2454 mutex_lock(&ar->conf_mutex);
2455 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2456 mutex_unlock(&ar->conf_mutex);
2457 return ret;
2458}
2459
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460static int ath10k_start(struct ieee80211_hw *hw)
2461{
2462 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002463 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002465 /*
2466 * This makes sense only when restarting hw. It is harmless to call
2467 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2468 * commands will be submitted while restarting.
2469 */
2470 ath10k_drain_tx(ar);
2471
Michal Kazior548db542013-07-05 16:15:15 +03002472 mutex_lock(&ar->conf_mutex);
2473
Michal Kaziorc5058f52014-05-26 12:46:03 +03002474 switch (ar->state) {
2475 case ATH10K_STATE_OFF:
2476 ar->state = ATH10K_STATE_ON;
2477 break;
2478 case ATH10K_STATE_RESTARTING:
2479 ath10k_halt(ar);
2480 ar->state = ATH10K_STATE_RESTARTED;
2481 break;
2482 case ATH10K_STATE_ON:
2483 case ATH10K_STATE_RESTARTED:
2484 case ATH10K_STATE_WEDGED:
2485 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002486 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002487 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002488 }
2489
2490 ret = ath10k_hif_power_up(ar);
2491 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002492 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002493 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002494 }
2495
2496 ret = ath10k_core_start(ar);
2497 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002498 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002499 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002500 }
2501
Bartosz Markowski226a3392013-09-26 17:47:16 +02002502 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002503 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002504 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002505 goto err_core_stop;
2506 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002508 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002509 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002510 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002511 goto err_core_stop;
2512 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002513
Ben Greear46acf7b2014-05-16 17:15:38 +03002514 if (ar->cfg_tx_chainmask)
2515 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2516 ar->cfg_rx_chainmask);
2517
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002518 /*
2519 * By default FW set ARP frames ac to voice (6). In that case ARP
2520 * exchange is not working properly for UAPSD enabled AP. ARP requests
2521 * which arrives with access category 0 are processed by network stack
2522 * and send back with access category 0, but FW changes access category
2523 * to 6. Set ARP frames access category to best effort (0) solves
2524 * this problem.
2525 */
2526
2527 ret = ath10k_wmi_pdev_set_param(ar,
2528 ar->wmi.pdev_param->arp_ac_override, 0);
2529 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002530 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002531 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002532 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002533 }
2534
Michal Kaziord6500972014-04-08 09:56:09 +03002535 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002536 ath10k_regd_update(ar);
2537
Simon Wunderlich855aed12014-08-02 09:12:54 +03002538 ath10k_spectral_start(ar);
2539
Michal Kaziorae254432014-05-26 12:46:02 +03002540 mutex_unlock(&ar->conf_mutex);
2541 return 0;
2542
2543err_core_stop:
2544 ath10k_core_stop(ar);
2545
2546err_power_down:
2547 ath10k_hif_power_down(ar);
2548
2549err_off:
2550 ar->state = ATH10K_STATE_OFF;
2551
2552err:
Michal Kazior548db542013-07-05 16:15:15 +03002553 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002554 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002555}
2556
2557static void ath10k_stop(struct ieee80211_hw *hw)
2558{
2559 struct ath10k *ar = hw->priv;
2560
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002561 ath10k_drain_tx(ar);
2562
Michal Kazior548db542013-07-05 16:15:15 +03002563 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002564 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002565 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002566 ar->state = ATH10K_STATE_OFF;
2567 }
Michal Kazior548db542013-07-05 16:15:15 +03002568 mutex_unlock(&ar->conf_mutex);
2569
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002570 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002571 cancel_work_sync(&ar->restart_work);
2572}
2573
Michal Kaziorad088bf2013-10-16 15:44:46 +03002574static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002575{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002576 struct ath10k_vif *arvif;
2577 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002578
2579 lockdep_assert_held(&ar->conf_mutex);
2580
Michal Kaziorad088bf2013-10-16 15:44:46 +03002581 list_for_each_entry(arvif, &ar->arvifs, list) {
2582 ret = ath10k_mac_vif_setup_ps(arvif);
2583 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002584 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002585 break;
2586 }
2587 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002588
Michal Kaziorad088bf2013-10-16 15:44:46 +03002589 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590}
2591
Michal Kaziorc930f742014-01-23 11:38:25 +01002592static const char *chandef_get_width(enum nl80211_chan_width width)
2593{
2594 switch (width) {
2595 case NL80211_CHAN_WIDTH_20_NOHT:
2596 return "20 (noht)";
2597 case NL80211_CHAN_WIDTH_20:
2598 return "20";
2599 case NL80211_CHAN_WIDTH_40:
2600 return "40";
2601 case NL80211_CHAN_WIDTH_80:
2602 return "80";
2603 case NL80211_CHAN_WIDTH_80P80:
2604 return "80+80";
2605 case NL80211_CHAN_WIDTH_160:
2606 return "160";
2607 case NL80211_CHAN_WIDTH_5:
2608 return "5";
2609 case NL80211_CHAN_WIDTH_10:
2610 return "10";
2611 }
2612 return "?";
2613}
2614
2615static void ath10k_config_chan(struct ath10k *ar)
2616{
2617 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002618 int ret;
2619
2620 lockdep_assert_held(&ar->conf_mutex);
2621
Michal Kazior7aa7a722014-08-25 12:09:38 +02002622 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002623 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2624 ar->chandef.chan->center_freq,
2625 ar->chandef.center_freq1,
2626 ar->chandef.center_freq2,
2627 chandef_get_width(ar->chandef.width));
2628
2629 /* First stop monitor interface. Some FW versions crash if there's a
2630 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002631 if (ar->monitor_started)
2632 ath10k_monitor_vdev_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002633
2634 list_for_each_entry(arvif, &ar->arvifs, list) {
2635 if (!arvif->is_started)
2636 continue;
2637
Michal Kaziordc55e302014-07-29 12:53:36 +03002638 if (!arvif->is_up)
2639 continue;
2640
Michal Kaziorc930f742014-01-23 11:38:25 +01002641 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2642 continue;
2643
Michal Kaziordc55e302014-07-29 12:53:36 +03002644 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002645 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002646 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002647 arvif->vdev_id, ret);
2648 continue;
2649 }
2650 }
2651
Michal Kaziordc55e302014-07-29 12:53:36 +03002652 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002653
2654 list_for_each_entry(arvif, &ar->arvifs, list) {
2655 if (!arvif->is_started)
2656 continue;
2657
2658 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2659 continue;
2660
Michal Kaziordc55e302014-07-29 12:53:36 +03002661 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002663 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002664 arvif->vdev_id, ret);
2665 continue;
2666 }
2667
2668 if (!arvif->is_up)
2669 continue;
2670
2671 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2672 arvif->bssid);
2673 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002674 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002675 arvif->vdev_id, ret);
2676 continue;
2677 }
2678 }
2679
Michal Kazior1bbc0972014-04-08 09:45:47 +03002680 if (ath10k_monitor_is_enabled(ar))
2681 ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002682}
2683
Kalle Valo5e3dd152013-06-12 20:52:10 +03002684static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2685{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686 struct ath10k *ar = hw->priv;
2687 struct ieee80211_conf *conf = &hw->conf;
2688 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002689 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690
2691 mutex_lock(&ar->conf_mutex);
2692
2693 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002694 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002695 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002696 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002697 conf->chandef.chan->flags,
2698 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002699
Kalle Valo5e3dd152013-06-12 20:52:10 +03002700 spin_lock_bh(&ar->data_lock);
2701 ar->rx_channel = conf->chandef.chan;
2702 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002703
Michal Kaziord6500972014-04-08 09:56:09 +03002704 ar->radar_enabled = conf->radar_enabled;
2705 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002706
2707 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2708 ar->chandef = conf->chandef;
2709 ath10k_config_chan(ar);
2710 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711 }
2712
Michal Kazior5474efe2013-10-23 04:02:15 -07002713 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002714 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002715 hw->conf.power_level);
2716
2717 param = ar->wmi.pdev_param->txpower_limit2g;
2718 ret = ath10k_wmi_pdev_set_param(ar, param,
2719 hw->conf.power_level * 2);
2720 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002721 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002722 hw->conf.power_level, ret);
2723
2724 param = ar->wmi.pdev_param->txpower_limit5g;
2725 ret = ath10k_wmi_pdev_set_param(ar, param,
2726 hw->conf.power_level * 2);
2727 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002728 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002729 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002730 }
2731
Michal Kazioraffd3212013-07-16 09:54:35 +02002732 if (changed & IEEE80211_CONF_CHANGE_PS)
2733 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002734
2735 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior1bbc0972014-04-08 09:45:47 +03002736 if (conf->flags & IEEE80211_CONF_MONITOR && !ar->monitor) {
2737 ar->monitor = true;
2738 ret = ath10k_monitor_start(ar);
2739 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002740 ath10k_warn(ar, "failed to start monitor (config): %d\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +03002741 ret);
2742 ar->monitor = false;
2743 }
2744 } else if (!(conf->flags & IEEE80211_CONF_MONITOR) &&
2745 ar->monitor) {
2746 ar->monitor = false;
2747 ath10k_monitor_stop(ar);
2748 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002749 }
2750
2751 mutex_unlock(&ar->conf_mutex);
2752 return ret;
2753}
2754
2755/*
2756 * TODO:
2757 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2758 * because we will send mgmt frames without CCK. This requirement
2759 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2760 * in the TX packet.
2761 */
2762static int ath10k_add_interface(struct ieee80211_hw *hw,
2763 struct ieee80211_vif *vif)
2764{
2765 struct ath10k *ar = hw->priv;
2766 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2767 enum wmi_sta_powersave_param param;
2768 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002769 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002770 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002771 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002772
2773 mutex_lock(&ar->conf_mutex);
2774
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002775 memset(arvif, 0, sizeof(*arvif));
2776
Kalle Valo5e3dd152013-06-12 20:52:10 +03002777 arvif->ar = ar;
2778 arvif->vif = vif;
2779
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002780 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002781 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002782
Ben Greeara9aefb32014-08-12 11:02:19 +03002783 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002784 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002785 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002786 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002787 }
Ben Greeara9aefb32014-08-12 11:02:19 +03002788 bit = ffs(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002789
2790 arvif->vdev_id = bit - 1;
2791 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002792
2793 if (ar->p2p)
2794 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2795
2796 switch (vif->type) {
2797 case NL80211_IFTYPE_UNSPECIFIED:
2798 case NL80211_IFTYPE_STATION:
2799 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2800 if (vif->p2p)
2801 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2802 break;
2803 case NL80211_IFTYPE_ADHOC:
2804 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2805 break;
2806 case NL80211_IFTYPE_AP:
2807 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2808
2809 if (vif->p2p)
2810 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2811 break;
2812 case NL80211_IFTYPE_MONITOR:
2813 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2814 break;
2815 default:
2816 WARN_ON(1);
2817 break;
2818 }
2819
Michal Kazior7aa7a722014-08-25 12:09:38 +02002820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002821 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2822
2823 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2824 arvif->vdev_subtype, vif->addr);
2825 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002826 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002827 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002828 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002829 }
2830
Ben Greeara9aefb32014-08-12 11:02:19 +03002831 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002832 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002833
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002834 vdev_param = ar->wmi.vdev_param->def_keyid;
2835 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002836 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002837 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002838 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002839 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002840 goto err_vdev_delete;
2841 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002842
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002843 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2844 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002845 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002846 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002847 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002848 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002849 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002850 goto err_vdev_delete;
2851 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002852
2853 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2854 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2855 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002856 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002857 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002858 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002860
Kalle Valo5a13e762014-01-20 11:01:46 +02002861 ret = ath10k_mac_set_kickout(arvif);
2862 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002863 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002864 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002865 goto err_peer_delete;
2866 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002867 }
2868
2869 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2870 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2871 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2872 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2873 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002874 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002875 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002876 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002877 goto err_peer_delete;
2878 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002879
2880 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2881 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2882 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2883 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002884 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002885 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002886 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002887 goto err_peer_delete;
2888 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889
2890 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2891 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2892 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2893 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002894 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002895 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002896 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002897 goto err_peer_delete;
2898 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002899 }
2900
Michal Kazior424121c2013-07-22 14:13:31 +02002901 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002903 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002904 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002905 goto err_peer_delete;
2906 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002907
Michal Kazior424121c2013-07-22 14:13:31 +02002908 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002909 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002910 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002911 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002912 goto err_peer_delete;
2913 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002914
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002916 return 0;
2917
2918err_peer_delete:
2919 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2920 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2921
2922err_vdev_delete:
2923 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greeara9aefb32014-08-12 11:02:19 +03002924 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002925 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002926
2927err:
2928 mutex_unlock(&ar->conf_mutex);
2929
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930 return ret;
2931}
2932
2933static void ath10k_remove_interface(struct ieee80211_hw *hw,
2934 struct ieee80211_vif *vif)
2935{
2936 struct ath10k *ar = hw->priv;
2937 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2938 int ret;
2939
2940 mutex_lock(&ar->conf_mutex);
2941
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002942 cancel_work_sync(&arvif->wep_key_work);
2943
Michal Kaziored543882013-09-13 14:16:56 +02002944 spin_lock_bh(&ar->data_lock);
2945 if (arvif->beacon) {
Michal Kaziorec6bc552014-04-23 19:30:05 +03002946 dma_unmap_single(arvif->ar->dev,
2947 ATH10K_SKB_CB(arvif->beacon)->paddr,
2948 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02002949 dev_kfree_skb_any(arvif->beacon);
2950 arvif->beacon = NULL;
2951 }
Simon Wunderlich855aed12014-08-02 09:12:54 +03002952
Michal Kaziored543882013-09-13 14:16:56 +02002953 spin_unlock_bh(&ar->data_lock);
2954
Simon Wunderlich855aed12014-08-02 09:12:54 +03002955 ret = ath10k_spectral_vif_stop(arvif);
2956 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002957 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03002958 arvif->vdev_id, ret);
2959
Ben Greeara9aefb32014-08-12 11:02:19 +03002960 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002961 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002962
2963 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2964 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2965 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002966 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002967 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002968
2969 kfree(arvif->u.ap.noa_data);
2970 }
2971
Michal Kazior7aa7a722014-08-25 12:09:38 +02002972 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002973 arvif->vdev_id);
2974
Kalle Valo5e3dd152013-06-12 20:52:10 +03002975 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2976 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002977 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002978 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002979
Kalle Valo5e3dd152013-06-12 20:52:10 +03002980 ath10k_peer_cleanup(ar, arvif->vdev_id);
2981
2982 mutex_unlock(&ar->conf_mutex);
2983}
2984
2985/*
2986 * FIXME: Has to be verified.
2987 */
2988#define SUPPORTED_FILTERS \
2989 (FIF_PROMISC_IN_BSS | \
2990 FIF_ALLMULTI | \
2991 FIF_CONTROL | \
2992 FIF_PSPOLL | \
2993 FIF_OTHER_BSS | \
2994 FIF_BCN_PRBRESP_PROMISC | \
2995 FIF_PROBE_REQ | \
2996 FIF_FCSFAIL)
2997
2998static void ath10k_configure_filter(struct ieee80211_hw *hw,
2999 unsigned int changed_flags,
3000 unsigned int *total_flags,
3001 u64 multicast)
3002{
3003 struct ath10k *ar = hw->priv;
3004 int ret;
3005
3006 mutex_lock(&ar->conf_mutex);
3007
3008 changed_flags &= SUPPORTED_FILTERS;
3009 *total_flags &= SUPPORTED_FILTERS;
3010 ar->filter_flags = *total_flags;
3011
Michal Kazior1bbc0972014-04-08 09:45:47 +03003012 if (ar->filter_flags & FIF_PROMISC_IN_BSS && !ar->promisc) {
3013 ar->promisc = true;
3014 ret = ath10k_monitor_start(ar);
3015 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003016 ath10k_warn(ar, "failed to start monitor (promisc): %d\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +03003017 ret);
3018 ar->promisc = false;
3019 }
3020 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && ar->promisc) {
3021 ar->promisc = false;
3022 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003023 }
3024
3025 mutex_unlock(&ar->conf_mutex);
3026}
3027
3028static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3029 struct ieee80211_vif *vif,
3030 struct ieee80211_bss_conf *info,
3031 u32 changed)
3032{
3033 struct ath10k *ar = hw->priv;
3034 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3035 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02003036 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003037
3038 mutex_lock(&ar->conf_mutex);
3039
3040 if (changed & BSS_CHANGED_IBSS)
3041 ath10k_control_ibss(arvif, info, vif->addr);
3042
3043 if (changed & BSS_CHANGED_BEACON_INT) {
3044 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003045 vdev_param = ar->wmi.vdev_param->beacon_interval;
3046 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003048 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003049 "mac vdev %d beacon_interval %d\n",
3050 arvif->vdev_id, arvif->beacon_interval);
3051
Kalle Valo5e3dd152013-06-12 20:52:10 +03003052 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003053 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003054 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003055 }
3056
3057 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003059 "vdev %d set beacon tx mode to staggered\n",
3060 arvif->vdev_id);
3061
Bartosz Markowski226a3392013-09-26 17:47:16 +02003062 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3063 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003064 WMI_BEACON_STAGGERED_MODE);
3065 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003066 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003067 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003068 }
3069
John W. Linvilleb70727e2013-06-13 13:34:29 -04003070 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003071 arvif->dtim_period = info->dtim_period;
3072
Michal Kazior7aa7a722014-08-25 12:09:38 +02003073 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003074 "mac vdev %d dtim_period %d\n",
3075 arvif->vdev_id, arvif->dtim_period);
3076
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003077 vdev_param = ar->wmi.vdev_param->dtim_period;
3078 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003079 arvif->dtim_period);
3080 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003081 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003082 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003083 }
3084
3085 if (changed & BSS_CHANGED_SSID &&
3086 vif->type == NL80211_IFTYPE_AP) {
3087 arvif->u.ap.ssid_len = info->ssid_len;
3088 if (info->ssid_len)
3089 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3090 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3091 }
3092
Michal Kazior7b161a72014-05-26 12:46:03 +03003093 /*
3094 * Firmware manages AP self-peer internally so make sure to not create
3095 * it in driver. Otherwise AP self-peer deletion may timeout later.
3096 */
3097 if (changed & BSS_CHANGED_BSSID &&
3098 vif->type != NL80211_IFTYPE_AP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 if (!is_zero_ether_addr(info->bssid)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003100 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003101 "mac vdev %d create peer %pM\n",
3102 arvif->vdev_id, info->bssid);
3103
Kalle Valo5e3dd152013-06-12 20:52:10 +03003104 ret = ath10k_peer_create(ar, arvif->vdev_id,
3105 info->bssid);
3106 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003107 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003108 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003109
3110 if (vif->type == NL80211_IFTYPE_STATION) {
3111 /*
3112 * this is never erased as we it for crypto key
3113 * clearing; this is FW requirement
3114 */
Michal Kaziorc930f742014-01-23 11:38:25 +01003115 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116
Michal Kazior7aa7a722014-08-25 12:09:38 +02003117 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003118 "mac vdev %d start %pM\n",
3119 arvif->vdev_id, info->bssid);
3120
Kalle Valo5e3dd152013-06-12 20:52:10 +03003121 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003122 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003123 ath10k_warn(ar, "failed to start vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003124 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02003125 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01003126 }
3127
3128 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 }
3130
3131 /*
3132 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3133 * so driver need to store it. It is needed when leaving
3134 * IBSS in order to remove BSSID peer.
3135 */
3136 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01003137 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003138 ETH_ALEN);
3139 }
3140 }
3141
3142 if (changed & BSS_CHANGED_BEACON_ENABLED)
3143 ath10k_control_beaconing(arvif, info);
3144
3145 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003146 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003147 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003148 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003149
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003150 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003151 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003152 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003153 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003154 }
3155
3156 if (changed & BSS_CHANGED_ERP_SLOT) {
3157 u32 slottime;
3158 if (info->use_short_slot)
3159 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3160
3161 else
3162 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3163
Michal Kazior7aa7a722014-08-25 12:09:38 +02003164 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003165 arvif->vdev_id, slottime);
3166
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003167 vdev_param = ar->wmi.vdev_param->slot_time;
3168 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169 slottime);
3170 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003171 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003172 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003173 }
3174
3175 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3176 u32 preamble;
3177 if (info->use_short_preamble)
3178 preamble = WMI_VDEV_PREAMBLE_SHORT;
3179 else
3180 preamble = WMI_VDEV_PREAMBLE_LONG;
3181
Michal Kazior7aa7a722014-08-25 12:09:38 +02003182 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003183 "mac vdev %d preamble %dn",
3184 arvif->vdev_id, preamble);
3185
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003186 vdev_param = ar->wmi.vdev_param->preamble;
3187 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003188 preamble);
3189 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003190 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003191 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003192 }
3193
3194 if (changed & BSS_CHANGED_ASSOC) {
3195 if (info->assoc)
3196 ath10k_bss_assoc(hw, vif, info);
3197 }
3198
Kalle Valo75459e32014-02-13 18:13:12 +02003199exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003200 mutex_unlock(&ar->conf_mutex);
3201}
3202
3203static int ath10k_hw_scan(struct ieee80211_hw *hw,
3204 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003205 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003206{
3207 struct ath10k *ar = hw->priv;
3208 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003209 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210 struct wmi_start_scan_arg arg;
3211 int ret = 0;
3212 int i;
3213
3214 mutex_lock(&ar->conf_mutex);
3215
3216 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003217 switch (ar->scan.state) {
3218 case ATH10K_SCAN_IDLE:
3219 reinit_completion(&ar->scan.started);
3220 reinit_completion(&ar->scan.completed);
3221 ar->scan.state = ATH10K_SCAN_STARTING;
3222 ar->scan.is_roc = false;
3223 ar->scan.vdev_id = arvif->vdev_id;
3224 ret = 0;
3225 break;
3226 case ATH10K_SCAN_STARTING:
3227 case ATH10K_SCAN_RUNNING:
3228 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003229 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003230 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003231 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003232 spin_unlock_bh(&ar->data_lock);
3233
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003234 if (ret)
3235 goto exit;
3236
Kalle Valo5e3dd152013-06-12 20:52:10 +03003237 memset(&arg, 0, sizeof(arg));
3238 ath10k_wmi_start_scan_init(ar, &arg);
3239 arg.vdev_id = arvif->vdev_id;
3240 arg.scan_id = ATH10K_SCAN_ID;
3241
3242 if (!req->no_cck)
3243 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3244
3245 if (req->ie_len) {
3246 arg.ie_len = req->ie_len;
3247 memcpy(arg.ie, req->ie, arg.ie_len);
3248 }
3249
3250 if (req->n_ssids) {
3251 arg.n_ssids = req->n_ssids;
3252 for (i = 0; i < arg.n_ssids; i++) {
3253 arg.ssids[i].len = req->ssids[i].ssid_len;
3254 arg.ssids[i].ssid = req->ssids[i].ssid;
3255 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003256 } else {
3257 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003258 }
3259
3260 if (req->n_channels) {
3261 arg.n_channels = req->n_channels;
3262 for (i = 0; i < arg.n_channels; i++)
3263 arg.channels[i] = req->channels[i]->center_freq;
3264 }
3265
3266 ret = ath10k_start_scan(ar, &arg);
3267 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003268 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003269 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003270 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 spin_unlock_bh(&ar->data_lock);
3272 }
3273
3274exit:
3275 mutex_unlock(&ar->conf_mutex);
3276 return ret;
3277}
3278
3279static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3280 struct ieee80211_vif *vif)
3281{
3282 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003283
3284 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003285 cancel_delayed_work_sync(&ar->scan.timeout);
3286 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003287 mutex_unlock(&ar->conf_mutex);
3288}
3289
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003290static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3291 struct ath10k_vif *arvif,
3292 enum set_key_cmd cmd,
3293 struct ieee80211_key_conf *key)
3294{
3295 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3296 int ret;
3297
3298 /* 10.1 firmware branch requires default key index to be set to group
3299 * key index after installing it. Otherwise FW/HW Txes corrupted
3300 * frames with multi-vif APs. This is not required for main firmware
3301 * branch (e.g. 636).
3302 *
3303 * FIXME: This has been tested only in AP. It remains unknown if this
3304 * is required for multi-vif STA interfaces on 10.1 */
3305
3306 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3307 return;
3308
3309 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3310 return;
3311
3312 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3313 return;
3314
3315 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3316 return;
3317
3318 if (cmd != SET_KEY)
3319 return;
3320
3321 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3322 key->keyidx);
3323 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003324 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003325 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003326}
3327
Kalle Valo5e3dd152013-06-12 20:52:10 +03003328static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3329 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3330 struct ieee80211_key_conf *key)
3331{
3332 struct ath10k *ar = hw->priv;
3333 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3334 struct ath10k_peer *peer;
3335 const u8 *peer_addr;
3336 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3337 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3338 int ret = 0;
3339
3340 if (key->keyidx > WMI_MAX_KEY_INDEX)
3341 return -ENOSPC;
3342
3343 mutex_lock(&ar->conf_mutex);
3344
3345 if (sta)
3346 peer_addr = sta->addr;
3347 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3348 peer_addr = vif->bss_conf.bssid;
3349 else
3350 peer_addr = vif->addr;
3351
3352 key->hw_key_idx = key->keyidx;
3353
3354 /* the peer should not disappear in mid-way (unless FW goes awry) since
3355 * we already hold conf_mutex. we just make sure its there now. */
3356 spin_lock_bh(&ar->data_lock);
3357 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3358 spin_unlock_bh(&ar->data_lock);
3359
3360 if (!peer) {
3361 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003362 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003363 peer_addr);
3364 ret = -EOPNOTSUPP;
3365 goto exit;
3366 } else {
3367 /* if the peer doesn't exist there is no key to disable
3368 * anymore */
3369 goto exit;
3370 }
3371 }
3372
3373 if (is_wep) {
3374 if (cmd == SET_KEY)
3375 arvif->wep_keys[key->keyidx] = key;
3376 else
3377 arvif->wep_keys[key->keyidx] = NULL;
3378
3379 if (cmd == DISABLE_KEY)
3380 ath10k_clear_vdev_key(arvif, key);
3381 }
3382
3383 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3384 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003385 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003386 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003387 goto exit;
3388 }
3389
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003390 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3391
Kalle Valo5e3dd152013-06-12 20:52:10 +03003392 spin_lock_bh(&ar->data_lock);
3393 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3394 if (peer && cmd == SET_KEY)
3395 peer->keys[key->keyidx] = key;
3396 else if (peer && cmd == DISABLE_KEY)
3397 peer->keys[key->keyidx] = NULL;
3398 else if (peer == NULL)
3399 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003400 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401 spin_unlock_bh(&ar->data_lock);
3402
3403exit:
3404 mutex_unlock(&ar->conf_mutex);
3405 return ret;
3406}
3407
Michal Kazior9797feb2014-02-14 14:49:48 +01003408static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3409{
3410 struct ath10k *ar;
3411 struct ath10k_vif *arvif;
3412 struct ath10k_sta *arsta;
3413 struct ieee80211_sta *sta;
3414 u32 changed, bw, nss, smps;
3415 int err;
3416
3417 arsta = container_of(wk, struct ath10k_sta, update_wk);
3418 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3419 arvif = arsta->arvif;
3420 ar = arvif->ar;
3421
3422 spin_lock_bh(&ar->data_lock);
3423
3424 changed = arsta->changed;
3425 arsta->changed = 0;
3426
3427 bw = arsta->bw;
3428 nss = arsta->nss;
3429 smps = arsta->smps;
3430
3431 spin_unlock_bh(&ar->data_lock);
3432
3433 mutex_lock(&ar->conf_mutex);
3434
3435 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003436 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003437 sta->addr, bw);
3438
3439 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3440 WMI_PEER_CHAN_WIDTH, bw);
3441 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003442 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003443 sta->addr, bw, err);
3444 }
3445
3446 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003447 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003448 sta->addr, nss);
3449
3450 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3451 WMI_PEER_NSS, nss);
3452 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003453 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003454 sta->addr, nss, err);
3455 }
3456
3457 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003458 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003459 sta->addr, smps);
3460
3461 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3462 WMI_PEER_SMPS_STATE, smps);
3463 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003464 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003465 sta->addr, smps, err);
3466 }
3467
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003468 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003469 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003470 sta->addr);
3471
3472 err = ath10k_station_assoc(ar, arvif, sta, true);
3473 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003474 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003475 sta->addr);
3476 }
3477
Michal Kazior9797feb2014-02-14 14:49:48 +01003478 mutex_unlock(&ar->conf_mutex);
3479}
3480
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481static int ath10k_sta_state(struct ieee80211_hw *hw,
3482 struct ieee80211_vif *vif,
3483 struct ieee80211_sta *sta,
3484 enum ieee80211_sta_state old_state,
3485 enum ieee80211_sta_state new_state)
3486{
3487 struct ath10k *ar = hw->priv;
3488 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003489 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003490 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003491 int ret = 0;
3492
Michal Kazior76f90022014-02-25 09:29:57 +02003493 if (old_state == IEEE80211_STA_NOTEXIST &&
3494 new_state == IEEE80211_STA_NONE) {
3495 memset(arsta, 0, sizeof(*arsta));
3496 arsta->arvif = arvif;
3497 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3498 }
3499
Michal Kazior9797feb2014-02-14 14:49:48 +01003500 /* cancel must be done outside the mutex to avoid deadlock */
3501 if ((old_state == IEEE80211_STA_NONE &&
3502 new_state == IEEE80211_STA_NOTEXIST))
3503 cancel_work_sync(&arsta->update_wk);
3504
Kalle Valo5e3dd152013-06-12 20:52:10 +03003505 mutex_lock(&ar->conf_mutex);
3506
3507 if (old_state == IEEE80211_STA_NOTEXIST &&
3508 new_state == IEEE80211_STA_NONE &&
3509 vif->type != NL80211_IFTYPE_STATION) {
3510 /*
3511 * New station addition.
3512 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003513 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3514 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3515 else
3516 max_num_peers = TARGET_NUM_PEERS;
3517
3518 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003519 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003520 ar->num_peers, max_num_peers);
3521 ret = -ENOBUFS;
3522 goto exit;
3523 }
3524
Michal Kazior7aa7a722014-08-25 12:09:38 +02003525 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003526 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3527 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003528
Kalle Valo5e3dd152013-06-12 20:52:10 +03003529 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3530 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003531 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003532 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003533 } else if ((old_state == IEEE80211_STA_NONE &&
3534 new_state == IEEE80211_STA_NOTEXIST)) {
3535 /*
3536 * Existing station deletion.
3537 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003538 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003539 "mac vdev %d peer delete %pM (sta gone)\n",
3540 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3542 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003543 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003544 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003545
3546 if (vif->type == NL80211_IFTYPE_STATION)
3547 ath10k_bss_disassoc(hw, vif);
3548 } else if (old_state == IEEE80211_STA_AUTH &&
3549 new_state == IEEE80211_STA_ASSOC &&
3550 (vif->type == NL80211_IFTYPE_AP ||
3551 vif->type == NL80211_IFTYPE_ADHOC)) {
3552 /*
3553 * New association.
3554 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003555 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003556 sta->addr);
3557
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003558 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003559 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003560 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003561 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 } else if (old_state == IEEE80211_STA_ASSOC &&
3563 new_state == IEEE80211_STA_AUTH &&
3564 (vif->type == NL80211_IFTYPE_AP ||
3565 vif->type == NL80211_IFTYPE_ADHOC)) {
3566 /*
3567 * Disassociation.
3568 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003569 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003570 sta->addr);
3571
Kalle Valo5e3dd152013-06-12 20:52:10 +03003572 ret = ath10k_station_disassoc(ar, arvif, sta);
3573 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003574 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003575 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003577exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003578 mutex_unlock(&ar->conf_mutex);
3579 return ret;
3580}
3581
3582static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3583 u16 ac, bool enable)
3584{
3585 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3586 u32 value = 0;
3587 int ret = 0;
3588
Michal Kazior548db542013-07-05 16:15:15 +03003589 lockdep_assert_held(&ar->conf_mutex);
3590
Kalle Valo5e3dd152013-06-12 20:52:10 +03003591 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3592 return 0;
3593
3594 switch (ac) {
3595 case IEEE80211_AC_VO:
3596 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3597 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3598 break;
3599 case IEEE80211_AC_VI:
3600 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3601 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3602 break;
3603 case IEEE80211_AC_BE:
3604 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3605 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3606 break;
3607 case IEEE80211_AC_BK:
3608 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3609 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3610 break;
3611 }
3612
3613 if (enable)
3614 arvif->u.sta.uapsd |= value;
3615 else
3616 arvif->u.sta.uapsd &= ~value;
3617
3618 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3619 WMI_STA_PS_PARAM_UAPSD,
3620 arvif->u.sta.uapsd);
3621 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003622 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003623 goto exit;
3624 }
3625
3626 if (arvif->u.sta.uapsd)
3627 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3628 else
3629 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3630
3631 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3632 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3633 value);
3634 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003635 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003636
3637exit:
3638 return ret;
3639}
3640
3641static int ath10k_conf_tx(struct ieee80211_hw *hw,
3642 struct ieee80211_vif *vif, u16 ac,
3643 const struct ieee80211_tx_queue_params *params)
3644{
3645 struct ath10k *ar = hw->priv;
3646 struct wmi_wmm_params_arg *p = NULL;
3647 int ret;
3648
3649 mutex_lock(&ar->conf_mutex);
3650
3651 switch (ac) {
3652 case IEEE80211_AC_VO:
3653 p = &ar->wmm_params.ac_vo;
3654 break;
3655 case IEEE80211_AC_VI:
3656 p = &ar->wmm_params.ac_vi;
3657 break;
3658 case IEEE80211_AC_BE:
3659 p = &ar->wmm_params.ac_be;
3660 break;
3661 case IEEE80211_AC_BK:
3662 p = &ar->wmm_params.ac_bk;
3663 break;
3664 }
3665
3666 if (WARN_ON(!p)) {
3667 ret = -EINVAL;
3668 goto exit;
3669 }
3670
3671 p->cwmin = params->cw_min;
3672 p->cwmax = params->cw_max;
3673 p->aifs = params->aifs;
3674
3675 /*
3676 * The channel time duration programmed in the HW is in absolute
3677 * microseconds, while mac80211 gives the txop in units of
3678 * 32 microseconds.
3679 */
3680 p->txop = params->txop * 32;
3681
3682 /* FIXME: FW accepts wmm params per hw, not per vif */
3683 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3684 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003685 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003686 goto exit;
3687 }
3688
3689 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3690 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003691 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003692
3693exit:
3694 mutex_unlock(&ar->conf_mutex);
3695 return ret;
3696}
3697
3698#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3699
3700static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3701 struct ieee80211_vif *vif,
3702 struct ieee80211_channel *chan,
3703 int duration,
3704 enum ieee80211_roc_type type)
3705{
3706 struct ath10k *ar = hw->priv;
3707 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3708 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003709 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710
3711 mutex_lock(&ar->conf_mutex);
3712
3713 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003714 switch (ar->scan.state) {
3715 case ATH10K_SCAN_IDLE:
3716 reinit_completion(&ar->scan.started);
3717 reinit_completion(&ar->scan.completed);
3718 reinit_completion(&ar->scan.on_channel);
3719 ar->scan.state = ATH10K_SCAN_STARTING;
3720 ar->scan.is_roc = true;
3721 ar->scan.vdev_id = arvif->vdev_id;
3722 ar->scan.roc_freq = chan->center_freq;
3723 ret = 0;
3724 break;
3725 case ATH10K_SCAN_STARTING:
3726 case ATH10K_SCAN_RUNNING:
3727 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003728 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003729 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003730 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731 spin_unlock_bh(&ar->data_lock);
3732
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003733 if (ret)
3734 goto exit;
3735
Kalle Valo5e3dd152013-06-12 20:52:10 +03003736 memset(&arg, 0, sizeof(arg));
3737 ath10k_wmi_start_scan_init(ar, &arg);
3738 arg.vdev_id = arvif->vdev_id;
3739 arg.scan_id = ATH10K_SCAN_ID;
3740 arg.n_channels = 1;
3741 arg.channels[0] = chan->center_freq;
3742 arg.dwell_time_active = duration;
3743 arg.dwell_time_passive = duration;
3744 arg.max_scan_time = 2 * duration;
3745 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3746 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3747
3748 ret = ath10k_start_scan(ar, &arg);
3749 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003750 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003751 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003752 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003753 spin_unlock_bh(&ar->data_lock);
3754 goto exit;
3755 }
3756
3757 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3758 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003759 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003760
3761 ret = ath10k_scan_stop(ar);
3762 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003763 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003764
Kalle Valo5e3dd152013-06-12 20:52:10 +03003765 ret = -ETIMEDOUT;
3766 goto exit;
3767 }
3768
3769 ret = 0;
3770exit:
3771 mutex_unlock(&ar->conf_mutex);
3772 return ret;
3773}
3774
3775static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3776{
3777 struct ath10k *ar = hw->priv;
3778
3779 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003780 cancel_delayed_work_sync(&ar->scan.timeout);
3781 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003782 mutex_unlock(&ar->conf_mutex);
3783
3784 return 0;
3785}
3786
3787/*
3788 * Both RTS and Fragmentation threshold are interface-specific
3789 * in ath10k, but device-specific in mac80211.
3790 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003791
3792static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3793{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003794 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003795 struct ath10k_vif *arvif;
3796 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003797
Michal Kaziorad088bf2013-10-16 15:44:46 +03003798 mutex_lock(&ar->conf_mutex);
3799 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003800 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003801 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003802
Michal Kaziorad088bf2013-10-16 15:44:46 +03003803 ret = ath10k_mac_set_rts(arvif, value);
3804 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003805 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003806 arvif->vdev_id, ret);
3807 break;
3808 }
3809 }
3810 mutex_unlock(&ar->conf_mutex);
3811
3812 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003813}
3814
3815static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3816{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003817 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003818 struct ath10k_vif *arvif;
3819 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003820
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003822 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003824 arvif->vdev_id, value);
3825
3826 ret = ath10k_mac_set_rts(arvif, value);
3827 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003828 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003829 arvif->vdev_id, ret);
3830 break;
3831 }
3832 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003833 mutex_unlock(&ar->conf_mutex);
3834
Michal Kaziorad088bf2013-10-16 15:44:46 +03003835 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003836}
3837
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003838static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3839 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003840{
3841 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003842 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003843 int ret;
3844
3845 /* mac80211 doesn't care if we really xmit queued frames or not
3846 * we'll collect those frames either way if we stop/delete vdevs */
3847 if (drop)
3848 return;
3849
Michal Kazior548db542013-07-05 16:15:15 +03003850 mutex_lock(&ar->conf_mutex);
3851
Michal Kazioraffd3212013-07-16 09:54:35 +02003852 if (ar->state == ATH10K_STATE_WEDGED)
3853 goto skip;
3854
Michal Kazioredb82362013-07-05 16:15:14 +03003855 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003856 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003857
Michal Kazioredb82362013-07-05 16:15:14 +03003858 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003859 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003860 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003861
3862 skip = (ar->state == ATH10K_STATE_WEDGED);
3863
3864 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003865 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003866
3867 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003868 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003869 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003870
Michal Kazioraffd3212013-07-16 09:54:35 +02003871skip:
Michal Kazior548db542013-07-05 16:15:15 +03003872 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003873}
3874
3875/* TODO: Implement this function properly
3876 * For now it is needed to reply to Probe Requests in IBSS mode.
3877 * Propably we need this information from FW.
3878 */
3879static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3880{
3881 return 1;
3882}
3883
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003884#ifdef CONFIG_PM
3885static int ath10k_suspend(struct ieee80211_hw *hw,
3886 struct cfg80211_wowlan *wowlan)
3887{
3888 struct ath10k *ar = hw->priv;
3889 int ret;
3890
Marek Puzyniak9042e172014-02-10 17:14:23 +01003891 mutex_lock(&ar->conf_mutex);
3892
Marek Puzyniak00f54822014-02-10 17:14:24 +01003893 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003894 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003895 if (ret == -ETIMEDOUT)
3896 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003897 ret = 1;
3898 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003899 }
3900
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003901 ret = ath10k_hif_suspend(ar);
3902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003903 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003904 goto resume;
3905 }
3906
Marek Puzyniak9042e172014-02-10 17:14:23 +01003907 ret = 0;
3908 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003909resume:
3910 ret = ath10k_wmi_pdev_resume_target(ar);
3911 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003912 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003913
3914 ret = 1;
3915exit:
3916 mutex_unlock(&ar->conf_mutex);
3917 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003918}
3919
3920static int ath10k_resume(struct ieee80211_hw *hw)
3921{
3922 struct ath10k *ar = hw->priv;
3923 int ret;
3924
Marek Puzyniak9042e172014-02-10 17:14:23 +01003925 mutex_lock(&ar->conf_mutex);
3926
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003927 ret = ath10k_hif_resume(ar);
3928 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003929 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003930 ret = 1;
3931 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003932 }
3933
3934 ret = ath10k_wmi_pdev_resume_target(ar);
3935 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003936 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003937 ret = 1;
3938 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003939 }
3940
Marek Puzyniak9042e172014-02-10 17:14:23 +01003941 ret = 0;
3942exit:
3943 mutex_unlock(&ar->conf_mutex);
3944 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003945}
3946#endif
3947
Michal Kazioraffd3212013-07-16 09:54:35 +02003948static void ath10k_restart_complete(struct ieee80211_hw *hw)
3949{
3950 struct ath10k *ar = hw->priv;
3951
3952 mutex_lock(&ar->conf_mutex);
3953
3954 /* If device failed to restart it will be in a different state, e.g.
3955 * ATH10K_STATE_WEDGED */
3956 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003957 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02003958 ar->state = ATH10K_STATE_ON;
3959 }
3960
3961 mutex_unlock(&ar->conf_mutex);
3962}
3963
Michal Kazior2e1dea42013-07-31 10:32:40 +02003964static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3965 struct survey_info *survey)
3966{
3967 struct ath10k *ar = hw->priv;
3968 struct ieee80211_supported_band *sband;
3969 struct survey_info *ar_survey = &ar->survey[idx];
3970 int ret = 0;
3971
3972 mutex_lock(&ar->conf_mutex);
3973
3974 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3975 if (sband && idx >= sband->n_channels) {
3976 idx -= sband->n_channels;
3977 sband = NULL;
3978 }
3979
3980 if (!sband)
3981 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3982
3983 if (!sband || idx >= sband->n_channels) {
3984 ret = -ENOENT;
3985 goto exit;
3986 }
3987
3988 spin_lock_bh(&ar->data_lock);
3989 memcpy(survey, ar_survey, sizeof(*survey));
3990 spin_unlock_bh(&ar->data_lock);
3991
3992 survey->channel = &sband->channels[idx];
3993
3994exit:
3995 mutex_unlock(&ar->conf_mutex);
3996 return ret;
3997}
3998
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003999/* Helper table for legacy fixed_rate/bitrate_mask */
4000static const u8 cck_ofdm_rate[] = {
4001 /* CCK */
4002 3, /* 1Mbps */
4003 2, /* 2Mbps */
4004 1, /* 5.5Mbps */
4005 0, /* 11Mbps */
4006 /* OFDM */
4007 3, /* 6Mbps */
4008 7, /* 9Mbps */
4009 2, /* 12Mbps */
4010 6, /* 18Mbps */
4011 1, /* 24Mbps */
4012 5, /* 36Mbps */
4013 0, /* 48Mbps */
4014 4, /* 54Mbps */
4015};
4016
4017/* Check if only one bit set */
4018static int ath10k_check_single_mask(u32 mask)
4019{
4020 int bit;
4021
4022 bit = ffs(mask);
4023 if (!bit)
4024 return 0;
4025
4026 mask &= ~BIT(bit - 1);
4027 if (mask)
4028 return 2;
4029
4030 return 1;
4031}
4032
4033static bool
4034ath10k_default_bitrate_mask(struct ath10k *ar,
4035 enum ieee80211_band band,
4036 const struct cfg80211_bitrate_mask *mask)
4037{
4038 u32 legacy = 0x00ff;
4039 u8 ht = 0xff, i;
4040 u16 vht = 0x3ff;
4041
4042 switch (band) {
4043 case IEEE80211_BAND_2GHZ:
4044 legacy = 0x00fff;
4045 vht = 0;
4046 break;
4047 case IEEE80211_BAND_5GHZ:
4048 break;
4049 default:
4050 return false;
4051 }
4052
4053 if (mask->control[band].legacy != legacy)
4054 return false;
4055
4056 for (i = 0; i < ar->num_rf_chains; i++)
4057 if (mask->control[band].ht_mcs[i] != ht)
4058 return false;
4059
4060 for (i = 0; i < ar->num_rf_chains; i++)
4061 if (mask->control[band].vht_mcs[i] != vht)
4062 return false;
4063
4064 return true;
4065}
4066
4067static bool
4068ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4069 enum ieee80211_band band,
4070 u8 *fixed_nss)
4071{
4072 int ht_nss = 0, vht_nss = 0, i;
4073
4074 /* check legacy */
4075 if (ath10k_check_single_mask(mask->control[band].legacy))
4076 return false;
4077
4078 /* check HT */
4079 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4080 if (mask->control[band].ht_mcs[i] == 0xff)
4081 continue;
4082 else if (mask->control[band].ht_mcs[i] == 0x00)
4083 break;
4084 else
4085 return false;
4086 }
4087
4088 ht_nss = i;
4089
4090 /* check VHT */
4091 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4092 if (mask->control[band].vht_mcs[i] == 0x03ff)
4093 continue;
4094 else if (mask->control[band].vht_mcs[i] == 0x0000)
4095 break;
4096 else
4097 return false;
4098 }
4099
4100 vht_nss = i;
4101
4102 if (ht_nss > 0 && vht_nss > 0)
4103 return false;
4104
4105 if (ht_nss)
4106 *fixed_nss = ht_nss;
4107 else if (vht_nss)
4108 *fixed_nss = vht_nss;
4109 else
4110 return false;
4111
4112 return true;
4113}
4114
4115static bool
4116ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4117 enum ieee80211_band band,
4118 enum wmi_rate_preamble *preamble)
4119{
4120 int legacy = 0, ht = 0, vht = 0, i;
4121
4122 *preamble = WMI_RATE_PREAMBLE_OFDM;
4123
4124 /* check legacy */
4125 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4126 if (legacy > 1)
4127 return false;
4128
4129 /* check HT */
4130 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4131 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4132 if (ht > 1)
4133 return false;
4134
4135 /* check VHT */
4136 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4137 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4138 if (vht > 1)
4139 return false;
4140
4141 /* Currently we support only one fixed_rate */
4142 if ((legacy + ht + vht) != 1)
4143 return false;
4144
4145 if (ht)
4146 *preamble = WMI_RATE_PREAMBLE_HT;
4147 else if (vht)
4148 *preamble = WMI_RATE_PREAMBLE_VHT;
4149
4150 return true;
4151}
4152
4153static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004154ath10k_bitrate_mask_rate(struct ath10k *ar,
4155 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004156 enum ieee80211_band band,
4157 u8 *fixed_rate,
4158 u8 *fixed_nss)
4159{
4160 u8 rate = 0, pream = 0, nss = 0, i;
4161 enum wmi_rate_preamble preamble;
4162
4163 /* Check if single rate correct */
4164 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4165 return false;
4166
4167 pream = preamble;
4168
4169 switch (preamble) {
4170 case WMI_RATE_PREAMBLE_CCK:
4171 case WMI_RATE_PREAMBLE_OFDM:
4172 i = ffs(mask->control[band].legacy) - 1;
4173
4174 if (band == IEEE80211_BAND_2GHZ && i < 4)
4175 pream = WMI_RATE_PREAMBLE_CCK;
4176
4177 if (band == IEEE80211_BAND_5GHZ)
4178 i += 4;
4179
4180 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4181 return false;
4182
4183 rate = cck_ofdm_rate[i];
4184 break;
4185 case WMI_RATE_PREAMBLE_HT:
4186 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4187 if (mask->control[band].ht_mcs[i])
4188 break;
4189
4190 if (i == IEEE80211_HT_MCS_MASK_LEN)
4191 return false;
4192
4193 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4194 nss = i;
4195 break;
4196 case WMI_RATE_PREAMBLE_VHT:
4197 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4198 if (mask->control[band].vht_mcs[i])
4199 break;
4200
4201 if (i == NL80211_VHT_NSS_MAX)
4202 return false;
4203
4204 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4205 nss = i;
4206 break;
4207 }
4208
4209 *fixed_nss = nss + 1;
4210 nss <<= 4;
4211 pream <<= 6;
4212
Michal Kazior7aa7a722014-08-25 12:09:38 +02004213 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004214 pream, nss, rate);
4215
4216 *fixed_rate = pream | nss | rate;
4217
4218 return true;
4219}
4220
Michal Kazior7aa7a722014-08-25 12:09:38 +02004221static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4222 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004223 enum ieee80211_band band,
4224 u8 *fixed_rate,
4225 u8 *fixed_nss)
4226{
4227 /* First check full NSS mask, if we can simply limit NSS */
4228 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4229 return true;
4230
4231 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004232 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004233}
4234
4235static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4236 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004237 u8 fixed_nss,
4238 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004239{
4240 struct ath10k *ar = arvif->ar;
4241 u32 vdev_param;
4242 int ret = 0;
4243
4244 mutex_lock(&ar->conf_mutex);
4245
4246 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004247 arvif->fixed_nss == fixed_nss &&
4248 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004249 goto exit;
4250
4251 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004252 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004253
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004254 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004255 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004256
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004257 vdev_param = ar->wmi.vdev_param->fixed_rate;
4258 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4259 vdev_param, fixed_rate);
4260 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004261 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004262 fixed_rate, ret);
4263 ret = -EINVAL;
4264 goto exit;
4265 }
4266
4267 arvif->fixed_rate = fixed_rate;
4268
4269 vdev_param = ar->wmi.vdev_param->nss;
4270 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4271 vdev_param, fixed_nss);
4272
4273 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004274 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004275 fixed_nss, ret);
4276 ret = -EINVAL;
4277 goto exit;
4278 }
4279
4280 arvif->fixed_nss = fixed_nss;
4281
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004282 vdev_param = ar->wmi.vdev_param->sgi;
4283 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4284 force_sgi);
4285
4286 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004287 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004288 force_sgi, ret);
4289 ret = -EINVAL;
4290 goto exit;
4291 }
4292
4293 arvif->force_sgi = force_sgi;
4294
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004295exit:
4296 mutex_unlock(&ar->conf_mutex);
4297 return ret;
4298}
4299
4300static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4301 struct ieee80211_vif *vif,
4302 const struct cfg80211_bitrate_mask *mask)
4303{
4304 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4305 struct ath10k *ar = arvif->ar;
4306 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4307 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4308 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004309 u8 force_sgi;
4310
4311 force_sgi = mask->control[band].gi;
4312 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4313 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004314
4315 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004316 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004317 &fixed_rate,
4318 &fixed_nss))
4319 return -EINVAL;
4320 }
4321
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004322 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004323 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004324 return -EINVAL;
4325 }
4326
4327 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4328 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004329}
4330
Michal Kazior9797feb2014-02-14 14:49:48 +01004331static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4332 struct ieee80211_vif *vif,
4333 struct ieee80211_sta *sta,
4334 u32 changed)
4335{
4336 struct ath10k *ar = hw->priv;
4337 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4338 u32 bw, smps;
4339
4340 spin_lock_bh(&ar->data_lock);
4341
Michal Kazior7aa7a722014-08-25 12:09:38 +02004342 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004343 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4344 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4345 sta->smps_mode);
4346
4347 if (changed & IEEE80211_RC_BW_CHANGED) {
4348 bw = WMI_PEER_CHWIDTH_20MHZ;
4349
4350 switch (sta->bandwidth) {
4351 case IEEE80211_STA_RX_BW_20:
4352 bw = WMI_PEER_CHWIDTH_20MHZ;
4353 break;
4354 case IEEE80211_STA_RX_BW_40:
4355 bw = WMI_PEER_CHWIDTH_40MHZ;
4356 break;
4357 case IEEE80211_STA_RX_BW_80:
4358 bw = WMI_PEER_CHWIDTH_80MHZ;
4359 break;
4360 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004361 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004362 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004363 bw = WMI_PEER_CHWIDTH_20MHZ;
4364 break;
4365 }
4366
4367 arsta->bw = bw;
4368 }
4369
4370 if (changed & IEEE80211_RC_NSS_CHANGED)
4371 arsta->nss = sta->rx_nss;
4372
4373 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4374 smps = WMI_PEER_SMPS_PS_NONE;
4375
4376 switch (sta->smps_mode) {
4377 case IEEE80211_SMPS_AUTOMATIC:
4378 case IEEE80211_SMPS_OFF:
4379 smps = WMI_PEER_SMPS_PS_NONE;
4380 break;
4381 case IEEE80211_SMPS_STATIC:
4382 smps = WMI_PEER_SMPS_STATIC;
4383 break;
4384 case IEEE80211_SMPS_DYNAMIC:
4385 smps = WMI_PEER_SMPS_DYNAMIC;
4386 break;
4387 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004388 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004389 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004390 smps = WMI_PEER_SMPS_PS_NONE;
4391 break;
4392 }
4393
4394 arsta->smps = smps;
4395 }
4396
Michal Kazior9797feb2014-02-14 14:49:48 +01004397 arsta->changed |= changed;
4398
4399 spin_unlock_bh(&ar->data_lock);
4400
4401 ieee80211_queue_work(hw, &arsta->update_wk);
4402}
4403
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004404static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4405{
4406 /*
4407 * FIXME: Return 0 for time being. Need to figure out whether FW
4408 * has the API to fetch 64-bit local TSF
4409 */
4410
4411 return 0;
4412}
4413
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004414static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4415 struct ieee80211_vif *vif,
4416 enum ieee80211_ampdu_mlme_action action,
4417 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4418 u8 buf_size)
4419{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004420 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004421 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4422
Michal Kazior7aa7a722014-08-25 12:09:38 +02004423 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004424 arvif->vdev_id, sta->addr, tid, action);
4425
4426 switch (action) {
4427 case IEEE80211_AMPDU_RX_START:
4428 case IEEE80211_AMPDU_RX_STOP:
4429 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4430 * creation/removal. Do we need to verify this?
4431 */
4432 return 0;
4433 case IEEE80211_AMPDU_TX_START:
4434 case IEEE80211_AMPDU_TX_STOP_CONT:
4435 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4436 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4437 case IEEE80211_AMPDU_TX_OPERATIONAL:
4438 /* Firmware offloads Tx aggregation entirely so deny mac80211
4439 * Tx aggregation requests.
4440 */
4441 return -EOPNOTSUPP;
4442 }
4443
4444 return -EINVAL;
4445}
4446
Kalle Valo5e3dd152013-06-12 20:52:10 +03004447static const struct ieee80211_ops ath10k_ops = {
4448 .tx = ath10k_tx,
4449 .start = ath10k_start,
4450 .stop = ath10k_stop,
4451 .config = ath10k_config,
4452 .add_interface = ath10k_add_interface,
4453 .remove_interface = ath10k_remove_interface,
4454 .configure_filter = ath10k_configure_filter,
4455 .bss_info_changed = ath10k_bss_info_changed,
4456 .hw_scan = ath10k_hw_scan,
4457 .cancel_hw_scan = ath10k_cancel_hw_scan,
4458 .set_key = ath10k_set_key,
4459 .sta_state = ath10k_sta_state,
4460 .conf_tx = ath10k_conf_tx,
4461 .remain_on_channel = ath10k_remain_on_channel,
4462 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4463 .set_rts_threshold = ath10k_set_rts_threshold,
4464 .set_frag_threshold = ath10k_set_frag_threshold,
4465 .flush = ath10k_flush,
4466 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004467 .set_antenna = ath10k_set_antenna,
4468 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004469 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004470 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004471 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004472 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004473 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004474 .ampdu_action = ath10k_ampdu_action,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004475#ifdef CONFIG_PM
4476 .suspend = ath10k_suspend,
4477 .resume = ath10k_resume,
4478#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004479};
4480
4481#define RATETAB_ENT(_rate, _rateid, _flags) { \
4482 .bitrate = (_rate), \
4483 .flags = (_flags), \
4484 .hw_value = (_rateid), \
4485}
4486
4487#define CHAN2G(_channel, _freq, _flags) { \
4488 .band = IEEE80211_BAND_2GHZ, \
4489 .hw_value = (_channel), \
4490 .center_freq = (_freq), \
4491 .flags = (_flags), \
4492 .max_antenna_gain = 0, \
4493 .max_power = 30, \
4494}
4495
4496#define CHAN5G(_channel, _freq, _flags) { \
4497 .band = IEEE80211_BAND_5GHZ, \
4498 .hw_value = (_channel), \
4499 .center_freq = (_freq), \
4500 .flags = (_flags), \
4501 .max_antenna_gain = 0, \
4502 .max_power = 30, \
4503}
4504
4505static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4506 CHAN2G(1, 2412, 0),
4507 CHAN2G(2, 2417, 0),
4508 CHAN2G(3, 2422, 0),
4509 CHAN2G(4, 2427, 0),
4510 CHAN2G(5, 2432, 0),
4511 CHAN2G(6, 2437, 0),
4512 CHAN2G(7, 2442, 0),
4513 CHAN2G(8, 2447, 0),
4514 CHAN2G(9, 2452, 0),
4515 CHAN2G(10, 2457, 0),
4516 CHAN2G(11, 2462, 0),
4517 CHAN2G(12, 2467, 0),
4518 CHAN2G(13, 2472, 0),
4519 CHAN2G(14, 2484, 0),
4520};
4521
4522static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004523 CHAN5G(36, 5180, 0),
4524 CHAN5G(40, 5200, 0),
4525 CHAN5G(44, 5220, 0),
4526 CHAN5G(48, 5240, 0),
4527 CHAN5G(52, 5260, 0),
4528 CHAN5G(56, 5280, 0),
4529 CHAN5G(60, 5300, 0),
4530 CHAN5G(64, 5320, 0),
4531 CHAN5G(100, 5500, 0),
4532 CHAN5G(104, 5520, 0),
4533 CHAN5G(108, 5540, 0),
4534 CHAN5G(112, 5560, 0),
4535 CHAN5G(116, 5580, 0),
4536 CHAN5G(120, 5600, 0),
4537 CHAN5G(124, 5620, 0),
4538 CHAN5G(128, 5640, 0),
4539 CHAN5G(132, 5660, 0),
4540 CHAN5G(136, 5680, 0),
4541 CHAN5G(140, 5700, 0),
4542 CHAN5G(149, 5745, 0),
4543 CHAN5G(153, 5765, 0),
4544 CHAN5G(157, 5785, 0),
4545 CHAN5G(161, 5805, 0),
4546 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004547};
4548
4549static struct ieee80211_rate ath10k_rates[] = {
4550 /* CCK */
4551 RATETAB_ENT(10, 0x82, 0),
4552 RATETAB_ENT(20, 0x84, 0),
4553 RATETAB_ENT(55, 0x8b, 0),
4554 RATETAB_ENT(110, 0x96, 0),
4555 /* OFDM */
4556 RATETAB_ENT(60, 0x0c, 0),
4557 RATETAB_ENT(90, 0x12, 0),
4558 RATETAB_ENT(120, 0x18, 0),
4559 RATETAB_ENT(180, 0x24, 0),
4560 RATETAB_ENT(240, 0x30, 0),
4561 RATETAB_ENT(360, 0x48, 0),
4562 RATETAB_ENT(480, 0x60, 0),
4563 RATETAB_ENT(540, 0x6c, 0),
4564};
4565
4566#define ath10k_a_rates (ath10k_rates + 4)
4567#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4568#define ath10k_g_rates (ath10k_rates + 0)
4569#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4570
Michal Kaziore7b54192014-08-07 11:03:27 +02004571struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004572{
4573 struct ieee80211_hw *hw;
4574 struct ath10k *ar;
4575
Michal Kaziore7b54192014-08-07 11:03:27 +02004576 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004577 if (!hw)
4578 return NULL;
4579
4580 ar = hw->priv;
4581 ar->hw = hw;
4582
4583 return ar;
4584}
4585
4586void ath10k_mac_destroy(struct ath10k *ar)
4587{
4588 ieee80211_free_hw(ar->hw);
4589}
4590
4591static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4592 {
4593 .max = 8,
4594 .types = BIT(NL80211_IFTYPE_STATION)
4595 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004596 },
4597 {
4598 .max = 3,
4599 .types = BIT(NL80211_IFTYPE_P2P_GO)
4600 },
4601 {
4602 .max = 7,
4603 .types = BIT(NL80211_IFTYPE_AP)
4604 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004605};
4606
Bartosz Markowskif2595092013-12-10 16:20:39 +01004607static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004608 {
4609 .max = 8,
4610 .types = BIT(NL80211_IFTYPE_AP)
4611 },
4612};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004613
4614static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4615 {
4616 .limits = ath10k_if_limits,
4617 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4618 .max_interfaces = 8,
4619 .num_different_channels = 1,
4620 .beacon_int_infra_match = true,
4621 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004622};
4623
4624static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004625 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004626 .limits = ath10k_10x_if_limits,
4627 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004628 .max_interfaces = 8,
4629 .num_different_channels = 1,
4630 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004631#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004632 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4633 BIT(NL80211_CHAN_WIDTH_20) |
4634 BIT(NL80211_CHAN_WIDTH_40) |
4635 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004636#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004637 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004638};
4639
4640static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4641{
4642 struct ieee80211_sta_vht_cap vht_cap = {0};
4643 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004644 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004645
4646 vht_cap.vht_supported = 1;
4647 vht_cap.cap = ar->vht_cap_info;
4648
Michal Kazior8865bee42013-07-24 12:36:46 +02004649 mcs_map = 0;
4650 for (i = 0; i < 8; i++) {
4651 if (i < ar->num_rf_chains)
4652 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4653 else
4654 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4655 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004656
4657 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4658 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4659
4660 return vht_cap;
4661}
4662
4663static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4664{
4665 int i;
4666 struct ieee80211_sta_ht_cap ht_cap = {0};
4667
4668 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4669 return ht_cap;
4670
4671 ht_cap.ht_supported = 1;
4672 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4673 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4674 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4675 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4676 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4677
4678 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4679 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4680
4681 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4682 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4683
4684 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4685 u32 smps;
4686
4687 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4688 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4689
4690 ht_cap.cap |= smps;
4691 }
4692
4693 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4694 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4695
4696 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4697 u32 stbc;
4698
4699 stbc = ar->ht_cap_info;
4700 stbc &= WMI_HT_CAP_RX_STBC;
4701 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4702 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4703 stbc &= IEEE80211_HT_CAP_RX_STBC;
4704
4705 ht_cap.cap |= stbc;
4706 }
4707
4708 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4709 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4710
4711 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4712 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4713
4714 /* max AMSDU is implicitly taken from vht_cap_info */
4715 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4716 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4717
Michal Kazior8865bee42013-07-24 12:36:46 +02004718 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004719 ht_cap.mcs.rx_mask[i] = 0xFF;
4720
4721 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4722
4723 return ht_cap;
4724}
4725
4726
4727static void ath10k_get_arvif_iter(void *data, u8 *mac,
4728 struct ieee80211_vif *vif)
4729{
4730 struct ath10k_vif_iter *arvif_iter = data;
4731 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4732
4733 if (arvif->vdev_id == arvif_iter->vdev_id)
4734 arvif_iter->arvif = arvif;
4735}
4736
4737struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4738{
4739 struct ath10k_vif_iter arvif_iter;
4740 u32 flags;
4741
4742 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4743 arvif_iter.vdev_id = vdev_id;
4744
4745 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4746 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4747 flags,
4748 ath10k_get_arvif_iter,
4749 &arvif_iter);
4750 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004751 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004752 return NULL;
4753 }
4754
4755 return arvif_iter.arvif;
4756}
4757
4758int ath10k_mac_register(struct ath10k *ar)
4759{
4760 struct ieee80211_supported_band *band;
4761 struct ieee80211_sta_vht_cap vht_cap;
4762 struct ieee80211_sta_ht_cap ht_cap;
4763 void *channels;
4764 int ret;
4765
4766 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4767
4768 SET_IEEE80211_DEV(ar->hw, ar->dev);
4769
4770 ht_cap = ath10k_get_ht_cap(ar);
4771 vht_cap = ath10k_create_vht_cap(ar);
4772
4773 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4774 channels = kmemdup(ath10k_2ghz_channels,
4775 sizeof(ath10k_2ghz_channels),
4776 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004777 if (!channels) {
4778 ret = -ENOMEM;
4779 goto err_free;
4780 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004781
4782 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4783 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4784 band->channels = channels;
4785 band->n_bitrates = ath10k_g_rates_size;
4786 band->bitrates = ath10k_g_rates;
4787 band->ht_cap = ht_cap;
4788
4789 /* vht is not supported in 2.4 GHz */
4790
4791 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4792 }
4793
4794 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4795 channels = kmemdup(ath10k_5ghz_channels,
4796 sizeof(ath10k_5ghz_channels),
4797 GFP_KERNEL);
4798 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004799 ret = -ENOMEM;
4800 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004801 }
4802
4803 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4804 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4805 band->channels = channels;
4806 band->n_bitrates = ath10k_a_rates_size;
4807 band->bitrates = ath10k_a_rates;
4808 band->ht_cap = ht_cap;
4809 band->vht_cap = vht_cap;
4810 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4811 }
4812
4813 ar->hw->wiphy->interface_modes =
4814 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004815 BIT(NL80211_IFTYPE_AP);
4816
Ben Greear46acf7b2014-05-16 17:15:38 +03004817 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4818 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4819 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4820 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4821 } else {
4822 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4823 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4824 }
4825
4826 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4827 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4828
Bartosz Markowskid3541812013-12-10 16:20:40 +01004829 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4830 ar->hw->wiphy->interface_modes |=
4831 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4832 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004833
4834 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4835 IEEE80211_HW_SUPPORTS_PS |
4836 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4837 IEEE80211_HW_SUPPORTS_UAPSD |
4838 IEEE80211_HW_MFP_CAPABLE |
4839 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4840 IEEE80211_HW_HAS_RATE_CONTROL |
4841 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004842 IEEE80211_HW_AP_LINK_PS |
4843 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004844
Michal Kazior1f8bb152013-09-18 14:43:22 +02004845 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4846 * bytes is used for padding/alignment if necessary. */
4847 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4848
Kalle Valo5e3dd152013-06-12 20:52:10 +03004849 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4850 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4851
4852 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4853 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4854 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4855 }
4856
4857 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4858 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4859
4860 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004861 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004862
Kalle Valo5e3dd152013-06-12 20:52:10 +03004863 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4864
4865 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004866 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004867 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4868
4869 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4870 /*
4871 * on LL hardware queues are managed entirely by the FW
4872 * so we only advertise to mac we can do the queues thing
4873 */
4874 ar->hw->queues = 4;
4875
Bartosz Markowskif2595092013-12-10 16:20:39 +01004876 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4877 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4878 ar->hw->wiphy->n_iface_combinations =
4879 ARRAY_SIZE(ath10k_10x_if_comb);
4880 } else {
4881 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4882 ar->hw->wiphy->n_iface_combinations =
4883 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004884
4885 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004886 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004887
Michal Kazior7c199992013-07-31 10:47:57 +02004888 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4889
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004890 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4891 /* Init ath dfs pattern detector */
4892 ar->ath_common.debug_mask = ATH_DBG_DFS;
4893 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4894 NL80211_DFS_UNSET);
4895
4896 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004897 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004898 }
4899
Kalle Valo5e3dd152013-06-12 20:52:10 +03004900 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4901 ath10k_reg_notifier);
4902 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004903 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004904 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004905 }
4906
4907 ret = ieee80211_register_hw(ar->hw);
4908 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004909 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004910 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004911 }
4912
4913 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4914 ret = regulatory_hint(ar->hw->wiphy,
4915 ar->ath_common.regulatory.alpha2);
4916 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004917 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004918 }
4919
4920 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004921
4922err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004923 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004924err_free:
4925 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4926 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4927
Kalle Valo5e3dd152013-06-12 20:52:10 +03004928 return ret;
4929}
4930
4931void ath10k_mac_unregister(struct ath10k *ar)
4932{
4933 ieee80211_unregister_hw(ar->hw);
4934
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004935 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4936 ar->dfs_detector->exit(ar->dfs_detector);
4937
Kalle Valo5e3dd152013-06-12 20:52:10 +03004938 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4939 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4940
4941 SET_IEEE80211_DEV(ar->hw, NULL);
4942}