blob: 28e6db1d38462a2b244293659776768ff8a9a132 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030030
31/**********/
32/* Crypto */
33/**********/
34
35static int ath10k_send_key(struct ath10k_vif *arvif,
36 struct ieee80211_key_conf *key,
37 enum set_key_cmd cmd,
38 const u8 *macaddr)
39{
Michal Kazior7aa7a722014-08-25 12:09:38 +020040 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030041 struct wmi_vdev_install_key_arg arg = {
42 .vdev_id = arvif->vdev_id,
43 .key_idx = key->keyidx,
44 .key_len = key->keylen,
45 .key_data = key->key,
46 .macaddr = macaddr,
47 };
48
Michal Kazior548db542013-07-05 16:15:15 +030049 lockdep_assert_held(&arvif->ar->conf_mutex);
50
Kalle Valo5e3dd152013-06-12 20:52:10 +030051 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
52 arg.key_flags = WMI_KEY_PAIRWISE;
53 else
54 arg.key_flags = WMI_KEY_GROUP;
55
56 switch (key->cipher) {
57 case WLAN_CIPHER_SUITE_CCMP:
58 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030059 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
60 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
61 else
62 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030063 break;
64 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030065 arg.key_cipher = WMI_CIPHER_TKIP;
66 arg.key_txmic_len = 8;
67 arg.key_rxmic_len = 8;
68 break;
69 case WLAN_CIPHER_SUITE_WEP40:
70 case WLAN_CIPHER_SUITE_WEP104:
71 arg.key_cipher = WMI_CIPHER_WEP;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
75 arg.key_flags = WMI_KEY_PAIRWISE;
76 break;
77 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020078 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030079 return -EOPNOTSUPP;
80 }
81
82 if (cmd == DISABLE_KEY) {
83 arg.key_cipher = WMI_CIPHER_NONE;
84 arg.key_data = NULL;
85 }
86
87 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
88}
89
90static int ath10k_install_key(struct ath10k_vif *arvif,
91 struct ieee80211_key_conf *key,
92 enum set_key_cmd cmd,
93 const u8 *macaddr)
94{
95 struct ath10k *ar = arvif->ar;
96 int ret;
97
Michal Kazior548db542013-07-05 16:15:15 +030098 lockdep_assert_held(&ar->conf_mutex);
99
Wolfram Sang16735d02013-11-14 14:32:02 -0800100 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300101
102 ret = ath10k_send_key(arvif, key, cmd, macaddr);
103 if (ret)
104 return ret;
105
106 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
107 if (ret == 0)
108 return -ETIMEDOUT;
109
110 return 0;
111}
112
113static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
114 const u8 *addr)
115{
116 struct ath10k *ar = arvif->ar;
117 struct ath10k_peer *peer;
118 int ret;
119 int i;
120
121 lockdep_assert_held(&ar->conf_mutex);
122
123 spin_lock_bh(&ar->data_lock);
124 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
125 spin_unlock_bh(&ar->data_lock);
126
127 if (!peer)
128 return -ENOENT;
129
130 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
131 if (arvif->wep_keys[i] == NULL)
132 continue;
133
134 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
135 addr);
136 if (ret)
137 return ret;
138
139 peer->keys[i] = arvif->wep_keys[i];
140 }
141
142 return 0;
143}
144
145static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
146 const u8 *addr)
147{
148 struct ath10k *ar = arvif->ar;
149 struct ath10k_peer *peer;
150 int first_errno = 0;
151 int ret;
152 int i;
153
154 lockdep_assert_held(&ar->conf_mutex);
155
156 spin_lock_bh(&ar->data_lock);
157 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
158 spin_unlock_bh(&ar->data_lock);
159
160 if (!peer)
161 return -ENOENT;
162
163 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
164 if (peer->keys[i] == NULL)
165 continue;
166
167 ret = ath10k_install_key(arvif, peer->keys[i],
168 DISABLE_KEY, addr);
169 if (ret && first_errno == 0)
170 first_errno = ret;
171
172 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200173 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300174 i, ret);
175
176 peer->keys[i] = NULL;
177 }
178
179 return first_errno;
180}
181
182static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
183 struct ieee80211_key_conf *key)
184{
185 struct ath10k *ar = arvif->ar;
186 struct ath10k_peer *peer;
187 u8 addr[ETH_ALEN];
188 int first_errno = 0;
189 int ret;
190 int i;
191
192 lockdep_assert_held(&ar->conf_mutex);
193
194 for (;;) {
195 /* since ath10k_install_key we can't hold data_lock all the
196 * time, so we try to remove the keys incrementally */
197 spin_lock_bh(&ar->data_lock);
198 i = 0;
199 list_for_each_entry(peer, &ar->peers, list) {
200 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
201 if (peer->keys[i] == key) {
202 memcpy(addr, peer->addr, ETH_ALEN);
203 peer->keys[i] = NULL;
204 break;
205 }
206 }
207
208 if (i < ARRAY_SIZE(peer->keys))
209 break;
210 }
211 spin_unlock_bh(&ar->data_lock);
212
213 if (i == ARRAY_SIZE(peer->keys))
214 break;
215
216 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
217 if (ret && first_errno == 0)
218 first_errno = ret;
219
220 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200221 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200222 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300223 }
224
225 return first_errno;
226}
227
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228/*********************/
229/* General utilities */
230/*********************/
231
232static inline enum wmi_phy_mode
233chan_to_phymode(const struct cfg80211_chan_def *chandef)
234{
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
241 phymode = MODE_11G;
242 break;
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
245 break;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
248 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
255 break;
256 }
257 break;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
261 phymode = MODE_11A;
262 break;
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
265 break;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
268 break;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
271 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
277 break;
278 }
279 break;
280 default:
281 break;
282 }
283
284 WARN_ON(phymode == MODE_UNKNOWN);
285 return phymode;
286}
287
288static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
289{
290/*
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
293 * 1 for 1/4 us
294 * 2 for 1/2 us
295 * 3 for 1 us
296 * 4 for 2 us
297 * 5 for 4 us
298 * 6 for 8 us
299 * 7 for 16 us
300 */
301 switch (mpdudensity) {
302 case 0:
303 return 0;
304 case 1:
305 case 2:
306 case 3:
307 /* Our lower layer calculations limit our precision to
308 1 microsecond */
309 return 1;
310 case 4:
311 return 2;
312 case 5:
313 return 4;
314 case 6:
315 return 8;
316 case 7:
317 return 16;
318 default:
319 return 0;
320 }
321}
322
323static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
324{
325 int ret;
326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800330 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200332 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200339 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800341 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100342 spin_lock_bh(&ar->data_lock);
343 ar->num_peers++;
344 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300345
346 return 0;
347}
348
Kalle Valo5a13e762014-01-20 11:01:46 +0200349static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350{
351 struct ath10k *ar = arvif->ar;
352 u32 param;
353 int ret;
354
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
358 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200360 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200361 return ret;
362 }
363
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200370 return ret;
371 }
372
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200378 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200379 return ret;
380 }
381
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200387 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200388 return ret;
389 }
390
391 return 0;
392}
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200396 struct ath10k *ar = arvif->ar;
397 u32 vdev_param;
398
Michal Kazior424121c2013-07-22 14:13:31 +0200399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
401 ATH10K_RTS_MAX);
402
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200405}
406
407static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 struct ath10k *ar = arvif->ar;
410 u32 vdev_param;
411
Michal Kazior424121c2013-07-22 14:13:31 +0200412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
416
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
422{
423 int ret;
424
425 lockdep_assert_held(&ar->conf_mutex);
426
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
428 if (ret)
429 return ret;
430
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
432 if (ret)
433 return ret;
434
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100435 spin_lock_bh(&ar->data_lock);
436 ar->num_peers--;
437 spin_unlock_bh(&ar->data_lock);
438
Kalle Valo5e3dd152013-06-12 20:52:10 +0300439 return 0;
440}
441
442static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443{
444 struct ath10k_peer *peer, *tmp;
445
446 lockdep_assert_held(&ar->conf_mutex);
447
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
451 continue;
452
Michal Kazior7aa7a722014-08-25 12:09:38 +0200453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 peer->addr, vdev_id);
455
456 list_del(&peer->list);
457 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100458 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 }
460 spin_unlock_bh(&ar->data_lock);
461}
462
Michal Kaziora96d7742013-07-16 09:38:56 +0200463static void ath10k_peer_cleanup_all(struct ath10k *ar)
464{
465 struct ath10k_peer *peer, *tmp;
466
467 lockdep_assert_held(&ar->conf_mutex);
468
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
472 kfree(peer);
473 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200475 spin_unlock_bh(&ar->data_lock);
476}
477
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478/************************/
479/* Interface management */
480/************************/
481
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 int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300497{
Michal Kaziorc930f742014-01-23 11:38:25 +0100498 struct cfg80211_chan_def *chandef = &ar->chandef;
499 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300500 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300501 int ret = 0;
502
503 lockdep_assert_held(&ar->conf_mutex);
504
Kalle Valo5e3dd152013-06-12 20:52:10 +0300505 arg.vdev_id = vdev_id;
506 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100507 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300508
509 /* TODO setup this dynamically, what in case we
510 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100511 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200512 arg.channel.chan_radar =
513 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300514
Michal Kazior89c5c842013-10-23 04:02:13 -0700515 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700516 arg.channel.max_power = channel->max_power * 2;
517 arg.channel.max_reg_power = channel->max_reg_power * 2;
518 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300519
520 ret = ath10k_wmi_vdev_start(ar, &arg);
521 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200522 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200523 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300524 return ret;
525 }
526
527 ret = ath10k_vdev_setup_sync(ar);
528 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200529 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200530 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300531 return ret;
532 }
533
534 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
535 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200536 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200537 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300538 goto vdev_stop;
539 }
540
541 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300542
Michal Kazior7aa7a722014-08-25 12:09:38 +0200543 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300544 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300545 return 0;
546
547vdev_stop:
548 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
549 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200550 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200551 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300552
553 return ret;
554}
555
Michal Kazior1bbc0972014-04-08 09:45:47 +0300556static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300557{
558 int ret = 0;
559
560 lockdep_assert_held(&ar->conf_mutex);
561
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200562 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
563 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200564 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200565 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300566
567 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
568 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200569 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200570 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571
572 ret = ath10k_vdev_setup_sync(ar);
573 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200574 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200575 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300576
Michal Kazior7aa7a722014-08-25 12:09:38 +0200577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300578 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300579 return ret;
580}
581
Michal Kazior1bbc0972014-04-08 09:45:47 +0300582static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583{
584 int bit, ret = 0;
585
586 lockdep_assert_held(&ar->conf_mutex);
587
Ben Greeara9aefb32014-08-12 11:02:19 +0300588 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200589 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300590 return -ENOMEM;
591 }
592
Ben Greeara9aefb32014-08-12 11:02:19 +0300593 bit = ffs(ar->free_vdev_map);
594
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595 ar->monitor_vdev_id = bit - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300596
597 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
598 WMI_VDEV_TYPE_MONITOR,
599 0, ar->mac_addr);
600 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200601 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200602 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300603 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300604 }
605
Ben Greeara9aefb32014-08-12 11:02:19 +0300606 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300608 ar->monitor_vdev_id);
609
Kalle Valo5e3dd152013-06-12 20:52:10 +0300610 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300611}
612
Michal Kazior1bbc0972014-04-08 09:45:47 +0300613static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300614{
615 int ret = 0;
616
617 lockdep_assert_held(&ar->conf_mutex);
618
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
620 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200621 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200622 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623 return ret;
624 }
625
Ben Greeara9aefb32014-08-12 11:02:19 +0300626 ar->free_vdev_map |= 1 << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627
Michal Kazior7aa7a722014-08-25 12:09:38 +0200628 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300629 ar->monitor_vdev_id);
630 return ret;
631}
632
Michal Kazior1bbc0972014-04-08 09:45:47 +0300633static int ath10k_monitor_start(struct ath10k *ar)
634{
635 int ret;
636
637 lockdep_assert_held(&ar->conf_mutex);
638
Michal Kazior1bbc0972014-04-08 09:45:47 +0300639 ret = ath10k_monitor_vdev_create(ar);
640 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200641 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300642 return ret;
643 }
644
645 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
646 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200647 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300648 ath10k_monitor_vdev_delete(ar);
649 return ret;
650 }
651
652 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200653 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300654
655 return 0;
656}
657
Michal Kazior19337472014-08-28 12:58:16 +0200658static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300659{
660 int ret;
661
662 lockdep_assert_held(&ar->conf_mutex);
663
Michal Kazior1bbc0972014-04-08 09:45:47 +0300664 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200665 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200666 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200667 return ret;
668 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300669
670 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200671 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200672 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200673 return ret;
674 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300675
676 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200678
679 return 0;
680}
681
682static int ath10k_monitor_recalc(struct ath10k *ar)
683{
684 bool should_start;
685
686 lockdep_assert_held(&ar->conf_mutex);
687
688 should_start = ar->monitor ||
689 ar->filter_flags & FIF_PROMISC_IN_BSS ||
690 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
691
692 ath10k_dbg(ar, ATH10K_DBG_MAC,
693 "mac monitor recalc started? %d should? %d\n",
694 ar->monitor_started, should_start);
695
696 if (should_start == ar->monitor_started)
697 return 0;
698
699 if (should_start)
700 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300701
702 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300703}
704
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200705static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
706{
707 struct ath10k *ar = arvif->ar;
708 u32 vdev_param, rts_cts = 0;
709
710 lockdep_assert_held(&ar->conf_mutex);
711
712 vdev_param = ar->wmi.vdev_param->enable_rtscts;
713
714 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
715 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
716
717 if (arvif->num_legacy_stations > 0)
718 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
719 WMI_RTSCTS_PROFILE);
720
721 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
722 rts_cts);
723}
724
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200725static int ath10k_start_cac(struct ath10k *ar)
726{
727 int ret;
728
729 lockdep_assert_held(&ar->conf_mutex);
730
731 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
732
Michal Kazior19337472014-08-28 12:58:16 +0200733 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200734 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200735 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200736 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
737 return ret;
738 }
739
Michal Kazior7aa7a722014-08-25 12:09:38 +0200740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200741 ar->monitor_vdev_id);
742
743 return 0;
744}
745
746static int ath10k_stop_cac(struct ath10k *ar)
747{
748 lockdep_assert_held(&ar->conf_mutex);
749
750 /* CAC is not running - do nothing */
751 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
752 return 0;
753
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200754 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300755 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200756
Michal Kazior7aa7a722014-08-25 12:09:38 +0200757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200758
759 return 0;
760}
761
Michal Kaziord6500972014-04-08 09:56:09 +0300762static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200763{
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200764 int ret;
765
766 lockdep_assert_held(&ar->conf_mutex);
767
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200768 ath10k_stop_cac(ar);
769
Michal Kaziord6500972014-04-08 09:56:09 +0300770 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200771 return;
772
Michal Kaziord6500972014-04-08 09:56:09 +0300773 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200774 return;
775
776 ret = ath10k_start_cac(ar);
777 if (ret) {
778 /*
779 * Not possible to start CAC on current channel so starting
780 * radiation is not allowed, make this channel DFS_UNAVAILABLE
781 * by indicating that radar was detected.
782 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200783 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200784 ieee80211_radar_detected(ar->hw);
785 }
786}
787
Michal Kaziordc55e302014-07-29 12:53:36 +0300788static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +0300789{
790 struct ath10k *ar = arvif->ar;
791 struct cfg80211_chan_def *chandef = &ar->chandef;
792 struct wmi_vdev_start_request_arg arg = {};
793 int ret = 0;
794
795 lockdep_assert_held(&ar->conf_mutex);
796
797 reinit_completion(&ar->vdev_setup_done);
798
799 arg.vdev_id = arvif->vdev_id;
800 arg.dtim_period = arvif->dtim_period;
801 arg.bcn_intval = arvif->beacon_interval;
802
803 arg.channel.freq = chandef->chan->center_freq;
804 arg.channel.band_center_freq1 = chandef->center_freq1;
805 arg.channel.mode = chan_to_phymode(chandef);
806
807 arg.channel.min_power = 0;
808 arg.channel.max_power = chandef->chan->max_power * 2;
809 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
810 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
811
812 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
813 arg.ssid = arvif->u.ap.ssid;
814 arg.ssid_len = arvif->u.ap.ssid_len;
815 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
816
817 /* For now allow DFS for AP mode */
818 arg.channel.chan_radar =
819 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
820 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
821 arg.ssid = arvif->vif->bss_conf.ssid;
822 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
823 }
824
Michal Kazior7aa7a722014-08-25 12:09:38 +0200825 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +0300826 "mac vdev %d start center_freq %d phymode %s\n",
827 arg.vdev_id, arg.channel.freq,
828 ath10k_wmi_phymode_str(arg.channel.mode));
829
Michal Kaziordc55e302014-07-29 12:53:36 +0300830 if (restart)
831 ret = ath10k_wmi_vdev_restart(ar, &arg);
832 else
833 ret = ath10k_wmi_vdev_start(ar, &arg);
834
Michal Kazior72654fa2014-04-08 09:56:09 +0300835 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200836 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300837 arg.vdev_id, ret);
838 return ret;
839 }
840
841 ret = ath10k_vdev_setup_sync(ar);
842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200843 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300844 arg.vdev_id, ret);
845 return ret;
846 }
847
Michal Kaziord6500972014-04-08 09:56:09 +0300848 ar->num_started_vdevs++;
849 ath10k_recalc_radar_detection(ar);
850
Michal Kazior72654fa2014-04-08 09:56:09 +0300851 return ret;
852}
853
Michal Kaziordc55e302014-07-29 12:53:36 +0300854static int ath10k_vdev_start(struct ath10k_vif *arvif)
855{
856 return ath10k_vdev_start_restart(arvif, false);
857}
858
859static int ath10k_vdev_restart(struct ath10k_vif *arvif)
860{
861 return ath10k_vdev_start_restart(arvif, true);
862}
863
Michal Kazior72654fa2014-04-08 09:56:09 +0300864static int ath10k_vdev_stop(struct ath10k_vif *arvif)
865{
866 struct ath10k *ar = arvif->ar;
867 int ret;
868
869 lockdep_assert_held(&ar->conf_mutex);
870
871 reinit_completion(&ar->vdev_setup_done);
872
873 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
874 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200875 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300876 arvif->vdev_id, ret);
877 return ret;
878 }
879
880 ret = ath10k_vdev_setup_sync(ar);
881 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200882 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +0300883 arvif->vdev_id, ret);
884 return ret;
885 }
886
Michal Kaziord6500972014-04-08 09:56:09 +0300887 WARN_ON(ar->num_started_vdevs == 0);
888
889 if (ar->num_started_vdevs != 0) {
890 ar->num_started_vdevs--;
891 ath10k_recalc_radar_detection(ar);
892 }
893
Michal Kazior72654fa2014-04-08 09:56:09 +0300894 return ret;
895}
896
Kalle Valo5e3dd152013-06-12 20:52:10 +0300897static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +0300898 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200900 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901 int ret = 0;
902
Michal Kazior548db542013-07-05 16:15:15 +0300903 lockdep_assert_held(&arvif->ar->conf_mutex);
904
Kalle Valo5e3dd152013-06-12 20:52:10 +0300905 if (!info->enable_beacon) {
906 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +0100907
908 arvif->is_started = false;
909 arvif->is_up = false;
910
Michal Kazior748afc42014-01-23 12:48:21 +0100911 spin_lock_bh(&arvif->ar->data_lock);
912 if (arvif->beacon) {
Michal Kazior767d34f2014-02-27 18:50:03 +0200913 dma_unmap_single(arvif->ar->dev,
914 ATH10K_SKB_CB(arvif->beacon)->paddr,
915 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kazior748afc42014-01-23 12:48:21 +0100916 dev_kfree_skb_any(arvif->beacon);
917
918 arvif->beacon = NULL;
919 arvif->beacon_sent = false;
920 }
921 spin_unlock_bh(&arvif->ar->data_lock);
922
Kalle Valo5e3dd152013-06-12 20:52:10 +0300923 return;
924 }
925
926 arvif->tx_seq_no = 0x1000;
927
928 ret = ath10k_vdev_start(arvif);
929 if (ret)
930 return;
931
Michal Kaziorc930f742014-01-23 11:38:25 +0100932 arvif->aid = 0;
933 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
934
935 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
936 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300937 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200938 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200939 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +0100940 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941 return;
942 }
Michal Kaziorc930f742014-01-23 11:38:25 +0100943
944 arvif->is_started = true;
945 arvif->is_up = true;
946
Michal Kazior7aa7a722014-08-25 12:09:38 +0200947 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300948}
949
950static void ath10k_control_ibss(struct ath10k_vif *arvif,
951 struct ieee80211_bss_conf *info,
952 const u8 self_peer[ETH_ALEN])
953{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200954 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200955 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956 int ret = 0;
957
Michal Kazior548db542013-07-05 16:15:15 +0300958 lockdep_assert_held(&arvif->ar->conf_mutex);
959
Kalle Valo5e3dd152013-06-12 20:52:10 +0300960 if (!info->ibss_joined) {
961 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
962 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200963 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300964 self_peer, arvif->vdev_id, ret);
965
Michal Kaziorc930f742014-01-23 11:38:25 +0100966 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967 return;
968
969 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
Michal Kaziorc930f742014-01-23 11:38:25 +0100970 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200972 ath10k_warn(ar, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +0100973 arvif->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300974 return;
975 }
976
Michal Kaziorc930f742014-01-23 11:38:25 +0100977 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300978
979 return;
980 }
981
982 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
983 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200984 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300985 self_peer, arvif->vdev_id, ret);
986 return;
987 }
988
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200989 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
990 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 ATH10K_DEFAULT_ATIM);
992 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200993 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300994 arvif->vdev_id, ret);
995}
996
997/*
998 * Review this when mac80211 gains per-interface powersave support.
999 */
Michal Kaziorad088bf2013-10-16 15:44:46 +03001000static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001001{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001002 struct ath10k *ar = arvif->ar;
1003 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001004 enum wmi_sta_powersave_param param;
1005 enum wmi_sta_ps_mode psmode;
1006 int ret;
1007
Michal Kazior548db542013-07-05 16:15:15 +03001008 lockdep_assert_held(&arvif->ar->conf_mutex);
1009
Michal Kaziorad088bf2013-10-16 15:44:46 +03001010 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1011 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001012
1013 if (conf->flags & IEEE80211_CONF_PS) {
1014 psmode = WMI_STA_PS_MODE_ENABLED;
1015 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1016
Michal Kaziorad088bf2013-10-16 15:44:46 +03001017 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001018 conf->dynamic_ps_timeout);
1019 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001020 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001021 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001022 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001023 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001024 } else {
1025 psmode = WMI_STA_PS_MODE_DISABLED;
1026 }
1027
Michal Kazior7aa7a722014-08-25 12:09:38 +02001028 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001029 arvif->vdev_id, psmode ? "enable" : "disable");
1030
Michal Kaziorad088bf2013-10-16 15:44:46 +03001031 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1032 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001033 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001034 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001035 return ret;
1036 }
1037
1038 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001039}
1040
1041/**********************/
1042/* Station management */
1043/**********************/
1044
1045static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1046 struct ath10k_vif *arvif,
1047 struct ieee80211_sta *sta,
1048 struct ieee80211_bss_conf *bss_conf,
1049 struct wmi_peer_assoc_complete_arg *arg)
1050{
Michal Kazior548db542013-07-05 16:15:15 +03001051 lockdep_assert_held(&ar->conf_mutex);
1052
Kalle Valo5e3dd152013-06-12 20:52:10 +03001053 memcpy(arg->addr, sta->addr, ETH_ALEN);
1054 arg->vdev_id = arvif->vdev_id;
1055 arg->peer_aid = sta->aid;
1056 arg->peer_flags |= WMI_PEER_AUTH;
1057
1058 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1059 /*
1060 * Seems FW have problems with Power Save in STA
1061 * mode when we setup this parameter to high (eg. 5).
1062 * Often we see that FW don't send NULL (with clean P flags)
1063 * frame even there is info about buffered frames in beacons.
1064 * Sometimes we have to wait more than 10 seconds before FW
1065 * will wakeup. Often sending one ping from AP to our device
1066 * just fail (more than 50%).
1067 *
1068 * Seems setting this FW parameter to 1 couse FW
1069 * will check every beacon and will wakup immediately
1070 * after detection buffered data.
1071 */
1072 arg->peer_listen_intval = 1;
1073 else
1074 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1075
1076 arg->peer_num_spatial_streams = 1;
1077
1078 /*
1079 * The assoc capabilities are available only in managed mode.
1080 */
1081 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1082 arg->peer_caps = bss_conf->assoc_capability;
1083}
1084
1085static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1086 struct ath10k_vif *arvif,
1087 struct wmi_peer_assoc_complete_arg *arg)
1088{
1089 struct ieee80211_vif *vif = arvif->vif;
1090 struct ieee80211_bss_conf *info = &vif->bss_conf;
1091 struct cfg80211_bss *bss;
1092 const u8 *rsnie = NULL;
1093 const u8 *wpaie = NULL;
1094
Michal Kazior548db542013-07-05 16:15:15 +03001095 lockdep_assert_held(&ar->conf_mutex);
1096
Kalle Valo5e3dd152013-06-12 20:52:10 +03001097 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1098 info->bssid, NULL, 0, 0, 0);
1099 if (bss) {
1100 const struct cfg80211_bss_ies *ies;
1101
1102 rcu_read_lock();
1103 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1104
1105 ies = rcu_dereference(bss->ies);
1106
1107 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001108 WLAN_OUI_TYPE_MICROSOFT_WPA,
1109 ies->data,
1110 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001111 rcu_read_unlock();
1112 cfg80211_put_bss(ar->hw->wiphy, bss);
1113 }
1114
1115 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1116 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001117 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1119 }
1120
1121 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001122 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1124 }
1125}
1126
1127static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1128 struct ieee80211_sta *sta,
1129 struct wmi_peer_assoc_complete_arg *arg)
1130{
1131 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1132 const struct ieee80211_supported_band *sband;
1133 const struct ieee80211_rate *rates;
1134 u32 ratemask;
1135 int i;
1136
Michal Kazior548db542013-07-05 16:15:15 +03001137 lockdep_assert_held(&ar->conf_mutex);
1138
Kalle Valo5e3dd152013-06-12 20:52:10 +03001139 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1140 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1141 rates = sband->bitrates;
1142
1143 rateset->num_rates = 0;
1144
1145 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1146 if (!(ratemask & 1))
1147 continue;
1148
1149 rateset->rates[rateset->num_rates] = rates->hw_value;
1150 rateset->num_rates++;
1151 }
1152}
1153
1154static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1155 struct ieee80211_sta *sta,
1156 struct wmi_peer_assoc_complete_arg *arg)
1157{
1158 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001159 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001160 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161
Michal Kazior548db542013-07-05 16:15:15 +03001162 lockdep_assert_held(&ar->conf_mutex);
1163
Kalle Valo5e3dd152013-06-12 20:52:10 +03001164 if (!ht_cap->ht_supported)
1165 return;
1166
1167 arg->peer_flags |= WMI_PEER_HT;
1168 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1169 ht_cap->ampdu_factor)) - 1;
1170
1171 arg->peer_mpdu_density =
1172 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1173
1174 arg->peer_ht_caps = ht_cap->cap;
1175 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1176
1177 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1178 arg->peer_flags |= WMI_PEER_LDPC;
1179
1180 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1181 arg->peer_flags |= WMI_PEER_40MHZ;
1182 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1183 }
1184
1185 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1186 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1187
1188 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1189 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1190
1191 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1192 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1193 arg->peer_flags |= WMI_PEER_STBC;
1194 }
1195
1196 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001197 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1198 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1199 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1200 arg->peer_rate_caps |= stbc;
1201 arg->peer_flags |= WMI_PEER_STBC;
1202 }
1203
Kalle Valo5e3dd152013-06-12 20:52:10 +03001204 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1205 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1206 else if (ht_cap->mcs.rx_mask[1])
1207 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1208
1209 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1210 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1211 arg->peer_ht_rates.rates[n++] = i;
1212
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001213 /*
1214 * This is a workaround for HT-enabled STAs which break the spec
1215 * and have no HT capabilities RX mask (no HT RX MCS map).
1216 *
1217 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1218 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1219 *
1220 * Firmware asserts if such situation occurs.
1221 */
1222 if (n == 0) {
1223 arg->peer_ht_rates.num_rates = 8;
1224 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1225 arg->peer_ht_rates.rates[i] = i;
1226 } else {
1227 arg->peer_ht_rates.num_rates = n;
1228 arg->peer_num_spatial_streams = sta->rx_nss;
1229 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001230
Michal Kazior7aa7a722014-08-25 12:09:38 +02001231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001232 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001233 arg->peer_ht_rates.num_rates,
1234 arg->peer_num_spatial_streams);
1235}
1236
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001237static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1238 struct ath10k_vif *arvif,
1239 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001240{
1241 u32 uapsd = 0;
1242 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001243 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001244
Michal Kazior548db542013-07-05 16:15:15 +03001245 lockdep_assert_held(&ar->conf_mutex);
1246
Kalle Valo5e3dd152013-06-12 20:52:10 +03001247 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001248 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001249 sta->uapsd_queues, sta->max_sp);
1250
Kalle Valo5e3dd152013-06-12 20:52:10 +03001251 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1252 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1253 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1254 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1255 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1256 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1257 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1258 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1259 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1260 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1261 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1262 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1263
Kalle Valo5e3dd152013-06-12 20:52:10 +03001264 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1265 max_sp = sta->max_sp;
1266
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001267 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1268 sta->addr,
1269 WMI_AP_PS_PEER_PARAM_UAPSD,
1270 uapsd);
1271 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001272 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001273 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001274 return ret;
1275 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001276
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001277 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1278 sta->addr,
1279 WMI_AP_PS_PEER_PARAM_MAX_SP,
1280 max_sp);
1281 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001282 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001283 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001284 return ret;
1285 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001286
1287 /* TODO setup this based on STA listen interval and
1288 beacon interval. Currently we don't know
1289 sta->listen_interval - mac80211 patch required.
1290 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001291 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001292 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1293 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001295 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001296 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001297 return ret;
1298 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001299 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001300
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001301 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001302}
1303
1304static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1305 struct ieee80211_sta *sta,
1306 struct wmi_peer_assoc_complete_arg *arg)
1307{
1308 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001309 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001310
1311 if (!vht_cap->vht_supported)
1312 return;
1313
1314 arg->peer_flags |= WMI_PEER_VHT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001315 arg->peer_vht_caps = vht_cap->cap;
1316
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001317 ampdu_factor = (vht_cap->cap &
1318 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1319 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1320
1321 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1322 * zero in VHT IE. Using it would result in degraded throughput.
1323 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1324 * it if VHT max_mpdu is smaller. */
1325 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1326 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1327 ampdu_factor)) - 1);
1328
Kalle Valo5e3dd152013-06-12 20:52:10 +03001329 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1330 arg->peer_flags |= WMI_PEER_80MHZ;
1331
1332 arg->peer_vht_rates.rx_max_rate =
1333 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1334 arg->peer_vht_rates.rx_mcs_set =
1335 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1336 arg->peer_vht_rates.tx_max_rate =
1337 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1338 arg->peer_vht_rates.tx_mcs_set =
1339 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1340
Michal Kazior7aa7a722014-08-25 12:09:38 +02001341 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001342 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001343}
1344
1345static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1346 struct ath10k_vif *arvif,
1347 struct ieee80211_sta *sta,
1348 struct ieee80211_bss_conf *bss_conf,
1349 struct wmi_peer_assoc_complete_arg *arg)
1350{
1351 switch (arvif->vdev_type) {
1352 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001353 if (sta->wme)
1354 arg->peer_flags |= WMI_PEER_QOS;
1355
1356 if (sta->wme && sta->uapsd_queues) {
1357 arg->peer_flags |= WMI_PEER_APSD;
1358 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1359 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001360 break;
1361 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001362 if (bss_conf->qos)
1363 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364 break;
1365 default:
1366 break;
1367 }
1368}
1369
1370static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1371 struct ath10k_vif *arvif,
1372 struct ieee80211_sta *sta,
1373 struct wmi_peer_assoc_complete_arg *arg)
1374{
1375 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1376
Kalle Valo5e3dd152013-06-12 20:52:10 +03001377 switch (ar->hw->conf.chandef.chan->band) {
1378 case IEEE80211_BAND_2GHZ:
1379 if (sta->ht_cap.ht_supported) {
1380 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1381 phymode = MODE_11NG_HT40;
1382 else
1383 phymode = MODE_11NG_HT20;
1384 } else {
1385 phymode = MODE_11G;
1386 }
1387
1388 break;
1389 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001390 /*
1391 * Check VHT first.
1392 */
1393 if (sta->vht_cap.vht_supported) {
1394 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1395 phymode = MODE_11AC_VHT80;
1396 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1397 phymode = MODE_11AC_VHT40;
1398 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1399 phymode = MODE_11AC_VHT20;
1400 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001401 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1402 phymode = MODE_11NA_HT40;
1403 else
1404 phymode = MODE_11NA_HT20;
1405 } else {
1406 phymode = MODE_11A;
1407 }
1408
1409 break;
1410 default:
1411 break;
1412 }
1413
Michal Kazior7aa7a722014-08-25 12:09:38 +02001414 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001415 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001416
Kalle Valo5e3dd152013-06-12 20:52:10 +03001417 arg->peer_phymode = phymode;
1418 WARN_ON(phymode == MODE_UNKNOWN);
1419}
1420
Kalle Valob9ada652013-10-16 15:44:46 +03001421static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1422 struct ath10k_vif *arvif,
1423 struct ieee80211_sta *sta,
1424 struct ieee80211_bss_conf *bss_conf,
1425 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426{
Michal Kazior548db542013-07-05 16:15:15 +03001427 lockdep_assert_held(&ar->conf_mutex);
1428
Kalle Valob9ada652013-10-16 15:44:46 +03001429 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001430
Kalle Valob9ada652013-10-16 15:44:46 +03001431 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1432 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1433 ath10k_peer_assoc_h_rates(ar, sta, arg);
1434 ath10k_peer_assoc_h_ht(ar, sta, arg);
1435 ath10k_peer_assoc_h_vht(ar, sta, arg);
1436 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1437 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438
Kalle Valob9ada652013-10-16 15:44:46 +03001439 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001440}
1441
Michal Kazior90046f52014-02-14 14:45:51 +01001442static const u32 ath10k_smps_map[] = {
1443 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1444 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1445 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1446 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1447};
1448
1449static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1450 const u8 *addr,
1451 const struct ieee80211_sta_ht_cap *ht_cap)
1452{
1453 int smps;
1454
1455 if (!ht_cap->ht_supported)
1456 return 0;
1457
1458 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1459 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1460
1461 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1462 return -EINVAL;
1463
1464 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1465 WMI_PEER_SMPS_STATE,
1466 ath10k_smps_map[smps]);
1467}
1468
Kalle Valo5e3dd152013-06-12 20:52:10 +03001469/* can be called only in mac80211 callbacks due to `key_count` usage */
1470static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1471 struct ieee80211_vif *vif,
1472 struct ieee80211_bss_conf *bss_conf)
1473{
1474 struct ath10k *ar = hw->priv;
1475 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001476 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001477 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001478 struct ieee80211_sta *ap_sta;
1479 int ret;
1480
Michal Kazior548db542013-07-05 16:15:15 +03001481 lockdep_assert_held(&ar->conf_mutex);
1482
Kalle Valo5e3dd152013-06-12 20:52:10 +03001483 rcu_read_lock();
1484
1485 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1486 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001487 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001488 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001489 rcu_read_unlock();
1490 return;
1491 }
1492
Michal Kazior90046f52014-02-14 14:45:51 +01001493 /* ap_sta must be accessed only within rcu section which must be left
1494 * before calling ath10k_setup_peer_smps() which might sleep. */
1495 ht_cap = ap_sta->ht_cap;
1496
Kalle Valob9ada652013-10-16 15:44:46 +03001497 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1498 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001499 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001500 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001501 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502 rcu_read_unlock();
1503 return;
1504 }
1505
1506 rcu_read_unlock();
1507
Kalle Valob9ada652013-10-16 15:44:46 +03001508 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1509 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001510 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001511 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001512 return;
1513 }
1514
Michal Kazior90046f52014-02-14 14:45:51 +01001515 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001517 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001518 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001519 return;
1520 }
1521
Michal Kazior7aa7a722014-08-25 12:09:38 +02001522 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001523 "mac vdev %d up (associated) bssid %pM aid %d\n",
1524 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1525
Michal Kaziorc930f742014-01-23 11:38:25 +01001526 arvif->aid = bss_conf->aid;
1527 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1528
1529 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1530 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001531 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001532 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001533 return;
1534 }
1535
1536 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001537}
1538
1539/*
1540 * FIXME: flush TIDs
1541 */
1542static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1543 struct ieee80211_vif *vif)
1544{
1545 struct ath10k *ar = hw->priv;
1546 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1547 int ret;
1548
Michal Kazior548db542013-07-05 16:15:15 +03001549 lockdep_assert_held(&ar->conf_mutex);
1550
Kalle Valo5e3dd152013-06-12 20:52:10 +03001551 /*
1552 * For some reason, calling VDEV-DOWN before VDEV-STOP
1553 * makes the FW to send frames via HTT after disassociation.
1554 * No idea why this happens, even though VDEV-DOWN is supposed
1555 * to be analogous to link down, so just stop the VDEV.
1556 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001557 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001558 arvif->vdev_id);
1559
1560 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562
1563 /*
1564 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1565 * report beacons from previously associated network through HTT.
1566 * This in turn would spam mac80211 WARN_ON if we bring down all
1567 * interfaces as it expects there is no rx when no interface is
1568 * running.
1569 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001570 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001571
1572 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001575 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001576
1577 arvif->is_started = false;
1578 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579}
1580
1581static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001582 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583{
Kalle Valob9ada652013-10-16 15:44:46 +03001584 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001585 int ret = 0;
1586
Michal Kazior548db542013-07-05 16:15:15 +03001587 lockdep_assert_held(&ar->conf_mutex);
1588
Kalle Valob9ada652013-10-16 15:44:46 +03001589 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001590 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001591 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001592 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001593 return ret;
1594 }
1595
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001596 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001597 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1598 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001599 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001600 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001601 return ret;
1602 }
1603
Michal Kazior90046f52014-02-14 14:45:51 +01001604 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001606 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001607 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001608 return ret;
1609 }
1610
Michal Kaziora4841eb2014-08-28 09:59:39 +02001611 if (!sta->wme && !reassoc) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001612 arvif->num_legacy_stations++;
1613 ret = ath10k_recalc_rtscts_prot(arvif);
1614 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001615 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001616 arvif->vdev_id, ret);
1617 return ret;
1618 }
1619 }
1620
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1622 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001623 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001624 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001625 return ret;
1626 }
1627
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001628 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1629 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001630 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001631 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001632 return ret;
1633 }
1634
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 return ret;
1636}
1637
1638static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1639 struct ieee80211_sta *sta)
1640{
1641 int ret = 0;
1642
Michal Kazior548db542013-07-05 16:15:15 +03001643 lockdep_assert_held(&ar->conf_mutex);
1644
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001645 if (!sta->wme) {
1646 arvif->num_legacy_stations--;
1647 ret = ath10k_recalc_rtscts_prot(arvif);
1648 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001649 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001650 arvif->vdev_id, ret);
1651 return ret;
1652 }
1653 }
1654
Kalle Valo5e3dd152013-06-12 20:52:10 +03001655 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1656 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001657 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001658 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001659 return ret;
1660 }
1661
1662 return ret;
1663}
1664
1665/**************/
1666/* Regulatory */
1667/**************/
1668
1669static int ath10k_update_channel_list(struct ath10k *ar)
1670{
1671 struct ieee80211_hw *hw = ar->hw;
1672 struct ieee80211_supported_band **bands;
1673 enum ieee80211_band band;
1674 struct ieee80211_channel *channel;
1675 struct wmi_scan_chan_list_arg arg = {0};
1676 struct wmi_channel_arg *ch;
1677 bool passive;
1678 int len;
1679 int ret;
1680 int i;
1681
Michal Kazior548db542013-07-05 16:15:15 +03001682 lockdep_assert_held(&ar->conf_mutex);
1683
Kalle Valo5e3dd152013-06-12 20:52:10 +03001684 bands = hw->wiphy->bands;
1685 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1686 if (!bands[band])
1687 continue;
1688
1689 for (i = 0; i < bands[band]->n_channels; i++) {
1690 if (bands[band]->channels[i].flags &
1691 IEEE80211_CHAN_DISABLED)
1692 continue;
1693
1694 arg.n_channels++;
1695 }
1696 }
1697
1698 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1699 arg.channels = kzalloc(len, GFP_KERNEL);
1700 if (!arg.channels)
1701 return -ENOMEM;
1702
1703 ch = arg.channels;
1704 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1705 if (!bands[band])
1706 continue;
1707
1708 for (i = 0; i < bands[band]->n_channels; i++) {
1709 channel = &bands[band]->channels[i];
1710
1711 if (channel->flags & IEEE80211_CHAN_DISABLED)
1712 continue;
1713
1714 ch->allow_ht = true;
1715
1716 /* FIXME: when should we really allow VHT? */
1717 ch->allow_vht = true;
1718
1719 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001720 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001721
1722 ch->ht40plus =
1723 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1724
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001725 ch->chan_radar =
1726 !!(channel->flags & IEEE80211_CHAN_RADAR);
1727
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001728 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001729 ch->passive = passive;
1730
1731 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001732 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001733 ch->max_power = channel->max_power * 2;
1734 ch->max_reg_power = channel->max_reg_power * 2;
1735 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 ch->reg_class_id = 0; /* FIXME */
1737
1738 /* FIXME: why use only legacy modes, why not any
1739 * HT/VHT modes? Would that even make any
1740 * difference? */
1741 if (channel->band == IEEE80211_BAND_2GHZ)
1742 ch->mode = MODE_11G;
1743 else
1744 ch->mode = MODE_11A;
1745
1746 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1747 continue;
1748
Michal Kazior7aa7a722014-08-25 12:09:38 +02001749 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001750 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1751 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752 ch->freq, ch->max_power, ch->max_reg_power,
1753 ch->max_antenna_gain, ch->mode);
1754
1755 ch++;
1756 }
1757 }
1758
1759 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1760 kfree(arg.channels);
1761
1762 return ret;
1763}
1764
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001765static enum wmi_dfs_region
1766ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1767{
1768 switch (dfs_region) {
1769 case NL80211_DFS_UNSET:
1770 return WMI_UNINIT_DFS_DOMAIN;
1771 case NL80211_DFS_FCC:
1772 return WMI_FCC_DFS_DOMAIN;
1773 case NL80211_DFS_ETSI:
1774 return WMI_ETSI_DFS_DOMAIN;
1775 case NL80211_DFS_JP:
1776 return WMI_MKK4_DFS_DOMAIN;
1777 }
1778 return WMI_UNINIT_DFS_DOMAIN;
1779}
1780
Michal Kaziorf7843d72013-07-16 09:38:52 +02001781static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001782{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001785 enum wmi_dfs_region wmi_dfs_reg;
1786 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001787
Michal Kaziorf7843d72013-07-16 09:38:52 +02001788 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001789
1790 ret = ath10k_update_channel_list(ar);
1791 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001792 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001793
1794 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001795
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001796 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1797 nl_dfs_reg = ar->dfs_detector->region;
1798 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1799 } else {
1800 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1801 }
1802
Kalle Valo5e3dd152013-06-12 20:52:10 +03001803 /* Target allows setting up per-band regdomain but ath_common provides
1804 * a combined one only */
1805 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001806 regpair->reg_domain,
1807 regpair->reg_domain, /* 2ghz */
1808 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001809 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001810 regpair->reg_5ghz_ctl,
1811 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001812 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001813 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001814}
Michal Kazior548db542013-07-05 16:15:15 +03001815
Michal Kaziorf7843d72013-07-16 09:38:52 +02001816static void ath10k_reg_notifier(struct wiphy *wiphy,
1817 struct regulatory_request *request)
1818{
1819 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1820 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001821 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001822
1823 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1824
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001825 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001826 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001827 request->dfs_region);
1828 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1829 request->dfs_region);
1830 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001831 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001832 request->dfs_region);
1833 }
1834
Michal Kaziorf7843d72013-07-16 09:38:52 +02001835 mutex_lock(&ar->conf_mutex);
1836 if (ar->state == ATH10K_STATE_ON)
1837 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001838 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001839}
1840
1841/***************/
1842/* TX handlers */
1843/***************/
1844
Michal Kazior42c3aa62013-10-02 11:03:38 +02001845static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1846{
1847 if (ieee80211_is_mgmt(hdr->frame_control))
1848 return HTT_DATA_TX_EXT_TID_MGMT;
1849
1850 if (!ieee80211_is_data_qos(hdr->frame_control))
1851 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1852
1853 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1854 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1855
1856 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1857}
1858
Michal Kazior2b37c292014-09-02 11:00:22 +03001859static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001860{
Michal Kazior2b37c292014-09-02 11:00:22 +03001861 if (vif)
1862 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001863
Michal Kazior1bbc0972014-04-08 09:45:47 +03001864 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001865 return ar->monitor_vdev_id;
1866
Michal Kazior7aa7a722014-08-25 12:09:38 +02001867 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001868 return 0;
1869}
1870
Michal Kazior4b604552014-07-21 21:03:09 +03001871/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1872 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001873 */
Michal Kazior4b604552014-07-21 21:03:09 +03001874static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001875{
1876 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001877 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001878 u8 *qos_ctl;
1879
1880 if (!ieee80211_is_data_qos(hdr->frame_control))
1881 return;
1882
1883 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001884 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1885 skb->data, (void *)qos_ctl - (void *)skb->data);
1886 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001887
1888 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1889 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1890 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1891 * it is safe to downgrade to NullFunc.
1892 */
1893 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1894 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1895 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1896 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001897}
1898
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001899static void ath10k_tx_wep_key_work(struct work_struct *work)
1900{
1901 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1902 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001903 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001904 int ret, keyidx = arvif->def_wep_key_newidx;
1905
Michal Kazior911e6c02014-05-26 12:46:03 +03001906 mutex_lock(&arvif->ar->conf_mutex);
1907
1908 if (arvif->ar->state != ATH10K_STATE_ON)
1909 goto unlock;
1910
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001911 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001912 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001913
Michal Kazior7aa7a722014-08-25 12:09:38 +02001914 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001915 arvif->vdev_id, keyidx);
1916
1917 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1918 arvif->vdev_id,
1919 arvif->ar->wmi.vdev_param->def_keyid,
1920 keyidx);
1921 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001922 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001923 arvif->vdev_id,
1924 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001925 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001926 }
1927
1928 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001929
1930unlock:
1931 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001932}
1933
Michal Kazior4b604552014-07-21 21:03:09 +03001934static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1935 struct ieee80211_key_conf *key,
1936 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1939 struct ath10k *ar = arvif->ar;
1940 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 if (!ieee80211_has_protected(hdr->frame_control))
1943 return;
1944
1945 if (!key)
1946 return;
1947
1948 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1949 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1950 return;
1951
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001952 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 return;
1954
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001955 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1956 * queueing frames until key index is updated is not an option because
1957 * sk_buff may need more processing to be done, e.g. offchannel */
1958 arvif->def_wep_key_newidx = key->keyidx;
1959 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960}
1961
Michal Kazior4b604552014-07-21 21:03:09 +03001962static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1963 struct ieee80211_vif *vif,
1964 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965{
1966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1968
1969 /* This is case only for P2P_GO */
1970 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1971 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1972 return;
1973
1974 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1975 spin_lock_bh(&ar->data_lock);
1976 if (arvif->u.ap.noa_data)
1977 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1978 GFP_ATOMIC))
1979 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1980 arvif->u.ap.noa_data,
1981 arvif->u.ap.noa_len);
1982 spin_unlock_bh(&ar->data_lock);
1983 }
1984}
1985
1986static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1987{
1988 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001989 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990
Michal Kazior961d4c32013-08-09 10:13:34 +02001991 if (ar->htt.target_version_major >= 3) {
1992 /* Since HTT 3.0 there is no separate mgmt tx command */
1993 ret = ath10k_htt_tx(&ar->htt, skb);
1994 goto exit;
1995 }
1996
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001997 if (ieee80211_is_mgmt(hdr->frame_control)) {
1998 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1999 ar->fw_features)) {
2000 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2001 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002002 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002003 ret = -EBUSY;
2004 goto exit;
2005 }
2006
2007 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2008 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2009 } else {
2010 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2011 }
2012 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2013 ar->fw_features) &&
2014 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002015 /* FW does not report tx status properly for NullFunc frames
2016 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002017 * those frames when it detects link/beacon loss and depends
2018 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002019 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002020 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002021 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002022 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023
Michal Kazior961d4c32013-08-09 10:13:34 +02002024exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002025 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002026 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2027 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 ieee80211_free_txskb(ar->hw, skb);
2029 }
2030}
2031
2032void ath10k_offchan_tx_purge(struct ath10k *ar)
2033{
2034 struct sk_buff *skb;
2035
2036 for (;;) {
2037 skb = skb_dequeue(&ar->offchan_tx_queue);
2038 if (!skb)
2039 break;
2040
2041 ieee80211_free_txskb(ar->hw, skb);
2042 }
2043}
2044
2045void ath10k_offchan_tx_work(struct work_struct *work)
2046{
2047 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2048 struct ath10k_peer *peer;
2049 struct ieee80211_hdr *hdr;
2050 struct sk_buff *skb;
2051 const u8 *peer_addr;
2052 int vdev_id;
2053 int ret;
2054
2055 /* FW requirement: We must create a peer before FW will send out
2056 * an offchannel frame. Otherwise the frame will be stuck and
2057 * never transmitted. We delete the peer upon tx completion.
2058 * It is unlikely that a peer for offchannel tx will already be
2059 * present. However it may be in some rare cases so account for that.
2060 * Otherwise we might remove a legitimate peer and break stuff. */
2061
2062 for (;;) {
2063 skb = skb_dequeue(&ar->offchan_tx_queue);
2064 if (!skb)
2065 break;
2066
2067 mutex_lock(&ar->conf_mutex);
2068
Michal Kazior7aa7a722014-08-25 12:09:38 +02002069 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002070 skb);
2071
2072 hdr = (struct ieee80211_hdr *)skb->data;
2073 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002074 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075
2076 spin_lock_bh(&ar->data_lock);
2077 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2078 spin_unlock_bh(&ar->data_lock);
2079
2080 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002081 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002082 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083 peer_addr, vdev_id);
2084
2085 if (!peer) {
2086 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2087 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002088 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089 peer_addr, vdev_id, ret);
2090 }
2091
2092 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002093 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002094 ar->offchan_tx_skb = skb;
2095 spin_unlock_bh(&ar->data_lock);
2096
2097 ath10k_tx_htt(ar, skb);
2098
2099 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2100 3 * HZ);
2101 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002102 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002103 skb);
2104
2105 if (!peer) {
2106 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2107 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002108 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002109 peer_addr, vdev_id, ret);
2110 }
2111
2112 mutex_unlock(&ar->conf_mutex);
2113 }
2114}
2115
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002116void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2117{
2118 struct sk_buff *skb;
2119
2120 for (;;) {
2121 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2122 if (!skb)
2123 break;
2124
2125 ieee80211_free_txskb(ar->hw, skb);
2126 }
2127}
2128
2129void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2130{
2131 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2132 struct sk_buff *skb;
2133 int ret;
2134
2135 for (;;) {
2136 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2137 if (!skb)
2138 break;
2139
2140 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002141 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002142 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002143 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002144 ieee80211_free_txskb(ar->hw, skb);
2145 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002146 }
2147}
2148
Kalle Valo5e3dd152013-06-12 20:52:10 +03002149/************/
2150/* Scanning */
2151/************/
2152
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002153void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002154{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002155 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002157 switch (ar->scan.state) {
2158 case ATH10K_SCAN_IDLE:
2159 break;
2160 case ATH10K_SCAN_RUNNING:
2161 case ATH10K_SCAN_ABORTING:
2162 if (ar->scan.is_roc)
2163 ieee80211_remain_on_channel_expired(ar->hw);
2164 else
2165 ieee80211_scan_completed(ar->hw,
2166 (ar->scan.state ==
2167 ATH10K_SCAN_ABORTING));
2168 /* fall through */
2169 case ATH10K_SCAN_STARTING:
2170 ar->scan.state = ATH10K_SCAN_IDLE;
2171 ar->scan_channel = NULL;
2172 ath10k_offchan_tx_purge(ar);
2173 cancel_delayed_work(&ar->scan.timeout);
2174 complete_all(&ar->scan.completed);
2175 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002176 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002177}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002178
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002179void ath10k_scan_finish(struct ath10k *ar)
2180{
2181 spin_lock_bh(&ar->data_lock);
2182 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002183 spin_unlock_bh(&ar->data_lock);
2184}
2185
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002186static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187{
2188 struct wmi_stop_scan_arg arg = {
2189 .req_id = 1, /* FIXME */
2190 .req_type = WMI_SCAN_STOP_ONE,
2191 .u.scan_id = ATH10K_SCAN_ID,
2192 };
2193 int ret;
2194
2195 lockdep_assert_held(&ar->conf_mutex);
2196
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197 ret = ath10k_wmi_stop_scan(ar, &arg);
2198 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002199 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002200 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002201 }
2202
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002204 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002205 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002206 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002207 } else if (ret > 0) {
2208 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002210
2211out:
2212 /* Scan state should be updated upon scan completion but in case
2213 * firmware fails to deliver the event (for whatever reason) it is
2214 * desired to clean up scan state anyway. Firmware may have just
2215 * dropped the scan completion event delivery due to transport pipe
2216 * being overflown with data and/or it can recover on its own before
2217 * next scan request is submitted.
2218 */
2219 spin_lock_bh(&ar->data_lock);
2220 if (ar->scan.state != ATH10K_SCAN_IDLE)
2221 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222 spin_unlock_bh(&ar->data_lock);
2223
2224 return ret;
2225}
2226
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002227static void ath10k_scan_abort(struct ath10k *ar)
2228{
2229 int ret;
2230
2231 lockdep_assert_held(&ar->conf_mutex);
2232
2233 spin_lock_bh(&ar->data_lock);
2234
2235 switch (ar->scan.state) {
2236 case ATH10K_SCAN_IDLE:
2237 /* This can happen if timeout worker kicked in and called
2238 * abortion while scan completion was being processed.
2239 */
2240 break;
2241 case ATH10K_SCAN_STARTING:
2242 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002243 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002244 ath10k_scan_state_str(ar->scan.state),
2245 ar->scan.state);
2246 break;
2247 case ATH10K_SCAN_RUNNING:
2248 ar->scan.state = ATH10K_SCAN_ABORTING;
2249 spin_unlock_bh(&ar->data_lock);
2250
2251 ret = ath10k_scan_stop(ar);
2252 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002253 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002254
2255 spin_lock_bh(&ar->data_lock);
2256 break;
2257 }
2258
2259 spin_unlock_bh(&ar->data_lock);
2260}
2261
2262void ath10k_scan_timeout_work(struct work_struct *work)
2263{
2264 struct ath10k *ar = container_of(work, struct ath10k,
2265 scan.timeout.work);
2266
2267 mutex_lock(&ar->conf_mutex);
2268 ath10k_scan_abort(ar);
2269 mutex_unlock(&ar->conf_mutex);
2270}
2271
Kalle Valo5e3dd152013-06-12 20:52:10 +03002272static int ath10k_start_scan(struct ath10k *ar,
2273 const struct wmi_start_scan_arg *arg)
2274{
2275 int ret;
2276
2277 lockdep_assert_held(&ar->conf_mutex);
2278
2279 ret = ath10k_wmi_start_scan(ar, arg);
2280 if (ret)
2281 return ret;
2282
Kalle Valo5e3dd152013-06-12 20:52:10 +03002283 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2284 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002285 ret = ath10k_scan_stop(ar);
2286 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002287 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002288
2289 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002290 }
2291
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002292 /* Add a 200ms margin to account for event/command processing */
2293 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2294 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002295 return 0;
2296}
2297
2298/**********************/
2299/* mac80211 callbacks */
2300/**********************/
2301
2302static void ath10k_tx(struct ieee80211_hw *hw,
2303 struct ieee80211_tx_control *control,
2304 struct sk_buff *skb)
2305{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002307 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2308 struct ieee80211_vif *vif = info->control.vif;
2309 struct ieee80211_key_conf *key = info->control.hw_key;
2310 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002311
2312 /* We should disable CCK RATE due to P2P */
2313 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002314 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002315
Michal Kazior4b604552014-07-21 21:03:09 +03002316 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2317 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03002318 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002320 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002321 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2322 ath10k_tx_h_nwifi(hw, skb);
2323 ath10k_tx_h_update_wep_key(vif, key, skb);
2324 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2325 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002326 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327
Kalle Valo5e3dd152013-06-12 20:52:10 +03002328 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2329 spin_lock_bh(&ar->data_lock);
2330 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002331 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332 spin_unlock_bh(&ar->data_lock);
2333
Michal Kazior7aa7a722014-08-25 12:09:38 +02002334 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2335 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336
2337 skb_queue_tail(&ar->offchan_tx_queue, skb);
2338 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2339 return;
2340 }
2341
2342 ath10k_tx_htt(ar, skb);
2343}
2344
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002345/* Must not be called with conf_mutex held as workers can use that also. */
2346static void ath10k_drain_tx(struct ath10k *ar)
2347{
2348 /* make sure rcu-protected mac80211 tx path itself is drained */
2349 synchronize_net();
2350
2351 ath10k_offchan_tx_purge(ar);
2352 ath10k_mgmt_over_wmi_tx_purge(ar);
2353
2354 cancel_work_sync(&ar->offchan_tx_work);
2355 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2356}
2357
Michal Kazioraffd3212013-07-16 09:54:35 +02002358void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002359{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002360 struct ath10k_vif *arvif;
2361
Michal Kazior818bdd12013-07-16 09:38:57 +02002362 lockdep_assert_held(&ar->conf_mutex);
2363
Michal Kazior19337472014-08-28 12:58:16 +02002364 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2365 ar->filter_flags = 0;
2366 ar->monitor = false;
2367
2368 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002369 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002370
2371 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002372
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002373 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002374 ath10k_peer_cleanup_all(ar);
2375 ath10k_core_stop(ar);
2376 ath10k_hif_power_down(ar);
2377
2378 spin_lock_bh(&ar->data_lock);
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002379 list_for_each_entry(arvif, &ar->arvifs, list) {
2380 if (!arvif->beacon)
2381 continue;
2382
2383 dma_unmap_single(arvif->ar->dev,
2384 ATH10K_SKB_CB(arvif->beacon)->paddr,
2385 arvif->beacon->len, DMA_TO_DEVICE);
2386 dev_kfree_skb_any(arvif->beacon);
2387 arvif->beacon = NULL;
2388 }
Michal Kazior818bdd12013-07-16 09:38:57 +02002389 spin_unlock_bh(&ar->data_lock);
2390}
2391
Ben Greear46acf7b2014-05-16 17:15:38 +03002392static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2393{
2394 struct ath10k *ar = hw->priv;
2395
2396 mutex_lock(&ar->conf_mutex);
2397
2398 if (ar->cfg_tx_chainmask) {
2399 *tx_ant = ar->cfg_tx_chainmask;
2400 *rx_ant = ar->cfg_rx_chainmask;
2401 } else {
2402 *tx_ant = ar->supp_tx_chainmask;
2403 *rx_ant = ar->supp_rx_chainmask;
2404 }
2405
2406 mutex_unlock(&ar->conf_mutex);
2407
2408 return 0;
2409}
2410
2411static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2412{
2413 int ret;
2414
2415 lockdep_assert_held(&ar->conf_mutex);
2416
2417 ar->cfg_tx_chainmask = tx_ant;
2418 ar->cfg_rx_chainmask = rx_ant;
2419
2420 if ((ar->state != ATH10K_STATE_ON) &&
2421 (ar->state != ATH10K_STATE_RESTARTED))
2422 return 0;
2423
2424 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2425 tx_ant);
2426 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002427 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002428 ret, tx_ant);
2429 return ret;
2430 }
2431
2432 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2433 rx_ant);
2434 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002435 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03002436 ret, rx_ant);
2437 return ret;
2438 }
2439
2440 return 0;
2441}
2442
2443static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2444{
2445 struct ath10k *ar = hw->priv;
2446 int ret;
2447
2448 mutex_lock(&ar->conf_mutex);
2449 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2450 mutex_unlock(&ar->conf_mutex);
2451 return ret;
2452}
2453
Kalle Valo5e3dd152013-06-12 20:52:10 +03002454static int ath10k_start(struct ieee80211_hw *hw)
2455{
2456 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002457 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002459 /*
2460 * This makes sense only when restarting hw. It is harmless to call
2461 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2462 * commands will be submitted while restarting.
2463 */
2464 ath10k_drain_tx(ar);
2465
Michal Kazior548db542013-07-05 16:15:15 +03002466 mutex_lock(&ar->conf_mutex);
2467
Michal Kaziorc5058f52014-05-26 12:46:03 +03002468 switch (ar->state) {
2469 case ATH10K_STATE_OFF:
2470 ar->state = ATH10K_STATE_ON;
2471 break;
2472 case ATH10K_STATE_RESTARTING:
2473 ath10k_halt(ar);
2474 ar->state = ATH10K_STATE_RESTARTED;
2475 break;
2476 case ATH10K_STATE_ON:
2477 case ATH10K_STATE_RESTARTED:
2478 case ATH10K_STATE_WEDGED:
2479 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002480 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002481 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03002482 case ATH10K_STATE_UTF:
2483 ret = -EBUSY;
2484 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002485 }
2486
2487 ret = ath10k_hif_power_up(ar);
2488 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002489 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002490 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002491 }
2492
Kalle Valo43d2a302014-09-10 18:23:30 +03002493 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02002494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002496 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002497 }
2498
Bartosz Markowski226a3392013-09-26 17:47:16 +02002499 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002500 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002501 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002502 goto err_core_stop;
2503 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002504
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002505 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002506 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002507 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002508 goto err_core_stop;
2509 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002510
Ben Greear46acf7b2014-05-16 17:15:38 +03002511 if (ar->cfg_tx_chainmask)
2512 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2513 ar->cfg_rx_chainmask);
2514
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002515 /*
2516 * By default FW set ARP frames ac to voice (6). In that case ARP
2517 * exchange is not working properly for UAPSD enabled AP. ARP requests
2518 * which arrives with access category 0 are processed by network stack
2519 * and send back with access category 0, but FW changes access category
2520 * to 6. Set ARP frames access category to best effort (0) solves
2521 * this problem.
2522 */
2523
2524 ret = ath10k_wmi_pdev_set_param(ar,
2525 ar->wmi.pdev_param->arp_ac_override, 0);
2526 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002527 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002528 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002529 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002530 }
2531
Michal Kaziord6500972014-04-08 09:56:09 +03002532 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002533 ath10k_regd_update(ar);
2534
Simon Wunderlich855aed12014-08-02 09:12:54 +03002535 ath10k_spectral_start(ar);
2536
Michal Kaziorae254432014-05-26 12:46:02 +03002537 mutex_unlock(&ar->conf_mutex);
2538 return 0;
2539
2540err_core_stop:
2541 ath10k_core_stop(ar);
2542
2543err_power_down:
2544 ath10k_hif_power_down(ar);
2545
2546err_off:
2547 ar->state = ATH10K_STATE_OFF;
2548
2549err:
Michal Kazior548db542013-07-05 16:15:15 +03002550 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002551 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552}
2553
2554static void ath10k_stop(struct ieee80211_hw *hw)
2555{
2556 struct ath10k *ar = hw->priv;
2557
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002558 ath10k_drain_tx(ar);
2559
Michal Kazior548db542013-07-05 16:15:15 +03002560 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002561 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002562 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002563 ar->state = ATH10K_STATE_OFF;
2564 }
Michal Kazior548db542013-07-05 16:15:15 +03002565 mutex_unlock(&ar->conf_mutex);
2566
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002567 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002568 cancel_work_sync(&ar->restart_work);
2569}
2570
Michal Kaziorad088bf2013-10-16 15:44:46 +03002571static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002572{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002573 struct ath10k_vif *arvif;
2574 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002575
2576 lockdep_assert_held(&ar->conf_mutex);
2577
Michal Kaziorad088bf2013-10-16 15:44:46 +03002578 list_for_each_entry(arvif, &ar->arvifs, list) {
2579 ret = ath10k_mac_vif_setup_ps(arvif);
2580 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002581 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002582 break;
2583 }
2584 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002585
Michal Kaziorad088bf2013-10-16 15:44:46 +03002586 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002587}
2588
Michal Kaziorc930f742014-01-23 11:38:25 +01002589static const char *chandef_get_width(enum nl80211_chan_width width)
2590{
2591 switch (width) {
2592 case NL80211_CHAN_WIDTH_20_NOHT:
2593 return "20 (noht)";
2594 case NL80211_CHAN_WIDTH_20:
2595 return "20";
2596 case NL80211_CHAN_WIDTH_40:
2597 return "40";
2598 case NL80211_CHAN_WIDTH_80:
2599 return "80";
2600 case NL80211_CHAN_WIDTH_80P80:
2601 return "80+80";
2602 case NL80211_CHAN_WIDTH_160:
2603 return "160";
2604 case NL80211_CHAN_WIDTH_5:
2605 return "5";
2606 case NL80211_CHAN_WIDTH_10:
2607 return "10";
2608 }
2609 return "?";
2610}
2611
2612static void ath10k_config_chan(struct ath10k *ar)
2613{
2614 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002615 int ret;
2616
2617 lockdep_assert_held(&ar->conf_mutex);
2618
Michal Kazior7aa7a722014-08-25 12:09:38 +02002619 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002620 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2621 ar->chandef.chan->center_freq,
2622 ar->chandef.center_freq1,
2623 ar->chandef.center_freq2,
2624 chandef_get_width(ar->chandef.width));
2625
2626 /* First stop monitor interface. Some FW versions crash if there's a
2627 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002628 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002629 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002630
2631 list_for_each_entry(arvif, &ar->arvifs, list) {
2632 if (!arvif->is_started)
2633 continue;
2634
Michal Kaziordc55e302014-07-29 12:53:36 +03002635 if (!arvif->is_up)
2636 continue;
2637
Michal Kaziorc930f742014-01-23 11:38:25 +01002638 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2639 continue;
2640
Michal Kaziordc55e302014-07-29 12:53:36 +03002641 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002642 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002643 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002644 arvif->vdev_id, ret);
2645 continue;
2646 }
2647 }
2648
Michal Kaziordc55e302014-07-29 12:53:36 +03002649 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002650
2651 list_for_each_entry(arvif, &ar->arvifs, list) {
2652 if (!arvif->is_started)
2653 continue;
2654
2655 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2656 continue;
2657
Michal Kaziordc55e302014-07-29 12:53:36 +03002658 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002659 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002660 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002661 arvif->vdev_id, ret);
2662 continue;
2663 }
2664
2665 if (!arvif->is_up)
2666 continue;
2667
2668 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2669 arvif->bssid);
2670 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002671 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002672 arvif->vdev_id, ret);
2673 continue;
2674 }
2675 }
2676
Michal Kazior19337472014-08-28 12:58:16 +02002677 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002678}
2679
Kalle Valo5e3dd152013-06-12 20:52:10 +03002680static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2681{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 struct ath10k *ar = hw->priv;
2683 struct ieee80211_conf *conf = &hw->conf;
2684 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002685 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002686
2687 mutex_lock(&ar->conf_mutex);
2688
2689 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002690 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002691 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002692 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002693 conf->chandef.chan->flags,
2694 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002695
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 spin_lock_bh(&ar->data_lock);
2697 ar->rx_channel = conf->chandef.chan;
2698 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002699
Michal Kaziord6500972014-04-08 09:56:09 +03002700 ar->radar_enabled = conf->radar_enabled;
2701 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002702
2703 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2704 ar->chandef = conf->chandef;
2705 ath10k_config_chan(ar);
2706 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002707 }
2708
Michal Kazior5474efe2013-10-23 04:02:15 -07002709 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002710 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002711 hw->conf.power_level);
2712
2713 param = ar->wmi.pdev_param->txpower_limit2g;
2714 ret = ath10k_wmi_pdev_set_param(ar, param,
2715 hw->conf.power_level * 2);
2716 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002717 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002718 hw->conf.power_level, ret);
2719
2720 param = ar->wmi.pdev_param->txpower_limit5g;
2721 ret = ath10k_wmi_pdev_set_param(ar, param,
2722 hw->conf.power_level * 2);
2723 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002724 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002725 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002726 }
2727
Michal Kazioraffd3212013-07-16 09:54:35 +02002728 if (changed & IEEE80211_CONF_CHANGE_PS)
2729 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002730
2731 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002732 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2733 ret = ath10k_monitor_recalc(ar);
2734 if (ret)
2735 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002736 }
2737
2738 mutex_unlock(&ar->conf_mutex);
2739 return ret;
2740}
2741
2742/*
2743 * TODO:
2744 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2745 * because we will send mgmt frames without CCK. This requirement
2746 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2747 * in the TX packet.
2748 */
2749static int ath10k_add_interface(struct ieee80211_hw *hw,
2750 struct ieee80211_vif *vif)
2751{
2752 struct ath10k *ar = hw->priv;
2753 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2754 enum wmi_sta_powersave_param param;
2755 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002756 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002758 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759
2760 mutex_lock(&ar->conf_mutex);
2761
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002762 memset(arvif, 0, sizeof(*arvif));
2763
Kalle Valo5e3dd152013-06-12 20:52:10 +03002764 arvif->ar = ar;
2765 arvif->vif = vif;
2766
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002767 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002768 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002769
Ben Greeara9aefb32014-08-12 11:02:19 +03002770 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002771 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002772 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03002773 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002774 }
Ben Greeara9aefb32014-08-12 11:02:19 +03002775 bit = ffs(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776
2777 arvif->vdev_id = bit - 1;
2778 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779
2780 if (ar->p2p)
2781 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2782
2783 switch (vif->type) {
2784 case NL80211_IFTYPE_UNSPECIFIED:
2785 case NL80211_IFTYPE_STATION:
2786 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2787 if (vif->p2p)
2788 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2789 break;
2790 case NL80211_IFTYPE_ADHOC:
2791 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2792 break;
2793 case NL80211_IFTYPE_AP:
2794 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2795
2796 if (vif->p2p)
2797 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2798 break;
2799 case NL80211_IFTYPE_MONITOR:
2800 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2801 break;
2802 default:
2803 WARN_ON(1);
2804 break;
2805 }
2806
Michal Kazior7aa7a722014-08-25 12:09:38 +02002807 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002808 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2809
2810 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2811 arvif->vdev_subtype, vif->addr);
2812 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002813 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002814 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002815 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002816 }
2817
Ben Greeara9aefb32014-08-12 11:02:19 +03002818 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002819 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002820
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002821 vdev_param = ar->wmi.vdev_param->def_keyid;
2822 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002823 arvif->def_wep_key_idx);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002824 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002825 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002826 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002827 goto err_vdev_delete;
2828 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002829
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002830 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2831 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002832 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002833 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03002834 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002835 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002836 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002837 goto err_vdev_delete;
2838 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002839
2840 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2841 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002843 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002844 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002845 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002846 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002847
Kalle Valo5a13e762014-01-20 11:01:46 +02002848 ret = ath10k_mac_set_kickout(arvif);
2849 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002850 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002851 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002852 goto err_peer_delete;
2853 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854 }
2855
2856 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2857 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2858 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2859 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2860 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002861 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002862 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002863 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002864 goto err_peer_delete;
2865 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866
2867 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2868 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2869 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2870 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002871 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002872 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002873 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002874 goto err_peer_delete;
2875 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002876
2877 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2878 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2879 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2880 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002881 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002882 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002883 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002884 goto err_peer_delete;
2885 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002886 }
2887
Michal Kazior424121c2013-07-22 14:13:31 +02002888 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002890 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002891 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002892 goto err_peer_delete;
2893 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002894
Michal Kazior424121c2013-07-22 14:13:31 +02002895 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002896 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002897 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002898 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002899 goto err_peer_delete;
2900 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002901
Kalle Valo5e3dd152013-06-12 20:52:10 +03002902 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002903 return 0;
2904
2905err_peer_delete:
2906 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2907 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2908
2909err_vdev_delete:
2910 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greeara9aefb32014-08-12 11:02:19 +03002911 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002912 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03002913
2914err:
2915 mutex_unlock(&ar->conf_mutex);
2916
Kalle Valo5e3dd152013-06-12 20:52:10 +03002917 return ret;
2918}
2919
2920static void ath10k_remove_interface(struct ieee80211_hw *hw,
2921 struct ieee80211_vif *vif)
2922{
2923 struct ath10k *ar = hw->priv;
2924 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2925 int ret;
2926
2927 mutex_lock(&ar->conf_mutex);
2928
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002929 cancel_work_sync(&arvif->wep_key_work);
2930
Michal Kaziored543882013-09-13 14:16:56 +02002931 spin_lock_bh(&ar->data_lock);
2932 if (arvif->beacon) {
Michal Kaziorec6bc552014-04-23 19:30:05 +03002933 dma_unmap_single(arvif->ar->dev,
2934 ATH10K_SKB_CB(arvif->beacon)->paddr,
2935 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02002936 dev_kfree_skb_any(arvif->beacon);
2937 arvif->beacon = NULL;
2938 }
Simon Wunderlich855aed12014-08-02 09:12:54 +03002939
Michal Kaziored543882013-09-13 14:16:56 +02002940 spin_unlock_bh(&ar->data_lock);
2941
Simon Wunderlich855aed12014-08-02 09:12:54 +03002942 ret = ath10k_spectral_vif_stop(arvif);
2943 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03002945 arvif->vdev_id, ret);
2946
Ben Greeara9aefb32014-08-12 11:02:19 +03002947 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002948 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002949
2950 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2951 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2952 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002953 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002954 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955
2956 kfree(arvif->u.ap.noa_data);
2957 }
2958
Michal Kazior7aa7a722014-08-25 12:09:38 +02002959 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002960 arvif->vdev_id);
2961
Kalle Valo5e3dd152013-06-12 20:52:10 +03002962 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2963 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002964 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002965 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002966
Kalle Valo5e3dd152013-06-12 20:52:10 +03002967 ath10k_peer_cleanup(ar, arvif->vdev_id);
2968
2969 mutex_unlock(&ar->conf_mutex);
2970}
2971
2972/*
2973 * FIXME: Has to be verified.
2974 */
2975#define SUPPORTED_FILTERS \
2976 (FIF_PROMISC_IN_BSS | \
2977 FIF_ALLMULTI | \
2978 FIF_CONTROL | \
2979 FIF_PSPOLL | \
2980 FIF_OTHER_BSS | \
2981 FIF_BCN_PRBRESP_PROMISC | \
2982 FIF_PROBE_REQ | \
2983 FIF_FCSFAIL)
2984
2985static void ath10k_configure_filter(struct ieee80211_hw *hw,
2986 unsigned int changed_flags,
2987 unsigned int *total_flags,
2988 u64 multicast)
2989{
2990 struct ath10k *ar = hw->priv;
2991 int ret;
2992
2993 mutex_lock(&ar->conf_mutex);
2994
2995 changed_flags &= SUPPORTED_FILTERS;
2996 *total_flags &= SUPPORTED_FILTERS;
2997 ar->filter_flags = *total_flags;
2998
Michal Kazior19337472014-08-28 12:58:16 +02002999 ret = ath10k_monitor_recalc(ar);
3000 if (ret)
3001 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003002
3003 mutex_unlock(&ar->conf_mutex);
3004}
3005
3006static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3007 struct ieee80211_vif *vif,
3008 struct ieee80211_bss_conf *info,
3009 u32 changed)
3010{
3011 struct ath10k *ar = hw->priv;
3012 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3013 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03003014 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003015
3016 mutex_lock(&ar->conf_mutex);
3017
3018 if (changed & BSS_CHANGED_IBSS)
3019 ath10k_control_ibss(arvif, info, vif->addr);
3020
3021 if (changed & BSS_CHANGED_BEACON_INT) {
3022 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003023 vdev_param = ar->wmi.vdev_param->beacon_interval;
3024 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003025 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003026 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003027 "mac vdev %d beacon_interval %d\n",
3028 arvif->vdev_id, arvif->beacon_interval);
3029
Kalle Valo5e3dd152013-06-12 20:52:10 +03003030 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003031 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003032 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003033 }
3034
3035 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003036 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003037 "vdev %d set beacon tx mode to staggered\n",
3038 arvif->vdev_id);
3039
Bartosz Markowski226a3392013-09-26 17:47:16 +02003040 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3041 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003042 WMI_BEACON_STAGGERED_MODE);
3043 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003044 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003045 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003046 }
3047
John W. Linvilleb70727e2013-06-13 13:34:29 -04003048 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003049 arvif->dtim_period = info->dtim_period;
3050
Michal Kazior7aa7a722014-08-25 12:09:38 +02003051 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003052 "mac vdev %d dtim_period %d\n",
3053 arvif->vdev_id, arvif->dtim_period);
3054
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003055 vdev_param = ar->wmi.vdev_param->dtim_period;
3056 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003057 arvif->dtim_period);
3058 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003059 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003060 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003061 }
3062
3063 if (changed & BSS_CHANGED_SSID &&
3064 vif->type == NL80211_IFTYPE_AP) {
3065 arvif->u.ap.ssid_len = info->ssid_len;
3066 if (info->ssid_len)
3067 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3068 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3069 }
3070
Michal Kazior7b161a72014-05-26 12:46:03 +03003071 /*
3072 * Firmware manages AP self-peer internally so make sure to not create
3073 * it in driver. Otherwise AP self-peer deletion may timeout later.
3074 */
3075 if (changed & BSS_CHANGED_BSSID &&
3076 vif->type != NL80211_IFTYPE_AP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003077 if (!is_zero_ether_addr(info->bssid)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003078 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003079 "mac vdev %d create peer %pM\n",
3080 arvif->vdev_id, info->bssid);
3081
Kalle Valo5e3dd152013-06-12 20:52:10 +03003082 ret = ath10k_peer_create(ar, arvif->vdev_id,
3083 info->bssid);
3084 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003085 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003086 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003087
3088 if (vif->type == NL80211_IFTYPE_STATION) {
3089 /*
3090 * this is never erased as we it for crypto key
3091 * clearing; this is FW requirement
3092 */
Michal Kaziorc930f742014-01-23 11:38:25 +01003093 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094
Michal Kazior7aa7a722014-08-25 12:09:38 +02003095 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003096 "mac vdev %d start %pM\n",
3097 arvif->vdev_id, info->bssid);
3098
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003100 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003101 ath10k_warn(ar, "failed to start vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003102 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02003103 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01003104 }
3105
3106 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003107 }
3108
3109 /*
3110 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3111 * so driver need to store it. It is needed when leaving
3112 * IBSS in order to remove BSSID peer.
3113 */
3114 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01003115 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003116 ETH_ALEN);
3117 }
3118 }
3119
3120 if (changed & BSS_CHANGED_BEACON_ENABLED)
3121 ath10k_control_beaconing(arvif, info);
3122
3123 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003124 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003125 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003126 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003127
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003128 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003130 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003131 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 }
3133
3134 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003135 if (info->use_short_slot)
3136 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3137
3138 else
3139 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3140
Michal Kazior7aa7a722014-08-25 12:09:38 +02003141 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003142 arvif->vdev_id, slottime);
3143
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003144 vdev_param = ar->wmi.vdev_param->slot_time;
3145 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003146 slottime);
3147 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003148 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003149 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150 }
3151
3152 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003153 if (info->use_short_preamble)
3154 preamble = WMI_VDEV_PREAMBLE_SHORT;
3155 else
3156 preamble = WMI_VDEV_PREAMBLE_LONG;
3157
Michal Kazior7aa7a722014-08-25 12:09:38 +02003158 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003159 "mac vdev %d preamble %dn",
3160 arvif->vdev_id, preamble);
3161
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003162 vdev_param = ar->wmi.vdev_param->preamble;
3163 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164 preamble);
3165 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003166 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003167 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168 }
3169
3170 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003171 if (info->assoc) {
3172 /* Workaround: Make sure monitor vdev is not running
3173 * when associating to prevent some firmware revisions
3174 * (e.g. 10.1 and 10.2) from crashing.
3175 */
3176 if (ar->monitor_started)
3177 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003178 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003179 ath10k_monitor_recalc(ar);
3180 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003181 }
3182
Kalle Valo75459e32014-02-13 18:13:12 +02003183exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184 mutex_unlock(&ar->conf_mutex);
3185}
3186
3187static int ath10k_hw_scan(struct ieee80211_hw *hw,
3188 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003189 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190{
3191 struct ath10k *ar = hw->priv;
3192 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003193 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003194 struct wmi_start_scan_arg arg;
3195 int ret = 0;
3196 int i;
3197
3198 mutex_lock(&ar->conf_mutex);
3199
3200 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003201 switch (ar->scan.state) {
3202 case ATH10K_SCAN_IDLE:
3203 reinit_completion(&ar->scan.started);
3204 reinit_completion(&ar->scan.completed);
3205 ar->scan.state = ATH10K_SCAN_STARTING;
3206 ar->scan.is_roc = false;
3207 ar->scan.vdev_id = arvif->vdev_id;
3208 ret = 0;
3209 break;
3210 case ATH10K_SCAN_STARTING:
3211 case ATH10K_SCAN_RUNNING:
3212 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003213 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003214 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003215 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 spin_unlock_bh(&ar->data_lock);
3217
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003218 if (ret)
3219 goto exit;
3220
Kalle Valo5e3dd152013-06-12 20:52:10 +03003221 memset(&arg, 0, sizeof(arg));
3222 ath10k_wmi_start_scan_init(ar, &arg);
3223 arg.vdev_id = arvif->vdev_id;
3224 arg.scan_id = ATH10K_SCAN_ID;
3225
3226 if (!req->no_cck)
3227 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3228
3229 if (req->ie_len) {
3230 arg.ie_len = req->ie_len;
3231 memcpy(arg.ie, req->ie, arg.ie_len);
3232 }
3233
3234 if (req->n_ssids) {
3235 arg.n_ssids = req->n_ssids;
3236 for (i = 0; i < arg.n_ssids; i++) {
3237 arg.ssids[i].len = req->ssids[i].ssid_len;
3238 arg.ssids[i].ssid = req->ssids[i].ssid;
3239 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003240 } else {
3241 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242 }
3243
3244 if (req->n_channels) {
3245 arg.n_channels = req->n_channels;
3246 for (i = 0; i < arg.n_channels; i++)
3247 arg.channels[i] = req->channels[i]->center_freq;
3248 }
3249
3250 ret = ath10k_start_scan(ar, &arg);
3251 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003252 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003253 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003254 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003255 spin_unlock_bh(&ar->data_lock);
3256 }
3257
3258exit:
3259 mutex_unlock(&ar->conf_mutex);
3260 return ret;
3261}
3262
3263static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3264 struct ieee80211_vif *vif)
3265{
3266 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267
3268 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003269 cancel_delayed_work_sync(&ar->scan.timeout);
3270 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003271 mutex_unlock(&ar->conf_mutex);
3272}
3273
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003274static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3275 struct ath10k_vif *arvif,
3276 enum set_key_cmd cmd,
3277 struct ieee80211_key_conf *key)
3278{
3279 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3280 int ret;
3281
3282 /* 10.1 firmware branch requires default key index to be set to group
3283 * key index after installing it. Otherwise FW/HW Txes corrupted
3284 * frames with multi-vif APs. This is not required for main firmware
3285 * branch (e.g. 636).
3286 *
3287 * FIXME: This has been tested only in AP. It remains unknown if this
3288 * is required for multi-vif STA interfaces on 10.1 */
3289
3290 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3291 return;
3292
3293 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3294 return;
3295
3296 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3297 return;
3298
3299 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3300 return;
3301
3302 if (cmd != SET_KEY)
3303 return;
3304
3305 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3306 key->keyidx);
3307 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003308 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003309 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003310}
3311
Kalle Valo5e3dd152013-06-12 20:52:10 +03003312static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3313 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3314 struct ieee80211_key_conf *key)
3315{
3316 struct ath10k *ar = hw->priv;
3317 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3318 struct ath10k_peer *peer;
3319 const u8 *peer_addr;
3320 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3321 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3322 int ret = 0;
3323
3324 if (key->keyidx > WMI_MAX_KEY_INDEX)
3325 return -ENOSPC;
3326
3327 mutex_lock(&ar->conf_mutex);
3328
3329 if (sta)
3330 peer_addr = sta->addr;
3331 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3332 peer_addr = vif->bss_conf.bssid;
3333 else
3334 peer_addr = vif->addr;
3335
3336 key->hw_key_idx = key->keyidx;
3337
3338 /* the peer should not disappear in mid-way (unless FW goes awry) since
3339 * we already hold conf_mutex. we just make sure its there now. */
3340 spin_lock_bh(&ar->data_lock);
3341 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3342 spin_unlock_bh(&ar->data_lock);
3343
3344 if (!peer) {
3345 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003346 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003347 peer_addr);
3348 ret = -EOPNOTSUPP;
3349 goto exit;
3350 } else {
3351 /* if the peer doesn't exist there is no key to disable
3352 * anymore */
3353 goto exit;
3354 }
3355 }
3356
3357 if (is_wep) {
3358 if (cmd == SET_KEY)
3359 arvif->wep_keys[key->keyidx] = key;
3360 else
3361 arvif->wep_keys[key->keyidx] = NULL;
3362
3363 if (cmd == DISABLE_KEY)
3364 ath10k_clear_vdev_key(arvif, key);
3365 }
3366
3367 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3368 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003369 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003370 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003371 goto exit;
3372 }
3373
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003374 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3375
Kalle Valo5e3dd152013-06-12 20:52:10 +03003376 spin_lock_bh(&ar->data_lock);
3377 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3378 if (peer && cmd == SET_KEY)
3379 peer->keys[key->keyidx] = key;
3380 else if (peer && cmd == DISABLE_KEY)
3381 peer->keys[key->keyidx] = NULL;
3382 else if (peer == NULL)
3383 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003384 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 spin_unlock_bh(&ar->data_lock);
3386
3387exit:
3388 mutex_unlock(&ar->conf_mutex);
3389 return ret;
3390}
3391
Michal Kazior9797feb2014-02-14 14:49:48 +01003392static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3393{
3394 struct ath10k *ar;
3395 struct ath10k_vif *arvif;
3396 struct ath10k_sta *arsta;
3397 struct ieee80211_sta *sta;
3398 u32 changed, bw, nss, smps;
3399 int err;
3400
3401 arsta = container_of(wk, struct ath10k_sta, update_wk);
3402 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3403 arvif = arsta->arvif;
3404 ar = arvif->ar;
3405
3406 spin_lock_bh(&ar->data_lock);
3407
3408 changed = arsta->changed;
3409 arsta->changed = 0;
3410
3411 bw = arsta->bw;
3412 nss = arsta->nss;
3413 smps = arsta->smps;
3414
3415 spin_unlock_bh(&ar->data_lock);
3416
3417 mutex_lock(&ar->conf_mutex);
3418
3419 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003420 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003421 sta->addr, bw);
3422
3423 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3424 WMI_PEER_CHAN_WIDTH, bw);
3425 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003426 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003427 sta->addr, bw, err);
3428 }
3429
3430 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003431 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003432 sta->addr, nss);
3433
3434 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3435 WMI_PEER_NSS, nss);
3436 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003437 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003438 sta->addr, nss, err);
3439 }
3440
3441 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003442 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003443 sta->addr, smps);
3444
3445 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3446 WMI_PEER_SMPS_STATE, smps);
3447 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003448 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003449 sta->addr, smps, err);
3450 }
3451
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003452 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003453 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003454 sta->addr);
3455
3456 err = ath10k_station_assoc(ar, arvif, sta, true);
3457 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003458 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003459 sta->addr);
3460 }
3461
Michal Kazior9797feb2014-02-14 14:49:48 +01003462 mutex_unlock(&ar->conf_mutex);
3463}
3464
Kalle Valo5e3dd152013-06-12 20:52:10 +03003465static int ath10k_sta_state(struct ieee80211_hw *hw,
3466 struct ieee80211_vif *vif,
3467 struct ieee80211_sta *sta,
3468 enum ieee80211_sta_state old_state,
3469 enum ieee80211_sta_state new_state)
3470{
3471 struct ath10k *ar = hw->priv;
3472 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003473 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003474 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475 int ret = 0;
3476
Michal Kazior76f90022014-02-25 09:29:57 +02003477 if (old_state == IEEE80211_STA_NOTEXIST &&
3478 new_state == IEEE80211_STA_NONE) {
3479 memset(arsta, 0, sizeof(*arsta));
3480 arsta->arvif = arvif;
3481 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3482 }
3483
Michal Kazior9797feb2014-02-14 14:49:48 +01003484 /* cancel must be done outside the mutex to avoid deadlock */
3485 if ((old_state == IEEE80211_STA_NONE &&
3486 new_state == IEEE80211_STA_NOTEXIST))
3487 cancel_work_sync(&arsta->update_wk);
3488
Kalle Valo5e3dd152013-06-12 20:52:10 +03003489 mutex_lock(&ar->conf_mutex);
3490
3491 if (old_state == IEEE80211_STA_NOTEXIST &&
3492 new_state == IEEE80211_STA_NONE &&
3493 vif->type != NL80211_IFTYPE_STATION) {
3494 /*
3495 * New station addition.
3496 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003497 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3498 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3499 else
3500 max_num_peers = TARGET_NUM_PEERS;
3501
3502 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003503 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003504 ar->num_peers, max_num_peers);
3505 ret = -ENOBUFS;
3506 goto exit;
3507 }
3508
Michal Kazior7aa7a722014-08-25 12:09:38 +02003509 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003510 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3511 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003512
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3514 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003515 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 -08003516 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517 } else if ((old_state == IEEE80211_STA_NONE &&
3518 new_state == IEEE80211_STA_NOTEXIST)) {
3519 /*
3520 * Existing station deletion.
3521 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003522 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003523 "mac vdev %d peer delete %pM (sta gone)\n",
3524 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003525 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3526 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003527 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003528 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003529
3530 if (vif->type == NL80211_IFTYPE_STATION)
3531 ath10k_bss_disassoc(hw, vif);
3532 } else if (old_state == IEEE80211_STA_AUTH &&
3533 new_state == IEEE80211_STA_ASSOC &&
3534 (vif->type == NL80211_IFTYPE_AP ||
3535 vif->type == NL80211_IFTYPE_ADHOC)) {
3536 /*
3537 * New association.
3538 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003539 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003540 sta->addr);
3541
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003542 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003543 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003544 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003545 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 } else if (old_state == IEEE80211_STA_ASSOC &&
3547 new_state == IEEE80211_STA_AUTH &&
3548 (vif->type == NL80211_IFTYPE_AP ||
3549 vif->type == NL80211_IFTYPE_ADHOC)) {
3550 /*
3551 * Disassociation.
3552 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003553 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003554 sta->addr);
3555
Kalle Valo5e3dd152013-06-12 20:52:10 +03003556 ret = ath10k_station_disassoc(ar, arvif, sta);
3557 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003558 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003559 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003561exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 mutex_unlock(&ar->conf_mutex);
3563 return ret;
3564}
3565
3566static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03003567 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568{
3569 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3570 u32 value = 0;
3571 int ret = 0;
3572
Michal Kazior548db542013-07-05 16:15:15 +03003573 lockdep_assert_held(&ar->conf_mutex);
3574
Kalle Valo5e3dd152013-06-12 20:52:10 +03003575 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3576 return 0;
3577
3578 switch (ac) {
3579 case IEEE80211_AC_VO:
3580 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3581 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3582 break;
3583 case IEEE80211_AC_VI:
3584 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3585 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3586 break;
3587 case IEEE80211_AC_BE:
3588 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3589 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3590 break;
3591 case IEEE80211_AC_BK:
3592 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3593 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3594 break;
3595 }
3596
3597 if (enable)
3598 arvif->u.sta.uapsd |= value;
3599 else
3600 arvif->u.sta.uapsd &= ~value;
3601
3602 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3603 WMI_STA_PS_PARAM_UAPSD,
3604 arvif->u.sta.uapsd);
3605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003606 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003607 goto exit;
3608 }
3609
3610 if (arvif->u.sta.uapsd)
3611 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3612 else
3613 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3614
3615 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3616 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3617 value);
3618 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003619 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620
3621exit:
3622 return ret;
3623}
3624
3625static int ath10k_conf_tx(struct ieee80211_hw *hw,
3626 struct ieee80211_vif *vif, u16 ac,
3627 const struct ieee80211_tx_queue_params *params)
3628{
3629 struct ath10k *ar = hw->priv;
3630 struct wmi_wmm_params_arg *p = NULL;
3631 int ret;
3632
3633 mutex_lock(&ar->conf_mutex);
3634
3635 switch (ac) {
3636 case IEEE80211_AC_VO:
3637 p = &ar->wmm_params.ac_vo;
3638 break;
3639 case IEEE80211_AC_VI:
3640 p = &ar->wmm_params.ac_vi;
3641 break;
3642 case IEEE80211_AC_BE:
3643 p = &ar->wmm_params.ac_be;
3644 break;
3645 case IEEE80211_AC_BK:
3646 p = &ar->wmm_params.ac_bk;
3647 break;
3648 }
3649
3650 if (WARN_ON(!p)) {
3651 ret = -EINVAL;
3652 goto exit;
3653 }
3654
3655 p->cwmin = params->cw_min;
3656 p->cwmax = params->cw_max;
3657 p->aifs = params->aifs;
3658
3659 /*
3660 * The channel time duration programmed in the HW is in absolute
3661 * microseconds, while mac80211 gives the txop in units of
3662 * 32 microseconds.
3663 */
3664 p->txop = params->txop * 32;
3665
3666 /* FIXME: FW accepts wmm params per hw, not per vif */
3667 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3668 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003669 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003670 goto exit;
3671 }
3672
3673 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3674 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003675 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003676
3677exit:
3678 mutex_unlock(&ar->conf_mutex);
3679 return ret;
3680}
3681
3682#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3683
3684static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3685 struct ieee80211_vif *vif,
3686 struct ieee80211_channel *chan,
3687 int duration,
3688 enum ieee80211_roc_type type)
3689{
3690 struct ath10k *ar = hw->priv;
3691 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3692 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003693 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003694
3695 mutex_lock(&ar->conf_mutex);
3696
3697 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003698 switch (ar->scan.state) {
3699 case ATH10K_SCAN_IDLE:
3700 reinit_completion(&ar->scan.started);
3701 reinit_completion(&ar->scan.completed);
3702 reinit_completion(&ar->scan.on_channel);
3703 ar->scan.state = ATH10K_SCAN_STARTING;
3704 ar->scan.is_roc = true;
3705 ar->scan.vdev_id = arvif->vdev_id;
3706 ar->scan.roc_freq = chan->center_freq;
3707 ret = 0;
3708 break;
3709 case ATH10K_SCAN_STARTING:
3710 case ATH10K_SCAN_RUNNING:
3711 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003712 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003713 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003714 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715 spin_unlock_bh(&ar->data_lock);
3716
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003717 if (ret)
3718 goto exit;
3719
Kalle Valo5e3dd152013-06-12 20:52:10 +03003720 memset(&arg, 0, sizeof(arg));
3721 ath10k_wmi_start_scan_init(ar, &arg);
3722 arg.vdev_id = arvif->vdev_id;
3723 arg.scan_id = ATH10K_SCAN_ID;
3724 arg.n_channels = 1;
3725 arg.channels[0] = chan->center_freq;
3726 arg.dwell_time_active = duration;
3727 arg.dwell_time_passive = duration;
3728 arg.max_scan_time = 2 * duration;
3729 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3730 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3731
3732 ret = ath10k_start_scan(ar, &arg);
3733 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003734 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003736 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003737 spin_unlock_bh(&ar->data_lock);
3738 goto exit;
3739 }
3740
3741 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3742 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003743 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003744
3745 ret = ath10k_scan_stop(ar);
3746 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003747 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003748
Kalle Valo5e3dd152013-06-12 20:52:10 +03003749 ret = -ETIMEDOUT;
3750 goto exit;
3751 }
3752
3753 ret = 0;
3754exit:
3755 mutex_unlock(&ar->conf_mutex);
3756 return ret;
3757}
3758
3759static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3760{
3761 struct ath10k *ar = hw->priv;
3762
3763 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003764 cancel_delayed_work_sync(&ar->scan.timeout);
3765 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003766 mutex_unlock(&ar->conf_mutex);
3767
3768 return 0;
3769}
3770
3771/*
3772 * Both RTS and Fragmentation threshold are interface-specific
3773 * in ath10k, but device-specific in mac80211.
3774 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003775
3776static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3777{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003778 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003779 struct ath10k_vif *arvif;
3780 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003781
Michal Kaziorad088bf2013-10-16 15:44:46 +03003782 mutex_lock(&ar->conf_mutex);
3783 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003784 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003785 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003786
Michal Kaziorad088bf2013-10-16 15:44:46 +03003787 ret = ath10k_mac_set_rts(arvif, value);
3788 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003789 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003790 arvif->vdev_id, ret);
3791 break;
3792 }
3793 }
3794 mutex_unlock(&ar->conf_mutex);
3795
3796 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003797}
3798
3799static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3800{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003801 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003802 struct ath10k_vif *arvif;
3803 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003804
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003806 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003807 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003808 arvif->vdev_id, value);
3809
3810 ret = ath10k_mac_set_rts(arvif, value);
3811 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003812 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003813 arvif->vdev_id, ret);
3814 break;
3815 }
3816 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003817 mutex_unlock(&ar->conf_mutex);
3818
Michal Kaziorad088bf2013-10-16 15:44:46 +03003819 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003820}
3821
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003822static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3823 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003824{
3825 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003826 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827 int ret;
3828
3829 /* mac80211 doesn't care if we really xmit queued frames or not
3830 * we'll collect those frames either way if we stop/delete vdevs */
3831 if (drop)
3832 return;
3833
Michal Kazior548db542013-07-05 16:15:15 +03003834 mutex_lock(&ar->conf_mutex);
3835
Michal Kazioraffd3212013-07-16 09:54:35 +02003836 if (ar->state == ATH10K_STATE_WEDGED)
3837 goto skip;
3838
Michal Kazioredb82362013-07-05 16:15:14 +03003839 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003840 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003841
Michal Kazioredb82362013-07-05 16:15:14 +03003842 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003843 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003844 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003845
3846 skip = (ar->state == ATH10K_STATE_WEDGED);
3847
3848 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003850
3851 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003852 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003853 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003854
Michal Kazioraffd3212013-07-16 09:54:35 +02003855skip:
Michal Kazior548db542013-07-05 16:15:15 +03003856 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003857}
3858
3859/* TODO: Implement this function properly
3860 * For now it is needed to reply to Probe Requests in IBSS mode.
3861 * Propably we need this information from FW.
3862 */
3863static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3864{
3865 return 1;
3866}
3867
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003868#ifdef CONFIG_PM
3869static int ath10k_suspend(struct ieee80211_hw *hw,
3870 struct cfg80211_wowlan *wowlan)
3871{
3872 struct ath10k *ar = hw->priv;
3873 int ret;
3874
Marek Puzyniak9042e172014-02-10 17:14:23 +01003875 mutex_lock(&ar->conf_mutex);
3876
Marek Puzyniak00f54822014-02-10 17:14:24 +01003877 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003878 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003879 if (ret == -ETIMEDOUT)
3880 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003881 ret = 1;
3882 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003883 }
3884
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003885 ret = ath10k_hif_suspend(ar);
3886 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003887 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003888 goto resume;
3889 }
3890
Marek Puzyniak9042e172014-02-10 17:14:23 +01003891 ret = 0;
3892 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003893resume:
3894 ret = ath10k_wmi_pdev_resume_target(ar);
3895 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003896 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003897
3898 ret = 1;
3899exit:
3900 mutex_unlock(&ar->conf_mutex);
3901 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003902}
3903
3904static int ath10k_resume(struct ieee80211_hw *hw)
3905{
3906 struct ath10k *ar = hw->priv;
3907 int ret;
3908
Marek Puzyniak9042e172014-02-10 17:14:23 +01003909 mutex_lock(&ar->conf_mutex);
3910
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003911 ret = ath10k_hif_resume(ar);
3912 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003913 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003914 ret = 1;
3915 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003916 }
3917
3918 ret = ath10k_wmi_pdev_resume_target(ar);
3919 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003920 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003921 ret = 1;
3922 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003923 }
3924
Marek Puzyniak9042e172014-02-10 17:14:23 +01003925 ret = 0;
3926exit:
3927 mutex_unlock(&ar->conf_mutex);
3928 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003929}
3930#endif
3931
Michal Kazioraffd3212013-07-16 09:54:35 +02003932static void ath10k_restart_complete(struct ieee80211_hw *hw)
3933{
3934 struct ath10k *ar = hw->priv;
3935
3936 mutex_lock(&ar->conf_mutex);
3937
3938 /* If device failed to restart it will be in a different state, e.g.
3939 * ATH10K_STATE_WEDGED */
3940 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003941 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02003942 ar->state = ATH10K_STATE_ON;
3943 }
3944
3945 mutex_unlock(&ar->conf_mutex);
3946}
3947
Michal Kazior2e1dea42013-07-31 10:32:40 +02003948static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3949 struct survey_info *survey)
3950{
3951 struct ath10k *ar = hw->priv;
3952 struct ieee80211_supported_band *sband;
3953 struct survey_info *ar_survey = &ar->survey[idx];
3954 int ret = 0;
3955
3956 mutex_lock(&ar->conf_mutex);
3957
3958 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3959 if (sband && idx >= sband->n_channels) {
3960 idx -= sband->n_channels;
3961 sband = NULL;
3962 }
3963
3964 if (!sband)
3965 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3966
3967 if (!sband || idx >= sband->n_channels) {
3968 ret = -ENOENT;
3969 goto exit;
3970 }
3971
3972 spin_lock_bh(&ar->data_lock);
3973 memcpy(survey, ar_survey, sizeof(*survey));
3974 spin_unlock_bh(&ar->data_lock);
3975
3976 survey->channel = &sband->channels[idx];
3977
3978exit:
3979 mutex_unlock(&ar->conf_mutex);
3980 return ret;
3981}
3982
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003983/* Helper table for legacy fixed_rate/bitrate_mask */
3984static const u8 cck_ofdm_rate[] = {
3985 /* CCK */
3986 3, /* 1Mbps */
3987 2, /* 2Mbps */
3988 1, /* 5.5Mbps */
3989 0, /* 11Mbps */
3990 /* OFDM */
3991 3, /* 6Mbps */
3992 7, /* 9Mbps */
3993 2, /* 12Mbps */
3994 6, /* 18Mbps */
3995 1, /* 24Mbps */
3996 5, /* 36Mbps */
3997 0, /* 48Mbps */
3998 4, /* 54Mbps */
3999};
4000
4001/* Check if only one bit set */
4002static int ath10k_check_single_mask(u32 mask)
4003{
4004 int bit;
4005
4006 bit = ffs(mask);
4007 if (!bit)
4008 return 0;
4009
4010 mask &= ~BIT(bit - 1);
4011 if (mask)
4012 return 2;
4013
4014 return 1;
4015}
4016
4017static bool
4018ath10k_default_bitrate_mask(struct ath10k *ar,
4019 enum ieee80211_band band,
4020 const struct cfg80211_bitrate_mask *mask)
4021{
4022 u32 legacy = 0x00ff;
4023 u8 ht = 0xff, i;
4024 u16 vht = 0x3ff;
4025
4026 switch (band) {
4027 case IEEE80211_BAND_2GHZ:
4028 legacy = 0x00fff;
4029 vht = 0;
4030 break;
4031 case IEEE80211_BAND_5GHZ:
4032 break;
4033 default:
4034 return false;
4035 }
4036
4037 if (mask->control[band].legacy != legacy)
4038 return false;
4039
4040 for (i = 0; i < ar->num_rf_chains; i++)
4041 if (mask->control[band].ht_mcs[i] != ht)
4042 return false;
4043
4044 for (i = 0; i < ar->num_rf_chains; i++)
4045 if (mask->control[band].vht_mcs[i] != vht)
4046 return false;
4047
4048 return true;
4049}
4050
4051static bool
4052ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4053 enum ieee80211_band band,
4054 u8 *fixed_nss)
4055{
4056 int ht_nss = 0, vht_nss = 0, i;
4057
4058 /* check legacy */
4059 if (ath10k_check_single_mask(mask->control[band].legacy))
4060 return false;
4061
4062 /* check HT */
4063 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4064 if (mask->control[band].ht_mcs[i] == 0xff)
4065 continue;
4066 else if (mask->control[band].ht_mcs[i] == 0x00)
4067 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004068
4069 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004070 }
4071
4072 ht_nss = i;
4073
4074 /* check VHT */
4075 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4076 if (mask->control[band].vht_mcs[i] == 0x03ff)
4077 continue;
4078 else if (mask->control[band].vht_mcs[i] == 0x0000)
4079 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03004080
4081 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004082 }
4083
4084 vht_nss = i;
4085
4086 if (ht_nss > 0 && vht_nss > 0)
4087 return false;
4088
4089 if (ht_nss)
4090 *fixed_nss = ht_nss;
4091 else if (vht_nss)
4092 *fixed_nss = vht_nss;
4093 else
4094 return false;
4095
4096 return true;
4097}
4098
4099static bool
4100ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4101 enum ieee80211_band band,
4102 enum wmi_rate_preamble *preamble)
4103{
4104 int legacy = 0, ht = 0, vht = 0, i;
4105
4106 *preamble = WMI_RATE_PREAMBLE_OFDM;
4107
4108 /* check legacy */
4109 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4110 if (legacy > 1)
4111 return false;
4112
4113 /* check HT */
4114 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4115 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4116 if (ht > 1)
4117 return false;
4118
4119 /* check VHT */
4120 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4121 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4122 if (vht > 1)
4123 return false;
4124
4125 /* Currently we support only one fixed_rate */
4126 if ((legacy + ht + vht) != 1)
4127 return false;
4128
4129 if (ht)
4130 *preamble = WMI_RATE_PREAMBLE_HT;
4131 else if (vht)
4132 *preamble = WMI_RATE_PREAMBLE_VHT;
4133
4134 return true;
4135}
4136
4137static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004138ath10k_bitrate_mask_rate(struct ath10k *ar,
4139 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004140 enum ieee80211_band band,
4141 u8 *fixed_rate,
4142 u8 *fixed_nss)
4143{
4144 u8 rate = 0, pream = 0, nss = 0, i;
4145 enum wmi_rate_preamble preamble;
4146
4147 /* Check if single rate correct */
4148 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4149 return false;
4150
4151 pream = preamble;
4152
4153 switch (preamble) {
4154 case WMI_RATE_PREAMBLE_CCK:
4155 case WMI_RATE_PREAMBLE_OFDM:
4156 i = ffs(mask->control[band].legacy) - 1;
4157
4158 if (band == IEEE80211_BAND_2GHZ && i < 4)
4159 pream = WMI_RATE_PREAMBLE_CCK;
4160
4161 if (band == IEEE80211_BAND_5GHZ)
4162 i += 4;
4163
4164 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4165 return false;
4166
4167 rate = cck_ofdm_rate[i];
4168 break;
4169 case WMI_RATE_PREAMBLE_HT:
4170 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4171 if (mask->control[band].ht_mcs[i])
4172 break;
4173
4174 if (i == IEEE80211_HT_MCS_MASK_LEN)
4175 return false;
4176
4177 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4178 nss = i;
4179 break;
4180 case WMI_RATE_PREAMBLE_VHT:
4181 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4182 if (mask->control[band].vht_mcs[i])
4183 break;
4184
4185 if (i == NL80211_VHT_NSS_MAX)
4186 return false;
4187
4188 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4189 nss = i;
4190 break;
4191 }
4192
4193 *fixed_nss = nss + 1;
4194 nss <<= 4;
4195 pream <<= 6;
4196
Michal Kazior7aa7a722014-08-25 12:09:38 +02004197 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 +01004198 pream, nss, rate);
4199
4200 *fixed_rate = pream | nss | rate;
4201
4202 return true;
4203}
4204
Michal Kazior7aa7a722014-08-25 12:09:38 +02004205static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4206 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004207 enum ieee80211_band band,
4208 u8 *fixed_rate,
4209 u8 *fixed_nss)
4210{
4211 /* First check full NSS mask, if we can simply limit NSS */
4212 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4213 return true;
4214
4215 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004216 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004217}
4218
4219static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4220 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004221 u8 fixed_nss,
4222 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004223{
4224 struct ath10k *ar = arvif->ar;
4225 u32 vdev_param;
4226 int ret = 0;
4227
4228 mutex_lock(&ar->conf_mutex);
4229
4230 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004231 arvif->fixed_nss == fixed_nss &&
4232 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004233 goto exit;
4234
4235 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004237
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004238 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004239 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004240
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004241 vdev_param = ar->wmi.vdev_param->fixed_rate;
4242 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4243 vdev_param, fixed_rate);
4244 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004245 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004246 fixed_rate, ret);
4247 ret = -EINVAL;
4248 goto exit;
4249 }
4250
4251 arvif->fixed_rate = fixed_rate;
4252
4253 vdev_param = ar->wmi.vdev_param->nss;
4254 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4255 vdev_param, fixed_nss);
4256
4257 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004258 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004259 fixed_nss, ret);
4260 ret = -EINVAL;
4261 goto exit;
4262 }
4263
4264 arvif->fixed_nss = fixed_nss;
4265
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004266 vdev_param = ar->wmi.vdev_param->sgi;
4267 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4268 force_sgi);
4269
4270 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004271 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004272 force_sgi, ret);
4273 ret = -EINVAL;
4274 goto exit;
4275 }
4276
4277 arvif->force_sgi = force_sgi;
4278
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004279exit:
4280 mutex_unlock(&ar->conf_mutex);
4281 return ret;
4282}
4283
4284static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4285 struct ieee80211_vif *vif,
4286 const struct cfg80211_bitrate_mask *mask)
4287{
4288 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4289 struct ath10k *ar = arvif->ar;
4290 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4291 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4292 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004293 u8 force_sgi;
4294
4295 force_sgi = mask->control[band].gi;
4296 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4297 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004298
4299 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004300 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004301 &fixed_rate,
4302 &fixed_nss))
4303 return -EINVAL;
4304 }
4305
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004306 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004307 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004308 return -EINVAL;
4309 }
4310
4311 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4312 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004313}
4314
Michal Kazior9797feb2014-02-14 14:49:48 +01004315static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4316 struct ieee80211_vif *vif,
4317 struct ieee80211_sta *sta,
4318 u32 changed)
4319{
4320 struct ath10k *ar = hw->priv;
4321 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4322 u32 bw, smps;
4323
4324 spin_lock_bh(&ar->data_lock);
4325
Michal Kazior7aa7a722014-08-25 12:09:38 +02004326 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004327 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4328 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4329 sta->smps_mode);
4330
4331 if (changed & IEEE80211_RC_BW_CHANGED) {
4332 bw = WMI_PEER_CHWIDTH_20MHZ;
4333
4334 switch (sta->bandwidth) {
4335 case IEEE80211_STA_RX_BW_20:
4336 bw = WMI_PEER_CHWIDTH_20MHZ;
4337 break;
4338 case IEEE80211_STA_RX_BW_40:
4339 bw = WMI_PEER_CHWIDTH_40MHZ;
4340 break;
4341 case IEEE80211_STA_RX_BW_80:
4342 bw = WMI_PEER_CHWIDTH_80MHZ;
4343 break;
4344 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004345 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004346 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004347 bw = WMI_PEER_CHWIDTH_20MHZ;
4348 break;
4349 }
4350
4351 arsta->bw = bw;
4352 }
4353
4354 if (changed & IEEE80211_RC_NSS_CHANGED)
4355 arsta->nss = sta->rx_nss;
4356
4357 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4358 smps = WMI_PEER_SMPS_PS_NONE;
4359
4360 switch (sta->smps_mode) {
4361 case IEEE80211_SMPS_AUTOMATIC:
4362 case IEEE80211_SMPS_OFF:
4363 smps = WMI_PEER_SMPS_PS_NONE;
4364 break;
4365 case IEEE80211_SMPS_STATIC:
4366 smps = WMI_PEER_SMPS_STATIC;
4367 break;
4368 case IEEE80211_SMPS_DYNAMIC:
4369 smps = WMI_PEER_SMPS_DYNAMIC;
4370 break;
4371 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004372 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004373 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004374 smps = WMI_PEER_SMPS_PS_NONE;
4375 break;
4376 }
4377
4378 arsta->smps = smps;
4379 }
4380
Michal Kazior9797feb2014-02-14 14:49:48 +01004381 arsta->changed |= changed;
4382
4383 spin_unlock_bh(&ar->data_lock);
4384
4385 ieee80211_queue_work(hw, &arsta->update_wk);
4386}
4387
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004388static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4389{
4390 /*
4391 * FIXME: Return 0 for time being. Need to figure out whether FW
4392 * has the API to fetch 64-bit local TSF
4393 */
4394
4395 return 0;
4396}
4397
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004398static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4399 struct ieee80211_vif *vif,
4400 enum ieee80211_ampdu_mlme_action action,
4401 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4402 u8 buf_size)
4403{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004404 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004405 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4406
Michal Kazior7aa7a722014-08-25 12:09:38 +02004407 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 +02004408 arvif->vdev_id, sta->addr, tid, action);
4409
4410 switch (action) {
4411 case IEEE80211_AMPDU_RX_START:
4412 case IEEE80211_AMPDU_RX_STOP:
4413 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4414 * creation/removal. Do we need to verify this?
4415 */
4416 return 0;
4417 case IEEE80211_AMPDU_TX_START:
4418 case IEEE80211_AMPDU_TX_STOP_CONT:
4419 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4420 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4421 case IEEE80211_AMPDU_TX_OPERATIONAL:
4422 /* Firmware offloads Tx aggregation entirely so deny mac80211
4423 * Tx aggregation requests.
4424 */
4425 return -EOPNOTSUPP;
4426 }
4427
4428 return -EINVAL;
4429}
4430
Kalle Valo5e3dd152013-06-12 20:52:10 +03004431static const struct ieee80211_ops ath10k_ops = {
4432 .tx = ath10k_tx,
4433 .start = ath10k_start,
4434 .stop = ath10k_stop,
4435 .config = ath10k_config,
4436 .add_interface = ath10k_add_interface,
4437 .remove_interface = ath10k_remove_interface,
4438 .configure_filter = ath10k_configure_filter,
4439 .bss_info_changed = ath10k_bss_info_changed,
4440 .hw_scan = ath10k_hw_scan,
4441 .cancel_hw_scan = ath10k_cancel_hw_scan,
4442 .set_key = ath10k_set_key,
4443 .sta_state = ath10k_sta_state,
4444 .conf_tx = ath10k_conf_tx,
4445 .remain_on_channel = ath10k_remain_on_channel,
4446 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4447 .set_rts_threshold = ath10k_set_rts_threshold,
4448 .set_frag_threshold = ath10k_set_frag_threshold,
4449 .flush = ath10k_flush,
4450 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03004451 .set_antenna = ath10k_set_antenna,
4452 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004453 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004454 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004455 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004456 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004457 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004458 .ampdu_action = ath10k_ampdu_action,
Kalle Valo43d2a302014-09-10 18:23:30 +03004459
4460 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4461
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004462#ifdef CONFIG_PM
4463 .suspend = ath10k_suspend,
4464 .resume = ath10k_resume,
4465#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004466};
4467
4468#define RATETAB_ENT(_rate, _rateid, _flags) { \
4469 .bitrate = (_rate), \
4470 .flags = (_flags), \
4471 .hw_value = (_rateid), \
4472}
4473
4474#define CHAN2G(_channel, _freq, _flags) { \
4475 .band = IEEE80211_BAND_2GHZ, \
4476 .hw_value = (_channel), \
4477 .center_freq = (_freq), \
4478 .flags = (_flags), \
4479 .max_antenna_gain = 0, \
4480 .max_power = 30, \
4481}
4482
4483#define CHAN5G(_channel, _freq, _flags) { \
4484 .band = IEEE80211_BAND_5GHZ, \
4485 .hw_value = (_channel), \
4486 .center_freq = (_freq), \
4487 .flags = (_flags), \
4488 .max_antenna_gain = 0, \
4489 .max_power = 30, \
4490}
4491
4492static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4493 CHAN2G(1, 2412, 0),
4494 CHAN2G(2, 2417, 0),
4495 CHAN2G(3, 2422, 0),
4496 CHAN2G(4, 2427, 0),
4497 CHAN2G(5, 2432, 0),
4498 CHAN2G(6, 2437, 0),
4499 CHAN2G(7, 2442, 0),
4500 CHAN2G(8, 2447, 0),
4501 CHAN2G(9, 2452, 0),
4502 CHAN2G(10, 2457, 0),
4503 CHAN2G(11, 2462, 0),
4504 CHAN2G(12, 2467, 0),
4505 CHAN2G(13, 2472, 0),
4506 CHAN2G(14, 2484, 0),
4507};
4508
4509static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004510 CHAN5G(36, 5180, 0),
4511 CHAN5G(40, 5200, 0),
4512 CHAN5G(44, 5220, 0),
4513 CHAN5G(48, 5240, 0),
4514 CHAN5G(52, 5260, 0),
4515 CHAN5G(56, 5280, 0),
4516 CHAN5G(60, 5300, 0),
4517 CHAN5G(64, 5320, 0),
4518 CHAN5G(100, 5500, 0),
4519 CHAN5G(104, 5520, 0),
4520 CHAN5G(108, 5540, 0),
4521 CHAN5G(112, 5560, 0),
4522 CHAN5G(116, 5580, 0),
4523 CHAN5G(120, 5600, 0),
4524 CHAN5G(124, 5620, 0),
4525 CHAN5G(128, 5640, 0),
4526 CHAN5G(132, 5660, 0),
4527 CHAN5G(136, 5680, 0),
4528 CHAN5G(140, 5700, 0),
4529 CHAN5G(149, 5745, 0),
4530 CHAN5G(153, 5765, 0),
4531 CHAN5G(157, 5785, 0),
4532 CHAN5G(161, 5805, 0),
4533 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004534};
4535
4536static struct ieee80211_rate ath10k_rates[] = {
4537 /* CCK */
4538 RATETAB_ENT(10, 0x82, 0),
4539 RATETAB_ENT(20, 0x84, 0),
4540 RATETAB_ENT(55, 0x8b, 0),
4541 RATETAB_ENT(110, 0x96, 0),
4542 /* OFDM */
4543 RATETAB_ENT(60, 0x0c, 0),
4544 RATETAB_ENT(90, 0x12, 0),
4545 RATETAB_ENT(120, 0x18, 0),
4546 RATETAB_ENT(180, 0x24, 0),
4547 RATETAB_ENT(240, 0x30, 0),
4548 RATETAB_ENT(360, 0x48, 0),
4549 RATETAB_ENT(480, 0x60, 0),
4550 RATETAB_ENT(540, 0x6c, 0),
4551};
4552
4553#define ath10k_a_rates (ath10k_rates + 4)
4554#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4555#define ath10k_g_rates (ath10k_rates + 0)
4556#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4557
Michal Kaziore7b54192014-08-07 11:03:27 +02004558struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004559{
4560 struct ieee80211_hw *hw;
4561 struct ath10k *ar;
4562
Michal Kaziore7b54192014-08-07 11:03:27 +02004563 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004564 if (!hw)
4565 return NULL;
4566
4567 ar = hw->priv;
4568 ar->hw = hw;
4569
4570 return ar;
4571}
4572
4573void ath10k_mac_destroy(struct ath10k *ar)
4574{
4575 ieee80211_free_hw(ar->hw);
4576}
4577
4578static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4579 {
4580 .max = 8,
4581 .types = BIT(NL80211_IFTYPE_STATION)
4582 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004583 },
4584 {
4585 .max = 3,
4586 .types = BIT(NL80211_IFTYPE_P2P_GO)
4587 },
4588 {
4589 .max = 7,
4590 .types = BIT(NL80211_IFTYPE_AP)
4591 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592};
4593
Bartosz Markowskif2595092013-12-10 16:20:39 +01004594static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004595 {
4596 .max = 8,
4597 .types = BIT(NL80211_IFTYPE_AP)
4598 },
4599};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004600
4601static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4602 {
4603 .limits = ath10k_if_limits,
4604 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4605 .max_interfaces = 8,
4606 .num_different_channels = 1,
4607 .beacon_int_infra_match = true,
4608 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004609};
4610
4611static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004612 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004613 .limits = ath10k_10x_if_limits,
4614 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004615 .max_interfaces = 8,
4616 .num_different_channels = 1,
4617 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004618#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004619 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4620 BIT(NL80211_CHAN_WIDTH_20) |
4621 BIT(NL80211_CHAN_WIDTH_40) |
4622 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004623#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004624 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004625};
4626
4627static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4628{
4629 struct ieee80211_sta_vht_cap vht_cap = {0};
4630 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004631 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004632
4633 vht_cap.vht_supported = 1;
4634 vht_cap.cap = ar->vht_cap_info;
4635
Michal Kazior8865bee42013-07-24 12:36:46 +02004636 mcs_map = 0;
4637 for (i = 0; i < 8; i++) {
4638 if (i < ar->num_rf_chains)
4639 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4640 else
4641 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4642 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004643
4644 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4645 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4646
4647 return vht_cap;
4648}
4649
4650static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4651{
4652 int i;
4653 struct ieee80211_sta_ht_cap ht_cap = {0};
4654
4655 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4656 return ht_cap;
4657
4658 ht_cap.ht_supported = 1;
4659 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4660 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4661 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4662 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4663 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4664
4665 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4666 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4667
4668 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4669 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4670
4671 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4672 u32 smps;
4673
4674 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4675 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4676
4677 ht_cap.cap |= smps;
4678 }
4679
4680 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4681 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4682
4683 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4684 u32 stbc;
4685
4686 stbc = ar->ht_cap_info;
4687 stbc &= WMI_HT_CAP_RX_STBC;
4688 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4689 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4690 stbc &= IEEE80211_HT_CAP_RX_STBC;
4691
4692 ht_cap.cap |= stbc;
4693 }
4694
4695 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4696 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4697
4698 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4699 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4700
4701 /* max AMSDU is implicitly taken from vht_cap_info */
4702 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4703 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4704
Michal Kazior8865bee42013-07-24 12:36:46 +02004705 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004706 ht_cap.mcs.rx_mask[i] = 0xFF;
4707
4708 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4709
4710 return ht_cap;
4711}
4712
Kalle Valo5e3dd152013-06-12 20:52:10 +03004713static void ath10k_get_arvif_iter(void *data, u8 *mac,
4714 struct ieee80211_vif *vif)
4715{
4716 struct ath10k_vif_iter *arvif_iter = data;
4717 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4718
4719 if (arvif->vdev_id == arvif_iter->vdev_id)
4720 arvif_iter->arvif = arvif;
4721}
4722
4723struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4724{
4725 struct ath10k_vif_iter arvif_iter;
4726 u32 flags;
4727
4728 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4729 arvif_iter.vdev_id = vdev_id;
4730
4731 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4732 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4733 flags,
4734 ath10k_get_arvif_iter,
4735 &arvif_iter);
4736 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004737 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004738 return NULL;
4739 }
4740
4741 return arvif_iter.arvif;
4742}
4743
4744int ath10k_mac_register(struct ath10k *ar)
4745{
4746 struct ieee80211_supported_band *band;
4747 struct ieee80211_sta_vht_cap vht_cap;
4748 struct ieee80211_sta_ht_cap ht_cap;
4749 void *channels;
4750 int ret;
4751
4752 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4753
4754 SET_IEEE80211_DEV(ar->hw, ar->dev);
4755
4756 ht_cap = ath10k_get_ht_cap(ar);
4757 vht_cap = ath10k_create_vht_cap(ar);
4758
4759 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4760 channels = kmemdup(ath10k_2ghz_channels,
4761 sizeof(ath10k_2ghz_channels),
4762 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004763 if (!channels) {
4764 ret = -ENOMEM;
4765 goto err_free;
4766 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004767
4768 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4769 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4770 band->channels = channels;
4771 band->n_bitrates = ath10k_g_rates_size;
4772 band->bitrates = ath10k_g_rates;
4773 band->ht_cap = ht_cap;
4774
4775 /* vht is not supported in 2.4 GHz */
4776
4777 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4778 }
4779
4780 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4781 channels = kmemdup(ath10k_5ghz_channels,
4782 sizeof(ath10k_5ghz_channels),
4783 GFP_KERNEL);
4784 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004785 ret = -ENOMEM;
4786 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004787 }
4788
4789 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4790 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4791 band->channels = channels;
4792 band->n_bitrates = ath10k_a_rates_size;
4793 band->bitrates = ath10k_a_rates;
4794 band->ht_cap = ht_cap;
4795 band->vht_cap = vht_cap;
4796 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4797 }
4798
4799 ar->hw->wiphy->interface_modes =
4800 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004801 BIT(NL80211_IFTYPE_AP);
4802
Ben Greear46acf7b2014-05-16 17:15:38 +03004803 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4804 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4805 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4806 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4807 } else {
4808 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4809 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4810 }
4811
4812 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4813 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4814
Bartosz Markowskid3541812013-12-10 16:20:40 +01004815 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4816 ar->hw->wiphy->interface_modes |=
4817 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4818 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004819
4820 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4821 IEEE80211_HW_SUPPORTS_PS |
4822 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4823 IEEE80211_HW_SUPPORTS_UAPSD |
4824 IEEE80211_HW_MFP_CAPABLE |
4825 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4826 IEEE80211_HW_HAS_RATE_CONTROL |
4827 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004828 IEEE80211_HW_AP_LINK_PS |
4829 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004830
Michal Kazior1f8bb152013-09-18 14:43:22 +02004831 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4832 * bytes is used for padding/alignment if necessary. */
4833 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4834
Kalle Valo5e3dd152013-06-12 20:52:10 +03004835 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4836 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4837
4838 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4839 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4840 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4841 }
4842
4843 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4844 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4845
4846 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004847 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004848
Kalle Valo5e3dd152013-06-12 20:52:10 +03004849 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4850
4851 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004852 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004853 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4854
4855 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4856 /*
4857 * on LL hardware queues are managed entirely by the FW
4858 * so we only advertise to mac we can do the queues thing
4859 */
4860 ar->hw->queues = 4;
4861
Bartosz Markowskif2595092013-12-10 16:20:39 +01004862 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4863 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4864 ar->hw->wiphy->n_iface_combinations =
4865 ARRAY_SIZE(ath10k_10x_if_comb);
4866 } else {
4867 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4868 ar->hw->wiphy->n_iface_combinations =
4869 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004870
4871 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004872 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004873
Michal Kazior7c199992013-07-31 10:47:57 +02004874 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4875
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004876 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4877 /* Init ath dfs pattern detector */
4878 ar->ath_common.debug_mask = ATH_DBG_DFS;
4879 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4880 NL80211_DFS_UNSET);
4881
4882 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004883 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004884 }
4885
Kalle Valo5e3dd152013-06-12 20:52:10 +03004886 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4887 ath10k_reg_notifier);
4888 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004889 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004890 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004891 }
4892
4893 ret = ieee80211_register_hw(ar->hw);
4894 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004895 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004896 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004897 }
4898
4899 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4900 ret = regulatory_hint(ar->hw->wiphy,
4901 ar->ath_common.regulatory.alpha2);
4902 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004903 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004904 }
4905
4906 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004907
4908err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004909 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004910err_free:
4911 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4912 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4913
Kalle Valo5e3dd152013-06-12 20:52:10 +03004914 return ret;
4915}
4916
4917void ath10k_mac_unregister(struct ath10k *ar)
4918{
4919 ieee80211_unregister_hw(ar->hw);
4920
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004921 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4922 ar->dfs_detector->exit(ar->dfs_detector);
4923
Kalle Valo5e3dd152013-06-12 20:52:10 +03004924 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4925 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4926
4927 SET_IEEE80211_DEV(ar->hw, NULL);
4928}