blob: 100ed4f0cabdce0b2e0ad3985c4fdfb02813b2fd [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
Michal Kazior7aa7a722014-08-25 12:09:38 +020039 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030040 struct wmi_vdev_install_key_arg arg = {
41 .vdev_id = arvif->vdev_id,
42 .key_idx = key->keyidx,
43 .key_len = key->keylen,
44 .key_data = key->key,
45 .macaddr = macaddr,
46 };
47
Michal Kazior548db542013-07-05 16:15:15 +030048 lockdep_assert_held(&arvif->ar->conf_mutex);
49
Kalle Valo5e3dd152013-06-12 20:52:10 +030050 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
51 arg.key_flags = WMI_KEY_PAIRWISE;
52 else
53 arg.key_flags = WMI_KEY_GROUP;
54
55 switch (key->cipher) {
56 case WLAN_CIPHER_SUITE_CCMP:
57 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +030058 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
59 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
60 else
61 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Kalle Valo5e3dd152013-06-12 20:52:10 +030062 break;
63 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030064 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
67 break;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
75 break;
76 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +020077 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +030078 return -EOPNOTSUPP;
79 }
80
81 if (cmd == DISABLE_KEY) {
82 arg.key_cipher = WMI_CIPHER_NONE;
83 arg.key_data = NULL;
84 }
85
86 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
87}
88
89static int ath10k_install_key(struct ath10k_vif *arvif,
90 struct ieee80211_key_conf *key,
91 enum set_key_cmd cmd,
92 const u8 *macaddr)
93{
94 struct ath10k *ar = arvif->ar;
95 int ret;
96
Michal Kazior548db542013-07-05 16:15:15 +030097 lockdep_assert_held(&ar->conf_mutex);
98
Wolfram Sang16735d02013-11-14 14:32:02 -080099 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300100
101 ret = ath10k_send_key(arvif, key, cmd, macaddr);
102 if (ret)
103 return ret;
104
105 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
106 if (ret == 0)
107 return -ETIMEDOUT;
108
109 return 0;
110}
111
112static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
113 const u8 *addr)
114{
115 struct ath10k *ar = arvif->ar;
116 struct ath10k_peer *peer;
117 int ret;
118 int i;
119
120 lockdep_assert_held(&ar->conf_mutex);
121
122 spin_lock_bh(&ar->data_lock);
123 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
124 spin_unlock_bh(&ar->data_lock);
125
126 if (!peer)
127 return -ENOENT;
128
129 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
130 if (arvif->wep_keys[i] == NULL)
131 continue;
132
133 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 addr);
135 if (ret)
136 return ret;
137
138 peer->keys[i] = arvif->wep_keys[i];
139 }
140
141 return 0;
142}
143
144static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
145 const u8 *addr)
146{
147 struct ath10k *ar = arvif->ar;
148 struct ath10k_peer *peer;
149 int first_errno = 0;
150 int ret;
151 int i;
152
153 lockdep_assert_held(&ar->conf_mutex);
154
155 spin_lock_bh(&ar->data_lock);
156 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
157 spin_unlock_bh(&ar->data_lock);
158
159 if (!peer)
160 return -ENOENT;
161
162 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
163 if (peer->keys[i] == NULL)
164 continue;
165
166 ret = ath10k_install_key(arvif, peer->keys[i],
167 DISABLE_KEY, addr);
168 if (ret && first_errno == 0)
169 first_errno = ret;
170
171 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200172 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 i, ret);
174
175 peer->keys[i] = NULL;
176 }
177
178 return first_errno;
179}
180
181static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
182 struct ieee80211_key_conf *key)
183{
184 struct ath10k *ar = arvif->ar;
185 struct ath10k_peer *peer;
186 u8 addr[ETH_ALEN];
187 int first_errno = 0;
188 int ret;
189 int i;
190
191 lockdep_assert_held(&ar->conf_mutex);
192
193 for (;;) {
194 /* since ath10k_install_key we can't hold data_lock all the
195 * time, so we try to remove the keys incrementally */
196 spin_lock_bh(&ar->data_lock);
197 i = 0;
198 list_for_each_entry(peer, &ar->peers, list) {
199 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
200 if (peer->keys[i] == key) {
201 memcpy(addr, peer->addr, ETH_ALEN);
202 peer->keys[i] = NULL;
203 break;
204 }
205 }
206
207 if (i < ARRAY_SIZE(peer->keys))
208 break;
209 }
210 spin_unlock_bh(&ar->data_lock);
211
212 if (i == ARRAY_SIZE(peer->keys))
213 break;
214
215 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
216 if (ret && first_errno == 0)
217 first_errno = ret;
218
219 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200220 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200221 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300222 }
223
224 return first_errno;
225}
226
227
228/*********************/
229/* General utilities */
230/*********************/
231
232static inline enum wmi_phy_mode
233chan_to_phymode(const struct cfg80211_chan_def *chandef)
234{
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
236
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
241 phymode = MODE_11G;
242 break;
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
245 break;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
248 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
255 break;
256 }
257 break;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
261 phymode = MODE_11A;
262 break;
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
265 break;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
268 break;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
271 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
277 break;
278 }
279 break;
280 default:
281 break;
282 }
283
284 WARN_ON(phymode == MODE_UNKNOWN);
285 return phymode;
286}
287
288static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
289{
290/*
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
293 * 1 for 1/4 us
294 * 2 for 1/2 us
295 * 3 for 1 us
296 * 4 for 2 us
297 * 5 for 4 us
298 * 6 for 8 us
299 * 7 for 16 us
300 */
301 switch (mpdudensity) {
302 case 0:
303 return 0;
304 case 1:
305 case 2:
306 case 3:
307 /* Our lower layer calculations limit our precision to
308 1 microsecond */
309 return 1;
310 case 4:
311 return 2;
312 case 5:
313 return 4;
314 case 6:
315 return 8;
316 case 7:
317 return 16;
318 default:
319 return 0;
320 }
321}
322
323static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
324{
325 int ret;
326
327 lockdep_assert_held(&ar->conf_mutex);
328
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800330 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200332 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800334 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200339 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800341 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100342 spin_lock_bh(&ar->data_lock);
343 ar->num_peers++;
344 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300345
346 return 0;
347}
348
Kalle Valo5a13e762014-01-20 11:01:46 +0200349static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
350{
351 struct ath10k *ar = arvif->ar;
352 u32 param;
353 int ret;
354
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
358 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200360 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200361 return ret;
362 }
363
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
367 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200369 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200370 return ret;
371 }
372
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200378 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200379 return ret;
380 }
381
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
385 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200387 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200388 return ret;
389 }
390
391 return 0;
392}
393
Michal Kazior424121c2013-07-22 14:13:31 +0200394static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
395{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200396 struct ath10k *ar = arvif->ar;
397 u32 vdev_param;
398
Michal Kazior424121c2013-07-22 14:13:31 +0200399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
401 ATH10K_RTS_MAX);
402
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200405}
406
407static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
408{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200409 struct ath10k *ar = arvif->ar;
410 u32 vdev_param;
411
Michal Kazior424121c2013-07-22 14:13:31 +0200412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
416
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200419}
420
Kalle Valo5e3dd152013-06-12 20:52:10 +0300421static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
422{
423 int ret;
424
425 lockdep_assert_held(&ar->conf_mutex);
426
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
428 if (ret)
429 return ret;
430
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
432 if (ret)
433 return ret;
434
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100435 spin_lock_bh(&ar->data_lock);
436 ar->num_peers--;
437 spin_unlock_bh(&ar->data_lock);
438
Kalle Valo5e3dd152013-06-12 20:52:10 +0300439 return 0;
440}
441
442static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
443{
444 struct ath10k_peer *peer, *tmp;
445
446 lockdep_assert_held(&ar->conf_mutex);
447
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
451 continue;
452
Michal Kazior7aa7a722014-08-25 12:09:38 +0200453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300454 peer->addr, vdev_id);
455
456 list_del(&peer->list);
457 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100458 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300459 }
460 spin_unlock_bh(&ar->data_lock);
461}
462
Michal Kaziora96d7742013-07-16 09:38:56 +0200463static void ath10k_peer_cleanup_all(struct ath10k *ar)
464{
465 struct ath10k_peer *peer, *tmp;
466
467 lockdep_assert_held(&ar->conf_mutex);
468
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
472 kfree(peer);
473 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100474 ar->num_peers = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200475 spin_unlock_bh(&ar->data_lock);
476}
477
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478/************************/
479/* Interface management */
480/************************/
481
482static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
483{
484 int ret;
485
Michal Kazior548db542013-07-05 16:15:15 +0300486 lockdep_assert_held(&ar->conf_mutex);
487
Kalle Valo5e3dd152013-06-12 20:52:10 +0300488 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
489 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
490 if (ret == 0)
491 return -ETIMEDOUT;
492
493 return 0;
494}
495
Michal Kazior1bbc0972014-04-08 09:45:47 +0300496static 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);
701 else
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,
898 struct ieee80211_bss_conf *info)
899{
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,
1108 WLAN_OUI_TYPE_MICROSOFT_WPA,
1109 ies->data,
1110 ies->len);
1111 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;
1160
Michal Kazior548db542013-07-05 16:15:15 +03001161 lockdep_assert_held(&ar->conf_mutex);
1162
Kalle Valo5e3dd152013-06-12 20:52:10 +03001163 if (!ht_cap->ht_supported)
1164 return;
1165
1166 arg->peer_flags |= WMI_PEER_HT;
1167 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1168 ht_cap->ampdu_factor)) - 1;
1169
1170 arg->peer_mpdu_density =
1171 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1172
1173 arg->peer_ht_caps = ht_cap->cap;
1174 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1175
1176 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1177 arg->peer_flags |= WMI_PEER_LDPC;
1178
1179 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1180 arg->peer_flags |= WMI_PEER_40MHZ;
1181 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1182 }
1183
1184 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1185 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1186
1187 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1188 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1189
1190 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1191 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1192 arg->peer_flags |= WMI_PEER_STBC;
1193 }
1194
1195 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1196 u32 stbc;
1197 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
1264
1265 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1266 max_sp = sta->max_sp;
1267
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001268 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1269 sta->addr,
1270 WMI_AP_PS_PEER_PARAM_UAPSD,
1271 uapsd);
1272 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001273 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001274 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001275 return ret;
1276 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001277
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001278 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1279 sta->addr,
1280 WMI_AP_PS_PEER_PARAM_MAX_SP,
1281 max_sp);
1282 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001283 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001284 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001285 return ret;
1286 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287
1288 /* TODO setup this based on STA listen interval and
1289 beacon interval. Currently we don't know
1290 sta->listen_interval - mac80211 patch required.
1291 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001292 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1293 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1294 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
1318 ampdu_factor = (vht_cap->cap &
1319 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1320 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1321
1322 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1323 * zero in VHT IE. Using it would result in degraded throughput.
1324 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1325 * it if VHT max_mpdu is smaller. */
1326 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1327 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1328 ampdu_factor)) - 1);
1329
Kalle Valo5e3dd152013-06-12 20:52:10 +03001330 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1331 arg->peer_flags |= WMI_PEER_80MHZ;
1332
1333 arg->peer_vht_rates.rx_max_rate =
1334 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1335 arg->peer_vht_rates.rx_mcs_set =
1336 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1337 arg->peer_vht_rates.tx_max_rate =
1338 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1339 arg->peer_vht_rates.tx_mcs_set =
1340 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1341
Michal Kazior7aa7a722014-08-25 12:09:38 +02001342 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001343 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001344}
1345
1346static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1347 struct ath10k_vif *arvif,
1348 struct ieee80211_sta *sta,
1349 struct ieee80211_bss_conf *bss_conf,
1350 struct wmi_peer_assoc_complete_arg *arg)
1351{
1352 switch (arvif->vdev_type) {
1353 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001354 if (sta->wme)
1355 arg->peer_flags |= WMI_PEER_QOS;
1356
1357 if (sta->wme && sta->uapsd_queues) {
1358 arg->peer_flags |= WMI_PEER_APSD;
1359 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1360 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001361 break;
1362 case WMI_VDEV_TYPE_STA:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001363 if (bss_conf->qos)
1364 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001365 break;
1366 default:
1367 break;
1368 }
1369}
1370
1371static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1372 struct ath10k_vif *arvif,
1373 struct ieee80211_sta *sta,
1374 struct wmi_peer_assoc_complete_arg *arg)
1375{
1376 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1377
Kalle Valo5e3dd152013-06-12 20:52:10 +03001378 switch (ar->hw->conf.chandef.chan->band) {
1379 case IEEE80211_BAND_2GHZ:
1380 if (sta->ht_cap.ht_supported) {
1381 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1382 phymode = MODE_11NG_HT40;
1383 else
1384 phymode = MODE_11NG_HT20;
1385 } else {
1386 phymode = MODE_11G;
1387 }
1388
1389 break;
1390 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001391 /*
1392 * Check VHT first.
1393 */
1394 if (sta->vht_cap.vht_supported) {
1395 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1396 phymode = MODE_11AC_VHT80;
1397 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1398 phymode = MODE_11AC_VHT40;
1399 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1400 phymode = MODE_11AC_VHT20;
1401 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001402 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1403 phymode = MODE_11NA_HT40;
1404 else
1405 phymode = MODE_11NA_HT20;
1406 } else {
1407 phymode = MODE_11A;
1408 }
1409
1410 break;
1411 default:
1412 break;
1413 }
1414
Michal Kazior7aa7a722014-08-25 12:09:38 +02001415 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03001416 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001417
Kalle Valo5e3dd152013-06-12 20:52:10 +03001418 arg->peer_phymode = phymode;
1419 WARN_ON(phymode == MODE_UNKNOWN);
1420}
1421
Kalle Valob9ada652013-10-16 15:44:46 +03001422static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1423 struct ath10k_vif *arvif,
1424 struct ieee80211_sta *sta,
1425 struct ieee80211_bss_conf *bss_conf,
1426 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001427{
Michal Kazior548db542013-07-05 16:15:15 +03001428 lockdep_assert_held(&ar->conf_mutex);
1429
Kalle Valob9ada652013-10-16 15:44:46 +03001430 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001431
Kalle Valob9ada652013-10-16 15:44:46 +03001432 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1433 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1434 ath10k_peer_assoc_h_rates(ar, sta, arg);
1435 ath10k_peer_assoc_h_ht(ar, sta, arg);
1436 ath10k_peer_assoc_h_vht(ar, sta, arg);
1437 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1438 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001439
Kalle Valob9ada652013-10-16 15:44:46 +03001440 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001441}
1442
Michal Kazior90046f52014-02-14 14:45:51 +01001443static const u32 ath10k_smps_map[] = {
1444 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1445 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1446 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1447 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1448};
1449
1450static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1451 const u8 *addr,
1452 const struct ieee80211_sta_ht_cap *ht_cap)
1453{
1454 int smps;
1455
1456 if (!ht_cap->ht_supported)
1457 return 0;
1458
1459 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1460 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1461
1462 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1463 return -EINVAL;
1464
1465 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1466 WMI_PEER_SMPS_STATE,
1467 ath10k_smps_map[smps]);
1468}
1469
Kalle Valo5e3dd152013-06-12 20:52:10 +03001470/* can be called only in mac80211 callbacks due to `key_count` usage */
1471static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1472 struct ieee80211_vif *vif,
1473 struct ieee80211_bss_conf *bss_conf)
1474{
1475 struct ath10k *ar = hw->priv;
1476 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01001477 struct ieee80211_sta_ht_cap ht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03001478 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001479 struct ieee80211_sta *ap_sta;
1480 int ret;
1481
Michal Kazior548db542013-07-05 16:15:15 +03001482 lockdep_assert_held(&ar->conf_mutex);
1483
Kalle Valo5e3dd152013-06-12 20:52:10 +03001484 rcu_read_lock();
1485
1486 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1487 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001488 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001489 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001490 rcu_read_unlock();
1491 return;
1492 }
1493
Michal Kazior90046f52014-02-14 14:45:51 +01001494 /* ap_sta must be accessed only within rcu section which must be left
1495 * before calling ath10k_setup_peer_smps() which might sleep. */
1496 ht_cap = ap_sta->ht_cap;
1497
Kalle Valob9ada652013-10-16 15:44:46 +03001498 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1499 bss_conf, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001500 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001501 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001502 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001503 rcu_read_unlock();
1504 return;
1505 }
1506
1507 rcu_read_unlock();
1508
Kalle Valob9ada652013-10-16 15:44:46 +03001509 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1510 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001511 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001512 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001513 return;
1514 }
1515
Michal Kazior90046f52014-02-14 14:45:51 +01001516 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1517 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001518 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001519 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001520 return;
1521 }
1522
Michal Kazior7aa7a722014-08-25 12:09:38 +02001523 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001524 "mac vdev %d up (associated) bssid %pM aid %d\n",
1525 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1526
Michal Kaziorc930f742014-01-23 11:38:25 +01001527 arvif->aid = bss_conf->aid;
1528 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1529
1530 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1531 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001532 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001533 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001534 return;
1535 }
1536
1537 arvif->is_up = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001538}
1539
1540/*
1541 * FIXME: flush TIDs
1542 */
1543static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1544 struct ieee80211_vif *vif)
1545{
1546 struct ath10k *ar = hw->priv;
1547 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1548 int ret;
1549
Michal Kazior548db542013-07-05 16:15:15 +03001550 lockdep_assert_held(&ar->conf_mutex);
1551
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 /*
1553 * For some reason, calling VDEV-DOWN before VDEV-STOP
1554 * makes the FW to send frames via HTT after disassociation.
1555 * No idea why this happens, even though VDEV-DOWN is supposed
1556 * to be analogous to link down, so just stop the VDEV.
1557 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001558 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001559 arvif->vdev_id);
1560
1561 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001563
1564 /*
1565 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1566 * report beacons from previously associated network through HTT.
1567 * This in turn would spam mac80211 WARN_ON if we bring down all
1568 * interfaces as it expects there is no rx when no interface is
1569 * running.
1570 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001571 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
Kalle Valo60c3daa2013-09-08 17:56:07 +03001572
1573 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001576 arvif->def_wep_key_idx = 0;
Michal Kaziorc930f742014-01-23 11:38:25 +01001577
1578 arvif->is_started = false;
1579 arvif->is_up = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001580}
1581
1582static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001583 struct ieee80211_sta *sta, bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584{
Kalle Valob9ada652013-10-16 15:44:46 +03001585 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 int ret = 0;
1587
Michal Kazior548db542013-07-05 16:15:15 +03001588 lockdep_assert_held(&ar->conf_mutex);
1589
Kalle Valob9ada652013-10-16 15:44:46 +03001590 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001592 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001593 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03001594 return ret;
1595 }
1596
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02001597 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03001598 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001600 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001601 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001602 return ret;
1603 }
1604
Michal Kazior90046f52014-02-14 14:45:51 +01001605 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001607 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001608 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01001609 return ret;
1610 }
1611
Michal Kaziora4841eb2014-08-28 09:59:39 +02001612 if (!sta->wme && !reassoc) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001613 arvif->num_legacy_stations++;
1614 ret = ath10k_recalc_rtscts_prot(arvif);
1615 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001616 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001617 arvif->vdev_id, ret);
1618 return ret;
1619 }
1620 }
1621
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1623 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001624 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001625 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001626 return ret;
1627 }
1628
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001629 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1630 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001631 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001632 sta->addr, arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001633 return ret;
1634 }
1635
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 return ret;
1637}
1638
1639static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1640 struct ieee80211_sta *sta)
1641{
1642 int ret = 0;
1643
Michal Kazior548db542013-07-05 16:15:15 +03001644 lockdep_assert_held(&ar->conf_mutex);
1645
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001646 if (!sta->wme) {
1647 arvif->num_legacy_stations--;
1648 ret = ath10k_recalc_rtscts_prot(arvif);
1649 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001650 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001651 arvif->vdev_id, ret);
1652 return ret;
1653 }
1654 }
1655
Kalle Valo5e3dd152013-06-12 20:52:10 +03001656 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1657 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001658 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001659 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001660 return ret;
1661 }
1662
1663 return ret;
1664}
1665
1666/**************/
1667/* Regulatory */
1668/**************/
1669
1670static int ath10k_update_channel_list(struct ath10k *ar)
1671{
1672 struct ieee80211_hw *hw = ar->hw;
1673 struct ieee80211_supported_band **bands;
1674 enum ieee80211_band band;
1675 struct ieee80211_channel *channel;
1676 struct wmi_scan_chan_list_arg arg = {0};
1677 struct wmi_channel_arg *ch;
1678 bool passive;
1679 int len;
1680 int ret;
1681 int i;
1682
Michal Kazior548db542013-07-05 16:15:15 +03001683 lockdep_assert_held(&ar->conf_mutex);
1684
Kalle Valo5e3dd152013-06-12 20:52:10 +03001685 bands = hw->wiphy->bands;
1686 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1687 if (!bands[band])
1688 continue;
1689
1690 for (i = 0; i < bands[band]->n_channels; i++) {
1691 if (bands[band]->channels[i].flags &
1692 IEEE80211_CHAN_DISABLED)
1693 continue;
1694
1695 arg.n_channels++;
1696 }
1697 }
1698
1699 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1700 arg.channels = kzalloc(len, GFP_KERNEL);
1701 if (!arg.channels)
1702 return -ENOMEM;
1703
1704 ch = arg.channels;
1705 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1706 if (!bands[band])
1707 continue;
1708
1709 for (i = 0; i < bands[band]->n_channels; i++) {
1710 channel = &bands[band]->channels[i];
1711
1712 if (channel->flags & IEEE80211_CHAN_DISABLED)
1713 continue;
1714
1715 ch->allow_ht = true;
1716
1717 /* FIXME: when should we really allow VHT? */
1718 ch->allow_vht = true;
1719
1720 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001721 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722
1723 ch->ht40plus =
1724 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1725
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001726 ch->chan_radar =
1727 !!(channel->flags & IEEE80211_CHAN_RADAR);
1728
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001729 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 ch->passive = passive;
1731
1732 ch->freq = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07001733 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07001734 ch->max_power = channel->max_power * 2;
1735 ch->max_reg_power = channel->max_reg_power * 2;
1736 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737 ch->reg_class_id = 0; /* FIXME */
1738
1739 /* FIXME: why use only legacy modes, why not any
1740 * HT/VHT modes? Would that even make any
1741 * difference? */
1742 if (channel->band == IEEE80211_BAND_2GHZ)
1743 ch->mode = MODE_11G;
1744 else
1745 ch->mode = MODE_11A;
1746
1747 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1748 continue;
1749
Michal Kazior7aa7a722014-08-25 12:09:38 +02001750 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001751 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1752 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001753 ch->freq, ch->max_power, ch->max_reg_power,
1754 ch->max_antenna_gain, ch->mode);
1755
1756 ch++;
1757 }
1758 }
1759
1760 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1761 kfree(arg.channels);
1762
1763 return ret;
1764}
1765
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001766static enum wmi_dfs_region
1767ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1768{
1769 switch (dfs_region) {
1770 case NL80211_DFS_UNSET:
1771 return WMI_UNINIT_DFS_DOMAIN;
1772 case NL80211_DFS_FCC:
1773 return WMI_FCC_DFS_DOMAIN;
1774 case NL80211_DFS_ETSI:
1775 return WMI_ETSI_DFS_DOMAIN;
1776 case NL80211_DFS_JP:
1777 return WMI_MKK4_DFS_DOMAIN;
1778 }
1779 return WMI_UNINIT_DFS_DOMAIN;
1780}
1781
Michal Kaziorf7843d72013-07-16 09:38:52 +02001782static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001783{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001784 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001786 enum wmi_dfs_region wmi_dfs_reg;
1787 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001788
Michal Kaziorf7843d72013-07-16 09:38:52 +02001789 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790
1791 ret = ath10k_update_channel_list(ar);
1792 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001793 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001794
1795 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001796
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001797 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1798 nl_dfs_reg = ar->dfs_detector->region;
1799 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1800 } else {
1801 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1802 }
1803
Kalle Valo5e3dd152013-06-12 20:52:10 +03001804 /* Target allows setting up per-band regdomain but ath_common provides
1805 * a combined one only */
1806 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02001807 regpair->reg_domain,
1808 regpair->reg_domain, /* 2ghz */
1809 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001810 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02001811 regpair->reg_5ghz_ctl,
1812 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001813 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001814 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001815}
Michal Kazior548db542013-07-05 16:15:15 +03001816
Michal Kaziorf7843d72013-07-16 09:38:52 +02001817static void ath10k_reg_notifier(struct wiphy *wiphy,
1818 struct regulatory_request *request)
1819{
1820 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1821 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001822 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001823
1824 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1825
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001826 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001827 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001828 request->dfs_region);
1829 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1830 request->dfs_region);
1831 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001832 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001833 request->dfs_region);
1834 }
1835
Michal Kaziorf7843d72013-07-16 09:38:52 +02001836 mutex_lock(&ar->conf_mutex);
1837 if (ar->state == ATH10K_STATE_ON)
1838 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001839 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001840}
1841
1842/***************/
1843/* TX handlers */
1844/***************/
1845
Michal Kazior42c3aa62013-10-02 11:03:38 +02001846static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1847{
1848 if (ieee80211_is_mgmt(hdr->frame_control))
1849 return HTT_DATA_TX_EXT_TID_MGMT;
1850
1851 if (!ieee80211_is_data_qos(hdr->frame_control))
1852 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1853
1854 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1855 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1856
1857 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1858}
1859
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001860static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1861 struct ieee80211_tx_info *info)
1862{
1863 if (info->control.vif)
1864 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1865
Michal Kazior1bbc0972014-04-08 09:45:47 +03001866 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001867 return ar->monitor_vdev_id;
1868
Michal Kazior7aa7a722014-08-25 12:09:38 +02001869 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02001870 return 0;
1871}
1872
Michal Kazior4b604552014-07-21 21:03:09 +03001873/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1874 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03001875 */
Michal Kazior4b604552014-07-21 21:03:09 +03001876static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001877{
1878 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001879 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001880 u8 *qos_ctl;
1881
1882 if (!ieee80211_is_data_qos(hdr->frame_control))
1883 return;
1884
1885 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001886 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1887 skb->data, (void *)qos_ctl - (void *)skb->data);
1888 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03001889
1890 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1891 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1892 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1893 * it is safe to downgrade to NullFunc.
1894 */
1895 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1896 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1897 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1898 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001899}
1900
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001901static void ath10k_tx_wep_key_work(struct work_struct *work)
1902{
1903 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1904 wep_key_work);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001905 struct ath10k *ar = arvif->ar;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001906 int ret, keyidx = arvif->def_wep_key_newidx;
1907
Michal Kazior911e6c02014-05-26 12:46:03 +03001908 mutex_lock(&arvif->ar->conf_mutex);
1909
1910 if (arvif->ar->state != ATH10K_STATE_ON)
1911 goto unlock;
1912
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001913 if (arvif->def_wep_key_idx == keyidx)
Michal Kazior911e6c02014-05-26 12:46:03 +03001914 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001915
Michal Kazior7aa7a722014-08-25 12:09:38 +02001916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001917 arvif->vdev_id, keyidx);
1918
1919 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1920 arvif->vdev_id,
1921 arvif->ar->wmi.vdev_param->def_keyid,
1922 keyidx);
1923 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001924 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001925 arvif->vdev_id,
1926 ret);
Michal Kazior911e6c02014-05-26 12:46:03 +03001927 goto unlock;
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001928 }
1929
1930 arvif->def_wep_key_idx = keyidx;
Michal Kazior911e6c02014-05-26 12:46:03 +03001931
1932unlock:
1933 mutex_unlock(&arvif->ar->conf_mutex);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001934}
1935
Michal Kazior4b604552014-07-21 21:03:09 +03001936static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1937 struct ieee80211_key_conf *key,
1938 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1941 struct ath10k *ar = arvif->ar;
1942 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001943
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 if (!ieee80211_has_protected(hdr->frame_control))
1945 return;
1946
1947 if (!key)
1948 return;
1949
1950 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1951 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1952 return;
1953
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001954 if (key->keyidx == arvif->def_wep_key_idx)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955 return;
1956
Michal Kaziorcc4827b2013-10-16 15:44:45 +03001957 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1958 * queueing frames until key index is updated is not an option because
1959 * sk_buff may need more processing to be done, e.g. offchannel */
1960 arvif->def_wep_key_newidx = key->keyidx;
1961 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962}
1963
Michal Kazior4b604552014-07-21 21:03:09 +03001964static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1965 struct ieee80211_vif *vif,
1966 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967{
1968 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1970
1971 /* This is case only for P2P_GO */
1972 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1973 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1974 return;
1975
1976 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1977 spin_lock_bh(&ar->data_lock);
1978 if (arvif->u.ap.noa_data)
1979 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1980 GFP_ATOMIC))
1981 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1982 arvif->u.ap.noa_data,
1983 arvif->u.ap.noa_len);
1984 spin_unlock_bh(&ar->data_lock);
1985 }
1986}
1987
1988static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1989{
1990 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001991 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001992
Michal Kazior961d4c32013-08-09 10:13:34 +02001993 if (ar->htt.target_version_major >= 3) {
1994 /* Since HTT 3.0 there is no separate mgmt tx command */
1995 ret = ath10k_htt_tx(&ar->htt, skb);
1996 goto exit;
1997 }
1998
Bartosz Markowski5e00d312013-09-26 17:47:12 +02001999 if (ieee80211_is_mgmt(hdr->frame_control)) {
2000 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2001 ar->fw_features)) {
2002 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2003 ATH10K_MAX_NUM_MGMT_PENDING) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002004 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002005 ret = -EBUSY;
2006 goto exit;
2007 }
2008
2009 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2010 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2011 } else {
2012 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2013 }
2014 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2015 ar->fw_features) &&
2016 ieee80211_is_nullfunc(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 /* FW does not report tx status properly for NullFunc frames
2018 * unless they are sent through mgmt tx path. mac80211 sends
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002019 * those frames when it detects link/beacon loss and depends
2020 * on the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03002021 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002022 } else {
Michal Kazioredb82362013-07-05 16:15:14 +03002023 ret = ath10k_htt_tx(&ar->htt, skb);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002024 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002025
Michal Kazior961d4c32013-08-09 10:13:34 +02002026exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002028 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2029 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002030 ieee80211_free_txskb(ar->hw, skb);
2031 }
2032}
2033
2034void ath10k_offchan_tx_purge(struct ath10k *ar)
2035{
2036 struct sk_buff *skb;
2037
2038 for (;;) {
2039 skb = skb_dequeue(&ar->offchan_tx_queue);
2040 if (!skb)
2041 break;
2042
2043 ieee80211_free_txskb(ar->hw, skb);
2044 }
2045}
2046
2047void ath10k_offchan_tx_work(struct work_struct *work)
2048{
2049 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2050 struct ath10k_peer *peer;
2051 struct ieee80211_hdr *hdr;
2052 struct sk_buff *skb;
2053 const u8 *peer_addr;
2054 int vdev_id;
2055 int ret;
2056
2057 /* FW requirement: We must create a peer before FW will send out
2058 * an offchannel frame. Otherwise the frame will be stuck and
2059 * never transmitted. We delete the peer upon tx completion.
2060 * It is unlikely that a peer for offchannel tx will already be
2061 * present. However it may be in some rare cases so account for that.
2062 * Otherwise we might remove a legitimate peer and break stuff. */
2063
2064 for (;;) {
2065 skb = skb_dequeue(&ar->offchan_tx_queue);
2066 if (!skb)
2067 break;
2068
2069 mutex_lock(&ar->conf_mutex);
2070
Michal Kazior7aa7a722014-08-25 12:09:38 +02002071 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002072 skb);
2073
2074 hdr = (struct ieee80211_hdr *)skb->data;
2075 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002076 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077
2078 spin_lock_bh(&ar->data_lock);
2079 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2080 spin_unlock_bh(&ar->data_lock);
2081
2082 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002083 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002084 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085 peer_addr, vdev_id);
2086
2087 if (!peer) {
2088 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2089 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002090 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 peer_addr, vdev_id, ret);
2092 }
2093
2094 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002095 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 ar->offchan_tx_skb = skb;
2097 spin_unlock_bh(&ar->data_lock);
2098
2099 ath10k_tx_htt(ar, skb);
2100
2101 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2102 3 * HZ);
2103 if (ret <= 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002104 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002105 skb);
2106
2107 if (!peer) {
2108 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2109 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002110 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111 peer_addr, vdev_id, ret);
2112 }
2113
2114 mutex_unlock(&ar->conf_mutex);
2115 }
2116}
2117
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002118void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2119{
2120 struct sk_buff *skb;
2121
2122 for (;;) {
2123 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2124 if (!skb)
2125 break;
2126
2127 ieee80211_free_txskb(ar->hw, skb);
2128 }
2129}
2130
2131void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2132{
2133 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2134 struct sk_buff *skb;
2135 int ret;
2136
2137 for (;;) {
2138 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2139 if (!skb)
2140 break;
2141
2142 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002143 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002144 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002145 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002146 ieee80211_free_txskb(ar->hw, skb);
2147 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002148 }
2149}
2150
Kalle Valo5e3dd152013-06-12 20:52:10 +03002151/************/
2152/* Scanning */
2153/************/
2154
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002155void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002157 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002158
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002159 switch (ar->scan.state) {
2160 case ATH10K_SCAN_IDLE:
2161 break;
2162 case ATH10K_SCAN_RUNNING:
2163 case ATH10K_SCAN_ABORTING:
2164 if (ar->scan.is_roc)
2165 ieee80211_remain_on_channel_expired(ar->hw);
2166 else
2167 ieee80211_scan_completed(ar->hw,
2168 (ar->scan.state ==
2169 ATH10K_SCAN_ABORTING));
2170 /* fall through */
2171 case ATH10K_SCAN_STARTING:
2172 ar->scan.state = ATH10K_SCAN_IDLE;
2173 ar->scan_channel = NULL;
2174 ath10k_offchan_tx_purge(ar);
2175 cancel_delayed_work(&ar->scan.timeout);
2176 complete_all(&ar->scan.completed);
2177 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002178 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002179}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002181void ath10k_scan_finish(struct ath10k *ar)
2182{
2183 spin_lock_bh(&ar->data_lock);
2184 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 spin_unlock_bh(&ar->data_lock);
2186}
2187
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002188static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189{
2190 struct wmi_stop_scan_arg arg = {
2191 .req_id = 1, /* FIXME */
2192 .req_type = WMI_SCAN_STOP_ONE,
2193 .u.scan_id = ATH10K_SCAN_ID,
2194 };
2195 int ret;
2196
2197 lockdep_assert_held(&ar->conf_mutex);
2198
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199 ret = ath10k_wmi_stop_scan(ar, &arg);
2200 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002201 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002202 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 }
2204
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002206 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002207 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002209 } else if (ret > 0) {
2210 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002212
2213out:
2214 /* Scan state should be updated upon scan completion but in case
2215 * firmware fails to deliver the event (for whatever reason) it is
2216 * desired to clean up scan state anyway. Firmware may have just
2217 * dropped the scan completion event delivery due to transport pipe
2218 * being overflown with data and/or it can recover on its own before
2219 * next scan request is submitted.
2220 */
2221 spin_lock_bh(&ar->data_lock);
2222 if (ar->scan.state != ATH10K_SCAN_IDLE)
2223 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224 spin_unlock_bh(&ar->data_lock);
2225
2226 return ret;
2227}
2228
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002229static void ath10k_scan_abort(struct ath10k *ar)
2230{
2231 int ret;
2232
2233 lockdep_assert_held(&ar->conf_mutex);
2234
2235 spin_lock_bh(&ar->data_lock);
2236
2237 switch (ar->scan.state) {
2238 case ATH10K_SCAN_IDLE:
2239 /* This can happen if timeout worker kicked in and called
2240 * abortion while scan completion was being processed.
2241 */
2242 break;
2243 case ATH10K_SCAN_STARTING:
2244 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002245 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002246 ath10k_scan_state_str(ar->scan.state),
2247 ar->scan.state);
2248 break;
2249 case ATH10K_SCAN_RUNNING:
2250 ar->scan.state = ATH10K_SCAN_ABORTING;
2251 spin_unlock_bh(&ar->data_lock);
2252
2253 ret = ath10k_scan_stop(ar);
2254 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002255 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002256
2257 spin_lock_bh(&ar->data_lock);
2258 break;
2259 }
2260
2261 spin_unlock_bh(&ar->data_lock);
2262}
2263
2264void ath10k_scan_timeout_work(struct work_struct *work)
2265{
2266 struct ath10k *ar = container_of(work, struct ath10k,
2267 scan.timeout.work);
2268
2269 mutex_lock(&ar->conf_mutex);
2270 ath10k_scan_abort(ar);
2271 mutex_unlock(&ar->conf_mutex);
2272}
2273
Kalle Valo5e3dd152013-06-12 20:52:10 +03002274static int ath10k_start_scan(struct ath10k *ar,
2275 const struct wmi_start_scan_arg *arg)
2276{
2277 int ret;
2278
2279 lockdep_assert_held(&ar->conf_mutex);
2280
2281 ret = ath10k_wmi_start_scan(ar, arg);
2282 if (ret)
2283 return ret;
2284
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2286 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002287 ret = ath10k_scan_stop(ar);
2288 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002289 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002290
2291 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292 }
2293
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002294 /* Add a 200ms margin to account for event/command processing */
2295 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2296 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002297 return 0;
2298}
2299
2300/**********************/
2301/* mac80211 callbacks */
2302/**********************/
2303
2304static void ath10k_tx(struct ieee80211_hw *hw,
2305 struct ieee80211_tx_control *control,
2306 struct sk_buff *skb)
2307{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03002309 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2310 struct ieee80211_vif *vif = info->control.vif;
2311 struct ieee80211_key_conf *key = info->control.hw_key;
2312 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002313
2314 /* We should disable CCK RATE due to P2P */
2315 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002316 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317
Michal Kazior4b604552014-07-21 21:03:09 +03002318 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2319 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2320 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002322 /* it makes no sense to process injected frames like that */
Michal Kazior4b604552014-07-21 21:03:09 +03002323 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2324 ath10k_tx_h_nwifi(hw, skb);
2325 ath10k_tx_h_update_wep_key(vif, key, skb);
2326 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2327 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziorcf84bd42013-07-16 11:04:54 +02002328 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002329
Kalle Valo5e3dd152013-06-12 20:52:10 +03002330 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2331 spin_lock_bh(&ar->data_lock);
2332 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002333 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334 spin_unlock_bh(&ar->data_lock);
2335
Michal Kazior7aa7a722014-08-25 12:09:38 +02002336 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2337 skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338
2339 skb_queue_tail(&ar->offchan_tx_queue, skb);
2340 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2341 return;
2342 }
2343
2344 ath10k_tx_htt(ar, skb);
2345}
2346
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002347/* Must not be called with conf_mutex held as workers can use that also. */
2348static void ath10k_drain_tx(struct ath10k *ar)
2349{
2350 /* make sure rcu-protected mac80211 tx path itself is drained */
2351 synchronize_net();
2352
2353 ath10k_offchan_tx_purge(ar);
2354 ath10k_mgmt_over_wmi_tx_purge(ar);
2355
2356 cancel_work_sync(&ar->offchan_tx_work);
2357 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2358}
2359
Michal Kazioraffd3212013-07-16 09:54:35 +02002360void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02002361{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002362 struct ath10k_vif *arvif;
2363
Michal Kazior818bdd12013-07-16 09:38:57 +02002364 lockdep_assert_held(&ar->conf_mutex);
2365
Michal Kazior19337472014-08-28 12:58:16 +02002366 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2367 ar->filter_flags = 0;
2368 ar->monitor = false;
2369
2370 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03002371 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02002372
2373 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03002374
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002375 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02002376 ath10k_peer_cleanup_all(ar);
2377 ath10k_core_stop(ar);
2378 ath10k_hif_power_down(ar);
2379
2380 spin_lock_bh(&ar->data_lock);
Michal Kaziord9bc4b92014-04-23 19:30:06 +03002381 list_for_each_entry(arvif, &ar->arvifs, list) {
2382 if (!arvif->beacon)
2383 continue;
2384
2385 dma_unmap_single(arvif->ar->dev,
2386 ATH10K_SKB_CB(arvif->beacon)->paddr,
2387 arvif->beacon->len, DMA_TO_DEVICE);
2388 dev_kfree_skb_any(arvif->beacon);
2389 arvif->beacon = NULL;
2390 }
Michal Kazior818bdd12013-07-16 09:38:57 +02002391 spin_unlock_bh(&ar->data_lock);
2392}
2393
Ben Greear46acf7bb2014-05-16 17:15:38 +03002394static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2395{
2396 struct ath10k *ar = hw->priv;
2397
2398 mutex_lock(&ar->conf_mutex);
2399
2400 if (ar->cfg_tx_chainmask) {
2401 *tx_ant = ar->cfg_tx_chainmask;
2402 *rx_ant = ar->cfg_rx_chainmask;
2403 } else {
2404 *tx_ant = ar->supp_tx_chainmask;
2405 *rx_ant = ar->supp_rx_chainmask;
2406 }
2407
2408 mutex_unlock(&ar->conf_mutex);
2409
2410 return 0;
2411}
2412
2413static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2414{
2415 int ret;
2416
2417 lockdep_assert_held(&ar->conf_mutex);
2418
2419 ar->cfg_tx_chainmask = tx_ant;
2420 ar->cfg_rx_chainmask = rx_ant;
2421
2422 if ((ar->state != ATH10K_STATE_ON) &&
2423 (ar->state != ATH10K_STATE_RESTARTED))
2424 return 0;
2425
2426 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2427 tx_ant);
2428 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002429 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002430 ret, tx_ant);
2431 return ret;
2432 }
2433
2434 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2435 rx_ant);
2436 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002437 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7bb2014-05-16 17:15:38 +03002438 ret, rx_ant);
2439 return ret;
2440 }
2441
2442 return 0;
2443}
2444
2445static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2446{
2447 struct ath10k *ar = hw->priv;
2448 int ret;
2449
2450 mutex_lock(&ar->conf_mutex);
2451 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2452 mutex_unlock(&ar->conf_mutex);
2453 return ret;
2454}
2455
Kalle Valo5e3dd152013-06-12 20:52:10 +03002456static int ath10k_start(struct ieee80211_hw *hw)
2457{
2458 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02002459 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002461 /*
2462 * This makes sense only when restarting hw. It is harmless to call
2463 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2464 * commands will be submitted while restarting.
2465 */
2466 ath10k_drain_tx(ar);
2467
Michal Kazior548db542013-07-05 16:15:15 +03002468 mutex_lock(&ar->conf_mutex);
2469
Michal Kaziorc5058f52014-05-26 12:46:03 +03002470 switch (ar->state) {
2471 case ATH10K_STATE_OFF:
2472 ar->state = ATH10K_STATE_ON;
2473 break;
2474 case ATH10K_STATE_RESTARTING:
2475 ath10k_halt(ar);
2476 ar->state = ATH10K_STATE_RESTARTED;
2477 break;
2478 case ATH10K_STATE_ON:
2479 case ATH10K_STATE_RESTARTED:
2480 case ATH10K_STATE_WEDGED:
2481 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02002482 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03002483 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02002484 }
2485
2486 ret = ath10k_hif_power_up(ar);
2487 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002488 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002489 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02002490 }
2491
2492 ret = ath10k_core_start(ar);
2493 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002494 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002495 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02002496 }
2497
Bartosz Markowski226a3392013-09-26 17:47:16 +02002498 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002499 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002500 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002501 goto err_core_stop;
2502 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002503
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01002504 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03002505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002506 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002507 goto err_core_stop;
2508 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509
Ben Greear46acf7bb2014-05-16 17:15:38 +03002510 if (ar->cfg_tx_chainmask)
2511 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2512 ar->cfg_rx_chainmask);
2513
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002514 /*
2515 * By default FW set ARP frames ac to voice (6). In that case ARP
2516 * exchange is not working properly for UAPSD enabled AP. ARP requests
2517 * which arrives with access category 0 are processed by network stack
2518 * and send back with access category 0, but FW changes access category
2519 * to 6. Set ARP frames access category to best effort (0) solves
2520 * this problem.
2521 */
2522
2523 ret = ath10k_wmi_pdev_set_param(ar,
2524 ar->wmi.pdev_param->arp_ac_override, 0);
2525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002526 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002527 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03002528 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02002529 }
2530
Michal Kaziord6500972014-04-08 09:56:09 +03002531 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002532 ath10k_regd_update(ar);
2533
Simon Wunderlich855aed12014-08-02 09:12:54 +03002534 ath10k_spectral_start(ar);
2535
Michal Kaziorae254432014-05-26 12:46:02 +03002536 mutex_unlock(&ar->conf_mutex);
2537 return 0;
2538
2539err_core_stop:
2540 ath10k_core_stop(ar);
2541
2542err_power_down:
2543 ath10k_hif_power_down(ar);
2544
2545err_off:
2546 ar->state = ATH10K_STATE_OFF;
2547
2548err:
Michal Kazior548db542013-07-05 16:15:15 +03002549 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01002550 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551}
2552
2553static void ath10k_stop(struct ieee80211_hw *hw)
2554{
2555 struct ath10k *ar = hw->priv;
2556
Michal Kaziorbca7baf2014-05-26 12:46:03 +03002557 ath10k_drain_tx(ar);
2558
Michal Kazior548db542013-07-05 16:15:15 +03002559 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002560 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02002561 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03002562 ar->state = ATH10K_STATE_OFF;
2563 }
Michal Kazior548db542013-07-05 16:15:15 +03002564 mutex_unlock(&ar->conf_mutex);
2565
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002566 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02002567 cancel_work_sync(&ar->restart_work);
2568}
2569
Michal Kaziorad088bf2013-10-16 15:44:46 +03002570static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02002571{
Michal Kaziorad088bf2013-10-16 15:44:46 +03002572 struct ath10k_vif *arvif;
2573 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02002574
2575 lockdep_assert_held(&ar->conf_mutex);
2576
Michal Kaziorad088bf2013-10-16 15:44:46 +03002577 list_for_each_entry(arvif, &ar->arvifs, list) {
2578 ret = ath10k_mac_vif_setup_ps(arvif);
2579 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002580 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03002581 break;
2582 }
2583 }
Michal Kazioraffd3212013-07-16 09:54:35 +02002584
Michal Kaziorad088bf2013-10-16 15:44:46 +03002585 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586}
2587
Michal Kaziorc930f742014-01-23 11:38:25 +01002588static const char *chandef_get_width(enum nl80211_chan_width width)
2589{
2590 switch (width) {
2591 case NL80211_CHAN_WIDTH_20_NOHT:
2592 return "20 (noht)";
2593 case NL80211_CHAN_WIDTH_20:
2594 return "20";
2595 case NL80211_CHAN_WIDTH_40:
2596 return "40";
2597 case NL80211_CHAN_WIDTH_80:
2598 return "80";
2599 case NL80211_CHAN_WIDTH_80P80:
2600 return "80+80";
2601 case NL80211_CHAN_WIDTH_160:
2602 return "160";
2603 case NL80211_CHAN_WIDTH_5:
2604 return "5";
2605 case NL80211_CHAN_WIDTH_10:
2606 return "10";
2607 }
2608 return "?";
2609}
2610
2611static void ath10k_config_chan(struct ath10k *ar)
2612{
2613 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01002614 int ret;
2615
2616 lockdep_assert_held(&ar->conf_mutex);
2617
Michal Kazior7aa7a722014-08-25 12:09:38 +02002618 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01002619 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2620 ar->chandef.chan->center_freq,
2621 ar->chandef.center_freq1,
2622 ar->chandef.center_freq2,
2623 chandef_get_width(ar->chandef.width));
2624
2625 /* First stop monitor interface. Some FW versions crash if there's a
2626 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03002627 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02002628 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002629
2630 list_for_each_entry(arvif, &ar->arvifs, list) {
2631 if (!arvif->is_started)
2632 continue;
2633
Michal Kaziordc55e302014-07-29 12:53:36 +03002634 if (!arvif->is_up)
2635 continue;
2636
Michal Kaziorc930f742014-01-23 11:38:25 +01002637 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2638 continue;
2639
Michal Kaziordc55e302014-07-29 12:53:36 +03002640 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01002641 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002642 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002643 arvif->vdev_id, ret);
2644 continue;
2645 }
2646 }
2647
Michal Kaziordc55e302014-07-29 12:53:36 +03002648 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01002649
2650 list_for_each_entry(arvif, &ar->arvifs, list) {
2651 if (!arvif->is_started)
2652 continue;
2653
2654 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2655 continue;
2656
Michal Kaziordc55e302014-07-29 12:53:36 +03002657 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01002658 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002659 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002660 arvif->vdev_id, ret);
2661 continue;
2662 }
2663
2664 if (!arvif->is_up)
2665 continue;
2666
2667 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2668 arvif->bssid);
2669 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002670 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01002671 arvif->vdev_id, ret);
2672 continue;
2673 }
2674 }
2675
Michal Kazior19337472014-08-28 12:58:16 +02002676 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002677}
2678
Kalle Valo5e3dd152013-06-12 20:52:10 +03002679static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2680{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002681 struct ath10k *ar = hw->priv;
2682 struct ieee80211_conf *conf = &hw->conf;
2683 int ret = 0;
Michal Kazior5474efe2013-10-23 04:02:15 -07002684 u32 param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002685
2686 mutex_lock(&ar->conf_mutex);
2687
2688 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002689 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03002690 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002691 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03002692 conf->chandef.chan->flags,
2693 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002694
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 spin_lock_bh(&ar->data_lock);
2696 ar->rx_channel = conf->chandef.chan;
2697 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002698
Michal Kaziord6500972014-04-08 09:56:09 +03002699 ar->radar_enabled = conf->radar_enabled;
2700 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01002701
2702 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2703 ar->chandef = conf->chandef;
2704 ath10k_config_chan(ar);
2705 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706 }
2707
Michal Kazior5474efe2013-10-23 04:02:15 -07002708 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002710 hw->conf.power_level);
2711
2712 param = ar->wmi.pdev_param->txpower_limit2g;
2713 ret = ath10k_wmi_pdev_set_param(ar, param,
2714 hw->conf.power_level * 2);
2715 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002716 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002717 hw->conf.power_level, ret);
2718
2719 param = ar->wmi.pdev_param->txpower_limit5g;
2720 ret = ath10k_wmi_pdev_set_param(ar, param,
2721 hw->conf.power_level * 2);
2722 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002723 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
Michal Kazior5474efe2013-10-23 04:02:15 -07002724 hw->conf.power_level, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002725 }
2726
Michal Kazioraffd3212013-07-16 09:54:35 +02002727 if (changed & IEEE80211_CONF_CHANGE_PS)
2728 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002729
2730 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02002731 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2732 ret = ath10k_monitor_recalc(ar);
2733 if (ret)
2734 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002735 }
2736
2737 mutex_unlock(&ar->conf_mutex);
2738 return ret;
2739}
2740
2741/*
2742 * TODO:
2743 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2744 * because we will send mgmt frames without CCK. This requirement
2745 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2746 * in the TX packet.
2747 */
2748static int ath10k_add_interface(struct ieee80211_hw *hw,
2749 struct ieee80211_vif *vif)
2750{
2751 struct ath10k *ar = hw->priv;
2752 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2753 enum wmi_sta_powersave_param param;
2754 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02002755 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002756 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002757 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758
2759 mutex_lock(&ar->conf_mutex);
2760
Michal Kazior0dbd09e2013-07-31 10:55:14 +02002761 memset(arvif, 0, sizeof(*arvif));
2762
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763 arvif->ar = ar;
2764 arvif->vif = vif;
2765
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002766 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
Ben Greeare63b33f2013-10-22 14:54:14 -07002767 INIT_LIST_HEAD(&arvif->list);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002768
Ben Greeara9aefb32014-08-12 11:02:19 +03002769 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771 ret = -EBUSY;
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002772 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773 }
Ben Greeara9aefb32014-08-12 11:02:19 +03002774 bit = ffs(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002775
2776 arvif->vdev_id = bit - 1;
2777 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778
2779 if (ar->p2p)
2780 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2781
2782 switch (vif->type) {
2783 case NL80211_IFTYPE_UNSPECIFIED:
2784 case NL80211_IFTYPE_STATION:
2785 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2786 if (vif->p2p)
2787 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2788 break;
2789 case NL80211_IFTYPE_ADHOC:
2790 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2791 break;
2792 case NL80211_IFTYPE_AP:
2793 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2794
2795 if (vif->p2p)
2796 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2797 break;
2798 case NL80211_IFTYPE_MONITOR:
2799 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2800 break;
2801 default:
2802 WARN_ON(1);
2803 break;
2804 }
2805
Michal Kazior7aa7a722014-08-25 12:09:38 +02002806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002807 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2808
2809 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2810 arvif->vdev_subtype, vif->addr);
2811 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002812 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002813 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002814 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815 }
2816
Ben Greeara9aefb32014-08-12 11:02:19 +03002817 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03002818 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002819
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002820 vdev_param = ar->wmi.vdev_param->def_keyid;
2821 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002822 arvif->def_wep_key_idx);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002824 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002825 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002826 goto err_vdev_delete;
2827 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002828
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002829 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2830 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002831 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02002832 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002833 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002834 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002835 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002836 goto err_vdev_delete;
2837 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002838
2839 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2840 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2841 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002842 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002843 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002844 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002845 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01002846
Kalle Valo5a13e762014-01-20 11:01:46 +02002847 ret = ath10k_mac_set_kickout(arvif);
2848 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002849 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002850 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02002851 goto err_peer_delete;
2852 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002853 }
2854
2855 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2856 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2857 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2858 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2859 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002860 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002861 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002862 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002863 goto err_peer_delete;
2864 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002865
2866 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2867 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2868 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2869 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002870 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002871 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002872 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002873 goto err_peer_delete;
2874 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002875
2876 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2877 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2878 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2879 param, value);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002880 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002881 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002882 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002883 goto err_peer_delete;
2884 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002885 }
2886
Michal Kazior424121c2013-07-22 14:13:31 +02002887 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002888 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002889 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002890 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002891 goto err_peer_delete;
2892 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002893
Michal Kazior424121c2013-07-22 14:13:31 +02002894 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002896 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03002897 arvif->vdev_id, ret);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002898 goto err_peer_delete;
2899 }
Michal Kazior679c54a2013-07-05 16:15:04 +03002900
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002902 return 0;
2903
2904err_peer_delete:
2905 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2906 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2907
2908err_vdev_delete:
2909 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greeara9aefb32014-08-12 11:02:19 +03002910 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002911 list_del(&arvif->list);
Michal Kazior9dad14ae2013-10-16 15:44:45 +03002912
2913err:
2914 mutex_unlock(&ar->conf_mutex);
2915
Kalle Valo5e3dd152013-06-12 20:52:10 +03002916 return ret;
2917}
2918
2919static void ath10k_remove_interface(struct ieee80211_hw *hw,
2920 struct ieee80211_vif *vif)
2921{
2922 struct ath10k *ar = hw->priv;
2923 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2924 int ret;
2925
2926 mutex_lock(&ar->conf_mutex);
2927
Michal Kaziorcc4827b2013-10-16 15:44:45 +03002928 cancel_work_sync(&arvif->wep_key_work);
2929
Michal Kaziored543882013-09-13 14:16:56 +02002930 spin_lock_bh(&ar->data_lock);
2931 if (arvif->beacon) {
Michal Kaziorec6bc552014-04-23 19:30:05 +03002932 dma_unmap_single(arvif->ar->dev,
2933 ATH10K_SKB_CB(arvif->beacon)->paddr,
2934 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02002935 dev_kfree_skb_any(arvif->beacon);
2936 arvif->beacon = NULL;
2937 }
Simon Wunderlich855aed12014-08-02 09:12:54 +03002938
Michal Kaziored543882013-09-13 14:16:56 +02002939 spin_unlock_bh(&ar->data_lock);
2940
Simon Wunderlich855aed12014-08-02 09:12:54 +03002941 ret = ath10k_spectral_vif_stop(arvif);
2942 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002943 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03002944 arvif->vdev_id, ret);
2945
Ben Greeara9aefb32014-08-12 11:02:19 +03002946 ar->free_vdev_map |= 1 << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03002947 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002948
2949 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2950 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2951 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002952 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002953 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002954
2955 kfree(arvif->u.ap.noa_data);
2956 }
2957
Michal Kazior7aa7a722014-08-25 12:09:38 +02002958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002959 arvif->vdev_id);
2960
Kalle Valo5e3dd152013-06-12 20:52:10 +03002961 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2962 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002963 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002964 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002965
Kalle Valo5e3dd152013-06-12 20:52:10 +03002966 ath10k_peer_cleanup(ar, arvif->vdev_id);
2967
2968 mutex_unlock(&ar->conf_mutex);
2969}
2970
2971/*
2972 * FIXME: Has to be verified.
2973 */
2974#define SUPPORTED_FILTERS \
2975 (FIF_PROMISC_IN_BSS | \
2976 FIF_ALLMULTI | \
2977 FIF_CONTROL | \
2978 FIF_PSPOLL | \
2979 FIF_OTHER_BSS | \
2980 FIF_BCN_PRBRESP_PROMISC | \
2981 FIF_PROBE_REQ | \
2982 FIF_FCSFAIL)
2983
2984static void ath10k_configure_filter(struct ieee80211_hw *hw,
2985 unsigned int changed_flags,
2986 unsigned int *total_flags,
2987 u64 multicast)
2988{
2989 struct ath10k *ar = hw->priv;
2990 int ret;
2991
2992 mutex_lock(&ar->conf_mutex);
2993
2994 changed_flags &= SUPPORTED_FILTERS;
2995 *total_flags &= SUPPORTED_FILTERS;
2996 ar->filter_flags = *total_flags;
2997
Michal Kazior19337472014-08-28 12:58:16 +02002998 ret = ath10k_monitor_recalc(ar);
2999 if (ret)
3000 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003001
3002 mutex_unlock(&ar->conf_mutex);
3003}
3004
3005static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_bss_conf *info,
3008 u32 changed)
3009{
3010 struct ath10k *ar = hw->priv;
3011 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3012 int ret = 0;
Bartosz Markowski226a3392013-09-26 17:47:16 +02003013 u32 vdev_param, pdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003014
3015 mutex_lock(&ar->conf_mutex);
3016
3017 if (changed & BSS_CHANGED_IBSS)
3018 ath10k_control_ibss(arvif, info, vif->addr);
3019
3020 if (changed & BSS_CHANGED_BEACON_INT) {
3021 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003022 vdev_param = ar->wmi.vdev_param->beacon_interval;
3023 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003024 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02003025 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003026 "mac vdev %d beacon_interval %d\n",
3027 arvif->vdev_id, arvif->beacon_interval);
3028
Kalle Valo5e3dd152013-06-12 20:52:10 +03003029 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003030 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003031 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003032 }
3033
3034 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003035 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003036 "vdev %d set beacon tx mode to staggered\n",
3037 arvif->vdev_id);
3038
Bartosz Markowski226a3392013-09-26 17:47:16 +02003039 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3040 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003041 WMI_BEACON_STAGGERED_MODE);
3042 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003043 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003044 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045 }
3046
John W. Linvilleb70727e82013-06-13 13:34:29 -04003047 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003048 arvif->dtim_period = info->dtim_period;
3049
Michal Kazior7aa7a722014-08-25 12:09:38 +02003050 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003051 "mac vdev %d dtim_period %d\n",
3052 arvif->vdev_id, arvif->dtim_period);
3053
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003054 vdev_param = ar->wmi.vdev_param->dtim_period;
3055 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003056 arvif->dtim_period);
3057 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003058 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003059 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003060 }
3061
3062 if (changed & BSS_CHANGED_SSID &&
3063 vif->type == NL80211_IFTYPE_AP) {
3064 arvif->u.ap.ssid_len = info->ssid_len;
3065 if (info->ssid_len)
3066 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3067 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3068 }
3069
Michal Kazior7b161a72014-05-26 12:46:03 +03003070 /*
3071 * Firmware manages AP self-peer internally so make sure to not create
3072 * it in driver. Otherwise AP self-peer deletion may timeout later.
3073 */
3074 if (changed & BSS_CHANGED_BSSID &&
3075 vif->type != NL80211_IFTYPE_AP) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076 if (!is_zero_ether_addr(info->bssid)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003077 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003078 "mac vdev %d create peer %pM\n",
3079 arvif->vdev_id, info->bssid);
3080
Kalle Valo5e3dd152013-06-12 20:52:10 +03003081 ret = ath10k_peer_create(ar, arvif->vdev_id,
3082 info->bssid);
3083 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003084 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08003085 info->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003086
3087 if (vif->type == NL80211_IFTYPE_STATION) {
3088 /*
3089 * this is never erased as we it for crypto key
3090 * clearing; this is FW requirement
3091 */
Michal Kaziorc930f742014-01-23 11:38:25 +01003092 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003093
Michal Kazior7aa7a722014-08-25 12:09:38 +02003094 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003095 "mac vdev %d start %pM\n",
3096 arvif->vdev_id, info->bssid);
3097
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098 ret = ath10k_vdev_start(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003099 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003100 ath10k_warn(ar, "failed to start vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003101 arvif->vdev_id, ret);
Kalle Valo75459e32014-02-13 18:13:12 +02003102 goto exit;
Michal Kaziorc930f742014-01-23 11:38:25 +01003103 }
3104
3105 arvif->is_started = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003106 }
3107
3108 /*
3109 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3110 * so driver need to store it. It is needed when leaving
3111 * IBSS in order to remove BSSID peer.
3112 */
3113 if (vif->type == NL80211_IFTYPE_ADHOC)
Michal Kaziorc930f742014-01-23 11:38:25 +01003114 memcpy(arvif->bssid, info->bssid,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115 ETH_ALEN);
3116 }
3117 }
3118
3119 if (changed & BSS_CHANGED_BEACON_ENABLED)
3120 ath10k_control_beaconing(arvif, info);
3121
3122 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003123 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02003124 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003125 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003126
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02003127 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003129 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003130 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003131 }
3132
3133 if (changed & BSS_CHANGED_ERP_SLOT) {
3134 u32 slottime;
3135 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) {
3153 u32 preamble;
3154 if (info->use_short_preamble)
3155 preamble = WMI_VDEV_PREAMBLE_SHORT;
3156 else
3157 preamble = WMI_VDEV_PREAMBLE_LONG;
3158
Michal Kazior7aa7a722014-08-25 12:09:38 +02003159 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003160 "mac vdev %d preamble %dn",
3161 arvif->vdev_id, preamble);
3162
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003163 vdev_param = ar->wmi.vdev_param->preamble;
3164 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003165 preamble);
3166 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003167 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003168 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169 }
3170
3171 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02003172 if (info->assoc) {
3173 /* Workaround: Make sure monitor vdev is not running
3174 * when associating to prevent some firmware revisions
3175 * (e.g. 10.1 and 10.2) from crashing.
3176 */
3177 if (ar->monitor_started)
3178 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003179 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02003180 ath10k_monitor_recalc(ar);
3181 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003182 }
3183
Kalle Valo75459e32014-02-13 18:13:12 +02003184exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003185 mutex_unlock(&ar->conf_mutex);
3186}
3187
3188static int ath10k_hw_scan(struct ieee80211_hw *hw,
3189 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02003190 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003191{
3192 struct ath10k *ar = hw->priv;
3193 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02003194 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003195 struct wmi_start_scan_arg arg;
3196 int ret = 0;
3197 int i;
3198
3199 mutex_lock(&ar->conf_mutex);
3200
3201 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003202 switch (ar->scan.state) {
3203 case ATH10K_SCAN_IDLE:
3204 reinit_completion(&ar->scan.started);
3205 reinit_completion(&ar->scan.completed);
3206 ar->scan.state = ATH10K_SCAN_STARTING;
3207 ar->scan.is_roc = false;
3208 ar->scan.vdev_id = arvif->vdev_id;
3209 ret = 0;
3210 break;
3211 case ATH10K_SCAN_STARTING:
3212 case ATH10K_SCAN_RUNNING:
3213 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003214 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003215 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003216 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003217 spin_unlock_bh(&ar->data_lock);
3218
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003219 if (ret)
3220 goto exit;
3221
Kalle Valo5e3dd152013-06-12 20:52:10 +03003222 memset(&arg, 0, sizeof(arg));
3223 ath10k_wmi_start_scan_init(ar, &arg);
3224 arg.vdev_id = arvif->vdev_id;
3225 arg.scan_id = ATH10K_SCAN_ID;
3226
3227 if (!req->no_cck)
3228 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3229
3230 if (req->ie_len) {
3231 arg.ie_len = req->ie_len;
3232 memcpy(arg.ie, req->ie, arg.ie_len);
3233 }
3234
3235 if (req->n_ssids) {
3236 arg.n_ssids = req->n_ssids;
3237 for (i = 0; i < arg.n_ssids; i++) {
3238 arg.ssids[i].len = req->ssids[i].ssid_len;
3239 arg.ssids[i].ssid = req->ssids[i].ssid;
3240 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02003241 } else {
3242 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003243 }
3244
3245 if (req->n_channels) {
3246 arg.n_channels = req->n_channels;
3247 for (i = 0; i < arg.n_channels; i++)
3248 arg.channels[i] = req->channels[i]->center_freq;
3249 }
3250
3251 ret = ath10k_start_scan(ar, &arg);
3252 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003253 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003254 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003255 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003256 spin_unlock_bh(&ar->data_lock);
3257 }
3258
3259exit:
3260 mutex_unlock(&ar->conf_mutex);
3261 return ret;
3262}
3263
3264static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3265 struct ieee80211_vif *vif)
3266{
3267 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003268
3269 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003270 cancel_delayed_work_sync(&ar->scan.timeout);
3271 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272 mutex_unlock(&ar->conf_mutex);
3273}
3274
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003275static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3276 struct ath10k_vif *arvif,
3277 enum set_key_cmd cmd,
3278 struct ieee80211_key_conf *key)
3279{
3280 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3281 int ret;
3282
3283 /* 10.1 firmware branch requires default key index to be set to group
3284 * key index after installing it. Otherwise FW/HW Txes corrupted
3285 * frames with multi-vif APs. This is not required for main firmware
3286 * branch (e.g. 636).
3287 *
3288 * FIXME: This has been tested only in AP. It remains unknown if this
3289 * is required for multi-vif STA interfaces on 10.1 */
3290
3291 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3292 return;
3293
3294 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3295 return;
3296
3297 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3298 return;
3299
3300 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3301 return;
3302
3303 if (cmd != SET_KEY)
3304 return;
3305
3306 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3307 key->keyidx);
3308 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003309 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003310 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003311}
3312
Kalle Valo5e3dd152013-06-12 20:52:10 +03003313static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3314 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3315 struct ieee80211_key_conf *key)
3316{
3317 struct ath10k *ar = hw->priv;
3318 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3319 struct ath10k_peer *peer;
3320 const u8 *peer_addr;
3321 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3322 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3323 int ret = 0;
3324
3325 if (key->keyidx > WMI_MAX_KEY_INDEX)
3326 return -ENOSPC;
3327
3328 mutex_lock(&ar->conf_mutex);
3329
3330 if (sta)
3331 peer_addr = sta->addr;
3332 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3333 peer_addr = vif->bss_conf.bssid;
3334 else
3335 peer_addr = vif->addr;
3336
3337 key->hw_key_idx = key->keyidx;
3338
3339 /* the peer should not disappear in mid-way (unless FW goes awry) since
3340 * we already hold conf_mutex. we just make sure its there now. */
3341 spin_lock_bh(&ar->data_lock);
3342 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3343 spin_unlock_bh(&ar->data_lock);
3344
3345 if (!peer) {
3346 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003347 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003348 peer_addr);
3349 ret = -EOPNOTSUPP;
3350 goto exit;
3351 } else {
3352 /* if the peer doesn't exist there is no key to disable
3353 * anymore */
3354 goto exit;
3355 }
3356 }
3357
3358 if (is_wep) {
3359 if (cmd == SET_KEY)
3360 arvif->wep_keys[key->keyidx] = key;
3361 else
3362 arvif->wep_keys[key->keyidx] = NULL;
3363
3364 if (cmd == DISABLE_KEY)
3365 ath10k_clear_vdev_key(arvif, key);
3366 }
3367
3368 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3369 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003370 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003371 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003372 goto exit;
3373 }
3374
Michal Kaziorcfb27d22013-12-02 09:06:36 +01003375 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3376
Kalle Valo5e3dd152013-06-12 20:52:10 +03003377 spin_lock_bh(&ar->data_lock);
3378 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3379 if (peer && cmd == SET_KEY)
3380 peer->keys[key->keyidx] = key;
3381 else if (peer && cmd == DISABLE_KEY)
3382 peer->keys[key->keyidx] = NULL;
3383 else if (peer == NULL)
3384 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003385 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003386 spin_unlock_bh(&ar->data_lock);
3387
3388exit:
3389 mutex_unlock(&ar->conf_mutex);
3390 return ret;
3391}
3392
Michal Kazior9797feb2014-02-14 14:49:48 +01003393static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3394{
3395 struct ath10k *ar;
3396 struct ath10k_vif *arvif;
3397 struct ath10k_sta *arsta;
3398 struct ieee80211_sta *sta;
3399 u32 changed, bw, nss, smps;
3400 int err;
3401
3402 arsta = container_of(wk, struct ath10k_sta, update_wk);
3403 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3404 arvif = arsta->arvif;
3405 ar = arvif->ar;
3406
3407 spin_lock_bh(&ar->data_lock);
3408
3409 changed = arsta->changed;
3410 arsta->changed = 0;
3411
3412 bw = arsta->bw;
3413 nss = arsta->nss;
3414 smps = arsta->smps;
3415
3416 spin_unlock_bh(&ar->data_lock);
3417
3418 mutex_lock(&ar->conf_mutex);
3419
3420 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003421 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003422 sta->addr, bw);
3423
3424 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3425 WMI_PEER_CHAN_WIDTH, bw);
3426 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003427 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003428 sta->addr, bw, err);
3429 }
3430
3431 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003432 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003433 sta->addr, nss);
3434
3435 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3436 WMI_PEER_NSS, nss);
3437 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003438 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003439 sta->addr, nss, err);
3440 }
3441
3442 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003443 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003444 sta->addr, smps);
3445
3446 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3447 WMI_PEER_SMPS_STATE, smps);
3448 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003449 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01003450 sta->addr, smps, err);
3451 }
3452
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003453 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003454 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003455 sta->addr);
3456
3457 err = ath10k_station_assoc(ar, arvif, sta, true);
3458 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003459 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003460 sta->addr);
3461 }
3462
Michal Kazior9797feb2014-02-14 14:49:48 +01003463 mutex_unlock(&ar->conf_mutex);
3464}
3465
Kalle Valo5e3dd152013-06-12 20:52:10 +03003466static int ath10k_sta_state(struct ieee80211_hw *hw,
3467 struct ieee80211_vif *vif,
3468 struct ieee80211_sta *sta,
3469 enum ieee80211_sta_state old_state,
3470 enum ieee80211_sta_state new_state)
3471{
3472 struct ath10k *ar = hw->priv;
3473 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01003474 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003475 int max_num_peers;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476 int ret = 0;
3477
Michal Kazior76f90022014-02-25 09:29:57 +02003478 if (old_state == IEEE80211_STA_NOTEXIST &&
3479 new_state == IEEE80211_STA_NONE) {
3480 memset(arsta, 0, sizeof(*arsta));
3481 arsta->arvif = arvif;
3482 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3483 }
3484
Michal Kazior9797feb2014-02-14 14:49:48 +01003485 /* cancel must be done outside the mutex to avoid deadlock */
3486 if ((old_state == IEEE80211_STA_NONE &&
3487 new_state == IEEE80211_STA_NOTEXIST))
3488 cancel_work_sync(&arsta->update_wk);
3489
Kalle Valo5e3dd152013-06-12 20:52:10 +03003490 mutex_lock(&ar->conf_mutex);
3491
3492 if (old_state == IEEE80211_STA_NOTEXIST &&
3493 new_state == IEEE80211_STA_NONE &&
3494 vif->type != NL80211_IFTYPE_STATION) {
3495 /*
3496 * New station addition.
3497 */
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003498 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3499 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3500 else
3501 max_num_peers = TARGET_NUM_PEERS;
3502
3503 if (ar->num_peers >= max_num_peers) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003504 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003505 ar->num_peers, max_num_peers);
3506 ret = -ENOBUFS;
3507 goto exit;
3508 }
3509
Michal Kazior7aa7a722014-08-25 12:09:38 +02003510 ath10k_dbg(ar, ATH10K_DBG_MAC,
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003511 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3512 arvif->vdev_id, sta->addr, ar->num_peers);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003513
Kalle Valo5e3dd152013-06-12 20:52:10 +03003514 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3515 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003516 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 -08003517 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 } else if ((old_state == IEEE80211_STA_NONE &&
3519 new_state == IEEE80211_STA_NOTEXIST)) {
3520 /*
3521 * Existing station deletion.
3522 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003523 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03003524 "mac vdev %d peer delete %pM (sta gone)\n",
3525 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003526 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3527 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003528 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003529 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003530
3531 if (vif->type == NL80211_IFTYPE_STATION)
3532 ath10k_bss_disassoc(hw, vif);
3533 } else if (old_state == IEEE80211_STA_AUTH &&
3534 new_state == IEEE80211_STA_ASSOC &&
3535 (vif->type == NL80211_IFTYPE_AP ||
3536 vif->type == NL80211_IFTYPE_ADHOC)) {
3537 /*
3538 * New association.
3539 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003540 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003541 sta->addr);
3542
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003543 ret = ath10k_station_assoc(ar, arvif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003545 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003546 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003547 } else if (old_state == IEEE80211_STA_ASSOC &&
3548 new_state == IEEE80211_STA_AUTH &&
3549 (vif->type == NL80211_IFTYPE_AP ||
3550 vif->type == NL80211_IFTYPE_ADHOC)) {
3551 /*
3552 * Disassociation.
3553 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003554 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003555 sta->addr);
3556
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 ret = ath10k_station_disassoc(ar, arvif, sta);
3558 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003559 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02003560 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003561 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01003562exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003563 mutex_unlock(&ar->conf_mutex);
3564 return ret;
3565}
3566
3567static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3568 u16 ac, bool enable)
3569{
3570 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3571 u32 value = 0;
3572 int ret = 0;
3573
Michal Kazior548db542013-07-05 16:15:15 +03003574 lockdep_assert_held(&ar->conf_mutex);
3575
Kalle Valo5e3dd152013-06-12 20:52:10 +03003576 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3577 return 0;
3578
3579 switch (ac) {
3580 case IEEE80211_AC_VO:
3581 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3582 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3583 break;
3584 case IEEE80211_AC_VI:
3585 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3586 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3587 break;
3588 case IEEE80211_AC_BE:
3589 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3590 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3591 break;
3592 case IEEE80211_AC_BK:
3593 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3594 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3595 break;
3596 }
3597
3598 if (enable)
3599 arvif->u.sta.uapsd |= value;
3600 else
3601 arvif->u.sta.uapsd &= ~value;
3602
3603 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3604 WMI_STA_PS_PARAM_UAPSD,
3605 arvif->u.sta.uapsd);
3606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003607 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003608 goto exit;
3609 }
3610
3611 if (arvif->u.sta.uapsd)
3612 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3613 else
3614 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3615
3616 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3617 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3618 value);
3619 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003620 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621
3622exit:
3623 return ret;
3624}
3625
3626static int ath10k_conf_tx(struct ieee80211_hw *hw,
3627 struct ieee80211_vif *vif, u16 ac,
3628 const struct ieee80211_tx_queue_params *params)
3629{
3630 struct ath10k *ar = hw->priv;
3631 struct wmi_wmm_params_arg *p = NULL;
3632 int ret;
3633
3634 mutex_lock(&ar->conf_mutex);
3635
3636 switch (ac) {
3637 case IEEE80211_AC_VO:
3638 p = &ar->wmm_params.ac_vo;
3639 break;
3640 case IEEE80211_AC_VI:
3641 p = &ar->wmm_params.ac_vi;
3642 break;
3643 case IEEE80211_AC_BE:
3644 p = &ar->wmm_params.ac_be;
3645 break;
3646 case IEEE80211_AC_BK:
3647 p = &ar->wmm_params.ac_bk;
3648 break;
3649 }
3650
3651 if (WARN_ON(!p)) {
3652 ret = -EINVAL;
3653 goto exit;
3654 }
3655
3656 p->cwmin = params->cw_min;
3657 p->cwmax = params->cw_max;
3658 p->aifs = params->aifs;
3659
3660 /*
3661 * The channel time duration programmed in the HW is in absolute
3662 * microseconds, while mac80211 gives the txop in units of
3663 * 32 microseconds.
3664 */
3665 p->txop = params->txop * 32;
3666
3667 /* FIXME: FW accepts wmm params per hw, not per vif */
3668 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3669 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003670 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003671 goto exit;
3672 }
3673
3674 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3675 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003676 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003677
3678exit:
3679 mutex_unlock(&ar->conf_mutex);
3680 return ret;
3681}
3682
3683#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3684
3685static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3686 struct ieee80211_vif *vif,
3687 struct ieee80211_channel *chan,
3688 int duration,
3689 enum ieee80211_roc_type type)
3690{
3691 struct ath10k *ar = hw->priv;
3692 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3693 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003694 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003695
3696 mutex_lock(&ar->conf_mutex);
3697
3698 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003699 switch (ar->scan.state) {
3700 case ATH10K_SCAN_IDLE:
3701 reinit_completion(&ar->scan.started);
3702 reinit_completion(&ar->scan.completed);
3703 reinit_completion(&ar->scan.on_channel);
3704 ar->scan.state = ATH10K_SCAN_STARTING;
3705 ar->scan.is_roc = true;
3706 ar->scan.vdev_id = arvif->vdev_id;
3707 ar->scan.roc_freq = chan->center_freq;
3708 ret = 0;
3709 break;
3710 case ATH10K_SCAN_STARTING:
3711 case ATH10K_SCAN_RUNNING:
3712 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003713 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003714 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003716 spin_unlock_bh(&ar->data_lock);
3717
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003718 if (ret)
3719 goto exit;
3720
Kalle Valo5e3dd152013-06-12 20:52:10 +03003721 memset(&arg, 0, sizeof(arg));
3722 ath10k_wmi_start_scan_init(ar, &arg);
3723 arg.vdev_id = arvif->vdev_id;
3724 arg.scan_id = ATH10K_SCAN_ID;
3725 arg.n_channels = 1;
3726 arg.channels[0] = chan->center_freq;
3727 arg.dwell_time_active = duration;
3728 arg.dwell_time_passive = duration;
3729 arg.max_scan_time = 2 * duration;
3730 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3731 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3732
3733 ret = ath10k_start_scan(ar, &arg);
3734 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003735 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003736 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003737 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003738 spin_unlock_bh(&ar->data_lock);
3739 goto exit;
3740 }
3741
3742 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3743 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003744 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003745
3746 ret = ath10k_scan_stop(ar);
3747 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003748 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003749
Kalle Valo5e3dd152013-06-12 20:52:10 +03003750 ret = -ETIMEDOUT;
3751 goto exit;
3752 }
3753
3754 ret = 0;
3755exit:
3756 mutex_unlock(&ar->conf_mutex);
3757 return ret;
3758}
3759
3760static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3761{
3762 struct ath10k *ar = hw->priv;
3763
3764 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003765 cancel_delayed_work_sync(&ar->scan.timeout);
3766 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003767 mutex_unlock(&ar->conf_mutex);
3768
3769 return 0;
3770}
3771
3772/*
3773 * Both RTS and Fragmentation threshold are interface-specific
3774 * in ath10k, but device-specific in mac80211.
3775 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03003776
3777static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3778{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003780 struct ath10k_vif *arvif;
3781 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03003782
Michal Kaziorad088bf2013-10-16 15:44:46 +03003783 mutex_lock(&ar->conf_mutex);
3784 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003785 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003786 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03003787
Michal Kaziorad088bf2013-10-16 15:44:46 +03003788 ret = ath10k_mac_set_rts(arvif, value);
3789 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003790 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003791 arvif->vdev_id, ret);
3792 break;
3793 }
3794 }
3795 mutex_unlock(&ar->conf_mutex);
3796
3797 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003798}
3799
3800static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3801{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003802 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03003803 struct ath10k_vif *arvif;
3804 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805
Kalle Valo5e3dd152013-06-12 20:52:10 +03003806 mutex_lock(&ar->conf_mutex);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003807 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003809 arvif->vdev_id, value);
3810
3811 ret = ath10k_mac_set_rts(arvif, value);
3812 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003813 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03003814 arvif->vdev_id, ret);
3815 break;
3816 }
3817 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003818 mutex_unlock(&ar->conf_mutex);
3819
Michal Kaziorad088bf2013-10-16 15:44:46 +03003820 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821}
3822
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02003823static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3824 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003825{
3826 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02003827 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003828 int ret;
3829
3830 /* mac80211 doesn't care if we really xmit queued frames or not
3831 * we'll collect those frames either way if we stop/delete vdevs */
3832 if (drop)
3833 return;
3834
Michal Kazior548db542013-07-05 16:15:15 +03003835 mutex_lock(&ar->conf_mutex);
3836
Michal Kazioraffd3212013-07-16 09:54:35 +02003837 if (ar->state == ATH10K_STATE_WEDGED)
3838 goto skip;
3839
Michal Kazioredb82362013-07-05 16:15:14 +03003840 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03003841 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02003842
Michal Kazioredb82362013-07-05 16:15:14 +03003843 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02003844 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03003845 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02003846
3847 skip = (ar->state == ATH10K_STATE_WEDGED);
3848
3849 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003850 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02003851
3852 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003853 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02003854 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03003855
Michal Kazioraffd3212013-07-16 09:54:35 +02003856skip:
Michal Kazior548db542013-07-05 16:15:15 +03003857 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003858}
3859
3860/* TODO: Implement this function properly
3861 * For now it is needed to reply to Probe Requests in IBSS mode.
3862 * Propably we need this information from FW.
3863 */
3864static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3865{
3866 return 1;
3867}
3868
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003869#ifdef CONFIG_PM
3870static int ath10k_suspend(struct ieee80211_hw *hw,
3871 struct cfg80211_wowlan *wowlan)
3872{
3873 struct ath10k *ar = hw->priv;
3874 int ret;
3875
Marek Puzyniak9042e172014-02-10 17:14:23 +01003876 mutex_lock(&ar->conf_mutex);
3877
Marek Puzyniak00f54822014-02-10 17:14:24 +01003878 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003879 if (ret) {
Marek Puzyniak00f54822014-02-10 17:14:24 +01003880 if (ret == -ETIMEDOUT)
3881 goto resume;
Marek Puzyniak9042e172014-02-10 17:14:23 +01003882 ret = 1;
3883 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003884 }
3885
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003886 ret = ath10k_hif_suspend(ar);
3887 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003888 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003889 goto resume;
3890 }
3891
Marek Puzyniak9042e172014-02-10 17:14:23 +01003892 ret = 0;
3893 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003894resume:
3895 ret = ath10k_wmi_pdev_resume_target(ar);
3896 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003897 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003898
3899 ret = 1;
3900exit:
3901 mutex_unlock(&ar->conf_mutex);
3902 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003903}
3904
3905static int ath10k_resume(struct ieee80211_hw *hw)
3906{
3907 struct ath10k *ar = hw->priv;
3908 int ret;
3909
Marek Puzyniak9042e172014-02-10 17:14:23 +01003910 mutex_lock(&ar->conf_mutex);
3911
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003912 ret = ath10k_hif_resume(ar);
3913 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003914 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003915 ret = 1;
3916 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003917 }
3918
3919 ret = ath10k_wmi_pdev_resume_target(ar);
3920 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003921 ath10k_warn(ar, "failed to resume target: %d\n", ret);
Marek Puzyniak9042e172014-02-10 17:14:23 +01003922 ret = 1;
3923 goto exit;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003924 }
3925
Marek Puzyniak9042e172014-02-10 17:14:23 +01003926 ret = 0;
3927exit:
3928 mutex_unlock(&ar->conf_mutex);
3929 return ret;
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003930}
3931#endif
3932
Michal Kazioraffd3212013-07-16 09:54:35 +02003933static void ath10k_restart_complete(struct ieee80211_hw *hw)
3934{
3935 struct ath10k *ar = hw->priv;
3936
3937 mutex_lock(&ar->conf_mutex);
3938
3939 /* If device failed to restart it will be in a different state, e.g.
3940 * ATH10K_STATE_WEDGED */
3941 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003942 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02003943 ar->state = ATH10K_STATE_ON;
3944 }
3945
3946 mutex_unlock(&ar->conf_mutex);
3947}
3948
Michal Kazior2e1dea42013-07-31 10:32:40 +02003949static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3950 struct survey_info *survey)
3951{
3952 struct ath10k *ar = hw->priv;
3953 struct ieee80211_supported_band *sband;
3954 struct survey_info *ar_survey = &ar->survey[idx];
3955 int ret = 0;
3956
3957 mutex_lock(&ar->conf_mutex);
3958
3959 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3960 if (sband && idx >= sband->n_channels) {
3961 idx -= sband->n_channels;
3962 sband = NULL;
3963 }
3964
3965 if (!sband)
3966 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3967
3968 if (!sband || idx >= sband->n_channels) {
3969 ret = -ENOENT;
3970 goto exit;
3971 }
3972
3973 spin_lock_bh(&ar->data_lock);
3974 memcpy(survey, ar_survey, sizeof(*survey));
3975 spin_unlock_bh(&ar->data_lock);
3976
3977 survey->channel = &sband->channels[idx];
3978
3979exit:
3980 mutex_unlock(&ar->conf_mutex);
3981 return ret;
3982}
3983
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01003984/* Helper table for legacy fixed_rate/bitrate_mask */
3985static const u8 cck_ofdm_rate[] = {
3986 /* CCK */
3987 3, /* 1Mbps */
3988 2, /* 2Mbps */
3989 1, /* 5.5Mbps */
3990 0, /* 11Mbps */
3991 /* OFDM */
3992 3, /* 6Mbps */
3993 7, /* 9Mbps */
3994 2, /* 12Mbps */
3995 6, /* 18Mbps */
3996 1, /* 24Mbps */
3997 5, /* 36Mbps */
3998 0, /* 48Mbps */
3999 4, /* 54Mbps */
4000};
4001
4002/* Check if only one bit set */
4003static int ath10k_check_single_mask(u32 mask)
4004{
4005 int bit;
4006
4007 bit = ffs(mask);
4008 if (!bit)
4009 return 0;
4010
4011 mask &= ~BIT(bit - 1);
4012 if (mask)
4013 return 2;
4014
4015 return 1;
4016}
4017
4018static bool
4019ath10k_default_bitrate_mask(struct ath10k *ar,
4020 enum ieee80211_band band,
4021 const struct cfg80211_bitrate_mask *mask)
4022{
4023 u32 legacy = 0x00ff;
4024 u8 ht = 0xff, i;
4025 u16 vht = 0x3ff;
4026
4027 switch (band) {
4028 case IEEE80211_BAND_2GHZ:
4029 legacy = 0x00fff;
4030 vht = 0;
4031 break;
4032 case IEEE80211_BAND_5GHZ:
4033 break;
4034 default:
4035 return false;
4036 }
4037
4038 if (mask->control[band].legacy != legacy)
4039 return false;
4040
4041 for (i = 0; i < ar->num_rf_chains; i++)
4042 if (mask->control[band].ht_mcs[i] != ht)
4043 return false;
4044
4045 for (i = 0; i < ar->num_rf_chains; i++)
4046 if (mask->control[band].vht_mcs[i] != vht)
4047 return false;
4048
4049 return true;
4050}
4051
4052static bool
4053ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4054 enum ieee80211_band band,
4055 u8 *fixed_nss)
4056{
4057 int ht_nss = 0, vht_nss = 0, i;
4058
4059 /* check legacy */
4060 if (ath10k_check_single_mask(mask->control[band].legacy))
4061 return false;
4062
4063 /* check HT */
4064 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4065 if (mask->control[band].ht_mcs[i] == 0xff)
4066 continue;
4067 else if (mask->control[band].ht_mcs[i] == 0x00)
4068 break;
4069 else
4070 return false;
4071 }
4072
4073 ht_nss = i;
4074
4075 /* check VHT */
4076 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4077 if (mask->control[band].vht_mcs[i] == 0x03ff)
4078 continue;
4079 else if (mask->control[band].vht_mcs[i] == 0x0000)
4080 break;
4081 else
4082 return false;
4083 }
4084
4085 vht_nss = i;
4086
4087 if (ht_nss > 0 && vht_nss > 0)
4088 return false;
4089
4090 if (ht_nss)
4091 *fixed_nss = ht_nss;
4092 else if (vht_nss)
4093 *fixed_nss = vht_nss;
4094 else
4095 return false;
4096
4097 return true;
4098}
4099
4100static bool
4101ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4102 enum ieee80211_band band,
4103 enum wmi_rate_preamble *preamble)
4104{
4105 int legacy = 0, ht = 0, vht = 0, i;
4106
4107 *preamble = WMI_RATE_PREAMBLE_OFDM;
4108
4109 /* check legacy */
4110 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4111 if (legacy > 1)
4112 return false;
4113
4114 /* check HT */
4115 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4116 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4117 if (ht > 1)
4118 return false;
4119
4120 /* check VHT */
4121 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4122 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4123 if (vht > 1)
4124 return false;
4125
4126 /* Currently we support only one fixed_rate */
4127 if ((legacy + ht + vht) != 1)
4128 return false;
4129
4130 if (ht)
4131 *preamble = WMI_RATE_PREAMBLE_HT;
4132 else if (vht)
4133 *preamble = WMI_RATE_PREAMBLE_VHT;
4134
4135 return true;
4136}
4137
4138static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02004139ath10k_bitrate_mask_rate(struct ath10k *ar,
4140 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004141 enum ieee80211_band band,
4142 u8 *fixed_rate,
4143 u8 *fixed_nss)
4144{
4145 u8 rate = 0, pream = 0, nss = 0, i;
4146 enum wmi_rate_preamble preamble;
4147
4148 /* Check if single rate correct */
4149 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4150 return false;
4151
4152 pream = preamble;
4153
4154 switch (preamble) {
4155 case WMI_RATE_PREAMBLE_CCK:
4156 case WMI_RATE_PREAMBLE_OFDM:
4157 i = ffs(mask->control[band].legacy) - 1;
4158
4159 if (band == IEEE80211_BAND_2GHZ && i < 4)
4160 pream = WMI_RATE_PREAMBLE_CCK;
4161
4162 if (band == IEEE80211_BAND_5GHZ)
4163 i += 4;
4164
4165 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4166 return false;
4167
4168 rate = cck_ofdm_rate[i];
4169 break;
4170 case WMI_RATE_PREAMBLE_HT:
4171 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4172 if (mask->control[band].ht_mcs[i])
4173 break;
4174
4175 if (i == IEEE80211_HT_MCS_MASK_LEN)
4176 return false;
4177
4178 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4179 nss = i;
4180 break;
4181 case WMI_RATE_PREAMBLE_VHT:
4182 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4183 if (mask->control[band].vht_mcs[i])
4184 break;
4185
4186 if (i == NL80211_VHT_NSS_MAX)
4187 return false;
4188
4189 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4190 nss = i;
4191 break;
4192 }
4193
4194 *fixed_nss = nss + 1;
4195 nss <<= 4;
4196 pream <<= 6;
4197
Michal Kazior7aa7a722014-08-25 12:09:38 +02004198 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 +01004199 pream, nss, rate);
4200
4201 *fixed_rate = pream | nss | rate;
4202
4203 return true;
4204}
4205
Michal Kazior7aa7a722014-08-25 12:09:38 +02004206static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4207 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004208 enum ieee80211_band band,
4209 u8 *fixed_rate,
4210 u8 *fixed_nss)
4211{
4212 /* First check full NSS mask, if we can simply limit NSS */
4213 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4214 return true;
4215
4216 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004217 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004218}
4219
4220static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4221 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004222 u8 fixed_nss,
4223 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004224{
4225 struct ath10k *ar = arvif->ar;
4226 u32 vdev_param;
4227 int ret = 0;
4228
4229 mutex_lock(&ar->conf_mutex);
4230
4231 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004232 arvif->fixed_nss == fixed_nss &&
4233 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004234 goto exit;
4235
4236 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004237 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004238
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004239 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004240 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004241
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004242 vdev_param = ar->wmi.vdev_param->fixed_rate;
4243 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4244 vdev_param, fixed_rate);
4245 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004246 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004247 fixed_rate, ret);
4248 ret = -EINVAL;
4249 goto exit;
4250 }
4251
4252 arvif->fixed_rate = fixed_rate;
4253
4254 vdev_param = ar->wmi.vdev_param->nss;
4255 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4256 vdev_param, fixed_nss);
4257
4258 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004259 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004260 fixed_nss, ret);
4261 ret = -EINVAL;
4262 goto exit;
4263 }
4264
4265 arvif->fixed_nss = fixed_nss;
4266
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004267 vdev_param = ar->wmi.vdev_param->sgi;
4268 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4269 force_sgi);
4270
4271 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004272 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004273 force_sgi, ret);
4274 ret = -EINVAL;
4275 goto exit;
4276 }
4277
4278 arvif->force_sgi = force_sgi;
4279
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004280exit:
4281 mutex_unlock(&ar->conf_mutex);
4282 return ret;
4283}
4284
4285static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4286 struct ieee80211_vif *vif,
4287 const struct cfg80211_bitrate_mask *mask)
4288{
4289 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4290 struct ath10k *ar = arvif->ar;
4291 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4292 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4293 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004294 u8 force_sgi;
4295
4296 force_sgi = mask->control[band].gi;
4297 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4298 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004299
4300 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004301 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004302 &fixed_rate,
4303 &fixed_nss))
4304 return -EINVAL;
4305 }
4306
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004307 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004308 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01004309 return -EINVAL;
4310 }
4311
4312 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4313 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004314}
4315
Michal Kazior9797feb2014-02-14 14:49:48 +01004316static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4317 struct ieee80211_vif *vif,
4318 struct ieee80211_sta *sta,
4319 u32 changed)
4320{
4321 struct ath10k *ar = hw->priv;
4322 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4323 u32 bw, smps;
4324
4325 spin_lock_bh(&ar->data_lock);
4326
Michal Kazior7aa7a722014-08-25 12:09:38 +02004327 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01004328 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4329 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4330 sta->smps_mode);
4331
4332 if (changed & IEEE80211_RC_BW_CHANGED) {
4333 bw = WMI_PEER_CHWIDTH_20MHZ;
4334
4335 switch (sta->bandwidth) {
4336 case IEEE80211_STA_RX_BW_20:
4337 bw = WMI_PEER_CHWIDTH_20MHZ;
4338 break;
4339 case IEEE80211_STA_RX_BW_40:
4340 bw = WMI_PEER_CHWIDTH_40MHZ;
4341 break;
4342 case IEEE80211_STA_RX_BW_80:
4343 bw = WMI_PEER_CHWIDTH_80MHZ;
4344 break;
4345 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004346 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004347 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004348 bw = WMI_PEER_CHWIDTH_20MHZ;
4349 break;
4350 }
4351
4352 arsta->bw = bw;
4353 }
4354
4355 if (changed & IEEE80211_RC_NSS_CHANGED)
4356 arsta->nss = sta->rx_nss;
4357
4358 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4359 smps = WMI_PEER_SMPS_PS_NONE;
4360
4361 switch (sta->smps_mode) {
4362 case IEEE80211_SMPS_AUTOMATIC:
4363 case IEEE80211_SMPS_OFF:
4364 smps = WMI_PEER_SMPS_PS_NONE;
4365 break;
4366 case IEEE80211_SMPS_STATIC:
4367 smps = WMI_PEER_SMPS_STATIC;
4368 break;
4369 case IEEE80211_SMPS_DYNAMIC:
4370 smps = WMI_PEER_SMPS_DYNAMIC;
4371 break;
4372 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02004373 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02004374 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01004375 smps = WMI_PEER_SMPS_PS_NONE;
4376 break;
4377 }
4378
4379 arsta->smps = smps;
4380 }
4381
Michal Kazior9797feb2014-02-14 14:49:48 +01004382 arsta->changed |= changed;
4383
4384 spin_unlock_bh(&ar->data_lock);
4385
4386 ieee80211_queue_work(hw, &arsta->update_wk);
4387}
4388
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004389static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4390{
4391 /*
4392 * FIXME: Return 0 for time being. Need to figure out whether FW
4393 * has the API to fetch 64-bit local TSF
4394 */
4395
4396 return 0;
4397}
4398
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004399static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4400 struct ieee80211_vif *vif,
4401 enum ieee80211_ampdu_mlme_action action,
4402 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4403 u8 buf_size)
4404{
Michal Kazior7aa7a722014-08-25 12:09:38 +02004405 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004406 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4407
Michal Kazior7aa7a722014-08-25 12:09:38 +02004408 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 +02004409 arvif->vdev_id, sta->addr, tid, action);
4410
4411 switch (action) {
4412 case IEEE80211_AMPDU_RX_START:
4413 case IEEE80211_AMPDU_RX_STOP:
4414 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4415 * creation/removal. Do we need to verify this?
4416 */
4417 return 0;
4418 case IEEE80211_AMPDU_TX_START:
4419 case IEEE80211_AMPDU_TX_STOP_CONT:
4420 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4421 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4422 case IEEE80211_AMPDU_TX_OPERATIONAL:
4423 /* Firmware offloads Tx aggregation entirely so deny mac80211
4424 * Tx aggregation requests.
4425 */
4426 return -EOPNOTSUPP;
4427 }
4428
4429 return -EINVAL;
4430}
4431
Kalle Valo5e3dd152013-06-12 20:52:10 +03004432static const struct ieee80211_ops ath10k_ops = {
4433 .tx = ath10k_tx,
4434 .start = ath10k_start,
4435 .stop = ath10k_stop,
4436 .config = ath10k_config,
4437 .add_interface = ath10k_add_interface,
4438 .remove_interface = ath10k_remove_interface,
4439 .configure_filter = ath10k_configure_filter,
4440 .bss_info_changed = ath10k_bss_info_changed,
4441 .hw_scan = ath10k_hw_scan,
4442 .cancel_hw_scan = ath10k_cancel_hw_scan,
4443 .set_key = ath10k_set_key,
4444 .sta_state = ath10k_sta_state,
4445 .conf_tx = ath10k_conf_tx,
4446 .remain_on_channel = ath10k_remain_on_channel,
4447 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4448 .set_rts_threshold = ath10k_set_rts_threshold,
4449 .set_frag_threshold = ath10k_set_frag_threshold,
4450 .flush = ath10k_flush,
4451 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7bb2014-05-16 17:15:38 +03004452 .set_antenna = ath10k_set_antenna,
4453 .get_antenna = ath10k_get_antenna,
Michal Kazioraffd3212013-07-16 09:54:35 +02004454 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02004455 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01004456 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01004457 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02004458 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02004459 .ampdu_action = ath10k_ampdu_action,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02004460#ifdef CONFIG_PM
4461 .suspend = ath10k_suspend,
4462 .resume = ath10k_resume,
4463#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03004464};
4465
4466#define RATETAB_ENT(_rate, _rateid, _flags) { \
4467 .bitrate = (_rate), \
4468 .flags = (_flags), \
4469 .hw_value = (_rateid), \
4470}
4471
4472#define CHAN2G(_channel, _freq, _flags) { \
4473 .band = IEEE80211_BAND_2GHZ, \
4474 .hw_value = (_channel), \
4475 .center_freq = (_freq), \
4476 .flags = (_flags), \
4477 .max_antenna_gain = 0, \
4478 .max_power = 30, \
4479}
4480
4481#define CHAN5G(_channel, _freq, _flags) { \
4482 .band = IEEE80211_BAND_5GHZ, \
4483 .hw_value = (_channel), \
4484 .center_freq = (_freq), \
4485 .flags = (_flags), \
4486 .max_antenna_gain = 0, \
4487 .max_power = 30, \
4488}
4489
4490static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4491 CHAN2G(1, 2412, 0),
4492 CHAN2G(2, 2417, 0),
4493 CHAN2G(3, 2422, 0),
4494 CHAN2G(4, 2427, 0),
4495 CHAN2G(5, 2432, 0),
4496 CHAN2G(6, 2437, 0),
4497 CHAN2G(7, 2442, 0),
4498 CHAN2G(8, 2447, 0),
4499 CHAN2G(9, 2452, 0),
4500 CHAN2G(10, 2457, 0),
4501 CHAN2G(11, 2462, 0),
4502 CHAN2G(12, 2467, 0),
4503 CHAN2G(13, 2472, 0),
4504 CHAN2G(14, 2484, 0),
4505};
4506
4507static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02004508 CHAN5G(36, 5180, 0),
4509 CHAN5G(40, 5200, 0),
4510 CHAN5G(44, 5220, 0),
4511 CHAN5G(48, 5240, 0),
4512 CHAN5G(52, 5260, 0),
4513 CHAN5G(56, 5280, 0),
4514 CHAN5G(60, 5300, 0),
4515 CHAN5G(64, 5320, 0),
4516 CHAN5G(100, 5500, 0),
4517 CHAN5G(104, 5520, 0),
4518 CHAN5G(108, 5540, 0),
4519 CHAN5G(112, 5560, 0),
4520 CHAN5G(116, 5580, 0),
4521 CHAN5G(120, 5600, 0),
4522 CHAN5G(124, 5620, 0),
4523 CHAN5G(128, 5640, 0),
4524 CHAN5G(132, 5660, 0),
4525 CHAN5G(136, 5680, 0),
4526 CHAN5G(140, 5700, 0),
4527 CHAN5G(149, 5745, 0),
4528 CHAN5G(153, 5765, 0),
4529 CHAN5G(157, 5785, 0),
4530 CHAN5G(161, 5805, 0),
4531 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03004532};
4533
4534static struct ieee80211_rate ath10k_rates[] = {
4535 /* CCK */
4536 RATETAB_ENT(10, 0x82, 0),
4537 RATETAB_ENT(20, 0x84, 0),
4538 RATETAB_ENT(55, 0x8b, 0),
4539 RATETAB_ENT(110, 0x96, 0),
4540 /* OFDM */
4541 RATETAB_ENT(60, 0x0c, 0),
4542 RATETAB_ENT(90, 0x12, 0),
4543 RATETAB_ENT(120, 0x18, 0),
4544 RATETAB_ENT(180, 0x24, 0),
4545 RATETAB_ENT(240, 0x30, 0),
4546 RATETAB_ENT(360, 0x48, 0),
4547 RATETAB_ENT(480, 0x60, 0),
4548 RATETAB_ENT(540, 0x6c, 0),
4549};
4550
4551#define ath10k_a_rates (ath10k_rates + 4)
4552#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4553#define ath10k_g_rates (ath10k_rates + 0)
4554#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4555
Michal Kaziore7b54192014-08-07 11:03:27 +02004556struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004557{
4558 struct ieee80211_hw *hw;
4559 struct ath10k *ar;
4560
Michal Kaziore7b54192014-08-07 11:03:27 +02004561 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004562 if (!hw)
4563 return NULL;
4564
4565 ar = hw->priv;
4566 ar->hw = hw;
4567
4568 return ar;
4569}
4570
4571void ath10k_mac_destroy(struct ath10k *ar)
4572{
4573 ieee80211_free_hw(ar->hw);
4574}
4575
4576static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4577 {
4578 .max = 8,
4579 .types = BIT(NL80211_IFTYPE_STATION)
4580 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02004581 },
4582 {
4583 .max = 3,
4584 .types = BIT(NL80211_IFTYPE_P2P_GO)
4585 },
4586 {
4587 .max = 7,
4588 .types = BIT(NL80211_IFTYPE_AP)
4589 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004590};
4591
Bartosz Markowskif2595092013-12-10 16:20:39 +01004592static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004593 {
4594 .max = 8,
4595 .types = BIT(NL80211_IFTYPE_AP)
4596 },
4597};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004598
4599static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4600 {
4601 .limits = ath10k_if_limits,
4602 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4603 .max_interfaces = 8,
4604 .num_different_channels = 1,
4605 .beacon_int_infra_match = true,
4606 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01004607};
4608
4609static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004610 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01004611 .limits = ath10k_10x_if_limits,
4612 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004613 .max_interfaces = 8,
4614 .num_different_channels = 1,
4615 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01004616#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004617 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4618 BIT(NL80211_CHAN_WIDTH_20) |
4619 BIT(NL80211_CHAN_WIDTH_40) |
4620 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02004621#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01004622 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03004623};
4624
4625static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4626{
4627 struct ieee80211_sta_vht_cap vht_cap = {0};
4628 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02004629 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004630
4631 vht_cap.vht_supported = 1;
4632 vht_cap.cap = ar->vht_cap_info;
4633
Michal Kazior8865bee42013-07-24 12:36:46 +02004634 mcs_map = 0;
4635 for (i = 0; i < 8; i++) {
4636 if (i < ar->num_rf_chains)
4637 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4638 else
4639 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4640 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004641
4642 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4643 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4644
4645 return vht_cap;
4646}
4647
4648static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4649{
4650 int i;
4651 struct ieee80211_sta_ht_cap ht_cap = {0};
4652
4653 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4654 return ht_cap;
4655
4656 ht_cap.ht_supported = 1;
4657 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4658 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4659 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4660 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4661 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4662
4663 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4664 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4665
4666 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4667 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4668
4669 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4670 u32 smps;
4671
4672 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4673 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4674
4675 ht_cap.cap |= smps;
4676 }
4677
4678 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4679 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4680
4681 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4682 u32 stbc;
4683
4684 stbc = ar->ht_cap_info;
4685 stbc &= WMI_HT_CAP_RX_STBC;
4686 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4687 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4688 stbc &= IEEE80211_HT_CAP_RX_STBC;
4689
4690 ht_cap.cap |= stbc;
4691 }
4692
4693 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4694 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4695
4696 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4697 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4698
4699 /* max AMSDU is implicitly taken from vht_cap_info */
4700 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4701 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4702
Michal Kazior8865bee42013-07-24 12:36:46 +02004703 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704 ht_cap.mcs.rx_mask[i] = 0xFF;
4705
4706 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4707
4708 return ht_cap;
4709}
4710
4711
4712static void ath10k_get_arvif_iter(void *data, u8 *mac,
4713 struct ieee80211_vif *vif)
4714{
4715 struct ath10k_vif_iter *arvif_iter = data;
4716 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4717
4718 if (arvif->vdev_id == arvif_iter->vdev_id)
4719 arvif_iter->arvif = arvif;
4720}
4721
4722struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4723{
4724 struct ath10k_vif_iter arvif_iter;
4725 u32 flags;
4726
4727 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4728 arvif_iter.vdev_id = vdev_id;
4729
4730 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4731 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4732 flags,
4733 ath10k_get_arvif_iter,
4734 &arvif_iter);
4735 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004736 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004737 return NULL;
4738 }
4739
4740 return arvif_iter.arvif;
4741}
4742
4743int ath10k_mac_register(struct ath10k *ar)
4744{
4745 struct ieee80211_supported_band *band;
4746 struct ieee80211_sta_vht_cap vht_cap;
4747 struct ieee80211_sta_ht_cap ht_cap;
4748 void *channels;
4749 int ret;
4750
4751 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4752
4753 SET_IEEE80211_DEV(ar->hw, ar->dev);
4754
4755 ht_cap = ath10k_get_ht_cap(ar);
4756 vht_cap = ath10k_create_vht_cap(ar);
4757
4758 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4759 channels = kmemdup(ath10k_2ghz_channels,
4760 sizeof(ath10k_2ghz_channels),
4761 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02004762 if (!channels) {
4763 ret = -ENOMEM;
4764 goto err_free;
4765 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004766
4767 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4768 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4769 band->channels = channels;
4770 band->n_bitrates = ath10k_g_rates_size;
4771 band->bitrates = ath10k_g_rates;
4772 band->ht_cap = ht_cap;
4773
4774 /* vht is not supported in 2.4 GHz */
4775
4776 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4777 }
4778
4779 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4780 channels = kmemdup(ath10k_5ghz_channels,
4781 sizeof(ath10k_5ghz_channels),
4782 GFP_KERNEL);
4783 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02004784 ret = -ENOMEM;
4785 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004786 }
4787
4788 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4789 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4790 band->channels = channels;
4791 band->n_bitrates = ath10k_a_rates_size;
4792 band->bitrates = ath10k_a_rates;
4793 band->ht_cap = ht_cap;
4794 band->vht_cap = vht_cap;
4795 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4796 }
4797
4798 ar->hw->wiphy->interface_modes =
4799 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01004800 BIT(NL80211_IFTYPE_AP);
4801
Ben Greear46acf7bb2014-05-16 17:15:38 +03004802 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4803 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4804 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4805 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4806 } else {
4807 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4808 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4809 }
4810
4811 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4812 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4813
Bartosz Markowskid3541812013-12-10 16:20:40 +01004814 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4815 ar->hw->wiphy->interface_modes |=
4816 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4817 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004818
4819 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4820 IEEE80211_HW_SUPPORTS_PS |
4821 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4822 IEEE80211_HW_SUPPORTS_UAPSD |
4823 IEEE80211_HW_MFP_CAPABLE |
4824 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4825 IEEE80211_HW_HAS_RATE_CONTROL |
4826 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02004827 IEEE80211_HW_AP_LINK_PS |
4828 IEEE80211_HW_SPECTRUM_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004829
Michal Kazior1f8bb152013-09-18 14:43:22 +02004830 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4831 * bytes is used for padding/alignment if necessary. */
4832 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4833
Kalle Valo5e3dd152013-06-12 20:52:10 +03004834 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4835 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4836
4837 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4838 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4839 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4840 }
4841
4842 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4843 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4844
4845 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004846 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004847
Kalle Valo5e3dd152013-06-12 20:52:10 +03004848 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4849
4850 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01004851 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004852 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4853
4854 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4855 /*
4856 * on LL hardware queues are managed entirely by the FW
4857 * so we only advertise to mac we can do the queues thing
4858 */
4859 ar->hw->queues = 4;
4860
Bartosz Markowskif2595092013-12-10 16:20:39 +01004861 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4862 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4863 ar->hw->wiphy->n_iface_combinations =
4864 ARRAY_SIZE(ath10k_10x_if_comb);
4865 } else {
4866 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4867 ar->hw->wiphy->n_iface_combinations =
4868 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03004869
4870 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Bartosz Markowskif2595092013-12-10 16:20:39 +01004871 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004872
Michal Kazior7c199992013-07-31 10:47:57 +02004873 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4874
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004875 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4876 /* Init ath dfs pattern detector */
4877 ar->ath_common.debug_mask = ATH_DBG_DFS;
4878 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4879 NL80211_DFS_UNSET);
4880
4881 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004882 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004883 }
4884
Kalle Valo5e3dd152013-06-12 20:52:10 +03004885 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4886 ath10k_reg_notifier);
4887 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004888 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004889 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004890 }
4891
4892 ret = ieee80211_register_hw(ar->hw);
4893 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004894 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02004895 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004896 }
4897
4898 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4899 ret = regulatory_hint(ar->hw->wiphy,
4900 ar->ath_common.regulatory.alpha2);
4901 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02004902 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004903 }
4904
4905 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02004906
4907err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004908 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02004909err_free:
4910 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4911 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4912
Kalle Valo5e3dd152013-06-12 20:52:10 +03004913 return ret;
4914}
4915
4916void ath10k_mac_unregister(struct ath10k *ar)
4917{
4918 ieee80211_unregister_hw(ar->hw);
4919
Janusz Dziedzic9702c682013-11-20 09:59:41 +02004920 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4921 ar->dfs_detector->exit(ar->dfs_detector);
4922
Kalle Valo5e3dd152013-06-12 20:52:10 +03004923 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4924 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4925
4926 SET_IEEE80211_DEV(ar->hw, NULL);
4927}